You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP →

@mattermost/react-native-paste-input

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mattermost/react-native-paste-input - npm Package Compare versions

Comparing version

to
0.5.1

@@ -16,2 +16,4 @@ "use strict";

var _setAndForwardRef = _interopRequireDefault(require("react-native/Libraries/Utilities/setAndForwardRef"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -102,4 +104,51 @@

}, []);
(0, _react.useImperativeHandle)(ref, () => inputRef.current);
function clear() {
if (inputRef.current != null) {
viewCommands.setTextAndSelection(inputRef.current, mostRecentEventCount, '', 0, 0);
}
} // TODO: Fix this returning true on null === null, when no input is focused
function isFocused() {
return _TextInputState.default.currentlyFocusedInput() === inputRef.current;
}
function getNativeRef() {
return inputRef.current;
}
const _setNativeRef = (0, _setAndForwardRef.default)({
getForwardedRef: () => ref,
setLocalRef: localRef => {
inputRef.current = localRef;
/*
Hi reader from the future. I'm sorry for this.
This is a hack. Ideally we would forwardRef to the underlying
host component. However, since TextInput has it's own methods that can be
called as well, if we used the standard forwardRef then these
methods wouldn't be accessible and thus be a breaking change.
We have a couple of options of how to handle this:
- Return a new ref with everything we methods from both. This is problematic
because we need React to also know it is a host component which requires
internals of the class implementation of the ref.
- Break the API and have some other way to call one set of the methods or
the other. This is our long term approach as we want to eventually
get the methods on host components off the ref. So instead of calling
ref.measure() you might call ReactNative.measure(ref). This would hopefully
let the ref for TextInput then have the methods like `.clear`. Or we do it
the other way and make it TextInput.clear(textInputRef) which would be fine
too. Either way though is a breaking change that is longer term.
- Mutate this ref. :( Gross, but accomplishes what we need in the meantime
before we can get to the long term breaking change.
*/
if (localRef) {
localRef.clear = clear;
localRef.isFocused = isFocused;
localRef.getNativeRef = getNativeRef;
}
}
});
const _onBlur = event => {

@@ -196,3 +245,3 @@ _TextInputState.default.blurInput(inputRef.current);

,
ref: inputRef
ref: _setNativeRef
}))));

@@ -199,0 +248,0 @@ });

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
import React, { forwardRef, useEffect, useMemo, useRef, useState } from 'react';
import { requireNativeComponent, TouchableWithoutFeedback } from 'react-native';
import TextInputState from 'react-native/Libraries/Components/TextInput/TextInputState';
import TextAncestor from 'react-native/Libraries/Text/TextAncestor';
import setAndForwardRef from 'react-native/Libraries/Utilities/setAndForwardRef';
const RCTPasteInput = requireNativeComponent('PasteInput');

@@ -84,4 +85,51 @@ const PasteInput = /*#__PURE__*/forwardRef((props, ref) => {

}, []);
useImperativeHandle(ref, () => inputRef.current);
function clear() {
if (inputRef.current != null) {
viewCommands.setTextAndSelection(inputRef.current, mostRecentEventCount, '', 0, 0);
}
} // TODO: Fix this returning true on null === null, when no input is focused
function isFocused() {
return TextInputState.currentlyFocusedInput() === inputRef.current;
}
function getNativeRef() {
return inputRef.current;
}
const _setNativeRef = setAndForwardRef({
getForwardedRef: () => ref,
setLocalRef: localRef => {
inputRef.current = localRef;
/*
Hi reader from the future. I'm sorry for this.
This is a hack. Ideally we would forwardRef to the underlying
host component. However, since TextInput has it's own methods that can be
called as well, if we used the standard forwardRef then these
methods wouldn't be accessible and thus be a breaking change.
We have a couple of options of how to handle this:
- Return a new ref with everything we methods from both. This is problematic
because we need React to also know it is a host component which requires
internals of the class implementation of the ref.
- Break the API and have some other way to call one set of the methods or
the other. This is our long term approach as we want to eventually
get the methods on host components off the ref. So instead of calling
ref.measure() you might call ReactNative.measure(ref). This would hopefully
let the ref for TextInput then have the methods like `.clear`. Or we do it
the other way and make it TextInput.clear(textInputRef) which would be fine
too. Either way though is a breaking change that is longer term.
- Mutate this ref. :( Gross, but accomplishes what we need in the meantime
before we can get to the long term breaking change.
*/
if (localRef) {
localRef.clear = clear;
localRef.isFocused = isFocused;
localRef.getNativeRef = getNativeRef;
}
}
});
const _onBlur = event => {

@@ -178,3 +226,3 @@ TextInputState.blurInput(inputRef.current);

,
ref: inputRef
ref: _setNativeRef
}))));

@@ -181,0 +229,0 @@ });

{
"name": "@mattermost/react-native-paste-input",
"version": "0.5.0",
"version": "0.5.1",
"description": "React Native TextInput replacement to allow pasting files",

@@ -54,13 +54,13 @@ "main": "lib/commonjs/index",

"devDependencies": {
"@commitlint/config-conventional": "17.0.3",
"@commitlint/config-conventional": "17.1.0",
"@react-native-community/bob": "0.17.1",
"@react-native-community/eslint-config": "3.1.0",
"@release-it/conventional-changelog": "5.0.0",
"@types/jest": "28.1.6",
"@types/react": "18.0.15",
"@types/react-native": "0.69.5",
"@typescript-eslint/eslint-plugin": "5.32.0",
"@typescript-eslint/parser": "5.32.0",
"commitlint": "17.0.3",
"eslint": "8.21.0",
"@release-it/conventional-changelog": "5.1.0",
"@types/jest": "29.1.1",
"@types/react": "18.0.21",
"@types/react-native": "0.70.4",
"@typescript-eslint/eslint-plugin": "5.39.0",
"@typescript-eslint/parser": "5.39.0",
"commitlint": "17.1.2",
"eslint": "8.24.0",
"eslint-config-prettier": "8.5.0",

@@ -72,3 +72,3 @@ "eslint-plugin-flowtype": "8.0.3",

"husky": "8.0.1",
"jest": "28.1.3",
"jest": "29.1.2",
"pod-install": "0.1.38",

@@ -78,4 +78,4 @@ "prettier": "2.7.1",

"react-native": "0.69.3",
"release-it": "15.2.0",
"typescript": "4.7.4"
"release-it": "15.5.0",
"typescript": "4.8.4"
},

@@ -82,0 +82,0 @@ "peerDependencies": {

declare module 'react-native/Libraries/Components/TextInput/TextInputState';
declare module 'react-native/Libraries/Text/TextAncestor';
declare module 'react-native/Libraries/Utilities/setAndForwardRef';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet