Skip to content

Commit

Permalink
Merge pull request #26870 from software-mansion-labs/ts-migration/kow…
Browse files Browse the repository at this point in the history
…czarz/controll-selection-lib

[No QA][TS migration] Migrate 'ControlSelection' lib to TypeScript
  • Loading branch information
roryabraham authored Sep 10, 2023
2 parents b11bddc + 27a49c1 commit 74ffaff
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ from 'underscore';
import ControlSelectionModule from './types';
import CustomRefObject from '../../types/utils/CustomRefObject';

/**
* Block selection on the whole app
Expand All @@ -18,10 +19,9 @@ function unblock() {

/**
* Block selection on particular element
* @param {Element} ref
*/
function blockElement(ref) {
if (_.isNull(ref)) {
function blockElement<T>(ref?: CustomRefObject<T> | null) {
if (!ref) {
return;
}

Expand All @@ -31,20 +31,21 @@ function blockElement(ref) {

/**
* Unblock selection on particular element
* @param {Element} ref
*/
function unblockElement(ref) {
if (_.isNull(ref)) {
function unblockElement<T>(ref?: CustomRefObject<T> | null) {
if (!ref) {
return;
}

// eslint-disable-next-line no-param-reassign
ref.onselectstart = () => true;
}

export default {
const ControlSelection: ControlSelectionModule = {
block,
unblock,
blockElement,
unblockElement,
};

export default ControlSelection;
10 changes: 10 additions & 0 deletions src/libs/ControlSelection/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import CustomRefObject from '../../types/utils/CustomRefObject';

type ControlSelectionModule = {
block: () => void;
unblock: () => void;
blockElement: <T>(ref?: CustomRefObject<T> | null) => void;
unblockElement: <T>(ref?: CustomRefObject<T> | null) => void;
};

export default ControlSelectionModule;
5 changes: 5 additions & 0 deletions src/types/utils/CustomRefObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {RefObject} from 'react';

type CustomRefObject<T> = RefObject<T> & {onselectstart: () => boolean};

export default CustomRefObject;

0 comments on commit 74ffaff

Please sign in to comment.