@jupyterlab/apputils 4.0.0-alpha.8 → 4.0.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 (81) 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.d.ts +9 -0
  15. package/lib/mainareawidget.js +29 -4
  16. package/lib/mainareawidget.js.map +1 -1
  17. package/lib/menufactory.js +14 -15
  18. package/lib/menufactory.js.map +1 -1
  19. package/lib/notification.d.ts +336 -0
  20. package/lib/notification.js +310 -0
  21. package/lib/notification.js.map +1 -0
  22. package/lib/runningSessions.js +2 -2
  23. package/lib/runningSessions.js.map +1 -1
  24. package/lib/sanitizer.d.ts +20 -7
  25. package/lib/sanitizer.js +34 -7
  26. package/lib/sanitizer.js.map +1 -1
  27. package/lib/semanticCommand.js +11 -2
  28. package/lib/semanticCommand.js.map +1 -1
  29. package/lib/sessioncontext.d.ts +53 -6
  30. package/lib/sessioncontext.js +100 -68
  31. package/lib/sessioncontext.js.map +1 -1
  32. package/lib/testutils.d.ts +5 -0
  33. package/lib/testutils.js +46 -0
  34. package/lib/testutils.js.map +1 -0
  35. package/lib/thememanager.js +20 -5
  36. package/lib/thememanager.js.map +1 -1
  37. package/lib/tokens.d.ts +21 -42
  38. package/lib/tokens.js.map +1 -1
  39. package/lib/toolbar/factory.d.ts +2 -1
  40. package/lib/toolbar/factory.js +132 -105
  41. package/lib/toolbar/factory.js.map +1 -1
  42. package/lib/toolbar/index.js +4 -0
  43. package/lib/toolbar/index.js.map +1 -1
  44. package/lib/toolbar/registry.d.ts +11 -0
  45. package/lib/toolbar/registry.js +20 -3
  46. package/lib/toolbar/registry.js.map +1 -1
  47. package/lib/toolbar/widget.d.ts +3 -0
  48. package/lib/toolbar/widget.js +8 -5
  49. package/lib/toolbar/widget.js.map +1 -1
  50. package/lib/widgettracker.d.ts +13 -1
  51. package/lib/widgettracker.js +29 -2
  52. package/lib/widgettracker.js.map +1 -1
  53. package/package.json +31 -30
  54. package/src/clipboard.ts +107 -0
  55. package/src/commandlinker.ts +209 -0
  56. package/src/commandpalette.ts +175 -0
  57. package/src/dialog.tsx +1133 -0
  58. package/src/domutils.ts +53 -0
  59. package/src/index.ts +78 -0
  60. package/src/inputdialog.ts +551 -0
  61. package/src/kernelstatuses.tsx +279 -0
  62. package/src/mainareawidget.ts +362 -0
  63. package/src/menufactory.ts +201 -0
  64. package/src/notification.ts +559 -0
  65. package/src/printing.ts +180 -0
  66. package/src/runningSessions.tsx +233 -0
  67. package/src/sanitizer.ts +986 -0
  68. package/src/semanticCommand.ts +77 -0
  69. package/src/sessioncontext.tsx +1774 -0
  70. package/src/testutils.ts +49 -0
  71. package/src/thememanager.ts +530 -0
  72. package/src/tokens.ts +351 -0
  73. package/src/toolbar/factory.ts +422 -0
  74. package/src/toolbar/index.ts +8 -0
  75. package/src/toolbar/registry.ts +158 -0
  76. package/src/toolbar/widget.tsx +242 -0
  77. package/src/widgettracker.ts +391 -0
  78. package/src/windowresolver.ts +218 -0
  79. package/style/dialog.css +16 -1
  80. package/style/inputdialog.css +5 -0
  81. package/style/materialcolors.css +5 -0
