All files / extensions/default/src/CustomizableContextMenu types.ts

50% Statements 2/4
100% Branches 0/0
33.33% Functions 1/3
33.33% Lines 1/3

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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127        277x                                                                                                                                                                                                                                                    
import { Types } from '@ohif/core';
 
/**
 * SelectorProps are properties used to decide whether to select a menu or
 * menu item for display.
 * An instance of SelectorProps is provided to the selector functions, which
 * return true to include the item or false to exclude it.
 * The point of this is to allow more specific context menus which hide
 * non-relevant menu options, optimizing the speed of selection of menus
 */
export interface SelectorProps {
  // If the context menu is invoked in the context of a measurement, then it
  // will contain the nearby tool data.
  nearbyToolData?: Record<string, unknown>;
 
  // The tool name for the nearby tool
  toolName?: string;
 
  // An annotation UID - this will be present if nearbyToolData is present.
  uid?: string;
 
  // If the context menu is invoked on an active viewport, then it will contain
  // the first display set.
  displaySet?: Record<string, unknown>;
 
  // The triggering event - can be used to determine key modifiers
  event?: Event;
 
  // Any other properties
  [propertyName: string]: unknown;
}
 
/**
 * The type of item actually required for the ContextMenu UI display
 */
export type UIMenuItem = {
  label: string;
  // Called when the item is selected
  action?: (itemRef, componentProps) => void;
};
 
/**
 * A MenuItem is a single line item within a menu, and specifies a selectable
 * value for the menu.
 */
export interface MenuItem {
  id?: string;
  /**
   * The customization type is used to apply preset values to this item
   * when registered with the customization service.
   */
  inheritsFrom?: string;
 
  // The label is the value to show in the menu for this item
  label?: string;
 
  // Delegating items are used to include other sub-menus inline within
  // this menu.  That allows sharing part of the menu structure, but also,
  // more importantly to use a single selector function to include/exclude
  // and entire section of sub-menu.
  // See the `siteSelectionSubMenu` within the example `findingsMenu`
  // for an example
  delegating?: boolean;
 
  // A sub-menu is shown when this item is selected or is delegating.
  //  This item gives the name of the sub-menu.
  subMenu?: string;
 
  // The selector is used to determine if this menu entry will be shown
  // or more importantly, if the delegating subMenu will be included.
  selector?: (props: SelectorProps) => boolean;
 
  /** Adapts the item by filling in additional properties as required */
  adaptItem?: (item: MenuItem, props: ContextMenuProps) => UIMenuItem;
 
  /** List of commands to run when this item's action is taken. */
  commands?: Types.Command[];
}
 
/**
 * A menu is a list of menu items, plus a selector.
 * The selector is used to determine whether the menu should be displayed
 * in a given context.  The parameters passed to the selector come from
 * the 'selectorProps' value in the options, and are intended to be context
 * specific values containing things like the selected object, the currently
 * displayed study etc so that the context menu can dynamically choose which
 * view to show.
 */
export interface Menu {
  id: string;
 
  /** The customization type is used to apply preset values to this item
   * when registered with the customization service.
   */
  inheritsFrom?: string;
 
  // Choose whether this menu applies.
  selector?: Types.Predicate;
 
  items: MenuItem[];
}
 
export type Point = {
  x: number;
  y: number;
};
 
/**
 * ContextMenuProps is the top level argument used to invoke the context menu
 * itself.  It contains the menus available for display, as well as the event
 * and selector props used to decide the menu.
 */
export type ContextMenuProps = {
  event?: EventTarget;
  menuCustomizationId?: string;
  menuId: string;
  element?: HTMLElement;
 
  /** A set of menus to choose from for this context menu */
  menus: Menu[];
 
  /** The properties used to decide the menu type */
  selectorProps: SelectorProps;
 
  defaultPointsPosition?: [number, number] | [];
};