All files / packages/tools/src/store cancelActiveManipulations.ts

100% Statements 6/6
50% Branches 1/2
100% Functions 1/1
100% Lines 6/6

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                                  12x         12x 12x 12x 12x 12x        
import { ToolModes } from '../enums';
import getToolsWithModesForElement from '../utilities/getToolsWithModesForElement';
import filterToolsWithAnnotationsForElement from './filterToolsWithAnnotationsForElement';
 
/**
 * Cancel the current active manipulation that is being performed on the provided
 * element. It filters all the active and passive tools for the enabledElement
 * and calls cancel() method for all of them, and returns the tool that has executed its
 * cancellation (returned its annotationUID), since tools that are not being manipulated will
 * short circuit early. Note: not all tools currently implement a cancel method.
 *
 * @param element - canvas element
 * @returns annotationUID that is cancelled
 */
export default function cancelActiveManipulations(
  element: HTMLDivElement
): string | undefined {
  const tools = getToolsWithModesForElement(element, [
    ToolModes.Active,
    ToolModes.Passive,
  ]);
 
  const toolsWithData = filterToolsWithAnnotationsForElement(element, tools);
  for (const { tool } of toolsWithData) {
    const annotationUID = tool.cancel(element);
    Eif (annotationUID) {
      return annotationUID;
    }
  }
}