@lijian-ui/dsh-file-manager 0.1.20

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 (169) hide show
  1. package/LICENSE +38 -0
  2. package/README.i18n.yaml +6 -0
  3. package/README.md +66 -0
  4. package/README.zh.md +66 -0
  5. package/cordis.patch.yml +13 -0
  6. package/lib/assets/mermaid.min.js +3587 -0
  7. package/lib/client.js +7621 -0
  8. package/lib/client.js.map +1 -0
  9. package/lib/index.js +3207 -0
  10. package/lib/tsconfig.client.tsbuildinfo +1 -0
  11. package/lib/tsconfig.host.tsbuildinfo +1 -0
  12. package/lib/types/client/FileManagerSettingsCard.d.ts +56 -0
  13. package/lib/types/client/FileManagerSettingsCard.d.ts.map +1 -0
  14. package/lib/types/client/PluginSettingsCard.d.ts +104 -0
  15. package/lib/types/client/PluginSettingsCard.d.ts.map +1 -0
  16. package/lib/types/client/api.d.ts +75 -0
  17. package/lib/types/client/api.d.ts.map +1 -0
  18. package/lib/types/client/chat/AttachedFilesDock.d.ts +51 -0
  19. package/lib/types/client/chat/AttachedFilesDock.d.ts.map +1 -0
  20. package/lib/types/client/chat/file-ref.d.ts +35 -0
  21. package/lib/types/client/chat/file-ref.d.ts.map +1 -0
  22. package/lib/types/client/chat/mermaid-chat.d.ts +30 -0
  23. package/lib/types/client/chat/mermaid-chat.d.ts.map +1 -0
  24. package/lib/types/client/chat/placeholder-hint.d.ts +16 -0
  25. package/lib/types/client/chat/placeholder-hint.d.ts.map +1 -0
  26. package/lib/types/client/components/ExplorerPanel.d.ts +26 -0
  27. package/lib/types/client/components/ExplorerPanel.d.ts.map +1 -0
  28. package/lib/types/client/components/FileIcon.d.ts +15 -0
  29. package/lib/types/client/components/FileIcon.d.ts.map +1 -0
  30. package/lib/types/client/components/ScmPanel.d.ts +23 -0
  31. package/lib/types/client/components/ScmPanel.d.ts.map +1 -0
  32. package/lib/types/client/components/a11y.d.ts +12 -0
  33. package/lib/types/client/components/a11y.d.ts.map +1 -0
  34. package/lib/types/client/components/icons.d.ts +41 -0
  35. package/lib/types/client/components/icons.d.ts.map +1 -0
  36. package/lib/types/client/components/overlay.d.ts +45 -0
  37. package/lib/types/client/components/overlay.d.ts.map +1 -0
  38. package/lib/types/client/drag/DragFileInlay.d.ts +31 -0
  39. package/lib/types/client/drag/DragFileInlay.d.ts.map +1 -0
  40. package/lib/types/client/drag/file-drag.d.ts +47 -0
  41. package/lib/types/client/drag/file-drag.d.ts.map +1 -0
  42. package/lib/types/client/drag.d.ts +31 -0
  43. package/lib/types/client/drag.d.ts.map +1 -0
  44. package/lib/types/client/file-source.d.ts +29 -0
  45. package/lib/types/client/file-source.d.ts.map +1 -0
  46. package/lib/types/client/fileType.d.ts +31 -0
  47. package/lib/types/client/fileType.d.ts.map +1 -0
  48. package/lib/types/client/floating.d.ts +27 -0
  49. package/lib/types/client/floating.d.ts.map +1 -0
  50. package/lib/types/client/hooks/useResizableSplit.d.ts +37 -0
  51. package/lib/types/client/hooks/useResizableSplit.d.ts.map +1 -0
  52. package/lib/types/client/hooks/useStore.d.ts +10 -0
  53. package/lib/types/client/hooks/useStore.d.ts.map +1 -0
  54. package/lib/types/client/index.d.ts +57 -0
  55. package/lib/types/client/index.d.ts.map +1 -0
  56. package/lib/types/client/layout.d.ts +104 -0
  57. package/lib/types/client/layout.d.ts.map +1 -0
  58. package/lib/types/client/locales.d.ts +125 -0
  59. package/lib/types/client/locales.d.ts.map +1 -0
  60. package/lib/types/client/maximize.d.ts +24 -0
  61. package/lib/types/client/maximize.d.ts.map +1 -0
  62. package/lib/types/client/mention.d.ts +44 -0
  63. package/lib/types/client/mention.d.ts.map +1 -0
  64. package/lib/types/client/mount.d.ts +22 -0
  65. package/lib/types/client/mount.d.ts.map +1 -0
  66. package/lib/types/client/persist.d.ts +55 -0
  67. package/lib/types/client/persist.d.ts.map +1 -0
  68. package/lib/types/client/picker/FilePickerModal.d.ts +47 -0
  69. package/lib/types/client/picker/FilePickerModal.d.ts.map +1 -0
  70. package/lib/types/client/picker/file-picker.d.ts +62 -0
  71. package/lib/types/client/picker/file-picker.d.ts.map +1 -0
  72. package/lib/types/client/preview/PreviewPanel.d.ts +17 -0
  73. package/lib/types/client/preview/PreviewPanel.d.ts.map +1 -0
  74. package/lib/types/client/preview/PreviewTabs.d.ts +30 -0
  75. package/lib/types/client/preview/PreviewTabs.d.ts.map +1 -0
  76. package/lib/types/client/preview/PreviewToolbar.d.ts +37 -0
  77. package/lib/types/client/preview/PreviewToolbar.d.ts.map +1 -0
  78. package/lib/types/client/preview/content.d.ts +43 -0
  79. package/lib/types/client/preview/content.d.ts.map +1 -0
  80. package/lib/types/client/preview/markdown.d.ts +60 -0
  81. package/lib/types/client/preview/markdown.d.ts.map +1 -0
  82. package/lib/types/client/preview/mermaid.d.ts +78 -0
  83. package/lib/types/client/preview/mermaid.d.ts.map +1 -0
  84. package/lib/types/client/preview/selection.d.ts +26 -0
  85. package/lib/types/client/preview/selection.d.ts.map +1 -0
  86. package/lib/types/client/reference.d.ts +75 -0
  87. package/lib/types/client/reference.d.ts.map +1 -0
  88. package/lib/types/client/settings-form.d.ts +206 -0
  89. package/lib/types/client/settings-form.d.ts.map +1 -0
  90. package/lib/types/client/store.d.ts +279 -0
  91. package/lib/types/client/store.d.ts.map +1 -0
  92. package/lib/types/core/types.d.ts +132 -0
  93. package/lib/types/core/types.d.ts.map +1 -0
  94. package/lib/types/host/fs-service.d.ts +96 -0
  95. package/lib/types/host/fs-service.d.ts.map +1 -0
  96. package/lib/types/host/gate.d.ts +45 -0
  97. package/lib/types/host/gate.d.ts.map +1 -0
  98. package/lib/types/host/git-runner.d.ts +80 -0
  99. package/lib/types/host/git-runner.d.ts.map +1 -0
  100. package/lib/types/host/git-service.d.ts +130 -0
  101. package/lib/types/host/git-service.d.ts.map +1 -0
  102. package/lib/types/host/loopback.d.ts +25 -0
  103. package/lib/types/host/loopback.d.ts.map +1 -0
  104. package/lib/types/host/poll-guard.d.ts +55 -0
  105. package/lib/types/host/poll-guard.d.ts.map +1 -0
  106. package/lib/types/host/routes.d.ts +54 -0
  107. package/lib/types/host/routes.d.ts.map +1 -0
  108. package/lib/types/index.d.ts +35 -0
  109. package/lib/types/index.d.ts.map +1 -0
  110. package/lib/types/mount-once.d.ts +25 -0
  111. package/lib/types/mount-once.d.ts.map +1 -0
  112. package/package.json +85 -0
  113. package/src/client/FileManagerSettingsCard.tsx +117 -0
  114. package/src/client/PluginSettingsCard.tsx +337 -0
  115. package/src/client/api.ts +141 -0
  116. package/src/client/chat/file-ref.ts +144 -0
  117. package/src/client/chat/mermaid-chat.tsx +102 -0
  118. package/src/client/chat/placeholder-hint.tsx +46 -0
  119. package/src/client/components/ExplorerPanel.tsx +534 -0
  120. package/src/client/components/FileIcon.tsx +46 -0
  121. package/src/client/components/ScmPanel.tsx +480 -0
  122. package/src/client/components/a11y.ts +20 -0
  123. package/src/client/components/icons.tsx +274 -0
  124. package/src/client/components/overlay.tsx +225 -0
  125. package/src/client/css-modules.d.ts +5 -0
  126. package/src/client/drag/DragFileInlay.tsx +89 -0
  127. package/src/client/drag/file-drag.ts +67 -0
  128. package/src/client/drag.ts +154 -0
  129. package/src/client/file-source.ts +58 -0
  130. package/src/client/fileType.ts +129 -0
  131. package/src/client/floating.ts +63 -0
  132. package/src/client/hooks/useResizableSplit.ts +91 -0
  133. package/src/client/hooks/useStore.ts +15 -0
  134. package/src/client/index.ts +389 -0
  135. package/src/client/layout.ts +546 -0
  136. package/src/client/locales.ts +247 -0
  137. package/src/client/maximize.ts +34 -0
  138. package/src/client/mount.tsx +74 -0
  139. package/src/client/persist.ts +194 -0
  140. package/src/client/picker/FilePickerModal.tsx +506 -0
  141. package/src/client/picker/file-picker.ts +86 -0
  142. package/src/client/preview/PreviewPanel.tsx +233 -0
  143. package/src/client/preview/PreviewTabs.tsx +159 -0
  144. package/src/client/preview/PreviewToolbar.tsx +160 -0
  145. package/src/client/preview/content.tsx +617 -0
  146. package/src/client/preview/markdown.ts +351 -0
  147. package/src/client/preview/mermaid.ts +274 -0
  148. package/src/client/preview/selection.ts +82 -0
  149. package/src/client/reference.ts +161 -0
  150. package/src/client/settings-card.module.css +316 -0
  151. package/src/client/settings-form.ts +451 -0
  152. package/src/client/store.ts +1290 -0
  153. package/src/client/styles/chip.module.css +38 -0
  154. package/src/client/styles/drag.module.css +30 -0
  155. package/src/client/styles/explorer.module.css +371 -0
  156. package/src/client/styles/picker.module.css +344 -0
  157. package/src/client/styles/preview.module.css +904 -0
  158. package/src/client/styles/scm.module.css +380 -0
  159. package/src/client/styles/tokens.module.css +480 -0
  160. package/src/core/types.ts +162 -0
  161. package/src/host/fs-service.ts +513 -0
  162. package/src/host/gate.ts +74 -0
  163. package/src/host/git-runner.ts +116 -0
  164. package/src/host/git-service.ts +395 -0
  165. package/src/host/loopback.ts +63 -0
  166. package/src/host/poll-guard.ts +109 -0
  167. package/src/host/routes.ts +695 -0
  168. package/src/index.ts +97 -0
  169. package/src/mount-once.ts +48 -0
