From 59e540441a63559aced6ef1c0569ff8e48ff30c7 Mon Sep 17 00:00:00 2001 From: Kamil Owczarz Date: Tue, 5 Sep 2023 17:06:02 +0200 Subject: [PATCH 1/3] Migrate 'ControlSelection' lib to TypeScript --- .../{index.native.js => index.native.ts} | 6 +++++- src/libs/ControlSelection/{index.js => index.ts} | 12 ++++++------ src/libs/ControlSelection/types.ts | 10 ++++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) rename src/libs/ControlSelection/{index.native.js => index.native.ts} (55%) rename src/libs/ControlSelection/{index.js => index.ts} (81%) create mode 100644 src/libs/ControlSelection/types.ts 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 81% rename from src/libs/ControlSelection/index.js rename to src/libs/ControlSelection/index.ts index 7269960d744a..b430dd801254 100644 --- a/src/libs/ControlSelection/index.js +++ b/src/libs/ControlSelection/index.ts @@ -1,4 +1,4 @@ -import _ from 'underscore'; +import ControlSelectionModule from './types'; /** * Block selection on the whole app @@ -18,10 +18,9 @@ function unblock() { /** * Block selection on particular element - * @param {Element} ref */ function blockElement(ref) { - if (_.isNull(ref)) { + if (!ref) { return; } @@ -31,10 +30,9 @@ function blockElement(ref) { /** * Unblock selection on particular element - * @param {Element} ref */ function unblockElement(ref) { - if (_.isNull(ref)) { + if (!ref) { return; } @@ -42,9 +40,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..d94c0e0180ba --- /dev/null +++ b/src/libs/ControlSelection/types.ts @@ -0,0 +1,10 @@ +import {RefObject} from 'react'; + +type ControlSelectionModule = { + block: () => void; + unblock: () => void; + blockElement: (ref?: RefObject) => void; + unblockElement: (ref?: RefObject) => void; +}; + +export default ControlSelectionModule; From 6734257c7538137b0ba2919c3fd7fb2cb6f2c667 Mon Sep 17 00:00:00 2001 From: Kamil Owczarz Date: Wed, 6 Sep 2023 12:00:46 +0200 Subject: [PATCH 2/3] Fix types --- src/libs/ControlSelection/index.ts | 4 ++-- src/libs/ControlSelection/types.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/ControlSelection/index.ts b/src/libs/ControlSelection/index.ts index b430dd801254..4616701a55df 100644 --- a/src/libs/ControlSelection/index.ts +++ b/src/libs/ControlSelection/index.ts @@ -20,7 +20,7 @@ function unblock() { * Block selection on particular element */ function blockElement(ref) { - if (!ref) { + if (ref === null) { return; } @@ -32,7 +32,7 @@ function blockElement(ref) { * Unblock selection on particular element */ function unblockElement(ref) { - if (!ref) { + if (ref === null) { return; } diff --git a/src/libs/ControlSelection/types.ts b/src/libs/ControlSelection/types.ts index d94c0e0180ba..156fa25d27a1 100644 --- a/src/libs/ControlSelection/types.ts +++ b/src/libs/ControlSelection/types.ts @@ -3,8 +3,8 @@ import {RefObject} from 'react'; type ControlSelectionModule = { block: () => void; unblock: () => void; - blockElement: (ref?: RefObject) => void; - unblockElement: (ref?: RefObject) => void; + blockElement: (ref?: RefObject | null) => void; + unblockElement: (ref?: RefObject | null) => void; }; export default ControlSelectionModule; From 27a49c17196b0abe9308e3ba538b7da2d418a96b Mon Sep 17 00:00:00 2001 From: Kamil Owczarz Date: Wed, 6 Sep 2023 15:44:26 +0200 Subject: [PATCH 3/3] Fix lint --- src/libs/ControlSelection/index.ts | 9 +++++---- src/libs/ControlSelection/types.ts | 6 +++--- src/types/utils/CustomRefObject.ts | 5 +++++ 3 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 src/types/utils/CustomRefObject.ts diff --git a/src/libs/ControlSelection/index.ts b/src/libs/ControlSelection/index.ts index 4616701a55df..9625b4e49787 100644 --- a/src/libs/ControlSelection/index.ts +++ b/src/libs/ControlSelection/index.ts @@ -1,4 +1,5 @@ import ControlSelectionModule from './types'; +import CustomRefObject from '../../types/utils/CustomRefObject'; /** * Block selection on the whole app @@ -19,8 +20,8 @@ function unblock() { /** * Block selection on particular element */ -function blockElement(ref) { - if (ref === null) { +function blockElement(ref?: CustomRefObject | null) { + if (!ref) { return; } @@ -31,8 +32,8 @@ function blockElement(ref) { /** * Unblock selection on particular element */ -function unblockElement(ref) { - if (ref === null) { +function unblockElement(ref?: CustomRefObject | null) { + if (!ref) { return; } diff --git a/src/libs/ControlSelection/types.ts b/src/libs/ControlSelection/types.ts index 156fa25d27a1..5706a4981d30 100644 --- a/src/libs/ControlSelection/types.ts +++ b/src/libs/ControlSelection/types.ts @@ -1,10 +1,10 @@ -import {RefObject} from 'react'; +import CustomRefObject from '../../types/utils/CustomRefObject'; type ControlSelectionModule = { block: () => void; unblock: () => void; - blockElement: (ref?: RefObject | null) => void; - unblockElement: (ref?: RefObject | null) => 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;