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.
- package/README.md +10 -0
- package/lib/about/icons.d.ts +0 -5
- package/lib/about/icons.js +0 -5
- package/lib/about/index.d.ts +4 -8
- package/lib/about/index.js +6 -17
- package/lib/agentSessions.d.ts +9 -29
- package/lib/agentSessions.js +2 -7
- package/lib/askAgent/editorSelection.d.ts +20 -26
- package/lib/askAgent/editorSelection.js +11 -26
- package/lib/askAgent/icons.d.ts +2 -3
- package/lib/askAgent/icons.js +2 -3
- package/lib/askAgent/index.d.ts +4 -26
- package/lib/askAgent/index.js +54 -158
- package/lib/askAgent/popup.d.ts +12 -16
- package/lib/askAgent/popup.js +18 -37
- package/lib/askAgent/prompt.d.ts +3 -5
- package/lib/askAgent/prompt.js +6 -19
- package/lib/askAgent/queue.d.ts +11 -21
- package/lib/askAgent/queue.js +9 -19
- package/lib/askAgent/queuePanel.d.ts +13 -18
- package/lib/askAgent/queuePanel.js +15 -37
- package/lib/askAgent/targetPicker.d.ts +2 -9
- package/lib/askAgent/targetPicker.js +6 -11
- package/lib/askAgent/tokens.d.ts +32 -46
- package/lib/askAgent/tokens.js +4 -6
- package/lib/commandBar/index.d.ts +4 -13
- package/lib/commandBar/index.js +21 -39
- package/lib/customPanel/index.js +15 -0
- package/lib/editorBreadcrumbs/index.d.ts +3 -6
- package/lib/editorBreadcrumbs/index.js +10 -6
- package/lib/editorBreadcrumbs/widget.d.ts +17 -4
- package/lib/editorBreadcrumbs/widget.js +11 -17
- package/lib/editorIndent/index.d.ts +4 -12
- package/lib/editorIndent/index.js +8 -23
- package/lib/fileBrowser/commands.d.ts +28 -19
- package/lib/fileBrowser/commands.js +39 -98
- package/lib/fileBrowser/contents.d.ts +3 -0
- package/lib/fileBrowser/dragAndDrop.d.ts +17 -4
- package/lib/fileBrowser/dragAndDrop.js +2 -7
- package/lib/fileBrowser/fileBrowser.d.ts +19 -9
- package/lib/fileBrowser/fileBrowser.js +68 -216
- package/lib/fileBrowser/gitStatus.d.ts +4 -9
- package/lib/fileBrowser/gitStatus.js +7 -17
- package/lib/fileBrowser/gitignore.d.ts +4 -17
- package/lib/fileBrowser/gitignore.js +4 -25
- package/lib/fileBrowser/icons.d.ts +7 -17
- package/lib/fileBrowser/icons.js +25 -80
- package/lib/fileBrowser/index.js +2 -4
- package/lib/fileBrowser/widget.d.ts +126 -48
- package/lib/fileBrowser/widget.js +89 -4
- package/lib/fileTypeIcons/index.js +0 -10
- package/lib/git/api.d.ts +5 -13
- package/lib/git/api.js +10 -36
- package/lib/git/askRequest.d.ts +4 -8
- package/lib/git/askRequest.js +6 -20
- package/lib/git/commands.d.ts +40 -5
- package/lib/git/commands.js +16 -10
- package/lib/git/diffModel.js +4 -0
- package/lib/git/diffSurface.d.ts +41 -55
- package/lib/git/diffSurface.js +42 -117
- package/lib/git/diffWidget.d.ts +81 -2
- package/lib/git/diffWidget.js +62 -12
- package/lib/git/imageDiff.d.ts +5 -6
- package/lib/git/imageDiff.js +18 -48
- package/lib/git/index.d.ts +0 -3
- package/lib/git/index.js +3 -8
- package/lib/git/notebookDiff.d.ts +110 -33
- package/lib/git/notebookDiff.js +52 -195
- package/lib/git/tokens.d.ts +73 -31
- package/lib/git/tokens.js +2 -3
- package/lib/highlight/index.d.ts +4 -10
- package/lib/highlight/index.js +10 -41
- package/lib/index.d.ts +0 -9
- package/lib/index.js +0 -9
- package/lib/launcher/agents.d.ts +55 -51
- package/lib/launcher/agents.js +15 -57
- package/lib/launcher/availability.d.ts +3 -9
- package/lib/launcher/availability.js +3 -9
- package/lib/launcher/commands.d.ts +7 -32
- package/lib/launcher/commands.js +14 -45
- package/lib/launcher/dashboard.d.ts +19 -24
- package/lib/launcher/dashboard.js +21 -67
- package/lib/launcher/editorRegistry.d.ts +10 -22
- package/lib/launcher/editorRegistry.js +14 -18
- package/lib/launcher/editors.d.ts +39 -45
- package/lib/launcher/editors.js +8 -34
- package/lib/launcher/icons.d.ts +0 -12
- package/lib/launcher/icons.js +5 -39
- package/lib/launcher/index.js +12 -55
- package/lib/launcher/invocation.d.ts +4 -10
- package/lib/launcher/invocation.js +7 -22
- package/lib/launcher/registry.d.ts +9 -7
- package/lib/launcher/registry.js +9 -7
- package/lib/launcher/tokens.d.ts +10 -22
- package/lib/launcher/tokens.js +5 -8
- package/lib/menuBar/index.d.ts +3 -10
- package/lib/menuBar/index.js +11 -28
- package/lib/menus/index.d.ts +3 -9
- package/lib/menus/index.js +14 -30
- package/lib/omnibox/files.d.ts +2 -4
- package/lib/omnibox/files.js +5 -11
- package/lib/omnibox/index.d.ts +4 -14
- package/lib/omnibox/index.js +9 -27
- package/lib/omnibox/model.d.ts +38 -10
- package/lib/omnibox/model.js +15 -33
- package/lib/omnibox/recents.d.ts +15 -17
- package/lib/omnibox/recents.js +12 -17
- package/lib/omnibox/tokens.d.ts +5 -10
- package/lib/omnibox/tokens.js +2 -6
- package/lib/omnibox/widget.d.ts +11 -7
- package/lib/omnibox/widget.js +8 -16
- package/lib/searchReplace/index.d.ts +4 -20
- package/lib/searchReplace/index.js +7 -27
- package/lib/showOutput/index.d.ts +3 -12
- package/lib/showOutput/index.js +6 -22
- package/lib/sidebar/index.d.ts +4 -7
- package/lib/sidebar/index.js +5 -12
- package/lib/terminalNotifications/index.d.ts +4 -10
- package/lib/terminalNotifications/index.js +6 -20
- package/lib/terminals/agentTerminals.d.ts +12 -5
- package/lib/terminals/agentTerminals.js +25 -44
- package/lib/terminals/detection.d.ts +4 -8
- package/lib/terminals/detection.js +4 -8
- package/lib/terminals/index.d.ts +0 -35
- package/lib/terminals/index.js +12 -101
- package/lib/terminals/model.d.ts +64 -139
- package/lib/terminals/model.js +80 -220
- package/lib/terminals/tokens.d.ts +11 -22
- package/lib/terminals/tokens.js +2 -2
- package/lib/terminals/widget.d.ts +43 -13
- package/lib/terminals/widget.js +33 -18
- package/lib/topBar/icons.d.ts +3 -8
- package/lib/topBar/icons.js +3 -8
- package/lib/topBar/index.d.ts +4 -11
- package/lib/topBar/index.js +10 -38
- package/lib/walkthrough/index.d.ts +4 -9
- package/lib/walkthrough/index.js +6 -20
- package/lib/walkthrough/panel.d.ts +40 -9
- package/lib/walkthrough/panel.js +4 -10
- package/package.json +2 -2
- package/src/about/icons.ts +0 -5
- package/src/about/index.tsx +6 -17
- package/src/agentSessions.ts +9 -29
- package/src/askAgent/editorSelection.ts +22 -29
- package/src/askAgent/icons.ts +2 -3
- package/src/askAgent/index.ts +54 -158
- package/src/askAgent/popup.tsx +23 -45
- package/src/askAgent/prompt.ts +6 -19
- package/src/askAgent/queue.ts +13 -24
- package/src/askAgent/queuePanel.tsx +21 -46
- package/src/askAgent/targetPicker.tsx +5 -15
- package/src/askAgent/tokens.ts +32 -46
- package/src/commandBar/index.ts +24 -39
- package/src/customPanel/index.ts +15 -0
- package/src/editorBreadcrumbs/index.ts +10 -6
- package/src/editorBreadcrumbs/widget.ts +23 -17
- package/src/editorIndent/index.ts +17 -23
- package/src/fileBrowser/commands.ts +57 -98
- package/src/fileBrowser/contents.ts +3 -0
- package/src/fileBrowser/dragAndDrop.ts +17 -7
- package/src/fileBrowser/fileBrowser.tsx +84 -223
- package/src/fileBrowser/gitStatus.ts +7 -17
- package/src/fileBrowser/gitignore.ts +4 -25
- package/src/fileBrowser/icons.ts +25 -80
- package/src/fileBrowser/index.ts +2 -4
- package/src/fileBrowser/widget.tsx +149 -50
- package/src/fileTypeIcons/index.ts +0 -10
- package/src/git/api.ts +10 -36
- package/src/git/askRequest.ts +6 -20
- package/src/git/commands.ts +70 -10
- package/src/git/diffModel.ts +25 -0
- package/src/git/diffSurface.tsx +71 -159
- package/src/git/diffWidget.tsx +104 -14
- package/src/git/imageDiff.tsx +45 -51
- package/src/git/index.ts +3 -8
- package/src/git/notebookDiff.tsx +211 -238
- package/src/git/tokens.ts +73 -31
- package/src/highlight/index.ts +10 -41
- package/src/index.ts +0 -9
- package/src/launcher/agents.ts +64 -95
- package/src/launcher/availability.ts +3 -9
- package/src/launcher/commands.ts +14 -51
- package/src/launcher/dashboard.tsx +49 -88
- package/src/launcher/editorRegistry.ts +21 -29
- package/src/launcher/editors.ts +39 -58
- package/src/launcher/icons.ts +5 -39
- package/src/launcher/index.ts +12 -55
- package/src/launcher/invocation.ts +7 -22
- package/src/launcher/registry.ts +9 -7
- package/src/launcher/tokens.ts +10 -22
- package/src/menuBar/index.ts +11 -28
- package/src/menus/index.ts +14 -30
- package/src/omnibox/files.ts +10 -14
- package/src/omnibox/index.ts +9 -27
- package/src/omnibox/model.ts +50 -38
- package/src/omnibox/recents.ts +17 -22
- package/src/omnibox/tokens.ts +5 -10
- package/src/omnibox/widget.tsx +14 -19
- package/src/searchReplace/index.ts +7 -27
- package/src/showOutput/index.ts +6 -22
- package/src/sidebar/index.ts +20 -12
- package/src/terminalNotifications/index.ts +42 -25
- package/src/terminals/agentTerminals.ts +25 -49
- package/src/terminals/detection.ts +4 -8
- package/src/terminals/index.ts +12 -101
- package/src/terminals/model.ts +130 -246
- package/src/terminals/tokens.ts +11 -22
- package/src/terminals/widget.tsx +48 -31
- package/src/topBar/icons.ts +3 -8
- package/src/topBar/index.ts +21 -44
- package/src/walkthrough/index.ts +6 -20
- package/src/walkthrough/panel.ts +40 -10
- package/style/about.css +2 -7
- package/style/askAgent.css +8 -40
- package/style/base.css +9 -45
- package/style/chrome.css +108 -308
- package/style/commandBar.css +4 -20
- package/style/customPanel.css +1 -4
- package/style/git.css +22 -184
- package/style/highlight.css +1 -3
- package/style/launcher.css +6 -70
- package/style/omnibox.css +2 -14
- package/style/showOutput.css +0 -6
- package/style/sidebar.css +29 -9
- package/style/tabs.css +5 -13
- package/style/terminals.css +6 -53
- package/style/topBar.css +2 -22
- 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
|
-
*
|
|
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
|
-
*
|
|
48
|
-
*
|
|
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
|
-
*
|
|
63
|
-
*
|
|
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
|
-
*
|
|
80
|
-
*
|
|
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
|
|
95
|
-
* box unless the host carries the
|
|
96
|
-
*
|
|
97
|
-
*
|
|
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
|
|
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
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
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
|
|
163
|
-
//
|
|
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
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
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
|
-
//
|
|
257
|
-
//
|
|
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
|
-
//
|
|
267
|
-
//
|
|
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
|
-
*
|
|
293
|
-
*
|
|
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
|
-
//
|
|
334
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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:
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
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
|
-
//
|
|
437
|
-
//
|
|
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
|
|
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
|
-
//
|
|
498
|
-
//
|
|
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
|
-
//
|
|
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
|
-
*
|
|
546
|
-
*
|
|
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
|
-
//
|
|
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
|
-
// `
|
|
672
|
-
//
|
|
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
|
|
679
|
-
*
|
|
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
|
-
//
|
|
694
|
-
//
|
|
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
|
-
//
|
|
870
|
-
//
|
|
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
|
-
//
|
|
890
|
-
//
|
|
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-
|
|
903
|
-
//
|
|
904
|
-
//
|
|
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
|
|
987
|
-
//
|
|
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
|
-
//
|
|
1015
|
-
//
|
|
1016
|
-
//
|
|
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
|
-
//
|
|
1089
|
-
//
|
|
1090
|
-
//
|
|
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) {
|