@jupyterlab/apputils 4.8.0-alpha.1 → 4.8.0-beta.0

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 (44) hide show
  1. package/lib/clipboard.d.ts +11 -0
  2. package/lib/clipboard.js +26 -4
  3. package/lib/clipboard.js.map +1 -1
  4. package/lib/commandlinker.d.ts +4 -0
  5. package/lib/commandlinker.js +21 -5
  6. package/lib/commandlinker.js.map +1 -1
  7. package/lib/commandpalette.js +1 -1
  8. package/lib/commandpalette.js.map +1 -1
  9. package/lib/dialog.d.ts +12 -0
  10. package/lib/dialog.js +45 -5
  11. package/lib/dialog.js.map +1 -1
  12. package/lib/inputdialog.js +2 -1
  13. package/lib/inputdialog.js.map +1 -1
  14. package/lib/licenses.d.ts +10 -1
  15. package/lib/licenses.js +27 -5
  16. package/lib/licenses.js.map +1 -1
  17. package/lib/sanitizer.d.ts +16 -0
  18. package/lib/sanitizer.js +20 -0
  19. package/lib/sanitizer.js.map +1 -1
  20. package/lib/sessioncontext.d.ts +6 -0
  21. package/lib/sessioncontext.js +19 -6
  22. package/lib/sessioncontext.js.map +1 -1
  23. package/lib/thememanager.js +2 -2
  24. package/lib/thememanager.js.map +1 -1
  25. package/lib/tokens.d.ts +6 -3
  26. package/lib/tokens.js.map +1 -1
  27. package/lib/toolbar/factory.js +2 -2
  28. package/lib/toolbar/factory.js.map +1 -1
  29. package/lib/widgettracker.d.ts +1 -1
  30. package/lib/widgettracker.js +0 -1
  31. package/lib/widgettracker.js.map +1 -1
  32. package/package.json +12 -12
  33. package/src/clipboard.ts +46 -6
  34. package/src/commandlinker.ts +40 -5
  35. package/src/commandpalette.ts +1 -1
  36. package/src/dialog.tsx +56 -3
  37. package/src/inputdialog.ts +2 -1
  38. package/src/licenses.tsx +30 -5
  39. package/src/sanitizer.ts +22 -0
  40. package/src/sessioncontext.tsx +21 -2
  41. package/src/thememanager.ts +6 -3
  42. package/src/tokens.ts +6 -3
  43. package/src/toolbar/factory.ts +8 -5
  44. package/src/widgettracker.ts +2 -3
@@ -29,7 +29,7 @@ export class ModalCommandPalette extends Panel {
29
29
  if (this.isAttached && this.isVisible) {
30
30
  this.hideAndReset();
31
31
  }
32
- });
32
+ }, this);
33
33
  // required to properly receive blur and focus events;
34
34
  // selection of items with mouse may not work without this.
35
35
  this.node.tabIndex = 0;