@@ -0,0 +1,201 @@
1
+ /*
2
+ * Copyright (c) Jupyter Development Team.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+
6
+ import { Text } from '@jupyterlab/coreutils';
7
+ import { ISettingRegistry } from '@jupyterlab/settingregistry';
8
+ import { LabIcon } from '@jupyterlab/ui-components';
9
+ import { JSONExt } from '@lumino/coreutils';
10
+ import { ContextMenu, Menu } from '@lumino/widgets';
11
+
12
+ /**
13
+ * Helper functions to build a menu from the settings
14
+ */
15
+ export namespace MenuFactory {
16
+ /**
17
+ * Menu constructor options
18
+ */
19
+ export interface IMenuOptions {
20
+ /**
21
+ * The unique menu identifier.
22
+ */
23
+ id: string;
24
+
25
+ /**
26
+ * The menu label.
27
+ */
28
+ label?: string;
29
+
30
+ /**
31
+ * The menu rank.
32
+ */
33
+ rank?: number;
34
+ }
35
+
36
+ /**
37
+ * Create menus from their description
38
+ *
39
+ * @param data Menubar description
40
+ * @param menuFactory Factory for empty menu
41
+ */
42
+ export function createMenus(
43
+ data: ISettingRegistry.IMenu[],
44
+ menuFactory: (options: IMenuOptions) => Menu
45
+ ): Menu[] {
46
+ return data
47
+ .filter(item => !item.disabled)
48
+ .sort((a, b) => (a.rank ?? Infinity) - (b.rank ?? Infinity))
49
+ .map(menuItem => {
50
+ return dataToMenu(menuItem, menuFactory);
51
+ });
52
+ }
53
+
54
+ /**
55
+ * Convert a menu description in a JupyterLabMenu object
56
+ *
57
+ * @param item Menu description
58
+ * @param menuFactory Empty menu factory
59
+ * @returns The menu widget
60
+ */
61
+ function dataToMenu(
62
+ item: ISettingRegistry.IMenu,
63
+ menuFactory: (options: IMenuOptions) => Menu
64
+ ): Menu {
65
+ const menu = menuFactory(item);
66
+ menu.id = item.id;
67
+
68
+ // Set the label in case the menu factory did not.
69
+ if (!menu.title.label) {
70
+ menu.title.label = item.label ?? Text.titleCase(menu.id.trim());
71
+ }
72
+
73
+ if (item.icon) {
74
+ menu.title.icon = LabIcon.resolve({ icon: item.icon });
75
+ }
76
+ if (item.mnemonic !== undefined) {
77
+ menu.title.mnemonic = item.mnemonic;
78
+ }
79
+
80
+ item.items
81
+ ?.filter(item => !item.disabled)
82
+ .sort((a, b) => (a.rank ?? Infinity) - (b.rank ?? Infinity))
83
+ .map(item => {
84
+ addItem(item, menu, menuFactory);
85
+ });
86
+ return menu;
87
+ }
88
+
89
+ /**
90
+ * Convert an item description in a context menu item object
91
+ *
92
+ * @param item Context menu item
93
+ * @param menu Context menu to populate
94
+ * @param menuFactory Empty menu factory
95
+ */
96
+ export function addContextItem(
97
+ item: ISettingRegistry.IContextMenuItem,
98
+ menu: ContextMenu,
99
+ menuFactory: (options: IMenuOptions) => Menu
100
+ ): void {
101
+ const { submenu, ...newItem } = item;
102
+ // Commands may not have been registered yet; so we don't force it to exist
103
+ menu.addItem({
104
+ ...newItem,
105
+ submenu: submenu ? dataToMenu(submenu, menuFactory) : null
106
+ } as any);
107
+ }
108
+
109
+ /**
110
+ * Convert an item description in a menu item object
111
+ *
112
+ * @param item Menu item
113
+ * @param menu Menu to populate
114
+ * @param menuFactory Empty menu factory
115
+ */
116
+ function addItem(
117
+ item: ISettingRegistry.IMenuItem,
118
+ menu: Menu,
119
+ menuFactory: (options: IMenuOptions) => Menu
120
+ ): void {
121
+ const { submenu, ...newItem } = item;
122
+ // Commands may not have been registered yet; so we don't force it to exist
123
+ menu.addItem({
124
+ ...newItem,
125
+ submenu: submenu ? dataToMenu(submenu, menuFactory) : null
126
+ } as any);
127
+ }
128
+
129
+ /**
130
+ * Update an existing list of menu and returns
131
+ * the new elements.
132
+ *
133
+ * #### Note
134
+ * New elements are added to the current menu list.
135
+ *
136
+ * @param menus Current menus
137
+ * @param data New description to take into account
138
+ * @param menuFactory Empty menu factory
139
+ * @returns Newly created menus
140
+ */
141
+ export function updateMenus(
142
+ menus: Menu[],
143
+ data: ISettingRegistry.IMenu[],
144
+ menuFactory: (options: IMenuOptions) => Menu
145
+ ): Menu[] {
146
+ const newMenus: Menu[] = [];
147
+ data.forEach(item => {
148
+ const menu = menus.find(menu => menu.id === item.id);
149
+ if (menu) {
150
+ mergeMenus(item, menu, menuFactory);
151
+ } else {
152
+ if (!item.disabled) {
153
+ newMenus.push(dataToMenu(item, menuFactory));
154
+ }
155
+ }
156
+ });
157
+ menus.push(...newMenus);
158
+ return newMenus;
159
+ }
160
+
161
+ function mergeMenus(
162
+ item: ISettingRegistry.IMenu,
163
+ menu: Menu,
164
+ menuFactory: (options: IMenuOptions) => Menu
165
+ ) {
166
+ if (item.disabled) {
167
+ menu.dispose();
168
+ } else {
169
+ item.items?.forEach(entry => {
170
+ const existingItem = menu?.items.find(
171
+ (i, idx) =>
172
+ i.type === entry.type &&
173
+ i.command === (entry.command ?? '') &&
174
+ i.submenu?.id === entry.submenu?.id
175
+ );
176
+
177
+ if (existingItem && entry.type !== 'separator') {
178
+ if (entry.disabled) {
179
+ menu.removeItem(existingItem);
180
+ } else {
181
+ switch (entry.type ?? 'command') {
182
+ case 'command':
183
+ if (entry.command) {
184
+ if (!JSONExt.deepEqual(existingItem.args, entry.args ?? {})) {
185
+ addItem(entry, menu, menuFactory);
186
+ }
187
+ }
188
+ break;
189
+ case 'submenu':
190
+ if (entry.submenu) {
191
+ mergeMenus(entry.submenu, existingItem.submenu!, menuFactory);
192
+ }
193
+ }
194
+ }
195
+ } else {
196
+ addItem(entry, menu, menuFactory);
197
+ }
198
+ });
199
+ }
200
+ }
201
+ }