xtralab 0.14.0 → 0.15.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 (52) hide show
  1. package/lib/customPanel/index.d.ts +7 -0
  2. package/lib/customPanel/index.js +74 -0
  3. package/lib/fileBrowser/commands.js +13 -1
  4. package/lib/fileBrowser/contents.d.ts +11 -0
  5. package/lib/fileBrowser/contents.js +28 -0
  6. package/lib/fileBrowser/dragAndDrop.d.ts +66 -0
  7. package/lib/fileBrowser/dragAndDrop.js +115 -0
  8. package/lib/fileBrowser/fileBrowser.d.ts +2 -0
  9. package/lib/fileBrowser/fileBrowser.js +151 -197
  10. package/lib/fileBrowser/index.js +39 -6
  11. package/lib/fileBrowser/widget.d.ts +44 -5
  12. package/lib/fileBrowser/widget.js +153 -14
  13. package/lib/index.js +4 -0
  14. package/lib/launcher/agents.d.ts +1 -1
  15. package/lib/launcher/agents.js +15 -2
  16. package/lib/launcher/icons.js +15 -4
  17. package/lib/launcher/schemaDefaults.d.ts +2 -9
  18. package/lib/launcher/schemaDefaults.js +37 -13
  19. package/lib/menuBar/icons.d.ts +6 -0
  20. package/lib/menuBar/icons.js +13 -0
  21. package/lib/menuBar/index.d.ts +15 -0
  22. package/lib/menuBar/index.js +164 -0
  23. package/lib/sidebar/index.d.ts +7 -13
  24. package/lib/sidebar/index.js +80 -46
  25. package/lib/terminals/index.d.ts +5 -3
  26. package/lib/terminals/index.js +17 -6
  27. package/lib/terminals/widget.d.ts +29 -25
  28. package/lib/terminals/widget.js +150 -65
  29. package/package.json +1 -1
  30. package/schema/launcher.json +2 -2
  31. package/schema/menu-bar.json +37 -0
  32. package/schema/sidebar.json +47 -7
  33. package/src/customPanel/index.ts +104 -0
  34. package/src/fileBrowser/commands.ts +14 -1
  35. package/src/fileBrowser/contents.ts +30 -0
  36. package/src/fileBrowser/dragAndDrop.ts +178 -0
  37. package/src/fileBrowser/fileBrowser.tsx +183 -225
  38. package/src/fileBrowser/index.ts +41 -6
  39. package/src/fileBrowser/widget.tsx +195 -14
  40. package/src/index.ts +4 -0
  41. package/src/launcher/agents.ts +16 -3
  42. package/src/launcher/icons.ts +16 -4
  43. package/src/launcher/schemaDefaults.ts +43 -13
  44. package/src/menuBar/icons.ts +14 -0
  45. package/src/menuBar/index.ts +195 -0
  46. package/src/sidebar/index.ts +95 -52
  47. package/src/terminals/index.ts +24 -6
  48. package/src/terminals/widget.tsx +186 -87
  49. package/style/base.css +22 -34
  50. package/style/customPanel.css +9 -0
  51. package/style/index.js +1 -0
  52. package/style/terminals.css +19 -77
