dsh-remote 0.8.76 → 0.8.77

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.
Files changed (2) hide show
  1. package/lib/client.js +146 -17
  2. package/package.json +1 -1
package/lib/client.js CHANGED
@@ -38,6 +38,23 @@ window.__ModuleLoader__.load({
38
38
  // plain source.
39
39
  const Primitives = (() => { try { return require('@deepseek-ai/dsh-client-ui-primitives') } catch { return null } })()
40
40
  const MarkdownText = (Primitives && typeof Primitives.MarkdownText === 'function') ? Primitives.MarkdownText : null
41
+ // Host visual primitives adopted incrementally, always with a graceful
42
+ // fallback (the shared map's contents vary by host version — the bundle
43
+ // ships ~290 exports, older type packages fewer):
44
+ // Modal — always-portaled dialog with focus trap/autofocus/restore and
45
+ // IME-composition guards (useModalLayer underneath). Its mask dismisses
46
+ // on bare click, so the DIR PICKER keeps its own press-origin-guarded
47
+ // overlay (issue #52); simple dialogs without mid-gesture re-layouts
48
+ // (PromptDialog, ConfirmDialog) adopt Modal wholesale.
49
+ // HostMenu — anchored menu with optional body portal; replaces our
50
+ // imperative-DOM context menu when present.
51
+ // useModalLayer — the focus/escape layer on its own, applied to the picker's
52
+ // custom overlay (which keeps its #52 mask guard).
53
+ // writeClipboard — replaces the scratch-textarea copy hack.
54
+ const Modal = (Primitives && typeof Primitives.Modal === 'function') ? Primitives.Modal : null
55
+ const HostMenu = (Primitives && typeof Primitives.Menu === 'function') ? Primitives.Menu : null
56
+ const useModalLayerFn = (Primitives && typeof Primitives.useModalLayer === 'function') ? Primitives.useModalLayer : null
57
+ const writeClipboardFn = (Primitives && typeof Primitives.writeClipboard === 'function') ? Primitives.writeClipboard : null
41
58
 
42
59
  // Issue #93: floating layers must PORTAL to document.body, exactly like the
43
60
  // host's own Modal/Menu (and like our context menu already does with an
@@ -284,6 +301,7 @@ window.__ModuleLoader__.load({
284
301
  'picker.setRemoteWs': '设为远程工作区',
285
302
  'picker.mirroring': '镜像中…',
286
303
  'picker.cancel': '取消',
304
+ 'confirm.title': '请确认',
287
305
  'picker.selectDir': '选择工作目录',
288
306
  'picker.selected': '所选: {path}',
289
307
  'picker.driveRoot': '(驱动器根)',
@@ -589,6 +607,7 @@ window.__ModuleLoader__.load({
589
607
  'picker.setRemoteWs': 'Set as remote workspace',
590
608
  'picker.mirroring': 'Mirroring…',
591
609
  'picker.cancel': 'Cancel',
610
+ 'confirm.title': 'Please confirm',
592
611
  'picker.selectDir': 'Select working directory',
593
612
  'picker.selected': 'Selected: {path}',
594
613
  'picker.driveRoot': ' (drive root)',
@@ -909,17 +928,39 @@ window.__ModuleLoader__.load({
909
928
  const { title, initial, placeholder, onSubmit, onCancel } = props
910
929
  const backdrop = useBackdropGuard()
911
930
  const [val, setVal] = React.useState(initial || '')
931
+ const submit = () => { const t = val.trim(); if (t) onSubmit(t) }
912
932
  React.useEffect(() => {
913
933
  try {
914
934
  if (typeof document === 'undefined') return
915
935
  const onKey = (e) => {
916
936
  if (e.key === 'Escape') { e.preventDefault(); onCancel() }
917
- if (e.key === 'Enter') { e.preventDefault(); const t = val.trim(); if (t) onSubmit(t) }
937
+ if (e.key === 'Enter') { e.preventDefault(); submit() }
918
938
  }
919
939
  document.addEventListener('keydown', onKey)
920
940
  return () => document.removeEventListener('keydown', onKey)
921
941
  } catch { return undefined }
922
942
  }, [val, onSubmit, onCancel])
943
+ // Host Modal when available: portal + focus trap + autofocus + restore +
944
+ // IME-composition guard come from its useModalLayer; our document-level
945
+ // Escape/Enter stays as the fallback path's key handling (harmless
946
+ // duplication: Modal's layer preventDefaults first).
947
+ if (Modal) {
948
+ return React.createElement(Modal, {
949
+ open: true,
950
+ onClose: onCancel,
951
+ title,
952
+ closeLabel: tr('picker.close'),
953
+ onKeyDownCapture: (e) => {
954
+ if (e.key === 'Enter' && !e.isComposing) { e.preventDefault(); submit() }
955
+ },
956
+ },
957
+ React.createElement('input', { autoFocus: true, 'data-modal-autofocus': true, value: val, onChange: (e) => setVal(e.target.value), placeholder: placeholder || '', className: 'dsh-rw-input', style: inputS }),
958
+ React.createElement('div', { style: { display: 'flex', gap: 8, justifyContent: 'flex-end', marginTop: 10 } },
959
+ React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: buttonS, onClick: onCancel }, tr('file.cancel')),
960
+ React.createElement('button', { type: 'button', className: 'dsh-rw-btn dsh-rw-primary', style: primaryBtnS, onClick: submit, disabled: !val.trim() }, tr('common.confirm')),
961
+ ),
962
+ )
963
+ }
923
964
  return React.createElement('div', {
924
965
  style: { position: 'fixed', inset: 0, zIndex: 1000000, background: 'rgba(0,0,0,0.45)', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 16 },
925
966
  onMouseDown: backdrop.onMouseDown,
@@ -942,6 +983,58 @@ window.__ModuleLoader__.load({
942
983
  )
943
984
  }
944
985
 
986
+ /**
987
+ * Themed confirm dialog. Uses the host Modal when the build ships one
988
+ * (always portaled, focus trap, autofocus, focus restore, Escape, IME
989
+ * guard); otherwise our own press-guarded portalized overlay. Either way it
990
+ * replaces `window.confirm`, which is visually alien and may be suppressed
991
+ * by embedders. Safe for Mask adoption here because the content never
992
+ * re-lays-out mid-gesture (no autocomplete list — that is why the DIRECTORY
993
+ * picker keeps its custom guarded overlay).
994
+ */
995
+ function ConfirmDialog(props) {
996
+ const { message, onAnswer } = props
997
+ const cancelBtn = React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: buttonS, onClick: () => onAnswer(false) }, tr('file.cancel'))
998
+ const okBtn = React.createElement('button', { type: 'button', className: 'dsh-rw-btn dsh-rw-primary', style: primaryBtnS, 'data-modal-autofocus': true, onClick: () => onAnswer(true) }, tr('common.confirm'))
999
+ if (Modal) {
1000
+ return React.createElement(Modal, {
1001
+ open: true,
1002
+ onClose: () => onAnswer(false),
1003
+ title: tr('confirm.title'),
1004
+ closeLabel: tr('picker.close'),
1005
+ },
1006
+ React.createElement('div', { style: { fontSize: 13, color: T.label, whiteSpace: 'pre-wrap', wordBreak: 'break-word', maxWidth: 'min(460px, 86vw)' } }, message),
1007
+ React.createElement('div', { style: { display: 'flex', gap: 8, justifyContent: 'flex-end', marginTop: 14 } }, cancelBtn, okBtn),
1008
+ )
1009
+ }
1010
+ const backdrop = useBackdropGuard()
1011
+ return portalize(React.createElement('div', {
1012
+ style: { position: 'fixed', inset: 0, zIndex: 1000001, background: 'rgba(0,0,0,0.45)', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 16 },
1013
+ onMouseDown: backdrop.onMouseDown,
1014
+ onClick: (e) => { if (backdrop.onClick(e)) onAnswer(false) },
1015
+ },
1016
+ React.createElement('div', { style: { background: v('--dsw-alias-bg-layer-1', '#18181b'), color: T.label, border: '1px solid ' + T.borderStrong, borderRadius: 12, boxShadow: '0 12px 48px rgba(0,0,0,0.5)', padding: 16, maxWidth: 'min(460px, 86vw)' }, onClick: (e) => e.stopPropagation() },
1017
+ React.createElement('div', { style: { fontSize: 13, fontWeight: 600, marginBottom: 10 } }, tr('confirm.title')),
1018
+ React.createElement('div', { style: { fontSize: 13, whiteSpace: 'pre-wrap', wordBreak: 'break-word' } }, message),
1019
+ React.createElement('div', { style: { display: 'flex', gap: 8, justifyContent: 'flex-end', marginTop: 14 } }, cancelBtn, okBtn),
1020
+ ),
1021
+ ))
1022
+ }
1023
+
1024
+ /** Promise-style confirm: `if (!(await confirm.ask(msg))) return`. Render
1025
+ * `confirm.node` anywhere in the component's tree. */
1026
+ function useConfirm() {
1027
+ const [req, setReq] = React.useState(null)
1028
+ const ask = React.useCallback((message) => new Promise((resolve) => setReq({ message, resolve })), [])
1029
+ const node = req
1030
+ ? React.createElement(ConfirmDialog, {
1031
+ message: req.message,
1032
+ onAnswer: (ok) => { setReq(null); req.resolve(ok) },
1033
+ })
1034
+ : null
1035
+ return { ask, node }
1036
+ }
1037
+
945
1038
  function humanSize(n) {
946
1039
  if (n == null) return ''
947
1040
  if (n < 1024) return n + ' B'
@@ -958,10 +1051,13 @@ window.__ModuleLoader__.load({
958
1051
  return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`
959
1052
  }
960
1053
 
961
- // Write text to the clipboard. Prefers the async Clipboard API (works on
962
- // http://127.0.0.1 secure contexts) and falls back to the legacy
963
- // execCommand('copy') path, mirroring primitives' writeClipboard semantics.
1054
+ // Write text to the clipboard. Order: the host primitive (its behavior is
1055
+ // the reference), then the async Clipboard API (works on http://127.0.0.1
1056
+ // secure contexts), then the legacy execCommand('copy') path.
964
1057
  function copyToClipboard(text) {
1058
+ if (writeClipboardFn) {
1059
+ try { return Promise.resolve(writeClipboardFn(String(text))).then(() => true).catch(() => false) } catch { /* fall through to the manual paths */ }
1060
+ }
965
1061
  if (navigator.clipboard && window.isSecureContext) {
966
1062
  return navigator.clipboard.writeText(text).then(() => true).catch(() => false)
967
1063
  }
@@ -1177,9 +1273,10 @@ window.__ModuleLoader__.load({
1177
1273
  .catch((e) => setUpdMsg(String((e && e.message) || e)))
1178
1274
  .finally(() => setUpdBusy(false))
1179
1275
  }
1180
- const applyUpdateNow = () => {
1276
+ const confirmUi = useConfirm()
1277
+ const applyUpdateNow = async () => {
1181
1278
  if (!upd || !upd.latest) return
1182
- if (!window.confirm(tr('settings.updateConfirm', { version: upd.latest }))) return
1279
+ if (!(await confirmUi.ask(tr('settings.updateConfirm', { version: upd.latest })))) return
1183
1280
  setUpdBusy(true); setUpdMsg('')
1184
1281
  api('POST', '/dsh-remote/update-apply', { version: upd.latest })
1185
1282
  .then((r) => {
@@ -1311,7 +1408,7 @@ window.__ModuleLoader__.load({
1311
1408
  // Issue #13: "active remote = none" — saved machines stay, but no machine
1312
1409
  // is current, so local sessions are never dragged into a remote context.
1313
1410
  const clearCurrent = () => { setBusy(true); api('POST', '/dsh-remote/current', { id: '' }).then((r) => { setCurrentId(''); setMsg(tr('settings.cleared')) }).catch((e) => setErr(String((e && e.message) || e))).finally(() => setBusy(false)) }
1314
- const del = (id) => { if (window.confirm(tr('settings.deleteConfirm'))) { api('POST', '/dsh-remote/machines', { action: 'delete', id }).then(refresh).then(() => setMsg(tr('settings.deleted'))).catch((e) => setErr(String((e && e.message) || e))) } }
1411
+ const del = async (id) => { if (!(await confirmUi.ask(tr('settings.deleteConfirm')))) return; api('POST', '/dsh-remote/machines', { action: 'delete', id }).then(refresh).then(() => setMsg(tr('settings.deleted'))).catch((e) => setErr(String((e && e.message) || e))) }
1315
1412
 
1316
1413
  /**
1317
1414
  * Issue #73: connect to one row of the host list.
@@ -1455,6 +1552,7 @@ window.__ModuleLoader__.load({
1455
1552
  }
1456
1553
 
1457
1554
  return React.createElement('div', { style: { padding: 16, display: 'flex', flexDirection: 'column', gap: 12, maxWidth: 860 } },
1555
+ confirmUi.node,
1458
1556
  React.createElement('div', { style: { fontSize: 16, fontWeight: 650, letterSpacing: '-0.01em' } }, tr('settings.title')),
1459
1557
  React.createElement('div', { style: { fontSize: 12, opacity: 0.8, lineHeight: 1.55 } },
1460
1558
  tr('settings.intro')),
@@ -3138,6 +3236,7 @@ window.__ModuleLoader__.load({
3138
3236
  /** Row whose path was just copied — shows a brief「已复制」label. */
3139
3237
  const [copiedPath, setCopiedPath] = React.useState('')
3140
3238
  const [namePrompt, setNamePrompt] = React.useState(null) // { kind, path, name }
3239
+ const confirmUi = useConfirm()
3141
3240
  React.useEffect(() => { ensureChromeCss() }, [])
3142
3241
  const expanded = Array.isArray(props.expanded) ? props.expanded : []
3143
3242
  const scopeCwd = props.scope && props.scope.cwd
@@ -3267,10 +3366,22 @@ window.__ModuleLoader__.load({
3267
3366
  React.useEffect(() => {
3268
3367
  if (root && typeof props.evictStray === 'function') props.evictStray(root)
3269
3368
  }, [root, props.evictStray])
3369
+ /** Shared dispatch for the context menu (host Menu or the DOM fallback). */
3370
+ const runMenuAction = (id, m) => {
3371
+ if (!m) return
3372
+ if (id === 'open') { if (m.isDir) { if (props.onToggleDir) props.onToggleDir(m.path) } else openFile(m.path); return }
3373
+ if (id === 'download') { doFs('download', { path: m.path }); return }
3374
+ if (id === 'copy-rel') { copyPath(relPath(m.path), m.path); return }
3375
+ if (id === 'copy-abs') { copyPath(m.path, m.path); return }
3376
+ if (id === 'rename') { setNamePrompt({ kind: 'rename', path: m.path, name: m.name }); return }
3377
+ if (id === 'delete') { confirmUi.ask(tr('explorer.deleteConfirm', { path: m.path })).then((ok) => { if (ok) doFs('remove', { path: m.path }, true) }) }
3378
+ }
3270
3379
  // ── Context-menu portal: append to document.body so the sidebar's
3271
3380
  // overflow/transform cannot clip it. Pure DOM, no React portal needed.
3381
+ // Only the FALLBACK when the host ships no Menu primitive: the main
3382
+ // path renders HostMenu (anchored, body-portaled, keyboard-navigable).
3272
3383
  React.useEffect(() => {
3273
- if (!menu) return
3384
+ if (!menu || HostMenu) return
3274
3385
  const host = document.createElement('div')
3275
3386
  host.style.cssText = 'position:fixed;z-index:999999;pointer-events:auto'
3276
3387
  const box = document.createElement('div')
@@ -3284,19 +3395,21 @@ window.__ModuleLoader__.load({
3284
3395
  d.addEventListener('click', (e) => { e.stopPropagation(); setMenu(null); fn() })
3285
3396
  return d
3286
3397
  }
3287
- box.appendChild(mkItem(menu.isDir ? tr('explorer.menuExpand') : tr('explorer.menuOpen'), false, () => { if (menu.isDir) { if (props.onToggleDir) props.onToggleDir(menu.path) } else openFile(menu.path) }))
3288
- box.appendChild(mkItem(tr('explorer.menuDownload'), false, () => doFs('download', { path: menu.path })))
3289
- box.appendChild(mkItem(tr('explorer.menuCopyRel'), false, () => copyPath(relPath(menu.path), menu.path)))
3290
- box.appendChild(mkItem(tr('explorer.menuCopyAbs'), false, () => copyPath(menu.path, menu.path)))
3291
- box.appendChild(mkItem(tr('explorer.menuRename'), false, () => { setNamePrompt({ kind: 'rename', path: menu.path, name: menu.name }) }))
3292
- box.appendChild(mkItem(menu.isDir ? tr('explorer.menuDeleteDir') : tr('explorer.menuDelete'), true, () => { if (window.confirm(tr('explorer.deleteConfirm', { path: menu.path }))) doFs('remove', { path: menu.path }, true) }))
3398
+ box.appendChild(mkItem(menu.isDir ? tr('explorer.menuExpand') : tr('explorer.menuOpen'), false, () => runMenuAction('open', menu)))
3399
+ box.appendChild(mkItem(tr('explorer.menuDownload'), false, () => runMenuAction('download', menu)))
3400
+ box.appendChild(mkItem(tr('explorer.menuCopyRel'), false, () => runMenuAction('copy-rel', menu)))
3401
+ box.appendChild(mkItem(tr('explorer.menuCopyAbs'), false, () => runMenuAction('copy-abs', menu)))
3402
+ box.appendChild(mkItem(tr('explorer.menuRename'), false, () => runMenuAction('rename', menu)))
3403
+ box.appendChild(mkItem(menu.isDir ? tr('explorer.menuDeleteDir') : tr('explorer.menuDelete'), true, () => runMenuAction('delete', menu)))
3293
3404
  host.appendChild(box)
3294
3405
  document.body.appendChild(host)
3295
3406
  const close = (e) => { if (!box.contains(e.target)) { setMenu(null) } }
3296
3407
  // Delay adding listener so the same mousedown that opened the menu doesn't close it
3297
3408
  const tid = setTimeout(() => document.addEventListener('mousedown', close), 0)
3298
3409
  return () => { clearTimeout(tid); document.removeEventListener('mousedown', close); host.remove() }
3299
- }, [menu])
3410
+ // confirmUi.ask is stable (useCallback); depending on the wrapper object
3411
+ // would rebuild the menu DOM on every render.
3412
+ }, [menu, confirmUi.ask])
3300
3413
 
3301
3414
  // Open one remote file. The viewer is a RESOURCE tab type: the address
3302
3415
  // names the file, and the HOST's tab registry picks the type that claims
@@ -3485,8 +3598,24 @@ window.__ModuleLoader__.load({
3485
3598
  rootLevel && rootOpen ? renderLevel(root, 1) : null,
3486
3599
  ),
3487
3600
  ),
3488
- // context menu — now rendered via DOM portal in useEffect above
3489
- null,
3601
+ // context menu — host Menu primitive when available (anchored at the
3602
+ // pointer, body-portaled), otherwise the DOM portal in the effect above
3603
+ menu && HostMenu ? React.createElement(HostMenu, {
3604
+ open: true,
3605
+ portal: true,
3606
+ getAnchorRect: () => ({ left: menu.x, top: menu.y, right: menu.x, bottom: menu.y, width: 0, height: 0 }),
3607
+ items: [
3608
+ { id: 'open', label: menu.isDir ? tr('explorer.menuExpand') : tr('explorer.menuOpen') },
3609
+ { id: 'download', label: tr('explorer.menuDownload') },
3610
+ { id: 'copy-rel', label: tr('explorer.menuCopyRel') },
3611
+ { id: 'copy-abs', label: tr('explorer.menuCopyAbs') },
3612
+ { id: 'rename', label: tr('explorer.menuRename') },
3613
+ { id: 'delete', label: menu.isDir ? tr('explorer.menuDeleteDir') : tr('explorer.menuDelete'), danger: true },
3614
+ ],
3615
+ onSelect: (id) => { const m = menu; setMenu(null); runMenuAction(id, m) },
3616
+ onClose: () => setMenu(null),
3617
+ }) : null,
3618
+ confirmUi.node,
3490
3619
  err ? React.createElement('div', { style: { color: T.danger, fontSize: 12, padding: '4px 8px' } }, (busy ? tr('explorer.busy') : '') + err) : null,
3491
3620
  namePrompt ? React.createElement(PromptDialog, {
3492
3621
  title: namePrompt.kind === 'rename' ? tr('explorer.renameTitle') : tr('explorer.mkdirTitle'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-remote",
3
- "version": "0.8.76",
3
+ "version": "0.8.77",
4
4
  "description": "Remote-work assistant for DeepSeek Harness: connect SSH (password/key/agent/keyboard-interactive, multi-hop ProxyJump), list hosts from ~/.ssh/config, pick a remote workspace, operate on it with 21 rw_* tools, conflict-aware mirror sync, an embedded PTY terminal, remote DSH web UI attach, port forwarding, host grouping, remote sandbox fencing, audit log, keychain passwords.",
5
5
  "license": "MIT",
6
6
  "author": "flymysql <flyphp@outlook.com>",