@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,294 @@
1
+ import { useCallback, useMemo, useState } from 'react'
2
+ import clsx from 'clsx'
3
+ import { parseAnsiLines, type AnsiLine } from './ansi.ts'
4
+ import { headTailCap } from './head-tail-cap.ts'
5
+ import { useClipboardCopy } from './use-clipboard-copy.ts'
6
+ import { Pill } from './Pill.tsx'
7
+ import { StateDot, type StateDotState } from './StateDot.tsx'
8
+ import css from './TerminalBlock.module.css'
9
+ import { CommandText } from './CommandText.tsx'
10
+
11
+ /** Output lines shown before the height cap collapses the middle. */
12
+ export const DEFAULT_TERMINAL_MAX_LINES = 16
13
+
14
+ /**
15
+ * Display copy for the terminal surface; the owner passes localized labels
16
+ * (this package is cordis-free, so copy arrives via props).
17
+ */
18
+ export interface TerminalBlockLabels {
19
+ /** Accessible name for an overflowing authored command line, numbered from one. */
20
+ commandLine: (line: number) => string
21
+ /** Status pill text for a signal-terminated command. */
22
+ signal: (signal: string) => string
23
+ /** Status pill text for a non-zero exit code. */
24
+ exitCode: (exitCode: number) => string
25
+ /** Status pill text for a command that ended without an exit code: killed by a signal the view does not know, or never started. */
26
+ noExitCode: string
27
+ /** Run-state text while the command is still running. */
28
+ running: string
29
+ /** Run-state text for a signal or non-zero-exit settle. */
30
+ failed: string
31
+ /** Run-state text for a clean settle. */
32
+ done: string
33
+ /** Copy-button idle label. */
34
+ copy: string
35
+ /** Copy-button label during the post-copy confirmation window. */
36
+ copied: string
37
+ /** Placeholder when a settled command produced no visible output. */
38
+ noOutput: string
39
+ /** Collapse-toggle aria label while expanded. */
40
+ collapseAria: string
41
+ /** Collapse-toggle text while expanded. */
42
+ collapse: string
43
+ /** Expand-toggle aria label while capped, given the hidden line count. */
44
+ expandAria: (hidden: number) => string
45
+ /** Expand-toggle text while capped, given the hidden line count. */
46
+ expand: (hidden: number) => string
47
+ }
48
+
49
+ export interface TerminalBlockProps {
50
+ /** The command, rendered verbatim after the prompt label; long lines scroll horizontally unless the host enables wrapping. */
51
+ command: string
52
+ /** Working directory for the prompt label; absent renders a plain `$`. */
53
+ cwd?: string | undefined
54
+ /** Absolute home directory, so a cwd equal to it collapses to `~`; absent disables that collapse. */
55
+ home?: string | undefined
56
+ /** The command's output text; may contain ANSI escape sequences. */
57
+ output?: string | undefined
58
+ /** Settled exit code; a non-zero value renders the status pill, and null (settled without one) the no-exit-code pill. */
59
+ exitCode?: number | null | undefined
60
+ /** Settled terminating signal name; any value renders the status pill, taking precedence over the exit code. */
61
+ signal?: string | undefined
62
+ /**
63
+ * The command is still running: with no `output` the block shows the prompt
64
+ * line alone; with output it renders the live text under the running state.
65
+ */
66
+ running?: boolean | undefined
67
+ /**
68
+ * The call launches background work (default false). `running` describes the
69
+ * launch call only; after it returns, retain the command without job status
70
+ * or output. An explicit `copyText` override remains available.
71
+ */
72
+ background?: boolean | undefined
73
+ /** Height cap in output lines before the middle collapses (default {@link DEFAULT_TERMINAL_MAX_LINES}); Infinity disables the cap. */
74
+ maxLines?: number | undefined
75
+ /**
76
+ * Copy-control payload override; the control copies the raw output when
77
+ * absent. Supplying it also keeps the control rendered before any output
78
+ * exists — a command is copyable before it prints.
79
+ */
80
+ copyText?: string | undefined
81
+ /**
82
+ * Draw the run-state dot and its assistive label in the card gutter
83
+ * (default true). Hosts whose surrounding row already carries the same
84
+ * state omit both and reclaim the gutter via `--dsl-terminal-gutter`.
85
+ */
86
+ runStateDot?: boolean | undefined
87
+ /** Extra class merged onto the wrapper (callers position; this component draws). */
88
+ className?: string | undefined
89
+ /** Localized display copy supplied by the owning render site. */
90
+ labels: TerminalBlockLabels
91
+ }
92
+
93
+ /**
94
+ * Prompt label for a working directory: `~` for the home directory itself,
95
+ * otherwise the path's last segment (both separators accepted, trailing
96
+ * separators ignored), falling back to the path itself when it has no
97
+ * segment.
98
+ * @param cwd - the working directory path.
99
+ * @param home - absolute home directory, when the caller knows it.
100
+ * @returns the prompt label.
101
+ */
102
+ function promptLabel(cwd: string, home: string | undefined): string {
103
+ const trimmed = cwd.replace(/[/\\]+$/, '')
104
+ if (home !== undefined && trimmed === home.replace(/[/\\]+$/, '')) return '~'
105
+ const segment = trimmed.split(/[/\\]/).pop()
106
+ return segment === undefined || segment === '' ? cwd : segment
107
+ }
108
+
109
+ /**
110
+ * Status pill text for a settled command, or undefined when the command
111
+ * settled cleanly (exit 0, no signal) and needs no pill — the same
112
+ * distinction the bash tool's own exit-status markers draw.
113
+ * @param exitCode - settled exit code, when known; null when the command settled without one.
114
+ * @param signal - settled terminating signal name, when known.
115
+ * @param labels - display copy for the pill text.
116
+ * @returns the pill text, or undefined for a clean exit.
117
+ */
118
+ function statusText(
119
+ exitCode: number | null | undefined,
120
+ signal: string | undefined,
121
+ labels: TerminalBlockLabels,
122
+ ): string | undefined {
123
+ if (signal !== undefined) return labels.signal(signal)
124
+ if (exitCode === null) return labels.noExitCode
125
+ if (exitCode !== undefined && exitCode !== 0) return labels.exitCode(exitCode)
126
+ return undefined
127
+ }
128
+
129
+ /**
130
+ * Run-state indicator for the command, shown at the head of the prompt line so
131
+ * the card states whether the command is still running without the reader
132
+ * having to infer it from the presence of output. Three of {@link StateDotState}'s
133
+ * five states are reachable: the running chase (the same
134
+ * indicator a running tool row's leading icon uses, so the row and its card
135
+ * never disagree), green for a clean settle, red for a signal or a non-zero
136
+ * exit — the same status distinction {@link statusText} draws for the pill. A
137
+ * settled command whose exit status never reached the view counts as a clean
138
+ * settle: the view says it finished and says nothing went wrong.
139
+ * @param running - the command has not settled.
140
+ * @param exitCode - settled exit code, when known; null when the command settled without one.
141
+ * @param signal - settled terminating signal name, when known.
142
+ * @param labels - display copy for the text label.
143
+ * @returns the dot's state and its text label, since the dot is aria-hidden.
144
+ */
145
+ function runState(
146
+ running: boolean,
147
+ exitCode: number | null | undefined,
148
+ signal: string | undefined,
149
+ labels: TerminalBlockLabels,
150
+ ): { state: StateDotState; label: string } {
151
+ if (running) return { state: 'ongoing', label: labels.running }
152
+ if (statusText(exitCode, signal, labels) !== undefined) return { state: 'error', label: labels.failed }
153
+ return { state: 'done', label: labels.done }
154
+ }
155
+
156
+ /**
157
+ * Render one parsed output line. Runs without SGR state render as bare text,
158
+ * so uncolored output carries no span wrappers.
159
+ * @param line - the line's styled runs.
160
+ * @returns the line's children.
161
+ */
162
+ function renderLine(line: AnsiLine) {
163
+ return line.map((span, index) => span.style === undefined
164
+ ? span.text
165
+ : <span key={index} style={span.style}>{span.text}</span>)
166
+ }
167
+
168
+ /**
169
+ * Render a shell command as a terminal surface.
170
+ * @param props - see {@link TerminalBlockProps}.
171
+ * @returns the terminal block element.
172
+ */
173
+ export function TerminalBlock({
174
+ command,
175
+ cwd,
176
+ home,
177
+ output,
178
+ exitCode,
179
+ signal,
180
+ running = false,
181
+ background = false,
182
+ maxLines = DEFAULT_TERMINAL_MAX_LINES,
183
+ copyText,
184
+ runStateDot = true,
185
+ className,
186
+ labels,
187
+ }: TerminalBlockProps) {
188
+ const copy = labels
189
+ const text = output ?? ''
190
+ // A command's output ends with a newline; that terminator is not an extra
191
+ // blank line to draw or to count against the height cap. The check runs on the
192
+ // PARSED lines rather than on the raw text, because a reset after the final
193
+ // newline (`line\n\x1b[0m`) leaves the string not ending in one while still
194
+ // producing a last line with nothing visible in it. A genuinely blank final
195
+ // line — the double newline — survives, since it has a real empty line before
196
+ // the terminator. The copy control's payload is unaffected.
197
+ const lines = useMemo(() => {
198
+ const parsed = parseAnsiLines(text)
199
+ const last = parsed[parsed.length - 1]
200
+ const terminated = parsed.length > 1 && last !== undefined
201
+ && last.every(span => span.text === '')
202
+ return terminated ? parsed.slice(0, -1) : parsed
203
+ }, [text])
204
+ const [expanded, setExpanded] = useState(false)
205
+ // The raw output (or the caller's override), never the rendered tree: the
206
+ // prompt line and the status pill are chrome the user did not run.
207
+ const { copied, onCopy } = useClipboardCopy(copyText ?? text)
208
+
209
+ const onToggle = useCallback(() => { setExpanded(value => !value) }, [])
210
+
211
+ const status = background ? undefined : statusText(exitCode, signal, copy)
212
+ const state = runState(running, exitCode, signal, copy)
213
+ const showState = runStateDot && (!background || running)
214
+ // A multi-line command gets one prompt row per line, so a two-command shell
215
+ // snippet reads as the two commands it is instead of collapsing into one
216
+ // ellipsized row. A trailing newline is a terminator, not an empty command.
217
+ const commandLines = useMemo(() => {
218
+ const body = command.endsWith('\n') ? command.slice(0, -1) : command
219
+ return body.split('\n')
220
+ }, [command])
221
+ // Read from the parsed lines the card actually renders, not from the raw text:
222
+ // output that is only escapes or control bytes (a lone reset, an OSC title, an
223
+ // erase) survives `text.trim()` yet parses to nothing visible. Judging it on
224
+ // the raw text would draw an output box of blank rows plus a copy control
225
+ // for invisible bytes, and hide the placeholder that belongs there.
226
+ const empty = lines.every(line => line.every(span => span.text.trim() === ''))
227
+ const { hidden, capped, headLines, tailLines } = headTailCap(lines.length, maxLines, expanded)
228
+ // A running command with nothing printed yet is banner-only; once it has
229
+ // printed, the output streams in under the banner as it would in a terminal.
230
+ const body = !background && (!running || !empty)
231
+
232
+ return (
233
+ <div
234
+ className={clsx(css.block, className)}
235
+ data-terminal=""
236
+ data-running={running ? '' : undefined}
237
+ data-body={body ? '' : undefined}
238
+ >
239
+ <div className={css.header}>
240
+ <div className={css.prompt}>
241
+ {showState && <span className={css.runStateLabel}>{state.label}</span>}
242
+ {commandLines.map((line, index) => (
243
+ <div key={index} className={css.promptLine}>
244
+ {/* One dot for the card, on the first row: the exit status the
245
+ view carries is the whole call's, and bash reports no
246
+ per-command status, so a dot per row would assert a
247
+ per-line outcome nothing here knows. */}
248
+ {index === 0 && showState && <StateDot state={state.state} className={css.runState} />}
249
+ {/* The cwd labels the CALL, so only its first row carries it. The
250
+ view knows one working directory — where the call started —
251
+ and a later line may well run somewhere else (a `cd` in the
252
+ command is enough), so repeating the label down the rows would
253
+ assert a directory per line that nothing here knows. Later
254
+ rows keep a bare `$` to stay aligned as prompts. */}
255
+ <span className={css.cwd}>
256
+ {index > 0 || cwd === undefined ? '$' : promptLabel(cwd, home)}
257
+ </span>
258
+ <CommandText className={css.command} text={line} label={copy.commandLine(index + 1)} />
259
+ </div>
260
+ ))}
261
+ </div>
262
+ {status !== undefined && <Pill className={css.status}>{status}</Pill>}
263
+ {(copyText !== undefined || (!background && !running && !empty)) && (
264
+ <button type="button" className={css.copyButton} onClick={onCopy}>
265
+ {copied ? copy.copied : copy.copy}
266
+ </button>
267
+ )}
268
+ </div>
269
+ {body && (empty
270
+ ? <div className={css.empty}>{copy.noOutput}</div>
271
+ : (
272
+ <div className={css.output}>
273
+ {(capped ? lines.slice(0, headLines) : lines).map((line, index) => (
274
+ <div key={index} className={css.line}>{renderLine(line)}</div>
275
+ ))}
276
+ {hidden > 0 && (
277
+ <button
278
+ type="button"
279
+ className={css.expand}
280
+ aria-expanded={expanded}
281
+ aria-label={expanded ? copy.collapseAria : copy.expandAria(hidden)}
282
+ onClick={onToggle}
283
+ >
284
+ {expanded ? copy.collapse : copy.expand(hidden)}
285
+ </button>
286
+ )}
287
+ {capped && lines.slice(lines.length - tailLines).map((line, index) => (
288
+ <div key={index} className={css.line}>{renderLine(line)}</div>
289
+ ))}
290
+ </div>
291
+ ))}
292
+ </div>
293
+ )
294
+ }
@@ -0,0 +1,88 @@
1
+ .root {
2
+ position: relative;
3
+ display: inline-grid;
4
+ width: max-content;
5
+ max-width: 100%;
6
+ min-width: 0;
7
+ vertical-align: top;
8
+ color: inherit;
9
+ }
10
+
11
+ .content {
12
+ display: flex;
13
+ align-items: center;
14
+ min-width: 0;
15
+ }
16
+
17
+ .text {
18
+ color: inherit;
19
+ }
20
+
21
+ .text[data-shimmer-text]::after {
22
+ content: attr(data-shimmer-text);
23
+ }
24
+
25
+ .decoration {
26
+ position: absolute;
27
+ inset: 0;
28
+ /* The moving mask must not enlarge any ancestor's scrollable area. */
29
+ overflow: clip;
30
+ pointer-events: none;
31
+ user-select: none;
32
+ }
33
+
34
+ .sweep {
35
+ position: absolute;
36
+ inset: 0;
37
+ overflow: hidden;
38
+ color: var(--dsw-alias-label-shimmer);
39
+ mask-image: linear-gradient(105deg, transparent 0%, black 40% 60%, transparent 100%);
40
+ transform: translateX(-100%);
41
+ animation-name: dsh-row-shimmer-sweep;
42
+ }
43
+
44
+ /* Semantic base colors stay on the real content; the overlay supplies one tint. */
45
+ .sweep * {
46
+ color: inherit !important;
47
+ }
48
+
49
+ .sweep [data-shimmer-decoration] {
50
+ background: currentColor;
51
+ }
52
+
53
+ /* Opposite transforms keep every glyph aligned while their shared mask moves. */
54
+ .highlight {
55
+ width: 100%;
56
+ height: 100%;
57
+ transform: translateX(100%);
58
+ animation-name: dsh-row-shimmer-highlight;
59
+ }
60
+
61
+ .sweep,
62
+ .highlight {
63
+ animation-duration: 1.5s;
64
+ animation-delay: 0.3s;
65
+ animation-timing-function: steps(48, end);
66
+ animation-iteration-count: infinite;
67
+ }
68
+
69
+ @keyframes dsh-row-shimmer-sweep {
70
+ 0% { transform: translateX(-100%); }
71
+ 66.6667%, 100% { transform: translateX(100%); }
72
+ }
73
+
74
+ @keyframes dsh-row-shimmer-highlight {
75
+ 0% { transform: translateX(100%); }
76
+ 66.6667%, 100% { transform: translateX(-100%); }
77
+ }
78
+
79
+ @media (prefers-reduced-motion: reduce) {
80
+ .decoration {
81
+ display: none;
82
+ }
83
+
84
+ .sweep,
85
+ .highlight {
86
+ animation: none;
87
+ }
88
+ }
@@ -0,0 +1,58 @@
1
+ /** Text activity animation shared by a row and its nested text fragments. */
2
+ import { createContext, memo, useContext, type ReactNode } from 'react'
3
+ import clsx from 'clsx'
4
+ import css from './TextShimmer.module.css'
5
+
6
+ const DecorativeCopy = createContext<boolean | undefined>(undefined)
7
+
8
+ /** Text and activity supplied by the owning row. */
9
+ export interface TextShimmerProps {
10
+ /** Text or presentational children with text in nested TextShimmer instances. No effects or element ids. */
11
+ children: ReactNode
12
+ /** Whether to animate; nested instances share the containing row's activity. */
13
+ active?: boolean | undefined
14
+ className?: string | undefined
15
+ /** Layout class applied equally to the base and decorative content. */
16
+ contentClassName?: string | undefined
17
+ }
18
+
19
+ function TextContent({ children, className }: Pick<TextShimmerProps, 'children' | 'className'>) {
20
+ const decorative = useContext(DecorativeCopy)
21
+ const generated = decorative === true && typeof children === 'string'
22
+ return (
23
+ <span className={clsx(css.text, className)} data-shimmer-text={generated ? children : undefined}>
24
+ {generated ? null : children}
25
+ </span>
26
+ )
27
+ }
28
+
29
+ /**
30
+ * Render text with one shared highlight while retaining selectable, accessible content.
31
+ * Nested instances inherit the outer animation. Keep icons outside; mark decorative
32
+ * separators with data-shimmer-decoration so their background follows the highlight.
33
+ * Active children also render in an inert, clipped decoration; supply only presentation.
34
+ * @param props - localized text, running state, and owner styling.
35
+ * @returns retained text and its optional decorative highlight.
36
+ */
37
+ export const TextShimmer = memo(function TextShimmer({ children, active = false, className, contentClassName }: TextShimmerProps) {
38
+ const decorative = useContext(DecorativeCopy)
39
+ if (decorative !== undefined) return <TextContent className={className}>{children}</TextContent>
40
+ const content = typeof children === 'string' ? <TextContent>{children}</TextContent> : children
41
+ return (
42
+ <span className={clsx(css.root, className)} data-shimmer={active || undefined}>
43
+ <DecorativeCopy.Provider value={false}>
44
+ <span className={clsx(css.content, contentClassName)}>{content}</span>
45
+ </DecorativeCopy.Provider>
46
+ {active && (
47
+ // React 18 forwards inert as an empty string; a boolean is dropped.
48
+ <span className={css.decoration} aria-hidden="true" {...{ inert: '' }}>
49
+ <span className={css.sweep}>
50
+ <DecorativeCopy.Provider value>
51
+ <span className={clsx(css.content, css.highlight, contentClassName)}>{content}</span>
52
+ </DecorativeCopy.Provider>
53
+ </span>
54
+ </span>
55
+ )}
56
+ </span>
57
+ )
58
+ })
@@ -0,0 +1,102 @@
1
+ /* The fade delay comes from the component as `--dsh-toast-hold`, so one value
2
+ drives both the unmount timer and this animation; the fallback matches the
3
+ component's own default. The fade DURATION still has to agree with FADE_MS
4
+ in Toast.tsx, which no owner varies. */
5
+
6
+ .toast {
7
+ position: fixed;
8
+ top: 40px;
9
+ left: 50%;
10
+ /* Above the 1000 the image lightbox backdrop uses: a failure reported while
11
+ a preview is open must stay readable. */
12
+ z-index: 1100;
13
+ /* Announcements never intercept clicks. */
14
+ pointer-events: none;
15
+ display: flex;
16
+ align-items: center;
17
+ gap: 10px;
18
+ /* Fixed boxes with `left` set shrink-to-fit against the space RIGHT of
19
+ `left` (the -50% translate happens after sizing), so an anchored banner
20
+ near the window edge would wrap early. max-content sizes the box from
21
+ its text alone, capped by the max-width below. */
22
+ width: max-content;
23
+ max-width: min(640px, calc(100vw - 48px));
24
+ padding: 12px 16px;
25
+ border-radius: var(--dsw-radius-lg);
26
+ /* The design platform's toast surface is dark in BOTH themes (bluish-800
27
+ light / bluish-750 dark), so the label and the action text below stay
28
+ fixed instead of flipping with the theme. */
29
+ background: var(--dsw-alias-toast-bg);
30
+ color: var(--dsw-alias-toast-label);
31
+ font-size: 14px;
32
+ line-height: 22px;
33
+ box-shadow: var(--dsw-shadow-lv3);
34
+ transform: translateX(-50%);
35
+ animation:
36
+ dsh-toast-in 160ms ease-out,
37
+ dsh-toast-fade 1000ms ease var(--dsh-toast-hold, 3000ms) forwards;
38
+ }
39
+
40
+ .icon {
41
+ display: grid;
42
+ place-items: center;
43
+ flex: none;
44
+ color: var(--dsw-alias-state-warn-label);
45
+ }
46
+
47
+ .icon.success {
48
+ color: var(--dsw-alias-state-success-primary);
49
+ }
50
+
51
+ .text {
52
+ min-width: 0;
53
+ }
54
+
55
+ .action {
56
+ display: inline;
57
+ padding: 0;
58
+ border: 0;
59
+ background: none;
60
+ /* Reads as the action against the always-dark toast surface without an underline. */
61
+ color: var(--dsw-alias-toast-action);
62
+ font: inherit;
63
+ cursor: pointer;
64
+ /* Breathing room where the action text meets the surrounding copy. */
65
+ margin-inline: 3px;
66
+ /* The banner surface stays click-through (`pointer-events: none` above);
67
+ only its action text takes the pointer. */
68
+ pointer-events: auto;
69
+ }
70
+
71
+ @media (hover: hover) {
72
+ .action:hover {
73
+ opacity: 0.8;
74
+ }
75
+ }
76
+
77
+ @keyframes dsh-toast-in {
78
+ from {
79
+ opacity: 0;
80
+ transform: translate(-50%, -6px);
81
+ }
82
+
83
+ to {
84
+ opacity: 1;
85
+ transform: translate(-50%, 0);
86
+ }
87
+ }
88
+
89
+ @keyframes dsh-toast-fade {
90
+ to {
91
+ opacity: 0;
92
+ visibility: hidden;
93
+ }
94
+ }
95
+
96
+ /* Reduced motion drops the slide-in; the delayed fade (an opacity change,
97
+ not movement) still ends the banner before the timed unmount. */
98
+ @media (prefers-reduced-motion: reduce) {
99
+ .toast {
100
+ animation: dsh-toast-fade 1000ms ease var(--dsh-toast-hold, 3000ms) forwards;
101
+ }
102
+ }
package/src/Toast.tsx ADDED
@@ -0,0 +1,101 @@
1
+ import { Fragment, useEffect, useLayoutEffect, useRef, useState } from 'react'
2
+ import type { CSSProperties, ReactNode } from 'react'
3
+ import { createPortal } from 'react-dom'
4
+ import { IconCheckCircleOutlineRegular } from './icons/index.tsx'
5
+ import css from './Toast.module.css'
6
+
7
+ /** Full-opacity hold before the fade starts, when the owner names none. */
8
+ const HOLD_MS = 3000
9
+ /** Fade duration. Must agree with the stylesheet's toast-fade duration. */
10
+ const FADE_MS = 1000
11
+
12
+ /**
13
+ * Transient top-center banner: slides in, holds at full opacity, fades out,
14
+ * then reports done so the owner can unmount it. Re-showing the same text
15
+ * restarts the cycle when the owner remounts the component (key it by a
16
+ * per-show sequence). Rendered through a body portal so an owner inside a
17
+ * transformed or filtered ancestor cannot trap the fixed banner in that
18
+ * ancestor's box.
19
+ * With unchanged holdMs, parent rerenders do not extend the lifetime.
20
+ * Completion calls the latest onDone handler; fully faded actions receive no input.
21
+ *
22
+ * The hold is the owner's to set, because how long a banner has to stay
23
+ * depends on how much there is to read: a one-line limit lands in the default
24
+ * window, while a failure that names what broke does not. One value drives
25
+ * both the unmount timer and the stylesheet's fade delay — the stylesheet
26
+ * reads it as a custom property — so the two can no longer disagree and leave
27
+ * the banner unmounting mid-fade.
28
+ * @param props.text - resolved banner copy; the owner passes localized text.
29
+ * @param props.icon - optional leading glyph (e.g. a warning icon); ignored
30
+ * under `tone="success"`, which brings its own glyph.
31
+ * @param props.tone - 'success' renders the design's circled green check as
32
+ * the leading glyph; omitted, the icon seat keeps its warning tint.
33
+ * @param props.actions - optional inline actions continuing the sentence:
34
+ * each renders its plain-text `prefix` (a connective like 或) followed by its
35
+ * localized `label` as blue clickable text, flowing after `text` as one
36
+ * sentence. Each press is the owner's to handle (e.g. undo the reported
37
+ * change, then unmount the toast). The banner surface stays click-through —
38
+ * only the action text takes the pointer.
39
+ * @param props.holdMs - full-opacity hold before the fade; defaults to 3000.
40
+ * @param props.anchor - optional element whose horizontal center the banner
41
+ * follows (e.g. the composer card, so the banner centers over the chat column
42
+ * rather than the whole window); omitted, it centers on the viewport.
43
+ * @param props.onDone - called once the fade completes; unmount the toast here.
44
+ * @returns the floating banner.
45
+ */
46
+ export function Toast({ text, icon, tone, anchor, holdMs = HOLD_MS, actions, onDone }: {
47
+ text: string
48
+ icon?: ReactNode
49
+ tone?: 'success'
50
+ anchor?: HTMLElement | null
51
+ holdMs?: number
52
+ actions?: readonly { label: string; prefix?: string; onClick: () => void }[]
53
+ onDone: () => void
54
+ }) {
55
+ const latestOnDone = useRef(onDone)
56
+ useLayoutEffect(() => { latestOnDone.current = onDone }, [onDone])
57
+ useEffect(() => {
58
+ const timer = setTimeout(() => { latestOnDone.current() }, holdMs + FADE_MS)
59
+ return () => { clearTimeout(timer) }
60
+ }, [holdMs])
61
+ // Anchor-centered placement re-measures on window resizes; the banner lives
62
+ // four seconds, so sub-window layout drift within that span stays out of
63
+ // scope.
64
+ const [left, setLeft] = useState<number | null>(null)
65
+ useLayoutEffect(() => {
66
+ if (anchor == null) return
67
+ const measure = (): void => {
68
+ const rect = anchor.getBoundingClientRect()
69
+ setLeft(rect.left + rect.width / 2)
70
+ }
71
+ measure()
72
+ window.addEventListener('resize', measure)
73
+ return () => { window.removeEventListener('resize', measure) }
74
+ }, [anchor])
75
+ return createPortal(
76
+ <div
77
+ className={css.toast}
78
+ role="alert"
79
+ style={{
80
+ ...left === null ? {} : { left },
81
+ '--dsh-toast-hold': `${String(holdMs)}ms`,
82
+ } as CSSProperties}
83
+ >
84
+ {tone === 'success'
85
+ ? <span className={`${css.icon} ${css.success}`} aria-hidden><IconCheckCircleOutlineRegular /></span>
86
+ : icon !== undefined && <span className={css.icon} aria-hidden>{icon}</span>}
87
+ <span className={css.text}>
88
+ {text}
89
+ {actions?.map(action => (
90
+ <Fragment key={action.label}>
91
+ {action.prefix}
92
+ <button type="button" className={css.action} onClick={action.onClick}>
93
+ {action.label}
94
+ </button>
95
+ </Fragment>
96
+ ))}
97
+ </span>
98
+ </div>,
99
+ document.body,
100
+ )
101
+ }