/
index.d.ts
187 lines (155 loc) · 4.63 KB
/
index.d.ts
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/// <reference lib="dom"/>
/// <reference types="node"/>
import {
BrowserWindow,
WebviewTag,
ContextMenuParams,
MenuItem,
Event as ElectronEvent
} from 'electron';
declare namespace contextMenu {
interface Labels {
/**
@default 'Cut'
*/
readonly cut?: string;
/**
@default 'Copy'
*/
readonly copy?: string;
/**
@default 'Paste'
*/
readonly paste?: string;
/**
@default 'Save Image'
*/
readonly save?: string;
/**
@default 'Save Image As…'
*/
readonly saveImageAs?: string;
/**
@default 'Copy Link'
*/
readonly copyLink?: string;
/**
@default 'Copy Image Address'
*/
readonly copyImageAddress?: string;
/**
@default 'Inspect Element'
*/
readonly inspect?: string;
}
interface ActionOptions {
/**
Apply a transformation to the content of the action.
*/
readonly transform?: (content: string) => string;
}
interface Actions {
readonly separator: () => MenuItem;
readonly inspect: () => MenuItem;
readonly cut: (options: ActionOptions) => MenuItem;
readonly copy: (options: ActionOptions) => MenuItem;
readonly paste: (options: ActionOptions) => MenuItem;
readonly saveImage: (options: ActionOptions) => MenuItem;
readonly saveImageAs: (options: ActionOptions) => MenuItem;
readonly copyImageAddress: (options: ActionOptions) => MenuItem;
}
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 | WebviewTag;
/**
Should return an array of [menu items](https://electronjs.org/docs/api/menu-item) to be prepended to the context menu.
*/
readonly prepend?: (
defaultActions: Actions,
params: ContextMenuParams,
browserWindow: BrowserWindow | WebviewTag
) => MenuItem[];
/**
Should return an array of [menu items](https://electronjs.org/docs/api/menu-item) to override the default context menu.
@default [defaultActions.cut(), defaultActions.copy(), defaultActions.paste(), defaultActions.separator(), defaultActions.saveImage(), defaultActions.saveImageAs(), defaultActions.copyImageAddress(), defaultActions.separator(), defaultActions.copyLink(), defaultActions.separator(), defaultActions.inspect()]
*/
readonly menu?: (
defaultActions: Actions,
params: ContextMenuParams,
browserWindow: BrowserWindow | WebviewTag
) => MenuItem[];
/**
Should return an array of [menu items](https://electronjs.org/docs/api/menu-item) to be appended to the context menu.
*/
readonly append?: (
defaultActions: Actions,
param: ContextMenuParams,
browserWindow: BrowserWindow | WebviewTag
) => MenuItem[];
/**
Show the `Copy Image Address` menu item when right-clicking on an image.
@default false
*/
readonly showCopyImageAddress?: boolean;
/**
Show the `Save Image As…` menu item when right-clicking on an image.
@default false
*/
readonly showSaveImageAs?: boolean;
/**
Force enable or disable the `Inspect Element` menu item.
Default: [Only in development](https://github.com/sindresorhus/electron-is-dev)
*/
readonly showInspectElement?: boolean;
/**
Overwrite labels for the default menu items. Useful for i18n.
@default {}
*/
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, params) => !params.isEditable
```
*/
readonly shouldShowMenu?: (
event: ElectronEvent,
params: ContextMenuParams
) => boolean;
}
}
declare const contextMenu: {
/**
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.
You can use this module directly in both the main and renderer process.
@example
```
import {app, BrowserWindow} from 'electron';
import contextMenu = require('electron-context-menu');
contextMenu({
prepend: (params, browserWindow) => [{
label: 'Rainbow',
// Only show it when right-clicking images
visible: params.mediaType === 'image'
}]
});
let win;
(async () => {
await app.whenReady();
win = new BrowserWindow();
});
```
*/
(options?: contextMenu.Options): void;
// TODO: Remove this for the next major release, refactor the whole definition to:
// declare function contextMenu(options?: contextMenu.Options): void;
// export = contextMenu;
default: typeof contextMenu;
};
export = contextMenu;