xtralab 0.3.0 → 0.4.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.
@@ -2,9 +2,11 @@ import * as React from 'react';
2
2
  import { fileIcon } from '@jupyterlab/ui-components';
3
3
  import { MimeData, PromiseDelegate } from '@lumino/coreutils';
4
4
  import { Drag } from '@lumino/dragdrop';
5
+ import { Poll } from '@lumino/polling';
5
6
  import { FileTree, useFileTree } from '@pierre/trees/react';
6
7
  import { ROOT_LOAD_KEY, listDirectory, toServerPath } from './contents';
7
8
  import { buildIgnoredEntries, loadGitignoreMatcher } from './gitignore';
9
+ import { loadGitStatusEntries } from './gitStatus';
8
10
  import { FILE_BROWSER_ICONS } from './icons';
9
11
  /**
10
12
  * MIME types used by the dock panel and other JupyterLab drop targets.
@@ -21,6 +23,41 @@ const CONTENTS_MIME = 'application/x-jupyter-icontents';
21
23
  * than a click. Matches the value used by the default JupyterLab listing.
22
24
  */
23
25
  const DRAG_THRESHOLD = 5;
26
+ /**
27
+ * Polling cadence for the git status decoration. Out-of-band changes (a
28
+ * terminal `git add`, a `git pull`, a file edited outside the JupyterLab
29
+ * editor) become visible within this interval without a manual refresh.
30
+ * Aligned with the git panel's own polling so both views update on the
31
+ * same rhythm.
32
+ */
33
+ const GIT_STATUS_POLL_INTERVAL_MS = 5000;
34
+ /**
35
+ * Upper bound on the git status poll's exponential backoff. Matches the
36
+ * other polls in the plugin so behavior is consistent across views.
37
+ */
38
+ const GIT_STATUS_POLL_MAX_MS = 300000;
39
+ /**
40
+ * Auto-refresh cadence for the file listing itself. Matches the default
41
+ * JupyterLab file browser (`DEFAULT_REFRESH_INTERVAL` in
42
+ * `@jupyterlab/filebrowser`) so the tree picks up files created outside
43
+ * JupyterLab (terminal commands, external editors, `git pull`, …) within
44
+ * the same window as the stock browser.
45
+ */
46
+ const FILE_LISTING_REFRESH_INTERVAL_MS = 10000;
47
+ /**
48
+ * Upper bound on the auto-refresh backoff when polls fail repeatedly.
49
+ * Matches the default file browser's `max: 300 * 1000` — five minutes is
50
+ * long enough that a server-side outage stops hammering the API, but
51
+ * short enough that a transient failure heals on its own.
52
+ */
53
+ const FILE_LISTING_REFRESH_MAX_MS = 300000;
54
+ /**
55
+ * Server-relative repository path used for `/git/*` calls. Empty string
56
+ * means "use the JupyterLab server's root and let git resolve the
57
+ * enclosing repo" — same convention as the git panel and the launcher
58
+ * dashboard.
59
+ */
60
+ const GIT_REPO_PATH = '';
24
61
  /**
25
62
  * The custom-element tag used by `@pierre/trees` for its shadow host. Kept
26
63
  * as a constant rather than imported so we don't pay the `@pierre/trees`
@@ -54,20 +91,29 @@ export function FileBrowserComponent(props) {
54
91
  // path-iteration API.
55
92
  const loadedPaths = new Set();
56
93
  let gitignoreMatcher = null;
94
+ let gitStatusEntries = [];
57
95
  let cancelled = false;
58
96
  /**
59
- * Recompute the `ignored` git status entries from the current
60
- * gitignore matcher and the set of loaded paths, and push them into
61
- * the tree. Safe to call at any time: when the matcher is `null`
62
- * (no `.gitignore` or it failed to load) we send an empty list, which
63
- * also clears any statuses that may have been applied previously.
97
+ * Recompute the combined `GitStatusEntry` list from the current
98
+ * gitignore matcher and the latest porcelain status, then push it into
99
+ * the tree. Safe to call at any time: empty inputs result in an empty
100
+ * payload, which clears any statuses applied previously.
101
+ *
102
+ * Ignored entries go first so the porcelain entries win in the
103
+ * unlikely event of overlap (a tracked path that also matches a
104
+ * `.gitignore` rule). `@pierre/trees` lets later entries overwrite
105
+ * earlier ones in its internal `statusByPath` map.
64
106
  */