package/package.json ADDED
@@ -0,0 +1,85 @@
1
+ {
2
+ "name": "@lijian-ui/dsh-file-manager",
3
+ "description": "DSH web GUI right-panel system: a pixel-faithful re-implementation of FileManager's Explorer + Preview columns (file tree, filename search, git changes, multi-tab preview of 10+ formats) driven by real host-side fs/git services, hot-pluggable via a profile bundle without any dsh source changes",
4
+ "version": "0.1.20",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "types": "lib/types/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./lib/types/index.d.ts",
11
+ "default": "./lib/index.js"
12
+ },
13
+ "./client": {
14
+ "types": "./lib/types/client/index.d.ts",
15
+ "default": "./lib/client.js"
16
+ },
17
+ "./src/*": "./src/*",
18
+ "./package.json": "./package.json"
19
+ },
20
+ "dsh": {
21
+ "bundle": {
22
+ "patch": "./cordis.patch.yml"
23
+ },
24
+ "client": {
25
+ "inject": [
26
+ "@deepseek-ai/dsh-client-runtime",
27
+ "@deepseek-ai/dsh-client-locale",
28
+ "@deepseek-ai/dsh-client-ui-conversation",
29
+ "@deepseek-ai/dsh-client-ui-settings",
30
+ "@deepseek-ai/dsh-client-ui-input-trigger"
31
+ ],
32
+ "platform": "web"
33
+ }
34
+ },
35
+ "scripts": {
36
+ "build": "tsc -b && node scripts/copy-mermaid.mjs && tsdown",
37
+ "prepare": "node scripts/copy-mermaid.mjs && tsdown",
38
+ "watch": "tsdown --watch",
39
+ "test": "vitest run",
40
+ "typecheck": "tsc -b --pretty false"
41
+ },
42
+ "peerDependencies": {
43
+ "react": "^18.2.0"
44
+ },
45
+ "devDependencies": {
46
+ "@deepseek-ai/cordis": "^4.0.1",
47
+ "@deepseek-ai/dsh-client-locale": "^0.1.0-rc.6",
48
+ "@deepseek-ai/dsh-client-runtime": "^0.1.0-rc.6",
49
+ "@deepseek-ai/dsh-client-ui-conversation": "^0.1.0-rc.6",
50
+ "@deepseek-ai/dsh-client-ui-primitives": "^0.1.0-rc.6",
51
+ "@deepseek-ai/dsh-client-ui-settings": "^0.1.0-rc.6",
52
+ "@deepseek-ai/dsh-client-ui-input-trigger": "^0.1.0-rc.6",
53
+ "@deepseek-ai/dsh-client-ui-slots": "^0.1.0-rc.6",
54
+ "@deepseek-ai/dsh-host-webserver": "^0.1.0-rc.6",
55
+ "@deepseek-ai/dsh-settings": "^0.1.0-rc.6",
56
+ "@deepseek-ai/dsh-subprocess": "^0.1.0-rc.6",
57
+ "@deepseek-ai/dsh-system-prompt": "^0.1.0-rc.6",
58
+ "@deepseek-ai/dsh-workspace": "^0.1.0-rc.6",
59
+ "schemastery": "^3.18.0",
60
+ "@types/node": "^22.20.0",
61
+ "@types/react": "~18.3.1",
62
+ "@types/react-dom": "^18.3.5",
63
+ "jsdom": "29.1.1",
64
+ "lightningcss": "^1.32.0",
65
+ "react": "^18.3.1",
66
+ "react-dom": "^18.3.1",
67
+ "tsdown": "0.22.2",
68
+ "typescript": "~5.7.2",
69
+ "vite-tsconfig-paths": "^6.1.1",
70
+ "vitest": "^4.1.8",
71
+ "mermaid": "11.16.1"
72
+ },
73
+ "files": [
74
+ "lib",
75
+ "src",
76
+ "cordis.patch.yml",
77
+ "README.md",
78
+ "README.zh.md"
79
+ ],
80
+ "license": "Apache-2.0",
81
+ "repository": {
82
+ "type": "git",
83
+ "url": "https://github.com/zhu1090093659/dsh-web-ui.git"
84
+ }
85
+ }
@@ -0,0 +1,117 @@
1
+ /**
2
+ * The filemgr settings card: the total on/off switch (issue #307).
3
+ * Registers into the `web-ui.plugin.item` slot the Web UI Plugins group
4
+ * renders, bound to the `filemgr` settings namespace through the family
5
+ * settings bridge (or the official settings scope when the deployment exposes
6
+ * the namespace directly). Turning the panel off unmounts the right-panel
7
+ * columns, the floating expand button, the /filemgr/* routes and the
8
+ * workspace fs watch + git polling behind them.
9
+ * @module @lijian-ui/dsh-file-manager/client/FileManagerSettingsCard
10
+ */
11
+
12
+ import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'
13
+ import type { SettingsScope, SnapshotStore } from '@deepseek-ai/dsh-client-runtime/client'
14
+ import { PluginSettingsCard, BooleanField } from './PluginSettingsCard.tsx'
15
+ import { CardForm, booleanField, type CardActions, type CardShell, type FieldState as CardFieldState } from './settings-form.ts'
16
+
17
+ /** The filemgr fields this card edits (the namespace's full schema). */
18
+ export interface FileManagerPanelSettings {
19
+ /** Whether the right-panel system (columns, floating button, routes, watch/polling) is mounted at all; default on. */
20
+ enabled?: boolean
21
+ }
22
+
23
+ /** What the filemgr card renders. */
24
+ export interface FileManagerSettingsCardState extends CardShell {
25
+ enabled: CardFieldState
26
+ }
27
+
28
+ /** The registration-side face the card's slot entry injects. */
29
+ export interface FileManagerSettingsCardFace extends CardActions {
30
+ hooks: {
31
+ /** Card snapshot bound by the renderer as useFilemgrSettingsCard. */
32
+ filemgrSettingsCard: SnapshotStore<FileManagerSettingsCardState>
33
+ }
34
+ }
35
+
36
+ /** Bridges the `filemgr` scope onto the card's staged form. */
37
+ export class FileManagerSettingsCardController {
38
+ private readonly form: CardForm<FileManagerPanelSettings>
39
+ private readonly store: SnapshotStore<FileManagerSettingsCardState>
40
+
41
+ /** @param scope - the bound settings scope for the `filemgr` namespace. */
42
+ constructor(scope: SettingsScope<FileManagerPanelSettings>) {
43
+ this.form = new CardForm(scope, [
44
+ booleanField('enabled'),
45
+ ])
46
+ this.store = this.form.bind(() => this.projection())
47
+ }
48
+
49
+ private projection(): FileManagerSettingsCardState {
50
+ return {
51
+ ...this.form.shell(),
52
+ enabled: this.form.field('enabled'),
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Build the face the card's slot registration injects.
58
+ * @returns the card's snapshot and its form actions.
59
+ */
60
+ inject(): FileManagerSettingsCardFace {
61
+ return { hooks: { filemgrSettingsCard: this.store }, ...this.form.actions() }
62
+ }
63
+
64
+ /**
65
+ * Release the card's scope subscription and bound stores; the slot
66
+ * disposer calls this on teardown.
67
+ */
68
+ dispose(): void {
69
+ this.form.dispose()
70
+ }
71
+ }
72
+
73
+ /** Props the renderer binds for the filemgr card. */
74
+ export type FileManagerSettingsCardProps =
75
+ PropsRuntime<'web-ui.plugin.item'>
76
+ & PropsLocale<'filemgr'>
77
+ & InjectFace<FileManagerSettingsCardFace>
78
+
79
+ /**
80
+ * Render the filemgr card.
81
+ * @param props - locale copy, the card snapshot, and its form actions.
82
+ * @returns the card.
83
+ */
84
+ export function FileManagerSettingsCard(props: FileManagerSettingsCardProps) {
85
+ const { t } = props
86
+ const state = props.useFilemgrSettingsCard(snapshot => snapshot)
87
+ const disabled = !state.writable
88
+ const fieldProps = {
89
+ overriddenLabel: t('settings.overridden'),
90
+ resetLabel: t('settings.reset'),
91
+ invalidLabel: t('settings.invalidNumber'),
92
+ disabled,
93
+ }
94
+ return (
95
+ <PluginSettingsCard
96
+ t={t}
97
+ titleKey="settings.title"
98
+ descriptionKey="settings.description"
99
+ state={state}
100
+ onSave={props.save}
101
+ onDiscard={props.discard}
102
+ >
103
+ <BooleanField
104
+ id="settings-filemgr-enabled"
105
+ label={t('settings.enabled')}
106
+ hint={t('settings.enabledHint')}
107
+ inheritLabel={t('settings.inherit')}
108
+ onLabel={t('settings.on')}
109
+ offLabel={t('settings.off')}
110
+ {...fieldProps}
111
+ {...state.enabled}
112
+ onEdit={(text) => { props.edit('enabled', text) }}
113
+ onReset={() => { props.resetField('enabled') }}
114
+ />
115
+ </PluginSettingsCard>
116
+ )
117
+ }
@@ -0,0 +1,337 @@
1
+ // Generated by scripts/sync-shared.mjs from shared/client/settings/PluginSettingsCard.tsx. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
2
+ /**
3
+ * Family-shared chrome for plugin settings cards: a disclosure header naming
4
+ * the plugin and what its settings govern, the controls inside, and the save
5
+ * that writes them. Renders nothing while the namespace is unavailable — a
6
+ * deployment that does not compose the owning plugin should show no trace of
7
+ * it. Inlined into each consumer's client bundle; mirrors the official
8
+ * ui-plugin-config PluginCard in a self-contained slice.
9
+ */
10
+
11
+ import { useState, type ReactNode } from 'react'
12
+ import type { CardShell } from './settings-form.ts'
13
+ import css from './settings-card.module.css'
14
+
15
+ /** Copy keys the card chrome itself reads; every consumer locale carries this shared vocabulary. */
16
+ export const CARD_COPY_KEYS = [
17
+ 'settings.collapse',
18
+ 'settings.expand',
19
+ 'settings.notExposed',
20
+ 'settings.unsaved',
21
+ 'settings.readOnly',
22
+ 'settings.saveFailed',
23
+ 'settings.discard',
24
+ 'settings.save',
25
+ 'settings.saving',
26
+ ] as const
27
+
28
+ /** Copy key the card chrome itself reads. */
29
+ export type CardCopyKey = (typeof CARD_COPY_KEYS)[number]
30
+
31
+ /** Key domain for the plugin's own copy (inferred per consumer). */
32
+ export type SettingsCardKey<TKey extends string = string> = TKey | CardCopyKey
33
+
34
+ /** Card chrome shared by every plugin settings card. */
35
+ export interface PluginSettingsCardProps<TKey extends string = string> {
36
+ /** Locale reader for this card's copy. */
37
+ t: (key: SettingsCardKey<TKey>, params?: Record<string, string | number>) => string
38
+ /** Locale key of the plugin's name. */
39
+ titleKey: TKey
40
+ /** Locale key of the line describing what this plugin's settings govern. */
41
+ descriptionKey: TKey
42
+ /** The card's form state: availability, writability, and what a save would do. */
43
+ state: CardShell
44
+ /** Write every staged edit. */
45
+ onSave: () => void
46
+ /** Drop every staged edit. */
47
+ onDiscard: () => void
48
+ /**
49
+ * Render the controls expanded on arrival (still collapsible). Defaults to
50
+ * true: promoted first-level sections show their settings immediately.
51
+ */
52
+ defaultOpen?: boolean
53
+ /**
54
+ * Render without the collapse affordance: a static header and an always
55
+ * visible body. Used by first-level settings sections whose nav entry
56
+ * already provides the selection.
57
+ */
58
+ alwaysOpen?: boolean
59
+ /** The plugin's controls. */
60
+ children: ReactNode
61
+ }
62
+
63
+ /**
64
+ * Render one plugin settings card.
65
+ * @param props - the plugin's copy keys, its form state, and its controls.
66
+ * @returns the card, or nothing while the namespace is still loading.
67
+ */
68
+ export function PluginSettingsCard<TKey extends string = string>(props: PluginSettingsCardProps<TKey>) {
69
+ const [open, setOpen] = useState(props.defaultOpen ?? true)
70
+ const { state, alwaysOpen } = props
71
+ if (!state.available) return null
72
+ const title = props.t(props.titleKey)
73
+ const description = props.t(props.descriptionKey)
74
+ const blocked = !state.dirty || state.invalid || state.saving
75
+ const expanded = alwaysOpen === true || open
76
+ const cardClass = expanded ? `${css.cardOpen} ${css.card}` : css.card
77
+ // With alwaysOpen the nav entry already provides the selection, so the
78
+ // header is a static title row instead of a disclosure button.
79
+ const header = alwaysOpen === true
80
+ ? (
81
+ <div className={css.headerStatic}>
82
+ <span className={css.headText}>
83
+ <span className={css.name} title={title}>{title}</span>
84
+ <span className={css.description} title={description}>{description}</span>
85
+ </span>
86
+ {state.dirty ? <span className={css.pending} title={props.t('settings.unsaved')}>{props.t('settings.unsaved')}</span> : null}
87
+ </div>
88
+ )
89
+ : (
90
+ <button
91
+ type="button"
92
+ className={css.header}
93
+ aria-expanded={open}
94
+ aria-label={`${props.t(open ? 'settings.collapse' : 'settings.expand')}: ${title}`}
95
+ onClick={() => { setOpen(!open) }}
96
+ >
97
+ <span className={css.headText}>
98
+ <span className={css.name} title={title}>{title}</span>
99
+ <span className={css.description} title={description}>{description}</span>
100
+ </span>
101
+ {state.dirty ? <span className={css.pending} title={props.t('settings.unsaved')}>{props.t('settings.unsaved')}</span> : null}
102
+ <svg
103
+ width="14"
104
+ height="14"
105
+ viewBox="0 0 14 14"
106
+ fill="none"
107
+ xmlns="http://www.w3.org/2000/svg"
108
+ className={open ? `${css.chevron} ${css.chevronOpen}` : css.chevron}
109
+ >
110
+ <path
111
+ d="M11.8486 5.5L11.4238 5.92383L8.69727 8.65137C8.44157 8.90706 8.21562 9.13382 8.01172 9.29785C7.79912 9.46883 7.55595 9.61756 7.25 9.66602C7.08435 9.69222 6.91565 9.69222 6.75 9.66602C6.44405 9.61756 6.20088 9.46883 5.98828 9.29785C5.78438 9.13382 5.55843 8.90706 5.30273 8.65137L2.57617 5.92383L2.15137 5.5L3 4.65137L3.42383 5.07617L6.15137 7.80273C6.42595 8.07732 6.59876 8.24849 6.74023 8.3623C6.87291 8.46904 6.92272 8.47813 6.9375 8.48047C6.97895 8.48703 7.02105 8.48703 7.0625 8.48047C7.07728 8.47813 7.12709 8.46904 7.25977 8.3623C7.40124 8.24849 7.57405 8.07732 7.84863 7.80273L10.5762 5.07617L11 4.65137L11.8486 5.5Z"
112
+ fill="currentColor"
113
+ />
114
+ </svg>
115
+ </button>
116
+ )
117
+ // The namespace exists but the Host does not serve it to this client (the
118
+ // official settings allowlist omits third-party namespaces): show a card
119
+ // that explains the gap instead of vanishing, so a missing card never
120
+ // reads as a missing plugin.
121
+ if (!state.exposed) {
122
+ return (
123
+ <li className={cardClass}>
124
+ {header}
125
+ {expanded
126
+ ? (
127
+ <div className={css.body}>
128
+ <p className={css.notExposed} role="status">{props.t('settings.notExposed')}</p>
129
+ </div>
130
+ )
131
+ : null}
132
+ </li>
133
+ )
134
+ }
135
+ return (
136
+ <li className={cardClass}>
137
+ {header}
138
+ {expanded
139
+ ? (
140
+ <div className={css.body}>
141
+ {!state.writable ? <p className={css.readOnly} role="status">{props.t('settings.readOnly')}</p> : null}
142
+ {props.children}
143
+ <div className={css.footer}>
144
+ {state.failed
145
+ ? (
146
+ <p className={css.failed} role="status">
147
+ {props.t('settings.saveFailed')}{state.failedReason ? ' - ' + state.failedReason : ''}
148
+ </p>
149
+ )
150
+ : null}
151
+ <button
152
+ type="button"
153
+ className={css.discard}
154
+ disabled={!state.dirty || state.saving}
155
+ onClick={props.onDiscard}
156
+ >
157
+ {props.t('settings.discard')}
158
+ </button>
159
+ <button
160
+ type="button"
161
+ className={css.save}
162
+ disabled={blocked}
163
+ onClick={props.onSave}
164
+ >
165
+ {props.t(!state.saving ? 'settings.save' : 'settings.saving')}
166
+ </button>
167
+ </div>
168
+ </div>
169
+ )
170
+ : null}
171
+ </li>
172
+ )
173
+ }
174
+
175
+ /** Props every field control needs regardless of its value type. */
176
+ export interface FieldProps {
177
+ /** Stable id associating the label with its control. */
178
+ id: string
179
+ /** Visible label. */
180
+ label: string
181
+ /** One-line explanation rendered under the control. */
182
+ hint: string
183
+ /** Draft text this control renders. */
184
+ text: string
185
+ /** True when saving would leave a user-layer entry for this field. */
186
+ overridden: boolean
187
+ /** True when the draft is not a value this field accepts. */
188
+ invalid: boolean
189
+ /** Copy for the overridden badge. */
190
+ overriddenLabel: string
191
+ /** Copy for the reset control. */
192
+ resetLabel: string
193
+ /** Copy shown in place of the hint while the draft is invalid. */
194
+ invalidLabel: string
195
+ /** Disables every control (read-only document, or an unavailable namespace). */
196
+ disabled: boolean
197
+ /** Stage draft text. */
198
+ onEdit: (text: string) => void
199
+ /** Stage a clear so the field re-inherits the composition layer. */
200
+ onReset: () => void
201
+ }
202
+
203
+ /** A staged value field. `numeric` only hints the keypad: which drafts a field accepts is decided by its spec. */
204
+ export function ValueField(props: FieldProps & {
205
+ /** Hints a numeric keypad without narrowing what the control accepts. */
206
+ numeric?: boolean
207
+ /** Placeholder shown while the draft is empty. */
208
+ placeholder?: string
209
+ }) {
210
+ return (
211
+ <div className={css.field}>
212
+ <div className={css.head}>
213
+ <label className={css.label} htmlFor={props.id}>{props.label}</label>
214
+ {props.overridden
215
+ ? (
216
+ <span className={css.badges}>
217
+ <span className={css.badge}>{props.overriddenLabel}</span>
218
+ <button
219
+ type="button"
220
+ className={css.reset}
221
+ disabled={props.disabled}
222
+ onClick={props.onReset}
223
+ >
224
+ {props.resetLabel}
225
+ </button>
226
+ </span>
227
+ )
228
+ : null}
229
+ </div>
230
+ <input
231
+ id={props.id}
232
+ className={props.invalid ? css.inputInvalid : css.input}
233
+ type="text"
234
+ {...props.numeric === true ? { inputMode: 'numeric' as const } : {}}
235
+ {...props.invalid ? { 'aria-invalid': true } : {}}
236
+ value={props.text}
237
+ placeholder={props.placeholder ?? ''}
238
+ disabled={props.disabled}
239
+ onChange={(event) => { props.onEdit(event.target.value) }}
240
+ />
241
+ <p className={props.invalid ? css.invalid : css.hint}>
242
+ {props.invalid ? props.invalidLabel : props.hint}
243
+ </p>
244
+ </div>
245
+ )
246
+ }
247
+
248
+ /** A staged boolean field: 继承 / 开 / 关. */
249
+ export function BooleanField(props: FieldProps & {
250
+ /** Copy for the inherit option. */
251
+ inheritLabel: string
252
+ /** Copy for the on option. */
253
+ onLabel: string
254
+ /** Copy for the off option. */
255
+ offLabel: string
256
+ }) {
257
+ return (
258
+ <div className={css.field}>
259
+ <div className={css.head}>
260
+ <label className={css.label} htmlFor={props.id}>{props.label}</label>
261
+ {props.overridden
262
+ ? (
263
+ <span className={css.badges}>
264
+ <span className={css.badge}>{props.overriddenLabel}</span>
265
+ <button
266
+ type="button"
267
+ className={css.reset}
268
+ disabled={props.disabled}
269
+ onClick={props.onReset}
270
+ >
271
+ {props.resetLabel}
272
+ </button>
273
+ </span>
274
+ )
275
+ : null}
276
+ </div>
277
+ <select
278
+ id={props.id}
279
+ className={css.select}
280
+ value={props.text}
281
+ disabled={props.disabled}
282
+ onChange={(event) => { props.onEdit(event.target.value) }}
283
+ >
284
+ <option value="">{props.inheritLabel}</option>
285
+ <option value="true">{props.onLabel}</option>
286
+ <option value="false">{props.offLabel}</option>
287
+ </select>
288
+ <p className={css.hint}>{props.hint}</p>
289
+ </div>
290
+ )
291
+ }
292
+
293
+ /** A staged enumerated field rendered as a select. */
294
+ export function ChoiceField(props: FieldProps & {
295
+ /** Copy for the inherit option (draft text is the empty string). */
296
+ inheritLabel: string
297
+ /** Choices rendered in order; `value` is the draft/stored text. */
298
+ choices: ReadonlyArray<{ value: string; label: string }>
299
+ }) {
300
+ return (
301
+ <div className={css.field}>
302
+ <div className={css.head}>
303
+ <label className={css.label} htmlFor={props.id}>{props.label}</label>
304
+ {props.overridden
305
+ ? (
306
+ <span className={css.badges}>
307
+ <span className={css.badge}>{props.overriddenLabel}</span>
308
+ <button
309
+ type="button"
310
+ className={css.reset}
311
+ disabled={props.disabled}
312
+ onClick={props.onReset}
313
+ >
314
+ {props.resetLabel}
315
+ </button>
316
+ </span>
317
+ )
318
+ : null}
319
+ </div>
320
+ <select
321
+ id={props.id}
322
+ className={css.select}
323
+ value={props.text}
324
+ disabled={props.disabled}
325
+ onChange={(event) => { props.onEdit(event.target.value) }}
326
+ >
327
+ <option value="">{props.inheritLabel}</option>
328
+ {props.choices.map(choice => (
329
+ <option key={choice.value} value={choice.value}>{choice.label}</option>
330
+ ))}
331
+ </select>
332
+ <p className={props.invalid ? css.invalid : css.hint}>
333
+ {props.invalid ? props.invalidLabel : props.hint}
334
+ </p>
335
+ </div>
336
+ )
337
+ }
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Browser client for the host /filemgr/* routes: typed JSON envelope
3
+ * calls plus the SSE change subscription. Same-origin relative fetch (the
4
+ * page and the routes share the webserver).
5
+ * @module dsh-filemgr/client/api
6
+ */
7
+
8
+ import type {
9
+ DirListing, FileRead, GitBatchResult, GitStatusView, PanelEnvelope, PanelError, SearchView,
10
+ } from '../core/types.ts'
11
+
12
+ /** Transport failure (fetch threw or the response was not JSON). */
13
+ const TRANSPORT_ERROR: PanelError = { code: 'internal', message: 'panel route unavailable' }
14
+
15
+ /** POST one JSON payload and decode the envelope; never throws. */
16
+ async function post<T>(path: string, payload: Record<string, unknown>): Promise<PanelEnvelope<T>> {
17
+ let response: Response
18
+ try {
19
+ response = await fetch(path, {
20
+ method: 'POST',
21
+ headers: { 'content-type': 'application/json' },
22
+ body: JSON.stringify(payload),
23
+ })
24
+ } catch {
25
+ return { ok: false, error: TRANSPORT_ERROR }
26
+ }
27
+ try {
28
+ const envelope = await response.json() as unknown
29
+ if (typeof envelope !== 'object' || envelope === null) return { ok: false, error: TRANSPORT_ERROR }
30
+ const record = envelope as Record<string, unknown>
31
+ if (record.ok === true) return { ok: true, value: record.value as T }
32
+ return { ok: false, error: (record.error as PanelError | undefined) ?? TRANSPORT_ERROR }
33
+ } catch {
34
+ return { ok: false, error: TRANSPORT_ERROR }
35
+ }
36
+ }
37
+
38
+ /** Typed panel operations over the wire. */
39
+ export class PanelApi {
40
+ /** List one directory of the project root (rel path; '' = root). */
41
+ list(root: string, path: string): Promise<PanelEnvelope<DirListing>> {
42
+ return post('/filemgr/list', { root, path })
43
+ }
44
+
45
+ /** Read one file (text or image data URL). */
46
+ read(root: string, path: string, asImage: boolean): Promise<PanelEnvelope<FileRead>> {
47
+ return post('/filemgr/read', { root, path, asImage })
48
+ }
49
+
50
+ /** Write text content back with an optional mtime conflict base. */
51
+ write(root: string, path: string, content: string, baseMtime?: number): Promise<PanelEnvelope<{ mtime: number }>> {
52
+ return post('/filemgr/write', { root, path, content, baseMtime })
53
+ }
54
+
55
+ /** Filename search under the root. */
56
+ search(root: string, query: string): Promise<PanelEnvelope<SearchView>> {
57
+ return post('/filemgr/search', { root, query })
58
+ }
59
+
60
+ /** Delete a path (untracked discard). */
61
+ delete(root: string, path: string): Promise<PanelEnvelope<{ ok: true }>> {
62
+ return post('/filemgr/delete', { root, path })
63
+ }
64
+
65
+ /** Reveal a path in the OS file manager (selecting the entry). */
66
+ reveal(root: string, path: string): Promise<PanelEnvelope<{ ok: true }>> {
67
+ return post('/filemgr/reveal', { root, path })
68
+ }
69
+
70
+ /** Open a path with the OS default app. */
71
+ openWithDefault(root: string, path: string): Promise<PanelEnvelope<{ ok: true }>> {
72
+ return post('/filemgr/open-with-default', { root, path })
73
+ }
74
+
75
+ /** Rename a path (newName is a bare name, no separators). */
76
+ rename(root: string, path: string, newName: string): Promise<PanelEnvelope<{ ok: true }>> {
77
+ return post('/filemgr/rename', { root, path, newName })
78
+ }
79
+
80
+ /** Create a directory at a relative path (parent must exist). */
81
+ mkdir(root: string, path: string): Promise<PanelEnvelope<{ ok: true }>> {
82
+ return post('/filemgr/mkdir', { root, path })
83
+ }
84
+
85
+ /** Create an empty file at a relative path (refuses to overwrite). */
86
+ newFile(root: string, path: string): Promise<PanelEnvelope<{ ok: true }>> {
87
+ return post('/filemgr/new-file', { root, path })
88
+ }
89
+
90
+ /** The repo status view; null when the root is not a repository. */
91
+ gitStatus(root: string): Promise<PanelEnvelope<GitStatusView | null>> {
92
+ return post('/filemgr/git-status', { root })
93
+ }
94
+
95
+ /** The unified diff text of one path (staged = index vs HEAD). */
96
+ gitDiff(root: string, path: string, staged: boolean): Promise<PanelEnvelope<{ content: string }>> {
97
+ return post('/filemgr/git-diff', { root, path, staged })
98
+ }
99
+
100
+ /** Stage paths. */
101
+ gitStage(root: string, paths: string[]): Promise<PanelEnvelope<GitBatchResult>> {
102
+ return post('/filemgr/git-stage', { root, paths })
103
+ }
104
+
105
+ /** Unstage paths. */
106
+ gitUnstage(root: string, paths: string[]): Promise<PanelEnvelope<GitBatchResult>> {
107
+ return post('/filemgr/git-unstage', { root, paths })
108
+ }
109
+
110
+ /** Discard paths (worktree side; untracked paths are deleted). */
111
+ gitDiscard(root: string, paths: string[]): Promise<PanelEnvelope<GitBatchResult>> {
112
+ return post('/filemgr/git-discard', { root, paths })
113
+ }
114
+ }
115
+
116
+ /** One SSE change event pushed by the host. */
117
+ export type PanelChangeEvent =
118
+ | { kind: 'fs' }
119
+ | { kind: 'git'; status: GitStatusView }
120
+ | { kind: 'gitUnavailable' }
121
+
122
+ /**
123
+ * Subscribe to host-pushed changes for one project root (fs watch events and
124
+ * git status polls). Reconnects are handled by the EventSource; the caller
125
+ * re-subscribes when the root changes.
126
+ * @param root - project root to watch.
127
+ * @param onChange - fired on every pushed change.
128
+ * @returns the disposer closing the stream.
129
+ */
130
+ export function subscribePanelEvents(root: string, onChange: (event: PanelChangeEvent) => void): () => void {
131
+ const source = new EventSource(`/filemgr/events?root=${encodeURIComponent(root)}`)
132
+ source.addEventListener('change', (raw) => {
133
+ try {
134
+ const event = JSON.parse((raw as MessageEvent).data as string) as PanelChangeEvent
135
+ onChange(event)
136
+ } catch {
137
+ // malformed push; ignore
138
+ }
139
+ })
140
+ return () => { source.close() }
141
+ }