Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
Closes #132
  • Loading branch information
sindresorhus committed Feb 22, 2021
1 parent 3b7fbb9 commit 4eae4e8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
20 changes: 10 additions & 10 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ declare namespace contextMenu {
*/
readonly prepend?: (
defaultActions: Actions,
params: ContextMenuParams,
parameters: ContextMenuParams,
browserWindow: BrowserWindow | BrowserView | WebviewTag | WebContents
) => MenuItemConstructorOptions[];

Expand All @@ -135,7 +135,7 @@ declare namespace contextMenu {
*/
readonly append?: (
defaultActions: Actions,
param: ContextMenuParams,
parameters: ContextMenuParams,
browserWindow: BrowserWindow | BrowserView | WebviewTag | WebContents
) => MenuItemConstructorOptions[];

Expand Down Expand Up @@ -205,7 +205,7 @@ declare namespace contextMenu {
/**
Override labels for the default menu items. Useful for i18n.
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: params.selectionText.trim().length > 0` when implementing a custom menu item.
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 {}
Expand All @@ -229,13 +229,13 @@ declare namespace contextMenu {
```
{
// Doesn't show the menu if the element is editable
shouldShowMenu: (event, params) => !params.isEditable
shouldShowMenu: (event, parameters) => !parameters.isEditable
}
```
*/
readonly shouldShowMenu?: (
event: ElectronEvent,
params: ContextMenuParams
parameters: ContextMenuParams
) => boolean;

/**
Expand All @@ -244,7 +244,7 @@ declare namespace contextMenu {
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 `params` object](https://electronjs.org/docs/api/web-contents/#event-context-menu).
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 last argument is an Array of menu items for dictionary suggestions. This should be used if you wish to implement spellcheck in your custom menu.
Expand All @@ -269,9 +269,9 @@ declare namespace contextMenu {
*/
readonly menu?: (
defaultActions: Actions,
params: ContextMenuParams,
parameters: ContextMenuParams,
browserWindow: BrowserWindow | BrowserView | WebviewTag | WebContents,
dictionarySuggestions: MenuItemConstructorOptions[] // eslint-disable-line @typescript-eslint/prefer-readonly-parameter-types
dictionarySuggestions: MenuItemConstructorOptions[]
) => MenuItemConstructorOptions[];
}
}
Expand All @@ -287,11 +287,11 @@ import {app, BrowserWindow} from 'electron';
import contextMenu = require('electron-context-menu');
contextMenu({
prepend: (defaultActions, params, browserWindow) => [
prepend: (defaultActions, parameters, browserWindow) => [
{
label: 'Rainbow',
// Only show it when right-clicking images
visible: params.mediaType === 'image'
visible: parameters.mediaType === 'image'
}
]
});
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const create = (win, options) => {
copyLink: decorateMenuItem({
id: 'copyLink',
label: 'Copy Lin&k',
visible: props.linkURL.length !== 0 && props.mediaType === 'none',
visible: props.linkURL.length > 0 && props.mediaType === 'none',
click(menuItem) {
props.linkURL = menuItem.transform ? menuItem.transform(props.linkURL) : props.linkURL;

Expand All @@ -153,7 +153,7 @@ const create = (win, options) => {
saveLinkAs: decorateMenuItem({
id: 'saveLinkAs',
label: 'Save Link As…',
visible: props.linkURL.length !== 0 && props.mediaType === 'none',
visible: props.linkURL.length > 0 && props.mediaType === 'none',
click(menuItem) {
props.linkURL = menuItem.transform ? menuItem.transform(props.linkURL) : props.linkURL;
download(win, props.linkURL, {saveAs: true});
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@
"dictionary"
],
"dependencies": {
"cli-truncate": "^2.0.0",
"electron-dl": "^3.0.0",
"electron-is-dev": "^1.0.1"
"cli-truncate": "^2.1.0",
"electron-dl": "^3.1.0",
"electron-is-dev": "^1.2.0"
},
"devDependencies": {
"@types/node": "^12.0.10",
"ava": "^2.1.0",
"electron": "^8.2.2",
"tsd": "^0.11.0",
"xo": "^0.30.0"
"@types/node": "^14.14.31",
"ava": "^2.4.0",
"electron": "^11.3.0",
"tsd": "^0.14.0",
"xo": "^0.38.1"
},
"xo": {
"envs": [
Expand Down
20 changes: 10 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ const {app, BrowserWindow} = require('electron');
const contextMenu = require('electron-context-menu');

contextMenu({
prepend: (defaultActions, params, browserWindow) => [
prepend: (defaultActions, parameters, browserWindow) => [
{
label: 'Rainbow',
// Only show it when right-clicking images
visible: params.mediaType === 'image'
visible: parameters.mediaType === 'image'
},
{
label: 'Search Google for “{selection}”',
// Only show it when right-clicking text
visible: params.selectionText.trim().length > 0,
visible: parameters.selectionText.trim().length > 0,
click: () => {
shell.openExternal(`https://google.com/search?q=${encodeURIComponent(params.selectionText)}`);
shell.openExternal(`https://google.com/search?q=${encodeURIComponent(parameters.selectionText)}`);
}
}
]
Expand Down Expand Up @@ -84,7 +84,7 @@ Type: `Function`

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 `params` 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 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.

`MenuItem` labels may contain the placeholder `{selection}` which will be replaced by the currently selected text as described in [`options.labels`](#labels).

Expand All @@ -94,7 +94,7 @@ Type: `Function`

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 `params` 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 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.

`MenuItem` labels may contain the placeholder `{selection}` which will be replaced by the currently selected text as described in [`options.labels`](#labels).

Expand Down Expand Up @@ -170,7 +170,7 @@ Default: `{}`

Override labels for the default menu items. Useful for i18n.

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: params.selectionText.trim().length > 0` when implementing a custom menu item, as shown in the usage example above.
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, as shown in the usage example above.

Format:

Expand All @@ -190,14 +190,14 @@ Type: `Function`

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.

The second argument is [this `params` object](https://electronjs.org/docs/api/web-contents#event-context-menu).
The second argument is [this `parameters` object](https://electronjs.org/docs/api/web-contents#event-context-menu).

Example:

```js
{
// Doesn't show the menu if the element is editable
shouldShowMenu: (event, params) => !params.isEditable
shouldShowMenu: (event, parameters) => !parameters.isEditable
}
```

Expand All @@ -207,7 +207,7 @@ Type: `Function`

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 [`MenuItem[]`](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 `params` 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 last 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 function passed to this option is expected to return [`MenuItem[]`](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 last argument is an Array of menu items for dictionary suggestions. This should be used if you wish to implement spellcheck in your custom menu.

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.

Expand Down

0 comments on commit 4eae4e8

Please sign in to comment.