@@ -0,0 +1,195 @@
1
+ import {
2
+ ILabShell,
3
+ JupyterFrontEnd,
4
+ JupyterFrontEndPlugin
5
+ } from '@jupyterlab/application';
6
+ import { ICommandPalette } from '@jupyterlab/apputils';
7
+ import { IMainMenu, MainMenu } from '@jupyterlab/mainmenu';
8
+ import { ISettingRegistry } from '@jupyterlab/settingregistry';
9
+ import { ITranslator, nullTranslator } from '@jupyterlab/translation';
10
+ import { CommandToolbarButton, MenuSvg } from '@jupyterlab/ui-components';
11
+ import { Menu, Widget } from '@lumino/widgets';
12
+
13
+ import { mainMenuIcon } from './icons';
14
+
15
+ const PLUGIN_ID = 'xtralab:menu-bar';
16
+
17
+ const OPEN_COMMAND = 'xtralab:open-main-menu';
18
+ const TOGGLE_COMMAND = 'xtralab:toggle-menu-bar';
19
+
20
+ /**
21
+ * How long after the popup closes a button press still counts as "close
22
+ * only". An open Lumino menu closes itself on any outside press from a
23
+ * document `pointerdown` listener in the capture phase, which runs before
24
+ * the button's own mousedown handler — so without this window, pressing the
25
+ * button while the popup is open would close it and instantly reopen it.
26
+ */
27
+ const REOPEN_GUARD_MS = 250;
28
+
29
+ /**
30
+ * Collapse the main menu bar into a compact menu button.
31
+ *
32
+ * The menu bar is hidden and a hamburger button in the top bar opens the same
33
+ * menus as a vertical popup. The popup reuses the live `RankedMenu` instances
34
+ * owned by the `MainMenu`, so menus added or removed at runtime are reflected
35
+ * without duplication.
36
+ *
37
+ * Hiding covers the `jp-menu-panel` container too, which has its own
38
+ * `min-height` and would otherwise leave an empty strip. The "Show Menu Bar"
39
+ * toggle restores the classic bar.
40
+ */
41
+ const plugin: JupyterFrontEndPlugin<void> = {
42
+ id: PLUGIN_ID,
43
+ description: 'Collapse the main menu bar into a compact menu button.',
44
+ autoStart: true,
45
+ requires: [IMainMenu, ILabShell, ISettingRegistry],
46
+ optional: [ICommandPalette, ITranslator],
47
+ activate: (
48
+ app: JupyterFrontEnd,
49
+ mainMenu: IMainMenu,
50
+ labShell: ILabShell,
51
+ settingRegistry: ISettingRegistry,
52
+ palette: ICommandPalette | null,
53
+ translator: ITranslator | null
54
+ ): void => {
55
+ const { commands } = app;
56
+ const trans = (translator ?? nullTranslator).load('jupyterlab');
57
+
58
+ if (!(mainMenu instanceof MainMenu)) {
59
+ return;
60
+ }
61
+
62
+ const menuPanel = (): Widget | null =>
63
+ mainMenu.parent ??
64
+ Array.from(labShell.widgets('top')).find(w => w.id === 'jp-menu-panel') ??
65
+ null;
66
+
67
+ let visible = false;
68
+ let button: CommandToolbarButton | null = null;
69
+ let settings: ISettingRegistry.ISettings | null = null;
70
+
71
+ const applyVisibility = (value: boolean): void => {
72
+ visible = value;
73
+ mainMenu.setHidden(!value);
74
+ menuPanel()?.setHidden(!value);
75
+ button?.setHidden(value);
76
+ commands.notifyCommandChanged(TOGGLE_COMMAND);
77
+ };
78
+
79
+ mainMenu.hide();
80
+ menuPanel()?.hide();
81
+
82
+ let popup: Menu | null = null;
83
+ let popupClosedAt = 0;
84
+
85
+ const openMenu = (): void => {
86
+ if (visible) {
87
+ // The classic bar is on screen; behave like keyboard menu
88
+ // activation instead of opening a redundant popup that would
89
+ // compete with the bar for the same Menu instances.
90
+ mainMenu.activeIndex = 0;
91
+ mainMenu.openActiveMenu();
92
+ return;
93
+ }
94
+ if (Date.now() - popupClosedAt < REOPEN_GUARD_MS) {
95
+ return;
96
+ }
97
+
98
+ // One popup instance, rebuilt from the bar's current menus on every
99
+ // open so runtime menu changes stay reflected. It is a plain Lumino
100
+ // Menu rather than a MenuSvg: MenuSvg.insertItem re-wraps each
101
+ // submenu's renderer and insertItem on every call, which would pile
102
+ // wrappers onto the shared menus across reopens. The svg renderer and
103
+ // themed-container class are applied directly instead, matching how
104
+ // the real menus are constructed in MainMenu.
105
+ if (popup === null) {
106
+ popup = new Menu({ commands, renderer: MenuSvg.defaultRenderer });
107
+ popup.addClass('jp-ThemedContainer');
108
+ popup.addClass('jp-xtralab-MainMenuPopup');
109
+ popup.aboutToClose.connect(() => {
110
+ popupClosedAt = Date.now();
111
+ });
112
+ } else {
113
+ popup.clearItems();
114
+ }
115
+
116
+ // Skip empty menus: MenuBar disables their headings, but submenu items
117
+ // have no such affordance and would open a blank panel.
118
+ for (const menu of mainMenu.menus) {
119
+ if (menu.items.length > 0) {
120
+ popup.addItem({ type: 'submenu', submenu: menu });
121
+ }
122
+ }
123
+
124
+ const anchor = button?.node.getBoundingClientRect();
125
+ // The 3px gap matches the detached-dropdown offset chrome.css gives
126
+ // the real menu bar's dropdowns (.lm-Menu.lm-MenuBar-menu).
127
+ popup.open(anchor?.left ?? 0, (anchor?.bottom ?? 0) + 3);
128
+ };
129
+
130
+ commands.addCommand(OPEN_COMMAND, {
131
+ label: trans.__('Open Menu'),
132
+ caption: trans.__('Open the main menu'),
133
+ icon: mainMenuIcon,
134
+ execute: openMenu
135
+ });
136
+
137
+ commands.addCommand(TOGGLE_COMMAND, {
138
+ label: trans.__('Show Menu Bar'),
139
+ caption: trans.__('Toggle the visibility of the main menu bar'),
140
+ isToggled: () => visible,
141
+ execute: async () => {
142
+ applyVisibility(!visible);
143
+ if (settings !== null) {
144
+ try {
145
+ await settings.set('visible', visible);
146
+ } catch (reason) {
147
+ console.error(
148
+ 'xtralab: failed to persist menu bar visibility',
149
+ reason
150
+ );
151
+ }
152
+ }
153
+ }
154
+ });
155
+
156
+ if (palette) {
157
+ const category = trans.__('Other');
158
+ palette.addItem({ command: OPEN_COMMAND, category });
159
+ palette.addItem({ command: TOGGLE_COMMAND, category });
160
+ }
161
+
162
+ Promise.all([settingRegistry.load(PLUGIN_ID), app.restored])
163
+ .then(([loaded]) => {
164
+ settings = loaded;
165
+
166
+ button = new CommandToolbarButton({
167
+ commands,
168
+ id: OPEN_COMMAND,
169
+ icon: mainMenuIcon,
170
+ label: '',
171
+ caption: trans.__('Menu'),
172
+ noFocusOnClick: true,
173
+ 'aria-haspopup': 'menu'
174
+ });
175
+ button.id = 'xtralab-main-menu-button';
176
+ button.addClass('jp-xtralab-TopBarButton');
177
+ labShell.add(button, 'top', { rank: 0 });
178
+
179
+ const update = (): void => {
180
+ applyVisibility(loaded.get('visible').composite as boolean);
181
+ };
182
+ update();
183
+ loaded.changed.connect(update);
184
+ })
185
+ .catch(reason => {
186
+ // Without settings the collapsed state cannot be managed (and the
187
+ // button was never added) — reveal the stock bar rather than leave
188
+ // the app with no reachable menus.
189
+ applyVisibility(true);
190
+ console.error(`Failed to load settings for ${PLUGIN_ID}`, reason);
191
+ });
192
+ }
193
+ };
194
+
195
+ export default plugin;
@@ -10,21 +10,46 @@ import type { Widget } from '@lumino/widgets';
10
10
  const PLUGIN_ID = 'xtralab:sidebar';
