@deepseek-ai/dsh-client-ui-primitives 0.2.2-rc.1 → 0.2.2-rc.2

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 (412) hide show
  1. package/README.i18n.yaml +16 -16
  2. package/README.md +21 -14
  3. package/README.zh.md +21 -14
  4. package/lib/HoverCard.module.css +8 -3
  5. package/lib/JsonTree.module.css +7 -17
  6. package/lib/Menu.module.css +157 -37
  7. package/lib/Modal.module.css +16 -0
  8. package/lib/QuotePreview.module.css +37 -0
  9. package/lib/RiskConfirmation.module.css +11 -37
  10. package/lib/Toast.module.css +2 -3
  11. package/lib/Tooltip.module.css +2 -1
  12. package/lib/index.js +1447 -776
  13. package/lib/index.js.map +1 -0
  14. package/lib/markdown/CodeBlock.module.css +64 -0
  15. package/lib/markdown/MarkdownText.module.css +20 -1
  16. package/lib/types/AnimatedRows.d.ts +3 -0
  17. package/lib/types/AnimatedRows.d.ts.map +1 -0
  18. package/lib/types/AnimatedRows.js.map +1 -0
  19. package/lib/types/BrandWordmark.d.ts.map +1 -0
  20. package/lib/types/BrandWordmark.js.map +1 -0
  21. package/lib/types/Button.d.ts.map +1 -0
  22. package/lib/types/Button.js.map +1 -0
  23. package/lib/types/Checkbox.d.ts +3 -1
  24. package/lib/types/Checkbox.d.ts.map +1 -0
  25. package/lib/types/Checkbox.js.map +1 -0
  26. package/lib/types/CodeFileIcon.d.ts.map +1 -0
  27. package/lib/types/CodeFileIcon.js.map +1 -0
  28. package/lib/types/CodeToolbar.d.ts.map +1 -0
  29. package/lib/types/CodeToolbar.js.map +1 -0
  30. package/lib/types/CommandText.d.ts.map +1 -0
  31. package/lib/types/CommandText.js.map +1 -0
  32. package/lib/types/ConfigField.d.ts.map +1 -0
  33. package/lib/types/ConfigField.js.map +1 -0
  34. package/lib/types/ConnectionIndicator.d.ts.map +1 -0
  35. package/lib/types/ConnectionIndicator.js.map +1 -0
  36. package/lib/types/DetailDocument.d.ts.map +1 -0
  37. package/lib/types/DetailDocument.js.map +1 -0
  38. package/lib/types/DiffBlock.d.ts.map +1 -0
  39. package/lib/types/DiffBlock.js.map +1 -0
  40. package/lib/types/DisclosureRow.d.ts.map +1 -0
  41. package/lib/types/DisclosureRow.js.map +1 -0
  42. package/lib/types/DraggableImage.d.ts.map +1 -0
  43. package/lib/types/DraggableImage.js.map +1 -0
  44. package/lib/types/FileTypeIcon.d.ts.map +1 -0
  45. package/lib/types/FileTypeIcon.js.map +1 -0
  46. package/lib/types/FishLogo.d.ts.map +1 -0
  47. package/lib/types/FishLogo.js.map +1 -0
  48. package/lib/types/FoldToggle.d.ts.map +1 -0
  49. package/lib/types/FoldToggle.js.map +1 -0
  50. package/lib/types/HoverCard.d.ts.map +1 -0
  51. package/lib/types/HoverCard.js.map +1 -0
  52. package/lib/types/HoverCardGroup.d.ts.map +1 -0
  53. package/lib/types/HoverCardGroup.js.map +1 -0
  54. package/lib/types/ImageLightbox.d.ts.map +1 -0
  55. package/lib/types/ImageLightbox.js.map +1 -0
  56. package/lib/types/ImagePreview.d.ts.map +1 -0
  57. package/lib/types/ImagePreview.js.map +1 -0
  58. package/lib/types/InlineEditor.d.ts.map +1 -0
  59. package/lib/types/InlineEditor.js.map +1 -0
  60. package/lib/types/Input.d.ts.map +1 -0
  61. package/lib/types/Input.js.map +1 -0
  62. package/lib/types/JsonTree.d.ts.map +1 -0
  63. package/lib/types/JsonTree.js.map +1 -0
  64. package/lib/types/LinkIcon.d.ts.map +1 -0
  65. package/lib/types/LinkIcon.js.map +1 -0
  66. package/lib/types/Menu.d.ts +26 -14
  67. package/lib/types/Menu.d.ts.map +1 -0
  68. package/lib/types/Menu.js.map +1 -0
  69. package/lib/types/MenuGroup.d.ts.map +1 -0
  70. package/lib/types/MenuGroup.js.map +1 -0
  71. package/lib/types/MenuRow.d.ts +37 -0
  72. package/lib/types/MenuRow.d.ts.map +1 -0
  73. package/lib/types/MenuRow.js.map +1 -0
  74. package/lib/types/MenuSurface.d.ts.map +1 -0
  75. package/lib/types/MenuSurface.js.map +1 -0
  76. package/lib/types/Modal.d.ts +3 -1
  77. package/lib/types/Modal.d.ts.map +1 -0
  78. package/lib/types/Modal.js.map +1 -0
  79. package/lib/types/PathLabel.d.ts.map +1 -0
  80. package/lib/types/PathLabel.js.map +1 -0
  81. package/lib/types/PermissionIcon.d.ts.map +1 -0
  82. package/lib/types/PermissionIcon.js.map +1 -0
  83. package/lib/types/Pill.d.ts.map +1 -0
  84. package/lib/types/Pill.js.map +1 -0
  85. package/lib/types/QuotePreview.d.ts +17 -4
  86. package/lib/types/QuotePreview.d.ts.map +1 -0
  87. package/lib/types/QuotePreview.js.map +1 -0
  88. package/lib/types/ReadBlock.d.ts.map +1 -0
  89. package/lib/types/ReadBlock.js.map +1 -0
  90. package/lib/types/ReferenceIcon.d.ts.map +1 -0
  91. package/lib/types/ReferenceIcon.js.map +1 -0
  92. package/lib/types/RiskConfirmation.d.ts.map +1 -0
  93. package/lib/types/RiskConfirmation.js.map +1 -0
  94. package/lib/types/SearchBlock.d.ts.map +1 -0
  95. package/lib/types/SearchBlock.js.map +1 -0
  96. package/lib/types/SegmentedControl.d.ts.map +1 -0
  97. package/lib/types/SegmentedControl.js.map +1 -0
  98. package/lib/types/SegmentedTabs.d.ts.map +1 -0
  99. package/lib/types/SegmentedTabs.js.map +1 -0
  100. package/lib/types/ShortcutKeys.d.ts.map +1 -0
  101. package/lib/types/ShortcutKeys.js.map +1 -0
  102. package/lib/types/SiteGlyph.d.ts.map +1 -0
  103. package/lib/types/SiteGlyph.js.map +1 -0
  104. package/lib/types/StateDot.d.ts.map +1 -0
  105. package/lib/types/StateDot.js.map +1 -0
  106. package/lib/types/SubmenuPanel.d.ts +19 -0
  107. package/lib/types/SubmenuPanel.d.ts.map +1 -0
  108. package/lib/types/SubmenuPanel.js.map +1 -0
  109. package/lib/types/Switch.d.ts.map +1 -0
  110. package/lib/types/Switch.js.map +1 -0
  111. package/lib/types/Tag.d.ts.map +1 -0
  112. package/lib/types/Tag.js.map +1 -0
  113. package/lib/types/TerminalBlock.d.ts.map +1 -0
  114. package/lib/types/TerminalBlock.js.map +1 -0
  115. package/lib/types/TextShimmer.d.ts.map +1 -0
  116. package/lib/types/TextShimmer.js.map +1 -0
  117. package/lib/types/Toast.d.ts.map +1 -0
  118. package/lib/types/Toast.js.map +1 -0
  119. package/lib/types/Tooltip.d.ts.map +1 -0
  120. package/lib/types/Tooltip.js.map +1 -0
  121. package/lib/types/UserMessageBubble.d.ts.map +1 -0
  122. package/lib/types/UserMessageBubble.js.map +1 -0
  123. package/lib/types/WebBlock.d.ts.map +1 -0
  124. package/lib/types/WebBlock.js.map +1 -0
  125. package/lib/types/ZoomControls.d.ts.map +1 -0
  126. package/lib/types/ZoomControls.js.map +1 -0
  127. package/lib/types/ansi.d.ts.map +1 -0
  128. package/lib/types/ansi.js.map +1 -0
  129. package/lib/types/clipboard.d.ts.map +1 -0
  130. package/lib/types/clipboard.js.map +1 -0
  131. package/lib/types/code-file-icon-artwork.d.ts.map +1 -0
  132. package/lib/types/code-file-icon-artwork.js.map +1 -0
  133. package/lib/types/code-file-types.d.ts.map +1 -0
  134. package/lib/types/code-file-types.js.map +1 -0
  135. package/lib/types/code-highlighting.d.ts.map +1 -0
  136. package/lib/types/code-highlighting.js.map +1 -0
  137. package/lib/types/darwin-desktop.d.ts.map +1 -0
  138. package/lib/types/darwin-desktop.js.map +1 -0
  139. package/lib/types/document-zoom.d.ts.map +1 -0
  140. package/lib/types/document-zoom.js.map +1 -0
  141. package/lib/types/file-drag-actions.d.ts.map +1 -0
  142. package/lib/types/file-drag-actions.js.map +1 -0
  143. package/lib/types/file-size.d.ts.map +1 -0
  144. package/lib/types/file-size.js.map +1 -0
  145. package/lib/types/focus.d.ts.map +1 -0
  146. package/lib/types/focus.js.map +1 -0
  147. package/lib/types/guide-artwork.d.ts.map +1 -0
  148. package/lib/types/guide-artwork.js.map +1 -0
  149. package/lib/types/head-tail-cap.d.ts.map +1 -0
  150. package/lib/types/head-tail-cap.js.map +1 -0
  151. package/lib/types/icons/artwork.d.ts +12 -0
  152. package/lib/types/icons/artwork.d.ts.map +1 -0
  153. package/lib/types/icons/artwork.js.map +1 -0
  154. package/lib/types/icons/index.d.ts +12 -0
  155. package/lib/types/icons/index.d.ts.map +1 -0
  156. package/lib/types/icons/index.js.map +1 -0
  157. package/lib/types/icons/props.d.ts.map +1 -0
  158. package/lib/types/icons/props.js.map +1 -0
  159. package/lib/types/icons/shared-artwork.d.ts.map +1 -0
  160. package/lib/types/icons/shared-artwork.js.map +1 -0
  161. package/lib/types/image-drag.d.ts.map +1 -0
  162. package/lib/types/image-drag.js.map +1 -0
  163. package/lib/types/index.d.ts +5 -4
  164. package/lib/types/index.d.ts.map +1 -0
  165. package/lib/types/index.js.map +1 -0
  166. package/lib/types/input-modality.d.ts.map +1 -0
  167. package/lib/types/input-modality.js.map +1 -0
  168. package/lib/types/keyboard-composition.d.ts.map +1 -0
  169. package/lib/types/keyboard-composition.js.map +1 -0
  170. package/lib/types/markdown/CodeBlock.d.ts +8 -1
  171. package/lib/types/markdown/CodeBlock.d.ts.map +1 -0
  172. package/lib/types/markdown/CodeBlock.js.map +1 -0
  173. package/lib/types/markdown/FenceBlocks.d.ts +31 -0
  174. package/lib/types/markdown/FenceBlocks.d.ts.map +1 -0
  175. package/lib/types/markdown/FenceBlocks.js.map +1 -0
  176. package/lib/types/markdown/JsonBlock.d.ts.map +1 -0
  177. package/lib/types/markdown/JsonBlock.js.map +1 -0
  178. package/lib/types/markdown/MarkdownDelegate.d.ts +23 -1
  179. package/lib/types/markdown/MarkdownDelegate.d.ts.map +1 -0
  180. package/lib/types/markdown/MarkdownDelegate.js.map +1 -0
  181. package/lib/types/markdown/MarkdownText.d.ts +2 -0
  182. package/lib/types/markdown/MarkdownText.d.ts.map +1 -0
  183. package/lib/types/markdown/MarkdownText.js.map +1 -0
  184. package/lib/types/markdown/cjkFriendlyStrong.d.ts.map +1 -0
  185. package/lib/types/markdown/cjkFriendlyStrong.js.map +1 -0
  186. package/lib/types/markdown/copy-tex.d.ts +14 -0
  187. package/lib/types/markdown/copy-tex.d.ts.map +1 -0
  188. package/lib/types/markdown/copy-tex.js.map +1 -0
  189. package/lib/types/markdown/diff-fence.d.ts +58 -0
  190. package/lib/types/markdown/diff-fence.d.ts.map +1 -0
  191. package/lib/types/markdown/diff-fence.js.map +1 -0
  192. package/lib/types/markdown/file-link.d.ts.map +1 -0
  193. package/lib/types/markdown/file-link.js.map +1 -0
  194. package/lib/types/markdown/highlight.d.ts +18 -0
  195. package/lib/types/markdown/highlight.d.ts.map +1 -0
  196. package/lib/types/markdown/highlight.js.map +1 -0
  197. package/lib/types/markdown/incremental.d.ts.map +1 -0
  198. package/lib/types/markdown/incremental.js.map +1 -0
  199. package/lib/types/markdown/katex.d.ts.map +1 -0
  200. package/lib/types/markdown/katex.js.map +1 -0
  201. package/lib/types/markdown/local-image-syntax.d.ts.map +1 -0
  202. package/lib/types/markdown/local-image-syntax.js.map +1 -0
  203. package/lib/types/markdown/mathCompatibility.d.ts.map +1 -0
  204. package/lib/types/markdown/mathCompatibility.js.map +1 -0
  205. package/lib/types/markdown/parse.d.ts.map +1 -0
  206. package/lib/types/markdown/parse.js.map +1 -0
  207. package/lib/types/markdown/plain-text.d.ts.map +1 -0
  208. package/lib/types/markdown/plain-text.js.map +1 -0
  209. package/lib/types/markdown/quote-text.d.ts.map +1 -0
  210. package/lib/types/markdown/quote-text.js.map +1 -0
  211. package/lib/types/markdown/render.d.ts.map +1 -0
  212. package/lib/types/markdown/render.js.map +1 -0
  213. package/lib/types/markdown/useViewportHighlighting.d.ts.map +1 -0
  214. package/lib/types/markdown/useViewportHighlighting.js.map +1 -0
  215. package/lib/types/markdown/windows-path-destinations.d.ts.map +1 -0
  216. package/lib/types/markdown/windows-path-destinations.js.map +1 -0
  217. package/lib/types/menu-submenu-position.d.ts +15 -0
  218. package/lib/types/menu-submenu-position.d.ts.map +1 -0
  219. package/lib/types/menu-submenu-position.js.map +1 -0
  220. package/lib/types/overlay-top-margin.d.ts.map +1 -0
  221. package/lib/types/overlay-top-margin.js.map +1 -0
  222. package/lib/types/plugin-artwork.d.ts.map +1 -0
  223. package/lib/types/plugin-artwork.js.map +1 -0
  224. package/lib/types/pointer-grace.d.ts.map +1 -0
  225. package/lib/types/pointer-grace.js.map +1 -0
  226. package/lib/types/rank-by-name.d.ts.map +1 -0
  227. package/lib/types/rank-by-name.js.map +1 -0
  228. package/lib/types/relative-time.d.ts.map +1 -0
  229. package/lib/types/relative-time.js.map +1 -0
  230. package/lib/types/settings-form/SettingsForm.d.ts.map +1 -0
  231. package/lib/types/settings-form/SettingsForm.js.map +1 -0
  232. package/lib/types/settings-form/fields.d.ts.map +1 -0
  233. package/lib/types/settings-form/fields.js.map +1 -0
  234. package/lib/types/settings-form/form-model.d.ts.map +1 -0
  235. package/lib/types/settings-form/form-model.js.map +1 -0
  236. package/lib/types/tooltip-placement.d.ts.map +1 -0
  237. package/lib/types/tooltip-placement.js.map +1 -0
  238. package/lib/types/use-clipboard-copy.d.ts.map +1 -0
  239. package/lib/types/use-clipboard-copy.js.map +1 -0
  240. package/lib/types/useAnchoredMaxHeight.d.ts.map +1 -0
  241. package/lib/types/useAnchoredMaxHeight.js.map +1 -0
  242. package/lib/types/useDismissOnOutsidePointer.d.ts.map +1 -0
  243. package/lib/types/useDismissOnOutsidePointer.js.map +1 -0
  244. package/lib/types/useMenuSubmenu.d.ts +43 -0
  245. package/lib/types/useMenuSubmenu.d.ts.map +1 -0
  246. package/lib/types/useMenuSubmenu.js.map +1 -0
  247. package/lib/types/useModalLayer.d.ts.map +1 -0
  248. package/lib/types/useModalLayer.js.map +1 -0
  249. package/lib/types/useRowDragPreview.d.ts.map +1 -0
  250. package/lib/types/useRowDragPreview.js.map +1 -0
  251. package/lib/types/user-text.d.ts.map +1 -0
  252. package/lib/types/user-text.js.map +1 -0
  253. package/package.json +9 -6
  254. package/src/AnimatedRows.module.css +7 -0
  255. package/src/AnimatedRows.tsx +195 -0
  256. package/src/BrandWordmark.tsx +59 -0
  257. package/src/Button.module.css +84 -0
  258. package/src/Button.tsx +36 -0
  259. package/src/Checkbox.module.css +28 -0
  260. package/src/Checkbox.tsx +34 -0
  261. package/src/CodeCard.module.css +85 -0
  262. package/src/CodeFileIcon.tsx +28 -0
  263. package/src/CodeToolbar.tsx +62 -0
  264. package/src/CommandText.module.css +12 -0
  265. package/src/CommandText.tsx +46 -0
  266. package/src/ConfigField.module.css +12 -0
  267. package/src/ConfigField.tsx +53 -0
  268. package/src/ConnectionIndicator.module.css +120 -0
  269. package/src/ConnectionIndicator.tsx +103 -0
  270. package/src/DetailDocument.module.css +67 -0
  271. package/src/DetailDocument.tsx +120 -0
  272. package/src/DiffBlock.module.css +82 -0
  273. package/src/DiffBlock.tsx +221 -0
  274. package/src/DisclosureRow.module.css +115 -0
  275. package/src/DisclosureRow.tsx +124 -0
  276. package/src/DraggableImage.tsx +26 -0
  277. package/src/FileTypeIcon.module.css +50 -0
  278. package/src/FileTypeIcon.tsx +285 -0
  279. package/src/FishLogo.tsx +28 -0
  280. package/src/FoldToggle.tsx +33 -0
  281. package/src/HoverCard.module.css +108 -0
  282. package/src/HoverCard.tsx +356 -0
  283. package/src/HoverCardGroup.tsx +77 -0
  284. package/src/ImageLightbox.module.css +54 -0
  285. package/src/ImageLightbox.tsx +72 -0
  286. package/src/ImagePreview.module.css +24 -0
  287. package/src/ImagePreview.tsx +36 -0
  288. package/src/InlineEditor.module.css +23 -0
  289. package/src/InlineEditor.tsx +69 -0
  290. package/src/Input.module.css +38 -0
  291. package/src/Input.tsx +24 -0
  292. package/src/JsonTree.module.css +371 -0
  293. package/src/JsonTree.tsx +850 -0
  294. package/src/LinkIcon.tsx +118 -0
  295. package/src/Menu.module.css +443 -0
  296. package/src/Menu.tsx +553 -0
  297. package/src/MenuGroup.module.css +37 -0
  298. package/src/MenuGroup.tsx +103 -0
  299. package/src/MenuRow.tsx +89 -0
  300. package/src/MenuSurface.module.css +65 -0
  301. package/src/MenuSurface.tsx +54 -0
  302. package/src/Modal.module.css +147 -0
  303. package/src/Modal.tsx +96 -0
  304. package/src/PathLabel.module.css +28 -0
  305. package/src/PathLabel.tsx +41 -0
  306. package/src/PermissionIcon.tsx +119 -0
  307. package/src/Pill.module.css +30 -0
  308. package/src/Pill.tsx +36 -0
  309. package/src/QuotePreview.module.css +138 -0
  310. package/src/QuotePreview.tsx +133 -0
  311. package/src/ReadBlock.module.css +45 -0
  312. package/src/ReadBlock.tsx +151 -0
  313. package/src/ReferenceIcon.tsx +49 -0
  314. package/src/RiskConfirmation.module.css +47 -0
  315. package/src/RiskConfirmation.tsx +79 -0
  316. package/src/RowDragPreview.module.css +12 -0
  317. package/src/SearchBlock.module.css +114 -0
  318. package/src/SearchBlock.tsx +281 -0
  319. package/src/SegmentedControl.module.css +81 -0
  320. package/src/SegmentedControl.tsx +140 -0
  321. package/src/SegmentedTabs.module.css +77 -0
  322. package/src/SegmentedTabs.tsx +84 -0
  323. package/src/ShortcutKeys.module.css +33 -0
  324. package/src/ShortcutKeys.tsx +12 -0
  325. package/src/SiteGlyph.tsx +149 -0
  326. package/src/StateDot.module.css +100 -0
  327. package/src/StateDot.tsx +77 -0
  328. package/src/SubmenuPanel.tsx +51 -0
  329. package/src/Switch.module.css +49 -0
  330. package/src/Switch.tsx +42 -0
  331. package/src/Tag.module.css +57 -0
  332. package/src/Tag.tsx +42 -0
  333. package/src/TerminalBlock.module.css +207 -0
  334. package/src/TerminalBlock.tsx +294 -0
  335. package/src/TextShimmer.module.css +88 -0
  336. package/src/TextShimmer.tsx +58 -0
  337. package/src/Toast.module.css +102 -0
  338. package/src/Toast.tsx +101 -0
  339. package/src/Tooltip.module.css +68 -0
  340. package/src/Tooltip.tsx +273 -0
  341. package/src/UserMessageBubble.module.css +11 -0
  342. package/src/UserMessageBubble.tsx +16 -0
  343. package/src/WebBlock.module.css +153 -0
  344. package/src/WebBlock.tsx +196 -0
  345. package/src/ZoomControls.module.css +54 -0
  346. package/src/ZoomControls.tsx +92 -0
  347. package/src/ansi.ts +447 -0
  348. package/src/clipboard.ts +47 -0
  349. package/src/code-file-icon-artwork.manifest.json +71 -0
  350. package/src/code-file-icon-artwork.ts +60 -0
  351. package/src/code-file-types.ts +340 -0
  352. package/src/code-highlighting.ts +25 -0
  353. package/src/css-modules.d.ts +6 -0
  354. package/src/darwin-desktop.ts +11 -0
  355. package/src/document-zoom.ts +12 -0
  356. package/src/file-drag-actions.ts +29 -0
  357. package/src/file-size.ts +16 -0
  358. package/src/focus.ts +44 -0
  359. package/src/guide-artwork.tsx +32 -0
  360. package/src/head-tail-cap.ts +27 -0
  361. package/src/icons/artwork.ts +156 -0
  362. package/src/icons/index.tsx +634 -0
  363. package/src/icons/props.ts +8 -0
  364. package/src/icons/shared-artwork.tsx +71 -0
  365. package/src/image-drag.ts +84 -0
  366. package/src/index.ts +142 -0
  367. package/src/input-modality.ts +59 -0
  368. package/src/keyboard-composition.ts +36 -0
  369. package/src/markdown/CodeBlock.module.css +209 -0
  370. package/src/markdown/CodeBlock.tsx +268 -0
  371. package/src/markdown/FenceBlocks.tsx +51 -0
  372. package/src/markdown/JsonBlock.module.css +34 -0
  373. package/src/markdown/JsonBlock.tsx +36 -0
  374. package/src/markdown/MarkdownDelegate.tsx +102 -0
  375. package/src/markdown/MarkdownText.module.css +511 -0
  376. package/src/markdown/MarkdownText.tsx +218 -0
  377. package/src/markdown/cjkFriendlyStrong.ts +83 -0
  378. package/src/markdown/copy-tex.ts +53 -0
  379. package/src/markdown/diff-fence.ts +212 -0
  380. package/src/markdown/file-link.ts +45 -0
  381. package/src/markdown/highlight.ts +689 -0
  382. package/src/markdown/incremental.ts +360 -0
  383. package/src/markdown/katex.tsx +90 -0
  384. package/src/markdown/local-image-syntax.ts +29 -0
  385. package/src/markdown/mathCompatibility.ts +349 -0
  386. package/src/markdown/parse.ts +49 -0
  387. package/src/markdown/plain-text.ts +121 -0
  388. package/src/markdown/quote-text.ts +10 -0
  389. package/src/markdown/render.tsx +834 -0
  390. package/src/markdown/useViewportHighlighting.ts +72 -0
  391. package/src/markdown/windows-path-destinations.ts +34 -0
  392. package/src/menu-submenu-position.ts +20 -0
  393. package/src/overlay-top-margin.ts +18 -0
  394. package/src/plugin-artwork.tsx +110 -0
  395. package/src/pointer-grace.ts +47 -0
  396. package/src/rank-by-name.ts +93 -0
  397. package/src/relative-time.ts +36 -0
  398. package/src/settings-form/SettingsForm.module.css +53 -0
  399. package/src/settings-form/SettingsForm.tsx +74 -0
  400. package/src/settings-form/fields.module.css +153 -0
  401. package/src/settings-form/fields.tsx +151 -0
  402. package/src/settings-form/form-model.ts +393 -0
  403. package/src/tooltip-placement.ts +60 -0
  404. package/src/use-clipboard-copy.ts +44 -0
  405. package/src/useAnchoredMaxHeight.ts +45 -0
  406. package/src/useDismissOnOutsidePointer.ts +34 -0
  407. package/src/useMenuSubmenu.ts +182 -0
  408. package/src/useModalLayer.ts +108 -0
  409. package/src/useRowDragPreview.ts +76 -0
  410. package/src/user-text.module.css +46 -0
  411. package/src/user-text.tsx +67 -0
  412. package/lib/types/useAnchoredPosition.d.ts +0 -36
