@jupyterlab/apputils 4.0.0-alpha.19 → 4.0.0-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { MimeData } from '@lumino/coreutils';
2
- export declare type ClipboardData = string | MimeData;
2
+ export type ClipboardData = string | MimeData;
3
3
  /**
4
4
  * The clipboard interface.
5
5
  */
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * Semantic group of commands
7
7
  */
8
- export class SemanticCommand {
8
+ class SemanticCommand {
9
9
  constructor() {
10
10
  this._commands = new Array();
11
11
  }
@@ -47,4 +47,5 @@ export class SemanticCommand {
47
47
  * Default rank for semantic command
48
48
  */
49
49
  SemanticCommand.DEFAULT_RANK = 500;
50
+ export { SemanticCommand };
50
51
  //# sourceMappingURL=semanticCommand.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"semanticCommand.js","sourceRoot":"","sources":["../src/semanticCommand.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA2BH;;GAEG;AACH,MAAM,OAAO,eAAe;IAA5B;QA0CY,cAAS,GAAG,IAAI,KAAK,EAA8B,CAAC;IAChE,CAAC;IArCC;;;;OAIG;IACH,GAAG,CAAC,OAAyB;QAC3B,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;YACtD,MAAM,KAAK,CAAC,WAAW,OAAO,CAAC,EAAE,sBAAsB,CAAC,CAAC;SAC1D;QAED,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;YAClB,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI;YACrB,IAAI,EAAE,eAAe,CAAC,YAAY;YAClC,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,kBAAkB,CAAC,MAAc;;QAC/B,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS;aAC5B,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;aAChC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACb,MAAM,SAAS,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;YAClC,OAAO,SAAS,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;QAEL,MAAM,OAAO,GAAG,MAAA,QAAQ,CAAC,CAAC,CAAC,mCAAI,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;QAC5C,OAAO,OAAO,CAAC,EAAE,CAAC;IACpB,CAAC;;AAvCD;;GAEG;AACa,4BAAY,GAAG,GAAG,CAAC"}
1
+ {"version":3,"file":"semanticCommand.js","sourceRoot":"","sources":["../src/semanticCommand.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA2BH;;GAEG;AACH,MAAa,eAAe;IAA5B;QA0CY,cAAS,GAAG,IAAI,KAAK,EAA8B,CAAC;IAChE,CAAC;IArCC;;;;OAIG;IACH,GAAG,CAAC,OAAyB;QAC3B,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;YACtD,MAAM,KAAK,CAAC,WAAW,OAAO,CAAC,EAAE,sBAAsB,CAAC,CAAC;SAC1D;QAED,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;YAClB,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI;YACrB,IAAI,EAAE,eAAe,CAAC,YAAY;YAClC,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,kBAAkB,CAAC,MAAc;;QAC/B,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS;aAC5B,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;aAChC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACb,MAAM,SAAS,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;YAClC,OAAO,SAAS,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;QAEL,MAAM,OAAO,GAAG,MAAA,QAAQ,CAAC,CAAC,CAAC,mCAAI,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;QAC5C,OAAO,OAAO,CAAC,EAAE,CAAC;IACpB,CAAC;;AAvCD;;GAEG;AACa,4BAAY,GAAG,GAAG,AAAN,CAAO;SAJxB,eAAe"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyterlab/apputils",
3
- "version": "4.0.0-alpha.19",
3
+ "version": "4.0.0-alpha.20",
4
4
  "description": "JupyterLab - Application Utilities",
5
5
  "keywords": [
6
6
  "jupyter",
@@ -30,7 +30,8 @@
30
30
  "files": [
31
31
  "lib/**/*.{d.ts,js,js.map}",
32
32
  "style/*.css",
33
- "style/index.js"
33
+ "style/index.js",
34
+ "src/**/*.{ts,tsx}"
34
35
  ],
35
36
  "scripts": {
36
37
  "build": "tsc -b",
@@ -44,35 +45,35 @@
44
45
  "watch": "tsc -b --watch"
45
46
  },
46
47
  "dependencies": {
47
- "@jupyterlab/coreutils": "^6.0.0-alpha.19",
48
- "@jupyterlab/observables": "^5.0.0-alpha.19",
49
- "@jupyterlab/rendermime-interfaces": "^3.8.0-alpha.19",
50
- "@jupyterlab/services": "^7.0.0-alpha.19",
51
- "@jupyterlab/settingregistry": "^4.0.0-alpha.19",
52
- "@jupyterlab/statedb": "^4.0.0-alpha.19",
53
- "@jupyterlab/statusbar": "^4.0.0-alpha.19",
54
- "@jupyterlab/translation": "^4.0.0-alpha.19",
55
- "@jupyterlab/ui-components": "^4.0.0-alpha.34",
56
- "@lumino/algorithm": "^2.0.0-beta.0",
57
- "@lumino/commands": "^2.0.0-beta.1",
58
- "@lumino/coreutils": "^2.0.0-beta.0",
59
- "@lumino/disposable": "^2.0.0-beta.1",
60
- "@lumino/domutils": "^2.0.0-beta.0",
61
- "@lumino/messaging": "^2.0.0-beta.0",
62
- "@lumino/signaling": "^2.0.0-beta.1",
63
- "@lumino/virtualdom": "^2.0.0-beta.0",
64
- "@lumino/widgets": "^2.0.0-beta.1",
48
+ "@jupyterlab/coreutils": "^6.0.0-alpha.20",
49
+ "@jupyterlab/observables": "^5.0.0-alpha.20",
50
+ "@jupyterlab/rendermime-interfaces": "^3.8.0-alpha.20",
51
+ "@jupyterlab/services": "^7.0.0-alpha.20",
52
+ "@jupyterlab/settingregistry": "^4.0.0-alpha.20",
53
+ "@jupyterlab/statedb": "^4.0.0-alpha.20",
54
+ "@jupyterlab/statusbar": "^4.0.0-alpha.20",
55
+ "@jupyterlab/translation": "^4.0.0-alpha.20",
56
+ "@jupyterlab/ui-components": "^4.0.0-alpha.35",
57
+ "@lumino/algorithm": "^2.0.0-rc.0",
58
+ "@lumino/commands": "^2.0.0-rc.0",
59
+ "@lumino/coreutils": "^2.0.0-rc.0",
60
+ "@lumino/disposable": "^2.0.0-rc.0",
61
+ "@lumino/domutils": "^2.0.0-rc.0",
62
+ "@lumino/messaging": "^2.0.0-rc.0",
63
+ "@lumino/signaling": "^2.0.0-rc.0",
64
+ "@lumino/virtualdom": "^2.0.0-rc.0",
65
+ "@lumino/widgets": "^2.0.0-rc.0",
65
66
  "@types/react": "^18.0.26",
66
67
  "react": "^18.2.0",
67
68
  "sanitize-html": "~2.7.3"
68
69
  },
69
70
  "devDependencies": {
70
- "@jupyterlab/testing": "^4.0.0-alpha.19",
71
+ "@jupyterlab/testing": "^4.0.0-alpha.20",
71
72
  "@types/jest": "^29.2.0",
72
73
  "@types/sanitize-html": "^2.3.1",
73
74
  "rimraf": "~3.0.0",
74
- "typedoc": "~0.22.10",
75
- "typescript": "~4.7.3"
75
+ "typedoc": "~0.23.25",
76
+ "typescript": "~5.0.0-beta"
76
77
  },
77
78
  "publishConfig": {
78
79
  "access": "public"
@@ -0,0 +1,107 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+
4
+ import { MimeData } from '@lumino/coreutils';
5
+
6
+ // 'string' is allowed so as to make it non-breaking for any 1.x releases
7
+ export type ClipboardData = string | MimeData;
8
+
9
+ /**
10
+ * The clipboard interface.
11
+ */
12
+ export namespace Clipboard {
13
+ /**
14
+ * Get the application clipboard instance.
15
+ */
16
+ export function getInstance(): MimeData {
17
+ return Private.instance;
18
+ }
19
+
20
+ /**
21
+ * Set the application clipboard instance.
22
+ */
23
+ export function setInstance(value: MimeData): void {
24
+ Private.instance = value;
25
+ }
26
+
27
+ /**
28
+ * Copy text to the system clipboard.
29
+ *
30
+ * #### Notes
31
+ * This can only be called in response to a user input event.
32
+ */
33
+ export function copyToSystem(clipboardData: ClipboardData): void {
34
+ const node = document.body;
35
+ const handler = (event: ClipboardEvent) => {
36
+ const data = event.clipboardData || (window as any).clipboardData;
37
+ if (typeof clipboardData === 'string') {
38
+ data.setData('text', clipboardData);
39
+ } else {
40
+ (clipboardData as MimeData).types().map((mimeType: string) => {
41
+ data.setData(mimeType, clipboardData.getData(mimeType));
42
+ });
43
+ }
44
+ event.preventDefault();
45
+ node.removeEventListener('copy', handler);
46
+ };
47
+ node.addEventListener('copy', handler);
48
+ generateEvent(node);
49
+ }
50
+
51
+ /**
52
+ * Generate a clipboard event on a node.
53
+ *
54
+ * @param node - The element on which to generate the event.
55
+ *
56
+ * @param type - The type of event to generate.
57
+ * `'paste'` events cannot be programmatically generated.
58
+ *
59
+ * #### Notes
60
+ * This can only be called in response to a user input event.
61
+ */
62
+ export function generateEvent(
63
+ node: HTMLElement,
64
+ type: 'copy' | 'cut' = 'copy'
65
+ ): void {
66
+ // http://stackoverflow.com/a/5210367
67
+
68
+ // Identify selected text.
69
+ let sel = window.getSelection();
70
+
71
+ // Save the current selection.
72
+ const savedRanges: any[] = [];
73
+ for (let i = 0, len = sel?.rangeCount || 0; i < len; ++i) {
74
+ savedRanges[i] = sel!.getRangeAt(i).cloneRange();
75
+ }
76
+
77
+ // Select the node content.
78
+ const range = document.createRange();
79
+ range.selectNodeContents(node);
80
+ if (sel) {
81
+ sel.removeAllRanges();
82
+ sel.addRange(range);
83
+ }
84
+
85
+ // Execute the command.
86
+ document.execCommand(type);
87
+
88
+ // Restore the previous selection.
89
+ sel = window.getSelection();
90
+ if (sel) {
91
+ sel.removeAllRanges();
92
+ for (let i = 0, len = savedRanges.length; i < len; ++i) {
93
+ sel.addRange(savedRanges[i]);
94
+ }
95
+ }
96
+ }
97
+ }
98
+
99
+ /**
100
+ * The namespace for module private data.
101
+ */
102
+ namespace Private {
103
+ /**
104
+ * The application clipboard instance.
105
+ */
106
+ export let instance = new MimeData();
107
+ }
@@ -0,0 +1,209 @@
1
+ /* -----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
5
+
6
+ import { CommandRegistry } from '@lumino/commands';
7
+ import { JSONExt, ReadonlyPartialJSONObject } from '@lumino/coreutils';
8
+ import { IDisposable } from '@lumino/disposable';
9
+ import { ElementDataset } from '@lumino/virtualdom';
10
+
11
+ /**
12
+ * The command data attribute added to nodes that are connected.
13
+ */
14
+ const COMMAND_ATTR = 'commandlinker-command';
15
+
16
+ /**
17
+ * The args data attribute added to nodes that are connected.
18
+ */
19
+ const ARGS_ATTR = 'commandlinker-args';
20
+
21
+ /**
22
+ * A static class that provides helper methods to generate clickable nodes that
23
+ * execute registered commands with pre-populated arguments.
24
+ */
25
+ export class CommandLinker implements IDisposable {
26
+ /**
27
+ * Instantiate a new command linker.
28
+ */
29
+ constructor(options: CommandLinker.IOptions) {
30
+ this._commands = options.commands;
31
+ document.body.addEventListener('click', this);
32
+ }
33
+
34
+ /**
35
+ * Test whether the linker is disposed.
36
+ */
37
+ get isDisposed(): boolean {
38
+ return this._isDisposed;
39
+ }
40
+
41
+ /**
42
+ * Dispose of the resources held by the linker.
43
+ */
44
+ dispose(): void {
45
+ if (this.isDisposed) {
46
+ return;
47
+ }
48
+ this._isDisposed = true;
49
+ document.body.removeEventListener('click', this);
50
+ }
51
+
52
+ /**
53
+ * Connect a command/argument pair to a given node so that when it is clicked,
54
+ * the command will execute.
55
+ *
56
+ * @param node - The node being connected.
57
+ *
58
+ * @param command - The command ID to execute upon click.
59
+ *
60
+ * @param args - The arguments with which to invoke the command.
61
+ *
62
+ * @returns The same node that was passed in, after it has been connected.
63
+ *
64
+ * #### Notes
65
+ * Only `click` events will execute the command on a connected node. So, there
66
+ * are two considerations that are relevant:
67
+ * 1. If a node is connected, the default click action will be prevented.
68
+ * 2. The `HTMLElement` passed in should be clickable.
69
+ */
70
+ connectNode(
71
+ node: HTMLElement,
72
+ command: string,
73
+ args?: ReadonlyPartialJSONObject
74
+ ): HTMLElement {
75
+ node.setAttribute(`data-${COMMAND_ATTR}`, command);
76
+ if (args !== void 0) {
77
+ node.setAttribute(`data-${ARGS_ATTR}`, JSON.stringify(args));
78
+ }
79
+ return node;
80
+ }
81
+
82
+ /**
83
+ * Disconnect a node that has been connected to execute a command on click.
84
+ *
85
+ * @param node - The node being disconnected.
86
+ *
87
+ * @returns The same node that was passed in, after it has been disconnected.
88
+ *
89
+ * #### Notes
90
+ * This method is safe to call multiple times and is safe to call on nodes
91
+ * that were never connected.
92
+ *
93
+ * This method can be called on rendered virtual DOM nodes that were populated
94
+ * using the `populateVNodeDataset` method in order to disconnect them from
95
+ * executing their command/argument pair.
96
+ */
97
+ disconnectNode(node: HTMLElement): HTMLElement {
98
+ node.removeAttribute(`data-${COMMAND_ATTR}`);
99
+ node.removeAttribute(`data-${ARGS_ATTR}`);
100
+ return node;
101
+ }
102
+
103
+ /**
104
+ * Handle the DOM events for the command linker helper class.
105
+ *
106
+ * @param event - The DOM event sent to the class.
107
+ *
108
+ * #### Notes
109
+ * This method implements the DOM `EventListener` interface and is
110
+ * called in response to events on the panel's DOM node. It should
111
+ * not be called directly by user code.
112
+ */
113
+ handleEvent(event: Event): void {
114
+ switch (event.type) {
115
+ case 'click':
116
+ this._evtClick(event as MouseEvent);
117
+ break;
118
+ default:
119
+ return;
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Populate the `dataset` attribute within the collection of attributes used
125
+ * to instantiate a virtual DOM node with the values necessary for its
126
+ * rendered DOM node to respond to clicks by executing a command/argument
127
+ * pair.
128
+ *
129
+ * @param command - The command ID to execute upon click.
130
+ *
131
+ * @param args - The arguments with which to invoke the command.
132
+ *
133
+ * @returns A `dataset` collection for use within virtual node attributes.
134
+ *
135
+ * #### Notes
136
+ * The return value can be used on its own as the value for the `dataset`
137
+ * attribute of a virtual element, or it can be added to an existing `dataset`
138
+ * as in the example below.
139
+ *
140
+ * #### Example
141
+ * ```typescript
142
+ * let command = 'some:command-id';
143
+ * let args = { alpha: 'beta' };
144
+ * let anchor = h.a({
145
+ * className: 'some-class',
146
+ * dataset: {
147
+ * foo: '1',
148
+ * bar: '2',
149
+ * ../...linker.populateVNodeDataset(command, args)
150
+ * }
151
+ * }, 'some text');
152
+ * ```
153
+ */
154
+ populateVNodeDataset(
155
+ command: string,
156
+ args?: ReadonlyPartialJSONObject
157
+ ): ElementDataset {
158
+ let dataset: ElementDataset;
159
+ if (args !== void 0) {
160
+ dataset = { [ARGS_ATTR]: JSON.stringify(args), [COMMAND_ATTR]: command };
161
+ } else {
162
+ dataset = { [COMMAND_ATTR]: command };
163
+ }
164
+ return dataset;
165
+ }
166
+
167
+ /**
168
+ * The global click handler that deploys commands/argument pairs that are
169
+ * attached to the node being clicked.
170
+ */
171
+ private _evtClick(event: MouseEvent): void {
172
+ let target = event.target as HTMLElement;
173
+ while (target && target.parentElement) {
174
+ if (target.hasAttribute(`data-${COMMAND_ATTR}`)) {
175
+ event.preventDefault();
176
+ const command = target.getAttribute(`data-${COMMAND_ATTR}`);
177
+ if (!command) {
178
+ return;
179
+ }
180
+ const argsValue = target.getAttribute(`data-${ARGS_ATTR}`);
181
+ let args = JSONExt.emptyObject;
182
+ if (argsValue) {
183
+ args = JSON.parse(argsValue);
184
+ }
185
+ void this._commands.execute(command, args);
186
+ return;
187
+ }
188
+ target = target.parentElement;
189
+ }
190
+ }
191
+
192
+ private _commands: CommandRegistry;
193
+ private _isDisposed = false;
194
+ }
195
+
196
+ /**
197
+ * A namespace for command linker statics.
198
+ */
199
+ export namespace CommandLinker {
200
+ /**
201
+ * The instantiation options for a command linker.
202
+ */
203
+ export interface IOptions {
204
+ /**
205
+ * The command registry instance that all linked commands will use.
206
+ */
207
+ commands: CommandRegistry;
208
+ }
209
+ }
@@ -0,0 +1,175 @@
1
+ /* -----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
5
+
6
+ import { searchIcon } from '@jupyterlab/ui-components';
7
+ import { Message } from '@lumino/messaging';
8
+ import { CommandPalette, Panel, Widget } from '@lumino/widgets';
9
+
10
+ /**
11
+ * Class name identifying the input group with search icon.
12
+ */
13
+ const SEARCH_ICON_GROUP_CLASS = 'jp-SearchIconGroup';
14
+
15
+ /**
16
+ * Wrap the command palette in a modal to make it more usable.
17
+ */
18
+ export class ModalCommandPalette extends Panel {
19
+ constructor(options: ModalCommandPalette.IOptions) {
20
+ super();
21
+ this.addClass('jp-ModalCommandPalette');
22
+ this.id = 'modal-command-palette';
23
+ this.palette = options.commandPalette;
24
+ this._commandPalette.commands.commandExecuted.connect(() => {
25
+ if (this.isAttached && this.isVisible) {
26
+ this.hideAndReset();
27
+ }
28
+ });
29
+ // required to properly receive blur and focus events;
30
+ // selection of items with mouse may not work without this.
31
+ this.node.tabIndex = 0;
32
+ }
33
+
34
+ get palette(): CommandPalette {
35
+ return this._commandPalette;
36
+ }
37
+
38
+ set palette(value: CommandPalette) {
39
+ this._commandPalette = value;
40
+ if (!this.searchIconGroup) {
41
+ this._commandPalette.inputNode.insertAdjacentElement(
42
+ 'afterend',
43
+ this.createSearchIconGroup()
44
+ );
45
+ }
46
+ this.addWidget(value);
47
+ this.hideAndReset();
48
+ }
49
+
50
+ attach(): void {
51
+ Widget.attach(this, document.body);
52
+ }
53
+
54
+ detach(): void {
55
+ Widget.detach(this);
56
+ }
57
+
58
+ /**
59
+ * Hide the modal command palette and reset its search.
60
+ */
61
+ hideAndReset(): void {
62
+ this.hide();
63
+ this._commandPalette.inputNode.value = '';
64
+ this._commandPalette.refresh();
65
+ }
66
+
67
+ /**
68
+ * Handle incoming events.
69
+ */
70
+ handleEvent(event: Event): void {
71
+ switch (event.type) {
72
+ case 'keydown':
73
+ this._evtKeydown(event as KeyboardEvent);
74
+ break;
75
+ case 'blur': {
76
+ // if the focus shifted outside of this DOM element, hide and reset.
77
+ if (
78
+ // focus went away from child element
79
+ this.node.contains(event.target as HTMLElement) &&
80
+ // and it did NOT go to another child element but someplace else
81
+ !this.node.contains(
82
+ (event as MouseEvent).relatedTarget as HTMLElement
83
+ )
84
+ ) {
85
+ event.stopPropagation();
86
+ this.hideAndReset();
87
+ }
88
+ break;
89
+ }
90
+ case 'contextmenu':
91
+ event.preventDefault();
92
+ event.stopPropagation();
93
+ break;
94
+ default:
95
+ break;
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Find the element with search icon group.
101
+ */
102
+ protected get searchIconGroup(): HTMLDivElement | undefined {
103
+ return this._commandPalette.node.getElementsByClassName(
104
+ SEARCH_ICON_GROUP_CLASS
105
+ )[0] as HTMLDivElement;
106
+ }
107
+
108
+ /**
109
+ * Create element with search icon group.
110
+ */
111
+ protected createSearchIconGroup(): HTMLDivElement {
112
+ const inputGroup = document.createElement('div');
113
+ inputGroup.classList.add(SEARCH_ICON_GROUP_CLASS);
114
+ searchIcon.render(inputGroup);
115
+ return inputGroup;
116
+ }
117
+
118
+ /**
119
+ * A message handler invoked on an `'after-attach'` message.
120
+ */
121
+ protected onAfterAttach(msg: Message): void {
122
+ this.node.addEventListener('keydown', this, true);
123
+ this.node.addEventListener('contextmenu', this, true);
124
+ }
125
+
126
+ /**
127
+ * A message handler invoked on an `'after-detach'` message.
128
+ */
129
+ protected onAfterDetach(msg: Message): void {
130
+ this.node.removeEventListener('keydown', this, true);
131
+ this.node.removeEventListener('contextmenu', this, true);
132
+ }
133
+
134
+ protected onBeforeHide(msg: Message): void {
135
+ document.removeEventListener('blur', this, true);
136
+ }
137
+
138
+ protected onAfterShow(msg: Message): void {
139
+ document.addEventListener('blur', this, true);
140
+ }
141
+
142
+ /**
143
+ * A message handler invoked on an `'activate-request'` message.
144
+ */
145
+ protected onActivateRequest(msg: Message): void {
146
+ if (this.isAttached) {
147
+ this.show();
148
+ this._commandPalette.activate();
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Handle the `'keydown'` event for the widget.
154
+ */
155
+ protected _evtKeydown(event: KeyboardEvent): void {
156
+ // Check for escape key
157
+ switch (event.keyCode) {
158
+ case 27: // Escape.
159
+ event.stopPropagation();
160
+ event.preventDefault();
161
+ this.hideAndReset();
162
+ break;
163
+ default:
164
+ break;
165
+ }
166
+ }
167
+
168
+ private _commandPalette: CommandPalette;
169
+ }
170
+
171
+ export namespace ModalCommandPalette {
172
+ export interface IOptions {
173
+ commandPalette: CommandPalette;
174
+ }
175
+ }