dsh-remote-vs 0.13.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.en.md +455 -443
- package/README.md +408 -396
- package/lib/client.js +8062 -2651
- package/lib/index.js +1058 -288
- package/lib/p2-router-fs.js +1 -1
- package/lib/p2-router-refs.js +89 -10
- package/lib/p2-router-spill.js +73 -1
- package/lib/p2-router-subprocess.js +18 -6
- package/lib/spill-retention-BwKEWrl5.js +115 -0
- package/lib/{ssh-proc-arI5lm4W.js → ssh-proc-VKWn_LZC.js} +17 -0
- package/lib/types/archive.d.ts +1 -1
- package/lib/types/changes/recorder.d.ts +34 -2
- package/lib/types/client/CodeEditor.d.ts +12 -0
- package/lib/types/client/ConnectionStatus.d.ts +17 -0
- package/lib/types/client/DirectoryFlow.d.ts +2 -0
- package/lib/types/client/DoctorPanel.d.ts +25 -0
- package/lib/types/client/QuickOpen.d.ts +17 -0
- package/lib/types/client/RemoteExplorer.d.ts +192 -1
- package/lib/types/client/RemoteRoot.d.ts +17 -0
- package/lib/types/client/SearchView.d.ts +55 -0
- package/lib/types/client/TerminalView.d.ts +38 -0
- package/lib/types/client/WorkspaceWizard.d.ts +17 -0
- package/lib/types/client/api.d.ts +54 -4
- package/lib/types/client/changes/undo-affordance.d.ts +16 -0
- package/lib/types/client/changes/undo-context.d.ts +14 -18
- package/lib/types/client/changes/undo-target.d.ts +78 -0
- package/lib/types/client/connection.d.ts +111 -0
- package/lib/types/client/doctor.d.ts +122 -0
- package/lib/types/client/download.d.ts +35 -5
- package/lib/types/client/downloads.d.ts +18 -1
- package/lib/types/client/file-open-probe.d.ts +64 -0
- package/lib/types/client/i18n.d.ts +1 -1
- package/lib/types/client/quickopen-model.d.ts +332 -0
- package/lib/types/client/scm/DiffView.d.ts +34 -0
- package/lib/types/client/scm/actions.d.ts +18 -0
- package/lib/types/client/scm/diff-model.d.ts +17 -1
- package/lib/types/client/scm/git-cache.d.ts +10 -2
- package/lib/types/client/scm/read-queue.d.ts +2 -1
- package/lib/types/client/scm/stage-queue.d.ts +13 -0
- package/lib/types/client/scm/status-map.d.ts +3 -1
- package/lib/types/client/store.d.ts +114 -5
- package/lib/types/client/vsc/FindWidget.d.ts +7 -0
- package/lib/types/client/vsc/save-shortcut.d.ts +57 -0
- package/lib/types/deploy.d.ts +44 -2
- package/lib/types/git-format.d.ts +15 -0
- package/lib/types/http.d.ts +44 -0
- package/lib/types/p2/file-refs.d.ts +39 -2
- package/lib/types/p2/helper-rpc.d.ts +26 -0
- package/lib/types/p2/router-spill.d.ts +19 -0
- package/lib/types/p2/router-subprocess.d.ts +2 -0
- package/lib/types/p2/spill-retention.d.ts +74 -0
- package/lib/types/p2/worlds.d.ts +11 -0
- package/lib/types/pool.d.ts +73 -11
- package/lib/types/protocol.d.ts +63 -0
- package/lib/types/routes.d.ts +18 -0
- package/lib/types/sftp.d.ts +114 -8
- package/lib/types/store.d.ts +34 -0
- package/lib/types/timeouts.d.ts +14 -0
- package/lib/{worlds-C6Xha1mQ.js → worlds-Be1YE2Ot.js} +727 -78
- package/package.json +1 -1
- package/src/archive.ts +41 -9
- package/src/changes/recorder.ts +227 -31
- package/src/changes/status.ts +37 -1
- package/src/client/CodeEditor.tsx +84 -2
- package/src/client/ConnectionStatus.tsx +130 -0
- package/src/client/DirectoryFlow.tsx +40 -5
- package/src/client/DoctorPanel.tsx +202 -0
- package/src/client/DownloadDock.tsx +13 -25
- package/src/client/EditorPane.tsx +291 -7
- package/src/client/HostsView.tsx +17 -8
- package/src/client/QuickOpen.tsx +371 -0
- package/src/client/RemoteDirectoryPicker.tsx +54 -3
- package/src/client/RemoteExplorer.tsx +879 -160
- package/src/client/RemoteRoot.tsx +178 -1
- package/src/client/SearchView.tsx +180 -6
- package/src/client/SettingsHosts.tsx +1 -1
- package/src/client/TerminalView.tsx +174 -9
- package/src/client/WorkspaceWizard.tsx +110 -16
- package/src/client/WorkspacesView.tsx +22 -6
- package/src/client/api.ts +197 -11
- package/src/client/changes/ChangesDock.tsx +35 -8
- package/src/client/changes/undo-affordance.ts +33 -0
- package/src/client/changes/undo-context.ts +14 -18
- package/src/client/changes/undo-target.ts +139 -0
- package/src/client/connection.ts +264 -0
- package/src/client/doctor.ts +441 -0
- package/src/client/download.ts +148 -12
- package/src/client/downloads.ts +43 -2
- package/src/client/file-open-probe.ts +83 -0
- package/src/client/i18n.ts +244 -0
- package/src/client/index.tsx +5 -2
- package/src/client/quickopen-model.ts +778 -0
- package/src/client/remote-file-open.ts +21 -33
- package/src/client/scm/DiffView.tsx +116 -6
- package/src/client/scm/ScmPanel.tsx +19 -0
- package/src/client/scm/actions.ts +34 -2
- package/src/client/scm/diff-model.ts +33 -37
- package/src/client/scm/git-cache.ts +61 -4
- package/src/client/scm/read-queue.ts +33 -2
- package/src/client/scm/stage-queue.ts +72 -1
- package/src/client/scm/status-map.ts +22 -1
- package/src/client/store.tsx +704 -21
- package/src/client/vsc/FindWidget.tsx +20 -0
- package/src/client/vsc/kit.tsx +115 -6
- package/src/client/vsc/reveal-line.ts +33 -14
- package/src/client/vsc/save-shortcut.ts +131 -0
- package/src/client/vsc/vsc.css +419 -0
- package/src/deploy.ts +185 -33
- package/src/git-format.ts +136 -22
- package/src/git-ops.ts +14 -6
- package/src/http.ts +80 -12
- package/src/importers.ts +80 -21
- package/src/index.ts +21 -1
- package/src/p2/file-refs.ts +112 -10
- package/src/p2/helper-rpc.ts +73 -36
- package/src/p2/router-spill.ts +96 -1
- package/src/p2/router-subprocess.ts +18 -5
- package/src/p2/spill-retention.ts +134 -0
- package/src/p2/ssh-proc.ts +22 -0
- package/src/p2/worlds.ts +24 -0
- package/src/pool.ts +329 -47
- package/src/protocol.ts +66 -0
- package/src/routes.ts +251 -43
- package/src/sftp.ts +486 -26
- package/src/store.ts +207 -85
- package/src/terminal.ts +38 -2
- package/src/timeouts.ts +14 -0
- package/src/tools.ts +14 -5
|
@@ -10,11 +10,12 @@
|
|
|
10
10
|
* previous explorer, and `insertRemoteReference` still writes into the
|
|
11
11
|
* on-screen session's composer draft.
|
|
12
12
|
*/
|
|
13
|
-
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
|
|
13
|
+
import { memo, useCallback, useEffect, useMemo, useRef, useState, type MutableRefObject, type ReactNode } from 'react'
|
|
14
14
|
import { copyIntoCommand, joinAbs, moveToCommand } from '../fs-ops.ts'
|
|
15
15
|
import { MAX_SELECTION_DOWNLOAD, type RemoteFileEntry } from '../protocol.ts'
|
|
16
16
|
import { api, uploadFile } from './api.ts'
|
|
17
17
|
import { startDownload, startSelectionDownload } from './downloads.ts'
|
|
18
|
+
import { useConnectionStatus, isConnectionFailure } from './connection.ts'
|
|
18
19
|
import { insertRemoteReference, sameLocalDir } from './composer.ts'
|
|
19
20
|
import { ListingRequests } from './listing-requests.ts'
|
|
20
21
|
import { repoRelative, useExplorer } from './store.tsx'
|
|
@@ -89,6 +90,158 @@ function dirKey(alias: string, dir: string): string {
|
|
|
89
90
|
return `${alias}:${dir}`
|
|
90
91
|
}
|
|
91
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Whether a "show this folder" request still needs to be processed.
|
|
95
|
+
*
|
|
96
|
+
* The store keeps the request object after it has been handled, and this effect
|
|
97
|
+
* re-runs whenever `root`/`loadDir` change (workspace switch, offline flip). No
|
|
98
|
+
* consumed marker meant switching back to a workspace replayed the OLD reveal:
|
|
99
|
+
* it re-expanded the ancestor chain and scrolled away from wherever the user was.
|
|
100
|
+
*/
|
|
101
|
+
export function shouldConsumeReveal(lastId: number, id: number): boolean {
|
|
102
|
+
return lastId !== id
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Whether a remote WRITE may start.
|
|
107
|
+
*
|
|
108
|
+
* Uploads hold one `AbortController` slot and a batch can run for minutes; a
|
|
109
|
+
* second upload used to overwrite that slot (the first became uncancellable and
|
|
110
|
+
* the two progress bars overwrote each other), and paste/delete could interleave
|
|
111
|
+
* with the transfer. Serializing writes through one flag is the smallest fix;
|
|
112
|
+
* read-only browsing stays allowed.
|
|
113
|
+
*/
|
|
114
|
+
export function writeAllowed(transferActive: boolean): boolean {
|
|
115
|
+
return !transferActive
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Whether the write ENTRIES (new file/folder, upload, paste, delete) are
|
|
120
|
+
* disabled right now.
|
|
121
|
+
*
|
|
122
|
+
* @param transferActive - is a write batch currently holding the slot?
|
|
123
|
+
*
|
|
124
|
+
* This is a named function, not an inline expression, because the expression it
|
|
125
|
+
* replaces was a double negative that inverted itself:
|
|
126
|
+
* `!writeAllowed(upload === undefined)` passes `true` ("busy") exactly when
|
|
127
|
+
* nothing is uploading, so the whole write menu was greyed out while idle and
|
|
128
|
+
* came alive during an upload — while the toolbar's own buttons, which test
|
|
129
|
+
* `upload !== undefined` directly, disagreed with it on the same screen. Two
|
|
130
|
+
* surfaces, one state, opposite answers.
|
|
131
|
+
*/
|
|
132
|
+
export function writeEntriesDisabled(transferActive: boolean): boolean {
|
|
133
|
+
return !writeAllowed(transferActive)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** True when `path` is `prefix` itself or a descendant of it. */
|
|
137
|
+
export function pathUnder(path: string, prefix: string): boolean {
|
|
138
|
+
return path === prefix || path.startsWith(`${prefix}/`)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Where a copy/cut/move of `sourcePath` into `intoDir` lands.
|
|
143
|
+
*
|
|
144
|
+
* `fs-ops`' commands copy/move the entry KEEPING its basename, so the new path
|
|
145
|
+
* is `intoDir/<basename>`; the explorer needs it to re-key its path indexes.
|
|
146
|
+
*/
|
|
147
|
+
export function destinationOfMove(intoDir: string, sourcePath: string): string {
|
|
148
|
+
const trimmed = sourcePath.replace(/\/+$/, '')
|
|
149
|
+
const base = trimmed.slice(trimmed.lastIndexOf('/') + 1)
|
|
150
|
+
return `${intoDir.replace(/\/+$/, '')}/${base}`
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Drop every path that is (or lives under) a removed path from a path-keyed set.
|
|
155
|
+
*
|
|
156
|
+
* `expanded` / `selected` / `anchor` are absolute-path indexes. Renaming re-keys
|
|
157
|
+
* them (see `rekeyPaths`), but deleting or moving a subtree used to leave the
|
|
158
|
+
* old paths behind: the root refresh effect then re-listed directories that no
|
|
159
|
+
* longer exist on every revision bump (one failed SFTP request and one error
|
|
160
|
+
* toast each), and `trimListings` protected those dead keys from eviction.
|
|
161
|
+
*/
|
|
162
|
+
export function withoutPaths(set: Set<string>, removed: readonly string[]): Set<string> {
|
|
163
|
+
if (removed.length === 0) return set
|
|
164
|
+
const next = new Set<string>()
|
|
165
|
+
let changed = false
|
|
166
|
+
for (const path of set) {
|
|
167
|
+
if (removed.some(root => pathUnder(path, root))) {
|
|
168
|
+
changed = true
|
|
169
|
+
continue
|
|
170
|
+
}
|
|
171
|
+
next.add(path)
|
|
172
|
+
}
|
|
173
|
+
return changed ? next : set
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Re-key a path-keyed set after a rename/move of `from` to `to`. */
|
|
177
|
+
export function rekeyPaths(set: Set<string>, from: string, to: string): Set<string> {
|
|
178
|
+
const next = new Set<string>()
|
|
179
|
+
let changed = false
|
|
180
|
+
for (const path of set) {
|
|
181
|
+
if (pathUnder(path, from)) {
|
|
182
|
+
next.add(`${to}${path.slice(from.length)}`)
|
|
183
|
+
changed = true
|
|
184
|
+
} else {
|
|
185
|
+
next.add(path)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return changed ? next : set
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Drop cached listings for removed paths.
|
|
193
|
+
*
|
|
194
|
+
* Same reason as `withoutPaths`, for the listing cache: a dead key would keep a
|
|
195
|
+
* whole directory's rows in memory forever (plus a requested-but-failing list
|
|
196
|
+
* on every refresh), while `trimListings` still counts it against the 50-entry
|
|
197
|
+
* budget of LIVE directories.
|
|
198
|
+
*/
|
|
199
|
+
export function withoutListingPaths(
|
|
200
|
+
listings: Record<string, RemoteFileEntry[]>,
|
|
201
|
+
alias: string,
|
|
202
|
+
removed: readonly string[],
|
|
203
|
+
): Record<string, RemoteFileEntry[]> {
|
|
204
|
+
if (removed.length === 0) return listings
|
|
205
|
+
const prefix = dirKey(alias, '')
|
|
206
|
+
const next: Record<string, RemoteFileEntry[]> = {}
|
|
207
|
+
let changed = false
|
|
208
|
+
for (const [key, rows] of Object.entries(listings)) {
|
|
209
|
+
const path = key.startsWith(prefix) ? key.slice(prefix.length) : key
|
|
210
|
+
if (removed.some(root => pathUnder(path, root))) {
|
|
211
|
+
changed = true
|
|
212
|
+
continue
|
|
213
|
+
}
|
|
214
|
+
next[key] = rows
|
|
215
|
+
}
|
|
216
|
+
return changed ? next : listings
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Re-key cached listings after a rename/move (memo keys are `alias:path`). */
|
|
220
|
+
export function rekeyListings(
|
|
221
|
+
listings: Record<string, RemoteFileEntry[]>,
|
|
222
|
+
alias: string,
|
|
223
|
+
from: string,
|
|
224
|
+
to: string,
|
|
225
|
+
): Record<string, RemoteFileEntry[]> {
|
|
226
|
+
const prefix = dirKey(alias, '')
|
|
227
|
+
const next: Record<string, RemoteFileEntry[]> = {}
|
|
228
|
+
let changed = false
|
|
229
|
+
for (const [key, rows] of Object.entries(listings)) {
|
|
230
|
+
if (!key.startsWith(prefix)) {
|
|
231
|
+
next[key] = rows
|
|
232
|
+
continue
|
|
233
|
+
}
|
|
234
|
+
const path = key.slice(prefix.length)
|
|
235
|
+
if (pathUnder(path, from)) {
|
|
236
|
+
next[dirKey(alias, `${to}${path.slice(from.length)}`)] = rows
|
|
237
|
+
changed = true
|
|
238
|
+
} else {
|
|
239
|
+
next[key] = rows
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return changed ? next : listings
|
|
243
|
+
}
|
|
244
|
+
|
|
92
245
|
/**
|
|
93
246
|
* Console trace for the drag & drop path.
|
|
94
247
|
*
|
|
@@ -199,9 +352,263 @@ function trimListings(
|
|
|
199
352
|
return next ?? prev
|
|
200
353
|
}
|
|
201
354
|
|
|
355
|
+
/**
|
|
356
|
+
* One rendered line of the flattened tree.
|
|
357
|
+
*
|
|
358
|
+
* The tree is rendered as a FLAT pre-order list (not nested components): the
|
|
359
|
+
* rows of a large directory then each own one memoized component whose props are
|
|
360
|
+
* primitives, so a selection change, an upload progress tick or an unrelated
|
|
361
|
+
* store publish only re-renders the rows that actually changed. Nesting the
|
|
362
|
+
* recursion in JSX made every row a child of its parent row, which defeated
|
|
363
|
+
* `memo` (the children element was new on every render).
|
|
364
|
+
*/
|
|
365
|
+
export type ExplorerRow =
|
|
366
|
+
| { kind: 'entry'; entry: RemoteFileEntry; depth: number }
|
|
367
|
+
| { kind: 'create'; dir: string; createKind: 'file' | 'folder'; depth: number }
|
|
368
|
+
/** An expanded directory whose listing is not available yet (loading/offline). */
|
|
369
|
+
| { kind: 'pending'; dir: string; depth: number; reason: 'loading' | 'offline' }
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* What double-clicking a row should open.
|
|
373
|
+
*
|
|
374
|
+
* `undefined` for a directory: `store.openFile()` has no type guard of its own,
|
|
375
|
+
* so handing it a directory path produced an editor tab whose Host read answers
|
|
376
|
+
* `not a file: … is a directory` — and the click also switched the surface to
|
|
377
|
+
* the editor. The guard lives here (and is applied in the row action) so every
|
|
378
|
+
* caller inherits it; the pre-refactor renderer had the same check inline.
|
|
379
|
+
*/
|
|
380
|
+
export function rowOpenTarget(entry: RemoteFileEntry): string | undefined {
|
|
381
|
+
return entry.isDir ? undefined : entry.path
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Flatten the loaded part of the tree into pre-order rows.
|
|
386
|
+
*
|
|
387
|
+
* Pure: the gate drives it with a synthetic `rowsOf`/`isExpanded` pair. The
|
|
388
|
+
* depth of a directory's entries is its own depth + 1 (same indentation the
|
|
389
|
+
* recursive renderer used), and the inline "new file/folder" row is emitted
|
|
390
|
+
* before that directory's children.
|
|
391
|
+
*
|
|
392
|
+
* `placeholderOf` makes an expanded directory with no listing yet emit a
|
|
393
|
+
* `pending` row. Before the flat rewrite the recursive renderer did this for
|
|
394
|
+
* EVERY directory; after it only the root had a placeholder, so expanding a
|
|
395
|
+
* cold (or offline) directory showed nothing until the listing landed.
|
|
396
|
+
*/
|
|
397
|
+
export function buildVisibleRows(input: {
|
|
398
|
+
root: string
|
|
399
|
+
rowsOf: (dir: string) => RemoteFileEntry[] | undefined
|
|
400
|
+
isExpanded: (path: string) => boolean
|
|
401
|
+
creating?: { dir: string; kind: 'file' | 'folder' }
|
|
402
|
+
placeholderOf?: (dir: string) => 'loading' | 'offline' | undefined
|
|
403
|
+
}): ExplorerRow[] {
|
|
404
|
+
if (input.root === '') return []
|
|
405
|
+
const out: ExplorerRow[] = []
|
|
406
|
+
const walk = (dir: string, depth: number): void => {
|
|
407
|
+
const creating = input.creating
|
|
408
|
+
if (creating?.dir === dir) out.push({ kind: 'create', dir, createKind: creating.kind, depth })
|
|
409
|
+
for (const entry of input.rowsOf(dir) ?? []) {
|
|
410
|
+
out.push({ kind: 'entry', entry, depth })
|
|
411
|
+
if (!entry.isDir || !input.isExpanded(entry.path)) continue
|
|
412
|
+
const children = input.rowsOf(entry.path)
|
|
413
|
+
if (children === undefined) {
|
|
414
|
+
const reason = input.placeholderOf?.(entry.path)
|
|
415
|
+
if (reason !== undefined) out.push({ kind: 'pending', dir: entry.path, depth: depth + 1, reason })
|
|
416
|
+
continue
|
|
417
|
+
}
|
|
418
|
+
walk(entry.path, depth + 1)
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
walk(input.root, 0)
|
|
422
|
+
return out
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Where a keyboard move from `currentPath` lands.
|
|
427
|
+
*
|
|
428
|
+
* Pure so the a11y gate can pin the tree navigation without mounting React:
|
|
429
|
+
* `up`/`down` walk the flat visible rows, `parent` finds the enclosing directory
|
|
430
|
+
* row (if it is still visible), `child` the first row under a directory.
|
|
431
|
+
*/
|
|
432
|
+
export function rowKeyboardTarget(
|
|
433
|
+
rows: readonly ExplorerRow[],
|
|
434
|
+
currentPath: string,
|
|
435
|
+
intent: 'up' | 'down' | 'parent' | 'child',
|
|
436
|
+
): string | undefined {
|
|
437
|
+
const entries = rows.filter((row): row is Extract<ExplorerRow, { kind: 'entry' }> => row.kind === 'entry')
|
|
438
|
+
const at = entries.findIndex(row => row.entry.path === currentPath)
|
|
439
|
+
if (at < 0) return undefined
|
|
440
|
+
if (intent === 'up') return entries[at - 1]?.entry.path
|
|
441
|
+
if (intent === 'down') return entries[at + 1]?.entry.path
|
|
442
|
+
const current = entries[at] as { depth: number }
|
|
443
|
+
if (intent === 'child') {
|
|
444
|
+
const next = entries[at + 1]
|
|
445
|
+
return next !== undefined && next.depth > current.depth ? next.entry.path : undefined
|
|
446
|
+
}
|
|
447
|
+
for (let index = at - 1; index >= 0; index -= 1) {
|
|
448
|
+
const candidate = entries[index] as { depth: number; entry: RemoteFileEntry }
|
|
449
|
+
if (candidate.depth < current.depth) return candidate.entry.path
|
|
450
|
+
}
|
|
451
|
+
return undefined
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Which row should own the tree's Tab stop.
|
|
456
|
+
*
|
|
457
|
+
* The roving tabindex puts `tabIndex={0}` on exactly ONE row (the focused one),
|
|
458
|
+
* so a focused path that stops existing — the row was deleted, renamed, or its
|
|
459
|
+
* directory collapsed — leaves every row at -1 and the whole tree unreachable by
|
|
460
|
+
* keyboard. This keeps a stop alive: an existing focused row wins, otherwise the
|
|
461
|
+
* first row does, otherwise none (empty tree).
|
|
462
|
+
*
|
|
463
|
+
* Pure, so the gate can pin the fallback without mounting React.
|
|
464
|
+
*/
|
|
465
|
+
export function nextFocusPath(rows: readonly ExplorerRow[], focusedPath: string | undefined): string | undefined {
|
|
466
|
+
const entries = rows.filter((row): row is Extract<ExplorerRow, { kind: 'entry' }> => row.kind === 'entry')
|
|
467
|
+
if (focusedPath !== undefined && entries.some(row => row.entry.path === focusedPath)) return focusedPath
|
|
468
|
+
return entries[0]?.entry.path
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/** Handlers one row needs, held in a ref so a memoized row never re-renders for them. */
|
|
472
|
+
export interface ExplorerRowActions {
|
|
473
|
+
select: (entry: RemoteFileEntry, event: React.MouseEvent) => void
|
|
474
|
+
openFile: (entry: RemoteFileEntry) => void
|
|
475
|
+
hoverDir: (path: string | undefined) => void
|
|
476
|
+
openMenu: (event: React.MouseEvent, entry: RemoteFileEntry) => void
|
|
477
|
+
contextMenu: (event: React.MouseEvent, entry: RemoteFileEntry) => void
|
|
478
|
+
startDrag: (entry: RemoteFileEntry) => void
|
|
479
|
+
dragOver: (entry: RemoteFileEntry, event: React.DragEvent) => void
|
|
480
|
+
dragLeave: (entry: RemoteFileEntry) => void
|
|
481
|
+
dropOn: (entry: RemoteFileEntry, event: React.DragEvent) => void
|
|
482
|
+
commitRename: (entry: RemoteFileEntry, name: string) => void
|
|
483
|
+
cancelRename: () => void
|
|
484
|
+
reference: (entry: RemoteFileEntry) => void
|
|
485
|
+
/** Keyboard navigation: ↑↓←→/Home/End/Enter/Space/Shift+F10 live in the parent. */
|
|
486
|
+
keyDown: (entry: RemoteFileEntry, event: React.KeyboardEvent) => void
|
|
487
|
+
focusPath: (path: string) => void
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
interface ExplorerRowProps {
|
|
491
|
+
entry: RemoteFileEntry
|
|
492
|
+
depth: number
|
|
493
|
+
status: string | undefined
|
|
494
|
+
ignored: boolean
|
|
495
|
+
isSelected: boolean
|
|
496
|
+
isOpen: boolean
|
|
497
|
+
isCut: boolean
|
|
498
|
+
isDropTarget: boolean
|
|
499
|
+
isRenaming: boolean
|
|
500
|
+
isFocused: boolean
|
|
501
|
+
chatEnabled: boolean
|
|
502
|
+
/** Precomputed so `t` (whose identity may change with a store publish) is not a prop. */
|
|
503
|
+
referenceTitle: string
|
|
504
|
+
symlinkTitle: string
|
|
505
|
+
actions: MutableRefObject<ExplorerRowActions>
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* One tree row.
|
|
510
|
+
*
|
|
511
|
+
* Memoized on primitive props: the parent re-renders on every store publish and
|
|
512
|
+
* on each upload-progress tick, and without this every one of those re-rendered
|
|
513
|
+
* the whole expanded tree (a 20 000-entry directory means 20 000 rows).
|
|
514
|
+
*/
|
|
515
|
+
export const ExplorerRowView = memo(function ExplorerRowView(props: ExplorerRowProps): ReactNode {
|
|
516
|
+
const { entry, depth, status, ignored, isSelected, isOpen, isCut, isDropTarget, isRenaming, isFocused, chatEnabled, actions } = props
|
|
517
|
+
const { openMenu } = actions.current
|
|
518
|
+
return (
|
|
519
|
+
<div
|
|
520
|
+
role="treeitem"
|
|
521
|
+
aria-level={depth + 1}
|
|
522
|
+
aria-selected={isSelected}
|
|
523
|
+
// Directories expose their expansion; files have no aria-expanded.
|
|
524
|
+
{...(entry.isDir ? { 'aria-expanded': isOpen } : {})}
|
|
525
|
+
tabIndex={isFocused ? 0 : -1}
|
|
526
|
+
onFocus={() => actions.current.focusPath(entry.path)}
|
|
527
|
+
onKeyDown={(e) => actions.current.keyDown(entry, e)}
|
|
528
|
+
className={[
|
|
529
|
+
'rvs-node',
|
|
530
|
+
isSelected ? 'selected' : '',
|
|
531
|
+
isCut ? 'cut' : '',
|
|
532
|
+
isDropTarget ? 'drop-target' : '',
|
|
533
|
+
isFocused ? 'focused' : '',
|
|
534
|
+
].filter(Boolean).join(' ')}
|
|
535
|
+
style={{ paddingLeft: 8 + depth * 14 }}
|
|
536
|
+
title={entry.path}
|
|
537
|
+
// Read by the document-level capture drop listeners, which live
|
|
538
|
+
// outside React's tree and cannot see component state.
|
|
539
|
+
data-rvs-path={entry.path}
|
|
540
|
+
data-rvs-dir={entry.isDir ? '1' : '0'}
|
|
541
|
+
draggable
|
|
542
|
+
onClick={(e) => actions.current.select(entry, e)}
|
|
543
|
+
onDoubleClick={() => actions.current.openFile(entry)}
|
|
544
|
+
// Hover-intent prefetch: a directory the pointer rests on gets its
|
|
545
|
+
// listing warmed, so the click that follows paints instead of
|
|
546
|
+
// waiting one round trip. Leave/collapse cancels the pending one.
|
|
547
|
+
onMouseEnter={() => { if (entry.isDir) actions.current.hoverDir(entry.path) }}
|
|
548
|
+
onMouseLeave={() => actions.current.hoverDir(undefined)}
|
|
549
|
+
// Right-click opens on POINTERDOWN — the first event of the
|
|
550
|
+
// gesture — so the menu is already mounted before any later
|
|
551
|
+
// event of the same click (a platform may replay mousedown, and
|
|
552
|
+
// a background git refresh may scroll) can close it. The
|
|
553
|
+
// contextmenu fallback covers surfaces that only send that
|
|
554
|
+
// (touch long-press).
|
|
555
|
+
onPointerDown={(e) => { if (e.button === 2) openMenu(e, entry) }}
|
|
556
|
+
onContextMenu={(e) => { actions.current.contextMenu(e, entry) }}
|
|
557
|
+
onDragStart={(e) => {
|
|
558
|
+
actions.current.startDrag(entry)
|
|
559
|
+
e.dataTransfer.effectAllowed = 'move'
|
|
560
|
+
e.dataTransfer.setData('text/plain', entry.path)
|
|
561
|
+
}}
|
|
562
|
+
onDragOver={(e) => { actions.current.dragOver(entry, e) }}
|
|
563
|
+
onDragLeave={() => { actions.current.dragLeave(entry) }}
|
|
564
|
+
onDrop={(e) => { actions.current.dropOn(entry, e) }}
|
|
565
|
+
>
|
|
566
|
+
<span className="rvs-node-icon">
|
|
567
|
+
{entry.isDir
|
|
568
|
+
? <FolderIcon path={entry.path} open={isOpen} size={15} />
|
|
569
|
+
: <FileIcon path={entry.path} size={15} />}
|
|
570
|
+
</span>
|
|
571
|
+
{isRenaming
|
|
572
|
+
? (
|
|
573
|
+
<RenameInput
|
|
574
|
+
initial={entry.name}
|
|
575
|
+
onCommit={(value) => { actions.current.commitRename(entry, value) }}
|
|
576
|
+
onCancel={() => actions.current.cancelRename()}
|
|
577
|
+
/>
|
|
578
|
+
)
|
|
579
|
+
: (
|
|
580
|
+
<span className={`rvs-node-name ${status !== undefined ? `rvs-git-${gitStatusClass(status)}` : ''}`} style={ignored && status === undefined ? { opacity: .5 } : undefined}>
|
|
581
|
+
{entry.name}
|
|
582
|
+
</span>
|
|
583
|
+
)}
|
|
584
|
+
{status !== undefined && (
|
|
585
|
+
<span className={`rvs-git-letter rvs-letter-${gitStatusClass(status)}`}>{gitLetter(status)}</span>
|
|
586
|
+
)}
|
|
587
|
+
{entry.isSymlink && <span className="rvs-hit-dir" title={props.symlinkTitle}>↩</span>}
|
|
588
|
+
<span className="rvs-node-actions">
|
|
589
|
+
<button
|
|
590
|
+
type="button"
|
|
591
|
+
className="rvs-hbtn"
|
|
592
|
+
title={props.referenceTitle}
|
|
593
|
+
disabled={!chatEnabled}
|
|
594
|
+
onClick={(e) => {
|
|
595
|
+
e.stopPropagation()
|
|
596
|
+
actions.current.reference(entry)
|
|
597
|
+
}}
|
|
598
|
+
>
|
|
599
|
+
@
|
|
600
|
+
</button>
|
|
601
|
+
</span>
|
|
602
|
+
</div>
|
|
603
|
+
)
|
|
604
|
+
})
|
|
605
|
+
|
|
202
606
|
export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: () => void; visible: boolean }): ReactNode {
|
|
203
607
|
const store = useExplorer()
|
|
204
608
|
const { t, alias, root, repoRoot, marks } = store
|
|
609
|
+
/** The host link is down: cached rows stay, new listings cannot load. */
|
|
610
|
+
const connection = useConnectionStatus()
|
|
611
|
+
const offline = connection?.state === 'error'
|
|
205
612
|
const ctx = store.ctx
|
|
206
613
|
const [listings, setListings] = useState<Record<string, RemoteFileEntry[]>>({})
|
|
207
614
|
/**
|
|
@@ -247,6 +654,10 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
247
654
|
const treeRef = useRef<HTMLDivElement>(null)
|
|
248
655
|
/** Abort handle for the batch on the wire (the upload bar's ✕). */
|
|
249
656
|
const uploadAbort = useRef<AbortController | undefined>(undefined)
|
|
657
|
+
/** True while a remote WRITE batch is in flight (upload/paste/delete serialization). */
|
|
658
|
+
const transferRef = useRef(false)
|
|
659
|
+
/** Last handled "show this folder" request id (see `shouldConsumeReveal`). */
|
|
660
|
+
const lastRevealId = useRef(0)
|
|
250
661
|
const menu = useContextMenu()
|
|
251
662
|
|
|
252
663
|
const chatTarget = useRemoteChatTarget(store.ctx)
|
|
@@ -292,6 +703,10 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
292
703
|
|
|
293
704
|
const loadDir = useCallback(async (dir: string, force = false): Promise<void> => {
|
|
294
705
|
if (alias === '') return
|
|
706
|
+
// While the link is down, a listing can only produce a 45 s SSH dial (and a
|
|
707
|
+
// spinner over the "no cache" placeholder). Cached rows stay; recovery
|
|
708
|
+
// re-lists through the revision bump, so skipping here loses nothing.
|
|
709
|
+
if (offline) return
|
|
295
710
|
const key = dirKey(alias, dir)
|
|
296
711
|
// NOTE: a cached listing is deliberately NOT reused as the only source. The
|
|
297
712
|
// tree relies on every caller re-listing after a write (`force` = start a
|
|
@@ -307,7 +722,10 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
307
722
|
try {
|
|
308
723
|
await listingsApi.request(dir, revisionRef.current, force)
|
|
309
724
|
} catch (error) {
|
|
310
|
-
|
|
725
|
+
// A transport failure is already on the connection chip, and the cached
|
|
726
|
+
// rows are still on screen: one toast per background refresh would repeat
|
|
727
|
+
// the same story until the link is back. Business failures still speak.
|
|
728
|
+
if (!isConnectionFailure(error)) toast(error instanceof Error ? error.message : String(error), true)
|
|
311
729
|
} finally {
|
|
312
730
|
setLoading(prev => {
|
|
313
731
|
const next = new Set(prev)
|
|
@@ -315,7 +733,7 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
315
733
|
return next
|
|
316
734
|
})
|
|
317
735
|
}
|
|
318
|
-
}, [alias, listingsApi])
|
|
736
|
+
}, [alias, listingsApi, offline])
|
|
319
737
|
|
|
320
738
|
/**
|
|
321
739
|
* Warm the listing cache for a directory the pointer is resting on.
|
|
@@ -328,11 +746,13 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
328
746
|
*/
|
|
329
747
|
const prefetchDir = useCallback((dir: string): void => {
|
|
330
748
|
if (alias === '') return
|
|
749
|
+
// A speculative read while the link is down is a real SSH dial for nothing.
|
|
750
|
+
if (offline) return
|
|
331
751
|
const key = dirKey(alias, dir)
|
|
332
752
|
if (listingsRef.current[key] !== undefined) return
|
|
333
753
|
if (listingsApi.busy(dir)) return
|
|
334
754
|
listingsApi.request(dir, revisionRef.current).catch(() => undefined)
|
|
335
|
-
}, [alias, listingsApi])
|
|
755
|
+
}, [alias, listingsApi, offline])
|
|
336
756
|
|
|
337
757
|
/** Hover intent: prefetch the row under the pointer after a short rest. */
|
|
338
758
|
const hoverDir = (path: string | undefined): void => {
|
|
@@ -359,6 +779,11 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
359
779
|
useEffect(() => {
|
|
360
780
|
const request = store.revealRequest
|
|
361
781
|
if (request === undefined) return
|
|
782
|
+
// Consume each request exactly once: this effect also re-runs when `root`
|
|
783
|
+
// or `loadDir` change, and replaying an old request re-expanded the
|
|
784
|
+
// previous workspace's chain and scrolled the tree away from the user.
|
|
785
|
+
if (!shouldConsumeReveal(lastRevealId.current, request.id)) return
|
|
786
|
+
lastRevealId.current = request.id
|
|
362
787
|
const base = root.replace(/\/+$/, '')
|
|
363
788
|
const target = request.path.replace(/\/+$/, '')
|
|
364
789
|
if (target !== base && !target.startsWith(`${base}/`)) return
|
|
@@ -461,14 +886,31 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
461
886
|
}
|
|
462
887
|
}, [])
|
|
463
888
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
889
|
+
/**
|
|
890
|
+
* One directory's visible, sorted rows, cached for the life of one
|
|
891
|
+
* `listings`/`showHidden`/`alias` combination.
|
|
892
|
+
*
|
|
893
|
+
* Sorting/filtering on every request was invisible for one directory and
|
|
894
|
+
* wasteful for a deep tree (the flattened list asks for every expanded
|
|
895
|
+
* directory on each rebuild); the cache also gives `buildVisibleRows` a stable
|
|
896
|
+
* row-array identity, which is what lets the memoized rows be reused.
|
|
897
|
+
*/
|
|
898
|
+
const rowsOf = useMemo(() => {
|
|
899
|
+
const cache = new Map<string, RemoteFileEntry[] | undefined>()
|
|
900
|
+
return (dir: string): RemoteFileEntry[] | undefined => {
|
|
901
|
+
if (cache.has(dir)) return cache.get(dir)
|
|
902
|
+
const rows = listings[dirKey(alias, dir)]
|
|
903
|
+
let sorted: RemoteFileEntry[] | undefined
|
|
904
|
+
if (rows !== undefined) {
|
|
905
|
+
const visible = props.showHidden ? rows : rows.filter(entry => !entry.name.startsWith('.'))
|
|
906
|
+
sorted = [...visible].sort((a, b) => {
|
|
907
|
+
if (a.isDir !== b.isDir) return a.isDir ? -1 : 1
|
|
908
|
+
return a.name.localeCompare(b.name)
|
|
909
|
+
})
|
|
910
|
+
}
|
|
911
|
+
cache.set(dir, sorted)
|
|
912
|
+
return sorted
|
|
913
|
+
}
|
|
472
914
|
}, [listings, alias, props.showHidden])
|
|
473
915
|
|
|
474
916
|
/** Flatten the loaded part of the tree in pre-order (shift-select spans it). */
|
|
@@ -574,7 +1016,57 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
574
1016
|
for (const dir of dirs) await loadDir(dir, true)
|
|
575
1017
|
}, [loadDir])
|
|
576
1018
|
|
|
1019
|
+
/**
|
|
1020
|
+
* Drop one removed subtree from every path-keyed index.
|
|
1021
|
+
*
|
|
1022
|
+
* Wired into delete (all successful removals) and into cut-paste/drag-move
|
|
1023
|
+
* (the sources left their old paths). Without it the removed directories stay
|
|
1024
|
+
* in `expanded`, so the revision-bump refresh re-lists them over SFTP on every
|
|
1025
|
+
* later write (business error → toast each time), and their listing keys are
|
|
1026
|
+
* kept alive by `trimListings`' open-directory exemption forever.
|
|
1027
|
+
*/
|
|
1028
|
+
const forgetPaths = useCallback((removed: readonly string[]): void => {
|
|
1029
|
+
if (removed.length === 0) return
|
|
1030
|
+
const gone = (path: string): boolean => removed.some(root => pathUnder(path, root))
|
|
1031
|
+
setExpanded(prev => withoutPaths(prev, removed))
|
|
1032
|
+
setSelected(prev => withoutPaths(prev, removed))
|
|
1033
|
+
setAnchor(prev => (prev !== undefined && gone(prev) ? undefined : prev))
|
|
1034
|
+
setListings(prev => withoutListingPaths(prev, alias, removed))
|
|
1035
|
+
setRenaming(prev => (prev !== undefined && gone(prev) ? undefined : prev))
|
|
1036
|
+
setCreating(prev => (prev !== undefined && gone(prev.dir) ? undefined : prev))
|
|
1037
|
+
setDropTarget(prev => (prev !== undefined && gone(prev) ? undefined : prev))
|
|
1038
|
+
// The focused row may be the one being removed. Clearing it here is what
|
|
1039
|
+
// lets the visibility effect below re-home the roving Tab stop to the first
|
|
1040
|
+
// remaining row instead of leaving EVERY row at tabIndex=-1.
|
|
1041
|
+
setFocusedPath(prev => (prev !== undefined && gone(prev) ? undefined : prev))
|
|
1042
|
+
setClipboard(prev => {
|
|
1043
|
+
if (prev === undefined) return prev
|
|
1044
|
+
const paths = prev.paths.filter(path => !gone(path))
|
|
1045
|
+
if (paths.length === prev.paths.length) return prev
|
|
1046
|
+
return paths.length === 0 ? undefined : { ...prev, paths }
|
|
1047
|
+
})
|
|
1048
|
+
}, [alias])
|
|
1049
|
+
|
|
1050
|
+
/** Re-key every path-keyed index after a rename/move of `from` to `to`. */
|
|
1051
|
+
const movePathIndex = useCallback((from: string, to: string): void => {
|
|
1052
|
+
const moved = (path: string): string => (pathUnder(path, from) ? `${to}${path.slice(from.length)}` : path)
|
|
1053
|
+
setExpanded(prev => rekeyPaths(prev, from, to))
|
|
1054
|
+
setSelected(prev => rekeyPaths(prev, from, to))
|
|
1055
|
+
setAnchor(prev => (prev === undefined ? undefined : moved(prev)))
|
|
1056
|
+
setListings(prev => rekeyListings(prev, alias, from, to))
|
|
1057
|
+
setRenaming(prev => (prev === undefined ? undefined : moved(prev)))
|
|
1058
|
+
setCreating(prev => (prev === undefined ? undefined : { ...prev, dir: moved(prev.dir) }))
|
|
1059
|
+
// A rename/move must carry the Tab stop with the row it belongs to.
|
|
1060
|
+
setFocusedPath(prev => (prev === undefined ? undefined : moved(prev)))
|
|
1061
|
+
}, [alias])
|
|
1062
|
+
|
|
577
1063
|
const doCreate = async (name: string): Promise<void> => {
|
|
1064
|
+
// Remote writes are serialized: an upload in flight owns the single
|
|
1065
|
+
// abort slot, so no second write batch may start beside it.
|
|
1066
|
+
if (!writeAllowed(transferRef.current)) {
|
|
1067
|
+
toast(t('files.transferBusy'), true)
|
|
1068
|
+
return
|
|
1069
|
+
}
|
|
578
1070
|
const state = creating
|
|
579
1071
|
setCreating(undefined)
|
|
580
1072
|
if (state === undefined || name.trim() === '') return
|
|
@@ -602,6 +1094,12 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
602
1094
|
|
|
603
1095
|
const doRename = async (entry: RemoteFileEntry, name: string): Promise<void> => {
|
|
604
1096
|
setRenaming(undefined)
|
|
1097
|
+
// Remote writes are serialized: an upload in flight owns the single
|
|
1098
|
+
// abort slot, so no second write batch may start beside it.
|
|
1099
|
+
if (!writeAllowed(transferRef.current)) {
|
|
1100
|
+
toast(t('files.transferBusy'), true)
|
|
1101
|
+
return
|
|
1102
|
+
}
|
|
605
1103
|
if (name.trim() === '' || name === entry.name) return
|
|
606
1104
|
let target: string
|
|
607
1105
|
try {
|
|
@@ -618,24 +1116,7 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
618
1116
|
// directory used to collapse (the new path was never in `expanded`), keep
|
|
619
1117
|
// its selection pointing at a path that no longer exists, and strand a
|
|
620
1118
|
// stale listing under the old key forever.
|
|
621
|
-
|
|
622
|
-
const movePath = (path: string): string =>
|
|
623
|
-
path === from || path.startsWith(`${from}/`) ? `${target}${path.slice(from.length)}` : path
|
|
624
|
-
setExpanded(prev => new Set([...prev].map(movePath)))
|
|
625
|
-
setSelected(prev => new Set([...prev].map(movePath)))
|
|
626
|
-
setAnchor(prev => (prev === undefined ? undefined : movePath(prev)))
|
|
627
|
-
setListings(prev => {
|
|
628
|
-
const next: Record<string, RemoteFileEntry[]> = {}
|
|
629
|
-
for (const [key, value] of Object.entries(prev)) {
|
|
630
|
-
const prefix = dirKey(alias, '')
|
|
631
|
-
if (!key.startsWith(prefix)) {
|
|
632
|
-
next[key] = value
|
|
633
|
-
continue
|
|
634
|
-
}
|
|
635
|
-
next[dirKey(alias, movePath(key.slice(prefix.length)))] = value
|
|
636
|
-
}
|
|
637
|
-
return next
|
|
638
|
-
})
|
|
1119
|
+
movePathIndex(entry.path, target)
|
|
639
1120
|
await refreshDirs([baseDirFor()])
|
|
640
1121
|
await store.afterWrite()
|
|
641
1122
|
toast(`${t('files.renamed')} ${target}`)
|
|
@@ -648,6 +1129,12 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
648
1129
|
|
|
649
1130
|
const doDelete = async (entries: RemoteFileEntry[]): Promise<void> => {
|
|
650
1131
|
if (entries.length === 0) return
|
|
1132
|
+
// Remote writes are serialized: an upload in flight owns the single
|
|
1133
|
+
// abort slot, so no second write batch may start beside it.
|
|
1134
|
+
if (!writeAllowed(transferRef.current)) {
|
|
1135
|
+
toast(t('files.transferBusy'), true)
|
|
1136
|
+
return
|
|
1137
|
+
}
|
|
651
1138
|
const first = entries[0] as RemoteFileEntry
|
|
652
1139
|
const label = entries.length === 1 ? first.path : `${entries.length} ${t('files.items')}`
|
|
653
1140
|
const ok = await confirmDialog({
|
|
@@ -659,15 +1146,23 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
659
1146
|
if (!ok) return
|
|
660
1147
|
setBusy(true)
|
|
661
1148
|
const failed: string[] = []
|
|
1149
|
+
/** Entries that really disappeared on the remote — their subtree is pruned. */
|
|
1150
|
+
const removed: string[] = []
|
|
662
1151
|
for (const entry of entries) {
|
|
663
1152
|
try {
|
|
664
1153
|
await api.fileOp.rm(alias, entry.path, entry.isDir)
|
|
1154
|
+
removed.push(entry.path)
|
|
665
1155
|
} catch (error) {
|
|
666
1156
|
failed.push(`${entry.name}: ${error instanceof Error ? error.message : String(error)}`)
|
|
667
1157
|
}
|
|
668
1158
|
}
|
|
669
1159
|
setBusy(false)
|
|
670
|
-
|
|
1160
|
+
// Drop the removed subtrees from `expanded`/`selected`/`listings` BEFORE any
|
|
1161
|
+
// refresh: `store.afterWrite()` bumps the revision, and the root effect
|
|
1162
|
+
// re-lists every expanded directory — the deleted ones would each answer
|
|
1163
|
+
// with a business error and a toast, on every write for the rest of the
|
|
1164
|
+
// session.
|
|
1165
|
+
forgetPaths(removed)
|
|
671
1166
|
await refreshDirs([...new Set(entries.map(entry => entry.path.split('/').slice(0, -1).join('/') || '/'))])
|
|
672
1167
|
await store.afterWrite()
|
|
673
1168
|
if (failed.length > 0) toast(failed.join('\n'), true)
|
|
@@ -677,8 +1172,16 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
677
1172
|
const doPaste = async (intoDir: string): Promise<void> => {
|
|
678
1173
|
const clip = clipboard
|
|
679
1174
|
if (clip === undefined || clip.paths.length === 0) return
|
|
1175
|
+
// Remote writes are serialized: an upload in flight owns the single
|
|
1176
|
+
// abort slot, so no second write batch may start beside it.
|
|
1177
|
+
if (!writeAllowed(transferRef.current)) {
|
|
1178
|
+
toast(t('files.transferBusy'), true)
|
|
1179
|
+
return
|
|
1180
|
+
}
|
|
680
1181
|
setBusy(true)
|
|
681
1182
|
const failed: string[] = []
|
|
1183
|
+
/** Cut sources that really moved: their path-indexed state follows them. */
|
|
1184
|
+
const moved: Array<{ from: string; to: string }> = []
|
|
682
1185
|
for (const source of clip.paths) {
|
|
683
1186
|
if (source === intoDir || intoDir.startsWith(`${source}/`)) {
|
|
684
1187
|
failed.push(`${source}: ${t('files.pasteIntoSelf')}`)
|
|
@@ -692,11 +1195,15 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
692
1195
|
try {
|
|
693
1196
|
const result = await api.exec(alias, command, 60_000)
|
|
694
1197
|
if (!result.success) failed.push(`${baseName(source)}: ${result.stderr.trim() || t('files.pasteFailed')}`)
|
|
1198
|
+
else if (clip.mode === 'cut') moved.push({ from: source, to: destinationOfMove(intoDir, source) })
|
|
695
1199
|
} catch (error) {
|
|
696
1200
|
failed.push(`${baseName(source)}: ${error instanceof Error ? error.message : String(error)}`)
|
|
697
1201
|
}
|
|
698
1202
|
}
|
|
699
1203
|
setBusy(false)
|
|
1204
|
+
// A moved source no longer exists at its old path: re-key (rather than drop)
|
|
1205
|
+
// its expanded/selected/listing state, exactly like a rename.
|
|
1206
|
+
for (const source of moved) movePathIndex(source.from, source.to)
|
|
700
1207
|
if (clip.mode === 'cut') setClipboard(undefined)
|
|
701
1208
|
await refreshDirs([intoDir, baseDirFor()])
|
|
702
1209
|
await store.afterWrite()
|
|
@@ -706,12 +1213,19 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
706
1213
|
|
|
707
1214
|
const doDrop = async (intoDir: string, event: React.DragEvent): Promise<void> => {
|
|
708
1215
|
event.preventDefault()
|
|
1216
|
+
// Remote writes are serialized: an upload in flight owns the single
|
|
1217
|
+
// abort slot, so no second write batch may start beside it.
|
|
1218
|
+
if (!writeAllowed(transferRef.current)) {
|
|
1219
|
+
toast(t('files.transferBusy'), true)
|
|
1220
|
+
return
|
|
1221
|
+
}
|
|
709
1222
|
setDropTarget(undefined)
|
|
710
1223
|
const sources = dragPaths.current
|
|
711
1224
|
dragPaths.current = []
|
|
712
1225
|
if (sources.length === 0) return
|
|
713
1226
|
setBusy(true)
|
|
714
1227
|
const failed: string[] = []
|
|
1228
|
+
const moved: Array<{ from: string; to: string }> = []
|
|
715
1229
|
for (const source of sources) {
|
|
716
1230
|
if (source === intoDir || intoDir.startsWith(`${source}/`)) {
|
|
717
1231
|
failed.push(`${baseName(source)}: ${t('files.moveIntoSelf')}`)
|
|
@@ -721,11 +1235,13 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
721
1235
|
try {
|
|
722
1236
|
const result = await api.exec(alias, moveToCommand(source, intoDir), 60_000)
|
|
723
1237
|
if (!result.success) failed.push(`${baseName(source)}: ${result.stderr.trim() || t('files.pasteFailed')}`)
|
|
1238
|
+
else moved.push({ from: source, to: destinationOfMove(intoDir, source) })
|
|
724
1239
|
} catch (error) {
|
|
725
1240
|
failed.push(`${baseName(source)}: ${error instanceof Error ? error.message : String(error)}`)
|
|
726
1241
|
}
|
|
727
1242
|
}
|
|
728
1243
|
setBusy(false)
|
|
1244
|
+
for (const source of moved) movePathIndex(source.from, source.to)
|
|
729
1245
|
await refreshDirs([intoDir, baseDirFor()])
|
|
730
1246
|
await store.afterWrite()
|
|
731
1247
|
if (failed.length > 0) toast(failed.join('\n'), true)
|
|
@@ -755,10 +1271,37 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
755
1271
|
): Promise<void> => {
|
|
756
1272
|
dropLog('runUpload', { dir, alias, entries: entries.length })
|
|
757
1273
|
if (alias === '' || dir === '') return
|
|
758
|
-
|
|
1274
|
+
// One write batch at a time: a second upload would overwrite the single
|
|
1275
|
+
// `uploadAbort` slot (the first then cannot be cancelled) and the two
|
|
1276
|
+
// progress bars would fight over one state object.
|
|
1277
|
+
if (!writeAllowed(transferRef.current)) {
|
|
1278
|
+
toast(t('files.transferBusy'), true)
|
|
1279
|
+
return
|
|
1280
|
+
}
|
|
1281
|
+
transferRef.current = true
|
|
1282
|
+
/**
|
|
1283
|
+
* The plan runs BEFORE the transfer's own try/finally, so a throw here used
|
|
1284
|
+
* to leave the write lock ON: `transferRef` stayed true and the upload bar
|
|
1285
|
+
* stayed up, which disables every write entry (new file/folder, upload,
|
|
1286
|
+
* paste, and DELETE) with nothing on screen explaining why — and it stayed
|
|
1287
|
+
* that way until the page was reloaded. Release the lock on the way out so a
|
|
1288
|
+
* bad batch is a toast, not a permanently greyed-out menu.
|
|
1289
|
+
*/
|
|
1290
|
+
let plan: ReturnType<typeof withDroppedDirs>
|
|
1291
|
+
try {
|
|
1292
|
+
plan = withDroppedDirs(planUpload(entries), extraDirs)
|
|
1293
|
+
} catch (error) {
|
|
1294
|
+
uploadAbort.current = undefined
|
|
1295
|
+
transferRef.current = false
|
|
1296
|
+
setUpload(undefined)
|
|
1297
|
+
setBusy(false)
|
|
1298
|
+
toast(error instanceof Error ? error.message : String(error), true)
|
|
1299
|
+
return
|
|
1300
|
+
}
|
|
759
1301
|
dropLog('plan', { files: plan.files.length, dirs: plan.dirs.length, skipped: plan.skipped.length })
|
|
760
1302
|
if (plan.files.length === 0 && plan.dirs.length === 0) {
|
|
761
1303
|
if (plan.skipped.length > 0) toast(t('files.uploadSkipped'), true)
|
|
1304
|
+
transferRef.current = false
|
|
762
1305
|
setUpload(undefined)
|
|
763
1306
|
return
|
|
764
1307
|
}
|
|
@@ -815,6 +1358,7 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
815
1358
|
if (!ok) {
|
|
816
1359
|
// ✕ during the prompt (or a dismissed modal) ends the batch here.
|
|
817
1360
|
uploadAbort.current = undefined
|
|
1361
|
+
transferRef.current = false
|
|
818
1362
|
setUpload(undefined)
|
|
819
1363
|
return
|
|
820
1364
|
}
|
|
@@ -887,6 +1431,7 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
887
1431
|
// which takes ~60 s on this tree; keeping the bar up through it made a
|
|
888
1432
|
// finished (or cancelled) upload look stuck and made ✕ look dead.
|
|
889
1433
|
uploadAbort.current = undefined
|
|
1434
|
+
transferRef.current = false
|
|
890
1435
|
setUpload(undefined)
|
|
891
1436
|
setBusy(false)
|
|
892
1437
|
}
|
|
@@ -963,6 +1508,12 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
963
1508
|
|
|
964
1509
|
const handleDrop = (dir: string, event: React.DragEvent): void => {
|
|
965
1510
|
if (!isFileDrag(event.dataTransfer)) return
|
|
1511
|
+
// Remote writes are serialized: an upload in flight owns the single
|
|
1512
|
+
// abort slot, so no second write batch may start beside it.
|
|
1513
|
+
if (!writeAllowed(transferRef.current)) {
|
|
1514
|
+
toast(t('files.transferBusy'), true)
|
|
1515
|
+
return
|
|
1516
|
+
}
|
|
966
1517
|
event.preventDefault()
|
|
967
1518
|
event.stopPropagation()
|
|
968
1519
|
setDropTarget(undefined)
|
|
@@ -1106,9 +1657,27 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
1106
1657
|
|
|
1107
1658
|
// ---------------------------------------------------------- context menu
|
|
1108
1659
|
|
|
1660
|
+
/**
|
|
1661
|
+
* Begin inline creation in `dir`.
|
|
1662
|
+
*
|
|
1663
|
+
* The create row is rendered only under an EXPANDED directory (the flat row
|
|
1664
|
+
* builder walks expanded nodes), so asking for "New file" on a collapsed
|
|
1665
|
+
* folder used to set state nobody could see — the menu looked dead until the
|
|
1666
|
+
* user expanded it by hand. Expand (and list) the target first.
|
|
1667
|
+
*/
|
|
1668
|
+
const startCreate = useCallback((dir: string, kind: 'file' | 'folder'): void => {
|
|
1669
|
+
if (dir !== '' && dir !== root && !expanded.has(dir)) {
|
|
1670
|
+
setExpanded(prev => new Set(prev).add(dir))
|
|
1671
|
+
void loadDir(dir)
|
|
1672
|
+
}
|
|
1673
|
+
setCreating({ dir, kind })
|
|
1674
|
+
}, [root, expanded, loadDir])
|
|
1675
|
+
|
|
1109
1676
|
const openMenu = (event: React.MouseEvent, entry: RemoteFileEntry | undefined): void => {
|
|
1110
1677
|
event.preventDefault()
|
|
1111
1678
|
event.stopPropagation()
|
|
1679
|
+
/** One write batch at a time (see `writeEntriesDisabled`). */
|
|
1680
|
+
const transferBusy = writeEntriesDisabled(upload !== undefined)
|
|
1112
1681
|
if (entry !== undefined && !selected.has(entry.path)) {
|
|
1113
1682
|
setSelected(new Set([entry.path]))
|
|
1114
1683
|
setAnchor(entry.path)
|
|
@@ -1124,14 +1693,15 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
1124
1693
|
dir = entry.isDir ? entry.path : (entry.path.split('/').slice(0, -1).join('/') || '/')
|
|
1125
1694
|
}
|
|
1126
1695
|
const entries: MenuEntry[] = [
|
|
1127
|
-
{ label: t('files.newFile'), onSelect: () =>
|
|
1128
|
-
{ label: t('files.newFolder'), onSelect: () =>
|
|
1696
|
+
{ label: t('files.newFile'), onSelect: () => startCreate(dir, 'file'), disabled: transferBusy },
|
|
1697
|
+
{ label: t('files.newFolder'), onSelect: () => startCreate(dir, 'folder'), disabled: transferBusy },
|
|
1129
1698
|
{
|
|
1130
1699
|
label: t('files.uploadFile'),
|
|
1131
1700
|
onSelect: () => {
|
|
1132
1701
|
uploadInto.current = dir
|
|
1133
1702
|
filePicker.current?.click()
|
|
1134
1703
|
},
|
|
1704
|
+
disabled: transferBusy,
|
|
1135
1705
|
},
|
|
1136
1706
|
{
|
|
1137
1707
|
label: t('files.uploadFolder'),
|
|
@@ -1139,11 +1709,12 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
1139
1709
|
uploadInto.current = dir
|
|
1140
1710
|
folderPickerHandle.current?.click()
|
|
1141
1711
|
},
|
|
1712
|
+
disabled: transferBusy,
|
|
1142
1713
|
},
|
|
1143
1714
|
{
|
|
1144
1715
|
label: t('files.pasteHere'),
|
|
1145
1716
|
onSelect: () => { void doPaste(dir) },
|
|
1146
|
-
disabled: clipboard === undefined,
|
|
1717
|
+
disabled: clipboard === undefined || transferBusy,
|
|
1147
1718
|
hint: clipboard === undefined ? undefined : `${clipboard.paths.length}`,
|
|
1148
1719
|
},
|
|
1149
1720
|
]
|
|
@@ -1187,6 +1758,7 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
1187
1758
|
label: t('files.delete') + (targets.length > 1 ? ` (${targets.length})` : ''),
|
|
1188
1759
|
onSelect: () => { void doDelete(targets) },
|
|
1189
1760
|
danger: true,
|
|
1761
|
+
disabled: transferBusy,
|
|
1190
1762
|
})
|
|
1191
1763
|
entries.push({ label: t('files.copyRel'), onSelect: () => { void copyText(targets.map(item => repoRelative(repoRoot, item.path) || item.path).join('\n')); toast(t('files.copiedClipboard')) }, separated: true })
|
|
1192
1764
|
entries.push({ label: t('files.copyAbs'), onSelect: () => { void copyText(targets.map(item => item.path).join('\n')); toast(t('files.copiedClipboard')) } })
|
|
@@ -1243,138 +1815,267 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
1243
1815
|
return entry.isDir ? marks.ignoredDirs.has(rel) : marks.ignored.has(rel)
|
|
1244
1816
|
}, [repoRoot, marks])
|
|
1245
1817
|
|
|
1818
|
+
/** The right-click menu's `contextmenu` fallback (touch long-press only). */
|
|
1819
|
+
const onRowContextMenu = (e: React.MouseEvent, entry: RemoteFileEntry): void => {
|
|
1820
|
+
e.preventDefault()
|
|
1821
|
+
if (menu.menu === undefined) openMenu(e, entry)
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
/**
|
|
1825
|
+
* Keyboard focus (roving tabindex).
|
|
1826
|
+
*
|
|
1827
|
+
* The rows are leaf `memo` components, so moving focus is an index walk over
|
|
1828
|
+
* the flat visible rows plus a DOM lookup by `data-rvs-path`: before this the
|
|
1829
|
+
* tree had no keyboard path at all (no focusable row, no arrow/Enter/Esc
|
|
1830
|
+
* handling), which made the explorer unusable without a pointer.
|
|
1831
|
+
*/
|
|
1832
|
+
const [focusedPath, setFocusedPath] = useState<string | undefined>(undefined)
|
|
1833
|
+
const visibleRowsRef = useRef<ExplorerRow[]>([])
|
|
1834
|
+
const focusRow = (path: string | undefined): void => {
|
|
1835
|
+
// `undefined` means an arrow key hit an edge: keep the current stop instead
|
|
1836
|
+
// of blanking it (the visibility effect only re-homes a path that stopped
|
|
1837
|
+
// existing — a no-op move must not cost the tree its Tab stop).
|
|
1838
|
+
if (path === undefined) return
|
|
1839
|
+
setFocusedPath(path)
|
|
1840
|
+
requestAnimationFrame(() => {
|
|
1841
|
+
const row = Array.from(document.querySelectorAll<HTMLElement>('[data-rvs-path]'))
|
|
1842
|
+
.find(candidate => candidate.dataset.rvsPath === path)
|
|
1843
|
+
row?.focus()
|
|
1844
|
+
})
|
|
1845
|
+
}
|
|
1846
|
+
const onRowKeyDown = (entry: RemoteFileEntry, event: React.KeyboardEvent): void => {
|
|
1847
|
+
const rows = visibleRowsRef.current
|
|
1848
|
+
const key = event.key
|
|
1849
|
+
if (key === 'ArrowDown' || key === 'ArrowUp') {
|
|
1850
|
+
event.preventDefault()
|
|
1851
|
+
focusRow(rowKeyboardTarget(rows, entry.path, key === 'ArrowDown' ? 'down' : 'up'))
|
|
1852
|
+
return
|
|
1853
|
+
}
|
|
1854
|
+
if (key === 'ArrowRight' && entry.isDir) {
|
|
1855
|
+
event.preventDefault()
|
|
1856
|
+
if (!expanded.has(entry.path)) {
|
|
1857
|
+
toggleDir(entry)
|
|
1858
|
+
focusRow(entry.path)
|
|
1859
|
+
return
|
|
1860
|
+
}
|
|
1861
|
+
focusRow(rowKeyboardTarget(rows, entry.path, 'child') ?? entry.path)
|
|
1862
|
+
return
|
|
1863
|
+
}
|
|
1864
|
+
if (key === 'ArrowLeft') {
|
|
1865
|
+
event.preventDefault()
|
|
1866
|
+
if (entry.isDir && expanded.has(entry.path)) {
|
|
1867
|
+
toggleDir(entry)
|
|
1868
|
+
focusRow(entry.path)
|
|
1869
|
+
return
|
|
1870
|
+
}
|
|
1871
|
+
focusRow(rowKeyboardTarget(rows, entry.path, 'parent') ?? entry.path)
|
|
1872
|
+
return
|
|
1873
|
+
}
|
|
1874
|
+
if (key === 'Enter') {
|
|
1875
|
+
event.preventDefault()
|
|
1876
|
+
openEntry(entry)
|
|
1877
|
+
return
|
|
1878
|
+
}
|
|
1879
|
+
if (key === ' ' || key === 'Spacebar') {
|
|
1880
|
+
event.preventDefault()
|
|
1881
|
+
setSelected(new Set([entry.path]))
|
|
1882
|
+
setAnchor(entry.path)
|
|
1883
|
+
return
|
|
1884
|
+
}
|
|
1885
|
+
if (key === 'Home' || key === 'End') {
|
|
1886
|
+
event.preventDefault()
|
|
1887
|
+
const entries = rows.filter(row => row.kind === 'entry')
|
|
1888
|
+
const target = key === 'Home' ? entries[0] : entries[entries.length - 1]
|
|
1889
|
+
if (target !== undefined) focusRow(target.entry.path)
|
|
1890
|
+
return
|
|
1891
|
+
}
|
|
1892
|
+
if ((key === 'F10' && event.shiftKey) || key === 'ContextMenu') {
|
|
1893
|
+
event.preventDefault()
|
|
1894
|
+
const row = Array.from(document.querySelectorAll<HTMLElement>('[data-rvs-path]'))
|
|
1895
|
+
.find(candidate => candidate.dataset.rvsPath === entry.path)
|
|
1896
|
+
const rect = row?.getBoundingClientRect()
|
|
1897
|
+
openMenu({
|
|
1898
|
+
preventDefault: () => undefined,
|
|
1899
|
+
stopPropagation: () => undefined,
|
|
1900
|
+
clientX: rect === undefined ? 0 : rect.left,
|
|
1901
|
+
clientY: rect === undefined ? 0 : rect.bottom,
|
|
1902
|
+
} as unknown as React.MouseEvent, entry)
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
|
|
1906
|
+
/**
|
|
1907
|
+
* Live row handlers, read through a ref.
|
|
1908
|
+
*
|
|
1909
|
+
* The rows are `memo`ized on primitive props; handing them a new callback
|
|
1910
|
+
* object every render would invalidate every row on every parent render,
|
|
1911
|
+
* which is exactly the cost this file is trying to avoid.
|
|
1912
|
+
*/
|
|
1913
|
+
const rowActions = useRef<ExplorerRowActions>({
|
|
1914
|
+
select: () => undefined,
|
|
1915
|
+
openFile: () => undefined,
|
|
1916
|
+
hoverDir: () => undefined,
|
|
1917
|
+
openMenu: () => undefined,
|
|
1918
|
+
contextMenu: () => undefined,
|
|
1919
|
+
startDrag: () => undefined,
|
|
1920
|
+
dragOver: () => undefined,
|
|
1921
|
+
dragLeave: () => undefined,
|
|
1922
|
+
dropOn: () => undefined,
|
|
1923
|
+
commitRename: () => undefined,
|
|
1924
|
+
cancelRename: () => undefined,
|
|
1925
|
+
reference: () => undefined,
|
|
1926
|
+
keyDown: () => undefined,
|
|
1927
|
+
focusPath: () => undefined,
|
|
1928
|
+
})
|
|
1929
|
+
rowActions.current = {
|
|
1930
|
+
select: selectRow,
|
|
1931
|
+
openFile: (entry) => {
|
|
1932
|
+
// The row passes the WHOLE entry: a directory must not reach
|
|
1933
|
+
// `store.openFile` (it has no type guard, so the Host would answer
|
|
1934
|
+
// "not a file" and the editor surface would be switched for nothing).
|
|
1935
|
+
const target = rowOpenTarget(entry)
|
|
1936
|
+
if (target !== undefined) store.openFile(target)
|
|
1937
|
+
},
|
|
1938
|
+
hoverDir,
|
|
1939
|
+
openMenu,
|
|
1940
|
+
contextMenu: onRowContextMenu,
|
|
1941
|
+
startDrag: (entry) => {
|
|
1942
|
+
dragPaths.current = selected.has(entry.path) ? [...selected] : [entry.path]
|
|
1943
|
+
},
|
|
1944
|
+
dragOver: (entry, e) => {
|
|
1945
|
+
// An OS file drag targets this row's DIRECTORY: a drop on a file row
|
|
1946
|
+
// means "put it beside that file" (what the user means when they aim at a
|
|
1947
|
+
// file in the list).
|
|
1948
|
+
if (isFileDrag(e.dataTransfer)) {
|
|
1949
|
+
e.preventDefault()
|
|
1950
|
+
e.stopPropagation()
|
|
1951
|
+
setDropTarget(entry.path)
|
|
1952
|
+
setDropHint(entry.isDir ? entry.path : (entry.path.split('/').slice(0, -1).join('/') || '/'))
|
|
1953
|
+
return
|
|
1954
|
+
}
|
|
1955
|
+
if (!entry.isDir) return
|
|
1956
|
+
const source = dragPaths.current[0]
|
|
1957
|
+
if (source === undefined) return
|
|
1958
|
+
if (entry.path === source || entry.path.startsWith(`${source}/`)) return
|
|
1959
|
+
e.preventDefault()
|
|
1960
|
+
setDropTarget(entry.path)
|
|
1961
|
+
},
|
|
1962
|
+
dragLeave: (entry) => { setDropTarget(current => (current === entry.path ? undefined : current)) },
|
|
1963
|
+
dropOn: (entry, e) => {
|
|
1964
|
+
if (isFileDrag(e.dataTransfer)) {
|
|
1965
|
+
const into = entry.isDir ? entry.path : (entry.path.split('/').slice(0, -1).join('/') || '/')
|
|
1966
|
+
handleDrop(into, e)
|
|
1967
|
+
return
|
|
1968
|
+
}
|
|
1969
|
+
if (entry.isDir) void doDrop(entry.path, e)
|
|
1970
|
+
},
|
|
1971
|
+
commitRename: (entry, name) => { void doRename(entry, name) },
|
|
1972
|
+
cancelRename: () => setRenaming(undefined),
|
|
1973
|
+
reference: (entry) => {
|
|
1974
|
+
if (chatTarget.sessionId === undefined) return
|
|
1975
|
+
insertRemoteReference(ctx, chatTarget.sessionId, repoRoot ?? root, entry.path, entry.isDir)
|
|
1976
|
+
},
|
|
1977
|
+
keyDown: onRowKeyDown,
|
|
1978
|
+
focusPath: (path) => { setFocusedPath(path) },
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
/**
|
|
1982
|
+
* The loaded tree as a flat pre-order list.
|
|
1983
|
+
*
|
|
1984
|
+
* Rebuilt only when the shape of the tree can have changed (a listing, an
|
|
1985
|
+
* expansion, the create row, a binding) — not on selection, upload progress or
|
|
1986
|
+
* a store publish. The memoized rows then skip the re-render themselves.
|
|
1987
|
+
*/
|
|
1988
|
+
const visibleRows = useMemo(() => buildVisibleRows({
|
|
1989
|
+
root,
|
|
1990
|
+
rowsOf,
|
|
1991
|
+
isExpanded: path => expanded.has(path),
|
|
1992
|
+
...(creating === undefined ? {} : { creating }),
|
|
1993
|
+
// A cold/or offline directory that was just expanded must say so IN PLACE
|
|
1994
|
+
// (the root's own placeholder below only covers the workspace root).
|
|
1995
|
+
placeholderOf: (dir) => (offline ? 'offline' : loading.has(dirKey(alias, dir)) ? 'loading' : undefined),
|
|
1996
|
+
}), [root, rowsOf, expanded, creating, offline, loading, alias])
|
|
1997
|
+
// Keyboard navigation reads the current flat list synchronously.
|
|
1998
|
+
visibleRowsRef.current = visibleRows
|
|
1999
|
+
|
|
2000
|
+
/**
|
|
2001
|
+
* Keep a Tab stop on screen.
|
|
2002
|
+
*
|
|
2003
|
+
* The roving tabindex puts `tabIndex=0` only on `focusedPath`'s row. Deleting
|
|
2004
|
+
* that row, renaming it, collapsing its parent or switching bindings used to
|
|
2005
|
+
* leave every row at -1: the tree stayed visible but keyboard users could no
|
|
2006
|
+
* longer Tab into it (the pointer was the only way back). Re-home the path to
|
|
2007
|
+
* the first remaining row; an empty tree keeps `undefined`.
|
|
2008
|
+
*/
|
|
2009
|
+
useEffect(() => {
|
|
2010
|
+
const next = nextFocusPath(visibleRows, focusedPath)
|
|
2011
|
+
if (next === focusedPath) return
|
|
2012
|
+
setFocusedPath(next)
|
|
2013
|
+
if (next === undefined) return
|
|
2014
|
+
// Do not yank DOM focus while the user is typing elsewhere; this only
|
|
2015
|
+
// restores the roving stop (the row is focusable again).
|
|
2016
|
+
}, [visibleRows, focusedPath])
|
|
2017
|
+
|
|
1246
2018
|
const renderDir = (dir: string, depth: number): ReactNode => {
|
|
1247
2019
|
const rows = rowsOf(dir)
|
|
1248
2020
|
const key = dirKey(alias, dir)
|
|
2021
|
+
if (rows === undefined && offline) {
|
|
2022
|
+
// Checked BEFORE the loading line: a request that was already in flight
|
|
2023
|
+
// when the link dropped would otherwise show "loading" for its own
|
|
2024
|
+
// deadline and hide the honest answer.
|
|
2025
|
+
return <div className="rvs-empty" style={{ paddingLeft: 12 + depth * 14 }}>{t('files.offline')}</div>
|
|
2026
|
+
}
|
|
1249
2027
|
if (rows === undefined && loading.has(key)) {
|
|
1250
2028
|
return <div className="rvs-empty" style={{ paddingLeft: 12 + depth * 14 }}>{t('common.loading')}</div>
|
|
1251
2029
|
}
|
|
2030
|
+
// Per-render constants, not per-row ones: the strings and the clipboard set
|
|
2031
|
+
// are identical for every row, and computing them inside the map is real
|
|
2032
|
+
// work when the tree has tens of thousands of rows.
|
|
2033
|
+
const referenceTitle = chatEnabled ? t('files.referenceFile') : t('files.refDisabled')
|
|
2034
|
+
const symlinkTitle = t('files.symlink')
|
|
2035
|
+
const cutPaths = clipboard !== undefined && clipboard.mode === 'cut' ? new Set(clipboard.paths) : undefined
|
|
1252
2036
|
return (
|
|
1253
2037
|
<>
|
|
1254
|
-
{
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
className={[
|
|
1275
|
-
'rvs-node',
|
|
1276
|
-
isSelected ? 'selected' : '',
|
|
1277
|
-
clip ? 'cut' : '',
|
|
1278
|
-
dropTarget === entry.path ? 'drop-target' : '',
|
|
1279
|
-
].filter(Boolean).join(' ')}
|
|
1280
|
-
style={{ paddingLeft: 8 + depth * 14 }}
|
|
1281
|
-
title={entry.path}
|
|
1282
|
-
// Read by the document-level capture drop listeners, which live
|
|
1283
|
-
// outside React's tree and cannot see component state.
|
|
1284
|
-
data-rvs-path={entry.path}
|
|
1285
|
-
data-rvs-dir={entry.isDir ? '1' : '0'}
|
|
1286
|
-
draggable
|
|
1287
|
-
onClick={(e) => selectRow(entry, e)}
|
|
1288
|
-
onDoubleClick={() => { if (!entry.isDir) store.openFile(entry.path) }}
|
|
1289
|
-
// Hover-intent prefetch: a directory the pointer rests on gets its
|
|
1290
|
-
// listing warmed, so the click that follows paints instead of
|
|
1291
|
-
// waiting one round trip. Leave/collapse cancels the pending one.
|
|
1292
|
-
onMouseEnter={() => { if (entry.isDir) hoverDir(entry.path) }}
|
|
1293
|
-
onMouseLeave={() => hoverDir(undefined)}
|
|
1294
|
-
// Right-click opens on POINTERDOWN — the first event of the
|
|
1295
|
-
// gesture — so the menu is already mounted before any later
|
|
1296
|
-
// event of the same click (a platform may replay mousedown, and
|
|
1297
|
-
// a background git refresh may scroll) can close it. The
|
|
1298
|
-
// contextmenu fallback covers surfaces that only send that
|
|
1299
|
-
// (touch long-press).
|
|
1300
|
-
onPointerDown={(e) => { if (e.button === 2) openMenu(e, entry) }}
|
|
1301
|
-
onContextMenu={(e) => {
|
|
1302
|
-
e.preventDefault()
|
|
1303
|
-
if (menu.menu === undefined) openMenu(e, entry)
|
|
1304
|
-
}}
|
|
1305
|
-
onDragStart={(e) => {
|
|
1306
|
-
dragPaths.current = selected.has(entry.path) ? [...selected] : [entry.path]
|
|
1307
|
-
e.dataTransfer.effectAllowed = 'move'
|
|
1308
|
-
e.dataTransfer.setData('text/plain', entry.path)
|
|
1309
|
-
}}
|
|
1310
|
-
onDragOver={(e) => {
|
|
1311
|
-
// An OS file drag targets this row's DIRECTORY: a drop on a
|
|
1312
|
-
// file row means "put it beside that file" (what the user
|
|
1313
|
-
// means when they aim at a file in the list).
|
|
1314
|
-
if (isFileDrag(e.dataTransfer)) {
|
|
1315
|
-
e.preventDefault()
|
|
1316
|
-
e.stopPropagation()
|
|
1317
|
-
setDropTarget(entry.path)
|
|
1318
|
-
setDropHint(entry.isDir ? entry.path : (entry.path.split('/').slice(0, -1).join('/') || '/'))
|
|
1319
|
-
return
|
|
1320
|
-
}
|
|
1321
|
-
if (!entry.isDir) return
|
|
1322
|
-
const source = dragPaths.current[0]
|
|
1323
|
-
if (source === undefined) return
|
|
1324
|
-
if (entry.path === source || entry.path.startsWith(`${source}/`)) return
|
|
1325
|
-
e.preventDefault()
|
|
1326
|
-
setDropTarget(entry.path)
|
|
1327
|
-
}}
|
|
1328
|
-
onDragLeave={() => { setDropTarget(current => (current === entry.path ? undefined : current)) }}
|
|
1329
|
-
onDrop={(e) => {
|
|
1330
|
-
if (isFileDrag(e.dataTransfer)) {
|
|
1331
|
-
const into = entry.isDir ? entry.path : (entry.path.split('/').slice(0, -1).join('/') || '/')
|
|
1332
|
-
handleDrop(into, e)
|
|
1333
|
-
return
|
|
1334
|
-
}
|
|
1335
|
-
if (entry.isDir) void doDrop(entry.path, e)
|
|
1336
|
-
}}
|
|
1337
|
-
>
|
|
1338
|
-
<span className="rvs-node-icon">
|
|
1339
|
-
{entry.isDir
|
|
1340
|
-
? <FolderIcon path={entry.path} open={isOpen} size={15} />
|
|
1341
|
-
: <FileIcon path={entry.path} size={15} />}
|
|
1342
|
-
</span>
|
|
1343
|
-
{renaming === entry.path
|
|
1344
|
-
? (
|
|
1345
|
-
<RenameInput
|
|
1346
|
-
initial={entry.name}
|
|
1347
|
-
onCommit={(value) => { void doRename(entry, value) }}
|
|
1348
|
-
onCancel={() => setRenaming(undefined)}
|
|
1349
|
-
/>
|
|
1350
|
-
)
|
|
1351
|
-
: (
|
|
1352
|
-
<span className={`rvs-node-name ${status !== undefined ? `rvs-git-${gitStatusClass(status)}` : ''}`} style={ignored && status === undefined ? { opacity: .5 } : undefined}>
|
|
1353
|
-
{entry.name}
|
|
1354
|
-
</span>
|
|
1355
|
-
)}
|
|
1356
|
-
{status !== undefined && (
|
|
1357
|
-
<span className={`rvs-git-letter rvs-letter-${gitStatusClass(status)}`}>{gitLetter(status)}</span>
|
|
1358
|
-
)}
|
|
1359
|
-
{entry.isSymlink && <span className="rvs-hit-dir" title={t('files.symlink')}>↩</span>}
|
|
1360
|
-
<span className="rvs-node-actions">
|
|
1361
|
-
<button
|
|
1362
|
-
type="button"
|
|
1363
|
-
className="rvs-hbtn"
|
|
1364
|
-
title={chatEnabled ? t('files.referenceFile') : t('files.refDisabled')}
|
|
1365
|
-
disabled={!chatEnabled}
|
|
1366
|
-
onClick={(e) => {
|
|
1367
|
-
e.stopPropagation()
|
|
1368
|
-
if (chatTarget.sessionId === undefined) return
|
|
1369
|
-
insertRemoteReference(ctx, chatTarget.sessionId, repoRoot ?? root, entry.path, entry.isDir)
|
|
1370
|
-
}}
|
|
1371
|
-
>
|
|
1372
|
-
@
|
|
1373
|
-
</button>
|
|
1374
|
-
</span>
|
|
2038
|
+
{visibleRows.map(row => {
|
|
2039
|
+
if (row.kind === 'create') {
|
|
2040
|
+
return (
|
|
2041
|
+
<CreateRow
|
|
2042
|
+
key={`create:${row.dir}`}
|
|
2043
|
+
depth={row.depth}
|
|
2044
|
+
kind={row.createKind}
|
|
2045
|
+
onCommit={(value) => { void doCreate(value) }}
|
|
2046
|
+
onCancel={() => setCreating(undefined)}
|
|
2047
|
+
fileIcon={<FileIcon path="name.ts" size={15} />}
|
|
2048
|
+
folderIcon={<FolderIcon path="name" open={false} size={15} />}
|
|
2049
|
+
t={t}
|
|
2050
|
+
/>
|
|
2051
|
+
)
|
|
2052
|
+
}
|
|
2053
|
+
if (row.kind === 'pending') {
|
|
2054
|
+
// Same copy/order as the root placeholder (offline before loading).
|
|
2055
|
+
return (
|
|
2056
|
+
<div key={`pending:${row.dir}`} className="rvs-empty" style={{ paddingLeft: 12 + row.depth * 14 }}>
|
|
2057
|
+
{row.reason === 'offline' ? t('files.offline') : t('common.loading')}
|
|
1375
2058
|
</div>
|
|
1376
|
-
|
|
1377
|
-
|
|
2059
|
+
)
|
|
2060
|
+
}
|
|
2061
|
+
return (
|
|
2062
|
+
<ExplorerRowView
|
|
2063
|
+
key={row.entry.path}
|
|
2064
|
+
entry={row.entry}
|
|
2065
|
+
depth={row.depth}
|
|
2066
|
+
status={statusFor(row.entry)}
|
|
2067
|
+
ignored={ignoredFor(row.entry)}
|
|
2068
|
+
isSelected={selected.has(row.entry.path)}
|
|
2069
|
+
isOpen={expanded.has(row.entry.path)}
|
|
2070
|
+
isCut={cutPaths !== undefined && cutPaths.has(row.entry.path)}
|
|
2071
|
+
isDropTarget={dropTarget === row.entry.path}
|
|
2072
|
+
isRenaming={renaming === row.entry.path}
|
|
2073
|
+
isFocused={focusedPath === row.entry.path}
|
|
2074
|
+
chatEnabled={chatEnabled}
|
|
2075
|
+
referenceTitle={referenceTitle}
|
|
2076
|
+
symlinkTitle={symlinkTitle}
|
|
2077
|
+
actions={rowActions}
|
|
2078
|
+
/>
|
|
1378
2079
|
)
|
|
1379
2080
|
})}
|
|
1380
2081
|
</>
|
|
@@ -1386,10 +2087,10 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
1386
2087
|
<div className="rvs-pane grow">
|
|
1387
2088
|
<div className="rvs-header">
|
|
1388
2089
|
<span className="rvs-title">{t('tab.files')}</span>
|
|
1389
|
-
<IconButton title={t('files.newFile')} onClick={() =>
|
|
2090
|
+
<IconButton title={t('files.newFile')} onClick={() => startCreate(root, 'file')} disabled={upload !== undefined}>
|
|
1390
2091
|
<IconPlus size={14} />
|
|
1391
2092
|
</IconButton>
|
|
1392
|
-
<IconButton title={t('files.newFolder')} onClick={() =>
|
|
2093
|
+
<IconButton title={t('files.newFolder')} onClick={() => startCreate(root, 'folder')} disabled={upload !== undefined}>
|
|
1393
2094
|
<IconNewFolder size={14} />
|
|
1394
2095
|
</IconButton>
|
|
1395
2096
|
<IconButton title={t('files.collapseAll')} onClick={() => setExpanded(new Set([root]))}>
|
|
@@ -1442,9 +2143,14 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
1442
2143
|
onChange={(e) => {
|
|
1443
2144
|
const picked = [...(e.target.files ?? [])]
|
|
1444
2145
|
e.target.value = ''
|
|
2146
|
+
if (!writeAllowed(transferRef.current)) return
|
|
1445
2147
|
const dir = uploadInto.current || root
|
|
1446
2148
|
const blobs = new Map<string, Blob>(picked.map(file => [file.name, file]))
|
|
2149
|
+
// A rejection here would be an unhandled one (this is not the drop
|
|
2150
|
+
// path, which does catch): the picker must report its failure the same
|
|
2151
|
+
// way the drop does.
|
|
1447
2152
|
void runUpload(dir, picked.map(file => ({ rel: file.name, size: file.size })), blobs, [])
|
|
2153
|
+
.catch((error: unknown) => { toast(error instanceof Error ? error.message : String(error), true) })
|
|
1448
2154
|
}}
|
|
1449
2155
|
/>
|
|
1450
2156
|
<input
|
|
@@ -1461,6 +2167,7 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
1461
2167
|
onChange={(e) => {
|
|
1462
2168
|
const picked = [...(e.target.files ?? [])]
|
|
1463
2169
|
e.target.value = ''
|
|
2170
|
+
if (!writeAllowed(transferRef.current)) return
|
|
1464
2171
|
const dir = uploadInto.current || root
|
|
1465
2172
|
const entries: DroppedFile[] = []
|
|
1466
2173
|
const blobs = new Map<string, Blob>()
|
|
@@ -1489,6 +2196,15 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
1489
2196
|
onClick={(e) => {
|
|
1490
2197
|
if (e.target === e.currentTarget) setSelected(new Set())
|
|
1491
2198
|
}}
|
|
2199
|
+
// The empty area BELOW the tree belongs to the scroll box, not to
|
|
2200
|
+
// .rvs-tree, so a right-click there used to open the browser's own
|
|
2201
|
+
// menu: the explorer's background actions were unreachable.
|
|
2202
|
+
onPointerDown={(e) => { if (e.button === 2 && e.target === e.currentTarget) openMenu(e, undefined) }}
|
|
2203
|
+
onContextMenu={(e) => {
|
|
2204
|
+
if (e.target !== e.currentTarget) return
|
|
2205
|
+
e.preventDefault()
|
|
2206
|
+
if (menu.menu === undefined) openMenu(e, undefined)
|
|
2207
|
+
}}
|
|
1492
2208
|
// Drop handlers live on the SCROLL container, not on `.rvs-tree`: when
|
|
1493
2209
|
// the tree is shorter than the pane, the empty space below it belongs to
|
|
1494
2210
|
// the scroll box, and dropping there (the natural target for "put it in
|
|
@@ -1509,6 +2225,9 @@ export function RemoteExplorer(props: { showHidden: boolean; onToggleHidden: ()
|
|
|
1509
2225
|
>
|
|
1510
2226
|
<div
|
|
1511
2227
|
className="rvs-tree"
|
|
2228
|
+
role="tree"
|
|
2229
|
+
aria-label={t('tab.files')}
|
|
2230
|
+
aria-multiselectable="true"
|
|
1512
2231
|
onPointerDown={(e) => { if (e.button === 2) openMenu(e, undefined) }}
|
|
1513
2232
|
onContextMenu={(e) => {
|
|
1514
2233
|
e.preventDefault()
|