@jupyterlab/apputils 4.7.0-alpha.5 → 4.7.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 (44) hide show
  1. package/lib/clipboard.d.ts +2 -0
  2. package/lib/clipboard.js +10 -0
  3. package/lib/clipboard.js.map +1 -1
  4. package/lib/dialog.js +9 -1
  5. package/lib/dialog.js.map +1 -1
  6. package/lib/index.d.ts +3 -1
  7. package/lib/index.js +1 -0
  8. package/lib/index.js.map +1 -1
  9. package/lib/mainareawidget.js +1 -0
  10. package/lib/mainareawidget.js.map +1 -1
  11. package/lib/menufactory.js.map +1 -1
  12. package/lib/movableSectionRegistry.d.ts +32 -0
  13. package/lib/movableSectionRegistry.js +36 -0
  14. package/lib/movableSectionRegistry.js.map +1 -0
  15. package/lib/sessioncontext.d.ts +6 -1
  16. package/lib/sessioncontext.js +18 -12
  17. package/lib/sessioncontext.js.map +1 -1
  18. package/lib/thememanager.js +2 -1
  19. package/lib/thememanager.js.map +1 -1
  20. package/lib/tokens.d.ts +194 -1
  21. package/lib/tokens.js +4 -0
  22. package/lib/tokens.js.map +1 -1
  23. package/lib/toolbar/factory.js +1 -0
  24. package/lib/toolbar/factory.js.map +1 -1
  25. package/lib/toolbar/registry.js.map +1 -1
  26. package/lib/widgettracker.js +1 -0
  27. package/lib/widgettracker.js.map +1 -1
  28. package/lib/windowresolver.js +1 -1
  29. package/lib/windowresolver.js.map +1 -1
  30. package/package.json +12 -12
  31. package/src/clipboard.ts +13 -0
  32. package/src/dialog.tsx +8 -1
  33. package/src/index.ts +5 -2
  34. package/src/mainareawidget.ts +1 -0
  35. package/src/menufactory.ts +2 -3
  36. package/src/movableSectionRegistry.ts +78 -0
  37. package/src/sessioncontext.tsx +23 -11
  38. package/src/thememanager.ts +2 -1
  39. package/src/tokens.ts +222 -1
  40. package/src/toolbar/factory.ts +1 -0
  41. package/src/toolbar/registry.ts +5 -2
  42. package/src/widgettracker.ts +1 -0
  43. package/src/windowresolver.ts +1 -1
  44. package/style/dialog.css +12 -8
@@ -0,0 +1,78 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+
4
+ import { Signal } from '@lumino/signaling';
5
+ import type {
6
+ IMovableSectionDestination,
7
+ IMovableSectionRegistry,
8
+ IMovableSectionSource
9
+ } from './tokens';
10
+
11
+ /**
12
+ * Source and target panels register themselves here so that generic
13
+ * section-moving commands can discover them.
14
+ */
15
+ export class MovableSectionRegistry implements IMovableSectionRegistry {
16
+ private readonly _sources = new Map<
17
+ string,
18
+ { label: string; sidebar: IMovableSectionSource }
19
+ >();
20
+ private readonly _targets = new Map<
21
+ string,
22
+ { label: string; panel: IMovableSectionDestination }
23
+ >();
24
+ private readonly _sourcePanelRegistered = new Signal<
25
+ this,
26
+ { id: string; label: string; sidebar: IMovableSectionSource }
27
+ >(this);
28
+ private readonly _targetPanelRegistered = new Signal<
29
+ this,
30
+ { id: string; label: string; panel: IMovableSectionDestination }
31
+ >(this);
32
+
33
+ get sourcePanelRegistered(): Signal<
34
+ this,
35
+ { id: string; label: string; sidebar: IMovableSectionSource }
36
+ > {
37
+ return this._sourcePanelRegistered;
38
+ }
39
+
40
+ get targetPanelRegistered(): Signal<
41
+ this,
42
+ { id: string; label: string; panel: IMovableSectionDestination }
43
+ > {
44
+ return this._targetPanelRegistered;
45
+ }
46
+
47
+ registerSource(
48
+ id: string,
49
+ label: string,
50
+ sidebar: IMovableSectionSource
51
+ ): void {
52
+ this._sources.set(id, { label, sidebar });
53
+ this._sourcePanelRegistered.emit({ id, label, sidebar });
54
+ }
55
+
56
+ registerTarget(
57
+ id: string,
58
+ label: string,
59
+ panel: IMovableSectionDestination
60
+ ): void {
61
+ this._targets.set(id, { label, panel });
62
+ this._targetPanelRegistered.emit({ id, label, panel });
63
+ }
64
+
65
+ getSources(): ReadonlyMap<
66
+ string,
67
+ { label: string; sidebar: IMovableSectionSource }
68
+ > {
69
+ return this._sources;
70
+ }
71
+
72
+ getTargets(): ReadonlyMap<
73
+ string,
74
+ { label: string; panel: IMovableSectionDestination }
75
+ > {
76
+ return this._targets;
77
+ }
78
+ }
@@ -1,5 +1,6 @@
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 */
3
4
 