@@ -0,0 +1,153 @@
1
+ /* Settings form fields: label, control, override badge, and hint. */
2
+
3
+ .field {
4
+ display: flex;
5
+ flex-direction: column;
6
+ gap: 6px;
7
+ padding: 12px 0;
8
+ }
9
+
10
+ .field + .field {
11
+ border-top: 0.5px solid var(--dsw-alias-border-l2);
12
+ }
13
+
14
+ .head {
15
+ display: flex;
16
+ align-items: center;
17
+ gap: 8px;
18
+ }
19
+
20
+ .label {
21
+ flex: 1;
22
+ min-width: 0;
23
+ font-size: 13px;
24
+ font-weight: 500;
25
+ line-height: 1.5;
26
+ color: var(--dsw-alias-label-primary);
27
+ }
28
+
29
+ .labelGroup {
30
+ display: flex;
31
+ align-items: center;
32
+ gap: 4px;
33
+ flex: 1;
34
+ min-width: 0;
35
+ }
36
+
37
+ .labelGroup > .label {
38
+ flex: 0 1 auto;
39
+ }
40
+
41
+ .helpButton {
42
+ display: inline-flex;
43
+ align-items: center;
44
+ justify-content: center;
45
+ flex: none;
46
+ width: 24px;
47
+ height: 24px;
48
+ padding: 0;
49
+ border: 0;
50
+ border-radius: var(--dsw-radius-sm);
51
+ background: none;
52
+ color: var(--dsw-alias-label-tertiary);
53
+ cursor: pointer;
54
+ }
55
+
56
+ .helpButton[aria-expanded='true'] {
57
+ background: var(--dsw-alias-bg-layer-4);
58
+ color: var(--dsw-alias-label-secondary);
59
+ }
60
+
61
+ @media (hover: hover) {
62
+ .helpButton:hover {
63
+ background: var(--dsw-alias-bg-layer-4);
64
+ color: var(--dsw-alias-label-secondary);
65
+ }
66
+ }
67
+
68
+ .helpButton:focus-visible {
69
+ outline: var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary));
70
+ outline-offset: 1px;
71
+ }
72
+
73
+ .help {
74
+ padding: 10px 0 0;
75
+ font-size: 12px;
76
+ line-height: 1.6;
77
+ color: var(--dsw-alias-label-secondary);
78
+ }
79
+
80
+ .help > p {
81
+ margin: 0;
82
+ }
83
+
84
+ .help > p + p {
85
+ margin-top: 8px;
86
+ }
87
+
88
+ .badges {
89
+ display: inline-flex;
90
+ align-items: center;
91
+ gap: 8px;
92
+ }
93
+
94
+ .reset {
95
+ border: none;
96
+ background: none;
97
+ padding: 0;
98
+ font: inherit;
99
+ font-size: 12px;
100
+ line-height: 1.5;
101
+ color: var(--dsw-alias-label-secondary);
102
+ cursor: pointer;
103
+ }
104
+
105
+ @media (hover: hover) {
106
+ .reset:hover:not(:disabled) {
107
+ color: var(--dsw-alias-label-primary);
108
+ }
109
+ }
110
+
111
+ .reset:disabled {
112
+ cursor: default;
113
+ }
114
+
115
+ .input {
116
+ height: 34px;
117
+ padding: 0 12px;
118
+ border: 0.5px solid var(--dsw-alias-border-l4);
119
+ border-radius: var(--dsw-radius-md);
120
+ background: var(--dsw-alias-bg-layer-3);
121
+ font: inherit;
122
+ font-size: 13px;
123
+ line-height: 1.5;
124
+ color: var(--dsw-alias-label-primary);
125
+ }
126
+
127
+ .input:focus-visible {
128
+ outline: none;
129
+ border-color: var(--dsw-alias-state-business-primary);
130
+ }
131
+
132
+ .input:disabled {
133
+ color: var(--dsw-alias-label-tertiary);
134
+ cursor: default;
135
+ }
136
+
137
+ .input[aria-invalid='true'] {
138
+ border-color: var(--dsw-alias-state-error-primary);
139
+ }
140
+
141
+ .invalid {
142
+ margin: 0;
143
+ font-size: 12px;
144
+ line-height: 1.5;
145
+ color: var(--dsw-alias-state-error-primary);
146
+ }
147
+
148
+ .hint {
149
+ margin: 0;
150
+ font-size: 12px;
151
+ line-height: 1.5;
152
+ color: var(--dsw-alias-label-tertiary);
153
+ }
@@ -0,0 +1,151 @@
1
+ /**
2
+ * The controls of a settings form. Each renders one field's label, its staged
3
+ * text, whether saving would leave an override, and — when one stands — the
4
+ * reset that stages a clear back to the composition layer. Nothing here
5
+ * writes: a control reports what the user typed, and the form's save is the
6
+ * single point where a draft becomes a document mutation.
7
+ */
8
+
9
+ import { useState, type ReactNode } from 'react'
10
+ import { IconInfoOutlineRegular } from '../icons/index.tsx'
11
+ import { Tag } from '../Tag.tsx'
12
+ import css from './fields.module.css'
13
+
14
+ /** What every settings field control needs regardless of its value type. */
15
+ export interface SettingsFieldProps {
16
+ /** Stable id associating the label with its control. */
17
+ id: string
18
+ /** Visible label. */
19
+ label: string
20
+ /** One-line explanation rendered under the control. */
21
+ hint: string
22
+ /** Draft text this control renders. */
23
+ text: string
24
+ /** True when saving would leave a user-layer entry for this field. */
25
+ overridden: boolean
26
+ /** True when the draft is not a value this field accepts. */
27
+ invalid: boolean
28
+ /** Copy for the overridden badge. */
29
+ overriddenLabel: string
30
+ /** Copy for the reset control. */
31
+ resetLabel: string
32
+ /** Copy shown in place of the hint while the draft is invalid. */
33
+ invalidLabel: string
34
+ /** Disables every control (read-only document, or an unavailable namespace). */
35
+ disabled: boolean
36
+ /** Stage draft text. */
37
+ onEdit: (text: string) => void
38
+ /** Stage a clear so the field re-inherits the composition layer. */
39
+ onReset: () => void
40
+ }
41
+
42
+ /**
43
+ * A staged value field. `numeric` only hints the keypad: which drafts a field
44
+ * accepts is decided by its spec, so the control never silently rewrites what
45
+ * the user typed.
46
+ * @param props - the field's copy, its staged text, and the edit actions.
47
+ * @returns the labelled control.
48
+ */
49
+ export function SettingsValueField(props: Omit<SettingsFieldProps, 'hint'> & {
50
+ /** Optional explanation shown below the input. */
51
+ hint?: string
52
+ /** Rules disclosed by the information button beside the label. */
53
+ help?: { label: string; content: ReactNode }
54
+ /** Hints a numeric keypad without narrowing what the control accepts. */
55
+ numeric?: boolean
56
+ /** Placeholder shown while the draft is empty. */
57
+ placeholder?: string
58
+ }) {
59
+ const [helpOpen, setHelpOpen] = useState(false)
60
+ const helpId = `${props.id}-help`
61
+ const messageId = `${props.id}-message`
62
+ const hasMessage = props.invalid || Boolean(props.hint)
63
+ const description = [hasMessage ? messageId : '', helpOpen ? helpId : ''].filter(Boolean).join(' ')
64
+ return (
65
+ <div className={css.field}>
66
+ <div className={css.head}>
67
+ <div className={css.labelGroup}>
68
+ <label className={css.label} htmlFor={props.id}>{props.label}</label>
69
+ {props.help !== undefined
70
+ ? (
71
+ <button type="button" className={css.helpButton}
72
+ aria-label={props.help.label} aria-expanded={helpOpen} aria-controls={helpId}
73
+ onClick={() => { setHelpOpen(!helpOpen) }}>
74
+ <IconInfoOutlineRegular size={12} />
75
+ </button>
76
+ )
77
+ : null}
78
+ </div>
79
+ {props.overridden
80
+ ? (
81
+ <span className={css.badges}>
82
+ <Tag tone="neutral">{props.overriddenLabel}</Tag>
83
+ <button
84
+ type="button"
85
+ className={css.reset}
86
+ disabled={props.disabled}
87
+ onClick={props.onReset}
88
+ >
89
+ {props.resetLabel}
90
+ </button>
91
+ </span>
92
+ )
93
+ : null}
94
+ </div>
95
+ <input
96
+ id={props.id}
97
+ className={css.input}
98
+ type="text"
99
+ {...props.numeric === true ? { inputMode: 'numeric' as const } : {}}
100
+ {...props.invalid ? { 'aria-invalid': true } : {}}
101
+ aria-describedby={description || undefined}
102
+ value={props.text}
103
+ placeholder={props.placeholder ?? ''}
104
+ disabled={props.disabled}
105
+ onChange={(event) => { props.onEdit(event.target.value) }}
106
+ />
107
+ {hasMessage
108
+ ? <p id={messageId} className={props.invalid ? css.invalid : css.hint}>{props.invalid ? props.invalidLabel : props.hint}</p>
109
+ : null}
110
+ {props.help !== undefined && helpOpen
111
+ ? <div id={helpId} className={css.help} role="region" aria-label={props.help.label}>{props.help.content}</div>
112
+ : null}
113
+ </div>
114
+ )
115
+ }
116
+
117
+ /**
118
+ * A write-only credential control. The value never rides a response, so the
119
+ * control reports only whether one is configured and starts blank; a blank
120
+ * draft writes nothing, which keeps the stored key rather than clearing it.
121
+ * The control asks browsers not to autofill saved login passwords.
122
+ * @param props - the field's copy, its staged text, and the configured state.
123
+ * @returns the labelled control.
124
+ */
125
+ export function SettingsSecretField(props: Pick<SettingsFieldProps, 'id' | 'label' | 'hint' | 'text' | 'disabled' | 'onEdit'> & {
126
+ /** Whether the Host reports a configured credential for this reference. */
127
+ configured: boolean
128
+ /** Copy describing the configured state. */
129
+ stateLabel: string
130
+ }) {
131
+ return (
132
+ <div className={css.field}>
133
+ <div className={css.head}>
134
+ <label className={css.label} htmlFor={props.id}>{props.label}</label>
135
+ <span className={css.badges}>
136
+ <Tag tone={props.configured ? 'neutral' : 'quiet'}>{props.stateLabel}</Tag>
137
+ </span>
138
+ </div>
139
+ <input
140
+ id={props.id}
141
+ className={css.input}
142
+ type="password"
143
+ autoComplete="new-password"
144
+ value={props.text}
145
+ disabled={props.disabled}
146
+ onChange={(event) => { props.onEdit(event.target.value) }}
147
+ />
148
+ <p className={css.hint}>{props.hint}</p>
149
+ </div>
150
+ )
151
+ }
@@ -0,0 +1,393 @@
1
+ /**
2
+ * The staged form model behind a plugin's settings page.
3
+ *
4
+ * A card stages what the user types and writes it only when they save. Each
5
+ * settings write is a durable, revision-fenced document mutation, so a control
6
+ * that committed as it settled turned one edit into a write the user never
7
+ * asked for and could not preview; staged text makes what is on screen exactly
8
+ * what a save would store.
9
+ *
10
+ * A field shows its effective value — the user layer over the composition
11
+ * layer over the schema default — and whether the user layer carries it. That
12
+ * presence, not a value comparison, is what marks a field overridden: an
13
+ * override equal to the composition default is still an override.
14
+ */
15
+
16
+ import { createSnapshotStore, type SnapshotStore } from '@deepseek-ai/dsh-client-store'
17
+
18
+ /** What the model reads of one Host entry's form. */
19
+ export interface SettingsFormScopeSnapshot<T> {
20
+ /** `ready` while the Host serves the entry to this client; the form renders nothing otherwise. */
21
+ status: 'loading' | 'ready' | 'unavailable'
22
+ /** Last accepted schema-resolved section; undefined before the first acceptance. */
23
+ value: T | undefined
24
+ /** Composition layer the value resolves over: what a field reverts to once cleared. */
25
+ base: unknown
26
+ /** Raw user layer as stored; a field's PRESENCE here is what marks it overridden. */
27
+ user: unknown
28
+ /** Whether the Host document accepts writes. */
29
+ writable: boolean
30
+ /** Revision the snapshot was read at; a save fences its mutation with the revision its drafts started from. */
31
+ revision: number | undefined
32
+ }
33
+
34
+ /** One path edit a save sends, as the shared configuration form's `mutate` accepts it. */
35
+ export type SettingsFormPathOp =
36
+ | { op: 'set'; path: readonly string[]; value: unknown }
37
+ | { op: 'unset'; path: readonly string[] }
38
+
39
+ /** The entry form the model stages over: the reads and the atomic write of the form `ui-settings` shares per Host entry. */
40
+ export interface SettingsFormScope<T> {
41
+ /** @returns the current sync snapshot. */
42
+ getSnapshot(): SettingsFormScopeSnapshot<T>
43
+ /**
44
+ * Observe snapshot replacements.
45
+ * @param listener - invoked after each snapshot change.
46
+ * @returns the disposer removing this listener.
47
+ */
48
+ subscribe(listener: () => void): () => void
49
+ /**
50
+ * Apply ordered field edits in one revision-fenced write.
51
+ * @param ops - the edits, in staging order.
52
+ * @param expectedRevision - the revision the drafts were staged against, when known.
53
+ * @returns true for Host acceptance, false for refusal, after any recovery read.
54
+ */
55
+ mutate(ops: readonly SettingsFormPathOp[], expectedRevision?: number): Promise<boolean>
56
+ }
57
+
58
+ /** The write one field's staged text performs when the card is saved. */
59
+ export type SettingsFieldWrite =
60
+ | { kind: 'set'; value: unknown }
61
+ | { kind: 'clear' }
62
+
63
+ /** How one section field converts between its stored value and its draft text. */
64
+ export interface SettingsFieldSpec {
65
+ /** Field name inside the namespace section. */
66
+ field: string
67
+ /** Render a stored value as draft text; the empty string when the section carries none. */
68
+ format: (value: unknown) => string
69
+ /**
70
+ * The write this draft text stages, or undefined when the text is not a
71
+ * value this field accepts — which blocks the save rather than discarding it.
72
+ */
73
+ parse: (text: string) => SettingsFieldWrite | undefined
74
+ }
75
+
76
+ /**
77
+ * A control whose value is written outside the settings section. A credential
78
+ * literal never rides a response, so its draft has nothing to seed from: it is
79
+ * blank until typed, and a blank draft writes nothing.
80
+ */
81
+ export interface SettingsSecretSpec {
82
+ /** Field name addressing this control inside the card's form. */
83
+ field: string
84
+ /** Write the staged text; resolves to whether the Host accepted it. */
85
+ write: (text: string) => Promise<boolean>
86
+ }
87
+
88
+ /** One field as a card's control renders it. */
89
+ export interface SettingsFieldState {
90
+ /** Draft text the control renders. */
91
+ text: string
92
+ /**
93
+ * Whether saving would leave a user-layer entry for this field. A staged
94
+ * edit answers for itself, so the badge previews the save rather than
95
+ * reporting a state the pending edit already contradicts.
96
+ */
97
+ overridden: boolean
98
+ /** Whether the draft is not a value this field accepts, which blocks saving. */
99
+ invalid: boolean
100
+ }
101
+
102
+ /** Form state every plugin card shares. */
103
+ export interface SettingsFormShell {
104
+ /** False while the namespace is not served to this client; the card renders nothing. */
105
+ available: boolean
106
+ /** Whether the Host document accepts writes. */
107
+ writable: boolean
108
+ /** Whether the form holds edits that a save would write. */
109
+ dirty: boolean
110
+ /** Whether any staged draft is invalid, which blocks the save. */
111
+ invalid: boolean
112
+ /** Whether a save is crossing the wire. */
113
+ saving: boolean
114
+ /** Whether the last save did not land as staged; cleared by the next edit or save. */
115
+ failed: boolean
116
+ }
117
+
118
+ /** The write actions every plugin card's slot entry injects. */
119
+ export interface SettingsFormActions {
120
+ /** Stage draft text for one field. */
121
+ edit: (field: string, text: string) => void
122
+ /** Stage a clear, so saving lets the field re-inherit the composition layer. */
123
+ resetField: (field: string) => void
124
+ /** Write every staged edit, then re-seed from what the Host accepted. */
125
+ save: () => void
126
+ /** Drop every staged edit. */
127
+ discard: () => void
128
+ }
129
+
130
+ /** One field's staged edit. */
131
+ interface StagedEdit {
132
+ /** Draft text the control renders. */
133
+ text: string
134
+ /** True when this edit clears the field whatever text it shows. */
135
+ clear: boolean
136
+ }
137
+
138
+ /** One staged edit resolved into the write a save performs. */
139
+ interface PlannedWrite {
140
+ /** Field this entry writes. */
141
+ field: string
142
+ /**
143
+ * Perform the write and report whether the Host holds the staged value
144
+ * afterwards; undefined when the draft is not a value the field accepts.
145
+ */
146
+ run?: () => Promise<boolean>
147
+ op?: SettingsFormPathOp
148
+ }
149
+
150
+ /**
151
+ * A whole-number field. An empty draft clears the field; any other draft that
152
+ * is not a finite number blocks the save.
153
+ * @param field - field name inside the namespace section.
154
+ * @returns the field's conversion spec.
155
+ */
156
+ export function settingsNumberField(field: string): SettingsFieldSpec {
157
+ return {
158
+ field,
159
+ // A section that carries no number for this field renders empty rather
160
+ // than as a value nobody chose.
161
+ format: value => typeof value === 'number' ? String(value) : '',
162
+ parse: (text) => {
163
+ const trimmed = text.trim()
164
+ if (trimmed === '') return { kind: 'clear' }
165
+ const parsed = Number(trimmed)
166
+ return Number.isFinite(parsed) ? { kind: 'set', value: parsed } : undefined
167
+ },
168
+ }
169
+ }
170
+
171
+ /**
172
+ * A free-text field. An empty draft clears the field, so emptying the control
173
+ * and saving is the same gesture as resetting it.
174
+ * @param field - field name inside the namespace section.
175
+ * @returns the field's conversion spec.
176
+ */
177
+ export function settingsTextField(field: string): SettingsFieldSpec {
178
+ return {
179
+ field,
180
+ format: value => typeof value === 'string' ? value : '',
181
+ parse: (text) => {
182
+ const trimmed = text.trim()
183
+ return trimmed === '' ? { kind: 'clear' } : { kind: 'set', value: trimmed }
184
+ },
185
+ }
186
+ }
187
+
188
+ /**
189
+ * Stages one card's edits over one settings namespace and writes them on save.
190
+ *
191
+ * The form publishes through a snapshot store because slot components read
192
+ * through a snapshot selector, while both the scope and the local drafts
193
+ * change underneath; every projection is rebuilt from the two together.
194
+ */
195
+ export class SettingsFormModel<T> {
196
+ private readonly specs: Map<string, SettingsFieldSpec>
197
+ private readonly secretSpecs: Map<string, SettingsSecretSpec>
198
+ private readonly staged = new Map<string, StagedEdit>()
199
+ private readonly listeners = new Set<() => void>()
200
+ private baseline: SettingsFormScopeSnapshot<T> | undefined
201
+ private readonly unsubscribe: () => void
202
+ private saving = false
203
+ private failed = false
204
+
205
+ /**
206
+ * @param scope - the shared configuration form for this card's namespace.
207
+ * @param specs - the section fields this card edits.
208
+ * @param secrets - the card's write-only controls, written outside the section.
209
+ */
210
+ constructor(
211
+ private readonly scope: SettingsFormScope<T>,
212
+ specs: SettingsFieldSpec[],
213
+ secrets: SettingsSecretSpec[] = [],
214
+ ) {
215
+ this.specs = new Map(specs.map(spec => [spec.field, spec]))
216
+ this.secretSpecs = new Map(secrets.map(spec => [spec.field, spec]))
217
+ this.unsubscribe = scope.subscribe(() => { this.publish() })
218
+ }
219
+
220
+ /**
221
+ * Publish a projection of this form, rebuilt whenever the scope or a draft changes.
222
+ * @param project - build the card's state from the form's current reads.
223
+ * @returns the store the card's component reads through its bound selector.
224
+ */
225
+ bind<S>(project: () => S): SnapshotStore<S> {
226
+ const store = createSnapshotStore(project())
227
+ this.listeners.add(() => { store.set(project()) })
228
+ return store
229
+ }
230
+
231
+ /**
232
+ * Read the card-level state: what the Host serves, and what a save would do.
233
+ * @returns the form state every card shares.
234
+ */
235
+ shell(): SettingsFormShell {
236
+ const snapshot = this.scope.getSnapshot()
237
+ const plan = this.plan()
238
+ return {
239
+ available: snapshot.status === 'ready',
240
+ writable: snapshot.writable,
241
+ dirty: plan.length > 0,
242
+ invalid: plan.some(item => item.run === undefined && item.op === undefined),
243
+ saving: this.saving,
244
+ failed: this.failed,
245
+ }
246
+ }
247
+
248
+ /**
249
+ * Read one control's state.
250
+ * @param field - field name of a section field or of a write-only control.
251
+ * @returns the draft text, whether a save would leave an override, and whether it is invalid.
252
+ */
253
+ field(field: string): SettingsFieldState {
254
+ const staged = this.staged.get(field)
255
+ if (this.secretSpecs.has(field)) {
256
+ return { text: staged?.text ?? '', overridden: false, invalid: false }
257
+ }
258
+ const spec = this.spec(field)
259
+ if (staged === undefined) {
260
+ return { text: spec.format(this.sectionValue(field)), overridden: this.stored(field), invalid: false }
261
+ }
262
+ const write = staged.clear ? { kind: 'clear' as const } : spec.parse(staged.text)
263
+ return {
264
+ text: staged.text,
265
+ overridden: write?.kind === 'set',
266
+ invalid: write === undefined,
267
+ }
268
+ }
269
+
270
+ /**
271
+ * Build the edit, reset, save, and discard actions bound to this form.
272
+ * @returns the actions a card's slot entry injects.
273
+ */
274
+ actions(): SettingsFormActions {
275
+ return {
276
+ edit: (field, text) => { this.stage(field, { text, clear: false }) },
277
+ resetField: (field) => {
278
+ this.stage(field, { text: this.spec(field).format(this.baseValue(field)), clear: true })
279
+ },
280
+ save: () => { void this.save() },
281
+ discard: () => {
282
+ if (this.staged.size === 0 && !this.failed) return
283
+ this.staged.clear()
284
+ this.baseline = undefined
285
+ this.failed = false
286
+ this.publish()
287
+ },
288
+ }
289
+ }
290
+
291
+ /**
292
+ * Write every staged edit, then re-seed from what the Host accepted.
293
+ *
294
+ * The Host is the only authority on whether a value was accepted — its
295
+ * validators own the constraints no schema can express — so the outcome is
296
+ * read back from the section rather than predicted here. A save that did not
297
+ * land keeps its drafts, so the user can correct them instead of retyping.
298
+ * @returns settlement after every write and the read-back.
299
+ */
300
+ async save(): Promise<void> {
301
+ const plan = this.plan()
302
+ if (!plan.length || this.saving || !this.scope.getSnapshot().writable
303
+ || plan.some(item => item.run === undefined && item.op === undefined)) return
304
+ this.saving = true
305
+ this.failed = false
306
+ this.publish()
307
+ try {
308
+ const ops = plan.flatMap(item => item.op === undefined ? [] : [item.op])
309
+ let landed = !ops.length || await this.scope.mutate(ops, this.baseline?.revision)
310
+ if (!landed) { this.failed = true; return }
311
+ for (const item of plan) if (item.run) landed = await item.run() && landed
312
+ if (landed) { this.staged.clear(); this.baseline = undefined }
313
+ this.failed = !landed
314
+ } catch (_error) {
315
+ this.failed = true
316
+ } finally {
317
+ this.saving = false
318
+ this.publish()
319
+ }
320
+ }
321
+
322
+ /** Release the form's accepted-value subscription. */
323
+ dispose(): void { this.unsubscribe(); this.listeners.clear() }
324
+
325
+ /**
326
+ * Every staged edit a save would write. An entry whose draft is not a value
327
+ * its field accepts carries no write: the form is still dirty, and the save
328
+ * refuses rather than dropping the edit.
329
+ * @returns the planned writes, in the order the fields were staged.
330
+ */
331
+ private plan(): PlannedWrite[] {
332
+ const plan: PlannedWrite[] = []
333
+ for (const [field, staged] of this.staged) {
334
+ const secret = this.secretSpecs.get(field)
335
+ if (secret !== undefined) {
336
+ const value = staged.text.trim()
337
+ if (value !== '') plan.push({ field, run: () => secret.write(value) })
338
+ continue
339
+ }
340
+ const spec = this.spec(field)
341
+ if (staged.clear) {
342
+ if (this.stored(field)) plan.push({ field, op: { op: 'unset', path: [field] } })
343
+ continue
344
+ }
345
+ if (staged.text === spec.format(this.sectionValue(field))) continue
346
+ const write = spec.parse(staged.text)
347
+ if (write === undefined) plan.push({ field })
348
+ else if (write.kind === 'clear') plan.push({ field, op: { op: 'unset', path: [field] } })
349
+ else plan.push({ field, op: { op: 'set', path: [field], value: write.value } })
350
+ }
351
+ return plan
352
+ }
353
+
354
+ private stage(field: string, edit: StagedEdit): void {
355
+ this.baseline ??= this.scope.getSnapshot()
356
+ this.staged.set(field, edit)
357
+ this.failed = false
358
+ this.publish()
359
+ }
360
+
361
+ private spec(field: string): SettingsFieldSpec {
362
+ const spec = this.specs.get(field)
363
+ // Every call site names a field this card declared; a missing one is a
364
+ // wiring mistake that must not degrade into a silently inert control.
365
+ if (spec === undefined) throw new Error(`plugin card has no field ${field}`)
366
+ return spec
367
+ }
368
+
369
+ private snapshotOf(): SettingsFormScopeSnapshot<T> {
370
+ return this.scope.getSnapshot()
371
+ }
372
+
373
+ private sectionValue(field: string): unknown {
374
+ return (this.snapshotOf().value as Record<string, unknown> | undefined)?.[field]
375
+ }
376
+
377
+ private baseValue(field: string): unknown {
378
+ return (this.snapshotOf().base as Record<string, unknown> | undefined)?.[field]
379
+ }
380
+
381
+ private userLayer(): Record<string, unknown> | undefined {
382
+ return this.snapshotOf().user as Record<string, unknown> | undefined
383
+ }
384
+
385
+ private stored(field: string): boolean {
386
+ const user = this.userLayer()
387
+ return user !== undefined && Object.hasOwn(user, field)
388
+ }
389
+
390
+ private publish(): void {
391
+ for (const listener of this.listeners) listener()
392
+ }
393
+ }