diff --git a/.github/funding.yml b/.github/funding.yml
deleted file mode 100644
index 15edf6e..0000000
--- a/.github/funding.yml
+++ /dev/null
@@ -1,4 +0,0 @@
-github: sindresorhus
-open_collective: sindresorhus
-patreon: sindresorhus
-custom: https://sindresorhus.com/donate
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index bafbe5e..346585c 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -10,10 +10,11 @@ jobs:
fail-fast: false
matrix:
node-version:
- - 14
+ - 20
+ - 18
steps:
- - uses: actions/checkout@v2
- - uses: actions/setup-node@v1
+ - uses: actions/checkout@v4
+ - uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
diff --git a/fixtures/fixture-menu.js b/fixtures/fixture-menu.js
index 920e7e1..a6d7054 100644
--- a/fixtures/fixture-menu.js
+++ b/fixtures/fixture-menu.js
@@ -1,41 +1,44 @@
-'use strict';
-const path = require('path');
-const {
- app,
- BrowserWindow
-} = require('electron');
-const contextMenu = require('..');
+import path from 'node:path';
+import {app, BrowserWindow} from 'electron';
+import contextMenu from '../index.js';
contextMenu({
menu: actions => [
actions.separator(),
actions.copyLink({
- transform: content => `modified_link_${content}`
+ transform: content => `modified_link_${content}`,
}),
actions.separator(),
{
- label: 'Unicorn'
+ label: 'Unicorn',
},
actions.separator(),
+ actions.saveVideo(),
+ actions.saveVideoAs(),
+ actions.copyVideoAddress({
+ transform: content => `modified_copy_${content}`,
+ }),
+ actions.separator(),
actions.copy({
- transform: content => `modified_copy_${content}`
+ transform: content => `modified_copy_${content}`,
}),
{
label: 'Invisible',
- visible: false
+ visible: false,
},
actions.paste({
- transform: content => `modified_paste_${content}`
- })
- ]
+ transform: content => `modified_paste_${content}`,
+ }),
+ ],
});
+// eslint-disable-next-line unicorn/prefer-top-level-await
(async () => {
await app.whenReady();
await (new BrowserWindow({
webPreferences: {
- spellcheck: true
- }
- })).loadFile(path.join(__dirname, 'fixture.html'));
+ spellcheck: true,
+ },
+ })).loadFile(path.join(import.meta.dirname, 'fixture.html'));
})();
diff --git a/fixtures/fixture-toggle.js b/fixtures/fixture-toggle.js
index d99fa83..fa089b7 100644
--- a/fixtures/fixture-toggle.js
+++ b/fixtures/fixture-toggle.js
@@ -1,13 +1,13 @@
-'use strict';
-const path = require('path');
-const {app, BrowserWindow} = require('electron');
+import path from 'node:path';
+import {app, BrowserWindow} from 'electron';
+// eslint-disable-next-line unicorn/prefer-top-level-await
(async () => {
await app.whenReady();
await (new BrowserWindow({
webPreferences: {
- nodeIntegration: true
- }
- })).loadFile(path.join(__dirname, 'fixture-toggle.html'));
+ nodeIntegration: true,
+ },
+ })).loadFile(path.join(import.meta.dirname, 'fixture-toggle.html'));
})();
diff --git a/fixtures/fixture.html b/fixtures/fixture.html
index b0d5b29..90b371b 100644
--- a/fixtures/fixture.html
+++ b/fixtures/fixture.html
@@ -22,6 +22,11 @@
Fixture
+
+
Editable text
Link
diff --git a/fixtures/fixture.js b/fixtures/fixture.js
index f5b70da..cd1e159 100644
--- a/fixtures/fixture.js
+++ b/fixtures/fixture.js
@@ -1,7 +1,6 @@
-'use strict';
-const path = require('path');
-const {app, BrowserWindow} = require('electron');
-const contextMenu = require('..');
+import path from 'node:path';
+import {app, BrowserWindow} from 'electron';
+import contextMenu from '../index.js';
contextMenu({
labels: {
@@ -12,42 +11,46 @@ contextMenu({
saveImageAs: 'Configured Save Image As…',
copyLink: 'Configured Copy Link',
saveLinkAs: 'Configured Save Link As…',
- inspect: 'Configured Inspect'
+ inspect: 'Configured Inspect',
},
prepend: () => [
{
- label: 'Unicorn'
+ label: 'Unicorn',
},
{
- type: 'separator'
+ type: 'separator',
},
{
- type: 'separator'
+ type: 'separator',
},
{
label: 'Invisible',
- visible: false
+ visible: false,
},
{
- type: 'separator'
+ type: 'separator',
},
{
- type: 'separator'
- }
+ type: 'separator',
+ },
],
- append: () => {},
+ append() {},
+ showSelectAll: true,
showCopyImageAddress: true,
showSaveImageAs: true,
+ showCopyVideoAddress: true,
+ showSaveVideoAs: true,
showInspectElement: false,
- showSaveLinkAs: true
+ showSaveLinkAs: true,
});
+// eslint-disable-next-line unicorn/prefer-top-level-await
(async () => {
await app.whenReady();
await (new BrowserWindow({
webPreferences: {
- spellcheck: true
- }
- })).loadFile(path.join(__dirname, 'fixture.html'));
+ spellcheck: true,
+ },
+ })).loadFile(path.join(import.meta.dirname, 'fixture.html'));
})();
diff --git a/fixtures/flower.mp4 b/fixtures/flower.mp4
new file mode 100644
index 0000000..ab9982a
Binary files /dev/null and b/fixtures/flower.mp4 differ
diff --git a/index.d.ts b/index.d.ts
index cdacb66..657d377 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -1,301 +1,364 @@
import {
- BrowserWindow,
- BrowserView,
- ContextMenuParams,
- MenuItemConstructorOptions,
- Event as ElectronEvent,
- WebContents
+ type BrowserWindow,
+ type BrowserView,
+ type ContextMenuParams,
+ type MenuItemConstructorOptions,
+ type Event as ElectronEvent,
+ type WebContents,
+ type WebContentsView,
} from 'electron';
-declare namespace contextMenu {
- interface Labels {
- /**
- @default 'Learn Spelling'
- */
- readonly learnSpelling?: string;
-
- /**
- The placeholder `{selection}` will be replaced by the currently selected text.
- @default 'Look Up “{selection}”'
- */
- readonly lookUpSelection?: string;
-
- /**
- @default 'Search with Google'
- */
- readonly searchWithGoogle?: string;
-
- /**
- @default 'Cut'
- */
- readonly cut?: string;
-
- /**
- @default 'Copy'
- */
- readonly copy?: string;
-
- /**
- @default 'Paste'
- */
- readonly paste?: string;
-
- /**
- @default 'Save Image'
- */
- readonly saveImage?: string;
-
- /**
- @default 'Save Image As…'
- */
- readonly saveImageAs?: string;
-
- /**
- @default 'Copy Link'
- */
- readonly copyLink?: string;
-
- /**
- @default 'Save Link As…'
- */
- readonly saveLinkAs?: string;
-
- /**
- @default 'Copy Image'
- */
- readonly copyImage?: string;
-
- /**
- @default 'Copy Image Address'
- */
- readonly copyImageAddress?: string;
-
- /**
- @default 'Inspect Element'
- */
- readonly inspect?: string;
-
- /**
- @default 'Services'
- */
- readonly services?: string;
- }
-
- interface ActionOptions {
- /**
- Apply a transformation to the content of the action.
-
- If you use this on `cut`, `copy`, or `paste`, they will convert rich text to plain text.
- */
- readonly transform?: (content: string) => string;
- }
-
- interface Actions {
- readonly separator: () => MenuItemConstructorOptions;
- readonly learnSpelling: (options: ActionOptions) => MenuItemConstructorOptions;
- readonly lookUpSelection: (options: ActionOptions) => MenuItemConstructorOptions;
- readonly searchWithGoogle: (options: ActionOptions) => MenuItemConstructorOptions;
- readonly cut: (options: ActionOptions) => MenuItemConstructorOptions;
- readonly copy: (options: ActionOptions) => MenuItemConstructorOptions;
- readonly paste: (options: ActionOptions) => MenuItemConstructorOptions;
- readonly saveImage: (options: ActionOptions) => MenuItemConstructorOptions;
- readonly saveImageAs: (options: ActionOptions) => MenuItemConstructorOptions;
- readonly copyLink: (options: ActionOptions) => MenuItemConstructorOptions;
- readonly copyImage: (options: ActionOptions) => MenuItemConstructorOptions;
- readonly copyImageAddress: (options: ActionOptions) => MenuItemConstructorOptions;
- readonly inspect: () => MenuItemConstructorOptions;
- readonly services: () => MenuItemConstructorOptions;
- }
-
- interface Options {
- /**
- Window or WebView to add the context menu to.
- When not specified, the context menu will be added to all existing and new windows.
- */
- readonly window?: BrowserWindow | BrowserView | Electron.WebviewTag | WebContents;
-
- /**
- Should return an array of [menu items](https://electronjs.org/docs/api/menu-item) to be prepended to the context menu.
-
- `MenuItem` labels may contain the placeholder `{selection}` which will be replaced by the currently selected text as described in `options.labels`.
- */
- readonly prepend?: (
- defaultActions: Actions,
- parameters: ContextMenuParams,
- browserWindow: BrowserWindow | BrowserView | Electron.WebviewTag | WebContents,
- event: ElectronEvent
- ) => MenuItemConstructorOptions[];
-
- /**
- Should return an array of [menu items](https://electronjs.org/docs/api/menu-item) to be appended to the context menu.
-
- `MenuItem` labels may contain the placeholder `{selection}` which will be replaced by the currently selected text as described in `options.labels`.
- */
- readonly append?: (
- defaultActions: Actions,
- parameters: ContextMenuParams,
- browserWindow: BrowserWindow | BrowserView | Electron.WebviewTag | WebContents,
- event: ElectronEvent
- ) => MenuItemConstructorOptions[];
-
- /**
- Show the `Learn Spelling {selection}` menu item when right-clicking text.
-
- Even if `true`, the `spellcheck` preference in browser window must still be enabled. It will also only show when right-clicking misspelled words.
-
- @default true
- */
- readonly showLearnSpelling?: boolean;
-
- /**
- Show the `Look Up {selection}` menu item when right-clicking text.
-
- @default true
- */
- readonly showLookUpSelection?: boolean;
+export type Labels = {
+ /**
+ @default 'Learn Spelling'
+ */
+ readonly learnSpelling?: string;
+
+ /**
+ The placeholder `{selection}` will be replaced by the currently selected text.
+ @default 'Look Up “{selection}”'
+ */
+ readonly lookUpSelection?: string;
+
+ /**
+ @default 'Search with Google'
+ */
+ readonly searchWithGoogle?: string;
+
+ /**
+ @default 'Cut'
+ */
+ readonly cut?: string;
+
+ /**
+ @default 'Copy'
+ */
+ readonly copy?: string;
+
+ /**
+ @default 'Paste'
+ */
+ readonly paste?: string;
+
+ /**
+ @default 'Select All'
+ */
+ readonly selectAll?: string;
+
+ /**
+ @default 'Save Image'
+ */
+ readonly saveImage?: string;
+
+ /**
+ @default 'Save Image As…'
+ */
+ readonly saveImageAs?: string;
+
+ /**
+ @default 'Save Video'
+ */
+ readonly saveVideo?: string;
+
+ /**
+ @default 'Save Video As…'
+ */
+ readonly saveVideoAs?: string;
+
+ /**
+ @default 'Copy Link'
+ */
+ readonly copyLink?: string;
+
+ /**
+ @default 'Save Link As…'
+ */
+ readonly saveLinkAs?: string;
+
+ /**
+ @default 'Copy Image'
+ */
+ readonly copyImage?: string;
+
+ /**
+ @default 'Copy Image Address'
+ */
+ readonly copyImageAddress?: string;
+
+ /**
+ @default 'Copy Video Address'
+ */
+ readonly copyVideoAddress?: string;
+
+ /**
+ @default 'Inspect Element'
+ */
+ readonly inspect?: string;
+
+ /**
+ @default 'Services'
+ */
+ readonly services?: string;
+};
+
+export type ActionOptions = {
+ /**
+ Apply a transformation to the content of the action.
+
+ If you use this on `cut`, `copy`, or `paste`, they will convert rich text to plain text.
+ */
+ readonly transform?: (content: string) => string;
+};
+
+export type Actions = {
+ readonly separator: () => MenuItemConstructorOptions;
+ readonly learnSpelling: (options: ActionOptions) => MenuItemConstructorOptions;
+ readonly lookUpSelection: (options: ActionOptions) => MenuItemConstructorOptions;
+ readonly searchWithGoogle: (options: ActionOptions) => MenuItemConstructorOptions;
+ readonly cut: (options: ActionOptions) => MenuItemConstructorOptions;
+ readonly copy: (options: ActionOptions) => MenuItemConstructorOptions;
+ readonly paste: (options: ActionOptions) => MenuItemConstructorOptions;
+ readonly selectAll: (options: ActionOptions) => MenuItemConstructorOptions;
+ readonly saveImage: (options: ActionOptions) => MenuItemConstructorOptions;
+ readonly saveImageAs: (options: ActionOptions) => MenuItemConstructorOptions;
+ readonly saveVideo: (options: ActionOptions) => MenuItemConstructorOptions;
+ readonly saveVideoAs: (options: ActionOptions) => MenuItemConstructorOptions;
+ readonly copyLink: (options: ActionOptions) => MenuItemConstructorOptions;
+ readonly copyImage: (options: ActionOptions) => MenuItemConstructorOptions;
+ readonly copyImageAddress: (options: ActionOptions) => MenuItemConstructorOptions;
+ readonly copyVideoAddress: (options: ActionOptions) => MenuItemConstructorOptions;
+ readonly inspect: () => MenuItemConstructorOptions;
+ readonly services: () => MenuItemConstructorOptions;
+};
+
+export type Options = {
+ /**
+ Window or WebView to add the context menu to.
+ When not specified, the context menu will be added to all existing and new windows.
+ */
+ readonly window?: BrowserWindow | BrowserView | Electron.WebviewTag | WebContents | WebContentsView;
+
+ /**
+ Should return an array of [menu items](https://electronjs.org/docs/api/menu-item) to be prepended to the context menu.
+
+ `MenuItem` labels may contain the placeholder `{selection}` which will be replaced by the currently selected text as described in `options.labels`.
+ */
+ readonly prepend?: (
+ defaultActions: Actions,
+ parameters: ContextMenuParams,
+ browserWindow: BrowserWindow | BrowserView | Electron.WebviewTag | WebContents,
+ event: ElectronEvent
+ ) => MenuItemConstructorOptions[];
+
+ /**
+ Should return an array of [menu items](https://electronjs.org/docs/api/menu-item) to be appended to the context menu.
+
+ `MenuItem` labels may contain the placeholder `{selection}` which will be replaced by the currently selected text as described in `options.labels`.
+ */
+ readonly append?: (
+ defaultActions: Actions,
+ parameters: ContextMenuParams,
+ browserWindow: BrowserWindow | BrowserView | Electron.WebviewTag | WebContents,
+ event: ElectronEvent
+ ) => MenuItemConstructorOptions[];
+
+ /**
+ Show the `Learn Spelling {selection}` menu item when right-clicking text.
+
+ Even if `true`, the `spellcheck` preference in browser window must still be enabled. It will also only show when right-clicking misspelled words.
+
+ @default true
+ */
+ readonly showLearnSpelling?: boolean;
+
+ /**
+ Show the `Look Up {selection}` menu item when right-clicking text.
+
+ @default true
+ */
+ readonly showLookUpSelection?: boolean;
+
+ /**
+ Show the `Search with Google` menu item when right-clicking text.
+
+ @default true
+ */
+ readonly showSearchWithGoogle?: boolean;
+
+ /**
+ Show the `Select All` menu item when right-clicking in a window.
+
+ Default: `false` on macOS, `true` on Windows and Linux
+ */
+ readonly showSelectAll?: boolean;
+
+ /**
+ Show the `Copy Image` menu item when right-clicking on an image.
+
+ @default true
+ */
+ readonly showCopyImage?: boolean;
+
+ /**
+ Show the `Copy Image Address` menu item when right-clicking on an image.
+
+ @default false
+ */
+ readonly showCopyImageAddress?: boolean;
+
+ /**
+ Show the `Save Image` menu item when right-clicking on an image.
+
+ @default false
+ */
+ readonly showSaveImage?: boolean;
+
+ /**
+ Show the `Save Image As…` menu item when right-clicking on an image.
+
+ @default false
+ */
+ readonly showSaveImageAs?: boolean;
- /**
- Show the `Search with Google` menu item when right-clicking text.
+ /**
+ Show the `Copy Video Address` menu item when right-clicking on a video.
- @default true
- */
- readonly showSearchWithGoogle?: boolean;
+ @default false
+ */
+ readonly showCopyVideoAddress?: boolean;
- /**
- Show the `Copy Image` menu item when right-clicking on an image.
+ /**
+ Show the `Save Video` menu item when right-clicking on a video.
- @default true
- */
- readonly showCopyImage?: boolean;
+ @default false
+ */
+ readonly showSaveVideo?: boolean;
- /**
- Show the `Copy Image Address` menu item when right-clicking on an image.
+ /**
+ Show the `Save Video As…` menu item when right-clicking on a video.
- @default false
- */
- readonly showCopyImageAddress?: boolean;
+ @default false
+ */
+ readonly showSaveVideoAs?: boolean;
- /**
- Show the `Save Image` menu item when right-clicking on an image.
+ /**
+ Show the `Copy Link` menu item when right-clicking on a link.
- @default false
- */
- readonly showSaveImage?: boolean;
+ @default true
+ */
+ readonly showCopyLink?: boolean;
- /**
- Show the `Save Image As…` menu item when right-clicking on an image.
+ /**
+ Show the `Save Link As…` menu item when right-clicking on a link.
- @default false
- */
- readonly showSaveImageAs?: boolean;
+ @default false
+ */
+ readonly showSaveLinkAs?: boolean;
- /**
- Show the `Save Link As…` menu item when right-clicking on a link.
+ /**
+ Force enable or disable the `Inspect Element` menu item.
- @default false
- */
- readonly showSaveLinkAs?: boolean;
+ Default: [Only in development](https://github.com/sindresorhus/electron-is-dev)
+ */
+ readonly showInspectElement?: boolean;
- /**
- Force enable or disable the `Inspect Element` menu item.
+ /**
+ Show the system `Services` submenu on macOS.
- Default: [Only in development](https://github.com/sindresorhus/electron-is-dev)
- */
- readonly showInspectElement?: boolean;
+ @default false
+ */
+ readonly showServices?: boolean;
- /**
- Show the system `Services` submenu on macOS.
+ /**
+ Override labels for the default menu items. Useful for i18n.
- @default false
- */
- readonly showServices?: boolean;
+ The placeholder `{selection}` may be used in any label, and will be replaced by the currently selected text, trimmed to a maximum of 25 characters length. This is useful when localizing the `Look Up “{selection}”` menu item, but can also be used in custom menu items, for example, to implement a `Search Google for “{selection}”` menu item. If there is no selection, the `{selection}` placeholder will be replaced by an empty string. Normally this placeholder is only useful for menu items which will only be shown when there is text selected. This can be checked using `visible: parameters.selectionText.trim().length > 0` when implementing a custom menu item.
- /**
- Override labels for the default menu items. Useful for i18n.
+ @default {}
- The placeholder `{selection}` may be used in any label, and will be replaced by the currently selected text, trimmed to a maximum of 25 characters length. This is useful when localizing the `Look Up “{selection}”` menu item, but can also be used in custom menu items, for example, to implement a `Search Google for “{selection}”` menu item. If there is no selection, the `{selection}` placeholder will be replaced by an empty string. Normally this placeholder is only useful for menu items which will only be shown when there is text selected. This can be checked using `visible: parameters.selectionText.trim().length > 0` when implementing a custom menu item.
-
- @default {}
-
- @example
- ```
- {
- labels: {
- copy: 'Configured Copy',
- saveImageAs: 'Configured Save Image As…'
- }
- }
- ```
- */
- readonly labels?: Labels;
-
- /**
- Determines whether or not to show the menu.
- Can be useful if you for example have other code presenting a context menu in some contexts.
-
- @example
- ```
- {
- // Doesn't show the menu if the element is editable
- shouldShowMenu: (event, parameters) => !parameters.isEditable
+ @example
+ ```
+ {
+ labels: {
+ copy: 'Configured Copy',
+ saveImageAs: 'Configured Save Image As…'
}
- ```
- */
- readonly shouldShowMenu?: (
- event: ElectronEvent,
- parameters: ContextMenuParams
- ) => boolean;
-
- /**
- This option lets you manually pick what menu items to include. It's meant for advanced needs. The default menu with the other options should be enough for most use-cases, and it ensures correct behavior, for example, correct order of menu items. So prefer the `append` and `prepend` option instead of `menu` whenever possible.
-
- The function passed to this option is expected to return an array of [`MenuItem` constructor options](https://electronjs.org/docs/api/menu-item/).
-
- The first argument the function receives is an array of default actions that can be used. These actions are functions that can take an object with a transform property (except for `separator` and `inspect`). The transform function will be passed the content of the action and can modify it if needed. If you use `transform` on `cut`, `copy`, or `paste`, they will convert rich text to plain text.
- The second argument is [this `parameters` object](https://electronjs.org/docs/api/web-contents/#event-context-menu).
- The third argument is the [BrowserWindow](https://electronjs.org/docs/api/browser-window/) the context menu was requested for.
- The fourth argument is an Array of menu items for dictionary suggestions. This should be used if you wish to implement spellcheck in your custom menu.
- The last argument is the event object passed to the `context-menu` event in web contents.
-
- Even though you include an action, it will still only be shown/enabled when appropriate. For example, the `saveImage` action is only shown when right-clicking an image.
-
- `MenuItem` labels may contain the placeholder `{selection}` which will be replaced by the currently selected text as described in `options.labels`.
-
- The following options are ignored when `menu` is used:
-
- - `showLearnSpelling`
- - `showLookUpSelection`
- - `showSearchWithGoogle`
- - `showCopyImage`
- - `showCopyImageAddress`
- - `showSaveImageAs`
- - `showSaveLinkAs`
- - `showInspectElement`
- - `showServices`
-
- To get spellchecking, “Correct Automatically”, and “Learn Spelling” in the menu, please enable the `spellcheck` preference in browser window: `new BrowserWindow({webPreferences: {spellcheck: true}})`
-
- @default [...dictionarySuggestions, defaultActions.separator(), defaultActions.separator(), defaultActions.learnSpelling(), defaultActions.separator(), defaultActions.lookUpSelection(), defaultActions.separator(),defaultActions.searchWithGoogle(), defaultActions.cut(), defaultActions.copy(), defaultActions.paste(), defaultActions.separator(), defaultActions.saveImage(), defaultActions.saveImageAs(), defaultActions.copyLink(), defaultActions.copyImage(), defaultActions.copyImageAddress(), defaultActions.separator(), defaultActions.copyLink(), defaultActions.saveLinkAs(), defaultActions.separator(), defaultActions.inspect()]
- */
- readonly menu?: (
- defaultActions: Actions,
- parameters: ContextMenuParams,
- browserWindow: BrowserWindow | BrowserView | Electron.WebviewTag | WebContents,
- dictionarySuggestions: MenuItemConstructorOptions[],
- event: ElectronEvent
- ) => MenuItemConstructorOptions[];
-
- /**
- Called when the context menu is shown.
- */
- readonly onShow?: (event: ElectronEvent) => void;
-
- /**
- Called when the context menu is closed.
- */
- readonly onClose?: (event: ElectronEvent) => void;
}
-}
+ ```
+ */
+ readonly labels?: Labels;
+
+ /**
+ Determines whether or not to show the menu.
+ Can be useful if you for example have other code presenting a context menu in some contexts.
+
+ @example
+ ```
+ {
+ // Doesn't show the menu if the element is editable
+ shouldShowMenu: (event, parameters) => !parameters.isEditable
+ }
+ ```
+ */
+ readonly shouldShowMenu?: (
+ event: ElectronEvent,
+ parameters: ContextMenuParams
+ ) => boolean;
+
+ /**
+ This option lets you manually pick what menu items to include. It's meant for advanced needs. The default menu with the other options should be enough for most use-cases, and it ensures correct behavior, for example, correct order of menu items. So prefer the `append` and `prepend` option instead of `menu` whenever possible.
+
+ The function passed to this option is expected to return an array of [`MenuItem` constructor options](https://electronjs.org/docs/api/menu-item/).
+
+ The first argument the function receives is an array of default actions that can be used. These actions are functions that can take an object with a transform property (except for `separator` and `inspect`). The transform function will be passed the content of the action and can modify it if needed. If you use `transform` on `cut`, `copy`, or `paste`, they will convert rich text to plain text.
+ The second argument is [this `parameters` object](https://electronjs.org/docs/api/web-contents/#event-context-menu).
+ The third argument is the [BrowserWindow](https://electronjs.org/docs/api/browser-window/) the context menu was requested for.
+ The fourth argument is an Array of menu items for dictionary suggestions. This should be used if you wish to implement spellcheck in your custom menu.
+ The last argument is the event object passed to the `context-menu` event in web contents.
+
+ Even though you include an action, it will still only be shown/enabled when appropriate. For example, the `saveImage` action is only shown when right-clicking an image.
+
+ `MenuItem` labels may contain the placeholder `{selection}` which will be replaced by the currently selected text as described in `options.labels`.
+
+ The following options are ignored when `menu` is used:
+
+ - `showLearnSpelling`
+ - `showLookUpSelection`
+ - `showSearchWithGoogle`
+ - `showSelectAll`
+ - `showCopyImage`
+ - `showCopyImageAddress`
+ - `showSaveImageAs`
+ - `showCopyVideoAddress`
+ - `showSaveVideo`
+ - `showSaveVideoAs`
+ - `showCopyLink`
+ - `showSaveLinkAs`
+ - `showInspectElement`
+ - `showServices`
+
+ To get spellchecking, “Correct Automatically”, and “Learn Spelling” in the menu, please enable the `spellcheck` preference in browser window: `new BrowserWindow({webPreferences: {spellcheck: true}})`
+
+ @default [...dictionarySuggestions, defaultActions.separator(), defaultActions.separator(), defaultActions.learnSpelling(), defaultActions.separator(), defaultActions.lookUpSelection(), defaultActions.separator(),defaultActions.searchWithGoogle(), defaultActions.cut(), defaultActions.copy(), defaultActions.paste(), defaultActions.selectAll(), defaultActions.separator(), defaultActions.saveImage(), defaultActions.saveImageAs(), defaultActions.saveVideo(), defaultActions.saveVideoAs(), defaultActions.copyLink(), defaultActions.copyImage(), defaultActions.copyImageAddress(), defaultActions.separator(), defaultActions.copyLink(), defaultActions.saveLinkAs(), defaultActions.separator(), defaultActions.inspect()]
+ */
+ readonly menu?: (
+ defaultActions: Actions,
+ parameters: ContextMenuParams,
+ browserWindow: BrowserWindow | BrowserView | Electron.WebviewTag | WebContents,
+ dictionarySuggestions: MenuItemConstructorOptions[],
+ event: ElectronEvent
+ ) => MenuItemConstructorOptions[];
+
+ /**
+ Called when the context menu is shown.
+ */
+ readonly onShow?: (event: ElectronEvent) => void;
+
+ /**
+ Called when the context menu is closed.
+ */
+ readonly onClose?: (event: ElectronEvent) => void;
+};
/**
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.
@@ -304,8 +367,8 @@ You can use this module directly in both the main and renderer process.
@example
```
-const {app, BrowserWindow} = require('electron');
-const contextMenu = require('electron-context-menu');
+import {app, BrowserWindow} from 'electron';
+import contextMenu from 'electron-context-menu';
contextMenu({
showSaveImageAs: true
@@ -326,7 +389,7 @@ let mainWindow;
@example
```
import {app, BrowserWindow} from 'electron';
-import contextMenu = require('electron-context-menu');
+import contextMenu from 'electron-context-menu';
contextMenu({
prepend: (defaultActions, parameters, browserWindow) => [
@@ -334,6 +397,14 @@ contextMenu({
label: 'Rainbow',
// Only show it when right-clicking images
visible: parameters.mediaType === 'image'
+ },
+ {
+ label: 'Search Google for “{selection}”',
+ // Only show it when right-clicking text
+ visible: parameters.selectionText.trim().length > 0,
+ click: () => {
+ shell.openExternal(`https://google.com/search?q=${encodeURIComponent(parameters.selectionText)}`);
+ }
}
]
});
@@ -347,7 +418,7 @@ let mainWindow;
spellcheck: true
}
});
-});
+})();
```
The return value of `contextMenu()` is a function that disposes of the created event listeners:
@@ -358,8 +429,5 @@ const dispose = contextMenu();
dispose();
```
-
*/
-declare function contextMenu(options?: contextMenu.Options): () => void; // eslint-disable-line no-redeclare
-
-export = contextMenu;
+export default function contextMenu(options?: Options): () => void;
diff --git a/index.js b/index.js
index 407c0b4..8ec2624 100644
--- a/index.js
+++ b/index.js
@@ -1,19 +1,17 @@
-'use strict';
-const electron = require('electron');
-const cliTruncate = require('cli-truncate');
-const {download} = require('electron-dl');
-const isDev = require('electron-is-dev');
-
-const webContents = win => win.webContents || (win.id && win);
-
-const decorateMenuItem = menuItem => {
- return (options = {}) => {
- if (options.transform && !options.click) {
- menuItem.transform = options.transform;
- }
+import process from 'node:process';
+import electron from 'electron';
+import cliTruncate from 'cli-truncate';
+import {download} from 'electron-dl';
+import isDev from 'electron-is-dev';
- return menuItem;
- };
+const webContents = win => win.webContents ?? (win.id && win);
+
+const decorateMenuItem = menuItem => (options = {}) => {
+ if (options.transform && !options.click) {
+ menuItem.transform = options.transform;
+ }
+
+ return menuItem;
};
const removeUnusedMenuItems = menuTemplate => {
@@ -29,14 +27,14 @@ const removeUnusedMenuItems = menuTemplate => {
};
const create = (win, options) => {
- const handleContextMenu = (event, props) => {
- if (typeof options.shouldShowMenu === 'function' && options.shouldShowMenu(event, props) === false) {
+ const handleContextMenu = (event, properties) => {
+ if (typeof options.shouldShowMenu === 'function' && options.shouldShowMenu(event, properties) === false) {
return;
}
- const {editFlags} = props;
- const hasText = props.selectionText.trim().length > 0;
- const isLink = Boolean(props.linkURL);
+ const {editFlags} = properties;
+ const hasText = properties.selectionText.length > 0;
+ const isLink = Boolean(properties.linkURL);
const can = type => editFlags[`can${type}`] && hasText;
const defaultActions = {
@@ -44,11 +42,11 @@ const create = (win, options) => {
learnSpelling: decorateMenuItem({
id: 'learnSpelling',
label: '&Learn Spelling',
- visible: Boolean(props.isEditable && hasText && props.misspelledWord),
+ visible: Boolean(properties.isEditable && hasText && properties.misspelledWord),
click() {
const target = webContents(win);
- target.session.addWordToSpellCheckerDictionary(props.misspelledWord);
- }
+ target.session.addWordToSpellCheckerDictionary(properties.misspelledWord);
+ },
}),
lookUpSelection: decorateMenuItem({
id: 'lookUpSelection',
@@ -58,7 +56,7 @@ const create = (win, options) => {
if (process.platform === 'darwin') {
webContents(win).showDefinitionForSelection();
}
- }
+ },
}),
searchWithGoogle: decorateMenuItem({
id: 'searchWithGoogle',
@@ -66,164 +64,203 @@ const create = (win, options) => {
visible: hasText,
click() {
const url = new URL('https://www.google.com/search');
- url.searchParams.set('q', props.selectionText);
+ url.searchParams.set('q', properties.selectionText);
electron.shell.openExternal(url.toString());
- }
+ },
}),
cut: decorateMenuItem({
id: 'cut',
label: 'Cu&t',
enabled: can('Cut'),
- visible: props.isEditable,
+ visible: properties.isEditable,
click(menuItem) {
const target = webContents(win);
if (!menuItem.transform && target) {
target.cut();
} else {
- props.selectionText = menuItem.transform ? menuItem.transform(props.selectionText) : props.selectionText;
- electron.clipboard.writeText(props.selectionText);
+ properties.selectionText = menuItem.transform ? menuItem.transform(properties.selectionText) : properties.selectionText;
+ electron.clipboard.writeText(properties.selectionText);
}
- }
+ },
}),
copy: decorateMenuItem({
id: 'copy',
label: '&Copy',
enabled: can('Copy'),
- visible: props.isEditable || hasText,
+ visible: properties.isEditable || hasText,
click(menuItem) {
const target = webContents(win);
if (!menuItem.transform && target) {
target.copy();
} else {
- props.selectionText = menuItem.transform ? menuItem.transform(props.selectionText) : props.selectionText;
- electron.clipboard.writeText(props.selectionText);
+ properties.selectionText = menuItem.transform ? menuItem.transform(properties.selectionText) : properties.selectionText;
+ electron.clipboard.writeText(properties.selectionText);
}
- }
+ },
}),
paste: decorateMenuItem({
id: 'paste',
label: '&Paste',
enabled: editFlags.canPaste,
- visible: props.isEditable,
+ visible: properties.isEditable,
click(menuItem) {
const target = webContents(win);
if (menuItem.transform) {
- let clipboardContent = electron.clipboard.readText(props.selectionText);
+ let clipboardContent = electron.clipboard.readText(properties.selectionText);
clipboardContent = menuItem.transform ? menuItem.transform(clipboardContent) : clipboardContent;
target.insertText(clipboardContent);
} else {
target.paste();
}
- }
+ },
+ }),
+ selectAll: decorateMenuItem({
+ id: 'selectAll',
+ label: 'Select &All',
+ click() {
+ webContents(win).selectAll();
+ },
}),
saveImage: decorateMenuItem({
id: 'saveImage',
label: 'Save I&mage',
- visible: props.mediaType === 'image',
+ visible: properties.mediaType === 'image',
click(menuItem) {
- props.srcURL = menuItem.transform ? menuItem.transform(props.srcURL) : props.srcURL;
- download(win, props.srcURL);
- }
+ properties.srcURL = menuItem.transform ? menuItem.transform(properties.srcURL) : properties.srcURL;
+ download(win, properties.srcURL);
+ },
}),
saveImageAs: decorateMenuItem({
id: 'saveImageAs',
label: 'Sa&ve Image As…',
- visible: props.mediaType === 'image',
+ visible: properties.mediaType === 'image',
+ click(menuItem) {
+ properties.srcURL = menuItem.transform ? menuItem.transform(properties.srcURL) : properties.srcURL;
+ download(win, properties.srcURL, {saveAs: true});
+ },
+ }),
+ saveVideo: decorateMenuItem({
+ id: 'saveVideo',
+ label: 'Save Vide&o',
+ visible: properties.mediaType === 'video',
click(menuItem) {
- props.srcURL = menuItem.transform ? menuItem.transform(props.srcURL) : props.srcURL;
- download(win, props.srcURL, {saveAs: true});
- }
+ properties.srcURL = menuItem.transform ? menuItem.transform(properties.srcURL) : properties.srcURL;
+ download(win, properties.srcURL);
+ },
+ }),
+ saveVideoAs: decorateMenuItem({
+ id: 'saveVideoAs',
+ label: 'Save Video& As…',
+ visible: properties.mediaType === 'video',
+ click(menuItem) {
+ properties.srcURL = menuItem.transform ? menuItem.transform(properties.srcURL) : properties.srcURL;
+ download(win, properties.srcURL, {saveAs: true});
+ },
}),
copyLink: decorateMenuItem({
id: 'copyLink',
label: 'Copy Lin&k',
- visible: props.linkURL.length > 0 && props.mediaType === 'none',
+ visible: properties.linkURL.length > 0 && properties.mediaType === 'none',
click(menuItem) {
- props.linkURL = menuItem.transform ? menuItem.transform(props.linkURL) : props.linkURL;
+ properties.linkURL = menuItem.transform ? menuItem.transform(properties.linkURL) : properties.linkURL;
electron.clipboard.write({
- bookmark: props.linkText,
- text: props.linkURL
+ bookmark: properties.linkText,
+ text: properties.linkURL,
});
- }
+ },
}),
saveLinkAs: decorateMenuItem({
id: 'saveLinkAs',
label: 'Save Link As…',
- visible: props.linkURL.length > 0 && props.mediaType === 'none',
+ visible: properties.linkURL.length > 0 && properties.mediaType === 'none',
click(menuItem) {
- props.linkURL = menuItem.transform ? menuItem.transform(props.linkURL) : props.linkURL;
- download(win, props.linkURL, {saveAs: true});
- }
+ properties.linkURL = menuItem.transform ? menuItem.transform(properties.linkURL) : properties.linkURL;
+ download(win, properties.linkURL, {saveAs: true});
+ },
}),
copyImage: decorateMenuItem({
id: 'copyImage',
label: 'Cop&y Image',
- visible: props.mediaType === 'image',
+ visible: properties.mediaType === 'image',
click() {
- webContents(win).copyImageAt(props.x, props.y);
- }
+ webContents(win).copyImageAt(properties.x, properties.y);
+ },
}),
copyImageAddress: decorateMenuItem({
id: 'copyImageAddress',
label: 'C&opy Image Address',
- visible: props.mediaType === 'image',
+ visible: properties.mediaType === 'image',
click(menuItem) {
- props.srcURL = menuItem.transform ? menuItem.transform(props.srcURL) : props.srcURL;
+ properties.srcURL = menuItem.transform ? menuItem.transform(properties.srcURL) : properties.srcURL;
electron.clipboard.write({
- bookmark: props.srcURL,
- text: props.srcURL
+ bookmark: properties.srcURL,
+ text: properties.srcURL,
});
- }
+ },
+ }),
+ copyVideoAddress: decorateMenuItem({
+ id: 'copyVideoAddress',
+ label: 'Copy Video Ad&dress',
+ visible: properties.mediaType === 'video',
+ click(menuItem) {
+ properties.srcURL = menuItem.transform ? menuItem.transform(properties.srcURL) : properties.srcURL;
+
+ electron.clipboard.write({
+ bookmark: properties.srcURL,
+ text: properties.srcURL,
+ });
+ },
}),
inspect: () => ({
id: 'inspect',
label: 'I&nspect Element',
click() {
- win.inspectElement(props.x, props.y);
+ webContents(win).inspectElement(properties.x, properties.y);
if (webContents(win).isDevToolsOpened()) {
webContents(win).devToolsWebContents.focus();
}
- }
+ },
}),
services: () => ({
id: 'services',
label: 'Services',
role: 'services',
- visible: process.platform === 'darwin' && (props.isEditable || hasText)
- })
+ visible: process.platform === 'darwin' && (properties.isEditable || hasText),
+ }),
};
const shouldShowInspectElement = typeof options.showInspectElement === 'boolean' ? options.showInspectElement : isDev;
+ const shouldShowSelectAll = options.showSelectAll || (options.showSelectAll !== false && process.platform !== 'darwin');
function word(suggestion) {
return {
id: 'dictionarySuggestions',
label: suggestion,
- visible: Boolean(props.isEditable && hasText && props.misspelledWord),
+ visible: Boolean(properties.isEditable && hasText && properties.misspelledWord),
click(menuItem) {
const target = webContents(win);
target.replaceMisspelling(menuItem.label);
- }
+ },
};
}
let dictionarySuggestions = [];
- if (hasText && props.misspelledWord && props.dictionarySuggestions.length > 0) {
- dictionarySuggestions = props.dictionarySuggestions.map(suggestion => word(suggestion));
+ if (hasText && properties.misspelledWord && properties.dictionarySuggestions.length > 0) {
+ dictionarySuggestions = properties.dictionarySuggestions.map(suggestion => word(suggestion));
} else {
dictionarySuggestions.push(
{
id: 'dictionarySuggestions',
label: 'No Guesses Found',
- visible: Boolean(hasText && props.misspelledWord),
- enabled: false
- }
+ visible: Boolean(hasText && properties.misspelledWord),
+ enabled: false,
+ },
);
}
@@ -240,26 +277,30 @@ const create = (win, options) => {
defaultActions.cut(),
defaultActions.copy(),
defaultActions.paste(),
+ shouldShowSelectAll && defaultActions.selectAll(),
defaultActions.separator(),
options.showSaveImage && defaultActions.saveImage(),
options.showSaveImageAs && defaultActions.saveImageAs(),
options.showCopyImage !== false && defaultActions.copyImage(),
options.showCopyImageAddress && defaultActions.copyImageAddress(),
+ options.showSaveVideo && defaultActions.saveVideo(),
+ options.showSaveVideoAs && defaultActions.saveVideoAs(),
+ options.showCopyVideoAddress && defaultActions.copyVideoAddress(),
defaultActions.separator(),
- defaultActions.copyLink(),
+ options.showCopyLink !== false && defaultActions.copyLink(),
options.showSaveLinkAs && defaultActions.saveLinkAs(),
defaultActions.separator(),
shouldShowInspectElement && defaultActions.inspect(),
options.showServices && defaultActions.services(),
- defaultActions.separator()
+ defaultActions.separator(),
];
if (options.menu) {
- menuTemplate = options.menu(defaultActions, props, win, dictionarySuggestions, event);
+ menuTemplate = options.menu(defaultActions, properties, win, dictionarySuggestions, event);
}
if (options.prepend) {
- const result = options.prepend(defaultActions, props, win, event);
+ const result = options.prepend(defaultActions, properties, win, event);
if (Array.isArray(result)) {
menuTemplate.unshift(...result);
@@ -267,7 +308,7 @@ const create = (win, options) => {
}
if (options.append) {
- const result = options.append(defaultActions, props, win, event);
+ const result = options.append(defaultActions, properties, win, event);
if (Array.isArray(result)) {
menuTemplate.push(...result);
@@ -286,8 +327,8 @@ const create = (win, options) => {
// Replace placeholders in menu item labels
if (typeof menuItem.label === 'string' && menuItem.label.includes('{selection}')) {
- const selectionString = typeof props.selectionText === 'string' ? props.selectionText.trim() : '';
- menuItem.label = menuItem.label.replace('{selection}', cliTruncate(selectionString, 25).replace(/&/g, '&&'));
+ const selectionString = typeof properties.selectionText === 'string' ? properties.selectionText.trim() : '';
+ menuItem.label = menuItem.label.replace('{selection}', cliTruncate(selectionString, 25).replaceAll('&', '&&'));
}
}
@@ -309,7 +350,7 @@ const create = (win, options) => {
webContents(win).on('context-menu', handleContextMenu);
return () => {
- if (win.isDestroyed()) {
+ if (win?.isDestroyed?.()) {
return;
}
@@ -317,7 +358,7 @@ const create = (win, options) => {
};
};
-module.exports = (options = {}) => {
+export default function contextMenu(options = {}) {
if (process.type === 'renderer') {
throw new Error('Cannot use electron-context-menu in the renderer process!');
}
@@ -332,21 +373,11 @@ module.exports = (options = {}) => {
const disposeMenu = create(win, options);
- disposables.push(disposeMenu);
- const removeDisposable = () => {
- const index = disposables.indexOf(disposeMenu);
- if (index !== -1) {
- disposables.splice(index, 1);
- }
+ const disposable = () => {
+ disposeMenu();
};
- if (typeof win.once !== 'undefined') { // Support for BrowserView
- win.once('closed', removeDisposable);
- }
-
- disposables.push(() => {
- win.off('closed', removeDisposable);
- });
+ webContents(win).once('destroyed', disposable);
};
const dispose = () => {
@@ -367,7 +398,7 @@ module.exports = (options = {}) => {
init(win);
};
- const listenerFunction = win.addEventListener || win.addListener;
+ const listenerFunction = win.addEventListener ?? win.addListener;
listenerFunction('dom-ready', onDomReady, {once: true});
disposables.push(() => {
@@ -396,4 +427,4 @@ module.exports = (options = {}) => {
});
return dispose;
-};
+}
diff --git a/index.test-d.ts b/index.test-d.ts
deleted file mode 100644
index 82fcd0a..0000000
--- a/index.test-d.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import {expectType} from 'tsd';
-import {app} from 'electron';
-import contextMenu = require('.');
-
-expectType<() => void>(contextMenu());
-
-contextMenu({
- append: () => [
- {
- label: 'Unicorn',
- enabled: false
- }
- ]
-});
-
-app.on('web-contents-created', (event, webContents) => {
- contextMenu({
- prepend: (defaultActions, parameters) => [{
- label: 'Rainbow',
- visible: parameters.mediaType === 'image'
- }],
- window: webContents
- });
-});
diff --git a/package.json b/package.json
index 1465c53..55efdc2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "electron-context-menu",
- "version": "3.3.0",
+ "version": "4.1.0",
"description": "Context menu for your Electron app",
"license": "MIT",
"repository": "sindresorhus/electron-context-menu",
@@ -10,9 +10,18 @@
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
+ "type": "module",
+ "exports": {
+ "types": "./index.d.ts",
+ "default": "./index.js"
+ },
+ "sideEffects": false,
+ "engines": {
+ "node": ">=18"
+ },
"scripts": {
"start": "electron fixtures/fixture.js",
- "test": "xo && ava && tsd",
+ "test": "xo && ava && tsc index.d.ts",
"start-fixture2": "electron fixtures/fixture-menu.js",
"start-fixture3": "electron fixtures/fixture-toggle.js"
},
@@ -40,29 +49,21 @@
"dictionary"
],
"dependencies": {
- "cli-truncate": "^2.1.0",
- "electron-dl": "^3.2.1",
- "electron-is-dev": "^2.0.0"
+ "cli-truncate": "^4.0.0",
+ "electron-dl": "^4.0.0",
+ "electron-is-dev": "^3.0.1"
},
"devDependencies": {
- "@types/node": "^15.0.1",
- "ava": "^2.4.0",
- "electron": "^12.0.6",
- "tsd": "^0.14.0",
- "xo": "^0.39.1"
+ "@types/node": "^20.12.7",
+ "ava": "^6.1.2",
+ "electron": "^30.0.1",
+ "typescript": "^5.4.5",
+ "xo": "^0.58.0"
},
"xo": {
"envs": [
"node",
"browser"
]
- },
- "tsd": {
- "compilerOptions": {
- "lib": [
- "es2019",
- "dom"
- ]
- }
}
}
diff --git a/readme.md b/readme.md
index 6e4bb7d..84995c0 100644
--- a/readme.md
+++ b/readme.md
@@ -10,17 +10,17 @@ This package can only be used in the main process.
## Install
-```
-$ npm install electron-context-menu
+```sh
+npm install electron-context-menu
```
-*Requires Electron 10 or later.*
+*Requires Electron 30 or later.*
## Usage
```js
-const {app, BrowserWindow} = require('electron');
-const contextMenu = require('electron-context-menu');
+import {app, BrowserWindow} from 'electron';
+import contextMenu from 'electron-context-menu';
contextMenu({
showSaveImageAs: true
@@ -30,19 +30,15 @@ let mainWindow;
(async () => {
await app.whenReady();
- mainWindow = new BrowserWindow({
- webPreferences: {
- spellcheck: true
- }
- });
+ mainWindow = new BrowserWindow();
})();
```
Advanced example:
```js
-const {app, BrowserWindow} = require('electron');
-const contextMenu = require('electron-context-menu');
+import {app, BrowserWindow, shell} from 'electron';
+import contextMenu from 'electron-context-menu';
contextMenu({
prepend: (defaultActions, parameters, browserWindow) => [
@@ -66,11 +62,7 @@ let mainWindow;
(async () => {
await app.whenReady();
- mainWindow = new BrowserWindow({
- webPreferences: {
- spellcheck: true
- }
- });
+ mainWindow = new BrowserWindow();
})();
```
@@ -94,7 +86,7 @@ Type: `object`
#### window
-Type: `BrowserWindow | BrowserView | WebViewTag | WebContents`
+Type: `BrowserWindow | BrowserView | WebViewTag | WebContents | WebContentsView`
Window or WebView to add the context menu to.
@@ -104,7 +96,7 @@ When not specified, the context menu will be added to all existing and new windo
Type: `Function`
-Should return an array of [MenuItem](https://electronjs.org/docs/api/menu-item/)'s to be prepended to the context menu.
+Should return an array of [`MenuItem`](https://electronjs.org/docs/api/menu-item/)'s to be prepended to the context menu.
The first argument is an array of default actions that can be used. The second argument is [this `parameters` object](https://electronjs.org/docs/api/web-contents/#event-context-menu). The third argument is the [BrowserWindow](https://electronjs.org/docs/api/browser-window/) the context menu was requested for. The fourth argument is the context menu event.
@@ -114,7 +106,7 @@ The first argument is an array of default actions that can be used. The second a
Type: `Function`
-Should return an array of [MenuItem](https://electronjs.org/docs/api/menu-item/)'s to be appended to the context menu.
+Should return an array of [`MenuItem`](https://electronjs.org/docs/api/menu-item/)'s to be appended to the context menu.
The first argument is an array of default actions that can be used. The second argument is [this `parameters` object](https://electronjs.org/docs/api/web-contents/#event-context-menu). The third argument is the [BrowserWindow](https://electronjs.org/docs/api/browser-window/) the context menu was requested for. The fourth argument is the context menu event.
@@ -127,7 +119,7 @@ Default: `true`
Show the `Learn Spelling {selection}` menu item when right-clicking text.
-Even if `true`, the `spellcheck` preference in browser window must still be enabled. It will also only show when right-clicking misspelled words.
+The spellcheck will only show when right-clicking misspelled words.
#### showLookUpSelection
@@ -143,6 +135,13 @@ Default: `true`
Show the `Search with Google` menu item when right-clicking text.
+#### showSelectAll
+
+Type: `boolean`\
+Default: `false` on macOS, `true` on Windows and Linux
+
+Show the `Select All` menu item when right-clicking in a window.
+
#### showCopyImage
Type: `boolean`\
@@ -171,6 +170,34 @@ Default: `false`
Show the `Save Image As…` menu item when right-clicking on an image.
+#### showCopyVideoAddress
+
+Type: `boolean`\
+Default: `false`
+
+Show the `Copy Video Address` menu item when right-clicking on a video.
+
+#### showSaveVideo
+
+Type: `boolean`\
+Default: `false`
+
+Show the `Save Video` menu item when right-clicking on a video.
+
+#### showSaveVideoAs
+
+Type: `boolean`\
+Default: `false`
+
+Show the `Save Video As…` menu item when right-clicking on a video.
+
+#### showCopyLink
+
+Type: `boolean`\
+Default: `true`
+
+Show the `Copy Link` menu item when right-clicking on a link.
+
#### showSaveLinkAs
Type: `boolean`\
@@ -244,18 +271,23 @@ Even though you include an action, it will still only be shown/enabled when appr
`MenuItem` labels may contain the placeholder `{selection}` which will be replaced by the currently selected text as described in [`options.labels`](#labels).
-To get spellchecking, “Correct Automatically”, and “Learn Spelling” in the menu, please enable the `spellcheck` preference in browser window: `new BrowserWindow({webPreferences: {spellcheck: true}})`
+To get spellchecking, “Correct Automatically”, and “Learn Spelling” in the menu, make sure you have not disabled the `spellcheck` option (it's `true` by default) in `BrowserWindow`.
The following options are ignored when `menu` is used:
- `showLookUpSelection`
+- `showSearchWithGoogle`
+- `showSelectAll`
- `showCopyImage`
- `showCopyImageAddress`
- `showSaveImageAs`
+- `showCopyVideoAddress`
+- `showSaveVideo`
+- `showSaveVideoAs`
+- `showCopyLink`
- `showSaveLinkAs`
- `showInspectElement`
- `showServices`
-- `showSearchWithGoogle`
Default actions:
@@ -267,10 +299,14 @@ Default actions:
- `cut`
- `copy`
- `paste`
+- `selectAll`
- `saveImage`
- `saveImageAs`
+- `saveVideo`
+- `saveVideoAs`
- `copyImage`
- `copyImageAddress`
+- `copyVideoAddress`
- `copyLink`
- `saveLinkAs`
- `inspect`
@@ -325,7 +361,7 @@ The function receives an [`Event` object](https://developer.mozilla.org/en-US/do
- [electron-util](https://github.com/sindresorhus/electron-util) - Useful utilities for developing Electron apps and modules
- [electron-debug](https://github.com/sindresorhus/electron-debug) - Adds useful debug features to your Electron app
-- [electron-store](https://github.com/sindresorhus/electron-store) - Save and load data like user preferences, app state, cache, etc
+- [electron-store](https://github.com/sindresorhus/electron-store) - Save and load data like user settings, app state, cache, etc
- [electron-reloader](https://github.com/sindresorhus/electron-reloader) - Simple auto-reloading for Electron apps during development
- [electron-serve](https://github.com/sindresorhus/electron-serve) - Static file serving for Electron apps
- [electron-unhandled](https://github.com/sindresorhus/electron-unhandled) - Catch unhandled errors and promise rejections in your Electron app
diff --git a/test.js b/test.js
index 3b9e94d..df3dbb1 100644
--- a/test.js
+++ b/test.js
@@ -1,3 +1,3 @@
import test from 'ava';
-test.todo('write tests with Spectron');
+test.todo('write proper tests');