4
5
  import type { IChangedArgs } from '@jupyterlab/coreutils';
5
6
  import { PathExt } from '@jupyterlab/coreutils';
@@ -280,6 +281,11 @@ export namespace ISessionContext {
280
281
  */
281
282
  readonly shouldStart?: boolean;
282
283
 
284
+ /**
285
+ * Reuse an existing session on the current path (default `true`).
286
+ */
287
+ readonly shouldReuse?: boolean;
288
+
283
289
  /**
284
290
  * A kernel can be started (default `true`).
285
291
  */
@@ -802,7 +808,8 @@ export class SessionContext implements ISessionContext {
802
808
  * @returns A promise that resolves with whether to ask the user to select a kernel.
803
809
  *
804
810
  * #### Notes
805
- * If a server session exists on the current path, we will connect to it.
811
+ * If a server session exists on the current path, we will connect to it
812
+ * unless `kernelPreference.shouldReuse === false`.
806
813
  * If preferences include disabling `canStart` or `shouldStart`, no
807
814
  * server session will be started.
808
815
  * If a kernel id is given, we attempt to start a session with that id.
@@ -834,16 +841,21 @@ export class SessionContext implements ISessionContext {
834
841
  const manager = this.sessionManager;
835
842
  await manager.ready;
836
843
  await manager.refreshRunning();
837
- const model = find(manager.running(), item => {
838
- return item.path === this._path;
839
- });
840
- if (model) {
841
- try {
842
- const session = manager.connectTo({ model });
843
- this._handleNewSession(session);
844
- } catch (err) {
845
- void this._handleSessionError(err);
846
- return Promise.reject(err);
844
+ const preference = this.kernelPreference;
845
+ const shouldConnectToPathSession = preference.shouldReuse !== false;
846
+
847
+ if (shouldConnectToPathSession) {
848
+ const model = find(manager.running(), item => {
849
+ return item.path === this._path;
850
+ });
851
+ if (model) {
852
+ try {
853
+ const session = manager.connectTo({ model });
854
+ this._handleNewSession(session);
855
+ } catch (err) {
856
+ void this._handleSessionError(err);
857
+ return Promise.reject(err);
858
+ }
847
859
  }
848
860
  }
849
861
 
@@ -1,5 +1,6 @@
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 */
3
4
 
4
5
  import type { IChangedArgs } from '@jupyterlab/coreutils';
5
6
  import { URLExt } from '@jupyterlab/coreutils';
@@ -378,7 +379,7 @@ export class ThemeManager implements IThemeManager {
378
379
  */
379
380
  private _incrFontSize(key: string, add: boolean = true): Promise<void> {
380
381
  // get the numeric and unit parts of the current font size
381
- const parts = (this.getCSS(key) ?? '13px').split(/([a-zA-Z]+)/);
382
+ const parts = (this.getCSS(key) ?? '13px').split(/([a-z]+)/i);
382
383
 
383
384
  // determine the increment
384
385
  const incr = (add ? 1 : -1) * (parts[1] === 'em' ? 0.1 : 1);
package/src/tokens.ts CHANGED
@@ -7,7 +7,7 @@ import type { ISettingRegistry } from '@jupyterlab/settingregistry';
7
7
  import { Token } from '@lumino/coreutils';
8
8
  import type { IDisposable } from '@lumino/disposable';
9
9
  import type { ISignal } from '@lumino/signaling';
10
- import type { CommandPalette, Widget } from '@lumino/widgets';
10
+ import type { AccordionPanel, CommandPalette, Widget } from '@lumino/widgets';
11
11
  import type { ISessionContext } from './sessioncontext';
12
12
  import type { Licenses } from './licenses';
13
13
 
@@ -419,3 +419,224 @@ export const IToolbarWidgetRegistry = new Token<IToolbarWidgetRegistry>(
419
419
  `A registry for toolbar widgets. Require this
420
420
  if you want to build the toolbar dynamically from a data definition (stored in settings for example).`
421
421
  );
422
+
423
+ /**
424
+ * A section entry returned by {@link IMovableSectionSource.getSections}.
425
+ *
426
+ * Bundles the three pieces of information the move plugin needs to identify,
427
+ * display, and transfer a sidebar section.
428
+ */
429
+ export interface ISectionEntry {
430
+ /**
431
+ * Stable identifier for this section, equal to the widget's Lumino `id`.
432
+ *
433
+ * The move plugin uses this to persist which sections have been moved and
434
+ * to restore them to the correct panel on reload.
435
+ */
436
+ readonly id: string;
437
+
438
+ /**
439
+ * The `.jp-AccordionPanel-title` DOM element rendered by Lumino as the
440
+ * visual header of this section.
441
+ *
442
+ * The move plugin attaches the `jp-movable-section` CSS class to this node
443
+ * so that Lumino's context-menu selector fires when the user right-clicks
444
+ * the header.
445
+ */
446
+ readonly titleNode: HTMLElement;
447
+
448
+ /**
449
+ * The content widget for this section.
450
+ */
451
+ readonly widget: Widget;
452
+ }
453
+
454
+ /**
455
+ * Implemented by sidebar panels whose accordion sections can be moved to
456
+ * another panel by the user.
457
+ *
458
+ * Register an implementation with
459
+ * {@link IMovableSectionRegistry.registerSource}.
460
+ */
461
+ export interface IMovableSectionSource {
462
+ /**
463
+ * Return the currently-available sections with their title DOM nodes.
464
+ */
465
+ getSections(): ReadonlyArray<ISectionEntry>;
466
+
467
+ /**
468
+ * Detach the section identified by `sectionId` and return its widget so
469
+ * the move plugin can hand it to a target panel.
470
+ *
471
+ * A typical implementation sets `widget.parent = null`, which detaches the
472
+ * widget from the `AccordionPanel` without destroying it. Returns `null` if
473
+ * no section with the given id currently exists in this panel.
474
+ *
475
+ * @param sectionId - The {@link ISectionEntry.id} of the section to remove.
476
+ */
477
+ removeSectionById(sectionId: string): Widget | null;
478
+
479
+ /**
480
+ * Re-attach a widget that was previously removed by
481
+ * {@link removeSectionById}.
482
+ *
483
+ * Called when the user chooses "Move back to …" on a section that was
484
+ * originally owned by this panel. A typical implementation calls
485
+ * `this.addWidget(widget)`.
486
+ *
487
+ * @param widget - The widget returned by an earlier {@link removeSectionById}
488
+ * call.
489
+ */
490
+ reinsertSection(widget: Widget): void;
491
+
492
+ /**
493
+ * The `AccordionPanel` that renders this sidebar's sections.
494
+ *
495
+ * The move plugin reads this to set up drag-to-reorder handles after a
496
+ * section is moved.
497
+ */
498
+ readonly accordionPanel: AccordionPanel | null;
499
+
500
+ /**
501
+ * Emitted each time a new section widget is added to this panel.
502
+ *
503
+ * Implementations should emit this signal from `addWidget` (or equivalent)
504
+ * with a fully-populated {@link ISectionEntry} for the newly added widget.
505
+ */
506
+ readonly sectionAdded: ISignal<this, ISectionEntry>;
507
+ }
508
+
509
+ /**
510
+ * Implemented by panels that can host sections moved in from another sidebar.
511
+ *
512
+ * Register an implementation with
513
+ * {@link IMovableSectionRegistry.registerTarget}.
514
+ */
515
+ export interface IMovableSectionDestination {
516
+ /**
517
+ * Insert a section widget into this panel.
518
+ *
519
+ * Called by the move plugin when the user selects "Move to …" from the
520
+ * context menu. A typical implementation calls `this.addWidget(widget)`.
521
+ *
522
+ * @param widget - The widget detached from its source panel.
523
+ */
524
+ addSection(widget: Widget): void;
525
+
526
+ /**
527
+ * Remove a section widget that was previously added via {@link addSection}.
528
+ *
529
+ * Called by the move plugin when the user moves the section back to its
530
+ * original panel. A typical implementation sets `widget.parent = null`.
531
+ *
532
+ * @param widget - The widget to detach.
533
+ */
534
+ removeSectionWidget(widget: Widget): void;
535
+
536
+ /**
537
+ * All section widgets currently hosted by this panel.
538
+ *
539
+ * Queried by the move plugin during state restoration to find sections that
540
+ * were persisted as belonging to this panel. Must stay in sync with
541
+ * {@link addSection} and {@link removeSectionWidget} calls.
542
+ */
543
+ readonly sections: ReadonlyArray<Widget>;
544
+
545
+ /**
546
+ * The `AccordionPanel` that wraps the hosted sections, or `null` if none
547
+ * has been created yet.
548
+ *
549
+ * The move plugin reads this to set up drag-to-reorder handles and to access
550
+ * the title elements of hosted sections.
551
+ */
552
+ readonly accordionPanel: AccordionPanel | null;
553
+ }
554
+
555
+ /**
556
+ * Registry that pairs source and target panels so the move plugin can wire up
557
+ * context-menu "Move to …" actions between them.
558
+ */
559
+ export interface IMovableSectionRegistry {
560
+ /**
561
+ * Register a sidebar as a source of moveable sections.
562
+ *
563
+ * After registration the move plugin adds a "Move to <target>" context-menu
564
+ * item to each section header in `sidebar`. The `label` appears in the menu
565
+ * as "Move back to <label>" on the destination side.
566
+ *
567
+ * @param id - Stable plugin-scoped identifier, e.g.
568
+ * `'@my-org/my-ext:panel'`. Must be unique across all registered sources.
569
+ * @param label - Human-readable panel name shown in the context menu.
570
+ * @param sidebar - The panel implementing {@link IMovableSectionSource}.
571
+ */
572
+ registerSource(
573
+ id: string,
574
+ label: string,
575
+ sidebar: IMovableSectionSource
576
+ ): void;
577
+
578
+ /**
579
+ * Register a panel as a destination that can receive sections.
580
+ *
581
+ * After registration the move plugin adds a "Move to <label>" context-menu
582
+ * item to eligible section headers in all registered source panels.
583
+ *
584
+ * @param id - Stable plugin-scoped identifier. Must be unique across all
585
+ * registered targets.
586
+ * @param label - Human-readable panel name shown in the context menu.
587
+ * @param panel - The panel implementing {@link IMovableSectionDestination}.
588
+ */
589
+ registerTarget(
590
+ id: string,
591
+ label: string,
592
+ panel: IMovableSectionDestination
593
+ ): void;
594
+
595
+ /**
596
+ * Return all registered source sidebars keyed by their `id`.
597
+ */
598
+ getSources(): ReadonlyMap<
599
+ string,
600
+ { label: string; sidebar: IMovableSectionSource }
601
+ >;
602
+
603
+ /**
604
+ * Return all registered target panels keyed by their `id`.
605
+ */
606
+ getTargets(): ReadonlyMap<
607
+ string,
608
+ { label: string; panel: IMovableSectionDestination }
609
+ >;
610
+
611
+ /**
612
+ * Fired each time a new source sidebar is registered via
613
+ * {@link registerSource}.
614
+ *
615
+ * The move plugin listens to this signal to retroactively wire up context
616
+ * menus for sources that register after the plugin has already activated.
617
+ */
618
+ readonly sourcePanelRegistered: ISignal<
619
+ IMovableSectionRegistry,
620
+ { id: string; label: string; sidebar: IMovableSectionSource }
621
+ >;
622
+
623
+ /**
624
+ * Fired each time a new target panel is registered via
625
+ * {@link registerTarget}.
626
+ *
627
+ * The move plugin listens to this signal to add the new target as an option
628
+ * in the context menus of all currently-registered source panels.
629
+ */
630
+ readonly targetPanelRegistered: ISignal<
631
+ IMovableSectionRegistry,
632
+ { id: string; label: string; panel: IMovableSectionDestination }
633
+ >;
634
+ }
635
+
636
+ /**
637
+ * The movable section registry token.
638
+ */
639
+ export const IMovableSectionRegistry = new Token<IMovableSectionRegistry>(
640
+ '@jupyterlab/apputils:IMovableSectionRegistry',
641
+ 'A registry for panels that can exchange moveable sections.'
642
+ );
@@ -2,6 +2,7 @@
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 */
5
6
 
6
7
  import type { IObservableList } from '@jupyterlab/observables';
7
8
  import { ObservableList } from '@jupyterlab/observables';
@@ -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
-
6
5
  import {
7
6
  CommandToolbarButton,
8
7
  LabIcon,
@@ -14,6 +13,10 @@ import type { IToolbarWidgetRegistry, ToolbarRegistry } from '../tokens';
14
13
  import type { ISignal } from '@lumino/signaling';
15
14
  import { Signal } from '@lumino/signaling';
16
15
 
16
+ interface IWidgetWithToolbar extends Widget {
17
+ toolbar: Toolbar;
18
+ }
19
+
17
20
  /**
18
21
  * Concrete implementation of IToolbarWidgetRegistry interface
19
22
  */
@@ -151,7 +154,7 @@ export function createDefaultFactory(
151
154
  const args = { toolbar: true, ...tArgs };
152
155
  const icon = tIcon ? LabIcon.resolve({ icon: tIcon }) : undefined;
153
156
 
154
- const toolbar = (widget as any).toolbar as Toolbar;
157
+ const toolbar = (widget as IWidgetWithToolbar).toolbar;
155
158
 
156
159
  // If there is an icon, undefined label will results in no label
157
160
  // otherwise the label will be set using the setting or the command label
@@ -1,5 +1,6 @@
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 */
3
4
 
4
5
  import type { IRestorable } from '@jupyterlab/statedb';
5
6
  import { RestorablePool } from '@jupyterlab/statedb';
@@ -134,7 +134,7 @@ namespace Private {
134
134
  return;
135
135
  }
136
136
 
137
- const reported = newValue.replace(/\-\d+$/, '');
137
+ const reported = newValue.replace(/-\d+$/, '');
138
138
 
139
139
  // Store the reported window name.
140
140
  known[reported] = null;
package/style/dialog.css CHANGED
@@ -17,9 +17,7 @@
17
17
  width: 100%;
18
18
  height: 100%;
19
19
  background: var(--jp-dialog-background);
20
- /* stylelint-disable */
21
20
  container-type: inline-size;
22
- /* stylelint-enable */
23
21
  }
24
22
 
25
23
  .jp-Dialog-content {
@@ -59,7 +57,9 @@ button.jp-Dialog-button:disabled {
59
57
  }
60
58
 
61
59
  button.jp-Dialog-button:focus {
62
- outline: 1px solid var(--jp-brand-color1);
60
+ outline-width: var(--jp-focus-outline-width);
61
+ outline-color: var(--jp-focus-outline-color);
62
+ outline-style: solid;
63
63
  outline-offset: 4px;
64
64
  -moz-outline-radius: 0;
65
65
  }
@@ -76,15 +76,21 @@ button.jp-Dialog-button.jp-mod-styled.jp-mod-reject:focus {
76
76
  }
77
77
 
78
78
  button.jp-Dialog-button.jp-mod-styled.jp-mod-accept:focus {
79
- outline: 1px solid var(--jp-accept-color-normal, var(--jp-brand-color1));
79
+ outline-width: var(--jp-focus-outline-width);
80
+ outline-color: var(--jp-accept-color-normal, var(--jp-focus-outline-color));
81
+ outline-style: solid;
80
82
  }
81
83
 
82
84
  button.jp-Dialog-button.jp-mod-styled.jp-mod-warn:focus {
83
- outline: 1px solid var(--jp-warn-color-normal, var(--jp-error-color1));
85
+ outline-width: var(--jp-focus-outline-width);
86
+ outline-color: var(--jp-warn-color-normal, var(--jp-error-color1));
87
+ outline-style: solid;
84
88
  }
85
89
 
86
90
  button.jp-Dialog-button.jp-mod-styled.jp-mod-reject:focus {
87
- outline: 1px solid var(--jp-reject-color-normal, var(--md-grey-600, #757575));
91
+ outline-width: var(--jp-focus-outline-width);
92
+ outline-color: var(--jp-reject-color-normal, var(--md-grey-600, #757575));
93
+ outline-style: solid;
88
94
  }
89
95
 
90
96
  button.jp-Dialog-close-button {
@@ -164,9 +170,7 @@ button.jp-Dialog-close-button {
164
170
  margin-right: 12px;
165
171
  }
166
172
 
167
- /* stylelint-disable */
168
173
  @container (max-width: 560px) {
169
- /* stylelint-enable */
170
174
  .jp-Dialog-footer {
171
175
  flex-direction: column;
172
176
  align-items: center;