@jupyterlab/application 4.7.0-alpha.1 → 4.7.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.
- package/lib/dockpanel.d.ts +44 -0
- package/lib/dockpanel.js +174 -36
- package/lib/dockpanel.js.map +1 -1
- package/lib/lab.d.ts +29 -1
- package/lib/lab.js +30 -3
- package/lib/lab.js.map +1 -1
- package/lib/layoutrestorer.js +129 -21
- package/lib/layoutrestorer.js.map +1 -1
- package/lib/shell.js +10 -6
- package/lib/shell.js.map +1 -1
- package/lib/utils.js +9 -9
- package/lib/utils.js.map +1 -1
- package/package.json +13 -13
- package/src/dockpanel.ts +182 -37
- package/src/lab.ts +57 -3
- package/src/layoutrestorer.ts +150 -26
- package/src/shell.ts +12 -4
- package/src/utils.ts +11 -17
- package/style/buttons.css +6 -6
package/src/layoutrestorer.ts
CHANGED
|
@@ -15,7 +15,7 @@ import type {
|
|
|
15
15
|
} from '@lumino/coreutils';
|
|
16
16
|
import { JSONExt, PromiseDelegate, Token } from '@lumino/coreutils';
|
|
17
17
|
import { AttachedProperty } from '@lumino/properties';
|
|
18
|
-
import type { DockPanel, Widget } from '@lumino/widgets';
|
|
18
|
+
import type { DockLayout, DockPanel, Widget } from '@lumino/widgets';
|
|
19
19
|
import type { ILabShell } from './shell';
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -776,6 +776,33 @@ namespace Private {
|
|
|
776
776
|
create: owner => ''
|
|
777
777
|
});
|
|
778
778
|
|
|
779
|
+
/**
|
|
780
|
+
* The name of the widget at `index`, or, when that widget has no name, the
|
|
781
|
+
* name of the nearest widget with a name before it, else after it.
|
|
782
|
+
*
|
|
783
|
+
* #### Notes
|
|
784
|
+
* A widget without a name, such as one that a plugin adds on each start,
|
|
785
|
+
* is not restored, so the tab next to it takes its place.
|
|
786
|
+
*/
|
|
787
|
+
function nearestName(
|
|
788
|
+
widgets: ReadonlyArray<Widget>,
|
|
789
|
+
index: number
|
|
790
|
+
): string | null {
|
|
791
|
+
for (let i = Math.min(index, widgets.length - 1); i >= 0; i--) {
|
|
792
|
+
const name = nameProperty.get(widgets[i]);
|
|
793
|
+
if (name) {
|
|
794
|
+
return name;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
for (let i = index + 1; i < widgets.length; i++) {
|
|
798
|
+
const name = nameProperty.get(widgets[i]);
|
|
799
|
+
if (name) {
|
|
800
|
+
return name;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
return null;
|
|
804
|
+
}
|
|
805
|
+
|
|
779
806
|
/**
|
|
780
807
|
* Serialize individual areas within the main area.
|
|
781
808
|
*/
|
|
@@ -787,12 +814,16 @@ namespace Private {
|
|
|
787
814
|
}
|
|
788
815
|
|
|
789
816
|
if (area.type === 'tab-area') {
|
|
817
|
+
const widgets = area.widgets
|
|
818
|
+
.map(widget => nameProperty.get(widget))
|
|
819
|
+
.filter(name => !!name);
|
|
820
|
+
// Only the widgets with a name are saved: count the current index
|
|
821
|
+
// among them, or it points at another tab after a restore.
|
|
822
|
+
const current = nearestName(area.widgets, area.currentIndex);
|
|
790
823
|
return {
|
|
791
824
|
type: 'tab-area',
|
|
792
|
-
currentIndex:
|
|
793
|
-
widgets
|
|
794
|
-
.map(widget => nameProperty.get(widget))
|
|
795
|
-
.filter(name => !!name)
|
|
825
|
+
currentIndex: current ? widgets.indexOf(current) : 0,
|
|
826
|
+
widgets
|
|
796
827
|
};
|
|
797
828
|
}
|
|
798
829
|
|
|
@@ -815,7 +846,9 @@ namespace Private {
|
|
|
815
846
|
};
|
|
816
847
|
if (area) {
|
|
817
848
|
if (area.currentWidget) {
|
|
818
|
-
const current =
|
|
849
|
+
const current =
|
|
850
|
+
Private.nameProperty.get(area.currentWidget) ||
|
|
851
|
+
nearestInArea(area.dock?.main ?? null, area.currentWidget);
|
|
819
852
|
if (current) {
|
|
820
853
|
dehydrated.current = current;
|
|
821
854
|
}
|
|
@@ -824,6 +857,57 @@ namespace Private {
|
|
|
824
857
|
return dehydrated;
|
|
825
858
|
}
|
|
826
859
|
|
|
860
|
+
/**
|
|
861
|
+
* The name of the widget nearest to `widget` in the tab area that holds it,
|
|
862
|
+
* for a current widget that has no name and is not restored.
|
|
863
|
+
*/
|
|
864
|
+
function nearestInArea(
|
|
865
|
+
area: ILabShell.AreaConfig | null,
|
|
866
|
+
widget: Widget
|
|
867
|
+
): string | null {
|
|
868
|
+
if (!area) {
|
|
869
|
+
return null;
|
|
870
|
+
}
|
|
871
|
+
if (area.type === 'tab-area') {
|
|
872
|
+
const index = area.widgets.indexOf(widget);
|
|
873
|
+
return index === -1 ? null : nearestName(area.widgets, index);
|
|
874
|
+
}
|
|
875
|
+
for (const child of area.children) {
|
|
876
|
+
const name = nearestInArea(child, widget);
|
|
877
|
+
if (name) {
|
|
878
|
+
return name;
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
return null;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
/**
|
|
885
|
+
* Restore a saved tab area from the names of its widgets.
|
|
886
|
+
*
|
|
887
|
+
* #### Notes
|
|
888
|
+
* A saved widget that was not restored drops out: the current index follows
|
|
889
|
+
* the widget saved at `index`, or the nearest restored one before it.
|
|
890
|
+
*/
|
|
891
|
+
function restoreTabArea(
|
|
892
|
+
widgets: ReadonlyArray<string>,
|
|
893
|
+
index: number,
|
|
894
|
+
names: Map<string, Widget>
|
|
895
|
+
): DockLayout.ITabAreaConfig {
|
|
896
|
+
const restored: Widget[] = [];
|
|
897
|
+
let current = 0;
|
|
898
|
+
widgets.forEach((name, i) => {
|
|
899
|
+
const widget = names.get(name);
|
|
900
|
+
if (!widget) {
|
|
901
|
+
return;
|
|
902
|
+
}
|
|
903
|
+
if (i <= index) {
|
|
904
|
+
current = restored.length;
|
|
905
|
+
}
|
|
906
|
+
restored.push(widget);
|
|
907
|
+
});
|
|
908
|
+
return { type: 'tab-area', currentIndex: current, widgets: restored };
|
|
909
|
+
}
|
|
910
|
+
|
|
827
911
|
/**
|
|
828
912
|
* Deserialize individual areas within the main area.
|
|
829
913
|
*
|
|
@@ -852,23 +936,7 @@ namespace Private {
|
|
|
852
936
|
|
|
853
937
|
if (type === 'tab-area') {
|
|
854
938
|
const { currentIndex, widgets } = area as ITabArea;
|
|
855
|
-
|
|
856
|
-
type: 'tab-area',
|
|
857
|
-
currentIndex: currentIndex || 0,
|
|
858
|
-
widgets:
|
|
859
|
-
(widgets &&
|
|
860
|
-
(widgets
|
|
861
|
-
.map(widget => names.get(widget))
|
|
862
|
-
.filter(widget => !!widget) as Widget[])) ||
|
|
863
|
-
[]
|
|
864
|
-
};
|
|
865
|
-
|
|
866
|
-
// Make sure the current index is within bounds.
|
|
867
|
-
if (hydrated.currentIndex > hydrated.widgets.length - 1) {
|
|
868
|
-
hydrated.currentIndex = 0;
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
return hydrated;
|
|
939
|
+
return restoreTabArea(widgets || [], currentIndex || 0, names);
|
|
872
940
|
}
|
|
873
941
|
|
|
874
942
|
const { orientation, sizes, children } = area as ISplitArea;
|
|
@@ -904,12 +972,68 @@ namespace Private {
|
|
|
904
972
|
return null;
|
|
905
973
|
}
|
|
906
974
|
|
|
907
|
-
const name = (area as any).current || null;
|
|
975
|
+
const name: string | null = (area as any).current || null;
|
|
908
976
|
const dock = (area as any).dock || null;
|
|
977
|
+
const main = dock ? deserializeArea(dock, names) : null;
|
|
978
|
+
|
|
979
|
+
// The shell activates only the current widget. When the saved one did not
|
|
980
|
+
// come back, or had no name, use the tab that is shown in its place.
|
|
981
|
+
const currentWidget =
|
|
982
|
+
(name && (names.get(name) || nearestRestored(dock, name, names))) ||
|
|
983
|
+
selectedWidget(main);
|
|
909
984
|
|
|
910
985
|
return {
|
|
911
|
-
currentWidget
|
|
912
|
-
dock: dock ? { main
|
|
986
|
+
currentWidget,
|
|
987
|
+
dock: dock ? { main } : null
|
|
913
988
|
};
|
|
914
989
|
}
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* The widget that a restored tab area shows in place of the widget saved as
|
|
993
|
+
* `name`, when that widget did not come back.
|
|
994
|
+
*/
|
|
995
|
+
function nearestRestored(
|
|
996
|
+
area: ITabArea | ISplitArea | null,
|
|
997
|
+
name: string,
|
|
998
|
+
names: Map<string, Widget>
|
|
999
|
+
): Widget | null {
|
|
1000
|
+
if (!area) {
|
|
1001
|
+
return null;
|
|
1002
|
+
}
|
|
1003
|
+
if (area.type === 'tab-area') {
|
|
1004
|
+
const widgets = area.widgets || [];
|
|
1005
|
+
const index = widgets.indexOf(name);
|
|
1006
|
+
if (index === -1) {
|
|
1007
|
+
return null;
|
|
1008
|
+
}
|
|
1009
|
+
const restored = restoreTabArea(widgets, index, names);
|
|
1010
|
+
return restored.widgets[restored.currentIndex] ?? null;
|
|
1011
|
+
}
|
|
1012
|
+
for (const child of area.children || []) {
|
|
1013
|
+
const widget = nearestRestored(child, name, names);
|
|
1014
|
+
if (widget) {
|
|
1015
|
+
return widget;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
return null;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
/**
|
|
1022
|
+
* The widget that the first tab area with widgets shows.
|
|
1023
|
+
*/
|
|
1024
|
+
function selectedWidget(area: ILabShell.AreaConfig | null): Widget | null {
|
|
1025
|
+
if (!area) {
|
|
1026
|
+
return null;
|
|
1027
|
+
}
|
|
1028
|
+
if (area.type === 'tab-area') {
|
|
1029
|
+
return area.widgets[area.currentIndex] ?? null;
|
|
1030
|
+
}
|
|
1031
|
+
for (const child of area.children) {
|
|
1032
|
+
const widget = selectedWidget(child);
|
|
1033
|
+
if (widget) {
|
|
1034
|
+
return widget;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
return null;
|
|
1038
|
+
}
|
|
915
1039
|
}
|
package/src/shell.ts
CHANGED
|
@@ -1323,7 +1323,9 @@ export class LabShell extends Widget implements JupyterFrontEnd.IShell {
|
|
|
1323
1323
|
// Rehydrate the down area
|
|
1324
1324
|
if (downArea) {
|
|
1325
1325
|
const { currentWidget, widgets, size } = downArea;
|
|
1326
|
-
const collapsed =
|
|
1326
|
+
const collapsed =
|
|
1327
|
+
downArea.collapsed ??
|
|
1328
|
+
(size === undefined || size === null || size === 0);
|
|
1327
1329
|
|
|
1328
1330
|
const widgetIds = widgets?.map(widget => widget.id) ?? [];
|
|
1329
1331
|
const otherAreaWidgetIds = new Set<string>();
|
|
@@ -1390,12 +1392,18 @@ export class LabShell extends Widget implements JupyterFrontEnd.IShell {
|
|
|
1390
1392
|
}
|
|
1391
1393
|
}
|
|
1392
1394
|
|
|
1393
|
-
if (
|
|
1395
|
+
if (
|
|
1396
|
+
!collapsed &&
|
|
1397
|
+
(widgets?.length ?? 0) > 0 &&
|
|
1398
|
+
size !== undefined &&
|
|
1399
|
+
size !== null &&
|
|
1400
|
+
size > 0.0
|
|
1401
|
+
) {
|
|
1394
1402
|
this._showDownPanel(size);
|
|
1395
1403
|
this._downPanel.currentWidget?.activate();
|
|
1396
1404
|
} else {
|
|
1397
1405
|
this._hideDownPanel();
|
|
1398
|
-
if (size && size > 0.0) {
|
|
1406
|
+
if (size !== undefined && size !== null && size > 0.0) {
|
|
1399
1407
|
// Remember the saved size so a later expand restores the user's
|
|
1400
1408
|
// previous height. `_hideDownPanel` seeds `_lastDownAreaSize`
|
|
1401
1409
|
// from the current splitter, which at cold startup reflects the
|
|
@@ -2443,7 +2451,7 @@ namespace Private {
|
|
|
2443
2451
|
if (w.id && w.content instanceof SplitPanel) {
|
|
2444
2452
|
widgetStates[w.id] = {
|
|
2445
2453
|
sizes: w.content.relativeSizes() as number[],
|
|
2446
|
-
expansionStates: w.content.widgets.map(wi => wi.
|
|
2454
|
+
expansionStates: w.content.widgets.map(wi => !wi.isHidden)
|
|
2447
2455
|
};
|
|
2448
2456
|
}
|
|
2449
2457
|
});
|
package/src/utils.ts
CHANGED
|
@@ -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 { SemanticCommand } from '@jupyterlab/apputils';
|
|
8
7
|
import type { TranslationBundle } from '@jupyterlab/translation';
|
|
@@ -169,26 +168,21 @@ export function createSemanticCommand(
|
|
|
169
168
|
caption: concatenateTexts('caption'),
|
|
170
169
|
isEnabled: () => {
|
|
171
170
|
const isEnabled = reduceAttribute('isEnabled');
|
|
172
|
-
return
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
(defaultValues.isEnabled ?? false)
|
|
176
|
-
);
|
|
171
|
+
return isEnabled.length > 0
|
|
172
|
+
? !isEnabled.some(enabled => enabled === false)
|
|
173
|
+
: (defaultValues.isEnabled ?? false);
|
|
177
174
|
},
|
|
178
175
|
isToggled: () => {
|
|
179
176
|
const isToggled = reduceAttribute('isToggled');
|
|
180
|
-
return
|
|
181
|
-
isToggled.some(enabled => enabled === true)
|
|
182
|
-
(defaultValues.isToggled ?? false)
|
|
183
|
-
);
|
|
177
|
+
return isToggled.length > 0
|
|
178
|
+
? isToggled.some(enabled => enabled === true)
|
|
179
|
+
: (defaultValues.isToggled ?? false);
|
|
184
180
|
},
|
|
185
181
|
isVisible: () => {
|
|
186
182
|
const isVisible = reduceAttribute('isVisible');
|
|
187
|
-
return
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
(defaultValues.isVisible ?? true)
|
|
191
|
-
);
|
|
183
|
+
return isVisible.length > 0
|
|
184
|
+
? !isVisible.some(visible => visible === false)
|
|
185
|
+
: (defaultValues.isVisible ?? true);
|
|
192
186
|
},
|
|
193
187
|
execute: async () => {
|
|
194
188
|
const widget = shell.currentWidget;
|
|
@@ -199,7 +193,7 @@ export function createSemanticCommand(
|
|
|
199
193
|
commandId => commandId !== null && commands.isEnabled(commandId)
|
|
200
194
|
);
|
|
201
195
|
|
|
202
|
-
let result:
|
|
196
|
+
let result: unknown = null;
|
|
203
197
|
if (toExecute.length > 0) {
|
|
204
198
|
for (const commandId of toExecute) {
|
|
205
199
|
const args = { [SemanticCommand.WIDGET]: widget!.id };
|
|
@@ -219,7 +213,7 @@ export function createSemanticCommand(
|
|
|
219
213
|
|
|
220
214
|
function reduceAttribute(
|
|
221
215
|
attribute: keyof CommandRegistry.ICommandOptions
|
|
222
|
-
):
|
|
216
|
+
): unknown[] {
|
|
223
217
|
const widget = shell.currentWidget;
|
|
224
218
|
const commandIds = commandList.map(cmd =>
|
|
225
219
|
widget !== null ? cmd.getActiveCommandId(widget) : null
|
package/style/buttons.css
CHANGED
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
button.jp-mod-styled.jp-mod-accept {
|
|
39
39
|
background: var(--jp-accept-color-normal, var(--md-blue-500, #2196f3));
|
|
40
40
|
border: 0;
|
|
41
|
-
color: white;
|
|
41
|
+
color: var(--jp-accept-color-foreground, white);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
button.jp-mod-styled.jp-mod-accept:hover {
|
|
@@ -51,14 +51,14 @@ button.jp-mod-styled.jp-mod-accept:active {
|
|
|
51
51
|
|
|
52
52
|
button.jp-mod-styled.jp-mod-accept:focus-visible {
|
|
53
53
|
outline-width: var(--jp-focus-outline-width);
|
|
54
|
-
outline-color: var(--jp-accept-color
|
|
54
|
+
outline-color: var(--jp-accept-outline-color, var(--jp-focus-outline-color));
|
|
55
55
|
outline-style: solid;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
button.jp-mod-styled.jp-mod-reject {
|
|
59
59
|
background: var(--jp-reject-color-normal, var(--md-grey-500, #9e9e9e));
|
|
60
60
|
border: 0;
|
|
61
|
-
color: white;
|
|
61
|
+
color: var(--jp-reject-color-foreground, white);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
button.jp-mod-styled.jp-mod-reject:hover {
|
|
@@ -71,14 +71,14 @@ button.jp-mod-styled.jp-mod-reject:active {
|
|
|
71
71
|
|
|
72
72
|
button.jp-mod-styled.jp-mod-reject:focus-visible {
|
|
73
73
|
outline-width: var(--jp-focus-outline-width);
|
|
74
|
-
outline-color: var(--jp-reject-color
|
|
74
|
+
outline-color: var(--jp-reject-outline-color, var(--md-grey-700, #616161));
|
|
75
75
|
outline-style: solid;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
button.jp-mod-styled.jp-mod-warn {
|
|
79
79
|
background: var(--jp-warn-color-normal, var(--jp-error-color1));
|
|
80
80
|
border: 0;
|
|
81
|
-
color: white;
|
|
81
|
+
color: var(--jp-warn-color-foreground, white);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
button.jp-mod-styled.jp-mod-warn:hover {
|
|
@@ -91,7 +91,7 @@ button.jp-mod-styled.jp-mod-warn:active {
|
|
|
91
91
|
|
|
92
92
|
button.jp-mod-styled.jp-mod-warn:focus-visible {
|
|
93
93
|
outline-width: var(--jp-focus-outline-width);
|
|
94
|
-
outline-color: var(--jp-warn-color
|
|
94
|
+
outline-color: var(--jp-warn-outline-color, var(--md-red-700, #d32f2f));
|
|
95
95
|
outline-style: solid;
|
|
96
96
|
}
|
|
97
97
|
|