xtralab 0.15.0 → 0.15.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 (228) hide show
  1. package/README.md +10 -0
  2. package/lib/about/icons.d.ts +0 -5
  3. package/lib/about/icons.js +0 -5
  4. package/lib/about/index.d.ts +4 -8
  5. package/lib/about/index.js +6 -17
  6. package/lib/agentSessions.d.ts +9 -29
  7. package/lib/agentSessions.js +2 -7
  8. package/lib/askAgent/editorSelection.d.ts +20 -26
  9. package/lib/askAgent/editorSelection.js +11 -26
  10. package/lib/askAgent/icons.d.ts +2 -3
  11. package/lib/askAgent/icons.js +2 -3
  12. package/lib/askAgent/index.d.ts +4 -26
  13. package/lib/askAgent/index.js +54 -158
  14. package/lib/askAgent/popup.d.ts +12 -16
  15. package/lib/askAgent/popup.js +18 -37
  16. package/lib/askAgent/prompt.d.ts +3 -5
  17. package/lib/askAgent/prompt.js +6 -19
  18. package/lib/askAgent/queue.d.ts +11 -21
  19. package/lib/askAgent/queue.js +9 -19
  20. package/lib/askAgent/queuePanel.d.ts +13 -18
  21. package/lib/askAgent/queuePanel.js +15 -37
  22. package/lib/askAgent/targetPicker.d.ts +2 -9
  23. package/lib/askAgent/targetPicker.js +6 -11
  24. package/lib/askAgent/tokens.d.ts +32 -46
  25. package/lib/askAgent/tokens.js +4 -6
  26. package/lib/commandBar/index.d.ts +4 -13
  27. package/lib/commandBar/index.js +21 -39
  28. package/lib/customPanel/index.js +15 -0
  29. package/lib/editorBreadcrumbs/index.d.ts +3 -6
  30. package/lib/editorBreadcrumbs/index.js +10 -6
  31. package/lib/editorBreadcrumbs/widget.d.ts +17 -4
  32. package/lib/editorBreadcrumbs/widget.js +11 -17
  33. package/lib/editorIndent/index.d.ts +4 -12
  34. package/lib/editorIndent/index.js +8 -23
  35. package/lib/fileBrowser/commands.d.ts +28 -19
  36. package/lib/fileBrowser/commands.js +39 -98
  37. package/lib/fileBrowser/contents.d.ts +3 -0
  38. package/lib/fileBrowser/dragAndDrop.d.ts +17 -4
  39. package/lib/fileBrowser/dragAndDrop.js +2 -7
  40. package/lib/fileBrowser/fileBrowser.d.ts +19 -9
  41. package/lib/fileBrowser/fileBrowser.js +68 -216
  42. package/lib/fileBrowser/gitStatus.d.ts +4 -9
  43. package/lib/fileBrowser/gitStatus.js +7 -17
  44. package/lib/fileBrowser/gitignore.d.ts +4 -17
  45. package/lib/fileBrowser/gitignore.js +4 -25
  46. package/lib/fileBrowser/icons.d.ts +7 -17
  47. package/lib/fileBrowser/icons.js +25 -80
  48. package/lib/fileBrowser/index.js +2 -4
  49. package/lib/fileBrowser/widget.d.ts +126 -48
  50. package/lib/fileBrowser/widget.js +89 -4
  51. package/lib/fileTypeIcons/index.js +0 -10
  52. package/lib/git/api.d.ts +5 -13
  53. package/lib/git/api.js +10 -36
  54. package/lib/git/askRequest.d.ts +4 -8
  55. package/lib/git/askRequest.js +6 -20
  56. package/lib/git/commands.d.ts +40 -5
  57. package/lib/git/commands.js +16 -10
  58. package/lib/git/diffModel.js +4 -0
  59. package/lib/git/diffSurface.d.ts +41 -55
  60. package/lib/git/diffSurface.js +42 -117
  61. package/lib/git/diffWidget.d.ts +81 -2
  62. package/lib/git/diffWidget.js +62 -12
  63. package/lib/git/imageDiff.d.ts +5 -6
  64. package/lib/git/imageDiff.js +18 -48
  65. package/lib/git/index.d.ts +0 -3
  66. package/lib/git/index.js +3 -8
  67. package/lib/git/notebookDiff.d.ts +110 -33
  68. package/lib/git/notebookDiff.js +52 -195
  69. package/lib/git/tokens.d.ts +73 -31
  70. package/lib/git/tokens.js +2 -3
  71. package/lib/highlight/index.d.ts +4 -10
  72. package/lib/highlight/index.js +10 -41
  73. package/lib/index.d.ts +0 -9
  74. package/lib/index.js +0 -9
  75. package/lib/launcher/agents.d.ts +55 -51
  76. package/lib/launcher/agents.js +15 -57
  77. package/lib/launcher/availability.d.ts +3 -9
  78. package/lib/launcher/availability.js +3 -9
  79. package/lib/launcher/commands.d.ts +7 -32
  80. package/lib/launcher/commands.js +14 -45
  81. package/lib/launcher/dashboard.d.ts +19 -24
  82. package/lib/launcher/dashboard.js +21 -67
  83. package/lib/launcher/editorRegistry.d.ts +10 -22
  84. package/lib/launcher/editorRegistry.js +14 -18
  85. package/lib/launcher/editors.d.ts +39 -45
  86. package/lib/launcher/editors.js +8 -34
  87. package/lib/launcher/icons.d.ts +0 -12
  88. package/lib/launcher/icons.js +5 -39
  89. package/lib/launcher/index.js +12 -55
  90. package/lib/launcher/invocation.d.ts +4 -10
  91. package/lib/launcher/invocation.js +7 -22
  92. package/lib/launcher/registry.d.ts +9 -7
  93. package/lib/launcher/registry.js +9 -7
  94. package/lib/launcher/tokens.d.ts +10 -22
  95. package/lib/launcher/tokens.js +5 -8
  96. package/lib/menuBar/index.d.ts +3 -10
  97. package/lib/menuBar/index.js +11 -28
  98. package/lib/menus/index.d.ts +3 -9
  99. package/lib/menus/index.js +14 -30
  100. package/lib/omnibox/files.d.ts +2 -4
  101. package/lib/omnibox/files.js +5 -11
  102. package/lib/omnibox/index.d.ts +4 -14
  103. package/lib/omnibox/index.js +9 -27
  104. package/lib/omnibox/model.d.ts +38 -10
  105. package/lib/omnibox/model.js +15 -33
  106. package/lib/omnibox/recents.d.ts +15 -17
  107. package/lib/omnibox/recents.js +12 -17
  108. package/lib/omnibox/tokens.d.ts +5 -10
  109. package/lib/omnibox/tokens.js +2 -6
  110. package/lib/omnibox/widget.d.ts +11 -7
  111. package/lib/omnibox/widget.js +8 -16
  112. package/lib/searchReplace/index.d.ts +4 -20
  113. package/lib/searchReplace/index.js +7 -27
  114. package/lib/showOutput/index.d.ts +3 -12
  115. package/lib/showOutput/index.js +6 -22
  116. package/lib/sidebar/index.d.ts +4 -7
  117. package/lib/sidebar/index.js +5 -12
  118. package/lib/terminalNotifications/index.d.ts +4 -10
  119. package/lib/terminalNotifications/index.js +6 -20
  120. package/lib/terminals/agentTerminals.d.ts +12 -5
  121. package/lib/terminals/agentTerminals.js +25 -44
  122. package/lib/terminals/detection.d.ts +4 -8
  123. package/lib/terminals/detection.js +4 -8
  124. package/lib/terminals/index.d.ts +0 -35
  125. package/lib/terminals/index.js +12 -101
  126. package/lib/terminals/model.d.ts +64 -139
  127. package/lib/terminals/model.js +80 -220
  128. package/lib/terminals/tokens.d.ts +11 -22
  129. package/lib/terminals/tokens.js +2 -2
  130. package/lib/terminals/widget.d.ts +43 -13
  131. package/lib/terminals/widget.js +33 -18
  132. package/lib/topBar/icons.d.ts +3 -8
  133. package/lib/topBar/icons.js +3 -8
  134. package/lib/topBar/index.d.ts +4 -11
  135. package/lib/topBar/index.js +10 -38
  136. package/lib/walkthrough/index.d.ts +4 -9
  137. package/lib/walkthrough/index.js +6 -20
  138. package/lib/walkthrough/panel.d.ts +40 -9
  139. package/lib/walkthrough/panel.js +4 -10
  140. package/package.json +2 -2
  141. package/src/about/icons.ts +0 -5
  142. package/src/about/index.tsx +6 -17
  143. package/src/agentSessions.ts +9 -29
  144. package/src/askAgent/editorSelection.ts +22 -29
  145. package/src/askAgent/icons.ts +2 -3
  146. package/src/askAgent/index.ts +54 -158
  147. package/src/askAgent/popup.tsx +23 -45
  148. package/src/askAgent/prompt.ts +6 -19
  149. package/src/askAgent/queue.ts +13 -24
  150. package/src/askAgent/queuePanel.tsx +21 -46
  151. package/src/askAgent/targetPicker.tsx +5 -15
  152. package/src/askAgent/tokens.ts +32 -46
  153. package/src/commandBar/index.ts +24 -39
  154. package/src/customPanel/index.ts +15 -0
  155. package/src/editorBreadcrumbs/index.ts +10 -6
  156. package/src/editorBreadcrumbs/widget.ts +23 -17
  157. package/src/editorIndent/index.ts +17 -23
  158. package/src/fileBrowser/commands.ts +57 -98
  159. package/src/fileBrowser/contents.ts +3 -0
  160. package/src/fileBrowser/dragAndDrop.ts +17 -7
  161. package/src/fileBrowser/fileBrowser.tsx +84 -223
  162. package/src/fileBrowser/gitStatus.ts +7 -17
  163. package/src/fileBrowser/gitignore.ts +4 -25
  164. package/src/fileBrowser/icons.ts +25 -80
  165. package/src/fileBrowser/index.ts +2 -4
  166. package/src/fileBrowser/widget.tsx +149 -50
  167. package/src/fileTypeIcons/index.ts +0 -10
  168. package/src/git/api.ts +10 -36
  169. package/src/git/askRequest.ts +6 -20
  170. package/src/git/commands.ts +70 -10
  171. package/src/git/diffModel.ts +25 -0
  172. package/src/git/diffSurface.tsx +71 -159
  173. package/src/git/diffWidget.tsx +104 -14
  174. package/src/git/imageDiff.tsx +45 -51
  175. package/src/git/index.ts +3 -8
  176. package/src/git/notebookDiff.tsx +211 -238
  177. package/src/git/tokens.ts +73 -31
  178. package/src/highlight/index.ts +10 -41
  179. package/src/index.ts +0 -9
  180. package/src/launcher/agents.ts +64 -95
  181. package/src/launcher/availability.ts +3 -9
  182. package/src/launcher/commands.ts +14 -51
  183. package/src/launcher/dashboard.tsx +49 -88
  184. package/src/launcher/editorRegistry.ts +21 -29
  185. package/src/launcher/editors.ts +39 -58
  186. package/src/launcher/icons.ts +5 -39
  187. package/src/launcher/index.ts +12 -55
  188. package/src/launcher/invocation.ts +7 -22
  189. package/src/launcher/registry.ts +9 -7
  190. package/src/launcher/tokens.ts +10 -22
  191. package/src/menuBar/index.ts +11 -28
  192. package/src/menus/index.ts +14 -30
  193. package/src/omnibox/files.ts +10 -14
  194. package/src/omnibox/index.ts +9 -27
  195. package/src/omnibox/model.ts +50 -38
  196. package/src/omnibox/recents.ts +17 -22
  197. package/src/omnibox/tokens.ts +5 -10
  198. package/src/omnibox/widget.tsx +14 -19
  199. package/src/searchReplace/index.ts +7 -27
  200. package/src/showOutput/index.ts +6 -22
  201. package/src/sidebar/index.ts +20 -12
  202. package/src/terminalNotifications/index.ts +42 -25
  203. package/src/terminals/agentTerminals.ts +25 -49
  204. package/src/terminals/detection.ts +4 -8
  205. package/src/terminals/index.ts +12 -101
  206. package/src/terminals/model.ts +130 -246
  207. package/src/terminals/tokens.ts +11 -22
  208. package/src/terminals/widget.tsx +48 -31
  209. package/src/topBar/icons.ts +3 -8
  210. package/src/topBar/index.ts +21 -44
  211. package/src/walkthrough/index.ts +6 -20
  212. package/src/walkthrough/panel.ts +40 -10
  213. package/style/about.css +2 -7
  214. package/style/askAgent.css +8 -40
  215. package/style/base.css +9 -45
  216. package/style/chrome.css +108 -308
  217. package/style/commandBar.css +4 -20
  218. package/style/customPanel.css +1 -4
  219. package/style/git.css +22 -184
  220. package/style/highlight.css +1 -3
  221. package/style/launcher.css +6 -70
  222. package/style/omnibox.css +2 -14
  223. package/style/showOutput.css +0 -6
  224. package/style/sidebar.css +29 -9
  225. package/style/tabs.css +5 -13
  226. package/style/terminals.css +6 -53
  227. package/style/topBar.css +2 -22
  228. package/style/walkthrough.css +0 -8
