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

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

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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65                                      1x 96x 96x 96x       96x       96x 96x 96x 96x               1x 4x 4x 4x       4x       4x 4x 4x 4x     1x            
import Events from '../enums/Events';
 
import {
  mouseClick,
  mouseDown,
  mouseDownActivate,
  mouseDoubleClick,
  mouseDrag,
  mouseMove,
  mouseUp,
  mouseWheel,
} from './mouseEventHandlers';
 
/**
 * Enable these listeners are emitted in order, and can be cancelled/prevented from bubbling
 * by any previous event.
 *
 * @param element - The element to add the event listeners to.
 */
const enable = function (element: HTMLDivElement): void {
  element.addEventListener(Events.MOUSE_CLICK, mouseClick as EventListener);
  element.addEventListener(Events.MOUSE_DOWN, mouseDown as EventListener);
  element.addEventListener(
    Events.MOUSE_DOWN_ACTIVATE,
    mouseDownActivate as EventListener
  );
  element.addEventListener(
    Events.MOUSE_DOUBLE_CLICK,
    mouseDoubleClick as EventListener
  );
  element.addEventListener(Events.MOUSE_DRAG, mouseDrag as EventListener);
  element.addEventListener(Events.MOUSE_MOVE, mouseMove as EventListener);
  element.addEventListener(Events.MOUSE_UP, mouseUp as EventListener);
  element.addEventListener(Events.MOUSE_WHEEL, mouseWheel as EventListener);
};
 
/**
 * Disable and Remove the MouseToolEventDispatcher handlers from the element.
 *
 * @param element - HTMLDivElement
 */
const disable = function (element: HTMLDivElement) {
  element.removeEventListener(Events.MOUSE_CLICK, mouseClick as EventListener);
  element.removeEventListener(Events.MOUSE_DOWN, mouseDown as EventListener);
  element.removeEventListener(
    Events.MOUSE_DOWN_ACTIVATE,
    mouseDownActivate as EventListener
  );
  element.removeEventListener(
    Events.MOUSE_DOUBLE_CLICK,
    mouseDoubleClick as EventListener
  );
  element.removeEventListener(Events.MOUSE_DRAG, mouseDrag as EventListener);
  element.removeEventListener(Events.MOUSE_MOVE, mouseMove as EventListener);
  element.removeEventListener(Events.MOUSE_UP, mouseUp as EventListener);
  element.removeEventListener(Events.MOUSE_WHEEL, mouseWheel as EventListener);
};
 
const mouseToolEventDispatcher = {
  enable,
  disable,
};
 
export default mouseToolEventDispatcher;