@jupyterlab/apputils 4.0.0-alpha.2 → 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.
- package/lib/clipboard.d.ts +1 -1
- package/lib/dialog.d.ts +73 -4
- package/lib/dialog.js +143 -30
- package/lib/dialog.js.map +1 -1
- package/lib/domutils.js.map +1 -1
- package/lib/index.d.ts +6 -5
- package/lib/index.js +6 -5
- package/lib/index.js.map +1 -1
- package/lib/inputdialog.d.ts +35 -3
- package/lib/inputdialog.js +122 -12
- package/lib/inputdialog.js.map +1 -1
- package/lib/kernelstatuses.d.ts +74 -2
- package/lib/kernelstatuses.js +142 -2
- package/lib/kernelstatuses.js.map +1 -1
- package/lib/mainareawidget.d.ts +9 -0
- package/lib/mainareawidget.js +29 -4
- package/lib/mainareawidget.js.map +1 -1
- package/lib/menufactory.js +14 -15
- package/lib/menufactory.js.map +1 -1
- package/lib/notification.d.ts +336 -0
- package/lib/notification.js +310 -0
- package/lib/notification.js.map +1 -0
- package/lib/runningSessions.d.ts +72 -0
- package/lib/runningSessions.js +119 -0
- package/lib/runningSessions.js.map +1 -0
- package/lib/sanitizer.d.ts +6 -4
- package/lib/sanitizer.js +32 -12
- package/lib/sanitizer.js.map +1 -1
- package/lib/semanticCommand.js +11 -2
- package/lib/semanticCommand.js.map +1 -1
- package/lib/sessioncontext.d.ts +2 -3
- package/lib/sessioncontext.js +46 -27
- package/lib/sessioncontext.js.map +1 -1
- package/lib/testutils.d.ts +5 -0
- package/lib/testutils.js +46 -0
- package/lib/testutils.js.map +1 -0
- package/lib/thememanager.js +13 -4
- package/lib/thememanager.js.map +1 -1
- package/lib/tokens.d.ts +26 -9
- package/lib/tokens.js +1 -6
- package/lib/tokens.js.map +1 -1
- package/lib/toolbar/factory.d.ts +12 -2
- package/lib/toolbar/factory.js +237 -145
- package/lib/toolbar/factory.js.map +1 -1
- package/lib/toolbar/index.js +4 -0
- package/lib/toolbar/index.js.map +1 -1
- package/lib/toolbar/registry.d.ts +11 -0
- package/lib/toolbar/registry.js +20 -3
- package/lib/toolbar/registry.js.map +1 -1
- package/lib/toolbar/widget.d.ts +3 -0
- package/lib/toolbar/widget.js +3 -0
- package/lib/toolbar/widget.js.map +1 -1
- package/lib/widgettracker.d.ts +13 -1
- package/lib/widgettracker.js +29 -2
- package/lib/widgettracker.js.map +1 -1
- package/package.json +30 -30
- package/src/clipboard.ts +107 -0
- package/src/commandlinker.ts +209 -0
- package/src/commandpalette.ts +175 -0
- package/src/dialog.tsx +1133 -0
- package/src/domutils.ts +53 -0
- package/src/index.ts +78 -0
- package/src/inputdialog.ts +551 -0
- package/src/kernelstatuses.tsx +279 -0
- package/src/mainareawidget.ts +362 -0
- package/src/menufactory.ts +201 -0
- package/src/notification.ts +559 -0
- package/src/printing.ts +180 -0
- package/src/runningSessions.tsx +233 -0
- package/src/sanitizer.ts +968 -0
- package/src/semanticCommand.ts +77 -0
- package/src/sessioncontext.tsx +1712 -0
- package/src/testutils.ts +49 -0
- package/src/thememanager.ts +519 -0
- package/src/tokens.ts +372 -0
- package/src/toolbar/factory.ts +422 -0
- package/src/toolbar/index.ts +8 -0
- package/src/toolbar/registry.ts +158 -0
- package/src/toolbar/widget.tsx +243 -0
- package/src/widgettracker.ts +391 -0
- package/src/windowresolver.ts +218 -0
- package/style/base.css +0 -1
- package/style/commandpalette.css +7 -10
- package/style/dialog.css +23 -7
- package/style/index.css +1 -0
- package/style/index.js +1 -0
- package/style/inputdialog.css +5 -0
- package/style/materialcolors.css +8 -21
- package/lib/hoverbox.d.ts +0 -82
- package/lib/hoverbox.js +0 -100
- package/lib/hoverbox.js.map +0 -1
- package/style/hoverbox.css +0 -13
|
@@ -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
|
+
}
|