@jupyterlab/apputils 4.0.0-alpha.9 → 4.0.0-beta.1
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 +66 -4
- package/lib/dialog.js +126 -29
- package/lib/dialog.js.map +1 -1
- package/lib/domutils.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- 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.js +26 -25
- package/lib/kernelstatuses.js.map +1 -1
- package/lib/mainareawidget.js +1 -1
- 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.js +2 -2
- package/lib/runningSessions.js.map +1 -1
- package/lib/sanitizer.d.ts +20 -7
- package/lib/sanitizer.js +34 -7
- 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 +53 -6
- package/lib/sessioncontext.js +100 -68
- 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 +20 -5
- package/lib/thememanager.js.map +1 -1
- package/lib/tokens.d.ts +21 -42
- package/lib/tokens.js.map +1 -1
- package/lib/toolbar/factory.d.ts +2 -1
- package/lib/toolbar/factory.js +135 -105
- 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 +8 -5
- 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 +31 -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 +986 -0
- package/src/semanticCommand.ts +77 -0
- package/src/sessioncontext.tsx +1774 -0
- package/src/testutils.ts +49 -0
- package/src/thememanager.ts +530 -0
- package/src/tokens.ts +351 -0
- package/src/toolbar/factory.ts +426 -0
- package/src/toolbar/index.ts +8 -0
- package/src/toolbar/registry.ts +158 -0
- package/src/toolbar/widget.tsx +242 -0
- package/src/widgettracker.ts +391 -0
- package/src/windowresolver.ts +218 -0
- package/style/dialog.css +16 -1
- package/style/inputdialog.css +5 -0
- package/style/materialcolors.css +5 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import { PromiseDelegate } from '@lumino/coreutils';
|
|
5
|
+
import { IWindowResolver } from './tokens';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A concrete implementation of a window name resolver.
|
|
9
|
+
*/
|
|
10
|
+
export class WindowResolver implements IWindowResolver {
|
|
11
|
+
/**
|
|
12
|
+
* The resolved window name.
|
|
13
|
+
*
|
|
14
|
+
* #### Notes
|
|
15
|
+
* If the `resolve` promise has not resolved, the behavior is undefined.
|
|
16
|
+
*/
|
|
17
|
+
get name(): string {
|
|
18
|
+
return this._name;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Resolve a window name to use as a handle among shared resources.
|
|
23
|
+
*
|
|
24
|
+
* @param candidate - The potential window name being resolved.
|
|
25
|
+
*
|
|
26
|
+
* #### Notes
|
|
27
|
+
* Typically, the name candidate should be a JupyterLab workspace name or
|
|
28
|
+
* an empty string if there is no workspace.
|
|
29
|
+
*
|
|
30
|
+
* If the returned promise rejects, a window name cannot be resolved without
|
|
31
|
+
* user intervention, which typically means navigation to a new URL.
|
|
32
|
+
*/
|
|
33
|
+
resolve(candidate: string): Promise<void> {
|
|
34
|
+
return Private.resolve(candidate).then(name => {
|
|
35
|
+
this._name = name;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private _name: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/*
|
|
43
|
+
* A namespace for private module data.
|
|
44
|
+
*/
|
|
45
|
+
namespace Private {
|
|
46
|
+
/**
|
|
47
|
+
* The internal prefix for private local storage keys.
|
|
48
|
+
*/
|
|
49
|
+
const PREFIX = '@jupyterlab/statedb:StateDB';
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The local storage beacon key.
|
|
53
|
+
*/
|
|
54
|
+
const BEACON = `${PREFIX}:beacon`;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The timeout (in ms) to wait for beacon responders.
|
|
58
|
+
*
|
|
59
|
+
* #### Notes
|
|
60
|
+
* This value is a whole number between 200 and 500 in order to prevent
|
|
61
|
+
* perfect timeout collisions between multiple simultaneously opening windows
|
|
62
|
+
* that have the same URL. This is an edge case because multiple windows
|
|
63
|
+
* should not ordinarily share the same URL, but it can be contrived.
|
|
64
|
+
*/
|
|
65
|
+
const TIMEOUT = Math.floor(200 + Math.random() * 300);
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The local storage window key.
|
|
69
|
+
*/
|
|
70
|
+
const WINDOW = `${PREFIX}:window`;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Current beacon request
|
|
74
|
+
*
|
|
75
|
+
* #### Notes
|
|
76
|
+
* We keep track of the current request so that we can ignore our own beacon
|
|
77
|
+
* requests. This is to work around a bug in Safari, where Safari sometimes
|
|
78
|
+
* triggers local storage events for changes made by the current tab. See
|
|
79
|
+
* https://github.com/jupyterlab/jupyterlab/issues/6921#issuecomment-540817283
|
|
80
|
+
* for more details.
|
|
81
|
+
*/
|
|
82
|
+
let currentBeaconRequest: string | null = null;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A potential preferred default window name.
|
|
86
|
+
*/
|
|
87
|
+
let candidate: string | null = null;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The window name promise.
|
|
91
|
+
*/
|
|
92
|
+
const delegate = new PromiseDelegate<string>();
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The known window names.
|
|
96
|
+
*/
|
|
97
|
+
const known: { [window: string]: null } = {};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The window name.
|
|
101
|
+
*/
|
|
102
|
+
let name: string | null = null;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Whether the name resolution has completed.
|
|
106
|
+
*/
|
|
107
|
+
let resolved = false;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Start the storage event handler.
|
|
111
|
+
*/
|
|
112
|
+
function initialize(): void {
|
|
113
|
+
// Listen to all storage events for beacons and window names.
|
|
114
|
+
window.addEventListener('storage', (event: StorageEvent) => {
|
|
115
|
+
const { key, newValue } = event;
|
|
116
|
+
|
|
117
|
+
// All the keys we care about have values.
|
|
118
|
+
if (newValue === null) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// If the beacon was fired, respond with a ping.
|
|
123
|
+
if (
|
|
124
|
+
key === BEACON &&
|
|
125
|
+
newValue !== currentBeaconRequest &&
|
|
126
|
+
candidate !== null
|
|
127
|
+
) {
|
|
128
|
+
ping(resolved ? name : candidate);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// If the window name is resolved, bail.
|
|
133
|
+
if (resolved || key !== WINDOW) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const reported = newValue.replace(/\-\d+$/, '');
|
|
138
|
+
|
|
139
|
+
// Store the reported window name.
|
|
140
|
+
known[reported] = null;
|
|
141
|
+
|
|
142
|
+
// If a reported window name and candidate collide, reject the candidate.
|
|
143
|
+
if (!candidate || candidate in known) {
|
|
144
|
+
reject();
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Ping peers with payload.
|
|
151
|
+
*/
|
|
152
|
+
function ping(payload: string | null): void {
|
|
153
|
+
if (payload === null) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const { localStorage } = window;
|
|
158
|
+
|
|
159
|
+
localStorage.setItem(WINDOW, `${payload}-${new Date().getTime()}`);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Reject the candidate.
|
|
164
|
+
*/
|
|
165
|
+
function reject(): void {
|
|
166
|
+
resolved = true;
|
|
167
|
+
currentBeaconRequest = null;
|
|
168
|
+
delegate.reject(`Window name candidate "${candidate}" already exists`);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Returns a promise that resolves with the window name used for restoration.
|
|
173
|
+
*/
|
|
174
|
+
export function resolve(potential: string): Promise<string> {
|
|
175
|
+
if (resolved) {
|
|
176
|
+
return delegate.promise;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Set the local candidate.
|
|
180
|
+
candidate = potential;
|
|
181
|
+
|
|
182
|
+
if (candidate in known) {
|
|
183
|
+
reject();
|
|
184
|
+
return delegate.promise;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const { localStorage, setTimeout } = window;
|
|
188
|
+
|
|
189
|
+
// Wait until other windows have reported before claiming the candidate.
|
|
190
|
+
setTimeout(() => {
|
|
191
|
+
if (resolved) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// If the window name has not already been resolved, check one last time
|
|
196
|
+
// to confirm it is not a duplicate before resolving.
|
|
197
|
+
if (!candidate || candidate in known) {
|
|
198
|
+
return reject();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
resolved = true;
|
|
202
|
+
currentBeaconRequest = null;
|
|
203
|
+
delegate.resolve((name = candidate));
|
|
204
|
+
ping(name);
|
|
205
|
+
}, TIMEOUT);
|
|
206
|
+
|
|
207
|
+
// Fire the beacon to collect other windows' names.
|
|
208
|
+
currentBeaconRequest = `${Math.random()}-${new Date().getTime()}`;
|
|
209
|
+
localStorage.setItem(BEACON, currentBeaconRequest);
|
|
210
|
+
|
|
211
|
+
return delegate.promise;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Initialize the storage listener at runtime.
|
|
215
|
+
(() => {
|
|
216
|
+
initialize();
|
|
217
|
+
})();
|
|
218
|
+
}
|
package/style/dialog.css
CHANGED
|
@@ -94,7 +94,7 @@ button.jp-Dialog-close-button {
|
|
|
94
94
|
padding-bottom: 12px;
|
|
95
95
|
font-size: var(--jp-ui-font-size3);
|
|
96
96
|
font-weight: 400;
|
|
97
|
-
color: var(--jp-ui-font-
|
|
97
|
+
color: var(--jp-ui-font-color1);
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
.jp-Dialog-body {
|
|
@@ -103,6 +103,7 @@ button.jp-Dialog-close-button {
|
|
|
103
103
|
flex: 1 1 auto;
|
|
104
104
|
font-size: var(--jp-ui-font-size1);
|
|
105
105
|
background: var(--jp-layout-color1);
|
|
106
|
+
color: var(--jp-ui-font-color1);
|
|
106
107
|
overflow: auto;
|
|
107
108
|
}
|
|
108
109
|
|
|
@@ -110,12 +111,26 @@ button.jp-Dialog-close-button {
|
|
|
110
111
|
display: flex;
|
|
111
112
|
flex-direction: row;
|
|
112
113
|
justify-content: flex-end;
|
|
114
|
+
align-items: center;
|
|
113
115
|
flex: 0 0 auto;
|
|
114
116
|
margin-left: -12px;
|
|
115
117
|
margin-right: -12px;
|
|
116
118
|
padding: 12px;
|
|
117
119
|
}
|
|
118
120
|
|
|
121
|
+
.jp-Dialog-checkbox {
|
|
122
|
+
padding-right: 5px;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.jp-Dialog-checkbox > input:focus-visible {
|
|
126
|
+
outline: 1px solid var(--jp-input-active-border-color);
|
|
127
|
+
outline-offset: 1px;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.jp-Dialog-spacer {
|
|
131
|
+
flex: 1 1 auto;
|
|
132
|
+
}
|
|
133
|
+
|
|
119
134
|
.jp-Dialog-title {
|
|
120
135
|
overflow: hidden;
|
|
121
136
|
white-space: nowrap;
|
package/style/inputdialog.css
CHANGED