@funstack/ui 0.1.0-alpha.19 → 0.1.0-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. package/dist/accordion/accordion-item.mjs +2 -2
  2. package/dist/accordion/accordion-item.mjs.map +1 -1
  3. package/dist/accordion/accordion-trigger.d.mts.map +1 -1
  4. package/dist/accordion/accordion-trigger.mjs +3 -20
  5. package/dist/accordion/accordion-trigger.mjs.map +1 -1
  6. package/dist/alert-dialog/alert-dialog-action.d.mts +73 -0
  7. package/dist/alert-dialog/alert-dialog-action.d.mts.map +1 -0
  8. package/dist/alert-dialog/alert-dialog-action.mjs +23 -0
  9. package/dist/alert-dialog/alert-dialog-action.mjs.map +1 -0
  10. package/dist/alert-dialog/alert-dialog-cancel.d.mts +31 -0
  11. package/dist/alert-dialog/alert-dialog-cancel.d.mts.map +1 -0
  12. package/dist/alert-dialog/alert-dialog-cancel.mjs +50 -0
  13. package/dist/alert-dialog/alert-dialog-cancel.mjs.map +1 -0
  14. package/dist/alert-dialog/alert-dialog-context.mjs +24 -0
  15. package/dist/alert-dialog/alert-dialog-context.mjs.map +1 -0
  16. package/dist/alert-dialog/alert-dialog-description.d.mts +25 -0
  17. package/dist/alert-dialog/alert-dialog-description.d.mts.map +1 -0
  18. package/dist/alert-dialog/alert-dialog-description.mjs +20 -0
  19. package/dist/alert-dialog/alert-dialog-description.mjs.map +1 -0
  20. package/dist/alert-dialog/alert-dialog-form.d.mts +27 -0
  21. package/dist/alert-dialog/alert-dialog-form.d.mts.map +1 -0
  22. package/dist/alert-dialog/alert-dialog-form.mjs +22 -0
  23. package/dist/alert-dialog/alert-dialog-form.mjs.map +1 -0
  24. package/dist/alert-dialog/alert-dialog-popup.d.mts +42 -0
  25. package/dist/alert-dialog/alert-dialog-popup.d.mts.map +1 -0
  26. package/dist/alert-dialog/alert-dialog-popup.mjs +53 -0
  27. package/dist/alert-dialog/alert-dialog-popup.mjs.map +1 -0
  28. package/dist/alert-dialog/alert-dialog-root.d.mts +31 -0
  29. package/dist/alert-dialog/alert-dialog-root.d.mts.map +1 -0
  30. package/dist/alert-dialog/alert-dialog-root.mjs +22 -0
  31. package/dist/alert-dialog/alert-dialog-root.mjs.map +1 -0
  32. package/dist/alert-dialog/alert-dialog-title.d.mts +23 -0
  33. package/dist/alert-dialog/alert-dialog-title.d.mts.map +1 -0
  34. package/dist/alert-dialog/alert-dialog-title.mjs +18 -0
  35. package/dist/alert-dialog/alert-dialog-title.mjs.map +1 -0
  36. package/dist/alert-dialog/alert-dialog-trigger.d.mts +23 -0
  37. package/dist/alert-dialog/alert-dialog-trigger.d.mts.map +1 -0
  38. package/dist/alert-dialog/alert-dialog-trigger.mjs +18 -0
  39. package/dist/alert-dialog/alert-dialog-trigger.mjs.map +1 -0
  40. package/dist/alert-dialog/index.d.mts +33 -0
  41. package/dist/alert-dialog/index.d.mts.map +1 -0
  42. package/dist/alert-dialog/index.mjs +33 -0
  43. package/dist/alert-dialog/index.mjs.map +1 -0
  44. package/dist/checkbox-group/checkbox-group-parent.mjs +1 -1
  45. package/dist/collapsible/collapsible-context.mjs +8 -0
  46. package/dist/collapsible/collapsible-context.mjs.map +1 -0
  47. package/dist/collapsible/collapsible-panel.d.mts +53 -0
  48. package/dist/collapsible/collapsible-panel.d.mts.map +1 -0
  49. package/dist/collapsible/collapsible-panel.mjs +41 -0
  50. package/dist/collapsible/collapsible-panel.mjs.map +1 -0
  51. package/dist/collapsible/collapsible-root.d.mts +108 -0
  52. package/dist/collapsible/collapsible-root.d.mts.map +1 -0
  53. package/dist/collapsible/collapsible-root.mjs +147 -0
  54. package/dist/collapsible/collapsible-root.mjs.map +1 -0
  55. package/dist/collapsible/collapsible-trigger.d.mts +45 -0
  56. package/dist/collapsible/collapsible-trigger.d.mts.map +1 -0
  57. package/dist/collapsible/collapsible-trigger.mjs +62 -0
  58. package/dist/collapsible/collapsible-trigger.mjs.map +1 -0
  59. package/dist/collapsible/index.d.mts +21 -0
  60. package/dist/collapsible/index.d.mts.map +1 -0
  61. package/dist/collapsible/index.mjs +21 -0
  62. package/dist/collapsible/index.mjs.map +1 -0
  63. package/dist/combobox/chip-text.mjs +24 -0
  64. package/dist/combobox/chip-text.mjs.map +1 -0
  65. package/dist/combobox/combobox-chips.d.mts +159 -0
  66. package/dist/combobox/combobox-chips.d.mts.map +1 -0
  67. package/dist/combobox/combobox-chips.mjs +198 -0
  68. package/dist/combobox/combobox-chips.mjs.map +1 -0
  69. package/dist/combobox/combobox-clear.d.mts +5 -2
  70. package/dist/combobox/combobox-clear.d.mts.map +1 -1
  71. package/dist/combobox/combobox-clear.mjs +3 -1
  72. package/dist/combobox/combobox-clear.mjs.map +1 -1
  73. package/dist/combobox/combobox-context.mjs +4 -5
  74. package/dist/combobox/combobox-context.mjs.map +1 -1
  75. package/dist/combobox/combobox-input.d.mts +10 -3
  76. package/dist/combobox/combobox-input.d.mts.map +1 -1
  77. package/dist/combobox/combobox-input.mjs +13 -5
  78. package/dist/combobox/combobox-input.mjs.map +1 -1
  79. package/dist/combobox/combobox-keyboard.mjs +50 -4
  80. package/dist/combobox/combobox-keyboard.mjs.map +1 -1
  81. package/dist/combobox/combobox-list.d.mts +1 -1
  82. package/dist/combobox/combobox-list.mjs +2 -1
  83. package/dist/combobox/combobox-list.mjs.map +1 -1
  84. package/dist/combobox/combobox-option.d.mts +5 -2
  85. package/dist/combobox/combobox-option.d.mts.map +1 -1
  86. package/dist/combobox/combobox-option.mjs +4 -3
  87. package/dist/combobox/combobox-option.mjs.map +1 -1
  88. package/dist/combobox/combobox-root.d.mts +127 -35
  89. package/dist/combobox/combobox-root.d.mts.map +1 -1
  90. package/dist/combobox/combobox-root.mjs +396 -44
  91. package/dist/combobox/combobox-root.mjs.map +1 -1
  92. package/dist/combobox/index.d.mts +8 -2
  93. package/dist/combobox/index.d.mts.map +1 -1
  94. package/dist/combobox/index.mjs +7 -1
  95. package/dist/combobox/index.mjs.map +1 -1
  96. package/dist/combobox/use-combobox-form.mjs +2 -3
  97. package/dist/combobox/use-combobox-form.mjs.map +1 -1
  98. package/dist/dialog/dialog-close.d.mts +9 -5
  99. package/dist/dialog/dialog-close.d.mts.map +1 -1
  100. package/dist/dialog/dialog-close.mjs +19 -8
  101. package/dist/dialog/dialog-close.mjs.map +1 -1
  102. package/dist/dialog/dialog-context.d.mts +2 -0
  103. package/dist/dialog/dialog-context.mjs +14 -2
  104. package/dist/dialog/dialog-context.mjs.map +1 -1
  105. package/dist/dialog/dialog-description.d.mts +2 -1
  106. package/dist/dialog/dialog-description.d.mts.map +1 -1
  107. package/dist/dialog/dialog-description.mjs +8 -4
  108. package/dist/dialog/dialog-description.mjs.map +1 -1
  109. package/dist/dialog/dialog-form.d.mts +2 -1
  110. package/dist/dialog/dialog-form.d.mts.map +1 -1
  111. package/dist/dialog/dialog-form.mjs +11 -6
  112. package/dist/dialog/dialog-form.mjs.map +1 -1
  113. package/dist/dialog/dialog-popup.d.mts +2 -1
  114. package/dist/dialog/dialog-popup.d.mts.map +1 -1
  115. package/dist/dialog/dialog-popup.mjs +23 -14
  116. package/dist/dialog/dialog-popup.mjs.map +1 -1
  117. package/dist/dialog/dialog-root.d.mts +2 -1
  118. package/dist/dialog/dialog-root.d.mts.map +1 -1
  119. package/dist/dialog/dialog-root.mjs +15 -5
  120. package/dist/dialog/dialog-root.mjs.map +1 -1
  121. package/dist/dialog/dialog-title.d.mts +2 -1
  122. package/dist/dialog/dialog-title.d.mts.map +1 -1
  123. package/dist/dialog/dialog-title.mjs +8 -4
  124. package/dist/dialog/dialog-title.mjs.map +1 -1
  125. package/dist/dialog/dialog-trigger.d.mts +2 -1
  126. package/dist/dialog/dialog-trigger.d.mts.map +1 -1
  127. package/dist/dialog/dialog-trigger.mjs +14 -9
  128. package/dist/dialog/dialog-trigger.mjs.map +1 -1
  129. package/dist/docs/components/accordion.md +2 -0
  130. package/dist/docs/components/alert-dialog.md +546 -0
  131. package/dist/docs/components/collapsible.md +408 -0
  132. package/dist/docs/components/combobox.md +288 -26
  133. package/dist/docs/components/dialog.md +7 -5
  134. package/dist/docs/components/field.md +180 -3
  135. package/dist/docs/components/hover-card.md +494 -0
  136. package/dist/docs/components/multi-select.md +622 -0
  137. package/dist/docs/components/number-field.md +1 -1
  138. package/dist/docs/components/popover.md +4 -4
  139. package/dist/docs/components/select.md +9 -1
  140. package/dist/docs/components/separator.md +182 -0
  141. package/dist/docs/components/slider.md +1 -1
  142. package/dist/docs/components/tooltip.md +1 -1
  143. package/dist/docs/concepts/experimental.md +3 -3
  144. package/dist/docs/concepts/server-components.md +1 -1
  145. package/dist/docs/index.md +7 -2
  146. package/dist/docs/roadmap.md +8 -0
  147. package/dist/field/field-control.d.mts +13 -4
  148. package/dist/field/field-control.d.mts.map +1 -1
  149. package/dist/field/field-control.mjs +39 -10
  150. package/dist/field/field-control.mjs.map +1 -1
  151. package/dist/field/field-label.d.mts +6 -2
  152. package/dist/field/field-label.d.mts.map +1 -1
  153. package/dist/field/field-label.mjs +12 -2
  154. package/dist/field/field-label.mjs.map +1 -1
  155. package/dist/field/field-root.mjs +9 -1
  156. package/dist/field/field-root.mjs.map +1 -1
  157. package/dist/hover-card/hover-card-context.mjs +13 -0
  158. package/dist/hover-card/hover-card-context.mjs.map +1 -0
  159. package/dist/hover-card/hover-card-popup.d.mts +102 -0
  160. package/dist/hover-card/hover-card-popup.d.mts.map +1 -0
  161. package/dist/hover-card/hover-card-popup.mjs +80 -0
  162. package/dist/hover-card/hover-card-popup.mjs.map +1 -0
  163. package/dist/hover-card/hover-card-root.d.mts +94 -0
  164. package/dist/hover-card/hover-card-root.d.mts.map +1 -0
  165. package/dist/hover-card/hover-card-root.mjs +74 -0
  166. package/dist/hover-card/hover-card-root.mjs.map +1 -0
  167. package/dist/hover-card/hover-card-trigger.d.mts +65 -0
  168. package/dist/hover-card/hover-card-trigger.d.mts.map +1 -0
  169. package/dist/hover-card/hover-card-trigger.mjs +109 -0
  170. package/dist/hover-card/hover-card-trigger.mjs.map +1 -0
  171. package/dist/hover-card/index.d.mts +24 -0
  172. package/dist/hover-card/index.d.mts.map +1 -0
  173. package/dist/hover-card/index.mjs +24 -0
  174. package/dist/hover-card/index.mjs.map +1 -0
  175. package/dist/hover-card/use-hover-card-interest.mjs +242 -0
  176. package/dist/hover-card/use-hover-card-interest.mjs.map +1 -0
  177. package/dist/index.d.mts +38 -9
  178. package/dist/index.mjs +6 -1
  179. package/dist/internal/action/use-multiple-selection.mjs +83 -0
  180. package/dist/internal/action/use-multiple-selection.mjs.map +1 -0
  181. package/dist/internal/details-summary.mjs +56 -0
  182. package/dist/internal/details-summary.mjs.map +1 -0
  183. package/dist/internal/form/field-context.mjs.map +1 -1
  184. package/dist/internal/form/hidden-values.mjs +29 -0
  185. package/dist/internal/form/hidden-values.mjs.map +1 -0
  186. package/dist/internal/form/validity.mjs +3 -1
  187. package/dist/internal/form/validity.mjs.map +1 -1
  188. package/dist/internal/overlay/use-interest-dismiss.mjs +2 -1
  189. package/dist/internal/overlay/use-interest-dismiss.mjs.map +1 -1
  190. package/dist/internal/overlay/use-overlay-close.mjs +5 -3
  191. package/dist/internal/overlay/use-overlay-close.mjs.map +1 -1
  192. package/dist/internal/overlay/use-overlay-root.mjs +4 -1
  193. package/dist/internal/overlay/use-overlay-root.mjs.map +1 -1
  194. package/dist/internal/overlay/use-popover-popup.mjs +20 -7
  195. package/dist/internal/overlay/use-popover-popup.mjs.map +1 -1
  196. package/dist/internal/overlay/use-popover-trigger.d.mts +1 -1
  197. package/dist/internal/typeahead.mjs +52 -0
  198. package/dist/internal/typeahead.mjs.map +1 -0
  199. package/dist/{combobox → internal}/use-active-option.mjs +8 -6
  200. package/dist/internal/use-active-option.mjs.map +1 -0
  201. package/dist/{combobox → internal}/use-deferred-leave.mjs +20 -12
  202. package/dist/internal/use-deferred-leave.mjs.map +1 -0
  203. package/dist/internal/use-name-warning.mjs +57 -1
  204. package/dist/internal/use-name-warning.mjs.map +1 -1
  205. package/dist/internal/use-option-registry.mjs +70 -0
  206. package/dist/internal/use-option-registry.mjs.map +1 -0
  207. package/dist/menu/use-menu-keyboard.mjs +7 -27
  208. package/dist/menu/use-menu-keyboard.mjs.map +1 -1
  209. package/dist/multi-select/index.d.mts +37 -0
  210. package/dist/multi-select/index.d.mts.map +1 -0
  211. package/dist/multi-select/index.mjs +37 -0
  212. package/dist/multi-select/index.mjs.map +1 -0
  213. package/dist/multi-select/multi-select-context.mjs +19 -0
  214. package/dist/multi-select/multi-select-context.mjs.map +1 -0
  215. package/dist/multi-select/multi-select-group.d.mts +120 -0
  216. package/dist/multi-select/multi-select-group.d.mts.map +1 -0
  217. package/dist/multi-select/multi-select-group.mjs +111 -0
  218. package/dist/multi-select/multi-select-group.mjs.map +1 -0
  219. package/dist/multi-select/multi-select-keyboard.mjs +145 -0
  220. package/dist/multi-select/multi-select-keyboard.mjs.map +1 -0
  221. package/dist/multi-select/multi-select-label.d.mts +42 -0
  222. package/dist/multi-select/multi-select-label.d.mts.map +1 -0
  223. package/dist/multi-select/multi-select-label.mjs +41 -0
  224. package/dist/multi-select/multi-select-label.mjs.map +1 -0
  225. package/dist/multi-select/multi-select-list.d.mts +47 -0
  226. package/dist/multi-select/multi-select-list.d.mts.map +1 -0
  227. package/dist/multi-select/multi-select-list.mjs +65 -0
  228. package/dist/multi-select/multi-select-list.mjs.map +1 -0
  229. package/dist/multi-select/multi-select-option.d.mts +68 -0
  230. package/dist/multi-select/multi-select-option.d.mts.map +1 -0
  231. package/dist/multi-select/multi-select-option.mjs +93 -0
  232. package/dist/multi-select/multi-select-option.mjs.map +1 -0
  233. package/dist/multi-select/multi-select-popup.d.mts +58 -0
  234. package/dist/multi-select/multi-select-popup.d.mts.map +1 -0
  235. package/dist/multi-select/multi-select-popup.mjs +71 -0
  236. package/dist/multi-select/multi-select-popup.mjs.map +1 -0
  237. package/dist/multi-select/multi-select-root.d.mts +125 -0
  238. package/dist/multi-select/multi-select-root.d.mts.map +1 -0
  239. package/dist/multi-select/multi-select-root.mjs +257 -0
  240. package/dist/multi-select/multi-select-root.mjs.map +1 -0
  241. package/dist/multi-select/multi-select-trigger.d.mts +66 -0
  242. package/dist/multi-select/multi-select-trigger.d.mts.map +1 -0
  243. package/dist/multi-select/multi-select-trigger.mjs +169 -0
  244. package/dist/multi-select/multi-select-trigger.mjs.map +1 -0
  245. package/dist/multi-select/multi-select-value.d.mts +57 -0
  246. package/dist/multi-select/multi-select-value.d.mts.map +1 -0
  247. package/dist/multi-select/multi-select-value.mjs +41 -0
  248. package/dist/multi-select/multi-select-value.mjs.map +1 -0
  249. package/dist/number-field/number-field-root.mjs +1 -1
  250. package/dist/number-field/use-step-button.d.mts.map +1 -1
  251. package/dist/number-field/use-step-button.mjs +11 -2
  252. package/dist/number-field/use-step-button.mjs.map +1 -1
  253. package/dist/popover/popover-close.d.mts +6 -3
  254. package/dist/popover/popover-close.d.mts.map +1 -1
  255. package/dist/popover/popover-close.mjs +3 -2
  256. package/dist/popover/popover-close.mjs.map +1 -1
  257. package/dist/popover/popover-popup.mjs +1 -1
  258. package/dist/select/select-root.d.mts +1 -1
  259. package/dist/select/select-root.d.mts.map +1 -1
  260. package/dist/select/select-root.mjs +5 -1
  261. package/dist/select/select-root.mjs.map +1 -1
  262. package/dist/separator/index.d.mts +3 -0
  263. package/dist/separator/index.mjs +1 -0
  264. package/dist/separator/separator.d.mts +58 -0
  265. package/dist/separator/separator.d.mts.map +1 -0
  266. package/dist/separator/separator.mjs +41 -0
  267. package/dist/separator/separator.mjs.map +1 -0
  268. package/dist/slider/slider-root.mjs +1 -0
  269. package/dist/slider/slider-root.mjs.map +1 -1
  270. package/dist/toast/toast-viewport.mjs +1 -1
  271. package/package.json +6 -1
  272. package/skills/funstack-ui-knowledge/SKILL.md +14 -9
  273. package/dist/combobox/use-active-option.mjs.map +0 -1
  274. package/dist/combobox/use-deferred-leave.mjs.map +0 -1
  275. package/dist/combobox/use-option-registry.mjs +0 -52
  276. package/dist/combobox/use-option-registry.mjs.map +0 -1