package/src/dialog.tsx CHANGED
@@ -98,6 +98,7 @@ export class Dialog<T> extends Widget {
98
98
  this._host = normalized.host;
99
99
  this._defaultButton = normalized.defaultButton;
100
100
  this._buttons = normalized.buttons;
101
+ this._skipQueue = normalized.skipQueue;
101
102
  this._hasClose = normalized.hasClose;
102
103
  this._buttonNodes = this._buttons.map(b => renderer.createButtonNode(b));
103
104
  this._checkboxNode = null;
@@ -179,16 +180,33 @@ export class Dialog<T> extends Widget {
179
180
  return this._promise.promise;
180
181
  }
181
182
  const promise = (this._promise = new PromiseDelegate<Dialog.IResult<T>>());
183
+
184
+ if (this._skipQueue) {
185
+ Private.launchQueue.push(this._promise.promise);
186
+ Widget.attach(this, this._host);
187
+ return promise.promise;
188
+ }
189
+
182
190
  const promises = Promise.all(Private.launchQueue);
183
191
  Private.launchQueue.push(this._promise.promise);
184
- return promises.then(() => {
192
+ return promises.then(async () => {
193
+ // A dialog that skipped the queue may have attached while this launch was
194
+ // pending; it must stay on top, so wait for it to close. Collecting the
195
+ // promises synchronously keeps this free of an `await` when none is open,
196
+ // so a dialog launched a microtask later still attaches on top.
197
+ let pending = this._skipQueuePromises();
198
+ while (pending.length > 0) {
199
+ await Promise.all(pending);
200
+ // Another one may have opened while we were waiting.
201
+ pending = this._skipQueuePromises();
202
+ }
185
203
  // Do not show Dialog if it was disposed of before it was at the front of the launch queue
186
204
  if (!this._promise) {
187
- return Promise.resolve({
205
+ return {
188
206
  button: Dialog.cancelButton(),
189
207
  isChecked: null,
190
208
  value: null
191
- });
209
+ };
192
210
  }
193
211
  Widget.attach(this, this._host);
194
212
  return promise.promise;
@@ -269,6 +287,7 @@ export class Dialog<T> extends Widget {
269
287
  */
270
288
  protected onAfterAttach(msg: Message): void {
271
289
  const node = this.node;
290
+ Private.openDialogs.push(this);
272
291
  node.addEventListener('keydown', this, true);
273
292
  node.addEventListener('contextmenu', this, true);
274
293
  node.addEventListener('click', this, true);
@@ -312,6 +331,7 @@ export class Dialog<T> extends Widget {
312
331
  */
313
332
  protected onAfterDetach(msg: Message): void {
314
333
  const node = this.node;
334
+ ArrayExt.removeFirstOf(Private.openDialogs, this);
315
335
  node.removeEventListener('keydown', this, true);
316
336
  node.removeEventListener('contextmenu', this, true);
317
337
  node.removeEventListener('click', this, true);
@@ -469,6 +489,10 @@ export class Dialog<T> extends Widget {
469
489
  * @param event - The DOM event sent to the widget
470
490
  */
471
491
  protected _evtFocus(event: FocusEvent): void {
492
+ // Only the most recently attached dialog traps the focus.
493
+ if (Private.openDialogs[Private.openDialogs.length - 1] !== this) {
494
+ return;
495
+ }
472
496
  const target = event.target as HTMLElement;
473
497
  if (!this.node.contains(target as HTMLElement)) {
474
498
  event.stopPropagation();
@@ -489,6 +513,20 @@ export class Dialog<T> extends Widget {
489
513
  this._lastMouseDownInDialog = content.contains(target as HTMLElement);
490
514
  }
491
515
 
516
+ /**
517
+ * The promises of the attached dialogs which skipped the launch queue.
518
+ */
519
+ private _skipQueuePromises(): Promise<unknown>[] {
520
+ const pending: Promise<unknown>[] = [];
521
+ for (const dialog of Private.openDialogs) {
522
+ if (dialog._skipQueue && dialog._promise) {
523
+ // Disposal rejects the promise; only its settling matters here.
524
+ pending.push(dialog._promise.promise.catch(() => undefined));
525
+ }
526
+ }
527
+ return pending;
528
+ }
529
+
492
530
  /**
493
531
  * Resolve a button item.
494
532
  */
@@ -541,6 +579,7 @@ export class Dialog<T> extends Widget {
541
579
  private _promise: PromiseDelegate<Dialog.IResult<T>> | null;
542
580
  private _defaultButton: number;
543
581
  private _host: HTMLElement;
582
+ private _skipQueue: boolean;
544
583
  private _hasClose: boolean;
545
584
  private _body: Dialog.Body<T>;
546
585
  private _lastMouseDownInDialog: boolean;
@@ -711,6 +750,14 @@ export namespace Dialog {
711
750
  */
712
751
  focusNodeSelector: string;
713
752
 
753
+ /**
754
+ * Whether the dialog should bypass the launch queue and attach immediately.
755
+ * Useful for nested dialogs (such as confirmation prompts) that must appear
756
+ * on top of an already open dialog. Such dialogs do not wait for each
757
+ * other, so a caller that opens several at once should show one at a time.
758
+ */
759
+ skipQueue: boolean;
760
+
714
761
  /**
715
762
  * When "false", disallows user from dismissing the dialog by clicking outside it
716
763
  * or pressing escape. Defaults to "true", which renders a close button.
@@ -1138,6 +1185,11 @@ namespace Private {
1138
1185
  */
1139
1186
  export const launchQueue: Promise<Dialog.IResult<any>>[] = [];
1140
1187
 
1188
+ /**
1189
+ * The attached dialogs, in the order they were attached.
1190
+ */
1191
+ export const openDialogs: Dialog<any>[] = [];
1192
+
1141
1193
  export const errorMessagePromiseCache: Map<string, Promise<void>> = new Map();
1142
1194
 
1143
1195
  /**
@@ -1163,6 +1215,7 @@ namespace Private {
1163
1215
  defaultButton: options.defaultButton ?? buttons.length - 1,
1164
1216
  renderer: options.renderer ?? Dialog.defaultRenderer,
1165
1217
  focusNodeSelector: options.focusNodeSelector ?? '',
1218
+ skipQueue: options.skipQueue ?? false,
1166
1219
  hasClose: options.hasClose ?? true
1167
1220
  };
1168
1221
  }
@@ -381,7 +381,8 @@ class InputNumberDialog extends InputDialogBase<number> {
381
381
  super(options);
382
382
 
383
383
  this._input.type = 'number';
384
- this._input.value = options.value ? options.value.toString() : '0';
384
+ this._input.value =
385
+ options.value !== undefined ? options.value.toString() : '0';
385
386
  }
386
387
 
387
388
  /**
package/src/licenses.tsx CHANGED
@@ -17,7 +17,8 @@ import type { ISignal } from '@lumino/signaling';
17
17
  import { Signal } from '@lumino/signaling';
18
18
  import type { VirtualElement } from '@lumino/virtualdom';
19
19
  import { h } from '@lumino/virtualdom';
20
- import { Panel, SplitPanel, TabBar, Widget } from '@lumino/widgets';
20
+ import type { Widget } from '@lumino/widgets';
21
+ import { Panel, SplitPanel, TabBar } from '@lumino/widgets';
21
22
  import * as React from 'react';
22
23
  import type { ILicensesClient } from './tokens';
23
24
  import { PageConfig, URLExt } from '@jupyterlab/coreutils';
@@ -54,6 +55,7 @@ export class Licenses extends SplitPanel {
54
55
  return;
55
56
  }
56
57
  this._bundles.currentChanged.disconnect(this.onBundleSelected, this);
58
+ this._disposeBundleTabs();
57
59
  this.model.dispose();
58
60
  super.dispose();
59
61
  }
@@ -124,20 +126,35 @@ export class Licenses extends SplitPanel {
124
126
  */
125
127
  protected _updateBundles(): void {
126
128
  this._bundles.clearTabs();
129
+ // The tabs are rebuilt from scratch on every model change, and each one
130
+ // needs a widget to own its title, so the previous owners are released
131
+ // here rather than left behind once their tab is gone.
132
+ this._disposeBundleTabs();
127
133
  let i = 0;
128
134
  const { currentBundleName } = this.model;
129
135
  let currentIndex = 0;
130
136
  for (const bundle of this.model.bundleNames) {
131
- const tab = new Widget();
132
- tab.title.label = bundle;
133
137
  if (bundle === currentBundleName) {
134
138
  currentIndex = i;
135
139
  }
136
- this._bundles.insertTab(++i, tab.title);
140
+ // Passing title options avoids creating a dummy widget per tab whose
141
+ // only purpose would be to own the title (and would have to be
142
+ // disposed when the tabs are rebuilt).
143
+ this._bundles.insertTab(++i, { owner: this, label: bundle });
137
144
  }
138
145
  this._bundles.currentIndex = currentIndex;
139
146
  }
140
147
 
148
+ /**
149
+ * Dispose of the widgets owning the bundle tab titles.
150
+ */
151
+ private _disposeBundleTabs(): void {
152
+ for (const tab of this._bundleTabs) {
153
+ tab.dispose();
154
+ }
155
+ this._bundleTabs.length = 0;
156
+ }
157
+
141
158
  /**
142
159
  * An area for selecting licenses by bundle and filters
143
160
  */
@@ -153,6 +170,11 @@ export class Licenses extends SplitPanel {
153
170
  */
154
171
  protected _bundles: TabBar<Widget>;
155
172
 
173
+ /**
174
+ * The widgets owning the titles of the bundle tabs.
175
+ */
176
+ private _bundleTabs: Widget[] = [];
177
+
156
178
  /**
157
179
  * A grid of the current bundle's packages' license metadata
158
180
  */
@@ -179,16 +201,19 @@ export namespace Licenses {
179
201
  export const REPORT_FORMATS: Record<string, IReportFormat> = {
180
202
  markdown: {
181
203
  id: 'markdown',
204
+ // eslint-disable-next-line jupyter/no-untranslated-string -- File format name.
182
205
  title: 'Markdown',
183
206
  icon: markdownIcon
184
207
  },
185
208
  csv: {
186
209
  id: 'csv',
210
+ // eslint-disable-next-line jupyter/no-untranslated-string -- File format name.
187
211
  title: 'CSV',
188
212
  icon: spreadsheetIcon
189
213
  },
190
214
  json: {
191
215
  id: 'json',
216
+ // eslint-disable-next-line jupyter/no-untranslated-string -- File format name.
192
217
  title: 'JSON',
193
218
  icon: jsonIcon
194
219
  }
@@ -372,7 +397,7 @@ export namespace Licenses {
372
397
  if (options.packageFilter) {
373
398
  this._packageFilter = options.packageFilter;
374
399
  }
375
- if (options.currentPackageIndex) {
400
+ if (options.currentPackageIndex !== undefined) {
376
401
  this._currentPackageIndex = options.currentPackageIndex;
377
402
  }
378
403
  }
package/src/sanitizer.ts CHANGED
@@ -590,6 +590,14 @@ export class Sanitizer implements IRenderMime.ISanitizer {
590
590
  return this._autolink;
591
591
  }
592
592
 
593
+ /**
594
+ * @returns Whether URLs are auto-linked incrementally (asynchronously,
595
+ * across animation frames) rather than in a single synchronous pass.
596
+ */
597
+ getIncrementalAutolink(): boolean {
598
+ return this._incrementalAutolink;
599
+ }
600
+
593
601
  /**
594
602
  * @returns Whether to allow name and id attributes.
595
603
  */
@@ -626,6 +634,19 @@ export class Sanitizer implements IRenderMime.ISanitizer {
626
634
  this._autolink = autolink;
627
635
  }
628
636
 
637
+ /**
638
+ * Set whether URLs are auto-linked incrementally (asynchronously, across
639
+ * animation frames) rather than in a single synchronous pass.
640
+ *
641
+ * Disabling this also disables incremental rendering of the text output (it is
642
+ * rendered synchronously in a single blocking pass).
643
+ *
644
+ * @param incrementalAutolink Whether to auto-link incrementally.
645
+ */
646
+ setIncrementalAutolink(incrementalAutolink: boolean): void {
647
+ this._incrementalAutolink = incrementalAutolink;
648
+ }
649
+
629
650
  /**
630
651
  * Set the whether to allow `name` and `id` attributes.
631
652
  */
@@ -645,6 +666,7 @@ export class Sanitizer implements IRenderMime.ISanitizer {
645
666
  }
646
667
 
647
668
  private _autolink: boolean = true;
669
+ private _incrementalAutolink: boolean = true;
648
670
  private _allowNamedProperties: boolean = false;
649
671
  private _allowCommandLinker: boolean = true;
650
672
  private _customAllowedSchemes: string[] | undefined;
@@ -378,6 +378,7 @@ export class SessionContext implements ISessionContext {
378
378
  this.translator = options.translator || nullTranslator;
379
379
  this._trans = this.translator.load('jupyterlab');
380
380
  this._path = options.path ?? UUID.uuid4();
381
+ this._driveName = options.driveName ?? '';
381
382
  this._type = options.type ?? '';
382
383
  this._name = options.name ?? '';
383
384
  this._setBusy = options.setBusy;
@@ -620,6 +621,10 @@ export class SessionContext implements ISessionContext {
620
621
  return 'restarting';
621
622
  }
622
623
 
624
+ if (this._isChangingKernel) {
625
+ return 'starting';
626
+ }
627
+
623
628
  if (this._pendingKernelName === this.noKernelName) {
624
629
  return 'unknown';
625
630
  }
@@ -950,13 +955,18 @@ export class SessionContext implements ISessionContext {
950
955
 
951
956
  // If we already have a session, just change the kernel.
952
957
  if (this._session && !this._isTerminating) {
958
+ this._isChangingKernel = true;
959
+ this._statusChanged.emit('starting');
953
960
  try {
954
961
  await this._session.changeKernel(model);
955
- return this._session.kernel;
956
962
  } catch (err) {
963
+ this._isChangingKernel = false;
957
964
  void this._handleSessionError(err);
958
965
  throw err;
959
966
  }
967
+ this._isChangingKernel = false;
968
+ this._statusChanged.emit(this._session?.kernel?.status || 'unknown');
969
+ return this._session.kernel;
960
970
  }
961
971
 
962
972
  // Use a UUID for the path to overcome a race condition on the server
@@ -964,7 +974,9 @@ export class SessionContext implements ISessionContext {
964
974
  // the kernel finishes starting.
965
975
  // We later switch to the real path below.
966
976
  // Use the correct directory so the kernel will be started in that directory.
967
- const dirName = PathExt.dirname(this._path);
977
+ const dirName =
978
+ PathExt.dirname(this._path) ||
979
+ (this._driveName ? `${this._driveName}:` : '');
968
980
  const requestId = (this._pendingSessionRequest = PathExt.join(
969
981
  dirName,
970
982
  UUID.uuid4()
@@ -1229,6 +1241,7 @@ export class SessionContext implements ISessionContext {
1229
1241
  }
1230
1242
 
1231
1243
  private _path = '';
1244
+ private _driveName = '';
1232
1245
  private _name = '';
1233
1246
  private _type = '';
1234
1247
  private _prevKernelName: string = '';
@@ -1243,6 +1256,7 @@ export class SessionContext implements ISessionContext {
1243
1256
  private _isReady = false;
1244
1257
  private _isTerminating = false;
1245
1258
  private _isRestarting = false;
1259
+ private _isChangingKernel = false;
1246
1260
  private _kernelChanged = new Signal<
1247
1261
  this,
1248
1262
  Session.ISessionConnection.IKernelChangedArgs
@@ -1307,6 +1321,11 @@ export namespace SessionContext {
1307
1321
  */
1308
1322
  path?: string;
1309
1323
 
1324
+ /**
1325
+ * The drive name for the path.
1326
+ */
1327
+ driveName?: string;
1328
+
1310
1329
  /**
1311
1330
  * The name of the session.
1312
1331
  */
@@ -1,6 +1,5 @@
1
1
  // Copyright (c) Jupyter Development Team.
2
2
  // Distributed under the terms of the Modified BSD License.
3
- /* eslint-disable @typescript-eslint/no-explicit-any */
4
3
 
5
4
  import type { IChangedArgs } from '@jupyterlab/coreutils';
6
5
  import { URLExt } from '@jupyterlab/coreutils';
@@ -27,6 +26,9 @@ const REQUEST_THRESHOLD = 20;
27
26
 
28
27
  type Dict<T> = { [key: string]: T };
29
28
  type ThemedProp<T> = { light: T; dark: T };
29
+ type ThemeManagerSchemaDefinitions = {
30
+ cssOverrides: { properties: Record<string, unknown> };
31
+ };
30
32
 
31
33
  /**
32
34
  * A class that provides theme management.
@@ -392,7 +394,8 @@ export class ThemeManager implements IThemeManager {
392
394
  * Initialize the key -> property dict for the overrides
393
395
  */
394
396
  private _initOverrideProps(): void {
395
- const definitions = this._settings.schema.definitions as any;
397
+ const definitions = this._settings.schema
398
+ .definitions as ThemeManagerSchemaDefinitions;
396
399
  const overidesSchema = definitions.cssOverrides.properties;
397
400
 
398
401
  Object.keys(overidesSchema).forEach(key => {
@@ -580,7 +583,7 @@ export class ThemeManager implements IThemeManager {
580
583
  /**
581
584
  * Handle a theme error.
582
585
  */
583
- private _onError(reason: any): void {
586
+ private _onError(reason: unknown): void {
584
587
  void showDialog({
585
588
  title: this._trans.__('Error Loading Theme'),
586
589
  body: String(reason),
package/src/tokens.ts CHANGED
@@ -428,10 +428,13 @@ export const IToolbarWidgetRegistry = new Token<IToolbarWidgetRegistry>(
428
428
  */
429
429
  export interface ISectionEntry {
430
430
  /**
431
- * Stable identifier for this section, equal to the widget's Lumino `id`.
431
+ * Identifier for this section, stable across reloads and unique within its
432
+ * source panel.
432
433
  *
433
- * The move plugin uses this to persist which sections have been moved and
434
- * to restore them to the correct panel on reload.
434
+ * The move plugin passes this value to
435
+ * {@link IMovableSectionSource.removeSectionById} and uses it to persist
436
+ * which sections have been moved and to restore them to the correct panel
437
+ * on reload.
435
438
  */
436
439
  readonly id: string;
437
440
 
@@ -2,7 +2,6 @@
2
2
  * Copyright (c) Jupyter Development Team.
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
- /* eslint-disable @typescript-eslint/no-explicit-any */
6
5
 
7
6
  import type { IObservableList } from '@jupyterlab/observables';
8
7
  import { ObservableList } from '@jupyterlab/observables';
@@ -110,7 +109,8 @@ async function setToolbarItems(
110
109
  schema.properties![propertyId].default =
111
110
  SettingRegistry.reconcileToolbarItems(
112
111
  pluginDefaults,
113
- schema.properties![propertyId].default as any[],
112
+ schema.properties![propertyId]
113
+ .default as ISettingRegistry.IToolbarItem[],
114
114
  true
115
115
  )!.sort(
116
116
  (a, b) =>
@@ -186,7 +186,7 @@ async function setToolbarItems(
186
186
  // React to customization by the user
187
187
  settings.changed.connect(() => {
188
188
  const newItems: ISettingRegistry.IToolbarItem[] =
189
- (settings.composite[propertyId] as any) ?? [];
189
+ (settings.composite[propertyId] as ISettingRegistry.IToolbarItem[]) ?? [];
190
190
 
191
191
  transferSettings(newItems);
192
192
  });
@@ -200,7 +200,9 @@ async function setToolbarItems(
200
200
  };
201
201
 
202
202
  // Initialize the toolbar
203
- transferSettings((settings.composite[propertyId] as any) ?? []);
203
+ transferSettings(
204
+ (settings.composite[propertyId] as ISettingRegistry.IToolbarItem[]) ?? []
205
+ );
204
206
 
205
207
  // React to plugin changes if no other transformer exists, otherwise bail.
206
208
  if (!listenPlugin) {
@@ -258,7 +260,8 @@ export function createToolbarFactory(
258
260
  propertyId: string = 'toolbar'
259
261
  ): (widget: Widget) => IObservableList<ToolbarRegistry.IToolbarItem> {
260
262
  const items = new ObservableList<ISettingRegistry.IToolbarItem>({
261
- itemCmp: (a, b) => JSONExt.deepEqual(a as any, b as any)
263
+ itemCmp: (a, b) =>
264
+ JSONExt.deepEqual(a as PartialJSONObject, b as PartialJSONObject)
262
265
  });
263
266
 
264
267
  // Get toolbar definition from the settings
@@ -1,6 +1,5 @@
1
1
  // Copyright (c) Jupyter Development Team.
2
2
  // Distributed under the terms of the Modified BSD License.
3
- /* eslint-disable @typescript-eslint/no-explicit-any */
4
3
 
5
4
  import type { IRestorable } from '@jupyterlab/statedb';
6
5
  import { RestorablePool } from '@jupyterlab/statedb';
@@ -311,7 +310,7 @@ export class WidgetTracker<T extends Widget = Widget>
311
310
  * @param widget - The widget whose existence is being checked.
312
311
  */
313
312
  has(widget: Widget): boolean {
314
- return this._pool.has(widget as any);
313
+ return this._pool.has(widget as T);
315
314
  }
316
315
 
317
316
  /**
@@ -325,7 +324,7 @@ export class WidgetTracker<T extends Widget = Widget>
325
324
  * This function should not typically be invoked by client code.
326
325
  * Its primary use case is to be invoked by a restorer.
327
326
  */
328
- async restore(options?: IRestorable.IOptions<T>): Promise<any> {
327
+ async restore(options?: IRestorable.IOptions<T>): Promise<unknown> {
329
328
  const deferred = this._deferred;
330
329
  if (deferred) {
331
330
  this._deferred = null;