diff --git a/src/libs/ControlSelection/index.native.js b/src/libs/ControlSelection/index.native.ts similarity index 55% rename from src/libs/ControlSelection/index.native.js rename to src/libs/ControlSelection/index.native.ts index ea91f4bbb1da..e9a1e4e9ad5b 100644 --- a/src/libs/ControlSelection/index.native.js +++ b/src/libs/ControlSelection/index.native.ts @@ -1,11 +1,15 @@ +import ControlSelectionModule from './types'; + function block() {} function unblock() {} function blockElement() {} function unblockElement() {} -export default { +const ControlSelection: ControlSelectionModule = { block, unblock, blockElement, unblockElement, }; + +export default ControlSelection; diff --git a/src/libs/ControlSelection/index.js b/src/libs/ControlSelection/index.ts similarity index 64% rename from src/libs/ControlSelection/index.js rename to src/libs/ControlSelection/index.ts index 7269960d744a..9625b4e49787 100644 --- a/src/libs/ControlSelection/index.js +++ b/src/libs/ControlSelection/index.ts @@ -1,4 +1,5 @@ -import _ from 'underscore'; +import ControlSelectionModule from './types'; +import CustomRefObject from '../../types/utils/CustomRefObject'; /** * Block selection on the whole app @@ -18,10 +19,9 @@ function unblock() { /** * Block selection on particular element - * @param {Element} ref */ -function blockElement(ref) { - if (_.isNull(ref)) { +function blockElement(ref?: CustomRefObject | null) { + if (!ref) { return; } @@ -31,10 +31,9 @@ function blockElement(ref) { /** * Unblock selection on particular element - * @param {Element} ref */ -function unblockElement(ref) { - if (_.isNull(ref)) { +function unblockElement(ref?: CustomRefObject | null) { + if (!ref) { return; } @@ -42,9 +41,11 @@ function unblockElement(ref) { ref.onselectstart = () => true; } -export default { +const ControlSelection: ControlSelectionModule = { block, unblock, blockElement, unblockElement, }; + +export default ControlSelection; diff --git a/src/libs/ControlSelection/types.ts b/src/libs/ControlSelection/types.ts new file mode 100644 index 000000000000..5706a4981d30 --- /dev/null +++ b/src/libs/ControlSelection/types.ts @@ -0,0 +1,10 @@ +import CustomRefObject from '../../types/utils/CustomRefObject'; + +type ControlSelectionModule = { + block: () => void; + unblock: () => void; + blockElement: (ref?: CustomRefObject | null) => void; + unblockElement: (ref?: CustomRefObject | null) => void; +}; + +export default ControlSelectionModule; diff --git a/src/types/utils/CustomRefObject.ts b/src/types/utils/CustomRefObject.ts new file mode 100644 index 000000000000..aa726d7a0f86 --- /dev/null +++ b/src/types/utils/CustomRefObject.ts @@ -0,0 +1,5 @@ +import {RefObject} from 'react'; + +type CustomRefObject = RefObject & {onselectstart: () => boolean}; + +export default CustomRefObject;