11
11
 
12
12
  /**
13
- * Each entry pairs an upstream sidebar widget id with the rank it was
14
- * originally added at. The ranks come from the upstream extensions —
15
- * `filebrowser-extension` adds the default browser at rank 100 and
16
- * `running-extension` adds the running panel at rank 200 — and we reuse
17
- * them when re-adding so the tab lands back in its usual position.
13
+ * `rank` is the fallback used when re-adding a hidden tab; the shipped
14
+ * `layout` setting normally wins because `LabShell.add` merges its
15
+ * per-widget options over the ones passed in.
18
16
  */
19
17
  interface ITarget {
20
18
  id: string;
21
19
  rank: number;
22
- settingKey: 'showDefaultFileBrowser' | 'showRunningSessions';
20
+ settingKey:
21
+ | 'showTerminals'
22
+ | 'showFileBrowser'
23
+ | 'showGitPanel'
24
+ | 'showDefaultFileBrowser'
25
+ | 'showRunningSessions'
26
+ | 'showSearchReplace';
23
27
  command: string;
24
28
  label: (trans: ReturnType<ITranslator['load']>) => string;
25
29
  }
26
30
 
27
31
  const TARGETS: ITarget[] = [
32
+ {
33
+ id: 'xtralab-running-terminals',
34
+ rank: 1,
35
+ settingKey: 'showTerminals',
36
+ command: 'xtralab:toggle-terminals',
37
+ label: trans => trans.__('Terminals')
38
+ },
39
+ {
40
+ id: 'xtralab:file-browser',
41
+ rank: 2,
42
+ settingKey: 'showFileBrowser',
43
+ command: 'xtralab:toggle-file-browser',
44
+ label: trans => trans.__('File Browser')
45
+ },
46
+ {
47
+ id: 'jp-git-sessions',
48
+ rank: 200,
49
+ settingKey: 'showGitPanel',
50
+ command: 'xtralab:toggle-git-panel',
51
+ label: trans => trans.__('Git')
52
+ },
28
53
  {
29
54
  id: 'filebrowser',
30
55
  rank: 100,
@@ -38,28 +63,29 @@ const TARGETS: ITarget[] = [
38
63
  settingKey: 'showRunningSessions',
39
64
  command: 'xtralab:toggle-running-sessions',
40
65
  label: trans => trans.__('Running Terminals and Kernels')
66
+ },
67
+ {
68
+ id: 'jp-search-replace',
69
+ rank: 900,
70
+ settingKey: 'showSearchReplace',
71
+ command: 'xtralab:toggle-search-replace',
72
+ label: trans => trans.__('Search and Replace')
41
73
  }
42
74
  ];
43
75
 
44
76
  /**
45
- * Lets the user toggle individual left-sidebar tabs from
46
- * View > Appearance > Left Sidebar. Removing a widget from a `LabShell`
47
- * side area is done by setting `widget.parent = null`: the StackedPanel
48
- * emits `widgetRemoved`, which the SideBarHandler responds to by removing
49
- * the matching tab. The widget instance is preserved, so we can re-add it
50
- * later via `labShell.add` with its original rank.
51
- *
52
- * The menu placement is contributed declaratively in
53
- * `schema/sidebar.json`, so this plugin only registers commands and
54
- * applies state — it does not touch `IMainMenu` directly.
55
- *
56
- * The preference is persisted to `xtralab:sidebar` settings so the choice
57
- * survives reloads.
77
+ * Toggles individual sidebar tabs from View > Appearance > Sidebars,
78
+ * whichever side a tab currently lives on. Hiding detaches the widget
79
+ * (`widget.parent = null`) while keeping the instance for a later
80
+ * re-add; the preference persists in this plugin's settings. Which side
81
+ * a hidden tab came from is only tracked in-memory, so after a reload a
82
+ * re-shown tab lands on the left. The menu placement is contributed
83
+ * declaratively in `schema/sidebar.json`.
58
84
  */
59
85
  const plugin: JupyterFrontEndPlugin<void> = {
60
86
  id: PLUGIN_ID,
61
87
  description:
62
- 'Toggle visibility of selected sidebar tabs (default file browser, running sessions) from the View menu.',
88
+ 'Toggle visibility of individual sidebar tabs from the View menu.',
63
89
  autoStart: true,
64
90
  requires: [ILabShell],
65
91
  optional: [ISettingRegistry, ITranslator],
@@ -72,31 +98,40 @@ const plugin: JupyterFrontEndPlugin<void> = {
72
98
  const trans = (translator ?? nullTranslator).load('jupyterlab');
73
99
  const { commands } = app;
74
100
 
75
- // Cache widget instances so we can re-add them after `widget.parent =
76
- // null` has detached them from the sidebar. The widget is no longer
77
- // reachable through `labShell.widgets('left')` once removed, so a
78
- // missing cache entry would leave us unable to bring the tab back.
101
+ // Detached widgets are unreachable via `labShell.widgets(...)`; keep
102
+ // instances here so hidden tabs can be re-added.
79
103
  const widgetCache = new Map<string, Widget>();
80
104
 
81
- const findInSidebar = (id: string): Widget | null => {
82
- for (const w of labShell.widgets('left')) {
83
- if (w.id === id) {
84
- return w;
105
+ // Side each hidden widget was removed from, so re-showing restores it
106
+ // there.
107
+ const hiddenFrom = new Map<string, 'left' | 'right'>();
108
+
109
+ const findInSidebars = (
110
+ id: string
111
+ ): { widget: Widget; area: 'left' | 'right' } | null => {
112
+ for (const area of ['left', 'right'] as const) {
113
+ for (const widget of labShell.widgets(area)) {
114
+ if (widget.id === id) {
115
+ return { widget, area };
116
+ }
85
117
  }
86
118
  }
87
119
  return null;
88
120
  };
89
121
 
122
+ const locate = (id: string): 'left' | 'right' | null =>
123
+ findInSidebars(id)?.area ?? null;
124
+
90
125
  const captureWidget = (id: string): Widget | null => {
91
126
  const cached = widgetCache.get(id);
92
127
  if (cached && !cached.isDisposed) {
93
128
  return cached;
94
129
  }
95
- const found = findInSidebar(id);
130
+ const found = findInSidebars(id);
96
131
  if (found) {
97
- widgetCache.set(id, found);
132
+ widgetCache.set(id, found.widget);
98
133
  }
99
- return found;
134
+ return found?.widget ?? null;
100
135
  };
101
136
 
102
137
  let settings: ISettingRegistry.ISettings | null = null;
@@ -112,19 +147,24 @@ const plugin: JupyterFrontEndPlugin<void> = {
112
147
  const apply = (target: ITarget): void => {
113
148
  const widget = captureWidget(target.id);
114
149
  if (!widget) {
115
- // The upstream widget hasn't been added yet (or the extension is
116
- // disabled). Nothing to do — the next time `apply` runs and finds
117
- // it, the preference will take effect.
150
+ // Not seen yet (extension disabled or not added) — nothing to do.
151
+ return;
152
+ }
153
+ const area = locate(target.id);
154
+ if (!area && widget.parent !== null) {
155
+ // Attached outside the sidebars — leave it alone.
118
156
  return;
119
157
  }
120
- const present = findInSidebar(target.id) !== null;
121
158
  const wantPresent = readPreference(target);
122
- if (wantPresent && !present) {
123
- labShell.add(widget, 'left', { rank: target.rank });
124
- } else if (!wantPresent && present) {
125
- // Setting `parent = null` triggers SideBarHandler's
126
- // `_onWidgetRemoved`, which strips the tab while leaving the
127
- // widget instance alive for a later re-add.
159
+ if (wantPresent && !area) {
160
+ labShell.add(widget, hiddenFrom.get(target.id) ?? 'left', {
161
+ rank: target.rank
162
+ });
163
+ hiddenFrom.delete(target.id);
164
+ } else if (!wantPresent && area) {
165
+ hiddenFrom.set(target.id, area);
166
+ // Detaching makes the SideBarHandler remove the tab while the
167
+ // widget instance stays alive for a later re-add.
128
168
  widget.parent = null;
129
169
  }
130
170
  };
@@ -139,14 +179,21 @@ const plugin: JupyterFrontEndPlugin<void> = {
139
179
  commands.addCommand(target.command, {
140
180
  label: target.label(trans),
141
181
  isToggled: () => readPreference(target),
182
+ isVisible: () => {
183
+ // List only tabs this plugin can manage: in a sidebar, or
184
+ // hidden by this plugin (`parent === null`).
185
+ const widget = captureWidget(target.id);
186
+ return (
187
+ widget !== null &&
188
+ (widget.parent === null || locate(target.id) !== null)
189
+ );
190
+ },
142
191
  execute: async () => {
143
192
  const next = !readPreference(target);
144
193
  if (settings) {
145
194
  try {
146
195
  await settings.set(target.settingKey, next);
147
- // `settings.changed` will fire and drive `apply` + the
148
- // command-state refresh. Returning here keeps the toggle's
149
- // single source of truth in the settings registry.
196
+ // `settings.changed` drives `apply` and the state refresh.
150
197
  return;
151
198
  } catch (reason) {
152
199
  console.error(
@@ -155,9 +202,8 @@ const plugin: JupyterFrontEndPlugin<void> = {
155
202
  );
156
203
  }
157
204
  }
158
- // No settings registry available (or the write failed): fall
159
- // back to applying the change in-memory so the toggle still
160
- // works for the current session.
205
+ // No settings registry (or the write failed): apply in-memory
206
+ // for the current session only.
161
207
  apply(target);
162
208
  commands.notifyCommandChanged(target.command);
163
209
  }
@@ -179,11 +225,8 @@ const plugin: JupyterFrontEndPlugin<void> = {
179
225
  }
180
226
 
181
227
  void app.restored.then(() => {
182
- // Capture references first so a hidden-on-startup widget is still
183
- // recoverable later. `apply` would also do the lookup, but only on
184
- // the targets that need to stay visible — by capturing every target
185
- // here we keep the cache populated for both directions of the
186
- // toggle.
228
+ // Capture every widget before applying, so tabs hidden on startup
229
+ // stay recoverable.
187
230
  for (const target of TARGETS) {
188
231
  captureWidget(target.id);
189
232
  }
@@ -3,7 +3,11 @@ import {
3
3
  JupyterFrontEnd,
4
4
  JupyterFrontEndPlugin
5
5
  } from '@jupyterlab/application';
6
- import { Dialog, showDialog } from '@jupyterlab/apputils';
6
+ import {
7
+ Dialog,
8
+ IMovableSectionRegistry,
9
+ showDialog
10
+ } from '@jupyterlab/apputils';
7
11
  import { ISettingRegistry } from '@jupyterlab/settingregistry';
8
12
  import { ITerminalTracker } from '@jupyterlab/terminal';
9
13
  import { ITranslator, nullTranslator } from '@jupyterlab/translation';
@@ -36,9 +40,11 @@ const PLUGIN_ID = 'xtralab:terminals';
36
40
  *
37
41
  * Clicking a row activates the existing tab if one is open, or reopens
38
42
  * the session in a fresh terminal widget (`terminal:open`). The inline
39
- * `×` button shuts the session down on the server. The header carries a
40
- * `+` button and a stop button (the latter shuts every session down at
41
- * once, after a confirmation).
43
+ * `×` button shuts the session down on the server. The Terminals
44
+ * section's title toolbar carries a `+` button and a stop button (the
45
+ * latter shuts every session down at once, after a confirmation).
46
+ *
47
+ * The list is one movable section, and other panels' sections can move in.
42
48
  *
43
49
  * The `+` button drops down a menu — built from the launcher's shared
44
50
  * `IAgentRegistry` — listing each available agent (Claude, Codex, …)
@@ -65,7 +71,8 @@ const plugin: JupyterFrontEndPlugin<IAgentTerminals> = {
65
71
  IAgentRegistry,
66
72
  IEditorRegistry,
67
73
  IAgentSessions,
68
- ISettingRegistry
74
+ ISettingRegistry,
75
+ IMovableSectionRegistry
69
76
  ],
70
77
  activate: (
71
78
  app: JupyterFrontEnd,
@@ -75,7 +82,8 @@ const plugin: JupyterFrontEndPlugin<IAgentTerminals> = {
75
82
  agentRegistry: IAgentRegistry | null,
76
83
  editorRegistry: IEditorRegistry | null,
77
84
  agentSessions: IAgentSessions | null,
78
- settingRegistry: ISettingRegistry | null
85
+ settingRegistry: ISettingRegistry | null,
86
+ movableSections: IMovableSectionRegistry | null
79
87
  ): IAgentTerminals => {
80
88
  const trans = (translator ?? nullTranslator).load('jupyterlab');
81
89
 
@@ -262,6 +270,16 @@ const plugin: JupyterFrontEndPlugin<IAgentTerminals> = {
262
270
  restorer.add(panel, panel.id);
263
271
  }
264
272
 
273
+ void app.restored.then(() => {
274
+ panel.expandOwnSection();
275
+ });
276
+
277
+ if (movableSections) {
278
+ movableSections.registerSource(PLUGIN_ID, trans.__('Terminals'), panel);
279
+ movableSections.registerTarget(PLUGIN_ID, trans.__('Terminals'), panel);
280
+ panel.announceSections();
281
+ }
282
+
265
283
  // The latest-activity line under each agent row is on by default; honour
266
284
  // the `showAgentActivity` setting so it can be turned off. Read on load and
267
285
  // re-applied on every change.