@@ -60,6 +60,9 @@ export function toServerPath(canonicalPath: string): string {
60
60
  : canonicalPath;
61
61
  }
62
62
 
63
+ /**
64
+ * The immediate children of a directory, as canonical `@pierre/trees` paths.
65
+ */
63
66
  interface IListedDirectory {
64
67
  /**
65
68
  * Canonical paths for every immediate child of the requested directory.
@@ -14,7 +14,13 @@ import { ROOT_LOAD_KEY, canonicalBasename, parentOf } from './contents';
14
14
  * One tree-model move a drop performs, as canonical paths.
15
15
  */
16
16
  export interface IDropMove {
17
+ /**
18
+ * The canonical path of the dragged item.
19
+ */
17
20
  from: string;
21
+ /**
22
+ * The canonical destination path: its basename under the target directory.
23
+ */
18
24
  to: string;
19
25
  }
20
26
 
@@ -55,9 +61,6 @@ export function computeDropMoves(context: FileTreeDropContext): IDropMove[] {
55
61
  .map(path => ({ from: path, to: `${dir}${canonicalBasename(path)}` }));
56
62
  }
57
63
 
58
- /**
59
- * The drop target the tree reports for a move to the workspace root.
60
- */
61
64
  const ROOT_DROP_TARGET: FileTreeDropTarget = {
62
65
  directoryPath: null,
63
66
  flattenedSegmentPath: null,
@@ -92,8 +95,17 @@ export function createTreeDragAndDropConfig(
92
95
  };
93
96
  }
94
97
 
98
+ /**
99
+ * Options for {@link useRootDropZone}.
100
+ */
95
101
  interface IRootDropZoneOptions {
102
+ /**
103
+ * The tree model, queried for the selection at drag start.
104
+ */
96
105
  model: FileTree;
106
+ /**
107
+ * The drop handler ref, filled by the contents-sync effect.
108
+ */
97
109
  handlerRef: React.RefObject<ITreeDropHandler | null>;
98
110
  /**
99
111
  * The light-DOM wrapper around the tree host; composed drag events
@@ -104,10 +116,8 @@ interface IRootDropZoneOptions {
104
116
 
105
117
  /**
106
118
  * Accept drops on the empty space below the last row as moves to the
107
- * workspace root — the tree resolves a drop target only while the
108
- * cursor is over a row and silently discards such drops. dragstart
109
- * records the dragged paths; a drop whose composed path contains no
110
- * row hands them over as a root move.
119
+ * workspace root — the tree resolves a drop target only while the cursor
120
+ * is over a row and silently discards such drops.
111
121
  */
112
122
  export function useRootDropZone(options: IRootDropZoneOptions): void {
113
123
  const { model, handlerRef, wrapperRef } = options;
@@ -36,69 +36,37 @@ import { loadGitStatusEntries } from './gitStatus';
36
36
  import { FILE_BROWSER_ICONS } from './icons';
37
37
  import type { XtralabFileBrowser } from './widget';
38
38
 
39
- /**
40
- * Load state for a directory in the file tree. Directories are tracked from
41
- * the moment they are first observed (as a child of a loaded parent) so the
42
- * subscribe/diff loop can decide whether to fetch their contents on expand.
43
- */
44
39
  type LoadState = 'unloaded' | 'loading' | 'loaded';
45
40
 
46
41
  /**
47
- * Polling cadence for the git status decoration. Out-of-band changes (a
48
- * terminal `git add`, a `git pull`, a file edited outside the JupyterLab
49
- * editor) become visible within this interval without a manual refresh.
50
- * Aligned with the git panel's own polling so both views update on the
51
- * same rhythm.
42
+ * Git status poll cadence, aligned with the git panel's polling so both
43
+ * views update on the same rhythm.
52
44
  */
53
45
  const GIT_STATUS_POLL_INTERVAL_MS = 5000;
54
46
 
55
- /**
56
- * Upper bound on the git status poll's exponential backoff. Matches the
57
- * other polls in the plugin so behavior is consistent across views.
58
- */
59
47
  const GIT_STATUS_POLL_MAX_MS = 300_000;
60
48
 
61
49
  /**
62
- * Auto-refresh cadence for the file listing itself. Matches the default
63
- * JupyterLab file browser (`DEFAULT_REFRESH_INTERVAL` in
64
- * `@jupyterlab/filebrowser`) so the tree picks up files created outside
65
- * JupyterLab (terminal commands, external editors, `git pull`, …) within
66
- * the same window as the stock browser.
50
+ * Listing auto-refresh cadence; matches the default file browser's
51
+ * `DEFAULT_REFRESH_INTERVAL` for picking up out-of-band file changes.
67
52
  */
68
53
  const FILE_LISTING_REFRESH_INTERVAL_MS = 10000;
69
54
 
70
- /**
71
- * Upper bound on the auto-refresh backoff when polls fail repeatedly.
72
- * Matches the default file browser's `max: 300 * 1000` — five minutes is
73
- * long enough that a server-side outage stops hammering the API, but
74
- * short enough that a transient failure heals on its own.
75
- */
76
55
  const FILE_LISTING_REFRESH_MAX_MS = 300_000;
77
56
 
78
57
  /**
79
- * Server-relative repository path used for `/git/*` calls. Empty string
80
- * means "use the JupyterLab server's root and let git resolve the
81
- * enclosing repo" — same convention as the git panel and the launcher
82
- * dashboard.
58
+ * Repo path for `/git/*` calls; empty means the server root, letting git
59
+ * resolve the enclosing repo (same convention as the git panel).
83
60
  */
84
61
  const GIT_REPO_PATH = '';
85
62
 
86
- /**
87
- * The custom-element tag used by `@pierre/trees` for its shadow host. Kept
88
- * as a constant rather than imported so we don't pay the `@pierre/trees`
89
- * resolution cost just for one string.
90
- */
91
63
  const FILE_TREE_TAG = 'file-tree-container';
92
64
 
93
65
  /**
94
- * Injected into the tree's shadow root. The second rule hides the search
95
- * box unless the host carries the visibility marker set by the filter
96
- * bridge effect below — `@pierre/trees` always renders the box when
97
- * `search` is enabled, and its stylesheet lives in the shadow root where
98
- * outside CSS cannot reach. The third rule restyles the drag-hover row:
99
- * the library paints it with the selection background, which xtralab
100
- * maps to a full-strength brand color that is illegible without the
101
- * inverted selection foreground — hence the quieter ring.
66
+ * Injected into the tree's shadow root, where outside CSS cannot reach.
67
+ * The search box is hidden unless the host carries the filter-bridge marker
68
+ * (the library always renders it), and the drag-hover row gets a quiet ring
69
+ * — the library's selection background is illegible with xtralab's colors.
102
70
  */
103
71
  const FILE_TREE_UNSAFE_CSS =
104
72
  '[data-type="item"][data-item-selected="true"] ' +
@@ -114,26 +82,36 @@ const FILE_TREE_UNSAFE_CSS =
114
82
  'box-shadow: inset 0 0 0 2px var(--trees-accent);' +
115
83
  '}';
116
84
 
85
+ /**
86
+ * Props for {@link FileBrowserComponent}.
87
+ */
117
88
  interface IFileBrowserProps {
89
+ /**
90
+ * The Jupyter contents manager backing the tree.
91
+ */
118
92
  contentsManager: Contents.IManager;
93
+ /**
94
+ * The document manager used to rename files on drag-and-drop moves.
95
+ */
119
96
  docManager: IDocumentManager;
97
+ /**
98
+ * Called with the server path of an activated file.
99
+ */
120
100
  onOpenFile?: (serverPath: string) => void;
101
+ /**
102
+ * The application translator; defaults to `nullTranslator`.
103
+ */
121
104
  translator?: ITranslator;
122
105
  /**
123
- * The host widget. Selection-change events are pushed up so context-menu
124
- * commands can react to what the user has selected.
106
+ * The host widget; selection changes are pushed up for command handlers.
125
107
  */
126
108
  widget?: XtralabFileBrowser;
127
109
  }
128
110
 
129
111
  /**
130
- * Renders a `@pierre/trees` file tree backed by the Jupyter contents API.
131
- *
132
- * The Jupyter contents API only returns one directory level per request, so
133
- * the tree is populated lazily: the root is fetched on mount, and each
134
- * directory is fetched the first time the user expands it. Expansion is
135
- * detected by subscribing to the model and diffing against an in-memory load
136
- * state map.
112
+ * A `@pierre/trees` file tree backed by the Jupyter contents API. The API
113
+ * returns one directory level per request, so directories load lazily on
114
+ * first expand, detected by diffing the model against a load-state map.
137
115
  */
138
116
  export function FileBrowserComponent(
139
117
  props: IFileBrowserProps
@@ -159,26 +137,17 @@ export function FileBrowserComponent(
159
137
 
160
138
  React.useEffect(() => {
161
139
  const knownDirs = new Map<string, LoadState>();
162
- // Mirror of the canonical paths currently loaded into the tree. Kept in
163
- // sync with `model.resetPaths`/`model.batch`/`model.add` so we can
164
- // re-test every loaded path against the gitignore matcher whenever
165
- // either side changes — the model itself does not expose a
166
- // path-iteration API.
140
+ // Mirror of the loaded canonical paths — the model has no path-iteration
141
+ // API, and the gitignore matcher must re-test every loaded path.
167
142
  const loadedPaths = new Set<string>();
168
143
  let gitignoreMatcher: Ignore | null = null;
169
144
  let gitStatusEntries: readonly GitStatusEntry[] = [];
170
145
  let cancelled = false;
171
146
 
172
147
  /**
173
- * Recompute the combined `GitStatusEntry` list from the current
174
- * gitignore matcher and the latest porcelain status, then push it into
175
- * the tree. Safe to call at any time: empty inputs result in an empty
176
- * payload, which clears any statuses applied previously.
177
- *
178
- * Ignored entries go first so the porcelain entries win in the
179
- * unlikely event of overlap (a tracked path that also matches a
180
- * `.gitignore` rule). `@pierre/trees` lets later entries overwrite
181
- * earlier ones in its internal `statusByPath` map.
148
+ * Push the combined gitignore + porcelain entries into the tree.
149
+ * Ignored entries go first so porcelain entries win on overlap —
150
+ * `@pierre/trees` lets later entries overwrite earlier ones.
182
151
  */
183
152
  const syncGitStatus = (): void => {
184
153
  const entries: GitStatusEntry[] = [];
@@ -196,12 +165,6 @@ export function FileBrowserComponent(
196
165
  model.setGitStatus(entries);
197
166
  };
198
167
 
199
- /**
200
- * Reload the workspace `.gitignore`, then re-apply the resulting
201
- * ignored statuses. Called on initial mount and whenever the user
202
- * triggers a refresh — the file may have been edited or created in
203
- * between.
204
- */
205
168
  const refreshGitignoreMatcher = async (): Promise<void> => {
206
169
  let next: Ignore | null = null;
207
170
  try {
@@ -216,12 +179,6 @@ export function FileBrowserComponent(
216
179
  syncGitStatus();
217
180
  };
218
181
 
219
- /**
220
- * Refresh the porcelain-derived git status entries and re-apply them
221
- * to the tree. Runs on mount, on every refresh, and on a periodic
222
- * poll so out-of-band changes (terminal `git add`, file edits saved
223
- * outside the editor, …) become visible without explicit user action.
224
- */
225
182
  const refreshGitStatus = async (): Promise<void> => {
226
183
  const next = await loadGitStatusEntries(GIT_REPO_PATH);
227
184
  if (cancelled) {
@@ -253,21 +210,16 @@ export function FileBrowserComponent(
253
210
  loadedPaths.add(path);
254
211
  }
255
212
  } else {
256
- // Filter out paths already in the model. The path-store throws
257
- // when an explicit directory is added a second time, so any
258
- // entry created out-of-band (e.g. by the "new folder" command's
259
- // `notifyPathAdded` callback) must be skipped here.
213
+ // The path-store throws when a path is added twice, and entries
214
+ // can arrive out-of-band (e.g. `notifyPathAdded`), so skip those.
260
215
  const operations: FileTreeBatchOperation[] = paths
261
216
  .filter(path => model.getItem(path) === null)
262
217
  .map(path => ({ type: 'add', path }));
263
218
  if (operations.length > 0) {
264
219
  model.batch(operations);
265
220
  }
266
- // Mirror every directory child into `loadedPaths` regardless of
267
- // whether it was just added or skipped above — paths skipped by
268
- // the filter are already in the model from a prior add and so
269
- // belong in the mirror too. `Set.add` is idempotent, so the
270
- // duplicate adds are a no-op.
221
+ // Paths skipped above are already in the model from a prior add,
222
+ // so they belong in the mirror too.
271
223
  for (const path of paths) {
272
224
  loadedPaths.add(path);
273
225
  }
@@ -289,10 +241,8 @@ export function FileBrowserComponent(
289
241
  };
290
242
 
291
243
  /**
292
- * Refresh every directory currently loaded into the tree. Walks down
293
- * from the root through the previously-expanded subdirectories so the
294
- * tree state mirrors what's on disk while preserving the user's
295
- * expansion state.
244
+ * Re-fetch the root and every previously-expanded directory so the tree
245
+ * mirrors the disk while preserving the user's expansion state.
296
246
  */
297
247
  const refreshAll = async (): Promise<void> => {
298
248
  const expandedPaths = new Set<string>();
@@ -330,9 +280,8 @@ export function FileBrowserComponent(
330
280
 
331
281
  const allPaths: string[] = [...rootPaths];
332
282
 
333
- // BFS through the previously-expanded subtree, fetching only the
334
- // directories the user had opened so the refresh doesn't walk the
335
- // entire workspace.
283
+ // Fetch only the previously-expanded subtree so the refresh doesn't
284
+ // walk the entire workspace.
336
285
  const subdirsByParent = new Map<string, string[]>();
337
286
  subdirsByParent.set(ROOT_LOAD_KEY, rootSubdirs);
338
287
  const queue = rootSubdirs.filter(s => expandedPaths.has(s));
@@ -359,8 +308,6 @@ export function FileBrowserComponent(
359
308
  }
360
309
  }
361
310
 
362
- // Reset the tree contents and restore the load-state map so future
363
- // expansions know which directories still need fetching.
364
311
  model.resetPaths(allPaths);
365
312
  loadedPaths.clear();
366
313
  for (const path of allPaths) {
@@ -376,19 +323,11 @@ export function FileBrowserComponent(
376
323
  }
377
324
  });
378
325
 
379
- // Refresh the `.gitignore` matcher in case the file was edited
380
- // since the last load, then re-apply the resulting statuses to the
381
- // newly-loaded paths. The reload runs in parallel with the rest of
382
- // the refresh — `refreshGitignoreMatcher` calls `syncGitStatus`
383
- // itself when it completes. The porcelain status is also re-fetched
384
- // here so a user-triggered refresh picks up out-of-band git changes
385
- // immediately instead of waiting for the next poll tick.
326
+ // Each re-applies the statuses itself when it completes.
386
327
  void refreshGitignoreMatcher();
387
328
  void refreshGitStatus();
388
329
 
389
- // Re-expand the directories that were expanded before the refresh.
390
- // We have to do this after `resetPaths` because the reset starts
391
- // every directory in its initial collapsed state.
330
+ // `resetPaths` starts every directory collapsed, so re-expand after it.
392
331
  for (const path of expandedPaths) {
393
332
  const item = model.getItem(path);
394
333
  if (item !== null && item.isDirectory()) {
@@ -398,20 +337,10 @@ export function FileBrowserComponent(
398
337
  };
399
338
 
400
339
  /**
401
- * Auto-refresh tick: walk every directory currently loaded into the
402
- * tree, fetch its children, and apply the per-directory diff as a
403
- * single batched mutation. Unlike {@link refreshAll} this never calls
404
- * `model.resetPaths`, so the user's expansion, selection, and scroll
405
- * state survive every poll. Mirrors what the default JupyterLab file
406
- * browser does for its single-directory view.
407
- *
408
- * A failed fetch for a single directory is treated as transient and
409
- * is skipped without touching that directory's children — they may
410
- * still be valid even if this one fetch lost the race with a server
411
- * restart. A deleted directory eventually surfaces through its
412
- * parent's diff: when the parent is re-fetched and no longer lists
413
- * the missing child, the child is removed recursively from the tree
414
- * and from the load-state tracking maps.
340
+ * Auto-refresh tick: diff every loaded directory and apply batched
341
+ * mutations without `resetPaths`, so expansion, selection, and scroll
342
+ * state survive. A failed fetch is skipped as transient; a deleted
343
+ * directory surfaces through its parent's diff and is removed recursively.
415
344
  */
416
345
  const quietRefresh = async (): Promise<void> => {
417
346
  if (cancelled) {
@@ -433,10 +362,8 @@ export function FileBrowserComponent(
433
362
  if (cancelled) {
434
363
  return;
435
364
  }
436
- // Skip directories that were removed from `knownDirs` while we
437
- // were processing an earlier sibling — the cascade cleanup below
438
- // can prune deep subtrees, so a path captured at the start of
439
- // the tick may already be gone.
365
+ // The cascade cleanup below can prune subtrees mid-tick, so a dir
366
+ // captured at the start may already be gone.
440
367
  if (knownDirs.get(dir) !== 'loaded') {
441
368
  continue;
442
369
  }
@@ -464,8 +391,6 @@ export function FileBrowserComponent(
464
391
  if (newChildren.has(lp)) {
465
392
  continue;
466
393
  }
467
- // Disappeared since the last tick. Remove recursively so any
468
- // descendants that were also being tracked go with it.
469
394
  ops.push({ type: 'remove', path: lp, recursive: true });
470
395
  removals.push(lp);
471
396
  if (lp.endsWith('/')) {
@@ -488,16 +413,13 @@ export function FileBrowserComponent(
488
413
  `xtralab: auto-refresh batch failed for "${dir}"`,
489
414
  err
490
415
  );
491
- // Leave the bookkeeping mirrors untouched so the next tick
492
- // sees the same starting state and tries again.
416
+ // Leave the mirrors untouched so the next tick retries.
493
417
  continue;
494
418
  }
495
419
  mutated = true;
496
420
 
497
- // Apply the matching mirror updates only after the batch lands
498
- // in the model. The cascade cleanup below mirrors the
499
- // `recursive: true` removal semantics so descendants we were
500
- // tracking don't linger in `loadedPaths` or `knownDirs`.
421
+ // Mirror updates only after the batch lands; the cascade below
422
+ // mirrors the `recursive: true` removal semantics.
501
423
  for (const r of removals) {
502
424
  loadedPaths.delete(r);
503
425
  }
@@ -527,8 +449,7 @@ export function FileBrowserComponent(
527
449
  }
528
450
  }
529
451
 
530
- // Register newly-observed subdirectories so the next user expand
531
- // triggers a fetch instead of being ignored.
452
+ // Untracked subdirectories would ignore their first expand.
532
453
  for (const subdir of fetched.subdirectories) {
533
454
  if (!knownDirs.has(subdir)) {
534
455
  knownDirs.set(subdir, 'unloaded');
@@ -542,24 +463,8 @@ export function FileBrowserComponent(
542
463
  };
543
464
 
544
465
  /**
545
- * Reveal {@link canonicalPath} in the tree: load any unloaded
546
- * ancestor directories, expand them, and select the target so it is
547
- * scrolled into view. Tolerant of partially-loaded state so the
548
- * editor breadcrumbs can call it on any path at any time without
549
- * caring about what the tree has already fetched.
550
- *
551
- * Each ancestor is awaited *before* it is expanded — expanding a
552
- * directory triggers the model's subscribe callback, which
553
- * synchronously sets the directory's load state to `loading` and
554
- * kicks off its own fetch in parallel. Awaiting that in-flight
555
- * fetch would return immediately on the second await, leaving the
556
- * children unloaded when we move to the next iteration.
557
- */
558
- /**
559
- * Clear the tree selection and scroll back to the top. Invoked by
560
- * the file browser widget's `scrollToRoot` method when the home
561
- * crumb is clicked; gives that gesture visible feedback even when
562
- * the sidebar is already focused on the file browser.
466
+ * Clear the selection and scroll to the top; gives the home-crumb
467
+ * gesture visible feedback even when the sidebar is already focused.
563
468
  */
564
469
  const goToRoot = (): void => {
565
470
  if (cancelled) {
@@ -574,13 +479,6 @@ export function FileBrowserComponent(
574
479
  }
575
480
  };
576
481
 
577
- /**
578
- * Collapse every currently expanded directory in the tree. Walks the
579
- * `knownDirs` map (the canonical record of which directories have been
580
- * observed in the tree) and calls `.collapse()` on each loaded
581
- * directory whose handle reports `isExpanded()`. Unloaded directories
582
- * are not expanded by definition, so they're skipped.
583
- */
584
482
  const collapseAll = (): void => {
585
483
  if (cancelled) {
586
484
  return;
@@ -600,6 +498,12 @@ export function FileBrowserComponent(
600
498
  });
601
499
  };
602
500
 
501
+ /**
502
+ * Reveal `canonicalPath`: fetch and expand ancestors, then select and
503
+ * scroll to the target. Each ancestor is fetched *before* expanding —
504
+ * expansion starts the subscribe callback's own fetch, and awaiting that
505
+ * in-flight fetch resolves with the children still unloaded.
506
+ */
603
507
  const revealPath = async (canonicalPath: string): Promise<void> => {
604
508
  if (cancelled || canonicalPath.length === 0) {
605
509
  return;
@@ -612,9 +516,7 @@ export function FileBrowserComponent(
612
516
  return;
613
517
  }
614
518
 
615
- // Build the ordered list of ancestor directory canonical paths.
616
- // For "foo/bar/baz.txt" → ["foo/", "foo/bar/"].
617
- // For "foo/bar/" → ["foo/"].
519
+ // "foo/bar/baz.txt" → ["foo/", "foo/bar/"].
618
520
  const ancestors: string[] = [];
619
521
  let cumulative = '';
620
522
  for (let i = 0; i < segments.length - 1; i++) {
@@ -668,16 +570,14 @@ export function FileBrowserComponent(
668
570
  previous?.deselect();
669
571
  }
670
572
  target.select();
671
- // `select` highlights the row; `scrollToPath` focuses it and scrolls it
672
- // to the middle of the viewport, even when the row is virtualized out of
673
- // the rendered window.
573
+ // `scrollToPath` focuses and scrolls even when the row is virtualized
574
+ // out of the rendered window.
674
575
  model.scrollToPath(canonicalPath, { focus: true, offset: 'center' });
675
576
  };
676
577
 
677
578
  /**
678
- * Insert a newly-created path (typically from "new folder" or
679
- * "duplicate") into the tree without doing a full refresh. Expands
680
- * the parent so the user sees the newly created entry immediately.
579
+ * Insert a newly-created path without a full refresh and expand its
580
+ * parent so the entry is visible immediately.
681
581
  */
682
582
  const handlePathAdded = (canonicalPath: string): void => {
683
583
  if (model.getItem(canonicalPath) === null) {
@@ -690,9 +590,8 @@ export function FileBrowserComponent(
690
590
  }
691
591
  loadedPaths.add(canonicalPath);
692
592
  if (canonicalPath.endsWith('/') && !knownDirs.has(canonicalPath)) {
693
- // The new directory has no children yet, so mark it as already
694
- // loaded — there's nothing to fetch and we don't want a stale
695
- // "unloaded" entry to trigger a fetch on the next expand.
593
+ // A new directory has no children; mark it loaded so a stale
594
+ // "unloaded" entry doesn't trigger a fetch on the next expand.
696
595
  knownDirs.set(canonicalPath, 'loaded');
697
596
  }
698
597
  syncGitStatus();
@@ -804,10 +703,6 @@ export function FileBrowserComponent(
804
703
  }
805
704
  };
806
705
 
807
- /**
808
- * The tree refused the drop and left its model untouched — almost
809
- * always a name collision at the destination.
810
- */
811
706
  const failedDrop = (error: string, context: FileTreeDropContext): void => {
812
707
  if (cancelled) {
813
708
  return;
@@ -866,13 +761,8 @@ export function FileBrowserComponent(
866
761
  standby: 'when-hidden'
867
762
  });
868
763
 
869
- // Auto-refresh the file listing on the same cadence as the default
870
- // JupyterLab file browser. Backoff on failures so a server-side
871
- // outage doesn't hammer the API, and stand by when the tab is
872
- // hidden so we don't run the polling loop while the user is in
873
- // another tab. `auto: false` keeps the first tick from racing the
874
- // initial `fetchDirectory(ROOT_LOAD_KEY)` above — the poll is
875
- // started explicitly once the initial load is in flight.
764
+ // `auto: false` keeps the first tick from racing the initial root
765
+ // fetch above; the poll is started explicitly below.
876
766
  const listingPoll = new Poll({
877
767
  auto: false,
878
768
  name: '@xtralab/fileBrowser:listing',
@@ -886,27 +776,17 @@ export function FileBrowserComponent(
886
776
  });
887
777
  void listingPoll.start();
888
778
 
889
- // Surface contents changes that happen inside JupyterLab (file save,
890
- // rename, delete) without waiting for the next poll tick. The
891
- // default file browser uses the same `fileChanged` signal for the
892
- // same reason. We can't tell from the signal alone whether the
893
- // change affects a path we're showing, so we just nudge the poll —
894
- // it diffs the loaded directories and emits no batch ops when
895
- // nothing relevant changed.
779
+ // In-app contents changes (save, rename, delete) nudge the poll; the
780
+ // signal doesn't say whether a shown path is affected, the diff does.
896
781
  const onContentsFileChanged = (): void => {
897
782
  void listingPoll.refresh();
898
783
  };
899
784
  contentsManager.fileChanged.connect(onContentsFileChanged);
900
785
 
901
786
  const unsubscribe = model.subscribe(() => {
902
- // Search-driven expansion must not trigger fetches: the tree
903
- // auto-expands every directory whose path matches the query, and
904
- // treating those as user expansions would recursively fetch every
905
- // matching subtree — a single common letter can walk the whole
906
- // workspace, node_modules included. Closing the search restores
907
- // the pre-search expansion state, and a directory clicked in the
908
- // results is toggled after the session closes, so real expansions
909
- // are still fetched the moment the session ends.
787
+ // Search auto-expands every matching directory — fetching those would
788
+ // walk whole subtrees (node_modules included); real expansions still
789
+ // fetch once the search session closes.
910
790
  if (model.isSearchOpen()) {
911
791
  return;
912
792
  }
@@ -983,11 +863,8 @@ export function FileBrowserComponent(
983
863
  };
984
864
  }, [model, contentsManager, widget, docManager, trans]);
985
865
 
986
- // Bridge the tree's selection state up to the widget so command handlers
987
- // can read it without depending on React internals. The tree exposes its
988
- // selection through `getSelectedPaths()` and emits a generic notification
989
- // through `subscribe`, so we diff against a snapshot to avoid spamming the
990
- // widget on every unrelated mutation.
866
+ // Bridge the tree selection up to the widget. `subscribe` fires on every
867
+ // mutation, so diff against a snapshot before notifying.
991
868
  React.useEffect(() => {
992
869
  if (widget === undefined) {
993
870
  return;
@@ -1011,13 +888,9 @@ export function FileBrowserComponent(
1011
888
  };
1012
889
  }, [model, widget]);
1013
890
 
1014
- // Bridge the filter-box visibility between the widget and the tree. The
1015
- // widget owns the flag; applying it stamps the marker attribute the
1016
- // unsafeCSS rule keys on and opens or closes the model's search session
1017
- // (opening focuses the input, closing clears any active filter). The
1018
- // model subscription covers the reverse direction: typing a printable
1019
- // character while the tree has focus opens a session on the tree's own
1020
- // initiative, and the box must surface for that session to be usable.
891
+ // Applying the widget's filter flag stamps the marker the unsafeCSS rule
892
+ // keys on and syncs the search session; the subscription surfaces the box
893
+ // when the tree opens a session itself (typing while focused).
1021
894
  React.useEffect(() => {
1022
895
  if (widget === undefined) {
1023
896
  return;
@@ -1085,21 +958,9 @@ export function FileBrowserComponent(
1085
958
  };
1086
959
  }, [onOpenFile]);
1087
960
 
1088
- // Bridge contextmenu events out of the `<file-tree-container>` shadow DOM.
1089
- //
1090
- // `@pierre/trees` mounts the tree under an open shadow root attached to the
1091
- // `<file-tree-container>` custom element. When the user right-clicks a row
1092
- // inside the shadow tree, the event is retargeted to the host element when
1093
- // observed from the light DOM, and `app.contextMenu` walks via
1094
- // `parentElement` — it never enters the shadow tree, so the `[data-type=
1095
- // "item"]` selectors registered in `schema/plugin.json` never match.
1096
- //
1097
- // We listen in the capture phase (so we run before the application's
1098
- // document-level handler) and copy the right-clicked row's data attributes
1099
- // onto the host. Lumino then matches the host as if it were the row, and
1100
- // `app.contextMenuHitTest` from command handlers reads the same attributes
1101
- // back to recover the path. When the right-click misses any row we clear
1102
- // the attributes so empty-area clicks don't show stale per-item entries.
961
+ // Lumino never enters the tree's shadow DOM, so the `[data-type="item"]`
962
+ // selectors can't match rows; mirror the right-clicked row's data
963
+ // attributes onto the host (capture phase, cleared on a miss).
1103
964
  React.useEffect(() => {
1104
965
  const wrapper = wrapperRef.current;
1105
966
  if (wrapper === null) {