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
package/src/sftp.ts
CHANGED
|
@@ -500,10 +500,37 @@ export class RemoteFiles {
|
|
|
500
500
|
})
|
|
501
501
|
this.trackPartial(alias, partial)
|
|
502
502
|
const size = await streamIntoFile(sftp, partial, source, maxBytes)
|
|
503
|
-
// Move into place
|
|
504
|
-
//
|
|
505
|
-
|
|
506
|
-
|
|
503
|
+
// Move into place the same way a save does: an overwrite must never
|
|
504
|
+
// delete the target first. The old unlink→rename pair left the directory
|
|
505
|
+
// empty when the rename failed, and the catch below then removed the new
|
|
506
|
+
// bytes too — the upload reported a failure and the user's file was gone.
|
|
507
|
+
// `replaceFile` swaps the names (posix-rename, or target-aside with a
|
|
508
|
+
// rollback), so the previous bytes survive every failure with the real
|
|
509
|
+
// error attached.
|
|
510
|
+
if (overwrite) {
|
|
511
|
+
// A write target must be a regular file (or absent). On servers without
|
|
512
|
+
// `posix-rename@openssh.com` the fallback renames the target aside — and
|
|
513
|
+
// SFTP v3 `rename` happily renames a DIRECTORY that way, so a file
|
|
514
|
+
// dropped onto a same-named folder would move the folder to `*.bak-*`
|
|
515
|
+
// (never swept) and report success. Fail before anything moves.
|
|
516
|
+
const targetStat = await lstatAsync(sftp, path).catch((error: unknown) => {
|
|
517
|
+
if ((error as { code?: number }).code === SFTP_NO_SUCH_FILE) return undefined
|
|
518
|
+
throw error
|
|
519
|
+
})
|
|
520
|
+
// `Stats.isDirectory()` is the real ssh2 shape; accept the raw mode for
|
|
521
|
+
// fake SFTPs (and any future backend) that only carry attributes.
|
|
522
|
+
const targetIsDirectory = targetStat !== undefined && (
|
|
523
|
+
typeof (targetStat as { isDirectory?: () => boolean }).isDirectory === 'function'
|
|
524
|
+
? (targetStat as { isDirectory: () => boolean }).isDirectory()
|
|
525
|
+
: (targetStat.mode & 0o170000) === 0o040000
|
|
526
|
+
)
|
|
527
|
+
if (targetIsDirectory) throw new Error(`not a file: ${path} is a directory`)
|
|
528
|
+
await replaceFile(sftp, partial, path)
|
|
529
|
+
} else {
|
|
530
|
+
// No consent to replace: SFTP v3 `rename` refuses to clobber, so a file
|
|
531
|
+
// that appeared after the route's 409 check is kept.
|
|
532
|
+
await renameAsync(sftp, partial, path)
|
|
533
|
+
}
|
|
507
534
|
this.forgetPartial(alias, partial)
|
|
508
535
|
this.remember(this.knownDirs, dirKey(alias, dir))
|
|
509
536
|
await this.sweepOrphanDirs(sftp, alias, dir)
|
|
@@ -701,16 +728,18 @@ export class RemoteFiles {
|
|
|
701
728
|
try {
|
|
702
729
|
await mkdirAsync(sftp, path)
|
|
703
730
|
} catch (error) {
|
|
704
|
-
// EEXIST (code 4, "Failure") means the level is already there.
|
|
705
731
|
const code = (error as { code?: number }).code
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
732
|
+
// OpenSSH's sftp-server answers EEXIST, EACCES, EROFS and ENOSPC with the
|
|
733
|
+
// same opaque `SSH_FX_FAILURE(4)`, so 4 cannot mean "already there" on its
|
|
734
|
+
// own: swallowing it hid a permission or disk-space refusal until it
|
|
735
|
+
// surfaced later as a misleading "no such file" (S3). Verify the path
|
|
736
|
+
// instead — an existing level is the case this walk must tolerate, any
|
|
737
|
+
// other failure rethrows the original status.
|
|
738
|
+
if (code !== SFTP_FAILURE && code !== undefined) throw error
|
|
739
|
+
try {
|
|
740
|
+
await lstatAsync(sftp, path)
|
|
741
|
+
} catch {
|
|
742
|
+
throw error
|
|
714
743
|
}
|
|
715
744
|
}
|
|
716
745
|
}
|
|
@@ -955,7 +984,15 @@ async function explainSftpFailure(
|
|
|
955
984
|
if (code !== SFTP_NO_SUCH_FILE && code !== SFTP_FAILURE) return undefined
|
|
956
985
|
const kind = await pathKind(sftp, path)
|
|
957
986
|
if (kind.kind === 'missing') {
|
|
958
|
-
|
|
987
|
+
// A status 4 with nothing at the path usually is not "it never existed":
|
|
988
|
+
// OpenSSH reports EACCES/EROFS/ENOSPC with that same code, and the path may
|
|
989
|
+
// be unreadable rather than absent. Name the alternative instead of guessing
|
|
990
|
+
// one cause — EACCES in particular keeps its own status (3), so hard-coding
|
|
991
|
+
// "permission denied" here would be wrong for this code path.
|
|
992
|
+
const hint = code === SFTP_FAILURE
|
|
993
|
+
? ' (the server reported only status 4: this can also be a permission or disk-space problem)'
|
|
994
|
+
: ''
|
|
995
|
+
return new Error(wanted === 'directory' ? `no such directory: ${path}${hint}` : `no such file: ${path}${hint}`)
|
|
959
996
|
}
|
|
960
997
|
if (wanted === 'directory' && kind.kind !== 'dir') {
|
|
961
998
|
return new Error(`not a directory: ${path} is ${describeKind(kind)}`)
|
package/src/store.ts
CHANGED
|
@@ -98,6 +98,16 @@ export class RemoteStore {
|
|
|
98
98
|
this.reload()
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Absolute path of the JSON document.
|
|
103
|
+
*
|
|
104
|
+
* Diagnostics only: a corrupt file must name itself in the error a surface
|
|
105
|
+
* shows, otherwise the user only sees "the request failed".
|
|
106
|
+
*/
|
|
107
|
+
get filePath(): string {
|
|
108
|
+
return this.file
|
|
109
|
+
}
|
|
110
|
+
|
|
101
111
|
/**
|
|
102
112
|
* Reload from disk (picks up external edits).
|
|
103
113
|
*
|
package/src/terminal.ts
CHANGED
|
@@ -31,6 +31,20 @@ interface Session {
|
|
|
31
31
|
*/
|
|
32
32
|
outBuffer: string
|
|
33
33
|
outTimer: ReturnType<typeof setTimeout> | undefined
|
|
34
|
+
/**
|
|
35
|
+
* Recent output already flushed to sockets, replayed to a REATTACHING socket.
|
|
36
|
+
*
|
|
37
|
+
* A PTY lives for ten minutes after its last socket, but the screen state
|
|
38
|
+
* (the prompt, the last command's output) lives only in xterm on the client.
|
|
39
|
+
* When a session switch remounts the sidebar, the new XTerm attaches to the
|
|
40
|
+
* still-running shell and used to start BLANK — the shell was at its prompt,
|
|
41
|
+
* but the prompt had been printed before the socket existed. Keeping the tail
|
|
42
|
+
* of the stream lets `attach` hand the newcomer the screen it missed.
|
|
43
|
+
*
|
|
44
|
+
* Bounded: `REPLAY_MAX_CHARS` is enough for a prompt plus a screenful or two;
|
|
45
|
+
* a `cat` of a huge file must not double the host's memory per session.
|
|
46
|
+
*/
|
|
47
|
+
replay: string
|
|
34
48
|
/**
|
|
35
49
|
* When the last `out` frame went out.
|
|
36
50
|
*
|
|
@@ -124,6 +138,15 @@ const OUT_COALESCE_CHARS = 64 * 1024
|
|
|
124
138
|
*/
|
|
125
139
|
const OUT_ECHO_IDLE_MS = 24
|
|
126
140
|
|
|
141
|
+
/**
|
|
142
|
+
* How much recent output a reattaching socket receives (see `Session.replay`).
|
|
143
|
+
*
|
|
144
|
+
* 128 Ki UTF-16 units is a few screens of logs plus the prompt line; the buffer
|
|
145
|
+
* may grow to twice this between trims, so one terminal costs at most ~512 KiB
|
|
146
|
+
* of the host's memory in replay state.
|
|
147
|
+
*/
|
|
148
|
+
const REPLAY_MAX_CHARS = 128 * 1024
|
|
149
|
+
|
|
127
150
|
/** Construction options (the terminal gate drives the registry directly). */
|
|
128
151
|
export interface TerminalRegistryOptions {
|
|
129
152
|
/**
|
|
@@ -194,6 +217,7 @@ export class TerminalSessionRegistry {
|
|
|
194
217
|
paused: false,
|
|
195
218
|
outBuffer: '',
|
|
196
219
|
outTimer: undefined,
|
|
220
|
+
replay: '',
|
|
197
221
|
lastFlushAt: 0,
|
|
198
222
|
outstanding: new Map(),
|
|
199
223
|
reap: undefined,
|
|
@@ -252,6 +276,13 @@ export class TerminalSessionRegistry {
|
|
|
252
276
|
const session = this.sessions.get(id)
|
|
253
277
|
if (session === undefined || !session.alive) return false
|
|
254
278
|
this.hookSocket(session, ws)
|
|
279
|
+
// Hand the newcomer the output this session produced before it attached
|
|
280
|
+
// (the shell's prompt, the previous command's screen). It goes through the
|
|
281
|
+
// same per-socket accounting as live output, so a huge replay cannot slip
|
|
282
|
+
// past the backpressure ceiling.
|
|
283
|
+
if (session.replay !== '') {
|
|
284
|
+
this.sendOutTo(session, ws, JSON.stringify({ t: 'out', d: session.replay }))
|
|
285
|
+
}
|
|
255
286
|
// Deliver anything the coalescing window still holds to the newcomer too,
|
|
256
287
|
// before its `ready`: it is output the shell already produced.
|
|
257
288
|
this.flushOut(session)
|
|
@@ -422,6 +453,11 @@ export class TerminalSessionRegistry {
|
|
|
422
453
|
if (session.outBuffer === '') return
|
|
423
454
|
const text = session.outBuffer
|
|
424
455
|
session.outBuffer = ''
|
|
456
|
+
// Remember what was already delivered: a later reattach replays this.
|
|
457
|
+
session.replay += text
|
|
458
|
+
if (session.replay.length > REPLAY_MAX_CHARS * 2) {
|
|
459
|
+
session.replay = session.replay.slice(-REPLAY_MAX_CHARS)
|
|
460
|
+
}
|
|
425
461
|
session.lastFlushAt = Date.now()
|
|
426
462
|
this.broadcast(session, { t: 'out', d: text })
|
|
427
463
|
}
|
|
@@ -447,35 +483,46 @@ export class TerminalSessionRegistry {
|
|
|
447
483
|
|
|
448
484
|
private broadcast(session: Session, frame: TerminalServerFrame): void {
|
|
449
485
|
const text = JSON.stringify(frame)
|
|
486
|
+
for (const socket of session.sockets) {
|
|
487
|
+
this.sendOutTo(session, socket, text)
|
|
488
|
+
}
|
|
489
|
+
if (session.pending > OUT_HIGH_WATER) this.setPaused(session, true)
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Send one already-stringified `out` frame to ONE socket with accounting.
|
|
494
|
+
*
|
|
495
|
+
* Shared by `broadcast` and by the replay on `attach`; the byte count must be
|
|
496
|
+
* counted once per socket so the session's brake reflects every socket's
|
|
497
|
+
* backlog (see `Session.pending`).
|
|
498
|
+
*/
|
|
499
|
+
private sendOutTo(session: Session, socket: WebSocket, text: string): void {
|
|
450
500
|
// Bytes, not UTF-16 code units: CJK and emoji output would otherwise be
|
|
451
501
|
// undercounted by up to 3x and the brake would come on too late.
|
|
452
502
|
const size = Buffer.byteLength(text, 'utf8')
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
done()
|
|
477
|
-
}
|
|
503
|
+
let settled = false
|
|
504
|
+
// The send callback fires once the frame is on the wire. It is the only
|
|
505
|
+
// public signal for "this socket has caught up", and it avoids relying on
|
|
506
|
+
// ws internals (bufferedAmount does not report the socket write queue).
|
|
507
|
+
const done = (): void => {
|
|
508
|
+
if (settled) return
|
|
509
|
+
settled = true
|
|
510
|
+
// A socket that detached already had its outstanding bytes released
|
|
511
|
+
// (its late callback must not decrement them a second time).
|
|
512
|
+
const left = session.outstanding.get(socket)
|
|
513
|
+
if (left === undefined) return
|
|
514
|
+
const remaining = Math.max(0, left - size)
|
|
515
|
+
if (remaining === 0) session.outstanding.delete(socket)
|
|
516
|
+
else session.outstanding.set(socket, remaining)
|
|
517
|
+
session.pending = Math.max(0, session.pending - size)
|
|
518
|
+
if (session.pending <= OUT_LOW_WATER) this.setPaused(session, false)
|
|
519
|
+
}
|
|
520
|
+
session.pending += size
|
|
521
|
+
session.outstanding.set(socket, (session.outstanding.get(socket) ?? 0) + size)
|
|
522
|
+
try {
|
|
523
|
+
socket.send(text, done)
|
|
524
|
+
} catch {
|
|
525
|
+
done()
|
|
478
526
|
}
|
|
479
|
-
if (session.pending > OUT_HIGH_WATER) this.setPaused(session, true)
|
|
480
527
|
}
|
|
481
528
|
}
|
package/src/view-settings.ts
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* keys are ignored — the browser is the only writer, and a stale tab must not be
|
|
19
19
|
* able to corrupt the file with an extra key).
|
|
20
20
|
*/
|
|
21
|
-
import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, writeSync } from 'node:fs'
|
|
21
|
+
import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, statSync, writeSync } from 'node:fs'
|
|
22
22
|
import { dirname } from 'node:path'
|
|
23
23
|
import {
|
|
24
24
|
REMOTE_VIEW_SETTINGS_DEFAULTS,
|
|
@@ -39,6 +39,26 @@ function defaults(): RemoteViewSettings {
|
|
|
39
39
|
return { ...REMOTE_VIEW_SETTINGS_DEFAULTS }
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/** Identity of the settings file at one point in time; `null` = the file is absent. */
|
|
43
|
+
type FileStamp = { mtimeMs: number; size: number } | null
|
|
44
|
+
|
|
45
|
+
/** Same file identity (both absent counts as same). */
|
|
46
|
+
function sameStamp(left: FileStamp, right: FileStamp): boolean {
|
|
47
|
+
if (left === null || right === null) return left === right
|
|
48
|
+
return left.mtimeMs === right.mtimeMs && left.size === right.size
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Replays one read-modify-write before giving up.
|
|
53
|
+
*
|
|
54
|
+
* Desktop and `dsh web` share `$DSH_HOME/dsh-remote-view.json` by design, and
|
|
55
|
+
* every patch rewrites the WHOLE document: a plain read-merge-write let the last
|
|
56
|
+
* window win and silently dropped the other one's preference. A stamp re-check
|
|
57
|
+
* right before the write turns that into a replay on fresh content; a third
|
|
58
|
+
* failed attempt fails loud instead of losing a setting.
|
|
59
|
+
*/
|
|
60
|
+
const PATCH_ATTEMPTS = 3
|
|
61
|
+
|
|
42
62
|
/** A finite width share, clamped into the allowed band; anything else is a miss. */
|
|
43
63
|
function readWidthRatio(value: unknown): number | undefined {
|
|
44
64
|
if (typeof value !== 'number' || !Number.isFinite(value)) return undefined
|
|
@@ -95,16 +115,36 @@ export class RemoteViewSettingsStore {
|
|
|
95
115
|
* @returns the settings as stored.
|
|
96
116
|
*/
|
|
97
117
|
patch(patch: Record<string, unknown>): RemoteViewSettings {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
118
|
+
for (let attempt = 0; attempt < PATCH_ATTEMPTS; attempt += 1) {
|
|
119
|
+
// Stamp BEFORE the read: a write landing in between leaves the older stamp
|
|
120
|
+
// behind, so the re-check below catches it and replays on the new content.
|
|
121
|
+
const before = this.stampOf()
|
|
122
|
+
const current = this.get()
|
|
123
|
+
const next: RemoteViewSettings = {
|
|
124
|
+
autoOpenRemoteWorkspace: typeof patch.autoOpenRemoteWorkspace === 'boolean'
|
|
125
|
+
? patch.autoOpenRemoteWorkspace
|
|
126
|
+
: current.autoOpenRemoteWorkspace,
|
|
127
|
+
remoteWorkspaceWidthRatio: readWidthRatio(patch.remoteWorkspaceWidthRatio)
|
|
128
|
+
?? current.remoteWorkspaceWidthRatio,
|
|
129
|
+
}
|
|
130
|
+
if (!sameStamp(before, this.stampOf())) continue
|
|
131
|
+
this.save(next)
|
|
132
|
+
return next
|
|
133
|
+
}
|
|
134
|
+
throw new Error(`${this.file}: another process keeps editing the view settings; retry the operation`)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* File identity right now; `null` when the file is absent (or cannot be
|
|
139
|
+
* statted — `get()` fails loud on that case anyway).
|
|
140
|
+
*/
|
|
141
|
+
private stampOf(): FileStamp {
|
|
142
|
+
try {
|
|
143
|
+
const stat = statSync(this.file, { throwIfNoEntry: false })
|
|
144
|
+
return stat === undefined ? null : { mtimeMs: stat.mtimeMs, size: stat.size }
|
|
145
|
+
} catch {
|
|
146
|
+
return null
|
|
105
147
|
}
|
|
106
|
-
this.save(next)
|
|
107
|
-
return next
|
|
108
148
|
}
|
|
109
149
|
|
|
110
150
|
/** Write one document atomically: a crash never leaves a half-written file. */
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Small inline input dialog (new file / folder / rename). Rendered as a
|
|
3
|
-
* fixed overlay card; Enter confirms, Escape cancels.
|
|
4
|
-
*/
|
|
5
|
-
import { type ReactNode } from 'react';
|
|
6
|
-
export declare function InputDialog(props: {
|
|
7
|
-
title: string;
|
|
8
|
-
label: string;
|
|
9
|
-
initial?: string;
|
|
10
|
-
placeholder?: string;
|
|
11
|
-
okText?: string;
|
|
12
|
-
onOk: (value: string) => void;
|
|
13
|
-
onCancel: () => void;
|
|
14
|
-
}): ReactNode;
|
package/src/client/Dialog.tsx
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Small inline input dialog (new file / folder / rename). Rendered as a
|
|
3
|
-
* fixed overlay card; Enter confirms, Escape cancels.
|
|
4
|
-
*/
|
|
5
|
-
import { useEffect, useRef, useState, type ReactNode } from 'react'
|
|
6
|
-
import { Btn, inputStyle } from './ui.tsx'
|
|
7
|
-
|
|
8
|
-
export function InputDialog(props: {
|
|
9
|
-
title: string
|
|
10
|
-
label: string
|
|
11
|
-
initial?: string
|
|
12
|
-
placeholder?: string
|
|
13
|
-
okText?: string
|
|
14
|
-
onOk: (value: string) => void
|
|
15
|
-
onCancel: () => void
|
|
16
|
-
}): ReactNode {
|
|
17
|
-
const [value, setValue] = useState(props.initial ?? '')
|
|
18
|
-
const inputRef = useRef<HTMLInputElement>(null)
|
|
19
|
-
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
inputRef.current?.focus()
|
|
22
|
-
inputRef.current?.select()
|
|
23
|
-
}, [])
|
|
24
|
-
|
|
25
|
-
const commit = (): void => {
|
|
26
|
-
const trimmed = value.trim()
|
|
27
|
-
if (trimmed === '') return
|
|
28
|
-
props.onOk(trimmed)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return (
|
|
32
|
-
<div
|
|
33
|
-
style={{
|
|
34
|
-
position: 'fixed',
|
|
35
|
-
inset: 0,
|
|
36
|
-
zIndex: 1000,
|
|
37
|
-
background: 'rgba(0,0,0,.45)',
|
|
38
|
-
display: 'flex',
|
|
39
|
-
alignItems: 'center',
|
|
40
|
-
justifyContent: 'center',
|
|
41
|
-
}}
|
|
42
|
-
onClick={props.onCancel}
|
|
43
|
-
>
|
|
44
|
-
<div
|
|
45
|
-
style={{
|
|
46
|
-
minWidth: 320,
|
|
47
|
-
maxWidth: '90vw',
|
|
48
|
-
background: 'Canvas',
|
|
49
|
-
color: 'CanvasText',
|
|
50
|
-
border: '1px solid rgba(127,127,127,.4)',
|
|
51
|
-
borderRadius: 8,
|
|
52
|
-
padding: 14,
|
|
53
|
-
}}
|
|
54
|
-
onClick={(e) => e.stopPropagation()}
|
|
55
|
-
onKeyDown={(e) => {
|
|
56
|
-
if (e.key === 'Enter') commit()
|
|
57
|
-
else if (e.key === 'Escape') props.onCancel()
|
|
58
|
-
}}
|
|
59
|
-
>
|
|
60
|
-
<div style={{ fontWeight: 600, marginBottom: 8 }}>{props.title}</div>
|
|
61
|
-
<div style={{ fontSize: 12, opacity: 0.75, marginBottom: 4 }}>{props.label}</div>
|
|
62
|
-
<input
|
|
63
|
-
ref={inputRef}
|
|
64
|
-
value={value}
|
|
65
|
-
placeholder={props.placeholder}
|
|
66
|
-
onChange={(e) => setValue(e.target.value)}
|
|
67
|
-
style={inputStyle}
|
|
68
|
-
/>
|
|
69
|
-
<div style={{ display: 'flex', gap: 8, justifyContent: 'flex-end', marginTop: 12 }}>
|
|
70
|
-
<Btn onClick={props.onCancel}>取消 / Cancel</Btn>
|
|
71
|
-
<Btn kind="primary" onClick={commit}>{props.okText ?? '确定 / OK'}</Btn>
|
|
72
|
-
</div>
|
|
73
|
-
</div>
|
|
74
|
-
</div>
|
|
75
|
-
)
|
|
76
|
-
}
|