@@ -9,8 +9,13 @@ import { useDialogContext } from "./dialog-context.mjs";
9
9
  *
10
10
  * @see https://ui.funstack.work/components/dialog
11
11
  */
12
- function DialogDescription({ className, style, children, render, ...rest }) {
13
- const ctx = useDialogContext("Dialog.Description");
12
+ function DialogDescription(props) {
13
+ return useDialogDescription(props, "Dialog");
14
+ }
15
+ DialogDescription.displayName = "DialogDescription";
16
+ /** The body of `Dialog.Description`, also run by `AlertDialog.Description` (alert-dialog.md 8). */
17
+ function useDialogDescription({ className, style, children, render, ...rest }, namespace) {
18
+ const ctx = useDialogContext(`${namespace}.Description`);
14
19
  const state = {
15
20
  open: ctx.committed,
16
21
  modal: ctx.modal
@@ -26,8 +31,7 @@ function DialogDescription({ className, style, children, render, ...rest }) {
26
31
  libraryProps: { id: ctx.ids.description }
27
32
  });
28
33
  }
29
- DialogDescription.displayName = "DialogDescription";
30
34
  //#endregion
31
- export { DialogDescription };
35
+ export { DialogDescription, useDialogDescription };
32
36
 
33
37
  //# sourceMappingURL=dialog-description.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"dialog-description.mjs","names":[],"sources":["../../src/dialog/dialog-description.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { useDialogContext } from \"./dialog-context.js\";\nimport type { DialogPopupState } from \"./dialog-popup.js\";\n\n/** State of `Dialog.Description`: the Popup's state. */\nexport type DialogDescriptionState = DialogPopupState;\n\n/**\n * Props of `Dialog.Description`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport interface DialogDescriptionProps extends Omit<\n ComponentPropsWithRef<\"p\">,\n \"id\" | \"className\" | \"style\" | \"children\"\n> {\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, DialogDescriptionState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, DialogDescriptionState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, DialogDescriptionState>;\n /** Replace the default `<p>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"p\">, DialogDescriptionState>;\n}\n\n/**\n * The dialog's description: a `<p>` whose id the Popup references with `aria-describedby`.\n *\n * Owned key (conventions 1.2): `id`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport function DialogDescription({\n className,\n style,\n children,\n render,\n ...rest\n}: DialogDescriptionProps) {\n const ctx = useDialogContext(\"Dialog.Description\");\n const state: DialogDescriptionState = { open: ctx.committed, modal: ctx.modal };\n return useRender<ComponentPropsWithRef<\"p\">, DialogDescriptionState>({\n defaultElement: \"p\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: { id: ctx.ids.description },\n });\n}\n\nDialogDescription.displayName = \"DialogDescription\";\n"],"mappings":";;;;;;;;;;;AAoCA,SAAgB,kBAAkB,EAChC,WACA,OACA,UACA,QACA,GAAG,QACsB;CACzB,MAAM,MAAM,iBAAiB,oBAAoB;CACjD,MAAM,QAAgC;EAAE,MAAM,IAAI;EAAW,OAAO,IAAI;CAAM;CAC9E,OAAO,UAA8D;EACnE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP,cAAc,EAAE,IAAI,IAAI,IAAI,YAAY;CAC1C,CAAC;AACH;AAEA,kBAAkB,cAAc"}
1
+ {"version":3,"file":"dialog-description.mjs","names":[],"sources":["../../src/dialog/dialog-description.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { useDialogContext } from \"./dialog-context.js\";\nimport type { DialogNamespace } from \"./dialog-context.js\";\nimport type { DialogPopupState } from \"./dialog-popup.js\";\n\n/** State of `Dialog.Description`: the Popup's state. */\nexport type DialogDescriptionState = DialogPopupState;\n\n/**\n * Props of `Dialog.Description`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport interface DialogDescriptionProps extends Omit<\n ComponentPropsWithRef<\"p\">,\n \"id\" | \"className\" | \"style\" | \"children\"\n> {\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, DialogDescriptionState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, DialogDescriptionState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, DialogDescriptionState>;\n /** Replace the default `<p>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"p\">, DialogDescriptionState>;\n}\n\n/**\n * The dialog's description: a `<p>` whose id the Popup references with `aria-describedby`.\n *\n * Owned key (conventions 1.2): `id`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport function DialogDescription(props: DialogDescriptionProps) {\n return useDialogDescription(props, \"Dialog\");\n}\n\nDialogDescription.displayName = \"DialogDescription\";\n\n/** The body of `Dialog.Description`, also run by `AlertDialog.Description` (alert-dialog.md 8). */\nexport function useDialogDescription(\n { className, style, children, render, ...rest }: DialogDescriptionProps,\n namespace: DialogNamespace,\n): ReactNode {\n const ctx = useDialogContext(`${namespace}.Description`);\n const state: DialogDescriptionState = { open: ctx.committed, modal: ctx.modal };\n return useRender<ComponentPropsWithRef<\"p\">, DialogDescriptionState>({\n defaultElement: \"p\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: { id: ctx.ids.description },\n });\n}\n"],"mappings":";;;;;;;;;;;AAqCA,SAAgB,kBAAkB,OAA+B;CAC/D,OAAO,qBAAqB,OAAO,QAAQ;AAC7C;AAEA,kBAAkB,cAAc;;AAGhC,SAAgB,qBACd,EAAE,WAAW,OAAO,UAAU,QAAQ,GAAG,QACzC,WACW;CACX,MAAM,MAAM,iBAAiB,GAAG,UAAU,aAAa;CACvD,MAAM,QAAgC;EAAE,MAAM,IAAI;EAAW,OAAO,IAAI;CAAM;CAC9E,OAAO,UAA8D;EACnE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP,cAAc,EAAE,IAAI,IAAI,IAAI,YAAY;CAC1C,CAAC;AACH"}
@@ -1,4 +1,5 @@
1
1
  import { RenderProp, StateValue } from "../internal/types.mjs";
2
+ import "./dialog-context.mjs";
2
3
  import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
3
4
  //#region src/dialog/dialog-form.d.ts
4
5
  /**
@@ -81,7 +82,7 @@ export interface DialogFormProps extends Omit<ComponentPropsWithRef<"form">, "me
81
82
  *
82
83
  * @see https://ui.funstack.work/components/dialog
83
84
  */
84
- export declare function DialogForm({ action, closeOnSettle, method, className, style, children, render, ...rest }: DialogFormProps): ReactNode;
85
+ export declare function DialogForm(props: DialogFormProps): ReactNode;
85
86
  export declare namespace DialogForm {
86
87
  var displayName: string;
87
88
  }
@@ -1 +1 @@
1
- {"version":3,"file":"dialog-form.d.mts","names":[],"sources":["../../src/dialog/dialog-form.tsx"],"mappings":";;;;;;;iBAiBiB;;WAEN;;;;;;;iBAQM,wBAAwB,KACvC;;;;;;;;;;;;;EAeA,oBAAoB,UAAU;;;;;;;;;;;;;;;;;;;;;EAqB9B;;;;;EAKA,SAAS;;EAET,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,+BAA+B;;;;;;;;;;;;;;;;;;;;wBAqBrC,aACd,QACA,eACA,QACA,WACA,OACA,UACA,WACG,QACF,kBAAe;yBATF"}
1
+ {"version":3,"file":"dialog-form.d.mts","names":[],"sources":["../../src/dialog/dialog-form.tsx"],"mappings":";;;;;;;;iBAkBiB;;WAEN;;;;;;;iBAQM,wBAAwB,KACvC;;;;;;;;;;;;;EAeA,oBAAoB,UAAU;;;;;;;;;;;;;;;;;;;;;EAqB9B;;;;;EAKA,SAAS;;EAET,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,+BAA+B;;;;;;;;;;;;;;;;;;;;wBAqBrC,WAAW,OAAO,kBAAe;yBAAjC"}
@@ -28,8 +28,13 @@ const isDev = process.env.NODE_ENV !== "production";
28
28
  *
29
29
  * @see https://ui.funstack.work/components/dialog
30
30
  */
31
- function DialogForm({ action, closeOnSettle = true, method, className, style, children, render, ...rest }) {
32
- const ctx = useDialogContext("Dialog.Form");
31
+ function DialogForm(props) {
32
+ return useDialogForm(props, "Dialog");
33
+ }
34
+ DialogForm.displayName = "DialogForm";
35
+ /** The body of `Dialog.Form`, also run by `AlertDialog.Form` (alert-dialog.md 8). */
36
+ function useDialogForm({ action, closeOnSettle = true, method, className, style, children, render, ...rest }, namespace) {
37
+ const ctx = useDialogContext(`${namespace}.Form`);
33
38
  const { popupRef, recordCloseIntent, requestClose } = ctx;
34
39
  const isLibrary = ctx.mode === "library";
35
40
  const [pending, setPending] = useState(false);
@@ -88,6 +93,7 @@ function DialogForm({ action, closeOnSettle = true, method, className, style, ch
88
93
  className,
89
94
  style,
90
95
  children: (s) => /* @__PURE__ */ jsxs(Fragment, { children: [resolveStateValue(children, s), /* @__PURE__ */ jsx(DialogFormSettle, {
96
+ namespace,
91
97
  watches,
92
98
  missingAction: action === void 0,
93
99
  onPendingChange: setPending,
@@ -101,16 +107,15 @@ function DialogForm({ action, closeOnSettle = true, method, className, style, ch
101
107
  ref: libraryRef
102
108
  });
103
109
  }
104
- DialogForm.displayName = "DialogForm";
105
110
  /**
106
111
  * Rendered among the form's children, so it reads the `FormContext` exactly when the form is a
107
112
  * `Form.Root` (either orientation of the `render` composition): the settle close then waits for
108
113
  * a result with no field error (`hasAnyError`, the `autoReset` predicate, hidden stale entries
109
114
  * included).
110
115
  */
111
- function DialogFormSettle({ watches, missingAction, onPendingChange, onSettled }) {
116
+ function DialogFormSettle({ namespace, watches, missingAction, onPendingChange, onSettled }) {
112
117
  const form = use(FormContext);
113
- useDevWarning(form !== null && missingAction, isDev && "Dialog.Form: rendered as a `Form.Root`, it needs a function `action`; without one the form navigates instead of closing the dialog. Render a plain `<Dialog.Form>` for a `method=\"dialog\"` form.");
118
+ useDevWarning(form !== null && missingAction, isDev && `${namespace}.Form: rendered as a \`Form.Root\`, it needs a function \`action\`; without one the form navigates instead of closing the dialog. Render a plain \`<${namespace}.Form>\` for a \`method="dialog"\` form.`);
114
119
  const isForm = form !== null;
115
120
  const errors = form?.errors;
116
121
  const settled = useCallback(() => onSettled(!isForm || !hasAnyError(errors)), [
@@ -125,6 +130,6 @@ function DialogFormSettle({ watches, missingAction, onPendingChange, onSettled }
125
130
  });
126
131
  }
127
132
  //#endregion
128
- export { DialogForm };
133
+ export { DialogForm, useDialogForm };
129
134
 
130
135
  //# sourceMappingURL=dialog-form.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"dialog-form.mjs","names":[],"sources":["../../src/dialog/dialog-form.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useRef, useState } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { FormContext } from \"../internal/form/field-context.js\";\nimport { FormStatusWatcher } from \"../internal/form/form-status-watcher.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport { hasAnyError } from \"../internal/form/validity.js\";\nimport { useDialogContext } from \"./dialog-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `Dialog.Form`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface DialogFormState {\n /** `useFormStatus().pending` of this form, exposed for `className` / `children` functions. */\n readonly pending: boolean;\n}\n\n/**\n * Props of `Dialog.Form`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport interface DialogFormProps extends Omit<\n ComponentPropsWithRef<\"form\">,\n \"method\" | \"action\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * React form action (`(formData) => unknown`, may be a Server Function). Passed to the form\n * unwrapped so React's progressive enhancement is kept; the dialog closes with the submitter's\n * `value` as `returnValue` once the action's transition settles (see `closeOnSettle`): in\n * library mode through the Root (`openChangeAction(false)` awaited, view transition if set),\n * in JS-free mode with `close(value)`. A rejection leaves the dialog open. Without `action`\n * the form renders `method=\"dialog\"`: submitting closes the dialog, natively in JS-free mode\n * and through the Root in library mode (a `preventDefault()` in your own `onSubmit` blocks\n * both; `stopPropagation()` there leaves the close to the browser, reported to `onOpenChange`\n * as a fact).\n * A string `action` (a URL) is a plain navigating form.\n */\n action?: string | ((formData: FormData) => unknown);\n /**\n * With a function `action`: close the dialog once the action's transition settles without\n * throwing and, when this form is rendered as a `Form.Root`\n * (`render={<Form.Root errors={state.errors} />}`), with no field error: a settle whose\n * `errors` has a non-empty entry (hidden stale ones included, the `autoReset` rule) keeps\n * the dialog open and the Form focuses the first errored field.\n *\n * Without a `Form.Root` the library never sees a result, so any settle that does not throw\n * counts, including a `useActionState` result that reports errors: render the form as a\n * `Form.Root` to route them, throw to keep the dialog open, or set `closeOnSettle={false}`\n * and close it yourself (a `Dialog.Close`, a submit button in a separate `method=\"dialog\"`\n * form, or a controlled `open`). A `formMethod=\"dialog\"` submitter inside this form cannot\n * close it: React prevents every submit of a form with a function `action` and runs the\n * action again.\n *\n * The dialog is not closed either when it was closed (Escape, a Close part) while the action\n * ran, also if the user re-opened it meanwhile.\n *\n * @defaultValue `true`\n */\n closeOnSettle?: boolean;\n /**\n * Only with a string `action` (a navigating form, for example `\"post\"`). Owned otherwise:\n * `\"dialog\"` without `action`, React's own with a function `action`.\n */\n method?: ComponentPropsWithRef<\"form\">[\"method\"];\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, DialogFormState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, DialogFormState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, DialogFormState>;\n /** Replace the default `<form>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"form\">, DialogFormState>;\n}\n\n/**\n * A form that completes the dialog. Without `action`: `<form method=\"dialog\">`, so a submit\n * closes the dialog with the submitter's `value` as `returnValue` (natively in JS-free mode;\n * in library mode the Popup cancels the submission and closes through the Root). With a\n * function `action`: `<form action={action}>` (React overrides the method) and a status watcher\n * that closes the dialog once the action has settled, with the submitter's `value`, unless\n * `closeOnSettle` is `false`, the dialog was closed while the action ran, or the form is rendered\n * as a `Form.Root` and the result has a field error (`render={<Form.Root errors={...} />}`, the\n * recommended composition for validation).\n *\n * `DialogFormState.pending` is this form's own status; it is not emitted as `data-pending` and\n * is not folded into any control's `pending` (conventions 2.7). Submit buttons read\n * `useFormStatus()` themselves.\n *\n * Owned keys (conventions 1.2): `method` (except with a string `action`), `action`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport function DialogForm({\n action,\n closeOnSettle = true,\n method,\n className,\n style,\n children,\n render,\n ...rest\n}: DialogFormProps) {\n const ctx = useDialogContext(\"Dialog.Form\");\n const { popupRef, recordCloseIntent, requestClose } = ctx;\n const isLibrary = ctx.mode === \"library\";\n const [pending, setPending] = useState(false);\n const submission = useRef<{ event: Event; returnValue: string } | null>(null);\n // The dialog closed after the last submit (Escape, a Close part): the settle must not close it\n // again, also when the user re-opened it meanwhile.\n const closedSinceSubmit = useRef(false);\n const watches = typeof action === \"function\";\n\n // The submitter's `value` comes from the native `submit` event (capture, before React's\n // handler runs the action).\n const libraryRef = useCallback((form: HTMLFormElement) => {\n const onSubmit = (event: Event) => {\n if (event.target !== form) return;\n const submitter = (event as SubmitEvent).submitter as\n | HTMLButtonElement\n | HTMLInputElement\n | null;\n submission.current = { event, returnValue: submitter?.value ?? \"\" };\n closedSinceSubmit.current = false;\n };\n const dialog = form.closest(\"dialog\");\n const onClose = (event: Event) => {\n if (event.target === dialog) closedSinceSubmit.current = true;\n };\n form.addEventListener(\"submit\", onSubmit, true);\n dialog?.addEventListener(\"close\", onClose);\n return () => {\n form.removeEventListener(\"submit\", onSubmit, true);\n dialog?.removeEventListener(\"close\", onClose);\n };\n }, []);\n\n // `clean`: no field error in the settle's result (always `true` without a `Form.Root`).\n const onSettled = useCallback(\n (clean: boolean) => {\n const dialog = popupRef.current;\n const submitted = submission.current;\n submission.current = null;\n if (!closeOnSettle || closedSinceSubmit.current) return;\n // A result with field errors keeps the dialog open; the Form.Root focuses the first errored\n // field (design/components/dialog.md, \"Dialog.Form and Form.Root\").\n if (!clean) return;\n if (dialog === null || !dialog.open) return;\n const returnValue = submitted?.returnValue ?? \"\";\n if (isLibrary) {\n // A library-owned close (design 2.3): `openChangeAction(false)` awaited, then\n // `close(returnValue)` in the commit, inside the view transition if set.\n requestClose(submitted?.event, \"activate\", returnValue);\n return;\n }\n recordCloseIntent({ reason: \"activate\", event: submitted?.event });\n dialog.close(returnValue);\n },\n [closeOnSettle, popupRef, isLibrary, recordCloseIntent, requestClose],\n );\n\n const state: DialogFormState = { pending };\n\n return useRender<ComponentPropsWithRef<\"form\">, DialogFormState>({\n defaultElement: \"form\",\n render,\n state,\n className,\n style,\n children: (s) => (\n <>\n {resolveStateValue(children, s)}\n <DialogFormSettle\n watches={watches}\n missingAction={action === undefined}\n onPendingChange={setPending}\n onSettled={onSettled}\n />\n </>\n ),\n props: rest,\n libraryProps: {\n method: action === undefined ? \"dialog\" : typeof action === \"string\" ? method : undefined,\n // React's own type wants `void | Promise<void>`; the library's actions return `unknown`\n // (conventions 2.2) and React ignores the result.\n action: action as ComponentPropsWithRef<\"form\">[\"action\"],\n },\n ref: libraryRef,\n });\n}\n\nDialogForm.displayName = \"DialogForm\";\n\n/**\n * Rendered among the form's children, so it reads the `FormContext` exactly when the form is a\n * `Form.Root` (either orientation of the `render` composition): the settle close then waits for\n * a result with no field error (`hasAnyError`, the `autoReset` predicate, hidden stale entries\n * included).\n */\nfunction DialogFormSettle({\n watches,\n missingAction,\n onPendingChange,\n onSettled,\n}: {\n readonly watches: boolean;\n readonly missingAction: boolean;\n readonly onPendingChange: (pending: boolean) => void;\n readonly onSettled: (clean: boolean) => void;\n}) {\n const form = use(FormContext);\n useDevWarning(\n form !== null && missingAction,\n isDev &&\n \"Dialog.Form: rendered as a `Form.Root`, it needs a function `action`; without one the form \" +\n \"navigates instead of closing the dialog. Render a plain `<Dialog.Form>` for a \" +\n '`method=\"dialog\"` form.',\n );\n const isForm = form !== null;\n const errors = form?.errors;\n const settled = useCallback(\n () => onSettled(!isForm || !hasAnyError(errors)),\n [isForm, errors, onSettled],\n );\n if (!watches) return null;\n return <FormStatusWatcher onPendingChange={onPendingChange} onSettled={settled} />;\n}\n"],"mappings":";;;;;;;;;;;AAWA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;;;;;AAuFvC,SAAgB,WAAW,EACzB,QACA,gBAAgB,MAChB,QACA,WACA,OACA,UACA,QACA,GAAG,QACe;CAClB,MAAM,MAAM,iBAAiB,aAAa;CAC1C,MAAM,EAAE,UAAU,mBAAmB,iBAAiB;CACtD,MAAM,YAAY,IAAI,SAAS;CAC/B,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,aAAa,OAAqD,IAAI;CAG5E,MAAM,oBAAoB,OAAO,KAAK;CACtC,MAAM,UAAU,OAAO,WAAW;CAIlC,MAAM,aAAa,aAAa,SAA0B;EACxD,MAAM,YAAY,UAAiB;GACjC,IAAI,MAAM,WAAW,MAAM;GAC3B,MAAM,YAAa,MAAsB;GAIzC,WAAW,UAAU;IAAE;IAAO,aAAa,WAAW,SAAS;GAAG;GAClE,kBAAkB,UAAU;EAC9B;EACA,MAAM,SAAS,KAAK,QAAQ,QAAQ;EACpC,MAAM,WAAW,UAAiB;GAChC,IAAI,MAAM,WAAW,QAAQ,kBAAkB,UAAU;EAC3D;EACA,KAAK,iBAAiB,UAAU,UAAU,IAAI;EAC9C,QAAQ,iBAAiB,SAAS,OAAO;EACzC,aAAa;GACX,KAAK,oBAAoB,UAAU,UAAU,IAAI;GAC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AoC;EAAiB,WAAW;CAAU,CAAA;AACnF"}
1
+ {"version":3,"file":"dialog-form.mjs","names":[],"sources":["../../src/dialog/dialog-form.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useRef, useState } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { FormContext } from \"../internal/form/field-context.js\";\nimport { FormStatusWatcher } from \"../internal/form/form-status-watcher.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport { hasAnyError } from \"../internal/form/validity.js\";\nimport { useDialogContext } from \"./dialog-context.js\";\nimport type { DialogNamespace } from \"./dialog-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `Dialog.Form`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface DialogFormState {\n /** `useFormStatus().pending` of this form, exposed for `className` / `children` functions. */\n readonly pending: boolean;\n}\n\n/**\n * Props of `Dialog.Form`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport interface DialogFormProps extends Omit<\n ComponentPropsWithRef<\"form\">,\n \"method\" | \"action\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * React form action (`(formData) => unknown`, may be a Server Function). Passed to the form\n * unwrapped so React's progressive enhancement is kept; the dialog closes with the submitter's\n * `value` as `returnValue` once the action's transition settles (see `closeOnSettle`): in\n * library mode through the Root (`openChangeAction(false)` awaited, view transition if set),\n * in JS-free mode with `close(value)`. A rejection leaves the dialog open. Without `action`\n * the form renders `method=\"dialog\"`: submitting closes the dialog, natively in JS-free mode\n * and through the Root in library mode (a `preventDefault()` in your own `onSubmit` blocks\n * both; `stopPropagation()` there leaves the close to the browser, reported to `onOpenChange`\n * as a fact).\n * A string `action` (a URL) is a plain navigating form.\n */\n action?: string | ((formData: FormData) => unknown);\n /**\n * With a function `action`: close the dialog once the action's transition settles without\n * throwing and, when this form is rendered as a `Form.Root`\n * (`render={<Form.Root errors={state.errors} />}`), with no field error: a settle whose\n * `errors` has a non-empty entry (hidden stale ones included, the `autoReset` rule) keeps\n * the dialog open and the Form focuses the first errored field.\n *\n * Without a `Form.Root` the library never sees a result, so any settle that does not throw\n * counts, including a `useActionState` result that reports errors: render the form as a\n * `Form.Root` to route them, throw to keep the dialog open, or set `closeOnSettle={false}`\n * and close it yourself (a `Dialog.Close`, a submit button in a separate `method=\"dialog\"`\n * form, or a controlled `open`). A `formMethod=\"dialog\"` submitter inside this form cannot\n * close it: React prevents every submit of a form with a function `action` and runs the\n * action again.\n *\n * The dialog is not closed either when it was closed (Escape, a Close part) while the action\n * ran, also if the user re-opened it meanwhile.\n *\n * @defaultValue `true`\n */\n closeOnSettle?: boolean;\n /**\n * Only with a string `action` (a navigating form, for example `\"post\"`). Owned otherwise:\n * `\"dialog\"` without `action`, React's own with a function `action`.\n */\n method?: ComponentPropsWithRef<\"form\">[\"method\"];\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, DialogFormState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, DialogFormState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, DialogFormState>;\n /** Replace the default `<form>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"form\">, DialogFormState>;\n}\n\n/**\n * A form that completes the dialog. Without `action`: `<form method=\"dialog\">`, so a submit\n * closes the dialog with the submitter's `value` as `returnValue` (natively in JS-free mode;\n * in library mode the Popup cancels the submission and closes through the Root). With a\n * function `action`: `<form action={action}>` (React overrides the method) and a status watcher\n * that closes the dialog once the action has settled, with the submitter's `value`, unless\n * `closeOnSettle` is `false`, the dialog was closed while the action ran, or the form is rendered\n * as a `Form.Root` and the result has a field error (`render={<Form.Root errors={...} />}`, the\n * recommended composition for validation).\n *\n * `DialogFormState.pending` is this form's own status; it is not emitted as `data-pending` and\n * is not folded into any control's `pending` (conventions 2.7). Submit buttons read\n * `useFormStatus()` themselves.\n *\n * Owned keys (conventions 1.2): `method` (except with a string `action`), `action`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport function DialogForm(props: DialogFormProps) {\n return useDialogForm(props, \"Dialog\");\n}\n\nDialogForm.displayName = \"DialogForm\";\n\n/** The body of `Dialog.Form`, also run by `AlertDialog.Form` (alert-dialog.md 8). */\nexport function useDialogForm(\n {\n action,\n closeOnSettle = true,\n method,\n className,\n style,\n children,\n render,\n ...rest\n }: DialogFormProps,\n namespace: DialogNamespace,\n): ReactNode {\n const ctx = useDialogContext(`${namespace}.Form`);\n const { popupRef, recordCloseIntent, requestClose } = ctx;\n const isLibrary = ctx.mode === \"library\";\n const [pending, setPending] = useState(false);\n const submission = useRef<{ event: Event; returnValue: string } | null>(null);\n // The dialog closed after the last submit (Escape, a Close part): the settle must not close it\n // again, also when the user re-opened it meanwhile.\n const closedSinceSubmit = useRef(false);\n const watches = typeof action === \"function\";\n\n // The submitter's `value` comes from the native `submit` event (capture, before React's\n // handler runs the action).\n const libraryRef = useCallback((form: HTMLFormElement) => {\n const onSubmit = (event: Event) => {\n if (event.target !== form) return;\n const submitter = (event as SubmitEvent).submitter as\n | HTMLButtonElement\n | HTMLInputElement\n | null;\n submission.current = { event, returnValue: submitter?.value ?? \"\" };\n closedSinceSubmit.current = false;\n };\n const dialog = form.closest(\"dialog\");\n const onClose = (event: Event) => {\n if (event.target === dialog) closedSinceSubmit.current = true;\n };\n form.addEventListener(\"submit\", onSubmit, true);\n dialog?.addEventListener(\"close\", onClose);\n return () => {\n form.removeEventListener(\"submit\", onSubmit, true);\n dialog?.removeEventListener(\"close\", onClose);\n };\n }, []);\n\n // `clean`: no field error in the settle's result (always `true` without a `Form.Root`).\n const onSettled = useCallback(\n (clean: boolean) => {\n const dialog = popupRef.current;\n const submitted = submission.current;\n submission.current = null;\n if (!closeOnSettle || closedSinceSubmit.current) return;\n // A result with field errors keeps the dialog open; the Form.Root focuses the first errored\n // field (design/components/dialog.md, \"Dialog.Form and Form.Root\").\n if (!clean) return;\n if (dialog === null || !dialog.open) return;\n const returnValue = submitted?.returnValue ?? \"\";\n if (isLibrary) {\n // A library-owned close (design 2.3): `openChangeAction(false)` awaited, then\n // `close(returnValue)` in the commit, inside the view transition if set.\n requestClose(submitted?.event, \"activate\", returnValue);\n return;\n }\n recordCloseIntent({ reason: \"activate\", event: submitted?.event });\n dialog.close(returnValue);\n },\n [closeOnSettle, popupRef, isLibrary, recordCloseIntent, requestClose],\n );\n\n const state: DialogFormState = { pending };\n\n return useRender<ComponentPropsWithRef<\"form\">, DialogFormState>({\n defaultElement: \"form\",\n render,\n state,\n className,\n style,\n children: (s) => (\n <>\n {resolveStateValue(children, s)}\n <DialogFormSettle\n namespace={namespace}\n watches={watches}\n missingAction={action === undefined}\n onPendingChange={setPending}\n onSettled={onSettled}\n />\n </>\n ),\n props: rest,\n libraryProps: {\n method: action === undefined ? \"dialog\" : typeof action === \"string\" ? method : undefined,\n // React's own type wants `void | Promise<void>`; the library's actions return `unknown`\n // (conventions 2.2) and React ignores the result.\n action: action as ComponentPropsWithRef<\"form\">[\"action\"],\n },\n ref: libraryRef,\n });\n}\n\n/**\n * Rendered among the form's children, so it reads the `FormContext` exactly when the form is a\n * `Form.Root` (either orientation of the `render` composition): the settle close then waits for\n * a result with no field error (`hasAnyError`, the `autoReset` predicate, hidden stale entries\n * included).\n */\nfunction DialogFormSettle({\n namespace,\n watches,\n missingAction,\n onPendingChange,\n onSettled,\n}: {\n readonly namespace: DialogNamespace;\n readonly watches: boolean;\n readonly missingAction: boolean;\n readonly onPendingChange: (pending: boolean) => void;\n readonly onSettled: (clean: boolean) => void;\n}) {\n const form = use(FormContext);\n useDevWarning(\n form !== null && missingAction,\n isDev &&\n `${namespace}.Form: rendered as a \\`Form.Root\\`, it needs a function \\`action\\`; without ` +\n \"one the form navigates instead of closing the dialog. Render a plain \" +\n `\\`<${namespace}.Form>\\` for a \\`method=\"dialog\"\\` form.`,\n );\n const isForm = form !== null;\n const errors = form?.errors;\n const settled = useCallback(\n () => onSettled(!isForm || !hasAnyError(errors)),\n [isForm, errors, onSettled],\n );\n if (!watches) return null;\n return <FormStatusWatcher onPendingChange={onPendingChange} onSettled={settled} />;\n}\n"],"mappings":";;;;;;;;;;;AAYA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;;;;;AAuFvC,SAAgB,WAAW,OAAwB;CACjD,OAAO,cAAc,OAAO,QAAQ;AACtC;AAEA,WAAW,cAAc;;AAGzB,SAAgB,cACd,EACE,QACA,gBAAgB,MAChB,QACA,WACA,OACA,UACA,QACA,GAAG,QAEL,WACW;CACX,MAAM,MAAM,iBAAiB,GAAG,UAAU,MAAM;CAChD,MAAM,EAAE,UAAU,mBAAmB,iBAAiB;CACtD,MAAM,YAAY,IAAI,SAAS;CAC/B,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,aAAa,OAAqD,IAAI;CAG5E,MAAM,oBAAoB,OAAO,KAAK;CACtC,MAAM,UAAU,OAAO,WAAW;CAIlC,MAAM,aAAa,aAAa,SAA0B;EACxD,MAAM,YAAY,UAAiB;GACjC,IAAI,MAAM,WAAW,MAAM;GAC3B,MAAM,YAAa,MAAsB;GAIzC,WAAW,UAAU;IAAE;IAAO,aAAa,WAAW,SAAS;GAAG;GAClE,kBAAkB,UAAU;EAC9B;EACA,MAAM,SAAS,KAAK,QAAQ,QAAQ;EACpC,MAAM,WAAW,UAAiB;GAChC,IAAI,MAAM,WAAW,QAAQ,kBAAkB,UAAU;EAC3D;EACA,KAAK,iBAAiB,UAAU,UAAU,IAAI;EAC9C,QAAQ,iBAAiB,SAAS,OAAO;EACzC,aAAa;GACX,KAAK,oBAAoB,UAAU,UAAU,IAAI;GACjD,QAAQ,oBAAoB,SAAS,OAAO;EAC9C;CACF,GAAG,CAAC,CAAC;CAGL,MAAM,YAAY,aACf,UAAmB;EAClB,MAAM,SAAS,SAAS;EACxB,M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context.mjs";
2
3
  import { CSSProperties, ComponentPropsWithRef, ReactNode, RefObject, ViewTransitionClass } from "react";
3
4
  //#region src/dialog/dialog-popup.d.ts
4
5
  /**
@@ -105,7 +106,7 @@ export interface DialogPopupProps extends Omit<ComponentPropsWithRef<"dialog">,
105
106
  *
106
107
  * @see https://ui.funstack.work/components/dialog
107
108
  */
108
- export declare function DialogPopup({ keepMounted, initialFocus, lightDismiss, experimental_closedBy, transition, className, style, children, render, ...rest }: DialogPopupProps): ReactNode;
109
+ export declare function DialogPopup(props: DialogPopupProps): ReactNode;
109
110
  export declare namespace DialogPopup {
110
111
  var displayName: string;
111
112
  }
@@ -1 +1 @@
1
- {"version":3,"file":"dialog-popup.d.mts","names":[],"sources":["../../src/dialog/dialog-popup.tsx"],"mappings":";;;;;;;iBAuCiB;;WAEN;;WAEA;;;;;;;iBAQM,yBAAyB,KACxC;;;;;;;;;;;;;EAeA;;;;;;;;;;;EAWA,eAAe,UAAU;;;;;;;;;;EAUzB;;;;;;;;EAQA;;;;;;;;;;;;;;;;EAgBA,aAAa;;EAEb,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;wBAkCvC,cACd,aACA,cACA,cACA,uBACA,YACA,WACA,OACA,UACA,WACG,QACF,mBAAgB;yBAXH"}
1
+ {"version":3,"file":"dialog-popup.d.mts","names":[],"sources":["../../src/dialog/dialog-popup.tsx"],"mappings":";;;;;;;;iBAwCiB;;WAEN;;WAEA;;;;;;;iBAQM,yBAAyB,KACxC;;;;;;;;;;;;;EAeA;;;;;;;;;;;EAWA,eAAe,UAAU;;;;;;;;;;EAUzB;;;;;;;;EAQA;;;;;;;;;;;;;;;;EAgBA,aAAa;;EAEb,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;wBAkCvC,YAAY,OAAO,mBAAgB;yBAAnC"}
@@ -5,15 +5,15 @@ import { resolveStateValue } from "../internal/render-element.mjs";
5
5
  import { useRender } from "../internal/use-render.mjs";
6
6
  import { useLatest } from "../internal/use-latest.mjs";
7
7
  import { useElementCheck } from "../internal/use-element-check.mjs";
8
- import { useDialogContext } from "./dialog-context.mjs";
8
+ import { eventSource } from "../internal/overlay/invokers.mjs";
9
9
  import { useContentFocusProbe } from "../internal/overlay/content-focus-probe.mjs";
10
10
  import { withCssTransitionCut } from "../internal/overlay/css-transition-cut.mjs";
11
11
  import { commandOf, renderOverlayContent, resolveInitialFocus, returnFocusToTrigger, useCloseHold, useInitialFocusTarget, useJsFreePropWarnings } from "../internal/overlay/overlay-popup.mjs";
12
12
  import { createPopupFlags, showWithFocus } from "../internal/overlay/overlay-show.mjs";
13
13
  import { useApplyOpenState } from "../internal/overlay/use-apply-open-state.mjs";
14
- import { eventSource } from "../internal/overlay/invokers.mjs";
15
- import { useModalRegistration } from "../internal/overlay/use-modal-registration.mjs";
16
14
  import { useShownNameWarning } from "../internal/use-name-warning.mjs";
15
+ import { useDialogContext } from "./dialog-context.mjs";
16
+ import { useModalRegistration } from "../internal/overlay/use-modal-registration.mjs";
17
17
  import { listenDialogDismiss } from "./dialog-dismiss.mjs";
18
18
  import { useCallback, useEffect, useEffectEvent, useLayoutEffect, useRef, useState } from "react";
19
19
  //#region src/dialog/dialog-popup.tsx
@@ -44,24 +44,33 @@ function valueOf(element) {
44
44
  *
45
45
  * @see https://ui.funstack.work/components/dialog
46
46
  */
47
- function DialogPopup({ keepMounted, initialFocus, lightDismiss = false, experimental_closedBy = false, transition, className, style, children, render, ...rest }) {
48
- const ctx = useDialogContext("Dialog.Popup");
47
+ function DialogPopup(props) {
48
+ return useDialogPopup(props, { namespace: "Dialog" });
49
+ }
50
+ DialogPopup.displayName = "DialogPopup";
51
+ /**
52
+ * The body of `Dialog.Popup`, also run by `AlertDialog.Popup` with `role`, no light dismiss and
53
+ * a default initial focus target (alert-dialog.md 8).
54
+ */
55
+ function useDialogPopup({ keepMounted, initialFocus, lightDismiss = false, experimental_closedBy = false, transition, className, style, children, render, ...rest }, { namespace, role, defaultInitialFocus, wrapChildren }) {
56
+ const part = `${namespace}.Popup`;
57
+ const ctx = useDialogContext(part);
49
58
  const isLibrary = ctx.mode === "library";
50
59
  const { modal, ids, popupRef, triggerRef } = ctx;
51
60
  const [dialog, setDialog] = useState(null);
52
61
  const [flags] = useState(createPopupFlags);
53
- const initialFocusTarget = useInitialFocusTarget("Dialog.Popup", "dialog");
62
+ const initialFocusTarget = useInitialFocusTarget(part, "dialog");
54
63
  const exit = useCloseHold(ctx.committed, isLibrary, transition);
55
64
  const contentProbe = useContentFocusProbe(popupRef);
56
65
  const { wrapContent } = contentProbe;
57
66
  useModalRegistration(dialog);
58
- useJsFreePropWarnings("Dialog.Popup", "dialog", isLibrary, transition, keepMounted);
59
- const checkElement = useElementCheck(isDev && ((element) => element.tagName !== "DIALOG" ? `Dialog.Popup: expected to render a <dialog> element but got <${element.tagName.toLowerCase()}>. Top layer, backdrop, focus and Escape all come from a real <dialog>.` : null));
67
+ useJsFreePropWarnings(part, "dialog", isLibrary, transition, keepMounted);
68
+ const checkElement = useElementCheck(isDev && ((element) => element.tagName !== "DIALOG" ? `${part}: expected to render a <dialog> element but got <${element.tagName.toLowerCase()}>. Top layer, backdrop, focus and Escape all come from a real <dialog>.` : null));
60
69
  const openDialog = (element) => {
61
70
  const refused = flags.takeRefusedFact() && !modal;
62
71
  showWithFocus(element, {
63
72
  refused,
64
- autofocus: refused ? null : initialFocusTarget(element, initialFocus),
73
+ autofocus: refused ? null : initialFocus === void 0 && defaultInitialFocus !== void 0 ? defaultInitialFocus(element) : initialFocusTarget(element, initialFocus),
65
74
  show: () => withCssTransitionCut(element, transition !== void 0, () => {
66
75
  if (modal) element.showModal();
67
76
  else element.show();
@@ -242,7 +251,7 @@ function DialogPopup({ keepMounted, initialFocus, lightDismiss = false, experime
242
251
  lightDismiss,
243
252
  experimental_closedBy
244
253
  ]);
245
- useShownNameWarning(dialog, !isLibrary || ctx.committed, isDev && "Dialog.Popup: the dialog has no accessible name. Render a Dialog.Title, or give the Popup an `aria-label`.");
254
+ useShownNameWarning(dialog, !isLibrary || ctx.committed, isDev && `${part}: the dialog has no accessible name. Render a ${namespace}.Title, or give the Popup an \`aria-label\`.`);
246
255
  const state = {
247
256
  open: ctx.committed,
248
257
  modal
@@ -253,7 +262,7 @@ function DialogPopup({ keepMounted, initialFocus, lightDismiss = false, experime
253
262
  keepMounted,
254
263
  visible,
255
264
  wrapContent
256
- }, () => resolveStateValue(children, s));
265
+ }, () => wrapChildren === void 0 ? resolveStateValue(children, s) : wrapChildren(resolveStateValue(children, s)));
257
266
  const libraryProps = {
258
267
  id: ids.popup,
259
268
  open: void 0,
@@ -261,6 +270,7 @@ function DialogPopup({ keepMounted, initialFocus, lightDismiss = false, experime
261
270
  "aria-labelledby": ids.title,
262
271
  "aria-describedby": ids.description,
263
272
  "data-modal": dataAttr(modal),
273
+ ...role !== void 0 && { role },
264
274
  suppressHydrationWarning: true
265
275
  };
266
276
  const element = useRender({
@@ -274,10 +284,9 @@ function DialogPopup({ keepMounted, initialFocus, lightDismiss = false, experime
274
284
  libraryProps,
275
285
  ref: libraryRef
276
286
  });
277
- return useTransitionBoundary("Dialog.Popup", isLibrary ? transition : void 0, element);
287
+ return useTransitionBoundary(part, isLibrary ? transition : void 0, element);
278
288
  }
279
- DialogPopup.displayName = "DialogPopup";
280
289
  //#endregion
281
- export { DialogPopup };
290
+ export { DialogPopup, useDialogPopup };
282
291
 
283
292
  //# sourceMappingURL=dialog-popup.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"dialog-popup.mjs","names":[],"sources":["../../src/dialog/dialog-popup.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useEffectEvent, useLayoutEffect, useRef, useState } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n ReactNode,\n RefObject,\n ViewTransitionClass,\n} from \"react\";\nimport { useContentFocusProbe } from \"../internal/overlay/content-focus-probe.js\";\nimport { withCssTransitionCut } from \"../internal/overlay/css-transition-cut.js\";\nimport {\n commandOf,\n renderOverlayContent,\n resolveInitialFocus,\n returnFocusToTrigger,\n useCloseHold,\n useInitialFocusTarget,\n useJsFreePropWarnings,\n} from \"../internal/overlay/overlay-popup.js\";\nimport { createPopupFlags, showWithFocus } from \"../internal/overlay/overlay-show.js\";\nimport { useApplyOpenState } from \"../internal/overlay/use-apply-open-state.js\";\nimport { eventSource } from \"../internal/overlay/invokers.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useModalRegistration } from \"../internal/overlay/use-modal-registration.js\";\nimport { useShownNameWarning } from \"../internal/use-name-warning.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { useDialogContext } from \"./dialog-context.js\";\nimport { listenDialogDismiss } from \"./dialog-dismiss.js\";\n\n/**\n * State of `Dialog.Popup`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface DialogPopupState {\n /** Committed open state (library mode); `false` in JS-free mode. Read `:open` for the DOM truth. */\n readonly open: boolean;\n /** The Root's `modal`. */\n readonly modal: boolean;\n}\n\n/**\n * Props of `Dialog.Popup`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport interface DialogPopupProps extends Omit<\n ComponentPropsWithRef<\"dialog\">,\n \"id\" | \"open\" | \"closedby\" | \"onToggle\" | \"onBeforeToggle\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Library mode: what happens to the children while the dialog is closed.\n * - `false` (default): not rendered. Mounting them is part of the opening transition, so\n * content that suspends holds the open until it is ready. Unmount waits for the dialog's\n * exit animations.\n * - `true`: rendered inside `<Activity mode=\"hidden\">`: DOM and state preserved, effects\n * stopped, pre-rendered at low priority. Not in the server HTML.\n *\n * Ignored in JS-free mode (always mounted).\n *\n * @defaultValue `false`\n */\n keepMounted?: boolean;\n /**\n * Element to focus when the dialog opens: a ref, or a selector resolved inside the dialog.\n * The library writes `autofocus` on it right before `showModal()` / `show()` and the platform\n * focuses it. Use `tabIndex={-1}` on a heading or wrapper for long or destructive dialogs (APG).\n *\n * In JS-free mode the browser opens the dialog itself, so the attribute is written after\n * hydration and kept while mounted; before hydration only `autoFocus` in the markup works.\n *\n * @defaultValue the platform's choice (first focusable descendant; the dialog itself if none)\n */\n initialFocus?: RefObject<HTMLElement | null> | string;\n /**\n * Close on a click outside the dialog (on the backdrop for modal dialogs).\n * Baseline: JS `pointerdown` + `click` listeners, which close only when both the press and the\n * click land outside (a drag that starts inside, such as selecting text, never closes); with\n * `experimental_closedBy`, native `closedby=\"any\"`, which behaves the same. A click on the\n * Trigger of an open non-modal dialog counts as outside, as it does natively.\n *\n * @defaultValue `false`\n */\n lightDismiss?: boolean;\n /**\n * Experimental (Chrome 134+, Firefox 141+; Safari 27.0 ignores it). Renders `closedby`\n * (`\"any\"` when `lightDismiss`, else `\"closerequest\"`) and skips the JS dismiss listeners where\n * `HTMLDialogElement.prototype.closedBy` exists. Elsewhere the JS baseline stays active.\n *\n * @defaultValue `false`\n */\n experimental_closedBy?: boolean;\n /**\n * Library mode only. Forwarded to the `<ViewTransition default>` around the dialog. Animates\n * the opening commit, content changes while open, and every library-driven close (a Close\n * part, a Form submit or settled action, a foreign close command, a controlled\n * `open={false}`), in all engines; dismissals (Escape, a click outside: `onOpenChange`) are the\n * browser's and animate with CSS only, never with a view transition. Ignored (dev warning) in\n * JS-free mode. While a view transition runs, the dialog's CSS transitions are turned off for\n * the moment of the library's own show or close (an inline `transition: none !important`,\n * restored right after), so that show or close runs no CSS transition (a `@keyframes`\n * animation is not cut).\n *\n * Static: setting or unsetting it remounts the element. Any value, `\"none\"` included, makes a\n * mount or `<Activity>` reveal inside a transition start a document view transition (a ~250 ms\n * page cross-fade that the next transition waits for).\n */\n transition?: ViewTransitionClass;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, DialogPopupState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, DialogPopupState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, DialogPopupState>;\n /** Must render a `<dialog>`. */\n render?: RenderProp<ComponentPropsWithRef<\"dialog\">, DialogPopupState>;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** The submitter's or invoker's `value` (`\"\"` without one, or where the engine gives no source). */\nfunction valueOf(element: unknown): string {\n if (element instanceof HTMLButtonElement || element instanceof HTMLInputElement) {\n return element.value;\n }\n return \"\";\n}\n\n/**\n * The dialog itself: a `<dialog>` with the id the Trigger's `commandfor` names, wired to Title\n * and Description through `aria-labelledby` / `aria-describedby`. Never renders `open`: modal\n * opening and closing go through `showModal()` / `close()` only. Style it with `:open` and\n * `:modal`; it emits `data-modal` but no `data-open`.\n *\n * In library mode the children render from committed state, so content that suspends keeps the\n * dialog closed (and the Trigger pending) until it is ready; `showModal()` runs in the layout\n * effect of the commit that mounted them. A close a part asks for (Close, a `method=\"dialog\"`\n * submit, a Form's settle close, a foreign close command) is cancelled and goes through the\n * Root: `openChangeAction(false)` is awaited and `close(returnValue)` runs in the layout effect\n * of the commit that ends it, inside the view transition if `transition` is set. A dismissal\n * (Escape, a click outside, script) is the browser's, a fact: the native `close` event makes\n * committed state `false` urgently and calls `onOpenChange(false, { reason: \"dismiss\",\n * returnValue })`; no view transition runs for it.\n *\n * Owned keys (conventions 1.2): `id`, `open`, `closedby`, `aria-labelledby` and\n * `aria-describedby` (token-merged), `data-modal`, `suppressHydrationWarning`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport function DialogPopup({\n keepMounted,\n initialFocus,\n lightDismiss = false,\n experimental_closedBy = false,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: DialogPopupProps) {\n const ctx = useDialogContext(\"Dialog.Popup\");\n const isLibrary = ctx.mode === \"library\";\n const { modal, ids, popupRef, triggerRef } = ctx;\n const [dialog, setDialog] = useState<HTMLDialogElement | null>(null);\n // `awaitingClose` (the `close` event of a close has not arrived), the library echo\n // `libraryClose` (every other close is a fact, dialog.md 2.7, reported the moment it happens,\n // also while a part's close is in flight) and `refusedFact` (conventions 3.9.4), as\n // usePopoverPopup's.\n const [flags] = useState(createPopupFlags);\n const initialFocusTarget = useInitialFocusTarget(\"Dialog.Popup\", \"dialog\");\n\n // `held`: children stay mounted while the close animates (design 4.4).\n const exit = useCloseHold(ctx.committed, isLibrary, transition);\n\n // Whether the content unmounted while holding focus since the dialog was last shown: a close\n // with `transition` removes the focused Close part before `close()` runs (design 6.2 rule 2).\n const contentProbe = useContentFocusProbe(popupRef);\n const { wrapContent } = contentProbe;\n\n // Toast's Viewport moves its region into the topmost open modal (design/components/toast.md 4.3).\n useModalRegistration(dialog);\n\n useJsFreePropWarnings(\"Dialog.Popup\", \"dialog\", isLibrary, transition, keepMounted);\n\n const checkElement = useElementCheck<HTMLDialogElement>(\n isDev &&\n ((element) =>\n element.tagName !== \"DIALOG\"\n ? `Dialog.Popup: expected to render a <dialog> element but got <${element.tagName.toLowerCase()}>. ` +\n \"Top layer, backdrop, focus and Escape all come from a real <dialog>.\"\n : null),\n );\n // --- Opening -----------------------------------------------------------------------------\n\n const openDialog = (element: HTMLDialogElement): void => {\n // A refused re-open of a non-modal dialog never moves focus (#156): no initial focus target,\n // and the dialog is `inert` for the duration of `show()`, so the dialog focusing steps focus\n // nothing (a consumer's own `inert` is left alone). A modal dialog must hold focus: its\n // re-open is a normal open. Two steps on purpose: the flag is taken (and cleared) on every\n // show, a modal one included; `!modal && take()` would leave it set for a modal dialog.\n const wasRefused = flags.takeRefusedFact();\n const refused = wasRefused && !modal;\n // Otherwise the platform's dialog focusing steps honour `autofocus` (design 6.1).\n showWithFocus(element, {\n refused,\n autofocus: refused ? null : initialFocusTarget(element, initialFocus),\n // A view transition animates the open: the CSS enter does not run next to it (conventions\n // 5.1).\n show: () =>\n withCssTransitionCut(element, transition !== undefined, () => {\n if (modal) element.showModal();\n else element.show();\n }),\n });\n };\n\n // Mount reconciliation (design 2.4): a click before hydration opened the dialog natively.\n // Runs before the apply effect; the dispatch makes the apply effect wait for it.\n const reconcileOnMount = useEffectEvent(() => {\n const element = popupRef.current;\n if (element === null || !element.open) return;\n ctx.requestOpen(undefined, \"platform\");\n });\n useLayoutEffect(() => {\n if (isLibrary) reconcileOnMount();\n }, [isLibrary]);\n\n // The apply effect (design 2.5), shared with usePopoverPopup. Keep this call right after mount\n // reconciliation (as there): layout effects run in call order, and at mount the\n // reconciliation's dispatch must come first, so that the first apply sees it in flight and\n // waits. Opens on the user's dispatch, `defaultOpen`, a controlled parent, the re-open of a\n // dismissal a controlled parent refused; closes after a part-initiated close settled, a\n // controlled close, or a refused pre-hydration open.\n useApplyOpenState(ctx, {\n flags,\n exit,\n probe: contentProbe,\n isShown: (element) => element.open,\n show: openDialog,\n hide: (element) => {\n // `close()`, not `requestClose()`: the veto point was `openChangeAction`, not `cancel`. The\n // part's `returnValue` (design 2.3), `\"\"` for a controlled close.\n const returnValue = ctx.takeCloseReturnValue();\n withCssTransitionCut(element, transition !== undefined, () => element.close(returnValue));\n // The close commit may have unmounted the focused content before `close()`: a non-modal\n // dialog restores focus only from inside, so do it now (a modal one always restores it on\n // `close()`).\n if (contentProbe.hadFocus()) {\n contentProbe.forget();\n returnFocusToTrigger(element, triggerRef.current);\n }\n },\n });\n\n // JS-free mode: there is no \"right before showModal()\" (the browser runs the command), so the\n // `autofocus` attribute stays on the target while it is mounted.\n useEffect(() => {\n if (isLibrary || initialFocus === undefined || dialog === null) return;\n const target = resolveInitialFocus(dialog, initialFocus);\n if (target === null || !dialog.contains(target) || target.hasAttribute(\"autofocus\")) return;\n target.setAttribute(\"autofocus\", \"\");\n return () => target.removeAttribute(\"autofocus\");\n }, [isLibrary, initialFocus, dialog]);\n\n // --- Native listeners (conventions 7.4) ---------------------------------------------------\n\n const onCommand = useEffectEvent((event: Event) => {\n const element = popupRef.current;\n if (element === null || event.target !== element || event.defaultPrevented) return;\n const command = commandOf(event);\n if (command === \"show-modal\") {\n // A foreign invoker (design 2.2): opening goes through the library in library mode.\n if (!isLibrary) return;\n event.preventDefault();\n ctx.requestOpen(event, \"activate\");\n } else if (command === \"request-close\" || command === \"close\") {\n if (isLibrary) {\n // A foreign close invoker (design 2.3) goes through the library like a foreign\n // `show-modal`: same markup as Dialog.Close, same behaviour. `source` is the invoker\n // (`\"\"` where an engine gives none).\n event.preventDefault();\n ctx.requestClose(event, \"activate\", valueOf(eventSource(event)));\n } else if (element.open) {\n // The `command` event fires whatever the dialog's state (HTML): a close at a closed\n // dialog leaves no intent for a later close.\n ctx.recordCloseIntent({ reason: \"activate\", event });\n }\n }\n });\n\n // On the dialog's root node (the document, or a shadow root: `submit` is not composed), bubble\n // phase: after React's root listener, so a consumer's `onSubmit` has run (design 8.1).\n const onSubmit = useEffectEvent((event: Event) => {\n const element = popupRef.current;\n const form = event.target;\n if (element === null || !(form instanceof HTMLFormElement)) return;\n if (form.closest(\"dialog\") !== element) return;\n const submitter = (event as SubmitEvent).submitter;\n const formMethod = submitter?.getAttribute(\"formmethod\");\n const method = formMethod != null ? formMethod.toLowerCase() : form.method;\n if (method !== \"dialog\") return;\n if (!isLibrary) {\n ctx.recordCloseIntent({ reason: \"activate\", event });\n return;\n }\n // The consumer blocked the submission: the form did not submit, the dialog stays open.\n if (event.defaultPrevented) return;\n // The consumer opted out with `stopPropagation()`: the browser closes the dialog, reported\n // as a fact. Checked explicitly because React's root can be this same node (FUNSTACK\n // Static hydrates the document), where `stopPropagation()` does not stop this listener.\n if (event.cancelBubble) return;\n // Cancel the native close; the library closes once `openChangeAction(false)` settled.\n event.preventDefault();\n ctx.requestClose(event, \"activate\", valueOf(submitter));\n });\n\n // The `close` listener's work, also replayed for an element that remounted before its `close`\n // event (#159; `event` is `undefined` there: no event fired).\n const handleClose = (element: HTMLDialogElement, event: Event | undefined): void => {\n flags.endClose();\n\n // Focus return is the platform's; it leaves focus inside the hidden dialog only when the\n // opener is gone (design 6.2).\n const active = element.ownerDocument.activeElement;\n if (active !== null && element.contains(active)) {\n returnFocusToTrigger(element, triggerRef.current);\n }\n\n const intent = ctx.takeCloseIntent();\n const echo = flags.takeLibraryClose();\n if (!isLibrary) return;\n\n // The library's own `close()` is no fact.\n exit.afterClose(element, echo);\n\n if (echo) return;\n flags.markFact();\n // Closed by the browser: a returnValue a pending part close recorded will never be used.\n ctx.takeCloseReturnValue();\n // A fact, also while a part's close is in flight: it supersedes that request (committed\n // `false` now) and `onOpenChange(false)` is called (conventions 3.9.5, dialog.md 2.7).\n ctx.notifyClosed(intent?.event ?? event, intent?.reason ?? \"dismiss\", element.returnValue);\n };\n const latestHandleClose = useLatest(handleClose);\n\n const onClose = useEffectEvent((event: Event) => {\n const element = popupRef.current;\n if (element === null || event.target !== element) return;\n handleClose(element, event);\n });\n\n // Whether the Popup is mounted, for the #159 replay. A passive effect: a Suspense hide detaches\n // the element's ref (and runs layout cleanups) but keeps passive effects, so a hidden Popup\n // still counts as mounted.\n const mounted = useRef(false);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, [mounted]);\n\n const libraryRef = useCallback(\n (element: HTMLDialogElement) => {\n checkElement?.(element);\n popupRef.current = element;\n // A new element (a remount mid-close): the old one's `close` event never comes (#159). A\n // lost fact is replayed a timer task later, unless the Popup unmounted meanwhile; also while\n // a Suspense boundary hides it (the fact happened before the hide). Here, not in the\n // listener effect's cleanup: that passive cleanup runs after the remount's layout effects,\n // and no apply follows it.\n flags.attach(element, (lost) => {\n if (mounted.current) latestHandleClose.current(lost as HTMLDialogElement, undefined);\n });\n setDialog(element);\n return () => {\n if (popupRef.current === element) popupRef.current = null;\n setDialog(null);\n };\n },\n [checkElement, popupRef, flags, latestHandleClose, mounted],\n );\n\n const onBeforeToggle = useEffectEvent((event: Event) => {\n const element = popupRef.current;\n if (element === null || event.target !== element) return;\n const newState = (event as ToggleEvent).newState;\n // An open does not end a close (as Popover's): the close's `close` event still comes, HTML\n // queues it whatever follows, and nothing reads the flag while the dialog is shown (#159).\n if (newState === \"closed\") {\n flags.beginClose();\n // What already runs inside is not the exit.\n exit.recordBaseline(element);\n }\n // Every native open counts as a new opening (design 3.4, as Popover 14.1): foreign,\n // pre-hydration and JS-free opens too, so a Close action from an earlier opening skips its\n // close. Counted here, synchronously inside `showModal()` / `show()`, not at the queued\n // `toggle`: an action settling between the open and that task would otherwise still see the\n // old generation and close the new open.\n if (newState === \"open\") {\n ctx.nextOpenGeneration();\n contentProbe.forget();\n }\n });\n\n useEffect(() => {\n if (dialog === null) return;\n // The document, or the shadow root the dialog lives in (`submit` does not cross it).\n const root = dialog.getRootNode();\n // Feature detection only with the flag on, inside an effect (conventions 8).\n const nativeClosedBy = experimental_closedBy && \"closedBy\" in dialog;\n\n const listeners: [EventTarget, string, EventListener, boolean][] = [\n [dialog, \"command\", onCommand, false],\n // Bubble phase on the root node: after React's root listener (the consumer's `onSubmit`).\n [root, \"submit\", onSubmit, false],\n [dialog, \"close\", onClose, false],\n [dialog, \"beforetoggle\", onBeforeToggle, false],\n ];\n\n for (const [target, type, listener, capture] of listeners) {\n target.addEventListener(type, listener, capture);\n }\n // Escape on a non-modal dialog and light dismiss, where native `closedby` does not do them.\n const stopDismiss = nativeClosedBy\n ? null\n : listenDialogDismiss(dialog, { modal, lightDismiss });\n return () => {\n for (const [target, type, listener, capture] of listeners) {\n target.removeEventListener(type, listener, capture);\n }\n stopDismiss?.();\n };\n }, [dialog, modal, lightDismiss, experimental_closedBy]);\n\n // Development check (design 9): the dialog has an accessible name when it is (or can be)\n // shown.\n useShownNameWarning(\n dialog,\n !isLibrary || ctx.committed,\n isDev &&\n \"Dialog.Popup: the dialog has no accessible name. Render a Dialog.Title, or give the \" +\n \"Popup an `aria-label`.\",\n );\n\n const state: DialogPopupState = { open: ctx.committed, modal };\n const visible = ctx.committed || exit.held;\n\n const content = (s: DialogPopupState): ReactNode =>\n renderOverlayContent({ isLibrary, keepMounted, visible, wrapContent }, () =>\n resolveStateValue(children, s),\n );\n\n const libraryProps: ComponentPropsWithRef<\"dialog\"> & DataAttributes = {\n id: ids.popup,\n // Never rendered: removing `open` by hand hides a modal dialog without `close` and leaves\n // `:modal` true (research). Owned so a `render` element cannot add it.\n open: undefined,\n closedby: experimental_closedBy ? (lightDismiss ? \"any\" : \"closerequest\") : undefined,\n \"aria-labelledby\": ids.title,\n \"aria-describedby\": ids.description,\n \"data-modal\": dataAttr(modal),\n // A pre-hydration open leaves an `open` attribute the server did not render (design 2.4).\n suppressHydrationWarning: true,\n };\n\n const element = useRender<ComponentPropsWithRef<\"dialog\">, DialogPopupState>({\n defaultElement: \"dialog\",\n render,\n state,\n className,\n style,\n children: content,\n props: rest,\n libraryProps,\n ref: libraryRef,\n });\n\n return useTransitionBoundary(\"Dialog.Popup\", isLibrary ? transition : undefined, element);\n}\n\nDialogPopup.displayName = \"DialogPopup\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2HA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAGvC,SAAS,QAAQ,SAA0B;CACzC,IAAI,mBAAmB,qBAAqB,mBAAmB,kBAC7D,OAAO,QAAQ;CAEjB,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,YAAY,EAC1B,aACA,cACA,eAAe,OACf,wBAAwB,OACxB,YACA,WACA,OACA,UACA,QACA,GAAG,QACgB;CACnB,MAAM,MAAM,iBAAiB,cAAc;CAC3C,MAAM,YAAY,IAAI,SAAS;CAC/B,MAAM,EAAE,OAAO,KAAK,UAAU,eAAe;CAC7C,MAAM,CAAC,QAAQ,aAAa,SAAmC,IAAI;CAKnE,MAAM,CAAC,SAAS,S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AAO;AAC1F;AAEA,YAAY,cAAc"}
1
+ {"version":3,"file":"dialog-popup.mjs","names":[],"sources":["../../src/dialog/dialog-popup.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useEffectEvent, useLayoutEffect, useRef, useState } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n ReactNode,\n RefObject,\n ViewTransitionClass,\n} from \"react\";\nimport { useContentFocusProbe } from \"../internal/overlay/content-focus-probe.js\";\nimport { withCssTransitionCut } from \"../internal/overlay/css-transition-cut.js\";\nimport {\n commandOf,\n renderOverlayContent,\n resolveInitialFocus,\n returnFocusToTrigger,\n useCloseHold,\n useInitialFocusTarget,\n useJsFreePropWarnings,\n} from \"../internal/overlay/overlay-popup.js\";\nimport { createPopupFlags, showWithFocus } from \"../internal/overlay/overlay-show.js\";\nimport { useApplyOpenState } from \"../internal/overlay/use-apply-open-state.js\";\nimport { eventSource } from \"../internal/overlay/invokers.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useModalRegistration } from \"../internal/overlay/use-modal-registration.js\";\nimport { useShownNameWarning } from \"../internal/use-name-warning.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { useDialogContext } from \"./dialog-context.js\";\nimport type { DialogNamespace } from \"./dialog-context.js\";\nimport { listenDialogDismiss } from \"./dialog-dismiss.js\";\n\n/**\n * State of `Dialog.Popup`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface DialogPopupState {\n /** Committed open state (library mode); `false` in JS-free mode. Read `:open` for the DOM truth. */\n readonly open: boolean;\n /** The Root's `modal`. */\n readonly modal: boolean;\n}\n\n/**\n * Props of `Dialog.Popup`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport interface DialogPopupProps extends Omit<\n ComponentPropsWithRef<\"dialog\">,\n \"id\" | \"open\" | \"closedby\" | \"onToggle\" | \"onBeforeToggle\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Library mode: what happens to the children while the dialog is closed.\n * - `false` (default): not rendered. Mounting them is part of the opening transition, so\n * content that suspends holds the open until it is ready. Unmount waits for the dialog's\n * exit animations.\n * - `true`: rendered inside `<Activity mode=\"hidden\">`: DOM and state preserved, effects\n * stopped, pre-rendered at low priority. Not in the server HTML.\n *\n * Ignored in JS-free mode (always mounted).\n *\n * @defaultValue `false`\n */\n keepMounted?: boolean;\n /**\n * Element to focus when the dialog opens: a ref, or a selector resolved inside the dialog.\n * The library writes `autofocus` on it right before `showModal()` / `show()` and the platform\n * focuses it. Use `tabIndex={-1}` on a heading or wrapper for long or destructive dialogs (APG).\n *\n * In JS-free mode the browser opens the dialog itself, so the attribute is written after\n * hydration and kept while mounted; before hydration only `autoFocus` in the markup works.\n *\n * @defaultValue the platform's choice (first focusable descendant; the dialog itself if none)\n */\n initialFocus?: RefObject<HTMLElement | null> | string;\n /**\n * Close on a click outside the dialog (on the backdrop for modal dialogs).\n * Baseline: JS `pointerdown` + `click` listeners, which close only when both the press and the\n * click land outside (a drag that starts inside, such as selecting text, never closes); with\n * `experimental_closedBy`, native `closedby=\"any\"`, which behaves the same. A click on the\n * Trigger of an open non-modal dialog counts as outside, as it does natively.\n *\n * @defaultValue `false`\n */\n lightDismiss?: boolean;\n /**\n * Experimental (Chrome 134+, Firefox 141+; Safari 27.0 ignores it). Renders `closedby`\n * (`\"any\"` when `lightDismiss`, else `\"closerequest\"`) and skips the JS dismiss listeners where\n * `HTMLDialogElement.prototype.closedBy` exists. Elsewhere the JS baseline stays active.\n *\n * @defaultValue `false`\n */\n experimental_closedBy?: boolean;\n /**\n * Library mode only. Forwarded to the `<ViewTransition default>` around the dialog. Animates\n * the opening commit, content changes while open, and every library-driven close (a Close\n * part, a Form submit or settled action, a foreign close command, a controlled\n * `open={false}`), in all engines; dismissals (Escape, a click outside: `onOpenChange`) are the\n * browser's and animate with CSS only, never with a view transition. Ignored (dev warning) in\n * JS-free mode. While a view transition runs, the dialog's CSS transitions are turned off for\n * the moment of the library's own show or close (an inline `transition: none !important`,\n * restored right after), so that show or close runs no CSS transition (a `@keyframes`\n * animation is not cut).\n *\n * Static: setting or unsetting it remounts the element. Any value, `\"none\"` included, makes a\n * mount or `<Activity>` reveal inside a transition start a document view transition (a ~250 ms\n * page cross-fade that the next transition waits for).\n */\n transition?: ViewTransitionClass;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, DialogPopupState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, DialogPopupState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, DialogPopupState>;\n /** Must render a `<dialog>`. */\n render?: RenderProp<ComponentPropsWithRef<\"dialog\">, DialogPopupState>;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** The submitter's or invoker's `value` (`\"\"` without one, or where the engine gives no source). */\nfunction valueOf(element: unknown): string {\n if (element instanceof HTMLButtonElement || element instanceof HTMLInputElement) {\n return element.value;\n }\n return \"\";\n}\n\n/**\n * The dialog itself: a `<dialog>` with the id the Trigger's `commandfor` names, wired to Title\n * and Description through `aria-labelledby` / `aria-describedby`. Never renders `open`: modal\n * opening and closing go through `showModal()` / `close()` only. Style it with `:open` and\n * `:modal`; it emits `data-modal` but no `data-open`.\n *\n * In library mode the children render from committed state, so content that suspends keeps the\n * dialog closed (and the Trigger pending) until it is ready; `showModal()` runs in the layout\n * effect of the commit that mounted them. A close a part asks for (Close, a `method=\"dialog\"`\n * submit, a Form's settle close, a foreign close command) is cancelled and goes through the\n * Root: `openChangeAction(false)` is awaited and `close(returnValue)` runs in the layout effect\n * of the commit that ends it, inside the view transition if `transition` is set. A dismissal\n * (Escape, a click outside, script) is the browser's, a fact: the native `close` event makes\n * committed state `false` urgently and calls `onOpenChange(false, { reason: \"dismiss\",\n * returnValue })`; no view transition runs for it.\n *\n * Owned keys (conventions 1.2): `id`, `open`, `closedby`, `aria-labelledby` and\n * `aria-describedby` (token-merged), `data-modal`, `suppressHydrationWarning`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport function DialogPopup(props: DialogPopupProps) {\n return useDialogPopup(props, { namespace: \"Dialog\" });\n}\n\nDialogPopup.displayName = \"DialogPopup\";\n\n/** What a caller of `useDialogPopup` fixes (design/components/alert-dialog.md 8). */\nexport interface DialogPopupOptions {\n readonly namespace: DialogNamespace;\n /** An owned `role` (AlertDialog's); without it `role` passes through. */\n readonly role?: \"alertdialog\";\n /**\n * The initial focus target when `initialFocus` is not given (AlertDialog: the first enabled\n * Cancel), resolved right before a library open. `null` leaves the choice to the platform,\n * without a warning.\n */\n readonly defaultInitialFocus?: (dialog: HTMLDialogElement) => HTMLElement | null;\n /** Wraps the rendered children (AlertDialog's Cancel context). */\n readonly wrapChildren?: (children: ReactNode) => ReactNode;\n}\n\n/**\n * The body of `Dialog.Popup`, also run by `AlertDialog.Popup` with `role`, no light dismiss and\n * a default initial focus target (alert-dialog.md 8).\n */\nexport function useDialogPopup(\n {\n keepMounted,\n initialFocus,\n lightDismiss = false,\n experimental_closedBy = false,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n }: DialogPopupProps,\n { namespace, role, defaultInitialFocus, wrapChildren }: DialogPopupOptions,\n): ReactNode {\n const part = `${namespace}.Popup`;\n const ctx = useDialogContext(part);\n const isLibrary = ctx.mode === \"library\";\n const { modal, ids, popupRef, triggerRef } = ctx;\n const [dialog, setDialog] = useState<HTMLDialogElement | null>(null);\n // `awaitingClose` (the `close` event of a close has not arrived), the library echo\n // `libraryClose` (every other close is a fact, dialog.md 2.7, reported the moment it happens,\n // also while a part's close is in flight) and `refusedFact` (conventions 3.9.4), as\n // usePopoverPopup's.\n const [flags] = useState(createPopupFlags);\n const initialFocusTarget = useInitialFocusTarget(part, \"dialog\");\n\n // `held`: children stay mounted while the close animates (design 4.4).\n const exit = useCloseHold(ctx.committed, isLibrary, transition);\n\n // Whether the content unmounted while holding focus since the dialog was last shown: a close\n // with `transition` removes the focused Close part before `close()` runs (design 6.2 rule 2).\n const contentProbe = useContentFocusProbe(popupRef);\n const { wrapContent } = contentProbe;\n\n // Toast's Viewport moves its region into the topmost open modal (design/components/toast.md 4.3).\n useModalRegistration(dialog);\n\n useJsFreePropWarnings(part, \"dialog\", isLibrary, transition, keepMounted);\n\n const checkElement = useElementCheck<HTMLDialogElement>(\n isDev &&\n ((element) =>\n element.tagName !== \"DIALOG\"\n ? `${part}: expected to render a <dialog> element but got <${element.tagName.toLowerCase()}>. ` +\n \"Top layer, backdrop, focus and Escape all come from a real <dialog>.\"\n : null),\n );\n // --- Opening -----------------------------------------------------------------------------\n\n const openDialog = (element: HTMLDialogElement): void => {\n // A refused re-open of a non-modal dialog never moves focus (#156): no initial focus target,\n // and the dialog is `inert` for the duration of `show()`, so the dialog focusing steps focus\n // nothing (a consumer's own `inert` is left alone). A modal dialog must hold focus: its\n // re-open is a normal open. Two steps on purpose: the flag is taken (and cleared) on every\n // show, a modal one included; `!modal && take()` would leave it set for a modal dialog.\n const wasRefused = flags.takeRefusedFact();\n const refused = wasRefused && !modal;\n // Otherwise the platform's dialog focusing steps honour `autofocus` (design 6.1).\n showWithFocus(element, {\n refused,\n autofocus: refused\n ? null\n : initialFocus === undefined && defaultInitialFocus !== undefined\n ? defaultInitialFocus(element)\n : initialFocusTarget(element, initialFocus),\n // A view transition animates the open: the CSS enter does not run next to it (conventions\n // 5.1).\n show: () =>\n withCssTransitionCut(element, transition !== undefined, () => {\n if (modal) element.showModal();\n else element.show();\n }),\n });\n };\n\n // Mount reconciliation (design 2.4): a click before hydration opened the dialog natively.\n // Runs before the apply effect; the dispatch makes the apply effect wait for it.\n const reconcileOnMount = useEffectEvent(() => {\n const element = popupRef.current;\n if (element === null || !element.open) return;\n ctx.requestOpen(undefined, \"platform\");\n });\n useLayoutEffect(() => {\n if (isLibrary) reconcileOnMount();\n }, [isLibrary]);\n\n // The apply effect (design 2.5), shared with usePopoverPopup. Keep this call right after mount\n // reconciliation (as there): layout effects run in call order, and at mount the\n // reconciliation's dispatch must come first, so that the first apply sees it in flight and\n // waits. Opens on the user's dispatch, `defaultOpen`, a controlled parent, the re-open of a\n // dismissal a controlled parent refused; closes after a part-initiated close settled, a\n // controlled close, or a refused pre-hydration open.\n useApplyOpenState(ctx, {\n flags,\n exit,\n probe: contentProbe,\n isShown: (element) => element.open,\n show: openDialog,\n hide: (element) => {\n // `close()`, not `requestClose()`: the veto point was `openChangeAction`, not `cancel`. The\n // part's `returnValue` (design 2.3), `\"\"` for a controlled close.\n const returnValue = ctx.takeCloseReturnValue();\n withCssTransitionCut(element, transition !== undefined, () => element.close(returnValue));\n // The close commit may have unmounted the focused content before `close()`: a non-modal\n // dialog restores focus only from inside, so do it now (a modal one always restores it on\n // `close()`).\n if (contentProbe.hadFocus()) {\n contentProbe.forget();\n returnFocusToTrigger(element, triggerRef.current);\n }\n },\n });\n\n // JS-free mode: there is no \"right before showModal()\" (the browser runs the command), so the\n // `autofocus` attribute stays on the target while it is mounted.\n useEffect(() => {\n if (isLibrary || initialFocus === undefined || dialog === null) return;\n const target = resolveInitialFocus(dialog, initialFocus);\n if (target === null || !dialog.contains(target) || target.hasAttribute(\"autofocus\")) return;\n target.setAttribute(\"autofocus\", \"\");\n return () => target.removeAttribute(\"autofocus\");\n }, [isLibrary, initialFocus, dialog]);\n\n // --- Native listeners (conventions 7.4) ---------------------------------------------------\n\n const onCommand = useEffectEvent((event: Event) => {\n const element = popupRef.current;\n if (element === null || event.target !== element || event.defaultPrevented) return;\n const command = commandOf(event);\n if (command === \"show-modal\") {\n // A foreign invoker (design 2.2): opening goes through the library in library mode.\n if (!isLibrary) return;\n event.preventDefault();\n ctx.requestOpen(event, \"activate\");\n } else if (command === \"request-close\" || command === \"close\") {\n if (isLibrary) {\n // A foreign close invoker (design 2.3) goes through the library like a foreign\n // `show-modal`: same markup as Dialog.Close, same behaviour. `source` is the invoker\n // (`\"\"` where an engine gives none).\n event.preventDefault();\n ctx.requestClose(event, \"activate\", valueOf(eventSource(event)));\n } else if (element.open) {\n // The `command` event fires whatever the dialog's state (HTML): a close at a closed\n // dialog leaves no intent for a later close.\n ctx.recordCloseIntent({ reason: \"activate\", event });\n }\n }\n });\n\n // On the dialog's root node (the document, or a shadow root: `submit` is not composed), bubble\n // phase: after React's root listener, so a consumer's `onSubmit` has run (design 8.1).\n const onSubmit = useEffectEvent((event: Event) => {\n const element = popupRef.current;\n const form = event.target;\n if (element === null || !(form instanceof HTMLFormElement)) return;\n if (form.closest(\"dialog\") !== element) return;\n const submitter = (event as SubmitEvent).submitter;\n const formMethod = submitter?.getAttribute(\"formmethod\");\n const method = formMethod != null ? formMethod.toLowerCase() : form.method;\n if (method !== \"dialog\") return;\n if (!isLibrary) {\n ctx.recordCloseIntent({ reason: \"activate\", event });\n return;\n }\n // The consumer blocked the submission: the form did not submit, the dialog stays open.\n if (event.defaultPrevented) return;\n // The consumer opted out with `stopPropagation()`: the browser closes the dialog, reported\n // as a fact. Checked explicitly because React's root can be this same node (FUNSTACK\n // Static hydrates the document), where `stopPropagation()` does not stop this listener.\n if (event.cancelBubble) return;\n // Cancel the native close; the library closes once `openChangeAction(false)` settled.\n event.preventDefault();\n ctx.requestClose(event, \"activate\", valueOf(submitter));\n });\n\n // The `close` listener's work, also replayed for an element that remounted before its `close`\n // event (#159; `event` is `undefined` there: no event fired).\n const handleClose = (element: HTMLDialogElement, event: Event | undefined): void => {\n flags.endClose();\n\n // Focus return is the platform's; it leaves focus inside the hidden dialog only when the\n // opener is gone (design 6.2).\n const active = element.ownerDocument.activeElement;\n if (active !== null && element.contains(active)) {\n returnFocusToTrigger(element, triggerRef.current);\n }\n\n const intent = ctx.takeCloseIntent();\n const echo = flags.takeLibraryClose();\n if (!isLibrary) return;\n\n // The library's own `close()` is no fact.\n exit.afterClose(element, echo);\n\n if (echo) return;\n flags.markFact();\n // Closed by the browser: a returnValue a pending part close recorded will never be used.\n ctx.takeCloseReturnValue();\n // A fact, also while a part's close is in flight: it supersedes that request (committed\n // `false` now) and `onOpenChange(false)` is called (conventions 3.9.5, dialog.md 2.7).\n ctx.notifyClosed(intent?.event ?? event, intent?.reason ?? \"dismiss\", element.returnValue);\n };\n const latestHandleClose = useLatest(handleClose);\n\n const onClose = useEffectEvent((event: Event) => {\n const element = popupRef.current;\n if (element === null || event.target !== element) return;\n handleClose(element, event);\n });\n\n // Whether the Popup is mounted, for the #159 replay. A passive effect: a Suspense hide detaches\n // the element's ref (and runs layout cleanups) but keeps passive effects, so a hidden Popup\n // still counts as mounted.\n const mounted = useRef(false);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, [mounted]);\n\n const libraryRef = useCallback(\n (element: HTMLDialogElement) => {\n checkElement?.(element);\n popupRef.current = element;\n // A new element (a remount mid-close): the old one's `close` event never comes (#159). A\n // lost fact is replayed a timer task later, unless the Popup unmounted meanwhile; also while\n // a Suspense boundary hides it (the fact happened before the hide). Here, not in the\n // listener effect's cleanup: that passive cleanup runs after the remount's layout effects,\n // and no apply follows it.\n flags.attach(element, (lost) => {\n if (mounted.current) latestHandleClose.current(lost as HTMLDialogElement, undefined);\n });\n setDialog(element);\n return () => {\n if (popupRef.current === element) popupRef.current = null;\n setDialog(null);\n };\n },\n [checkElement, popupRef, flags, latestHandleClose, mounted],\n );\n\n const onBeforeToggle = useEffectEvent((event: Event) => {\n const element = popupRef.current;\n if (element === null || event.target !== element) return;\n const newState = (event as ToggleEvent).newState;\n // An open does not end a close (as Popover's): the close's `close` event still comes, HTML\n // queues it whatever follows, and nothing reads the flag while the dialog is shown (#159).\n if (newState === \"closed\") {\n flags.beginClose();\n // What already runs inside is not the exit.\n exit.recordBaseline(element);\n }\n // Every native open counts as a new opening (design 3.4, as Popover 14.1): foreign,\n // pre-hydration and JS-free opens too, so a Close action from an earlier opening skips its\n // close. Counted here, synchronously inside `showModal()` / `show()`, not at the queued\n // `toggle`: an action settling between the open and that task would otherwise still see the\n // old generation and close the new open.\n if (newState === \"open\") {\n ctx.nextOpenGeneration();\n contentProbe.forget();\n }\n });\n\n useEffect(() => {\n if (dialog === null) return;\n // The document, or the shadow root the dialog lives in (`submit` does not cross it).\n const root = dialog.getRootNode();\n // Feature detection only with the flag on, inside an effect (conventions 8).\n const nativeClosedBy = experimental_closedBy && \"closedBy\" in dialog;\n\n const listeners: [EventTarget, string, EventListener, boolean][] = [\n [dialog, \"command\", onCommand, false],\n // Bubble phase on the root node: after React's root listener (the consumer's `onSubmit`).\n [root, \"submit\", onSubmit, false],\n [dialog, \"close\", onClose, false],\n [dialog, \"beforetoggle\", onBeforeToggle, false],\n ];\n\n for (const [target, type, listener, capture] of listeners) {\n target.addEventListener(type, listener, capture);\n }\n // Escape on a non-modal dialog and light dismiss, where native `closedby` does not do them.\n const stopDismiss = nativeClosedBy\n ? null\n : listenDialogDismiss(dialog, { modal, lightDismiss });\n return () => {\n for (const [target, type, listener, capture] of listeners) {\n target.removeEventListener(type, listener, capture);\n }\n stopDismiss?.();\n };\n }, [dialog, modal, lightDismiss, experimental_closedBy]);\n\n // Development check (design 9): the dialog has an accessible name when it is (or can be)\n // shown.\n useShownNameWarning(\n dialog,\n !isLibrary || ctx.committed,\n isDev &&\n `${part}: the dialog has no accessible name. Render a ${namespace}.Title, or give the ` +\n \"Popup an `aria-label`.\",\n );\n\n const state: DialogPopupState = { open: ctx.committed, modal };\n const visible = ctx.committed || exit.held;\n\n const content = (s: DialogPopupState): ReactNode =>\n renderOverlayContent({ isLibrary, keepMounted, visible, wrapContent }, () =>\n wrapChildren === undefined\n ? resolveStateValue(children, s)\n : wrapChildren(resolveStateValue(children, s)),\n );\n\n const libraryProps: ComponentPropsWithRef<\"dialog\"> & DataAttributes = {\n id: ids.popup,\n // Never rendered: removing `open` by hand hides a modal dialog without `close` and leaves\n // `:modal` true (research). Owned so a `render` element cannot add it.\n open: undefined,\n closedby: experimental_closedBy ? (lightDismiss ? \"any\" : \"closerequest\") : undefined,\n \"aria-labelledby\": ids.title,\n \"aria-describedby\": ids.description,\n \"data-modal\": dataAttr(modal),\n // Owned when fixed (AlertDialog's `alertdialog`): a consumer's `role` is dropped.\n ...(role !== undefined && { role }),\n // A pre-hydration open leaves an `open` attribute the server did not render (design 2.4).\n suppressHydrationWarning: true,\n };\n\n const element = useRender<ComponentPropsWithRef<\"dialog\">, DialogPopupState>({\n defaultElement: \"dialog\",\n render,\n state,\n className,\n style,\n children: content,\n props: rest,\n libraryProps,\n ref: libraryRef,\n });\n\n return useTransitionBoundary(part, isLibrary ? transition : undefined, element);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA4HA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAGvC,SAAS,QAAQ,SAA0B;CACzC,IAAI,mBAAmB,qBAAqB,mBAAmB,kBAC7D,OAAO,QAAQ;CAEjB,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,YAAY,OAAyB;CACnD,OAAO,eAAe,OAAO,EAAE,WAAW,SAAS,CAAC;AACtD;AAEA,YAAY,cAAc;;;;;AAqB1B,SAAgB,eACd,EACE,aACA,cACA,eAAe,OACf,wBAAwB,OACxB,YACA,WACA,OACA,UACA,QACA,GAAG,QAEL,EAAE,WAAW,MAAM,qBAAqB,gBAC7B;CACX,MAAM,OAAO,GAAG,UAAU;CAC1B,MAAM,MAAM,iBAAiB,IAAI;CACjC,MAAM,YAAY,IAAI,SAAS;CAC/B,MAAM,EAAE,OAAO,KAAK,UAAU,eAAe;CAC7C,MAAM,CAAC,QAAQ,aAAa,SAAmC,IAAI;CAKnE,MAAM,CAAC,SAAS,SAAS,gBAAgB;CACzC,MAAM,qBAAqB,sBAAsB,MAAM,QAAQ;CAG/D,MAAM,OAAO,aAAa,IAAI,WAAW,WAAW,UAAU;CAI9D,MAAM,eAAe,qBAAqB,QAAQ;C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;CAED,OAAO,sBAAsB,MAAM,YAAY,aAAa,KAAA,GAAW,OAAO;AAChF"}
@@ -1,4 +1,5 @@
1
1
  import { ActionDetails, ChangeAction, ChangeReason, StateValue, UrgentChangeHandler } from "../internal/types.mjs";
2
+ import "./dialog-context.mjs";
2
3
  import { ReactNode } from "react";
3
4
  //#region src/dialog/dialog-root.d.ts
4
5
  /** Details passed as the second argument of `openChangeAction` and `onOpenChange`. */
@@ -96,7 +97,7 @@ export interface DialogRootProps {
96
97
  *
97
98
  * @see https://ui.funstack.work/components/dialog
98
99
  */
99
- export declare function DialogRoot({ open, defaultOpen, openChangeAction, onOpenChange, modal, children }: DialogRootProps): import("react").JSX.Element;
100
+ export declare function DialogRoot({ modal, ...props }: DialogRootProps): ReactNode;
100
101
  export declare namespace DialogRoot {
101
102
  var displayName: string;
102
103
  }
@@ -1 +1 @@
1
- {"version":3,"file":"dialog-root.d.mts","names":[],"sources":["../../src/dialog/dialog-root.tsx"],"mappings":";;;;iBAkBiB,gCAAgC;;;;;;;;WAQtC,QAAQ;;;;;;WAMR;;;iBAIM;;WAEN;;WAEA;;WAEA;;;;;;;iBAQM;;;;;;EAMf;;;;;EAKA;;;;;;;;;;;;;EAaA,mBAAmB,sBAAsB;;;;;;;;;;;;;;;EAezC,eAAe,6BAA6B;;;;;;EAM5C;;EAEA,WAAW,WAAW,WAAW;;;;;;;;;;;;;;;;;wBA0BnB,aACd,MACA,aACA,kBACA,cACA,OACA,YACC,kCAAe,IAAA;yBAPF"}
1
+ {"version":3,"file":"dialog-root.d.mts","names":[],"sources":["../../src/dialog/dialog-root.tsx"],"mappings":";;;;;iBAkBiB,gCAAgC;;;;;;;;WAQtC,QAAQ;;;;;;WAMR;;;iBAIM;;WAEN;;WAEA;;WAEA;;;;;;;iBAQM;;;;;;EAMf;;;;;EAKA;;;;;;;;;;;;;EAaA,mBAAmB,sBAAsB;;;;;;;;;;;;;;;EAezC,eAAe,6BAA6B;;;;;;EAM5C;;EAEA,WAAW,WAAW,WAAW;;;;;;;;;;;;;;;;;wBA0BnB,aAAa,UAAiB,SAAS,kBAAe;yBAAtD"}
@@ -2,8 +2,8 @@
2
2
  import { createActionDetails } from "../internal/action/action-details.mjs";
3
3
  import { resolveStateValue } from "../internal/render-element.mjs";
4
4
  import { intendedValue } from "../internal/action/use-controllable-action.mjs";
5
- import { DialogContext } from "./dialog-context.mjs";
6
5
  import { useOverlayRoot } from "../internal/overlay/use-overlay-root.mjs";
6
+ import { DialogContext } from "./dialog-context.mjs";
7
7
  import { useCallback, useInsertionEffect, useMemo, useRef } from "react";
8
8
  import { jsx } from "react/jsx-runtime";
9
9
  //#region src/dialog/dialog-root.tsx
@@ -27,10 +27,21 @@ const isDialogOpen = (dialog) => dialog.open;
27
27
  *
28
28
  * @see https://ui.funstack.work/components/dialog
29
29
  */
30
- function DialogRoot({ open, defaultOpen, openChangeAction, onOpenChange, modal = true, children }) {
30
+ function DialogRoot({ modal = true, ...props }) {
31
+ return useDialogRoot(props, {
32
+ namespace: "Dialog",
33
+ modal
34
+ });
35
+ }
36
+ DialogRoot.displayName = "DialogRoot";
37
+ /**
38
+ * The body of `Dialog.Root`, also run by `AlertDialog.Root` with `modal` fixed to `true`
39
+ * (design/components/alert-dialog.md 8).
40
+ */
41
+ function useDialogRoot({ open, defaultOpen, openChangeAction, onOpenChange, children }, { namespace, modal }) {
31
42
  const root = useOverlayRoot({
32
43
  component: "dialog",
33
- part: "Dialog.Root",
44
+ part: `${namespace}.Root`,
34
45
  open,
35
46
  defaultOpen,
36
47
  openChangeAction,
@@ -78,8 +89,7 @@ function DialogRoot({ open, defaultOpen, openChangeAction, onOpenChange, modal =
78
89
  children: resolveStateValue(children, state)
79
90
  });
80
91
  }
81
- DialogRoot.displayName = "DialogRoot";
82
92
  //#endregion
83
- export { DialogRoot };
93
+ export { DialogRoot, useDialogRoot };
84
94
 
85
95
  //# sourceMappingURL=dialog-root.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"dialog-root.mjs","names":[],"sources":["../../src/dialog/dialog-root.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useInsertionEffect, useMemo, useRef } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action/action-details.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n StateValue,\n UrgentChangeHandler,\n} from \"../internal/types.js\";\nimport { intendedValue } from \"../internal/action/use-controllable-action.js\";\nimport { useOverlayRoot } from \"../internal/overlay/use-overlay-root.js\";\nimport { resolveStateValue } from \"../internal/use-render.js\";\nimport { DialogContext } from \"./dialog-context.js\";\nimport type { DialogContextValue } from \"./dialog-context.js\";\n\n/** Details passed as the second argument of `openChangeAction` and `onOpenChange`. */\nexport interface DialogOpenChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user acted on a part: Trigger (open), Close or Form submit (close).\n * `\"dismiss\"`: the user closed the dialog without a part: Escape, Android back, an assistive-\n * technology dismiss gesture, or a click outside (`lightDismiss` / `closedby=\"any\"`).\n * `\"platform\"`: the dialog was found open on mount (opened before hydration); `event` is\n * `undefined`.\n */\n readonly reason: ChangeReason;\n /**\n * On close: `dialog.returnValue`: the `value` of the Close button or the form submitter that\n * closed it; for a fact (`onOpenChange`), what the browser left (`\"\"` for Escape or a click\n * outside, the argument of a script `close(value)`). On open: `undefined`.\n */\n readonly returnValue: string | undefined;\n}\n\n/** State of `Dialog.Root`, passed to the function forms of `children`. */\nexport interface DialogRootState {\n /** Optimistic open state (`false` in JS-free mode). Content rendered from it must not suspend. */\n readonly open: boolean;\n /** An `openChangeAction` dispatched through this Dialog is in flight (library mode only). */\n readonly pending: boolean;\n /** The `modal` prop. */\n readonly modal: boolean;\n}\n\n/**\n * Props of `Dialog.Root`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport interface DialogRootProps {\n /**\n * Controlled open state. `undefined` means uncontrolled (and, with `defaultOpen`,\n * `openChangeAction` and `onOpenChange` also absent, JS-free mode). A controlled Root needs\n * `onOpenChange` too: the browser closes the dialog without asking (development warns).\n */\n open?: boolean;\n /**\n * Initial open state in uncontrolled library mode. The dialog opens after hydration, never in\n * the server HTML.\n */\n defaultOpen?: boolean;\n /**\n * Requests only. Awaited for `true` (the dialog opens when it resolves and the content has\n * rendered) and for a `false` the user asked a part for (`Dialog.Close`, a `Dialog.Form`\n * submit or settled action, a foreign close command: the dialog closes with\n * `details.returnValue` when it resolves, with a view transition if the Popup's `transition` is\n * set; a controlled parent that keeps `open` vetoes it). Never called for a dismissal: that goes\n * to `onOpenChange`. May be a Server Function. Rejections reach the nearest Error Boundary\n * above Root.\n *\n * A `setState` placed after your own `await` is not a Transition update; wrap it in\n * `startTransition` (React limitation).\n */\n openChangeAction?: ChangeAction<boolean, DialogOpenChangeDetails>;\n /**\n * Facts only: the dialog was closed without the library closing it (Escape, Android back, an\n * assistive-technology dismiss, a click outside with `lightDismiss`, script `close()` /\n * `requestClose()`). Always `false`, with `returnValue` as the browser left it. Called\n * synchronously in the platform's `close` event, outside any Transition, and not awaited:\n * nothing is pending and no view transition runs; the dialog is already closed and its\n * committed state is already `false` (uncontrolled). A dismissal while a part's close is in\n * flight is reported at once and supersedes that close.\n *\n * Controlled: set your state **directly** here (`onOpenChange={setOpen}`), not in\n * `startTransition` and not after an `await`; a parent that keeps `open={true}` gets the\n * dialog re-opened at once. May return a promise (a Server Function); a rejection or a throw\n * goes to `reportError`.\n */\n onOpenChange?: UrgentChangeHandler<boolean, DialogOpenChangeDetails>;\n /**\n * `showModal()` (top layer, backdrop, inert page, Escape) or `show()`.\n *\n * @defaultValue `true`\n */\n modal?: boolean;\n /** The parts. The function form receives the optimistic state and must not suspend. */\n children?: StateValue<ReactNode, DialogRootState>;\n}\n\nconst dialogDetails = (\n event: Event | undefined,\n reason: ChangeReason,\n returnValue?: string,\n): DialogOpenChangeDetails => createActionDetails(event, { reason, returnValue });\n\nconst isDialogOpen = (dialog: HTMLDialogElement): boolean => dialog.open;\n\n/**\n * Owns the ids, the mode, the open state and the context. Renders no DOM, so it has no `ref`,\n * `className` or `style`; `pending` is exposed through `children(state)` and the Trigger.\n *\n * Without `open`, `defaultOpen`, `openChangeAction` and `onOpenChange` the Dialog runs in\n * **JS-free mode**: the Trigger is a native `command=\"show-modal\"` invoker and the browser owns\n * everything. With any of them it runs in **library mode**: opening is a request, a transition\n * (the Trigger shows `data-pending`, content renders from committed state, `showModal()` runs\n * when it has committed), and so is a close a part asks for (Close, Form, a foreign close\n * command: `openChangeAction(false)` is awaited, `close(returnValue)` runs when it has\n * committed). Dismissals (Escape, a click outside) are the browser's facts, reported to\n * `onOpenChange`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport function DialogRoot({\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n modal = true,\n children,\n}: DialogRootProps) {\n // The popover machinery (design/components/popover.md 14.1) with the `<dialog>`'s `open` and\n // `returnValue` in the details: an open's `returnValue` is an own `undefined`.\n const root = useOverlayRoot<DialogOpenChangeDetails, HTMLDialogElement, [returnValue: string]>({\n component: \"dialog\",\n part: \"Dialog.Root\",\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n details: dialogDetails,\n isShown: isDialogOpen,\n });\n const { mode, intended, latestInFlight, optimistic, requestClose: closeRoot } = root;\n\n // The `returnValue` of a pending part-initiated close (design 2.3), handed to the apply\n // effect's `close()`. Stale once `true` is intended again (a vetoed close snapped back, or a\n // re-open), so the commit that shows it clears it.\n const closeReturnValue = useRef<string | undefined>(undefined);\n useInsertionEffect(() => {\n if (intendedValue(latestInFlight, optimistic)) closeReturnValue.current = undefined;\n });\n const takeCloseReturnValue = useCallback((): string => {\n const value = closeReturnValue.current;\n closeReturnValue.current = undefined;\n return value ?? \"\";\n }, []);\n\n // A library-owned close (design 2.3): `openChangeAction(false)` is awaited and the Popup's\n // apply effect calls `close(returnValue)` in the commit that ends it. A fact's `notifyClosed`\n // records no `returnValue`.\n const requestClose = useCallback(\n (event: Event | undefined, reason: ChangeReason, returnValue: string): void => {\n if (mode !== \"library\" || !intended()) return;\n closeReturnValue.current = returnValue;\n closeRoot(event, reason, returnValue);\n },\n [mode, intended, closeRoot],\n );\n\n // Memoised: `root` changes only with the open state and pending, so the value changes only\n // with those and `modal`, and the parts do not re-render for an unrelated render of the Root.\n const context = useMemo<DialogContextValue>(\n () => ({ ...root, modal, requestClose, takeCloseReturnValue }),\n [root, modal, requestClose, takeCloseReturnValue],\n );\n\n const state: DialogRootState = { open: optimistic, pending: root.pending, modal };\n\n return <DialogContext value={context}>{resolveStateValue(children, state)}</DialogContext>;\n}\n\nDialogRoot.displayName = \"DialogRoot\";\n"],"mappings":";;;;;;;;;AAoGA,MAAM,iBACJ,OACA,QACA,gBAC4B,oBAAoB,OAAO;CAAE;CAAQ;AAAY,CAAC;AAEhF,MAAM,gBAAgB,WAAuC,OAAO;;;;;;;;;;;;;;;;AAiBpE,SAAgB,WAAW,EACzB,MACA,aACA,kBACA,cACA,QAAQ,MACR,YACkB;CAGlB,MAAM,OAAO,eAAkF;EAC7F,WAAW;EACX,MAAM;EACN;EACA;EACA;EACA;EACA,SAAS;EACT,SAAS;CACX,CAAC;CACD,MAAM,EAAE,MAAM,UAAU,gBAAgB,YAAY,cAAc,cAAc;CAKhF,MAAM,mBAAmB,OAA2B,KAAA,CAAS;CAC7D,yBAAyB;EACvB,IAAI,cAAc,gBAAgB,UAAU,GAAG,iBAAiB,UAAU,KAAA;CAC5E,CAAC;CACD,MAAM,uBAAuB,kBAA0B;EACrD,MAAM,QAAQ,iBAAiB;EAC/B,iBAAiB,UAAU,KAAA;EAC3B,OAAO,SAAS;CAClB,GAAG,CAAC,CAAC;CAKL,MAAM,eAAe,aAClB,OAA0B,QAAsB,gBAA8B;EAC7E,IAAI,SAAS,aAAa,CAAC,SAAS,GAAG;EACvC,iBAAiB,UAAU;EAC3B,UAAU,OAAO,QAAQ,WAAW;CACtC,GACA;EAAC;EAAM;EAAU;CAAS,CAC5B;CAIA,MAAM,UAAU,eACP;EAAE,GAAG;EAAM;EAAO;EAAc;CAAqB,IAC5D;EAAC;EAAM;EAAO;EAAc;CAAoB,CAClD;CAEA,MAAM,QAAyB;EAAE,MAAM;EAAY,SAAS,KAAK;EAAS;CAAM;CAEhF,OAAO,oBAAC,eAAD;EAAe,OAAO;EAAU,UAAA,kBAAkB,UAAU,KAAK;CAAiB,CAAA;AAC3F;AAEA,WAAW,cAAc"}
1
+ {"version":3,"file":"dialog-root.mjs","names":[],"sources":["../../src/dialog/dialog-root.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useInsertionEffect, useMemo, useRef } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action/action-details.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n StateValue,\n UrgentChangeHandler,\n} from \"../internal/types.js\";\nimport { intendedValue } from \"../internal/action/use-controllable-action.js\";\nimport { useOverlayRoot } from \"../internal/overlay/use-overlay-root.js\";\nimport { resolveStateValue } from \"../internal/use-render.js\";\nimport { DialogContext } from \"./dialog-context.js\";\nimport type { DialogContextValue, DialogNamespace } from \"./dialog-context.js\";\n\n/** Details passed as the second argument of `openChangeAction` and `onOpenChange`. */\nexport interface DialogOpenChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user acted on a part: Trigger (open), Close or Form submit (close).\n * `\"dismiss\"`: the user closed the dialog without a part: Escape, Android back, an assistive-\n * technology dismiss gesture, or a click outside (`lightDismiss` / `closedby=\"any\"`).\n * `\"platform\"`: the dialog was found open on mount (opened before hydration); `event` is\n * `undefined`.\n */\n readonly reason: ChangeReason;\n /**\n * On close: `dialog.returnValue`: the `value` of the Close button or the form submitter that\n * closed it; for a fact (`onOpenChange`), what the browser left (`\"\"` for Escape or a click\n * outside, the argument of a script `close(value)`). On open: `undefined`.\n */\n readonly returnValue: string | undefined;\n}\n\n/** State of `Dialog.Root`, passed to the function forms of `children`. */\nexport interface DialogRootState {\n /** Optimistic open state (`false` in JS-free mode). Content rendered from it must not suspend. */\n readonly open: boolean;\n /** An `openChangeAction` dispatched through this Dialog is in flight (library mode only). */\n readonly pending: boolean;\n /** The `modal` prop. */\n readonly modal: boolean;\n}\n\n/**\n * Props of `Dialog.Root`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport interface DialogRootProps {\n /**\n * Controlled open state. `undefined` means uncontrolled (and, with `defaultOpen`,\n * `openChangeAction` and `onOpenChange` also absent, JS-free mode). A controlled Root needs\n * `onOpenChange` too: the browser closes the dialog without asking (development warns).\n */\n open?: boolean;\n /**\n * Initial open state in uncontrolled library mode. The dialog opens after hydration, never in\n * the server HTML.\n */\n defaultOpen?: boolean;\n /**\n * Requests only. Awaited for `true` (the dialog opens when it resolves and the content has\n * rendered) and for a `false` the user asked a part for (`Dialog.Close`, a `Dialog.Form`\n * submit or settled action, a foreign close command: the dialog closes with\n * `details.returnValue` when it resolves, with a view transition if the Popup's `transition` is\n * set; a controlled parent that keeps `open` vetoes it). Never called for a dismissal: that goes\n * to `onOpenChange`. May be a Server Function. Rejections reach the nearest Error Boundary\n * above Root.\n *\n * A `setState` placed after your own `await` is not a Transition update; wrap it in\n * `startTransition` (React limitation).\n */\n openChangeAction?: ChangeAction<boolean, DialogOpenChangeDetails>;\n /**\n * Facts only: the dialog was closed without the library closing it (Escape, Android back, an\n * assistive-technology dismiss, a click outside with `lightDismiss`, script `close()` /\n * `requestClose()`). Always `false`, with `returnValue` as the browser left it. Called\n * synchronously in the platform's `close` event, outside any Transition, and not awaited:\n * nothing is pending and no view transition runs; the dialog is already closed and its\n * committed state is already `false` (uncontrolled). A dismissal while a part's close is in\n * flight is reported at once and supersedes that close.\n *\n * Controlled: set your state **directly** here (`onOpenChange={setOpen}`), not in\n * `startTransition` and not after an `await`; a parent that keeps `open={true}` gets the\n * dialog re-opened at once. May return a promise (a Server Function); a rejection or a throw\n * goes to `reportError`.\n */\n onOpenChange?: UrgentChangeHandler<boolean, DialogOpenChangeDetails>;\n /**\n * `showModal()` (top layer, backdrop, inert page, Escape) or `show()`.\n *\n * @defaultValue `true`\n */\n modal?: boolean;\n /** The parts. The function form receives the optimistic state and must not suspend. */\n children?: StateValue<ReactNode, DialogRootState>;\n}\n\nconst dialogDetails = (\n event: Event | undefined,\n reason: ChangeReason,\n returnValue?: string,\n): DialogOpenChangeDetails => createActionDetails(event, { reason, returnValue });\n\nconst isDialogOpen = (dialog: HTMLDialogElement): boolean => dialog.open;\n\n/**\n * Owns the ids, the mode, the open state and the context. Renders no DOM, so it has no `ref`,\n * `className` or `style`; `pending` is exposed through `children(state)` and the Trigger.\n *\n * Without `open`, `defaultOpen`, `openChangeAction` and `onOpenChange` the Dialog runs in\n * **JS-free mode**: the Trigger is a native `command=\"show-modal\"` invoker and the browser owns\n * everything. With any of them it runs in **library mode**: opening is a request, a transition\n * (the Trigger shows `data-pending`, content renders from committed state, `showModal()` runs\n * when it has committed), and so is a close a part asks for (Close, Form, a foreign close\n * command: `openChangeAction(false)` is awaited, `close(returnValue)` runs when it has\n * committed). Dismissals (Escape, a click outside) are the browser's facts, reported to\n * `onOpenChange`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport function DialogRoot({ modal = true, ...props }: DialogRootProps) {\n return useDialogRoot(props, { namespace: \"Dialog\", modal });\n}\n\nDialogRoot.displayName = \"DialogRoot\";\n\n/** What a caller of `useDialogRoot` fixes (design/components/alert-dialog.md 8). */\nexport interface DialogRootOptions {\n readonly namespace: DialogNamespace;\n readonly modal: boolean;\n}\n\n/**\n * The body of `Dialog.Root`, also run by `AlertDialog.Root` with `modal` fixed to `true`\n * (design/components/alert-dialog.md 8).\n */\nexport function useDialogRoot(\n { open, defaultOpen, openChangeAction, onOpenChange, children }: Omit<DialogRootProps, \"modal\">,\n { namespace, modal }: DialogRootOptions,\n): ReactNode {\n // The popover machinery (design/components/popover.md 14.1) with the `<dialog>`'s `open` and\n // `returnValue` in the details: an open's `returnValue` is an own `undefined`.\n const root = useOverlayRoot<DialogOpenChangeDetails, HTMLDialogElement, [returnValue: string]>({\n component: \"dialog\",\n part: `${namespace}.Root`,\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n details: dialogDetails,\n isShown: isDialogOpen,\n });\n const { mode, intended, latestInFlight, optimistic, requestClose: closeRoot } = root;\n\n // The `returnValue` of a pending part-initiated close (design 2.3), handed to the apply\n // effect's `close()`. Stale once `true` is intended again (a vetoed close snapped back, or a\n // re-open), so the commit that shows it clears it.\n const closeReturnValue = useRef<string | undefined>(undefined);\n useInsertionEffect(() => {\n if (intendedValue(latestInFlight, optimistic)) closeReturnValue.current = undefined;\n });\n const takeCloseReturnValue = useCallback((): string => {\n const value = closeReturnValue.current;\n closeReturnValue.current = undefined;\n return value ?? \"\";\n }, []);\n\n // A library-owned close (design 2.3): `openChangeAction(false)` is awaited and the Popup's\n // apply effect calls `close(returnValue)` in the commit that ends it. A fact's `notifyClosed`\n // records no `returnValue`.\n const requestClose = useCallback(\n (event: Event | undefined, reason: ChangeReason, returnValue: string): void => {\n if (mode !== \"library\" || !intended()) return;\n closeReturnValue.current = returnValue;\n closeRoot(event, reason, returnValue);\n },\n [mode, intended, closeRoot],\n );\n\n // Memoised: `root` changes only with the open state and pending, so the value changes only\n // with those and `modal`, and the parts do not re-render for an unrelated render of the Root.\n const context = useMemo<DialogContextValue>(\n () => ({ ...root, modal, requestClose, takeCloseReturnValue }),\n [root, modal, requestClose, takeCloseReturnValue],\n );\n\n const state: DialogRootState = { open: optimistic, pending: root.pending, modal };\n\n return <DialogContext value={context}>{resolveStateValue(children, state)}</DialogContext>;\n}\n"],"mappings":";;;;;;;;;AAoGA,MAAM,iBACJ,OACA,QACA,gBAC4B,oBAAoB,OAAO;CAAE;CAAQ;AAAY,CAAC;AAEhF,MAAM,gBAAgB,WAAuC,OAAO;;;;;;;;;;;;;;;;AAiBpE,SAAgB,WAAW,EAAE,QAAQ,MAAM,GAAG,SAA0B;CACtE,OAAO,cAAc,OAAO;EAAE,WAAW;EAAU;CAAM,CAAC;AAC5D;AAEA,WAAW,cAAc;;;;;AAYzB,SAAgB,cACd,EAAE,MAAM,aAAa,kBAAkB,cAAc,YACrD,EAAE,WAAW,SACF;CAGX,MAAM,OAAO,eAAkF;EAC7F,WAAW;EACX,MAAM,GAAG,UAAU;EACnB;EACA;EACA;EACA;EACA,SAAS;EACT,SAAS;CACX,CAAC;CACD,MAAM,EAAE,MAAM,UAAU,gBAAgB,YAAY,cAAc,cAAc;CAKhF,MAAM,mBAAmB,OAA2B,KAAA,CAAS;CAC7D,yBAAyB;EACvB,IAAI,cAAc,gBAAgB,UAAU,GAAG,iBAAiB,UAAU,KAAA;CAC5E,CAAC;CACD,MAAM,uBAAuB,kBAA0B;EACrD,MAAM,QAAQ,iBAAiB;EAC/B,iBAAiB,UAAU,KAAA;EAC3B,OAAO,SAAS;CAClB,GAAG,CAAC,CAAC;CAKL,MAAM,eAAe,aAClB,OAA0B,QAAsB,gBAA8B;EAC7E,IAAI,SAAS,aAAa,CAAC,SAAS,GAAG;EACvC,iBAAiB,UAAU;EAC3B,UAAU,OAAO,QAAQ,WAAW;CACtC,GACA;EAAC;EAAM;EAAU;CAAS,CAC5B;CAIA,MAAM,UAAU,eACP;EAAE,GAAG;EAAM;EAAO;EAAc;CAAqB,IAC5D;EAAC;EAAM;EAAO;EAAc;CAAoB,CAClD;CAEA,MAAM,QAAyB;EAAE,MAAM;EAAY,SAAS,KAAK;EAAS;CAAM;CAEhF,OAAO,oBAAC,eAAD;EAAe,OAAO;EAAU,UAAA,kBAAkB,UAAU,KAAK;CAAiB,CAAA;AAC3F"}
@@ -1,4 +1,5 @@
1
1
  import { RenderProp, StateValue } from "../internal/types.mjs";
2
+ import "./dialog-context.mjs";
2
3
  import { DialogPopupState } from "./dialog-popup.mjs";
3
4
  import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
4
5
  //#region src/dialog/dialog-title.d.ts
@@ -26,7 +27,7 @@ export interface DialogTitleProps extends Omit<ComponentPropsWithRef<"h2">, "id"
26
27
  *
27
28
  * @see https://ui.funstack.work/components/dialog
28
29
  */
29
- export declare function DialogTitle({ className, style, children, render, ...rest }: DialogTitleProps): ReactNode;
30
+ export declare function DialogTitle(props: DialogTitleProps): ReactNode;
30
31
  export declare namespace DialogTitle {
31
32
  var displayName: string;
32
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"dialog-title.d.mts","names":[],"sources":["../../src/dialog/dialog-title.tsx"],"mappings":";;;;;YAQY,mBAAmB;;;;;;iBAOd,yBAAyB,KACxC;;EAIA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,6BAA6B;;;;;;;;;wBAUnC,cAAc,WAAW,OAAO,UAAU,WAAW,QAAQ,mBAAgB;yBAA7E"}
1
+ {"version":3,"file":"dialog-title.d.mts","names":[],"sources":["../../src/dialog/dialog-title.tsx"],"mappings":";;;;;;YASY,mBAAmB;;;;;;iBAOd,yBAAyB,KACxC;;EAIA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,6BAA6B;;;;;;;;;wBAUnC,YAAY,OAAO,mBAAgB;yBAAnC"}