All files / packages/tools/src/eventDispatchers keyboardToolEventDispatcher.ts

100% Statements 7/7
100% Branches 0/0
100% Functions 2/2
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29                1x 96x 96x             1x 4x 4x     1x            
import Events from '../enums/Events';
import { keyDown, keyUp } from './keyboardEventHandlers';
 
/**
 * Enable Key down and key up listeners
 *
 * @param element - The HTML element to attach the event listeners to.
 */
const enable = function (element: HTMLDivElement) {
  element.addEventListener(Events.KEY_DOWN, keyDown as EventListener);
  element.addEventListener(Events.KEY_UP, keyUp as EventListener);
};
 
/**
 * Disable Key down and key up listeners
 * @param element - The HTML element to attach the event listeners to.
 */
const disable = function (element: HTMLDivElement) {
  element.removeEventListener(Events.KEY_DOWN, keyDown as EventListener);
  element.removeEventListener(Events.KEY_UP, keyUp as EventListener);
};
 
const keyboardToolEventDispatcher = {
  enable,
  disable,
};
 
export default keyboardToolEventDispatcher;