dsh-remote-vs 0.25.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +11 -7
- package/README.md +10 -7
- package/THIRD-PARTY-NOTICES.md +188 -0
- package/lib/client.js +6512 -79961
- package/lib/index.js +1283 -992
- package/lib/p2-router-fs.js +1 -1
- package/lib/types/client/CodeEditor.d.ts +8 -0
- package/lib/types/client/RemoteExplorer.d.ts +53 -0
- package/lib/types/client/api.d.ts +37 -2
- package/lib/types/client/changes/review-state.d.ts +19 -0
- package/lib/types/client/connection.d.ts +16 -0
- package/lib/types/client/request-gate.d.ts +110 -0
- package/lib/types/client/scm/DiffView.d.ts +45 -7
- package/lib/types/client/scm/actions.d.ts +31 -3
- package/lib/types/client/store.d.ts +53 -0
- package/lib/types/client/vsc/FindWidget.d.ts +6 -0
- package/lib/types/client/vsc/change-marks.d.ts +16 -6
- package/lib/types/client/vsc/editor-keymap.d.ts +35 -1
- package/lib/types/client/vsc/kit.d.ts +11 -0
- package/lib/types/client/vsc/save-shortcut.d.ts +21 -0
- package/lib/types/client/vsc/terminal-theme.d.ts +28 -2
- package/lib/types/forward.d.ts +12 -0
- package/lib/types/fs-ops.d.ts +42 -0
- package/lib/types/http.d.ts +2 -0
- package/lib/types/keygen.d.ts +9 -0
- package/lib/types/monitor.d.ts +8 -0
- package/lib/types/notices.d.ts +16 -1
- package/lib/types/p2/helper-rpc.d.ts +45 -0
- package/lib/types/routes.d.ts +2 -0
- package/lib/types/store.d.ts +7 -0
- package/lib/types/terminal.d.ts +8 -0
- package/lib/types/view-settings.d.ts +5 -0
- package/lib/{worlds-B7gEDBzC.js → worlds-RG8K5eom.js} +113 -15
- package/package.json +2 -1
- package/src/client/CodeEditor.tsx +151 -8
- package/src/client/DirectoryFlow.tsx +16 -0
- package/src/client/DoctorPanel.tsx +70 -7
- package/src/client/EditorPane.tsx +63 -14
- package/src/client/HostsView.tsx +12 -3
- package/src/client/RemoteDirectoryPicker.tsx +12 -0
- package/src/client/RemoteExplorer.tsx +929 -40
- package/src/client/RemoteRoot.tsx +147 -22
- package/src/client/SearchView.tsx +8 -0
- package/src/client/TerminalSnippets.tsx +83 -8
- package/src/client/api.ts +106 -13
- package/src/client/changes/ChangesDock.tsx +188 -6
- package/src/client/changes/changes.css +10 -3
- package/src/client/changes/review-state.ts +34 -0
- package/src/client/connection.ts +29 -0
- package/src/client/downloads.ts +49 -4
- package/src/client/i18n.ts +82 -8
- package/src/client/request-gate.ts +221 -0
- package/src/client/scm/CommitPane.tsx +20 -2
- package/src/client/scm/DiffView.tsx +343 -117
- package/src/client/scm/HistoryPanel.tsx +23 -2
- package/src/client/scm/RepoPicker.tsx +1 -1
- package/src/client/scm/ScmPanel.tsx +391 -87
- package/src/client/scm/actions.ts +95 -12
- package/src/client/store.tsx +372 -9
- package/src/client/ui.tsx +4 -0
- package/src/client/vsc/FindWidget.tsx +24 -9
- package/src/client/vsc/breadcrumb.tsx +91 -3
- package/src/client/vsc/change-marks.ts +93 -44
- package/src/client/vsc/editor-keymap.ts +59 -1
- package/src/client/vsc/file-icons.tsx +17 -3
- package/src/client/vsc/kit.tsx +26 -9
- package/src/client/vsc/save-shortcut.ts +47 -1
- package/src/client/vsc/terminal-theme.ts +44 -18
- package/src/client/vsc/vsc.css +411 -153
- package/src/forward.ts +47 -9
- package/src/fs-ops.ts +124 -4
- package/src/git-ops.ts +20 -3
- package/src/http.ts +35 -4
- package/src/keygen.ts +55 -4
- package/src/monitor.ts +13 -0
- package/src/notices.ts +23 -1
- package/src/p2/helper-rpc.ts +113 -7
- package/src/p2/worlds.ts +14 -1
- package/src/routes.ts +212 -43
- package/src/sftp.ts +51 -14
- package/src/store.ts +10 -0
- package/src/terminal.ts +73 -26
- package/src/view-settings.ts +50 -10
- package/lib/types/client/Dialog.d.ts +0 -14
- package/src/client/Dialog.tsx +0 -76
|
@@ -6,19 +6,21 @@
|
|
|
6
6
|
* local viewer's twin — see selection-popup.ts); the payload is a fenced
|
|
7
7
|
* `rel:lines` block inserted into the on-screen session's composer draft.
|
|
8
8
|
*/
|
|
9
|
-
import { forwardRef, useEffect, useImperativeHandle, useRef, useState, type ReactNode } from 'react'
|
|
9
|
+
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState, type ReactNode } from 'react'
|
|
10
10
|
import { createPortal } from 'react-dom'
|
|
11
11
|
import type { Context } from '@deepseek-ai/cordis'
|
|
12
12
|
import { EditorSelection, EditorState, StateEffect, StateField, Compartment, type Extension, type Text } from '@codemirror/state'
|
|
13
|
-
import { Decoration, EditorView, highlightActiveLine, keymap, lineNumbers, type DecorationSet } from '@codemirror/view'
|
|
13
|
+
import { Decoration, EditorView, drawSelection, highlightActiveLine, keymap, lineNumbers, type DecorationSet } from '@codemirror/view'
|
|
14
14
|
import { history } from '@codemirror/commands'
|
|
15
15
|
import { bracketMatching, ensureSyntaxTree, indentOnInput } from '@codemirror/language'
|
|
16
16
|
import { closeBrackets } from '@codemirror/autocomplete'
|
|
17
|
-
import { search } from '@codemirror/search'
|
|
17
|
+
import { search, selectNextOccurrence } from '@codemirror/search'
|
|
18
18
|
import { syntaxHighlighting } from '@codemirror/language'
|
|
19
19
|
import { vscodeHighlightStyle } from './vsc/editor-palette.ts'
|
|
20
20
|
import { FindWidget, clearFindMarks, findMatchHighlight, stepFind } from './vsc/FindWidget.tsx'
|
|
21
|
-
import { editorKeymap } from './vsc/editor-keymap.ts'
|
|
21
|
+
import { editorKeymap, parseGotoLine } from './vsc/editor-keymap.ts'
|
|
22
|
+
import { promptDialog, toast } from './vsc/kit.tsx'
|
|
23
|
+
import { isModalLayerOpen } from './vsc/save-shortcut.ts'
|
|
22
24
|
import { javascript } from '@codemirror/lang-javascript'
|
|
23
25
|
import { python } from '@codemirror/lang-python'
|
|
24
26
|
import { json } from '@codemirror/lang-json'
|
|
@@ -38,6 +40,7 @@ import { diff } from '@codemirror/legacy-modes/mode/diff'
|
|
|
38
40
|
import { buildRemoteSelectionInsert, insertReferenceOrText, type PendingReference } from './composer.ts'
|
|
39
41
|
import { useSelectionPopup } from './selection-popup.ts'
|
|
40
42
|
import { initialEditorTheme, watchEditorScheme } from './vsc/editor-theme.ts'
|
|
43
|
+
import { detectLang, makeT } from './i18n.ts'
|
|
41
44
|
|
|
42
45
|
/**
|
|
43
46
|
* The bits of an editor's view state that must survive an unmount.
|
|
@@ -158,6 +161,14 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
158
161
|
readOnly?: boolean
|
|
159
162
|
/** Parent sub-tab visibility (views stay mounted; remeasure on show). */
|
|
160
163
|
visible?: boolean
|
|
164
|
+
/**
|
|
165
|
+
* Translator for the editor's own chrome (find widget + change marks).
|
|
166
|
+
*
|
|
167
|
+
* Optional so callers that do not own the dictionary (diff panes) keep
|
|
168
|
+
* working: the fallback makes the same `detectLang()` choice the store does,
|
|
169
|
+
* so the copy matches the language of the rest of the pane.
|
|
170
|
+
*/
|
|
171
|
+
t?: (key: string) => string
|
|
161
172
|
/**
|
|
162
173
|
* Soft wrap long lines.
|
|
163
174
|
*
|
|
@@ -280,6 +291,10 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
280
291
|
const dirtyRef = useRef<boolean>(false)
|
|
281
292
|
const propsRef = useRef(props)
|
|
282
293
|
propsRef.current = props
|
|
294
|
+
// Resolved once per mount: `detectLang()` is a page-level decision (the same
|
|
295
|
+
// one the store makes), so the identity is stable and safe in effect deps.
|
|
296
|
+
const fallbackT = useMemo(() => makeT(detectLang()), [])
|
|
297
|
+
const t = props.t ?? fallbackT
|
|
283
298
|
// The CodeMirror selection listener lives for the mount's lifetime; the
|
|
284
299
|
// chat target may change underneath it (session switches don't remount
|
|
285
300
|
// the editor), so it reads through refs, never captured props.
|
|
@@ -373,10 +388,19 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
373
388
|
*/
|
|
374
389
|
const armedRef = useRef('')
|
|
375
390
|
const pushedSetRef = useRef<ChangeSet | null | undefined>(undefined)
|
|
391
|
+
/**
|
|
392
|
+
* `changeMarksExtension` 的 gutter/chip 文案在安装时按 `t` 解析,所以语言换了
|
|
393
|
+
* 要和「能力翻转」一样重装一次 compartment。
|
|
394
|
+
*/
|
|
395
|
+
const labelsRef = useRef(t)
|
|
376
396
|
const undoArmed = props.onUndoChange !== undefined
|
|
377
397
|
useEffect(() => {
|
|
378
398
|
const current = viewRef.current
|
|
379
399
|
if (current === undefined) return
|
|
400
|
+
if (labelsRef.current !== t) {
|
|
401
|
+
labelsRef.current = t
|
|
402
|
+
armedRef.current = ''
|
|
403
|
+
}
|
|
380
404
|
const set = props.changeSet
|
|
381
405
|
const marks = set !== undefined
|
|
382
406
|
const armed = `${marks ? 'm' : ''}${undoArmed ? 'u' : ''}`
|
|
@@ -385,7 +409,7 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
385
409
|
// 重装扩展会重建字段,之前下发过的数据随之消失,必须再喂一次。
|
|
386
410
|
pushedSetRef.current = undefined
|
|
387
411
|
const extension: Extension = [
|
|
388
|
-
...(marks ? [changeMarksExtension] : []),
|
|
412
|
+
...(marks ? [changeMarksExtension(t)] : []),
|
|
389
413
|
...(undoArmed
|
|
390
414
|
? [undoAffordance({
|
|
391
415
|
onUndo: (mark) => { propsRef.current.onUndoChange?.(mark) },
|
|
@@ -407,7 +431,7 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
407
431
|
} catch {
|
|
408
432
|
// Disposed.
|
|
409
433
|
}
|
|
410
|
-
}, [props.changeSet, undoArmed, view])
|
|
434
|
+
}, [props.changeSet, undoArmed, view, t])
|
|
411
435
|
|
|
412
436
|
/**
|
|
413
437
|
* 跳到某个改动点。
|
|
@@ -454,6 +478,14 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
454
478
|
const host = hostRef.current
|
|
455
479
|
if (host === null) return
|
|
456
480
|
const rect = host.getBoundingClientRect()
|
|
481
|
+
// The surface can disappear while the widget is open (the preview swap
|
|
482
|
+
// hides the editor host with `display:none`). Close BEFORE positioning:
|
|
483
|
+
// a zero box would otherwise compute `right = innerWidth + 18` and shove
|
|
484
|
+
// the box out of the viewport, where Esc can no longer reach it.
|
|
485
|
+
if (rect.width === 0 || rect.height === 0) {
|
|
486
|
+
setFindOpen(false)
|
|
487
|
+
return
|
|
488
|
+
}
|
|
457
489
|
const next = {
|
|
458
490
|
top: Math.max(4, rect.top + 6),
|
|
459
491
|
right: Math.max(8, window.innerWidth - rect.right + 18),
|
|
@@ -478,6 +510,49 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
478
510
|
}
|
|
479
511
|
}, [findOpen])
|
|
480
512
|
|
|
513
|
+
/**
|
|
514
|
+
* Find widget lifecycle follows the editor surface.
|
|
515
|
+
*
|
|
516
|
+
* The widget is a `document.body` portal, so it does NOT live in the editor's
|
|
517
|
+
* DOM tree: when the surface it belongs to goes away (a Markdown/HTML preview
|
|
518
|
+
* swap, a hidden pane, a surface that left the viewport entirely) the box used
|
|
519
|
+
* to survive on screen with its 350 ms anchor poll still running — and Esc
|
|
520
|
+
* only works while its input has focus, so the user had to switch back to
|
|
521
|
+
* source just to close it.
|
|
522
|
+
*
|
|
523
|
+
* Closing is the same state flip Esc and the ✕ use (`setFindOpen(false)`), so
|
|
524
|
+
* the effect above drops the match marks and clears the poll through their
|
|
525
|
+
* existing path. Nothing here reopens it: when the surface comes back the user
|
|
526
|
+
* gets Ctrl+F again, but a widget they left behind does not pop up by itself.
|
|
527
|
+
*/
|
|
528
|
+
useEffect(() => {
|
|
529
|
+
if (!findOpen) return
|
|
530
|
+
// The parent's own answer for "this surface is mounted but not shown".
|
|
531
|
+
if (props.visible === false) {
|
|
532
|
+
setFindOpen(false)
|
|
533
|
+
return
|
|
534
|
+
}
|
|
535
|
+
const host = hostRef.current
|
|
536
|
+
if (host === null) return
|
|
537
|
+
// Geometry the parent cannot see: the preview swap puts `display:none` on
|
|
538
|
+
// the editor host without touching `visible`.
|
|
539
|
+
const rect = host.getBoundingClientRect()
|
|
540
|
+
if (rect.width === 0 || rect.height === 0) {
|
|
541
|
+
setFindOpen(false)
|
|
542
|
+
return
|
|
543
|
+
}
|
|
544
|
+
// Catch layout changes that emit no scroll/resize event (the preview swap,
|
|
545
|
+
// an ancestor collapsing). Absent in the jsdom harnesses, hence the guard.
|
|
546
|
+
if (typeof IntersectionObserver === 'undefined') return
|
|
547
|
+
const observer = new IntersectionObserver((entries) => {
|
|
548
|
+
if (entries.some(entry => !entry.isIntersecting)) setFindOpen(false)
|
|
549
|
+
})
|
|
550
|
+
observer.observe(host)
|
|
551
|
+
return () => {
|
|
552
|
+
observer.disconnect()
|
|
553
|
+
}
|
|
554
|
+
}, [findOpen, props.visible])
|
|
555
|
+
|
|
481
556
|
/**
|
|
482
557
|
* Note on the SCROLL report: it is wired up INSIDE the mount effect below,
|
|
483
558
|
* where the view is created — not in an effect of its own. An earlier version
|
|
@@ -631,8 +706,32 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
631
706
|
if (host === null) return
|
|
632
707
|
const extensions: Extension[] = [
|
|
633
708
|
history(),
|
|
634
|
-
|
|
635
|
-
|
|
709
|
+
/**
|
|
710
|
+
* Multi-range selections (Ctrl/Cmd+D's repeated "select next occurrence",
|
|
711
|
+
* and the stock Mod-Alt-Arrow cursor commands).
|
|
712
|
+
*
|
|
713
|
+
* Required, not cosmetic: without this facet `Transaction.state` collapses
|
|
714
|
+
* EVERY selection to its main range (`EditorSelection.asSingle`), so
|
|
715
|
+
* `selectNextOccurrence` reports success while nothing visible is added —
|
|
716
|
+
* the shortcut would look broken. The tab view-state code already carries
|
|
717
|
+
* multiple ranges across a remount, so this is the same model, enabled.
|
|
718
|
+
*/
|
|
719
|
+
EditorState.allowMultipleSelections.of(true),
|
|
720
|
+
// The facet above keeps the RANGES; `drawSelection` is what paints every
|
|
721
|
+
// secondary cursor and every non-main selection. Without it Ctrl+D changes
|
|
722
|
+
// the document on ranges the user cannot see (jsdom probes: the selection
|
|
723
|
+
// layer was null and one keystroke edited three ranges at once).
|
|
724
|
+
drawSelection(),
|
|
725
|
+
keymap.of(editorKeymap({
|
|
726
|
+
// The SAME modal gate the window-level listener applies (`save-shortcut.ts`):
|
|
727
|
+
// CodeMirror handles Mod-s first and prevents the default, so this callback —
|
|
728
|
+
// not that listener — is the one that decides while the editor has focus. A
|
|
729
|
+
// modal layer (host approval/settings, our confirm card, a menu) must not be
|
|
730
|
+
// written through; see editor-keymap's `EditorKeyHandlers.save` contract.
|
|
731
|
+
save: () => {
|
|
732
|
+
if (isModalLayerOpen()) return
|
|
733
|
+
propsRef.current.onSave()
|
|
734
|
+
},
|
|
636
735
|
openFindForSelection: (view) => {
|
|
637
736
|
const sel = view.state.selection.main
|
|
638
737
|
if (!sel.empty) {
|
|
@@ -657,6 +756,49 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
657
756
|
setFindOpen(false)
|
|
658
757
|
return true
|
|
659
758
|
},
|
|
759
|
+
/**
|
|
760
|
+
* Ctrl/Cmd+G: the prompt is ours (see `editor-keymap.ts`), because the
|
|
761
|
+
* stock `gotoLine` command renders CodeMirror's own search panel and
|
|
762
|
+
* this editor never mounts it. The jump reuses the same reveal helper a
|
|
763
|
+
* search hit uses: clamp to the document, put the caret there, light the
|
|
764
|
+
* landing line.
|
|
765
|
+
*/
|
|
766
|
+
gotoLine: (view) => {
|
|
767
|
+
void (async () => {
|
|
768
|
+
// Named with the `T` suffix the i18n key scanner accepts: the lookup
|
|
769
|
+
// must stay VISIBLE to `.spike/i18n-check`, or the three keys would
|
|
770
|
+
// later read as "defined but unreferenced" once they are added.
|
|
771
|
+
const editorT = propsRef.current.t ?? fallbackT
|
|
772
|
+
const total = view.state.doc.lines
|
|
773
|
+
const current = view.state.doc.lineAt(view.state.selection.main.head).number
|
|
774
|
+
const answer = await promptDialog({
|
|
775
|
+
title: editorT('editor.gotoLine'),
|
|
776
|
+
text: editorT('editor.gotoLineText').replace('{total}', String(total)),
|
|
777
|
+
initial: String(current),
|
|
778
|
+
})
|
|
779
|
+
if (answer === undefined) return
|
|
780
|
+
const target = parseGotoLine(answer, total)
|
|
781
|
+
if (target === undefined) {
|
|
782
|
+
toast(editorT('editor.gotoLineInvalid'), true)
|
|
783
|
+
return
|
|
784
|
+
}
|
|
785
|
+
// The prompt is async: the tab may have switched (or the surface
|
|
786
|
+
// unmounted) while it was open, and a disposed view must not be
|
|
787
|
+
// dispatched into.
|
|
788
|
+
if (viewRef.current !== view) return
|
|
789
|
+
revealLine(view, target, setLitPosition)
|
|
790
|
+
})()
|
|
791
|
+
},
|
|
792
|
+
/**
|
|
793
|
+
* Ctrl/Cmd+D: `@codemirror/search`'s command, verbatim. It only moves
|
|
794
|
+
* selections (never the document), so it is safe in the read-only views
|
|
795
|
+
* the diff panes mount; its false answer is returned so the key can fall
|
|
796
|
+
* through instead of being swallowed (see `editor-keymap.ts`).
|
|
797
|
+
*/
|
|
798
|
+
selectNextOccurrence: (view) => selectNextOccurrence({
|
|
799
|
+
state: view.state,
|
|
800
|
+
dispatch: transaction => view.dispatch(transaction),
|
|
801
|
+
}),
|
|
660
802
|
})),
|
|
661
803
|
lineNumbers(),
|
|
662
804
|
highlightActiveLine(),
|
|
@@ -1067,6 +1209,7 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
1067
1209
|
<FindWidget
|
|
1068
1210
|
view={view}
|
|
1069
1211
|
open={findOpen}
|
|
1212
|
+
t={t}
|
|
1070
1213
|
seed={findSeed}
|
|
1071
1214
|
tick={findTick}
|
|
1072
1215
|
anchor={anchor}
|
|
@@ -237,6 +237,8 @@ function LocalLeg(props: {
|
|
|
237
237
|
value={draft}
|
|
238
238
|
onChange={(e) => setDraft(e.target.value)}
|
|
239
239
|
onKeyDown={(e) => {
|
|
240
|
+
// IME candidate Enter must not navigate to a half-composed path.
|
|
241
|
+
if (e.nativeEvent.isComposing === true || e.keyCode === 229) return
|
|
240
242
|
if (e.key === 'Enter') go()
|
|
241
243
|
}}
|
|
242
244
|
disabled={blocked}
|
|
@@ -254,7 +256,19 @@ function LocalLeg(props: {
|
|
|
254
256
|
{(listing?.entries ?? []).filter((e) => !e.hidden).map((entry) => (
|
|
255
257
|
<div
|
|
256
258
|
key={entry.path}
|
|
259
|
+
// Same fix as the standalone picker (audit I-10): Enter/Space enter
|
|
260
|
+
// the directory. While a browse is in flight the row is inert, so it
|
|
261
|
+
// is taken out of the tab order instead of silently doing nothing.
|
|
262
|
+
role="button"
|
|
263
|
+
tabIndex={blocked ? -1 : 0}
|
|
264
|
+
aria-disabled={blocked === true ? true : undefined}
|
|
257
265
|
onClick={() => { if (!blocked) void browse(entry.path) }}
|
|
266
|
+
onKeyDown={(e) => {
|
|
267
|
+
if (blocked) return
|
|
268
|
+
if (e.key !== 'Enter' && e.key !== ' ') return
|
|
269
|
+
e.preventDefault()
|
|
270
|
+
void browse(entry.path)
|
|
271
|
+
}}
|
|
258
272
|
title={entry.path}
|
|
259
273
|
style={{ display: 'flex', gap: 6, alignItems: 'center', padding: '3px 8px', borderRadius: 4, cursor: blocked ? 'default' : 'pointer', fontSize: 13 }}
|
|
260
274
|
onMouseEnter={(e) => {
|
|
@@ -284,6 +298,8 @@ function LocalLeg(props: {
|
|
|
284
298
|
value={mkdirName}
|
|
285
299
|
onChange={(e) => setMkdirName(e.target.value)}
|
|
286
300
|
onKeyDown={(e) => {
|
|
301
|
+
// IME candidate Enter must not create a folder from a half-composed name.
|
|
302
|
+
if (e.nativeEvent.isComposing === true || e.keyCode === 229) return
|
|
287
303
|
if (e.key === 'Enter') mkdir()
|
|
288
304
|
}}
|
|
289
305
|
placeholder={t('flow.mkdirName')}
|
|
@@ -94,6 +94,20 @@ async function copyReport(text: string): Promise<boolean> {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Focusable controls inside this layer, in DOM order.
|
|
99
|
+
*
|
|
100
|
+
* Same rule as `vsc/kit.tsx`'s `focusables`, inlined instead of imported: this
|
|
101
|
+
* panel deliberately does not import the kit (its copy path must not use the
|
|
102
|
+
* silently-failing `copyText`), and `check-doctor.mjs` pins that.
|
|
103
|
+
*/
|
|
104
|
+
const FOCUSABLE = 'button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
|
|
105
|
+
|
|
106
|
+
function focusables(root: HTMLElement | null): HTMLElement[] {
|
|
107
|
+
if (root === null) return []
|
|
108
|
+
return Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE))
|
|
109
|
+
}
|
|
110
|
+
|
|
97
111
|
export function DoctorPanel(props: {
|
|
98
112
|
t: (key: string) => string
|
|
99
113
|
alias: string
|
|
@@ -103,6 +117,10 @@ export function DoctorPanel(props: {
|
|
|
103
117
|
/** `undefined` = the probe is still running. */
|
|
104
118
|
const [items, setItems] = useState<DoctorItem[] | undefined>(undefined)
|
|
105
119
|
const [copyState, setCopyState] = useState<'idle' | 'copied' | 'failed'>('idle')
|
|
120
|
+
/** The card, so the Tab trap below has one root to walk. */
|
|
121
|
+
const cardRef = useRef<HTMLDivElement>(null)
|
|
122
|
+
/** Where focus came from (the "环境自检" button); handed back on close. */
|
|
123
|
+
const openerRef = useRef<HTMLElement | null>(null)
|
|
106
124
|
const alive = useRef(true)
|
|
107
125
|
// Re-armed on every setup: a StrictMode/replay remount runs setup → cleanup →
|
|
108
126
|
// setup, and a flag that only ever got set to false would freeze the panel on
|
|
@@ -124,14 +142,59 @@ export function DoctorPanel(props: {
|
|
|
124
142
|
run()
|
|
125
143
|
}, [run])
|
|
126
144
|
|
|
145
|
+
/**
|
|
146
|
+
* The layer takes the keyboard on open and gives it back on close.
|
|
147
|
+
*
|
|
148
|
+
* The panel declared `role="dialog" aria-modal="true"` but nothing moved the
|
|
149
|
+
* focus into it, so Tab walked straight out into the DSH Settings form behind
|
|
150
|
+
* the overlay while a screen reader had been told that form is inert. It lives
|
|
151
|
+
* INSIDE the host Settings dialog, hence both halves: keep the keyboard here,
|
|
152
|
+
* and give it back to the button that opened this layer.
|
|
153
|
+
*/
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
openerRef.current = typeof document === 'undefined' ? null : (document.activeElement as HTMLElement | null)
|
|
156
|
+
// First paint first: the copy button is still disabled while the probe runs,
|
|
157
|
+
// so this settles on the close button — a safe, always-present target.
|
|
158
|
+
const focusTimer = window.setTimeout(() => { focusables(cardRef.current)[0]?.focus() }, 0)
|
|
159
|
+
return () => {
|
|
160
|
+
window.clearTimeout(focusTimer)
|
|
161
|
+
const opener = openerRef.current
|
|
162
|
+
if (opener !== null && document.body.contains(opener)) opener.focus()
|
|
163
|
+
}
|
|
164
|
+
}, [])
|
|
165
|
+
|
|
127
166
|
useEffect(() => {
|
|
128
167
|
const onKey = (e: KeyboardEvent): void => {
|
|
129
|
-
if (e.key
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
168
|
+
if (e.key === 'Escape') {
|
|
169
|
+
// CAPTURE phase + stop: the panel lives inside the DSH Settings dialog,
|
|
170
|
+
// whose own Escape handler would otherwise close the whole dialog (and the
|
|
171
|
+
// report) together with this layer.
|
|
172
|
+
e.stopPropagation()
|
|
173
|
+
props.onClose()
|
|
174
|
+
return
|
|
175
|
+
}
|
|
176
|
+
if (e.key !== 'Tab') return
|
|
177
|
+
// Tab trap, first <-> last (same shape as the kit's ModalCard).
|
|
178
|
+
const controls = focusables(cardRef.current)
|
|
179
|
+
if (controls.length === 0) return
|
|
180
|
+
const first = controls[0] as HTMLElement
|
|
181
|
+
const last = controls[controls.length - 1] as HTMLElement
|
|
182
|
+
const active = document.activeElement
|
|
183
|
+
const inside = cardRef.current?.contains(active) === true
|
|
184
|
+
// Focus outside the card: a plain Tab used to walk straight into the DSH
|
|
185
|
+
// Settings form behind the overlay (only Shift+Tab was pulled back, so the
|
|
186
|
+
// trap was not a closed loop). Both directions now return to the card.
|
|
187
|
+
if (!inside) {
|
|
188
|
+
e.preventDefault()
|
|
189
|
+
if (e.shiftKey) last.focus()
|
|
190
|
+
else first.focus()
|
|
191
|
+
} else if (e.shiftKey && active === first) {
|
|
192
|
+
e.preventDefault()
|
|
193
|
+
last.focus()
|
|
194
|
+
} else if (!e.shiftKey && active === last) {
|
|
195
|
+
e.preventDefault()
|
|
196
|
+
first.focus()
|
|
197
|
+
}
|
|
135
198
|
}
|
|
136
199
|
document.addEventListener('keydown', onKey, true)
|
|
137
200
|
return () => document.removeEventListener('keydown', onKey, true)
|
|
@@ -160,7 +223,7 @@ export function DoctorPanel(props: {
|
|
|
160
223
|
aria-label={title}
|
|
161
224
|
onClick={props.onClose}
|
|
162
225
|
>
|
|
163
|
-
<div className="rvs-doctor-card" onClick={(e) => e.stopPropagation()}>
|
|
226
|
+
<div ref={cardRef} className="rvs-doctor-card" onClick={(e) => e.stopPropagation()}>
|
|
164
227
|
<div className="rvs-doctor-head">
|
|
165
228
|
<span className="rvs-doctor-title">{title}</span>
|
|
166
229
|
<span style={{ flex: 1 }} />
|
|
@@ -354,6 +354,17 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
354
354
|
const connection = useConnectionStatus()
|
|
355
355
|
const offline = connection?.state === 'error'
|
|
356
356
|
|
|
357
|
+
/**
|
|
358
|
+
* The tab strip's roving focus stops, by tab id.
|
|
359
|
+
*
|
|
360
|
+
* The strip is ONE Tab stop (WAI-ARIA tabs): ←/→ and Home/End move the
|
|
361
|
+
* selection inside it, and only the active tab carries `tabIndex={0}`. A map
|
|
362
|
+
* (not refs on the elements) because the strip is rebuilt from the store on
|
|
363
|
+
* every render, and a keydown must be able to focus a SIBLING that is not the
|
|
364
|
+
* one it fired on.
|
|
365
|
+
*/
|
|
366
|
+
const tabElements = useRef(new Map<string, HTMLDivElement>())
|
|
367
|
+
|
|
357
368
|
// Image data URL cache, keyed by path (remote reads are not free). Bounded —
|
|
358
369
|
// see `rememberRecent` / `dropOversized`.
|
|
359
370
|
const [images, setImages] = useState<Record<string, string>>({})
|
|
@@ -465,10 +476,23 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
465
476
|
await store.reloadTab(tab.id)
|
|
466
477
|
}
|
|
467
478
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
479
|
+
/**
|
|
480
|
+
* The preview inputs as STABLE primitives, not the tab object.
|
|
481
|
+
*
|
|
482
|
+
* `patchTab` builds a fresh tab object for every change (`dirty`, `saving`,
|
|
483
|
+
* `activeHunk`, `reloadNonce`…) while leaving `text` and the render-mode flags
|
|
484
|
+
* alone. Keying the two preview memos below on the tab therefore re-parsed a
|
|
485
|
+
* whole Markdown/HTML document whenever the user saved, jumped to a change or
|
|
486
|
+
* toggled a dot — a parse per action, for text that had not moved. A string's
|
|
487
|
+
* identity is stable while its contents are, so `text` + the flags is the key
|
|
488
|
+
* that actually means "the preview source changed".
|
|
489
|
+
*/
|
|
490
|
+
const previewText = activeTab?.text
|
|
491
|
+
const previewIsHtml = activeTab?.html === true
|
|
492
|
+
const previewIsMarkdown = activeTab?.markdown === true
|
|
493
|
+
const previewVisible = activeTab?.preview === true
|
|
494
|
+
|
|
495
|
+
const htmlDoc = useMemo(() => (previewIsHtml ? (previewText ?? '') : ''), [previewIsHtml, previewText])
|
|
472
496
|
|
|
473
497
|
/**
|
|
474
498
|
* The parsed Markdown preview.
|
|
@@ -477,16 +501,16 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
477
501
|
* re-parsed the whole document into a fresh element tree on EVERY store
|
|
478
502
|
* publish: this component subscribes to the store, so opening another file,
|
|
479
503
|
* saving, a git refresh or switching a panel all paid for a parse of text
|
|
480
|
-
* that had not changed. `renderMarkdown` is a pure function of the text,
|
|
481
|
-
* a
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
504
|
+
* that had not changed. `renderMarkdown` is a pure function of the text, so
|
|
505
|
+
* the memo key is the TEXT (a stable identity while the bytes are) plus the
|
|
506
|
+
* two mode flags — see `previewText` above for why the tab object is the wrong
|
|
507
|
+
* key. The guards keep the parse from happening at all for a file that is
|
|
508
|
+
* being read in source mode.
|
|
485
509
|
*/
|
|
486
510
|
const markdownPreview = useMemo(() => {
|
|
487
|
-
if (
|
|
488
|
-
return renderMarkdown(
|
|
489
|
-
}, [
|
|
511
|
+
if (!previewIsMarkdown || !previewVisible || previewText === undefined) return null
|
|
512
|
+
return renderMarkdown(previewText)
|
|
513
|
+
}, [previewIsMarkdown, previewVisible, previewText])
|
|
490
514
|
|
|
491
515
|
/**
|
|
492
516
|
* The status bar's indent hint, derived from the loaded text.
|
|
@@ -806,15 +830,21 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
806
830
|
{/* Tab strip: switch / close / dirty dot / diff glyph. Middle-click closes
|
|
807
831
|
too — the muscle memory shared with VS Code and browsers. */}
|
|
808
832
|
<div className="rvs-etabs" role="tablist" aria-label={t('editor.tabsLabel')}>
|
|
809
|
-
{tabs.map(tab => {
|
|
833
|
+
{tabs.map((tab, index) => {
|
|
810
834
|
const active = tab.id === store.activeTabId
|
|
811
835
|
const tabIsDiff = tab.kind === 'diff'
|
|
812
836
|
return (
|
|
813
837
|
<div
|
|
814
838
|
key={tab.id}
|
|
815
839
|
role="tab"
|
|
816
|
-
|
|
840
|
+
// Roving tabindex (WAI-ARIA tabs): the strip is one Tab stop, so
|
|
841
|
+
// the panel's other controls are not separated by N tab stops.
|
|
842
|
+
tabIndex={active ? 0 : -1}
|
|
817
843
|
aria-selected={active}
|
|
844
|
+
ref={(element) => {
|
|
845
|
+
if (element === null) tabElements.current.delete(tab.id)
|
|
846
|
+
else tabElements.current.set(tab.id, element)
|
|
847
|
+
}}
|
|
818
848
|
className={`rvs-etab${active ? ' active' : ''}${tabIsDiff ? ' rvs-etab-diff' : ''}`}
|
|
819
849
|
title={tabIsDiff ? `${tab.rel}${t('editor.diffSuffix')}` : tab.fullPath}
|
|
820
850
|
onClick={() => store.activateTab(tab.id)}
|
|
@@ -829,7 +859,26 @@ export function EditorPane(props: { visible: boolean }): ReactNode {
|
|
|
829
859
|
if (event.key === 'Enter' || event.key === ' ') {
|
|
830
860
|
event.preventDefault()
|
|
831
861
|
store.activateTab(tab.id)
|
|
862
|
+
return
|
|
832
863
|
}
|
|
864
|
+
// WAI-ARIA tabs keyboard model (audit I-16): arrows walk the
|
|
865
|
+
// strip, Home/End jump to its edges, wrapping at both ends, and
|
|
866
|
+
// the selection follows focus — the tabs are the cheap file
|
|
867
|
+
// switcher, so requiring Enter afterwards would only add a step.
|
|
868
|
+
const step = event.key === 'ArrowRight'
|
|
869
|
+
? 1
|
|
870
|
+
: event.key === 'ArrowLeft' ? -1 : undefined
|
|
871
|
+
if (step === undefined && event.key !== 'Home' && event.key !== 'End') return
|
|
872
|
+
event.preventDefault()
|
|
873
|
+
const next = event.key === 'Home'
|
|
874
|
+
? 0
|
|
875
|
+
: event.key === 'End'
|
|
876
|
+
? tabs.length - 1
|
|
877
|
+
: (index + (step ?? 0) + tabs.length) % tabs.length
|
|
878
|
+
const target = tabs[next]
|
|
879
|
+
if (target === undefined) return
|
|
880
|
+
store.activateTab(target.id)
|
|
881
|
+
tabElements.current.get(target.id)?.focus()
|
|
833
882
|
}}
|
|
834
883
|
>
|
|
835
884
|
<span className="rvs-etab-glyph">{tabIcon(tab)}</span>
|
package/src/client/HostsView.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import type { RemoteDeployState, RemoteHostSummary } from '../protocol.ts'
|
|
|
6
6
|
import { RemoteApiError, api, type HostForm } from './api.ts'
|
|
7
7
|
import { DoctorPanel } from './DoctorPanel.tsx'
|
|
8
8
|
import { Btn, Field, Notice, Row, hairline, inputStyle } from './ui.tsx'
|
|
9
|
+
import { confirmDialog } from './vsc/kit.tsx'
|
|
9
10
|
|
|
10
11
|
function err(e: unknown): string {
|
|
11
12
|
return e instanceof RemoteApiError ? e.message : String(e)
|
|
@@ -204,8 +205,16 @@ export function HostsView(props: {
|
|
|
204
205
|
)
|
|
205
206
|
}
|
|
206
207
|
|
|
207
|
-
const runDelete = (alias: string): void => {
|
|
208
|
-
|
|
208
|
+
const runDelete = async (alias: string): Promise<void> => {
|
|
209
|
+
// Themed confirm instead of `window.confirm`: the native one ignores the
|
|
210
|
+
// plugin theme, is not keyboard-trapped with the rest of the UI and cannot
|
|
211
|
+
// mark the action as destructive.
|
|
212
|
+
const ok = await confirmDialog({
|
|
213
|
+
title: t('hosts.confirmDelete'),
|
|
214
|
+
danger: true,
|
|
215
|
+
okText: t('hosts.delete'),
|
|
216
|
+
})
|
|
217
|
+
if (!ok) return
|
|
209
218
|
setBusy(`del:${alias}`)
|
|
210
219
|
api.deleteHost(alias).then(
|
|
211
220
|
() => { setBusy(undefined); say(t('hosts.deleted').replace('{alias}', alias)); props.onChanged() },
|
|
@@ -303,7 +312,7 @@ export function HostsView(props: {
|
|
|
303
312
|
<Btn onClick={() => { setEditing(editing === h.alias ? null : h.alias); setNotice(undefined); setError(undefined) }} disabled={disabled}>
|
|
304
313
|
{t('hosts.edit')}
|
|
305
314
|
</Btn>
|
|
306
|
-
<Btn kind="danger" onClick={() => runDelete(h.alias)} disabled={disabled}>{t('hosts.delete')}</Btn>
|
|
315
|
+
<Btn kind="danger" onClick={() => { void runDelete(h.alias) }} disabled={disabled}>{t('hosts.delete')}</Btn>
|
|
307
316
|
</Row>
|
|
308
317
|
{editing === h.alias && (
|
|
309
318
|
<HostFormView t={t} initial={h} busy={disabled} onSave={saveForm} onCancel={() => setEditing(null)} />
|
|
@@ -157,6 +157,8 @@ export function RemoteDirectoryPicker(props: {
|
|
|
157
157
|
value={draft}
|
|
158
158
|
onChange={(e) => setDraft(e.target.value)}
|
|
159
159
|
onKeyDown={(e) => {
|
|
160
|
+
// IME candidate Enter must not navigate to a half-composed path.
|
|
161
|
+
if (e.nativeEvent.isComposing === true || e.keyCode === 229) return
|
|
160
162
|
if (e.key === 'Enter') go()
|
|
161
163
|
}}
|
|
162
164
|
placeholder="/home/user/project"
|
|
@@ -174,7 +176,17 @@ export function RemoteDirectoryPicker(props: {
|
|
|
174
176
|
{entries.map((entry) => (
|
|
175
177
|
<div
|
|
176
178
|
key={entry.path}
|
|
179
|
+
// A directory row was pointer-only: keyboard users could not enter
|
|
180
|
+
// it at all (audit I-10). Role + tabIndex + Enter/Space make it a
|
|
181
|
+
// real button without changing how it looks.
|
|
182
|
+
role="button"
|
|
183
|
+
tabIndex={0}
|
|
177
184
|
onClick={() => void browse(entry.path)}
|
|
185
|
+
onKeyDown={(e) => {
|
|
186
|
+
if (e.key !== 'Enter' && e.key !== ' ') return
|
|
187
|
+
e.preventDefault()
|
|
188
|
+
void browse(entry.path)
|
|
189
|
+
}}
|
|
178
190
|
title={entry.path}
|
|
179
191
|
style={{ display: 'flex', gap: 6, alignItems: 'center', padding: '3px 8px', borderRadius: 4, cursor: 'pointer', fontSize: 13 }}
|
|
180
192
|
onMouseEnter={(e) => {
|