@deepseek-ai/dsh-client-ui-primitives 0.2.2-alpha.3 → 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 +11 -8
  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
package/src/Menu.tsx ADDED
@@ -0,0 +1,553 @@
1
+ import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from 'react'
2
+ import type { ReactNode, RefObject } from 'react'
3
+ import { createPortal } from 'react-dom'
4
+ import clsx from 'clsx'
5
+ import { useMenuSubmenu, menuHoverAllowed } from './useMenuSubmenu.ts'
6
+ import { MenuRow, menuIconColumns, renderMenuDecoration } from './MenuRow.tsx'
7
+ import { SubmenuPanel } from './SubmenuPanel.tsx'
8
+ import { usePointerGrace } from './pointer-grace.ts'
9
+ import { isBehindModal } from './useModalLayer.ts'
10
+ import { observeComposition } from './keyboard-composition.ts'
11
+ import { focusWithoutRing } from './focus.ts'
12
+ import { MenuSurface } from './MenuSurface.tsx'
13
+ import css from './Menu.module.css'
14
+
15
+ /** Selectable row (optionally with a nested submenu). */
16
+ export interface MenuItem {
17
+ id: string
18
+ label: ReactNode
19
+ disabled?: boolean
20
+ /** Effective binding supplied by the command owner; omitted for unbound actions. */
21
+ shortcut?: { keys: readonly string[]; aria?: string | undefined }
22
+ /** Leading icon (figma .Menu_cell gap 8). */
23
+ icon?: ReactNode
24
+ /** Destructive row: error-colored text/icon and danger hover fill. */
25
+ danger?: boolean
26
+ /** Child choices opened by hover, focus, click, or ArrowRight; placement follows available space. */
27
+ submenu?: readonly MenuEntry[]
28
+ }
29
+
30
+ /** Hairline between item groups (not selectable). */
31
+ export interface MenuSeparator {
32
+ type: 'separator'
33
+ id: string
34
+ }
35
+
36
+ /** Non-interactive heading row above a group of items. */
37
+ export interface MenuLabel {
38
+ type: 'label'
39
+ id: string
40
+ text: string
41
+ }
42
+
43
+ /** One primary-menu entry: a row, a separator, or a heading label. */
44
+ export type MenuEntry = MenuItem | MenuSeparator | MenuLabel
45
+
46
+ /** Props for one component-rendered menu row. */
47
+ export interface MenuItemButtonProps {
48
+ /** Visible row label. */
49
+ children: ReactNode
50
+ /** Effective binding supplied by the command owner; omitted for unbound actions. */
51
+ shortcut?: MenuItem['shortcut']
52
+ /** Leading icon (figma .Menu_cell gap 8). */
53
+ icon?: ReactNode
54
+ /** Whether this row identifies the currently displayed page or view. */
55
+ current?: boolean
56
+ /** Whether the row cannot be activated. */
57
+ disabled?: boolean
58
+ /**
59
+ * Why the disabled row cannot be activated. The row then stays hoverable and
60
+ * focusable, shows the reason in a tooltip, and exposes it as the row's
61
+ * description; an enabled row ignores it.
62
+ */
63
+ disabledReason?: string | undefined
64
+ /** Destructive row: error-colored text/icon and danger hover fill. */
65
+ danger?: boolean
66
+ /**
67
+ * Start a new group: a hairline above this row, the same one a
68
+ * `{ type: 'separator' }` data entry draws. It comes and goes with the row,
69
+ * so a row that renders nothing leaves no stray line; a data separator
70
+ * directly before it draws no second line, and the list's first row draws none.
71
+ */
72
+ separatorBefore?: boolean
73
+ /** Row activation (click, Enter, or Tab on the focused row). */
74
+ onSelect: () => void
75
+ }
76
+
77
+ /**
78
+ * Render one `role="menuitem"` row for a {@link Menu} whose rows are
79
+ * components rather than `items` data: the same markup and styling as a data
80
+ * row, so it joins the list's keyboard walk and post-selection focus return
81
+ * without any shared state. Closing the menu stays the owner's decision, as
82
+ * it is for data rows.
83
+ * @param props.children - visible row label.
84
+ * @param props.shortcut - effective key labels and accessible combination.
85
+ * @param props.icon - optional leading icon.
86
+ * @param props.current - whether the row identifies the currently displayed page or view.
87
+ * @param props.disabled - whether the row cannot be activated.
88
+ * @param props.disabledReason - why a disabled row cannot be activated, shown in a tooltip and read as its description.
89
+ * @param props.danger - whether to use the destructive row colors.
90
+ * @param props.separatorBefore - whether this row starts a new group (hairline above it).
91
+ * @param props.onSelect - row activation callback.
92
+ * @returns one menu-item row.
93
+ */
94
+ export function MenuItemButton({ onSelect, ...props }: MenuItemButtonProps) {
95
+ return <MenuRow {...props} decorativeIcon={false} onClick={onSelect} />
96
+ }
97
+
98
+ /**
99
+ * Render an anchored dropdown menu. While the list is open its keys mirror the
100
+ * composer's: Tab settles the focused row — from the trigger, Tab enters the
101
+ * list instead — and Escape or Shift+Tab close it and return focus to the
102
+ * anchor's first button, and selecting a row does the same — the rows unmount
103
+ * with the list. Only a keyboard on the trigger or inside the list is
104
+ * intercepted; Tab presses elsewhere on the page stay the browser's. Escape
105
+ * first returns from a visible child, while ArrowRight enters and ArrowLeft returns.
106
+ * When neither side fits, click or ArrowRight opens a single-panel child page;
107
+ * focus alone retains the parent page.
108
+ * @param props.contextual - cursor positioning, context dismissal, and per-divider icon alignment.
109
+ * @param props.exiting - retain an inert popup during dismissal or replacement fade.
110
+ * @param props.returnFocus - original control captured before asynchronous menu preparation.
111
+ * @param props.isExternalTrigger - recognizes external controls whose pointer presses should not dismiss;
112
+ * omitted, every press outside the anchor and menu panels dismisses.
113
+ * @param props.autoFocus - focus the first item on open; the arrow keys walk the list either way.
114
+ * @param props.open - whether the list is showing (owner-controlled).
115
+ * @param props.anchor - the trigger element (rendered in place).
116
+ * @param props.items - selectable data rows and optional separators (default none; with no `children` either, the list is empty).
117
+ * @param props.submenuBackLabel - localized single-panel return label; omitted uses the caller's
118
+ * parent-row label beside a back arrow, without selecting that row.
119
+ * @param props.selectedId - row shown as selected.
120
+ * @param props.selectedIds - rows shown as selected when a menu contains independent option groups.
121
+ * @param props.onSelect - data-row activation callback (not called for disabled rows or submenu parents that only open children).
122
+ * @param props.onClose - invoked on outside click, Escape, or a window blur
123
+ * that moved focus into an iframe (the only signal a pointerdown inside a
124
+ * cross-origin iframe leaves).
125
+ * @param props.align - list alignment against the anchor (default 'start').
126
+ * @param props.side - open below (`bottom`, default) or above (`top`) the anchor.
127
+ * @param props.portal - render the list into document.body, fixed-positioned
128
+ * with CSS anchor positioning; it follows browser zoom and may exceed the
129
+ * visual viewport. Use when an ancestor's overflow clipping would crop the
130
+ * in-place list; default false keeps the pure-CSS in-place behavior.
131
+ * @param props.closeOnPointerLeave - close the list once the pointer has left
132
+ * both trigger and list for the pointer grace (default false keeps it open
133
+ * until outside click/Escape/selection). The grace makes the 4px trigger->list
134
+ * gap and a brief overshoot survivable; coming back cancels the close.
135
+ * @param props.dense - reduce vertical row spacing without changing the standard typography or card width.
136
+ * @param props.compact - use reduced menu typography and spacing.
137
+ * @param props.anchorRef - external element used as the CSS anchor in portal mode.
138
+ * @param props.anchorPoint - client viewport coordinates captured when a context menu opens.
139
+ * @param props.minWidthFromAnchor - in portal mode, keep the menu at least as wide as its anchor, bounded by viewport margins.
140
+ * @param props.footer - rows pinned below the scrolling items area, separated
141
+ * by a hairline; contextual menus reuse an explicit leading separator. These rows stay visible while the items above scroll.
142
+ * @param props.children - component rows rendered after `items` in the same
143
+ * list, each a `role="menuitem"` button such as {@link MenuItemButton}; they
144
+ * share the keyboard walk, the submenu exclusivity, and the post-selection
145
+ * focus return.
146
+ * @param props.selection - how a selected row is marked: a trailing check
147
+ * (`'check'`, default — figma .Menu_cell) or the hover fill held on the row
148
+ * with no check (`'fill'`, for icon-labelled rows where a trailing glyph
149
+ * crowds the cell).
150
+ * @param props.className - extra class on the anchor wrapper span.
151
+ * @param props.listClassName - extra class on the dropdown card itself; the
152
+ * only style hook that reaches a portaled list, which renders under
153
+ * document.body outside the owner's DOM subtree.
154
+ * @returns anchor wrapper with the conditional list.
155
+ */
156
+ export function Menu({ open, anchor, items = [], children, submenuBackLabel, selectedId, selectedIds, onSelect, onClose, align = 'start', side = 'bottom', portal = false, closeOnPointerLeave = false, dense = false, compact = false, autoFocus = false, selection = 'check', anchorRef, anchorPoint, minWidthFromAnchor = false, footer, className, listClassName, contextual = false, exiting, returnFocus, isExternalTrigger }: {
157
+ open: boolean
158
+ /** Pointer-positioned popup: cursor clearance, grouped icons, and context gestures. */
159
+ contextual?: boolean
160
+ /** Recognizes external triggers exempt from outside dismissal; omitted exempts no external nodes. */
161
+ isExternalTrigger?: (node: Node) => boolean
162
+ /** Resolve the original control for focus restoration and inert/hidden dismissal. */
163
+ returnFocus?: (() => HTMLElement | null) | undefined
164
+ /** Retain a dismissed context popup during its short fade. */
165
+ exiting?: 'dismiss' | 'replace' | undefined
166
+ autoFocus?: boolean
167
+ anchor: ReactNode
168
+ items?: readonly MenuEntry[]
169
+ /** Localized return action; omitted uses the caller's parent label with a back arrow. */
170
+ submenuBackLabel?: string | undefined
171
+ children?: ReactNode
172
+ footer?: readonly MenuEntry[]
173
+ selectedId?: string | undefined
174
+ selectedIds?: readonly string[] | undefined
175
+ onSelect?: (id: string) => void
176
+ onClose: () => void
177
+ align?: 'start' | 'end'
178
+ side?: 'bottom' | 'top' | 'right'
179
+ portal?: boolean
180
+ closeOnPointerLeave?: boolean
181
+ dense?: boolean
182
+ compact?: boolean
183
+ selection?: 'check' | 'fill'
184
+ anchorRef?: RefObject<HTMLElement | null> | undefined
185
+ /** Client coordinates captured for this opening; Safari offsets are applied once. */
186
+ anchorPoint?: { readonly x: number; readonly y: number } | undefined
187
+ minWidthFromAnchor?: boolean
188
+ className?: string | undefined
189
+ listClassName?: string | undefined
190
+ }) {
191
+ const rootRef = useRef<HTMLSpanElement>(null)
192
+ const listRef = useRef<HTMLDivElement>(null)
193
+ const menuId = useId()
194
+ const pointX = anchorPoint?.x
195
+ const pointY = anchorPoint?.y
196
+ const point = useMemo(() => {
197
+ if (pointX === undefined || pointY === undefined) return undefined
198
+ // WebKit reports client coordinates from the visual origin; fixed CSS uses
199
+ // the layout origin. Subsequent panning must not move this captured point.
200
+ const visualOrigin = open && typeof window.CSS !== 'undefined'
201
+ && window.CSS.supports('-webkit-backdrop-filter', 'none')
202
+ const viewport = visualOrigin ? window.visualViewport : undefined
203
+ return { x: pointX + (viewport?.offsetLeft ?? 0), y: pointY + (viewport?.offsetTop ?? 0) }
204
+ }, [open, pointX, pointY])
205
+ useLayoutEffect(() => {
206
+ const trigger = returnFocus?.()
207
+ if (!open || !contextual || trigger == null) return
208
+ const previous = trigger.getAttribute('aria-controls')
209
+ trigger.setAttribute('aria-controls', [previous, menuId].filter(Boolean).join(' '))
210
+ return () => {
211
+ if (previous === null) trigger.removeAttribute('aria-controls')
212
+ else trigger.setAttribute('aria-controls', previous)
213
+ }
214
+ }, [open, contextual, returnFocus, menuId])
215
+ /** Index the arrow walk last focused, the resume point when focus left the rows. */
216
+ const walkIndex = useRef<number | null>(null)
217
+ /**
218
+ * The control that had the keyboard when this menu opened — its own trigger,
219
+ * which an anchor that wraps several controls (a split button) would not be
220
+ * able to name by position.
221
+ */
222
+ const triggerRef = useRef<HTMLElement | null>(null)
223
+ const selectingWithTab = useRef(false)
224
+
225
+ /**
226
+ * Hand the keyboard back to the trigger that opened the menu — or, when the
227
+ * anchor never held it, to the anchor's first button. Focus left on a removed
228
+ * row otherwise falls to the page body, where the next Tab restarts from the
229
+ * top of the page.
230
+ * @param navigation - whether explicit keyboard traversal should retain its focus indicator.
231
+ */
232
+ const refocusAnchor = (navigation = false): void => {
233
+ const remembered = triggerRef.current
234
+ const trigger = returnFocus?.() ?? (remembered?.isConnected ? remembered : anchorRef?.current) ?? null
235
+ const target = trigger !== null && document.contains(trigger) && !(trigger as HTMLButtonElement).disabled
236
+ ? trigger : rootRef.current?.querySelector<HTMLButtonElement>('button:not(:disabled)')
237
+ if (target == null) return
238
+ if (navigation) target.focus()
239
+ else focusWithoutRing(target)
240
+ }
241
+
242
+ /**
243
+ * Post-selection focus, for the paths where the rows unmount with the list.
244
+ * A selection whose owner keeps the menu open is left alone, and so is an
245
+ * owner that moved focus itself (a presented file card hands it to its
246
+ * preview button): only a keyboard left on the closing list (or on the body
247
+ * its removal produced) comes back to the trigger.
248
+ */
249
+ const refocusAfterSelection = (): void => {
250
+ const navigation = selectingWithTab.current
251
+ queueMicrotask(() => {
252
+ if (openRef.current && exitingRef.current === undefined) return
253
+ const active = document.activeElement
254
+ if (active === null || active === document.body || listRef.current?.contains(active) === true
255
+ || submenu.contains(active)) refocusAnchor(navigation)
256
+ })
257
+ }
258
+ const exitingRef = useRef(exiting)
259
+ exitingRef.current = exiting
260
+ const openRef = useRef(open)
261
+ openRef.current = open
262
+ const submenu = useMenuSubmenu({ open: open && exiting === undefined, items, footer, listRef, refocusAnchor })
263
+ const submenuEvents = useRef<Pick<typeof submenu, 'contains' | 'activeList' | 'returnToParent'>>(submenu)
264
+ submenuEvents.current = submenu
265
+ const close = useRef(onClose)
266
+ close.current = onClose
267
+ const anchorName = `--dsh-menu-trigger-${menuId.replaceAll(':', '')}`
268
+ const [externalAnchor, setExternalAnchor] = useState<HTMLElement | null>(null)
269
+ const positioned = !portal || anchorRef === undefined || externalAnchor !== null
270
+ // External refs can attach after this component or replace their element
271
+ // without changing ref identity. Publish the anchor after all refs commit.
272
+ useEffect(() => {
273
+ if (!open || !portal || anchorRef === undefined) {
274
+ setExternalAnchor(null)
275
+ return
276
+ }
277
+ const element = anchorRef.current
278
+ setExternalAnchor(element)
279
+ if (element === null) return
280
+ const previous = element.style.getPropertyValue('anchor-name')
281
+ const priority = element.style.getPropertyPriority('anchor-name')
282
+ element.style.setProperty('anchor-name', anchorName)
283
+ return () => { element.style.setProperty('anchor-name', previous, priority) }
284
+ })
285
+ useEffect(() => {
286
+ if (!open || !portal || exiting !== undefined) return
287
+ const currentAnchor = (): HTMLElement | null => returnFocus?.() ?? (anchorRef === undefined ? rootRef.current : anchorRef.current)
288
+ const element = currentAnchor()
289
+ if (element === null) return
290
+ let dismissed = false
291
+ const check = (): void => {
292
+ const current = currentAnchor()
293
+ if (dismissed || (current !== null && current.isConnected && current.closest('[inert], [hidden]') === null)) return
294
+ dismissed = true
295
+ close.current()
296
+ }
297
+ const observer = new MutationObserver(check)
298
+ observer.observe(element.ownerDocument.documentElement, {
299
+ subtree: true, childList: true, attributes: true, attributeFilter: ['inert', 'hidden'],
300
+ })
301
+ check()
302
+ return () => { observer.disconnect() }
303
+ }, [open, portal, exiting, anchorRef, externalAnchor, returnFocus])
304
+ const { arm: armClose, cancel: cancelClose } = usePointerGrace(onClose)
305
+
306
+ // Opening remembers where the keyboard was, so closing can hand it back to
307
+ // that control — an anchor wrapping several (a split button) cannot be asked
308
+ // for it by position. Declared before the autoFocus effect so the capture
309
+ // sees the trigger, not the row autoFocus is about to focus.
310
+ useEffect(() => {
311
+ if (!open) return
312
+ const active = document.activeElement
313
+ triggerRef.current = active instanceof HTMLElement && active !== document.body
314
+ && (anchorRef !== undefined || anchorPoint !== undefined || rootRef.current?.contains(active) === true)
315
+ ? active : null
316
+ }, [open])
317
+
318
+ useEffect(() => {
319
+ if (!open || !positioned || exiting !== undefined || !autoFocus
320
+ || listRef.current?.contains(document.activeElement) || submenu.contains(document.activeElement)) return
321
+ const first = listRef.current?.querySelector<HTMLButtonElement>('button:not(:disabled)')
322
+ walkIndex.current = first === undefined || first === null ? null : 0
323
+ if (first != null) focusWithoutRing(first)
324
+ }, [open, autoFocus, items.length, footer?.length, positioned, exiting])
325
+
326
+ useEffect(() => {
327
+ if (!open || exiting !== undefined) {
328
+ walkIndex.current = null
329
+ return
330
+ }
331
+ const composition = observeComposition(document)
332
+ const onPointerDown = (e: PointerEvent) => {
333
+ if (!(e.target instanceof Node) || (contextual && e.button === 2)) return
334
+ // The portaled list is outside the anchor subtree; check both.
335
+ if (rootRef.current?.contains(e.target) === true || anchorRef?.current?.contains(e.target) === true) return
336
+ if (isExternalTrigger?.(e.target) === true) return
337
+ if (listRef.current?.contains(e.target) === true || submenuEvents.current.contains(e.target)) return
338
+ onClose()
339
+ }
340
+ const onKeyDown = (e: KeyboardEvent) => {
341
+ if (composition.guards(e) || isBehindModal(triggerRef.current ?? rootRef.current)
342
+ || e.defaultPrevented || e.ctrlKey || e.altKey || e.metaKey) return
343
+ // Where the keyboard is, computed once: the menu owns it when it holds a
344
+ // row or sits on its anchor region.
345
+ const focused = document.activeElement
346
+ const insideList = listRef.current?.contains(focused) === true || submenuEvents.current.contains(focused)
347
+ const anchored = focused === returnFocus?.() || anchorRef?.current?.contains(focused) === true
348
+ || rootRef.current?.contains(focused) === true || insideList
349
+ if (e.key === 'Escape' && !e.shiftKey) {
350
+ e.preventDefault()
351
+ if (e.repeat) return
352
+ if (submenuEvents.current.returnToParent()) return
353
+ // Closing hands the keyboard back when the menu had it — and, as this
354
+ // primitive always did for autoFocus menus, when it held the keyboard
355
+ // and lost it again (a row that unmounted under it).
356
+ onClose()
357
+ if (anchored || autoFocus) refocusAnchor()
358
+ }
359
+ if (e.key === 'ArrowLeft' && anchored && submenuEvents.current.returnToParent()) {
360
+ e.preventDefault()
361
+ return
362
+ }
363
+ if (e.key === 'ArrowRight' && insideList && focused instanceof HTMLButtonElement
364
+ && focused.getAttribute('aria-haspopup') === 'menu') {
365
+ e.preventDefault()
366
+ focused.click()
367
+ return
368
+ }
369
+ // Tab settles like Enter and Shift+Tab leaves like Escape, so a menu's
370
+ // keys mean what they mean in the composer. Only a keyboard already on
371
+ // the trigger or inside the list is intercepted: Tab elsewhere on the
372
+ // page keeps the browser's traversal even while a menu is open.
373
+ if (e.key === 'Tab') {
374
+ const list = submenuEvents.current.activeList(focused)
375
+ if (list === null || !anchored) return
376
+ if (e.shiftKey) {
377
+ e.preventDefault()
378
+ onClose()
379
+ refocusAnchor(true)
380
+ return
381
+ }
382
+ // Tab settles the row it is on; from anywhere else in the menu region
383
+ // it enters the list. A focused control that is not a row (a retry
384
+ // button inside an error strip) and a list with no enabled row keep the
385
+ // browser's traversal instead of being swallowed.
386
+ if (insideList) {
387
+ if (focused instanceof Element && focused.getAttribute('role') === 'menuitem') {
388
+ e.preventDefault()
389
+ if (focused.getAttribute('aria-disabled') === 'true') {
390
+ onClose()
391
+ refocusAnchor(true)
392
+ return
393
+ }
394
+ selectingWithTab.current = true
395
+ try { (focused as HTMLElement).click() }
396
+ finally { selectingWithTab.current = false }
397
+ }
398
+ return
399
+ }
400
+ const row = list.querySelector<HTMLButtonElement>('button:not(:disabled)')
401
+ if (row === null) return
402
+ e.preventDefault()
403
+ row.focus()
404
+ walkIndex.current = 0
405
+ return
406
+ }
407
+ // Arrows walk the list whether or not the menu focused its first item on
408
+ // open, so `autoFocus` chooses only that entry behavior. A keyboard still
409
+ // on the anchor enters at the end the step comes from — unless it already
410
+ // walked, in which case the walk resumes where it left off. The walk resumes
411
+ // from where it last put focus, not from `document.activeElement`: a row
412
+ // that refused focus (a hidden portal frame, a detached node) would
413
+ // otherwise re-enter at the near end on every press and the walk would
414
+ // alternate between two rows.
415
+ if (!['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(e.key)) return
416
+ const list = submenuEvents.current.activeList(focused)
417
+ if (list === null || !anchored) return
418
+ const buttons = Array.from(list.querySelectorAll<HTMLButtonElement>('button:not(:disabled)'))
419
+ if (buttons.length === 0) return
420
+ const index = buttons.indexOf(focused as HTMLButtonElement)
421
+ const from = index >= 0 ? index : walkIndex.current
422
+ const next = e.key === 'Home' ? 0 : e.key === 'End' ? buttons.length - 1
423
+ : from === null
424
+ ? (e.key === 'ArrowDown' ? 0 : buttons.length - 1)
425
+ : (from + (e.key === 'ArrowDown' ? 1 : -1) + buttons.length) % buttons.length
426
+ e.preventDefault()
427
+ walkIndex.current = next
428
+ buttons[next]?.focus()
429
+ }
430
+ // A pointerdown inside a cross-origin iframe (a sandboxed HTML preview)
431
+ // never reaches this document; the focus move it causes blurs the window
432
+ // instead. Only that case closes: an app or tab switch leaves the
433
+ // document's focus where it was, so activeElement is not an iframe.
434
+ const onWindowBlur = () => {
435
+ if (document.activeElement instanceof HTMLIFrameElement) onClose()
436
+ }
437
+ document.addEventListener('pointerdown', onPointerDown)
438
+ const onEscape = (event: KeyboardEvent): void => { if (event.key === 'Escape') onKeyDown(event) }
439
+ const onOtherKey = (event: KeyboardEvent): void => { if (event.key !== 'Escape') onKeyDown(event) }
440
+ document.addEventListener('keydown', onOtherKey)
441
+ document.addEventListener('keydown', onEscape, true)
442
+ window.addEventListener('blur', onWindowBlur)
443
+ return () => {
444
+ composition.dispose()
445
+ document.removeEventListener('pointerdown', onPointerDown)
446
+ document.removeEventListener('keydown', onOtherKey)
447
+ document.removeEventListener('keydown', onEscape, true)
448
+ window.removeEventListener('blur', onWindowBlur)
449
+ }
450
+ }, [open, onClose, autoFocus, contextual, exiting, anchorRef, returnFocus, isExternalTrigger])
451
+
452
+ useLayoutEffect(() => {
453
+ if (exiting === 'dismiss' && listRef.current?.contains(document.activeElement)) refocusAnchor()
454
+ }, [exiting])
455
+
456
+ // A close from selection/Escape/outside click outruns a pending grace close;
457
+ // left armed it would shut a list reopened inside the grace window. Its own
458
+ // effect, not the listener effect above: that one re-runs on every `onClose`
459
+ // identity change and would cancel the grace mid-transit.
460
+ useEffect(() => {
461
+ if (!open) cancelClose()
462
+ }, [open, cancelClose])
463
+
464
+ const itemColumns = menuIconColumns(items, contextual)
465
+ const footerColumns = menuIconColumns(footer ?? [], contextual)
466
+ const renderEntry = (entry: MenuEntry, columns: ReadonlySet<MenuEntry>) => {
467
+ if ('type' in entry) return renderMenuDecoration(entry)
468
+ const hasSub = entry.submenu !== undefined && entry.submenu.length > 0
469
+ return <MenuRow key={entry.id} icon={entry.icon} reserveIcon={columns.has(entry)}
470
+ disabled={entry.disabled} danger={entry.danger} shortcut={entry.shortcut}
471
+ selected={entry.id === selectedId || selectedIds?.includes(entry.id) === true} selection={selection}
472
+ aria-haspopup={hasSub ? 'menu' : undefined}
473
+ aria-expanded={hasSub ? submenu.entry?.id === entry.id && !submenu.hidden : undefined}
474
+ wrapperProps={hasSub ? {
475
+ onPointerEnter: (event) => {
476
+ if (!menuHoverAllowed(event) || entry.disabled) return
477
+ const trigger = event.currentTarget.querySelector<HTMLButtonElement>('button')
478
+ if (trigger !== null) submenu.openChild(entry.id, trigger)
479
+ },
480
+ onPointerLeave: (event) => { if (menuHoverAllowed(event)) submenu.leave() },
481
+ } : undefined}
482
+ onFocus={hasSub ? (event) => { submenu.focusParent(entry.id, event.currentTarget) } : undefined}
483
+ onClick={(event) => {
484
+ if (hasSub) submenu.openChild(entry.id, event.currentTarget, true)
485
+ else onSelect?.(entry.id)
486
+ }}>{entry.label}</MenuRow>
487
+ }
488
+
489
+ const list = open && positioned && (
490
+ <MenuSurface compact={compact} id={contextual ? menuId : undefined}
491
+ ref={listRef}
492
+ className={clsx(css.list, listClassName, dense && css.denseList, compact && css.compactList, css.scrollable, submenu.page && css.parentPage, portal && css.portal, side === 'top' && !portal && css.sideTop, align === 'end' && !portal && css.alignEnd)}
493
+ style={portal ? { positionAnchor: anchorName } : undefined}
494
+ data-anchor-side={portal ? side : undefined}
495
+ data-anchor-align={portal ? align : undefined}
496
+ data-match-anchor-width={portal && minWidthFromAnchor ? '' : undefined}
497
+ role={exiting === undefined && !submenu.page ? 'menu' : undefined}
498
+ aria-hidden={exiting === undefined && !submenu.page ? undefined : true}
499
+ data-context-menu={contextual ? '' : undefined}
500
+ phase={contextual ? exiting ?? 'enter' : undefined}
501
+ // React portals bubble synthetic events through the REACT tree: without
502
+ // this stop, an item click re-fires the anchor row's own onClick
503
+ // (open/toggle) after onSelect. The same bubble is where every row's
504
+ // activation lands — data rows and component rows alike — so the
505
+ // post-selection focus return is decided once here, after the row's
506
+ // own handler ran; a submenu parent only opened its card.
507
+ onClick={(e) => {
508
+ e.stopPropagation()
509
+ const row = e.target instanceof Element ? e.target.closest('button[role="menuitem"]') : null
510
+ if (row !== null && row.getAttribute('aria-haspopup') !== 'menu') refocusAfterSelection()
511
+ }}
512
+ onContextMenu={contextual ? (event) => {
513
+ event.preventDefault(); event.stopPropagation(); onClose()
514
+ } : undefined}
515
+ onPointerOver={(event) => { if (menuHoverAllowed(event)) submenu.collapseFrom(event) }}
516
+ onFocus={submenu.collapseFrom}
517
+ >
518
+ {/* Child cards anchor to this unscrolled box, which matches the card itself. */}
519
+ {submenu.entry !== undefined && <span aria-hidden="true" className={css.submenuAnchor} style={{ anchorName: submenu.parentAnchor }} />}
520
+ <div className={css.viewport} role="presentation">
521
+ {items.map(entry => renderEntry(entry, itemColumns))}
522
+ {children}
523
+ </div>
524
+ {footer !== undefined && footer.length > 0 && (
525
+ <div className={css.footer} role="presentation">
526
+ {footer.map(entry => renderEntry(entry, footerColumns))}
527
+ </div>
528
+ )}
529
+ </MenuSurface>
530
+ )
531
+
532
+ // Pointer-leave dismissal watches the WRAPPER, not the list: React's
533
+ // enter/leave traversal runs over the React tree, so trigger and portaled
534
+ // list are one region here. Aiming back at the trigger, or crossing the 4px
535
+ // gap between them, therefore never counts as leaving.
536
+ return (
537
+ <span
538
+ ref={rootRef}
539
+ className={clsx(css.root, className)}
540
+ style={{ anchorName: anchorRef === undefined ? anchorName : undefined, ...(point === undefined ? {} : {
541
+ position: 'fixed', left: point.x, top: point.y, width: 0, height: 0,
542
+ }) }}
543
+ onPointerEnter={closeOnPointerLeave ? cancelClose : undefined}
544
+ onPointerLeave={closeOnPointerLeave ? (event) => { if (open && menuHoverAllowed(event)) armClose() } : undefined}
545
+ >
546
+ {anchor}
547
+ {portal ? (list !== false && createPortal(list, document.body)) : list}
548
+ {open && exiting === undefined && submenu.entry !== undefined && <SubmenuPanel key={submenu.entry.id}
549
+ entry={submenu.entry} submenu={submenu} compact={compact} dense={dense} contextual={contextual}
550
+ backLabel={submenuBackLabel ?? submenu.entry.label} onSelect={onSelect} onClose={onClose} afterSelection={refocusAfterSelection} />}
551
+ </span>
552
+ )
553
+ }
@@ -0,0 +1,37 @@
1
+ .group {
2
+ position: relative;
3
+ }
4
+
5
+ .start {
6
+ position: absolute;
7
+ top: 0;
8
+ left: 0;
9
+ width: 1px;
10
+ height: 1px;
11
+ opacity: 0;
12
+ pointer-events: none;
13
+ }
14
+
15
+ .group + .group {
16
+ margin-top: 3px;
17
+ }
18
+
19
+ .heading {
20
+ position: sticky;
21
+ top: 0;
22
+ z-index: 1;
23
+ padding: 4px 7px 2px;
24
+ background: transparent;
25
+ color: var(--dsw-alias-label-tertiary);
26
+ font-size: 11px;
27
+ line-height: 16px;
28
+ font-weight: 500;
29
+ }
30
+
31
+ .heading[data-stuck] {
32
+ background: var(--dsw-alias-menu-group-header-fill);
33
+ }
34
+
35
+ :global(html:not([data-platform='darwin'])) .heading {
36
+ border-radius: var(--dsw-radius-md);
37
+ }