@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.
Files changed (80) hide show
  1. package/lib/clipboard.d.ts +1 -1
  2. package/lib/dialog.d.ts +66 -4
  3. package/lib/dialog.js +126 -29
  4. package/lib/dialog.js.map +1 -1
  5. package/lib/domutils.js.map +1 -1
  6. package/lib/index.d.ts +1 -0
  7. package/lib/index.js +1 -0
  8. package/lib/index.js.map +1 -1
  9. package/lib/inputdialog.d.ts +35 -3
  10. package/lib/inputdialog.js +122 -12
  11. package/lib/inputdialog.js.map +1 -1
  12. package/lib/kernelstatuses.js +26 -25
  13. package/lib/kernelstatuses.js.map +1 -1
  14. package/lib/mainareawidget.js +1 -1
  15. package/lib/mainareawidget.js.map +1 -1
  16. package/lib/menufactory.js +14 -15
  17. package/lib/menufactory.js.map +1 -1
  18. package/lib/notification.d.ts +336 -0
  19. package/lib/notification.js +310 -0
  20. package/lib/notification.js.map +1 -0
  21. package/lib/runningSessions.js +2 -2
  22. package/lib/runningSessions.js.map +1 -1
  23. package/lib/sanitizer.d.ts +20 -7
  24. package/lib/sanitizer.js +34 -7
  25. package/lib/sanitizer.js.map +1 -1
  26. package/lib/semanticCommand.js +11 -2
  27. package/lib/semanticCommand.js.map +1 -1
  28. package/lib/sessioncontext.d.ts +53 -6
  29. package/lib/sessioncontext.js +100 -68
  30. package/lib/sessioncontext.js.map +1 -1
  31. package/lib/testutils.d.ts +5 -0
  32. package/lib/testutils.js +46 -0
  33. package/lib/testutils.js.map +1 -0
  34. package/lib/thememanager.js +20 -5
  35. package/lib/thememanager.js.map +1 -1
  36. package/lib/tokens.d.ts +21 -42
  37. package/lib/tokens.js.map +1 -1
  38. package/lib/toolbar/factory.d.ts +2 -1
  39. package/lib/toolbar/factory.js +135 -105
  40. package/lib/toolbar/factory.js.map +1 -1
  41. package/lib/toolbar/index.js +4 -0
  42. package/lib/toolbar/index.js.map +1 -1
  43. package/lib/toolbar/registry.d.ts +11 -0
  44. package/lib/toolbar/registry.js +20 -3
  45. package/lib/toolbar/registry.js.map +1 -1
  46. package/lib/toolbar/widget.d.ts +3 -0
  47. package/lib/toolbar/widget.js +8 -5
  48. package/lib/toolbar/widget.js.map +1 -1
  49. package/lib/widgettracker.d.ts +13 -1
  50. package/lib/widgettracker.js +29 -2
  51. package/lib/widgettracker.js.map +1 -1
  52. package/package.json +31 -30
  53. package/src/clipboard.ts +107 -0
  54. package/src/commandlinker.ts +209 -0
  55. package/src/commandpalette.ts +175 -0
  56. package/src/dialog.tsx +1133 -0
  57. package/src/domutils.ts +53 -0
  58. package/src/index.ts +78 -0
  59. package/src/inputdialog.ts +551 -0
  60. package/src/kernelstatuses.tsx +279 -0
  61. package/src/mainareawidget.ts +362 -0
  62. package/src/menufactory.ts +201 -0
  63. package/src/notification.ts +559 -0
  64. package/src/printing.ts +180 -0
  65. package/src/runningSessions.tsx +233 -0
  66. package/src/sanitizer.ts +986 -0
  67. package/src/semanticCommand.ts +77 -0
  68. package/src/sessioncontext.tsx +1774 -0
  69. package/src/testutils.ts +49 -0
  70. package/src/thememanager.ts +530 -0
  71. package/src/tokens.ts +351 -0
  72. package/src/toolbar/factory.ts +426 -0
  73. package/src/toolbar/index.ts +8 -0
  74. package/src/toolbar/registry.ts +158 -0
  75. package/src/toolbar/widget.tsx +242 -0
  76. package/src/widgettracker.ts +391 -0
  77. package/src/windowresolver.ts +218 -0
  78. package/style/dialog.css +16 -1
  79. package/style/inputdialog.css +5 -0
  80. 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-color0);
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;
@@ -1,3 +1,8 @@
1
+ /*
2
+ * Copyright (c) Jupyter Development Team.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+
1
6
  .jp-Input-Boolean-Dialog {
2
7
  flex-direction: row-reverse;
3
8
  align-items: end;
@@ -1,3 +1,8 @@
1
+ /*
2
+ * Copyright (c) Jupyter Development Team.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+
1
6
  /**
2
7
  * google-material-color v1.2.6
3
8
  * https://github.com/danlevan/google-material-color