Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;