const acceleratorOrder = ["Control", "Option", "Shift", "CommandOrControl"] export interface MenuOption { label: string description?: string badge?: string badgeCustomClass?: string /** @deprecated - Use MenuItem.acceleratorLabel to define the shortcut text to be shown */ accelerator?: string acceleratorLabelTokens?: string[] tokenDelimiter?: string checked?: boolean disabled?: boolean action?: string icon?: MenuOptionIcon submenu?: MenuItem[] type?: "normal" visible?: boolean } export interface MenuOptionIcon { src: string /** If inlineSVG is true, menu-fisso will try to parse the src as an svg element. Please don't use it on untrusted input! */ inlineSVG?: boolean height?: number width?: number crossOrigin?: "disabled" | "anonymous" | "use-credentials" } interface MenuSeparator { type: "separator" visible?: boolean } export type MenuItem = (MenuOption | MenuSeparator) & { /** * Specify true for this item to be invisible to the callback. This means it won't have * a path and will not increment the path of any item after it. If it has a submenu, * non-virtual items in it will be treated as inline items in the parent menu. */ virtual?: boolean } /** * @deprecated - Use MenuItem.acceleratorLabel to define the shortcut text to be shown * TODO: Remove this when not used anymore * @param accelerator - Electron-notation accelerator string: https://electronjs.org/docs/api/accelerator * @returns platform-specific user-friendly label. E.g. `⇧⌘9` */ export function getAcceleratorLabelTokens(accelerator: string): string[] { if (!accelerator) return [] return accelerator .split("+") .sort((a, b) => { const ai = acceleratorOrder.indexOf(a) const bi = acceleratorOrder.indexOf(b) if (ai !== -1 && bi !== -1) return ai - bi if (ai !== -1) return -1 if (bi !== -1) return 1 return 0 }) .map(key => { switch (key) { case "Backspace": case "Delete": return "⌫" case "CommandOrControl": return "⌘" case "Control": return "⌃" case "Down": return "↓" case "Enter": case "Return": return "↩" case "Left": return "←" case "-": return "–" case "Option": return "⌥" case "Plus": return "+" case "Right": return "→" case "Shift": return "⇧" case "Up": return "↑" } return key }) }