|
| 1 | +export interface Labels { |
| 2 | + /** |
| 3 | + * @default 'Cut' |
| 4 | + */ |
| 5 | + cut?: string; |
| 6 | + |
| 7 | + /** |
| 8 | + * @default 'Copy' |
| 9 | + */ |
| 10 | + copy?: string; |
| 11 | + |
| 12 | + /** |
| 13 | + * @default 'Paste' |
| 14 | + */ |
| 15 | + paste?: string; |
| 16 | + |
| 17 | + /** |
| 18 | + * @default 'Save Image' |
| 19 | + */ |
| 20 | + save?: string; |
| 21 | + |
| 22 | + /** |
| 23 | + * @default 'Save Image As…' |
| 24 | + */ |
| 25 | + saveImageAs?: string; |
| 26 | + |
| 27 | + /** |
| 28 | + * @default 'Copy Link' |
| 29 | + */ |
| 30 | + copyLink?: string; |
| 31 | + |
| 32 | + /** |
| 33 | + * @default 'Copy Image Address' |
| 34 | + */ |
| 35 | + copyImageAddress?: string; |
| 36 | + |
| 37 | + /** |
| 38 | + * @default 'Inspect Element' |
| 39 | + */ |
| 40 | + inspect?: string; |
| 41 | +} |
| 42 | + |
| 43 | +export interface Options { |
| 44 | + /** |
| 45 | + * Window or WebView to add the context menu to. |
| 46 | + * When not specified, the context menu will be added to all existing and new windows. |
| 47 | + */ |
| 48 | + window?: Electron.BrowserWindow | Electron.WebviewTag; |
| 49 | + |
| 50 | + /** |
| 51 | + * Should return an array of [menu items](https://electronjs.org/docs/api/menu-item) to be prepended to the context menu. |
| 52 | + */ |
| 53 | + prepend?: (params: Electron.ContextMenuParams, browserWindow: Electron.BrowserWindow | Electron.WebviewTag) => Electron.MenuItem[]; |
| 54 | + |
| 55 | + /** |
| 56 | + * Should return an array of [menu items](https://electronjs.org/docs/api/menu-item) to be appended to the context menu. |
| 57 | + */ |
| 58 | + append?: (param: Electron.ContextMenuParams, browserWindow: Electron.BrowserWindow | Electron.WebviewTag) => Electron.MenuItem[]; |
| 59 | + |
| 60 | + /** |
| 61 | + * Show the `Copy Image Address` menu item when right-clicking on an image. |
| 62 | + * |
| 63 | + * @default false |
| 64 | + */ |
| 65 | + showCopyImageAddress?: boolean; |
| 66 | + |
| 67 | + /** |
| 68 | + * Show the `Save Image As…` menu item when right-clicking on an image. |
| 69 | + * |
| 70 | + * @default false |
| 71 | + */ |
| 72 | + showSaveImageAs?: boolean; |
| 73 | + |
| 74 | + /** |
| 75 | + * Force enable or disable the `Inspect Element` menu item. |
| 76 | + * |
| 77 | + * Default: [Only in development](https://github.com/sindresorhus/electron-is-dev) |
| 78 | + */ |
| 79 | + showInspectElement?: boolean; |
| 80 | + |
| 81 | + /** |
| 82 | + * Overwrite labels for the default menu items. Useful for i18n. |
| 83 | + * |
| 84 | + * @default {} |
| 85 | + */ |
| 86 | + labels?: Labels; |
| 87 | + |
| 88 | + /** |
| 89 | + * Determines whether or not to show the menu. |
| 90 | + * Can be useful if you for example have other code presenting a context menu in some contexts. |
| 91 | + * |
| 92 | + * @example |
| 93 | + * |
| 94 | + * // Doesn't show the menu if the element is editable |
| 95 | + * shouldShowMenu: (event, params) => !params.isEditable |
| 96 | + */ |
| 97 | + shouldShowMenu?: (event: Electron.Event, params: Electron.ContextMenuParams) => boolean; |
| 98 | +} |
| 99 | + |
| 100 | +/** |
| 101 | + * This module gives you a nice extensible context menu with items like `Cut`/`Copy`/`Paste` for text, `Save Image` for images, and `Copy Link` for links. It also adds an `Inspect Element` menu item when in development to quickly view items in the inspector like in Chrome. |
| 102 | + * |
| 103 | + * You can use this module directly in both the main and renderer process. |
| 104 | + * |
| 105 | + * @example |
| 106 | + * |
| 107 | + * import {app, BrowserWindow} from 'electron'; |
| 108 | + * import contextMenu from 'electron-context-menu'; |
| 109 | + * |
| 110 | + * contextMenu({ |
| 111 | + * prepend: (params, browserWindow) => [{ |
| 112 | + * label: 'Rainbow', |
| 113 | + * // Only show it when right-clicking images |
| 114 | + * visible: params.mediaType === 'image' |
| 115 | + * }] |
| 116 | + * }); |
| 117 | + * |
| 118 | + * let win; |
| 119 | + * (async () => { |
| 120 | + * await app.whenReady(); |
| 121 | + * win = new BrowserWindow(); |
| 122 | + * }); |
| 123 | + */ |
| 124 | +export default function contextMenu(options?: Options): void; |
0 commit comments