65
107
  const syncGitStatus = () => {
66
- if (gitignoreMatcher === null) {
67
- model.setGitStatus([]);
68
- return;
108
+ const entries = [];
109
+ if (gitignoreMatcher !== null) {
110
+ for (const entry of buildIgnoredEntries(gitignoreMatcher, loadedPaths)) {
111
+ entries.push(entry);
112
+ }
113
+ }
114
+ for (const entry of gitStatusEntries) {
115
+ entries.push(entry);
69
116
  }
70
- const entries = buildIgnoredEntries(gitignoreMatcher, loadedPaths);
71
117
  model.setGitStatus(entries);
72
118
  };
73
119
  /**
@@ -90,6 +136,20 @@ export function FileBrowserComponent(props) {
90
136
  gitignoreMatcher = next;
91
137
  syncGitStatus();
92
138
  };
139
+ /**
140
+ * Refresh the porcelain-derived git status entries and re-apply them
141
+ * to the tree. Runs on mount, on every refresh, and on a periodic
142
+ * poll so out-of-band changes (terminal `git add`, file edits saved
143
+ * outside the editor, …) become visible without explicit user action.
144
+ */
145
+ const refreshGitStatus = async () => {
146
+ const next = await loadGitStatusEntries(GIT_REPO_PATH);
147
+ if (cancelled) {
148
+ return;
149
+ }
150
+ gitStatusEntries = next;
151
+ syncGitStatus();
152
+ };
93
153
  const fetchDirectory = async (canonicalPath) => {
94
154
  const current = knownDirs.get(canonicalPath);
95
155
  if (current === 'loading' || current === 'loaded') {
@@ -236,8 +296,11 @@ export function FileBrowserComponent(props) {
236
296
  // since the last load, then re-apply the resulting statuses to the
237
297
  // newly-loaded paths. The reload runs in parallel with the rest of
238
298
  // the refresh — `refreshGitignoreMatcher` calls `syncGitStatus`
239
- // itself when it completes.
299
+ // itself when it completes. The porcelain status is also re-fetched
300
+ // here so a user-triggered refresh picks up out-of-band git changes
301
+ // immediately instead of waiting for the next poll tick.
240
302
  void refreshGitignoreMatcher();
303
+ void refreshGitStatus();
241
304
  // Re-expand the directories that were expanded before the refresh.
242
305
  // We have to do this after `resetPaths` because the reset starts
243
306
  // every directory in its initial collapsed state.
@@ -248,6 +311,259 @@ export function FileBrowserComponent(props) {
248
311
  }
249
312
  }
250
313
  };
314
+ /**
315
+ * Auto-refresh tick: walk every directory currently loaded into the
316
+ * tree, fetch its children, and apply the per-directory diff as a
317
+ * single batched mutation. Unlike {@link refreshAll} this never calls
318
+ * `model.resetPaths`, so the user's expansion, selection, and scroll
319
+ * state survive every poll. Mirrors what the default JupyterLab file
320
+ * browser does for its single-directory view.
321
+ *
322
+ * A failed fetch for a single directory is treated as transient and
323
+ * is skipped without touching that directory's children — they may
324
+ * still be valid even if this one fetch lost the race with a server
325
+ * restart. A deleted directory eventually surfaces through its
326
+ * parent's diff: when the parent is re-fetched and no longer lists
327
+ * the missing child, the child is removed recursively from the tree
328
+ * and from the load-state tracking maps.
329
+ */
330
+ const quietRefresh = async () => {
331
+ if (cancelled) {
332
+ return;
333
+ }
334
+ const dirsToRefresh = [];
335
+ knownDirs.forEach((state, path) => {
336
+ if (state === 'loaded') {
337
+ dirsToRefresh.push(path);
338
+ }
339
+ });
340
+ if (dirsToRefresh.length === 0) {
341
+ return;
342
+ }
343
+ let mutated = false;
344
+ for (const dir of dirsToRefresh) {
345
+ if (cancelled) {
346
+ return;
347
+ }
348
+ // Skip directories that were removed from `knownDirs` while we
349
+ // were processing an earlier sibling — the cascade cleanup below
350
+ // can prune deep subtrees, so a path captured at the start of
351
+ // the tick may already be gone.
352
+ if (knownDirs.get(dir) !== 'loaded') {
353
+ continue;
354
+ }
355
+ let fetched;
356
+ try {
357
+ fetched = await listDirectory(contentsManager, toServerPath(dir));
358
+ }
359
+ catch (err) {
360
+ console.warn(`xtralab: auto-refresh skipped "${dir}"`, err);
361
+ continue;
362
+ }
363
+ if (cancelled) {
364
+ return;
365
+ }
366
+ const newChildren = new Set(fetched.paths);
367
+ const ops = [];
368
+ const additions = [];
369
+ const removals = [];
370
+ const directoryRemovals = [];
371
+ for (const lp of loadedPaths) {
372
+ if (parentOf(lp) !== dir) {
373
+ continue;
374
+ }
375
+ if (newChildren.has(lp)) {
376
+ continue;
377
+ }
378
+ // Disappeared since the last tick. Remove recursively so any
379
+ // descendants that were also being tracked go with it.
380
+ ops.push({ type: 'remove', path: lp, recursive: true });
381
+ removals.push(lp);
382
+ if (lp.endsWith('/')) {
383
+ directoryRemovals.push(lp);
384
+ }
385
+ }
386
+ for (const newChild of fetched.paths) {
387
+ if (loadedPaths.has(newChild)) {
388
+ continue;
389
+ }
390
+ ops.push({ type: 'add', path: newChild });
391
+ additions.push(newChild);
392
+ }
393
+ if (ops.length > 0) {
394
+ try {
395
+ model.batch(ops);
396
+ }
397
+ catch (err) {
398
+ console.error(`xtralab: auto-refresh batch failed for "${dir}"`, err);
399
+ // Leave the bookkeeping mirrors untouched so the next tick
400
+ // sees the same starting state and tries again.
401
+ continue;
402
+ }
403
+ mutated = true;
404
+ // Apply the matching mirror updates only after the batch lands
405
+ // in the model. The cascade cleanup below mirrors the
406
+ // `recursive: true` removal semantics so descendants we were
407
+ // tracking don't linger in `loadedPaths` or `knownDirs`.
408
+ for (const r of removals) {
409
+ loadedPaths.delete(r);
410
+ }
411
+ for (const removedDir of directoryRemovals) {
412
+ knownDirs.delete(removedDir);
413
+ const descendantPaths = [];
414
+ for (const lp of loadedPaths) {
415
+ if (lp.startsWith(removedDir)) {
416
+ descendantPaths.push(lp);
417
+ }
418
+ }
419
+ for (const lp of descendantPaths) {
420
+ loadedPaths.delete(lp);
421
+ }
422
+ const descendantDirs = [];
423
+ knownDirs.forEach((_, kd) => {
424
+ if (kd !== ROOT_LOAD_KEY && kd.startsWith(removedDir)) {
425
+ descendantDirs.push(kd);
426
+ }
427
+ });
428
+ for (const kd of descendantDirs) {
429
+ knownDirs.delete(kd);
430
+ }
431
+ }
432
+ for (const a of additions) {
433
+ loadedPaths.add(a);
434
+ }
435
+ }
436
+ // Register newly-observed subdirectories so the next user expand
437
+ // triggers a fetch instead of being ignored.
438
+ for (const subdir of fetched.subdirectories) {
439
+ if (!knownDirs.has(subdir)) {
440
+ knownDirs.set(subdir, 'unloaded');
441
+ }
442
+ }
443
+ }
444
+ if (mutated) {
445
+ syncGitStatus();
446
+ }
447
+ };
448
+ /**
449
+ * Reveal {@link canonicalPath} in the tree: load any unloaded
450
+ * ancestor directories, expand them, and select the target so it is
451
+ * scrolled into view. Tolerant of partially-loaded state so the
452
+ * editor breadcrumbs can call it on any path at any time without
453
+ * caring about what the tree has already fetched.
454
+ *
455
+ * Each ancestor is awaited *before* it is expanded — expanding a
456
+ * directory triggers the model's subscribe callback, which
457
+ * synchronously sets the directory's load state to `loading` and
458
+ * kicks off its own fetch in parallel. Awaiting that in-flight
459
+ * fetch would return immediately on the second await, leaving the
460
+ * children unloaded when we move to the next iteration.
461
+ */
462
+ /**
463
+ * Clear the tree selection and scroll back to the top. Invoked by
464
+ * the file browser widget's `scrollToRoot` method when the home
465
+ * crumb is clicked; gives that gesture visible feedback even when
466
+ * the sidebar is already focused on the file browser.
467
+ */
468
+ const goToRoot = () => {
469
+ var _a;
470
+ if (cancelled) {
471
+ return;
472
+ }
473
+ for (const selected of model.getSelectedPaths()) {
474
+ (_a = model.getItem(selected)) === null || _a === void 0 ? void 0 : _a.deselect();
475
+ }
476
+ const container = model.getFileTreeContainer();
477
+ if (container !== undefined) {
478
+ container.scrollTop = 0;
479
+ }
480
+ };
481
+ /**
482
+ * Collapse every currently expanded directory in the tree. Walks the
483
+ * `knownDirs` map (the canonical record of which directories have been
484
+ * observed in the tree) and calls `.collapse()` on each loaded
485
+ * directory whose handle reports `isExpanded()`. Unloaded directories
486
+ * are not expanded by definition, so they're skipped.
487
+ */
488
+ const collapseAll = () => {
489
+ if (cancelled) {
490
+ return;
491
+ }
492
+ knownDirs.forEach((state, path) => {
493
+ if (path === ROOT_LOAD_KEY || state !== 'loaded') {
494
+ return;
495
+ }
496
+ const item = model.getItem(path);
497
+ if (item === null || !item.isDirectory()) {
498
+ return;
499
+ }
500
+ const handle = item;
501
+ if (handle.isExpanded()) {
502
+ handle.collapse();
503
+ }
504
+ });
505
+ };
506
+ const revealPath = async (canonicalPath) => {
507
+ if (cancelled || canonicalPath.length === 0) {
508
+ return;
509
+ }
510
+ const isDir = canonicalPath.endsWith('/');
511
+ const trimmed = isDir ? canonicalPath.slice(0, -1) : canonicalPath;
512
+ const segments = trimmed.split('/').filter(s => s.length > 0);
513
+ if (segments.length === 0) {
514
+ return;
515
+ }
516
+ // Build the ordered list of ancestor directory canonical paths.
517
+ // For "foo/bar/baz.txt" → ["foo/", "foo/bar/"].
518
+ // For "foo/bar/" → ["foo/"].
519
+ const ancestors = [];
520
+ let cumulative = '';
521
+ for (let i = 0; i < segments.length - 1; i++) {
522
+ cumulative += `${segments[i]}/`;
523
+ ancestors.push(cumulative);
524
+ }
525
+ await fetchDirectory(ROOT_LOAD_KEY);
526
+ if (cancelled) {
527
+ return;
528
+ }
529
+ for (const ancestor of ancestors) {
530
+ await fetchDirectory(ancestor);
531
+ if (cancelled) {
532
+ return;
533
+ }
534
+ const item = model.getItem(ancestor);
535
+ if (item === null || !item.isDirectory()) {
536
+ return;
537
+ }
538
+ const handle = item;
539
+ if (!handle.isExpanded()) {
540
+ handle.expand();
541
+ }
542
+ }
543
+ if (isDir) {
544
+ await fetchDirectory(canonicalPath);
545
+ if (cancelled) {
546
+ return;
547
+ }
548
+ }
549
+ const target = model.getItem(canonicalPath);
550
+ if (target === null) {
551
+ return;
552
+ }
553
+ if (target.isDirectory() &&
554
+ !target.isExpanded()) {
555
+ target.expand();
556
+ }
557
+ for (const selected of model.getSelectedPaths()) {
558
+ if (selected === canonicalPath) {
559
+ continue;
560
+ }
561
+ const previous = model.getItem(selected);
562
+ previous === null || previous === void 0 ? void 0 : previous.deselect();
563
+ }
564
+ target.select();
565
+ model.focusPath(canonicalPath);
566
+ };
251
567
  /**
252
568
  * Insert a newly-created path (typically from "new folder" or
253
569
  * "duplicate") into the tree without doing a full refresh. Expands
@@ -287,6 +603,46 @@ export function FileBrowserComponent(props) {
287
603
  knownDirs.set(ROOT_LOAD_KEY, 'unloaded');
288
604
  void fetchDirectory(ROOT_LOAD_KEY);
289
605
  void refreshGitignoreMatcher();
606
+ const gitStatusPoll = new Poll({
607
+ name: '@xtralab/fileBrowser:gitStatus',
608
+ factory: () => refreshGitStatus(),
609
+ frequency: {
610
+ interval: GIT_STATUS_POLL_INTERVAL_MS,
611
+ backoff: true,
612
+ max: GIT_STATUS_POLL_MAX_MS
613
+ },
614
+ standby: 'when-hidden'
615
+ });
616
+ // Auto-refresh the file listing on the same cadence as the default
617
+ // JupyterLab file browser. Backoff on failures so a server-side
618
+ // outage doesn't hammer the API, and stand by when the tab is
619
+ // hidden so we don't run the polling loop while the user is in
620
+ // another tab. `auto: false` keeps the first tick from racing the
621
+ // initial `fetchDirectory(ROOT_LOAD_KEY)` above — the poll is
622
+ // started explicitly once the initial load is in flight.
623
+ const listingPoll = new Poll({
624
+ auto: false,
625
+ name: '@xtralab/fileBrowser:listing',
626
+ factory: () => quietRefresh(),
627
+ frequency: {
628
+ interval: FILE_LISTING_REFRESH_INTERVAL_MS,
629
+ backoff: true,
630
+ max: FILE_LISTING_REFRESH_MAX_MS
631
+ },
632
+ standby: 'when-hidden'
633
+ });
634
+ void listingPoll.start();
635
+ // Surface contents changes that happen inside JupyterLab (file save,
636
+ // rename, delete) without waiting for the next poll tick. The
637
+ // default file browser uses the same `fileChanged` signal for the
638
+ // same reason. We can't tell from the signal alone whether the
639
+ // change affects a path we're showing, so we just nudge the poll —
640
+ // it diffs the loaded directories and emits no batch ops when
641
+ // nothing relevant changed.
642
+ const onContentsFileChanged = () => {
643
+ void listingPoll.refresh();
644
+ };
645
+ contentsManager.fileChanged.connect(onContentsFileChanged);
290
646
  const unsubscribe = model.subscribe(() => {
291
647
  knownDirs.forEach((state, canonicalPath) => {
292
648
  if (state !== 'unloaded') {
@@ -305,6 +661,9 @@ export function FileBrowserComponent(props) {
305
661
  });
306
662
  let refreshSlot;
307
663
  let pathAddedSlot;
664
+ let revealSlot;
665
+ let rootSlot;
666
+ let collapseAllSlot;
308
667
  if (widget !== undefined) {
309
668
  refreshSlot = () => {
310
669
  void refreshAll();
@@ -312,11 +671,26 @@ export function FileBrowserComponent(props) {
312
671
  pathAddedSlot = (_sender, path) => {
313
672
  handlePathAdded(path);
314
673
  };
674
+ revealSlot = (_sender, path) => {
675
+ void revealPath(path);
676
+ };
677
+ rootSlot = () => {
678
+ goToRoot();
679
+ };
680
+ collapseAllSlot = () => {
681
+ collapseAll();
682
+ };
315
683
  widget.refreshRequested.connect(refreshSlot);
316
684
  widget.pathAdded.connect(pathAddedSlot);
685
+ widget.revealRequested.connect(revealSlot);
686
+ widget.rootRequested.connect(rootSlot);
687
+ widget.collapseAllRequested.connect(collapseAllSlot);
317
688
  }
318
689
  return () => {
319
690
  cancelled = true;
691
+ gitStatusPoll.dispose();
692
+ contentsManager.fileChanged.disconnect(onContentsFileChanged);
693
+ listingPoll.dispose();
320
694
  unsubscribe();
321
695
  if (widget !== undefined) {
322
696
  if (refreshSlot !== undefined) {
@@ -325,6 +699,15 @@ export function FileBrowserComponent(props) {
325
699
  if (pathAddedSlot !== undefined) {
326
700
  widget.pathAdded.disconnect(pathAddedSlot);
327
701
  }
702
+ if (revealSlot !== undefined) {
703
+ widget.revealRequested.disconnect(revealSlot);
704
+ }
705
+ if (rootSlot !== undefined) {
706
+ widget.rootRequested.disconnect(rootSlot);
707
+ }
708
+ if (collapseAllSlot !== undefined) {
709
+ widget.collapseAllRequested.disconnect(collapseAllSlot);
710
+ }
328
711
  }
329
712
  };
330
713
  }, [model, contentsManager, widget]);
@@ -0,0 +1,13 @@
1
+ import type { GitStatusEntry } from '@pierre/trees';
2
+ /**
3
+ * Fetch the porcelain status for `repoPath` and convert it into a flat list
4
+ * of `GitStatusEntry` values consumable by `FileTree.setGitStatus`. Returns
5
+ * an empty array when the path is not in a git repo, the request fails, or
6
+ * the server reports a non-zero exit — the file browser must still work
7
+ * without git, so any error here is a no-op rather than a thrown exception.
8
+ *
9
+ * Files that have both a staged and an unstaged change are collapsed into a
10
+ * single entry: the unstaged status wins because that mirrors what is
11
+ * actually different on disk and matches VS Code's tree decoration behavior.
12
+ */
13
+ export declare function loadGitStatusEntries(repoPath: string): Promise<GitStatusEntry[]>;
@@ -0,0 +1,60 @@
1
+ import { expandStatusFiles, status } from '../git/api';
2
+ /**
3
+ * Translate a `jupyterlab_git` porcelain status into the closest
4
+ * `@pierre/trees` `GitStatus` enum value. The tree library only supports the
5
+ * six common statuses (added, deleted, ignored, modified, renamed, untracked)
6
+ * so the rare ones (unmerged, typechange, unknown) collapse onto `modified`
7
+ * — they all denote a pending change the user should see decorated.
8
+ */
9
+ function toTreeStatus(value) {
10
+ switch (value) {
11
+ case 'added':
12
+ case 'deleted':
13
+ case 'modified':
14
+ case 'renamed':
15
+ case 'untracked':
16
+ return value;
17
+ case 'unmerged':
18
+ case 'typechange':
19
+ case 'unknown':
20
+ default:
21
+ return 'modified';
22
+ }
23
+ }
24
+ /**
25
+ * Fetch the porcelain status for `repoPath` and convert it into a flat list
26
+ * of `GitStatusEntry` values consumable by `FileTree.setGitStatus`. Returns
27
+ * an empty array when the path is not in a git repo, the request fails, or
28
+ * the server reports a non-zero exit — the file browser must still work
29
+ * without git, so any error here is a no-op rather than a thrown exception.
30
+ *
31
+ * Files that have both a staged and an unstaged change are collapsed into a
32
+ * single entry: the unstaged status wins because that mirrors what is
33
+ * actually different on disk and matches VS Code's tree decoration behavior.
34
+ */
35
+ export async function loadGitStatusEntries(repoPath) {
36
+ try {
37
+ const result = await status(repoPath);
38
+ if (result.code !== 0) {
39
+ return [];
40
+ }
41
+ const changes = expandStatusFiles(result.files);
42
+ // Collapse staged + unstaged into one decoration per file. Prefer the
43
+ // unstaged group when both exist; otherwise keep whichever group is
44
+ // present.
45
+ const byPath = new Map();
46
+ for (const change of changes) {
47
+ if (change.group === 'unstaged' || !byPath.has(change.path)) {
48
+ byPath.set(change.path, change.status);
49
+ }
50
+ }
51
+ const entries = [];
52
+ byPath.forEach((value, path) => {
53
+ entries.push({ path, status: toTreeStatus(value) });
54
+ });
55
+ return entries;
56
+ }
57
+ catch (_a) {
58
+ return [];
59
+ }
60
+ }
@@ -56,6 +56,28 @@ export interface IXtralabFileBrowser {
56
56
  * sees the new item without a full refresh.
57
57
  */
58
58
  readonly pathAdded: ISignal<IXtralabFileBrowser, string>;
59
+ /**
60
+ * Emits when an external caller asks the tree to scroll to and select
61
+ * the given canonical path. The React component listens, lazily loads
62
+ * any unloaded ancestor directories, expands them, and selects the
63
+ * target. Used by the editor breadcrumbs to jump back to a file or
64
+ * folder shown in the breadcrumb trail.
65
+ */
66
+ readonly revealRequested: ISignal<IXtralabFileBrowser, string>;
67
+ /**
68
+ * Emits when an external caller asks the tree to return to the
69
+ * workspace root: clear any current selection and scroll back to the
70
+ * first row. Distinct from {@link revealRequested} because the
71
+ * workspace root has no tree row of its own — it cannot be reached
72
+ * by passing a path.
73
+ */
74
+ readonly rootRequested: ISignal<IXtralabFileBrowser, void>;
75
+ /**
76
+ * Emits when an external caller asks the tree to collapse every
77
+ * expanded folder. The React component listens and walks the loaded
78
+ * directories, calling `.collapse()` on each expanded one.
79
+ */
80
+ readonly collapseAllRequested: ISignal<IXtralabFileBrowser, void>;
59
81
  /** Trigger a refresh of every loaded directory in the tree. */
60
82
  refresh(): void;
61
83
  /**
@@ -64,6 +86,23 @@ export interface IXtralabFileBrowser {
64
86
  * convention: directories carry a trailing slash, files do not.
65
87
  */
66
88
  notifyPathAdded(canonicalPath: string): void;
89
+ /**
90
+ * Ask the tree to reveal {@link canonicalPath}: load and expand any
91
+ * unloaded ancestor directories, then select and scroll the target
92
+ * into view. `canonicalPath` follows the `@pierre/trees` convention
93
+ * (directories carry a trailing slash, files do not). Must be a
94
+ * non-empty path — use {@link scrollToRoot} for the root gesture.
95
+ */
96
+ reveal(canonicalPath: string): void;
97
+ /**
98
+ * Ask the tree to return to the workspace root: clear any current
99
+ * selection and scroll back to the top of the tree.
100
+ */
101
+ scrollToRoot(): void;
102
+ /**
103
+ * Ask the tree to collapse every currently expanded folder.
104
+ */
105
+ collapseAll(): void;
67
106
  }
68
107
  /**
69
108
  * Lumino widget that hosts the React-based `@pierre/trees` file browser.
@@ -78,6 +117,9 @@ export declare class XtralabFileBrowser extends Widget implements IXtralabFileBr
78
117
  get selectionChanged(): ISignal<this, readonly string[]>;
79
118
  get refreshRequested(): ISignal<this, void>;
80
119
  get pathAdded(): ISignal<this, string>;
120
+ get revealRequested(): ISignal<this, string>;
121
+ get rootRequested(): ISignal<this, void>;
122
+ get collapseAllRequested(): ISignal<this, void>;
81
123
  /**
82
124
  * Update the cached selection. Called from the React tree when the
83
125
  * underlying `@pierre/trees` model emits a selection change.
@@ -85,6 +127,9 @@ export declare class XtralabFileBrowser extends Widget implements IXtralabFileBr
85
127
  updateSelection(paths: readonly string[]): void;
86
128
  refresh(): void;
87
129
  notifyPathAdded(canonicalPath: string): void;
130
+ reveal(canonicalPath: string): void;
131
+ scrollToRoot(): void;
132
+ collapseAll(): void;
88
133
  private _contentsManager;
89
134
  private _docManager;
90
135
  private _onOpenFile;
@@ -92,6 +137,9 @@ export declare class XtralabFileBrowser extends Widget implements IXtralabFileBr
92
137
  private _selectionChanged;
93
138
  private _refreshRequested;
94
139
  private _pathAdded;
140
+ private _revealRequested;
141
+ private _rootRequested;
142
+ private _collapseAllRequested;
95
143
  private _toolbar;
96
144
  private _content;
97
145
  }
@@ -26,6 +26,9 @@ export class XtralabFileBrowser extends Widget {
26
26
  this._selectionChanged = new Signal(this);
27
27
  this._refreshRequested = new Signal(this);
28
28
  this._pathAdded = new Signal(this);
29
+ this._revealRequested = new Signal(this);
30
+ this._rootRequested = new Signal(this);
31
+ this._collapseAllRequested = new Signal(this);
29
32
  const layout = (this.layout = new PanelLayout());
30
33
  this._contentsManager = options.contentsManager;
31
34
  this._docManager = options.docManager;
@@ -65,6 +68,15 @@ export class XtralabFileBrowser extends Widget {
65
68
  get pathAdded() {
66
69
  return this._pathAdded;
67
70
  }
71
+ get revealRequested() {
72
+ return this._revealRequested;
73
+ }
74
+ get rootRequested() {
75
+ return this._rootRequested;
76
+ }
77
+ get collapseAllRequested() {
78
+ return this._collapseAllRequested;
79
+ }
68
80
  /**
69
81
  * Update the cached selection. Called from the React tree when the
70
82
  * underlying `@pierre/trees` model emits a selection change.
@@ -79,6 +91,18 @@ export class XtralabFileBrowser extends Widget {
79
91
  notifyPathAdded(canonicalPath) {
80
92
  this._pathAdded.emit(canonicalPath);
81
93
  }
94
+ reveal(canonicalPath) {
95
+ if (canonicalPath.length === 0) {
96
+ throw new Error('XtralabFileBrowser.reveal requires a non-empty canonical path; use scrollToRoot for the workspace root.');
97
+ }
98
+ this._revealRequested.emit(canonicalPath);
99
+ }
100
+ scrollToRoot() {
101
+ this._rootRequested.emit();
102
+ }
103
+ collapseAll() {
104
+ this._collapseAllRequested.emit();
105
+ }
82
106
  }
83
107
  /**
84
108
  * The React-rendered region of the file browser. Lives inside the host