All files canvasInteractionTargets.js

89.79% Statements 44/49
68% Branches 17/25
100% Functions 7/7
89.79% Lines 44/49

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 501x 1x 1x 42x 42x 42x 42x       42x 1x 17x 17x 17x 1x 25x 25x 25x 25x 1x 1x 9x 9x 6x 9x 1x 1x 3x 3x 3x     2x 3x 1x 1x 5x 5x 5x 2x 2x 2x 5x 1x 1x 3x 3x 3x  
const EXCLUDED_CANVAS_TARGETS = '.context-menu, .react-flow__node, .react-flow__edge, .react-flow__controls, .react-flow__minimap, .surface-view-container';
const CANVAS_AREA_TARGETS = '.react-flow, .react-flow__renderer, .react-flow__viewport, .react-flow__pane, .react-flow__background, .react-flow__selectionpane';
 
function getTargetElement(target) {
  if (!target) return null;
  if (typeof target.closest === 'function') return target;
  if (target.parentElement && typeof target.parentElement.closest === 'function') {
    return target.parentElement;
  }
  return null;
}
 
function supportsClosest(target) {
  return !!getTargetElement(target);
}
 
function matchesClosest(target, selector) {
  const element = getTargetElement(target);
  return !!element && element.closest(selector) !== null;
}
 
export function isEditableInteractionTarget(target) {
  if (!supportsClosest(target)) return false;
  if (matchesClosest(target, 'input, textarea, select')) return true;
  return matchesClosest(target, '[contenteditable="true"]');
}
 
export function canStartCanvasRightDragZoomTarget(target) {
  if (!supportsClosest(target)) return false;
  if (isEditableInteractionTarget(target)) return false;
  if (matchesClosest(target, EXCLUDED_CANVAS_TARGETS)) {
    return false;
  }
  return matchesClosest(target, CANVAS_AREA_TARGETS);
}
 
export function canOpenCanvasContextMenuTarget(target) {
  if (!supportsClosest(target)) return false;
  if (isEditableInteractionTarget(target)) return false;
  if (matchesClosest(target, EXCLUDED_CANVAS_TARGETS)) {
    return false;
  }
  return matchesClosest(target, CANVAS_AREA_TARGETS);
}
 
export function isSecondaryCanvasContextEvent(event) {
  if (!event || typeof event.button !== 'number') return false;
  return event.button === 2 || (event.button === 0 && !!event.ctrlKey);
}