@jupyterlab/apputils 4.8.0-alpha.0 → 4.8.0-alpha.2

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/inputdialog.js +2 -1
  10. package/lib/inputdialog.js.map +1 -1
  11. package/lib/licenses.d.ts +10 -1
  12. package/lib/licenses.js +24 -5
  13. package/lib/licenses.js.map +1 -1
  14. package/lib/mainareawidget.d.ts +2 -2
  15. package/lib/mainareawidget.js +0 -3
  16. package/lib/mainareawidget.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/toolbar/factory.js +2 -2
  26. package/lib/toolbar/factory.js.map +1 -1
  27. package/lib/widgettracker.d.ts +1 -1
  28. package/lib/widgettracker.js +0 -1
  29. package/lib/widgettracker.js.map +1 -1
  30. package/lib/windowresolver.js +27 -5
  31. package/lib/windowresolver.js.map +1 -1
  32. package/package.json +20 -20
  33. package/src/clipboard.ts +46 -6
  34. package/src/commandlinker.ts +40 -5
  35. package/src/commandpalette.ts +1 -1
  36. package/src/inputdialog.ts +2 -1
  37. package/src/licenses.tsx +27 -5
  38. package/src/mainareawidget.ts +2 -4
  39. package/src/sanitizer.ts +22 -0
  40. package/src/sessioncontext.tsx +21 -2
  41. package/src/thememanager.ts +6 -3
  42. package/src/toolbar/factory.ts +8 -5
  43. package/src/widgettracker.ts +2 -3
  44. package/src/windowresolver.ts +32 -5
@@ -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),
@@ -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;
@@ -159,6 +159,15 @@ namespace Private {
159
159
  localStorage.setItem(WINDOW, `${payload}-${new Date().getTime()}`);
160
160
  }
161
161
 
162
+ /**
163
+ * Accept a candidate.
164
+ */
165
+ function accept(accepted: string): void {
166
+ resolved = true;
167
+ currentBeaconRequest = null;
168
+ delegate.resolve((name = accepted));
169
+ }
170
+
162
171
  /**
163
172
  * Reject the candidate.
164
173
  */
@@ -184,7 +193,19 @@ namespace Private {
184
193
  return delegate.promise;
185
194
  }
186
195
 
187
- const { localStorage, setTimeout } = window;
196
+ const { setTimeout } = window;
197
+ let localStorage: Storage;
198
+ try {
199
+ localStorage = window.localStorage;
200
+ } catch (reason) {
201
+ // Sandboxed documents may not have access to local storage.
202
+ console.warn(
203
+ 'WindowResolver could not access localStorage; accepting the candidate name.',
204
+ reason
205
+ );
206
+ accept(potential);
207
+ return delegate.promise;
208
+ }
188
209
 
189
210
  // Wait until other windows have reported before claiming the candidate.
190
211
  setTimeout(() => {
@@ -198,15 +219,21 @@ namespace Private {
198
219
  return reject();
199
220
  }
200
221
 
201
- resolved = true;
202
- currentBeaconRequest = null;
203
- delegate.resolve((name = candidate));
222
+ accept(candidate);
204
223
  ping(name);
205
224
  }, TIMEOUT);
206
225
 
207
226
  // Fire the beacon to collect other windows' names.
208
227
  currentBeaconRequest = `${Math.random()}-${new Date().getTime()}`;
209
- localStorage.setItem(BEACON, currentBeaconRequest);
228
+ try {
229
+ localStorage.setItem(BEACON, currentBeaconRequest);
230
+ } catch (reason) {
231
+ console.warn(
232
+ 'WindowResolver could not write to localStorage; accepting the candidate name.',
233
+ reason
234
+ );
235
+ accept(potential);
236
+ }
210
237
 
211
238
  return delegate.promise;
212
239
  }