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

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 (345) hide show
  1. package/dist/accordion/accordion-item.mjs +1 -1
  2. package/dist/accordion/accordion-panel.mjs +1 -1
  3. package/dist/accordion/accordion-root.d.mts.map +1 -1
  4. package/dist/accordion/accordion-root.mjs +30 -35
  5. package/dist/accordion/accordion-root.mjs.map +1 -1
  6. package/dist/accordion/accordion-trigger.mjs +1 -1
  7. package/dist/button/button.d.mts +11 -6
  8. package/dist/button/button.d.mts.map +1 -1
  9. package/dist/button/button.mjs +25 -14
  10. package/dist/button/button.mjs.map +1 -1
  11. package/dist/checkbox/checkbox.mjs +1 -1
  12. package/dist/checkbox/checkbox.mjs.map +1 -1
  13. package/dist/checkbox-group/checkbox-group-item.mjs +3 -3
  14. package/dist/checkbox-group/checkbox-group-item.mjs.map +1 -1
  15. package/dist/checkbox-group/checkbox-group-parent.mjs +3 -3
  16. package/dist/checkbox-group/checkbox-group-parent.mjs.map +1 -1
  17. package/dist/checkbox-group/checkbox-group-root.d.mts.map +1 -1
  18. package/dist/checkbox-group/checkbox-group-root.mjs +5 -5
  19. package/dist/checkbox-group/checkbox-group-root.mjs.map +1 -1
  20. package/dist/combobox/combobox-context.mjs.map +1 -1
  21. package/dist/combobox/combobox-input.mjs +2 -2
  22. package/dist/combobox/combobox-input.mjs.map +1 -1
  23. package/dist/combobox/combobox-keyboard.mjs +81 -0
  24. package/dist/combobox/combobox-keyboard.mjs.map +1 -0
  25. package/dist/combobox/combobox-popup.mjs +3 -3
  26. package/dist/combobox/combobox-popup.mjs.map +1 -1
  27. package/dist/combobox/combobox-root.d.mts.map +1 -1
  28. package/dist/combobox/combobox-root.mjs +44 -129
  29. package/dist/combobox/combobox-root.mjs.map +1 -1
  30. package/dist/combobox/combobox-trigger.d.mts.map +1 -1
  31. package/dist/combobox/combobox-trigger.mjs +2 -9
  32. package/dist/combobox/combobox-trigger.mjs.map +1 -1
  33. package/dist/combobox/use-active-option.mjs +49 -0
  34. package/dist/combobox/use-active-option.mjs.map +1 -0
  35. package/dist/combobox/use-combobox-form.mjs +3 -5
  36. package/dist/combobox/use-combobox-form.mjs.map +1 -1
  37. package/dist/combobox/use-combobox-text.mjs +43 -0
  38. package/dist/combobox/use-combobox-text.mjs.map +1 -0
  39. package/dist/combobox/use-option-registry.mjs +7 -17
  40. package/dist/combobox/use-option-registry.mjs.map +1 -1
  41. package/dist/dialog/dialog-close.mjs +2 -2
  42. package/dist/dialog/dialog-close.mjs.map +1 -1
  43. package/dist/dialog/dialog-context.mjs.map +1 -1
  44. package/dist/dialog/dialog-dismiss.mjs +108 -0
  45. package/dist/dialog/dialog-dismiss.mjs.map +1 -0
  46. package/dist/dialog/dialog-form.mjs +4 -4
  47. package/dist/dialog/dialog-form.mjs.map +1 -1
  48. package/dist/dialog/dialog-popup.d.mts.map +1 -1
  49. package/dist/dialog/dialog-popup.mjs +73 -169
  50. package/dist/dialog/dialog-popup.mjs.map +1 -1
  51. package/dist/dialog/dialog-root.d.mts.map +1 -1
  52. package/dist/dialog/dialog-root.mjs +4 -3
  53. package/dist/dialog/dialog-root.mjs.map +1 -1
  54. package/dist/dialog/dialog-trigger.mjs +11 -8
  55. package/dist/dialog/dialog-trigger.mjs.map +1 -1
  56. package/dist/docs/components/button.md +3 -3
  57. package/dist/docs/components/dialog.md +3 -3
  58. package/dist/docs/components/field.md +4 -3
  59. package/dist/docs/components/popover.md +3 -3
  60. package/dist/docs/components/toast.md +8 -5
  61. package/dist/docs/roadmap.md +9 -1
  62. package/dist/field/field-control.d.mts +1 -1
  63. package/dist/field/field-control.mjs +2 -2
  64. package/dist/field/field-control.mjs.map +1 -1
  65. package/dist/field/field-description.d.mts +1 -1
  66. package/dist/field/field-description.mjs +1 -1
  67. package/dist/field/field-description.mjs.map +1 -1
  68. package/dist/field/field-error.d.mts +1 -1
  69. package/dist/field/field-error.mjs +1 -1
  70. package/dist/field/field-error.mjs.map +1 -1
  71. package/dist/field/field-label.d.mts +1 -1
  72. package/dist/field/field-label.mjs +1 -1
  73. package/dist/field/field-label.mjs.map +1 -1
  74. package/dist/field/field-root.d.mts +2 -2
  75. package/dist/field/field-root.d.mts.map +1 -1
  76. package/dist/field/field-root.mjs +4 -4
  77. package/dist/field/field-root.mjs.map +1 -1
  78. package/dist/field/index.d.mts +2 -2
  79. package/dist/form/form-root.d.mts +1 -1
  80. package/dist/form/form-root.d.mts.map +1 -1
  81. package/dist/form/form-root.mjs +14 -4
  82. package/dist/form/form-root.mjs.map +1 -1
  83. package/dist/form/form-submit.d.mts +7 -3
  84. package/dist/form/form-submit.d.mts.map +1 -1
  85. package/dist/form/form-submit.mjs +11 -7
  86. package/dist/form/form-submit.mjs.map +1 -1
  87. package/dist/form/index.d.mts +1 -1
  88. package/dist/index.d.mts +2 -2
  89. package/dist/internal/{action-details.mjs → action/action-details.mjs} +1 -1
  90. package/dist/internal/action/action-details.mjs.map +1 -0
  91. package/dist/internal/{call-urgent-handler.mjs → action/call-urgent-handler.mjs} +5 -10
  92. package/dist/internal/action/call-urgent-handler.mjs.map +1 -0
  93. package/dist/internal/{report-dropped.mjs → action/report-dropped.mjs} +3 -21
  94. package/dist/internal/action/report-dropped.mjs.map +1 -0
  95. package/dist/internal/{use-action-trigger.mjs → action/use-action-trigger.mjs} +3 -2
  96. package/dist/internal/action/use-action-trigger.mjs.map +1 -0
  97. package/dist/internal/action/use-connected.mjs +24 -0
  98. package/dist/internal/action/use-connected.mjs.map +1 -0
  99. package/dist/internal/{use-controllable-action.mjs → action/use-controllable-action.mjs} +13 -28
  100. package/dist/internal/action/use-controllable-action.mjs.map +1 -0
  101. package/dist/internal/action/use-pure-trigger.mjs +34 -0
  102. package/dist/internal/action/use-pure-trigger.mjs.map +1 -0
  103. package/dist/internal/action/use-step-commit.mjs +147 -0
  104. package/dist/internal/action/use-step-commit.mjs.map +1 -0
  105. package/dist/internal/{field-context.d.mts → form/field-context.d.mts} +1 -1
  106. package/dist/internal/form/field-context.d.mts.map +1 -0
  107. package/dist/internal/{field-context.mjs → form/field-context.mjs} +2 -2
  108. package/dist/internal/form/field-context.mjs.map +1 -0
  109. package/dist/internal/{focus-first-invalid.mjs → form/focus-first-invalid.mjs} +3 -3
  110. package/dist/internal/form/focus-first-invalid.mjs.map +1 -0
  111. package/dist/internal/{form-status-watcher.mjs → form/form-status-watcher.mjs} +1 -1
  112. package/dist/internal/form/form-status-watcher.mjs.map +1 -0
  113. package/dist/internal/{group-member.mjs → form/group-member.mjs} +2 -2
  114. package/dist/internal/form/group-member.mjs.map +1 -0
  115. package/dist/internal/{sync-presence.mjs → form/sync-presence.mjs} +1 -1
  116. package/dist/internal/form/sync-presence.mjs.map +1 -0
  117. package/dist/internal/{use-checkable-input.mjs → form/use-checkable-input.mjs} +5 -5
  118. package/dist/internal/form/use-checkable-input.mjs.map +1 -0
  119. package/dist/internal/{use-field-control.mjs → form/use-field-control.mjs} +3 -3
  120. package/dist/internal/form/use-field-control.mjs.map +1 -0
  121. package/dist/internal/{use-fieldset-group.mjs → form/use-fieldset-group.mjs} +3 -3
  122. package/dist/internal/form/use-fieldset-group.mjs.map +1 -0
  123. package/dist/internal/{use-form-owner-event.mjs → form/use-form-owner-event.mjs} +1 -1
  124. package/dist/internal/form/use-form-owner-event.mjs.map +1 -0
  125. package/dist/internal/{use-form-reset.mjs → form/use-form-reset.mjs} +15 -3
  126. package/dist/internal/form/use-form-reset.mjs.map +1 -0
  127. package/dist/internal/{use-native-checked.mjs → form/use-native-checked.mjs} +5 -4
  128. package/dist/internal/form/use-native-checked.mjs.map +1 -0
  129. package/dist/internal/{use-native-group-reconciliation.mjs → form/use-native-group-reconciliation.mjs} +2 -2
  130. package/dist/internal/form/use-native-group-reconciliation.mjs.map +1 -0
  131. package/dist/internal/{use-native-select-value.mjs → form/use-native-select-value.mjs} +2 -2
  132. package/dist/internal/form/use-native-select-value.mjs.map +1 -0
  133. package/dist/internal/{validity.d.mts → form/validity.d.mts} +1 -1
  134. package/dist/internal/form/validity.d.mts.map +1 -0
  135. package/dist/internal/{validity.mjs → form/validity.mjs} +1 -1
  136. package/dist/internal/form/validity.mjs.map +1 -0
  137. package/dist/internal/{anchor-position.d.mts → overlay/anchor-position.d.mts} +1 -1
  138. package/dist/internal/overlay/anchor-position.d.mts.map +1 -0
  139. package/dist/internal/{anchor-position.mjs → overlay/anchor-position.mjs} +1 -1
  140. package/dist/internal/overlay/anchor-position.mjs.map +1 -0
  141. package/dist/internal/{content-focus-probe.mjs → overlay/content-focus-probe.mjs} +1 -1
  142. package/dist/internal/overlay/content-focus-probe.mjs.map +1 -0
  143. package/dist/internal/{css-transition-cut.mjs → overlay/css-transition-cut.mjs} +1 -1
  144. package/dist/internal/overlay/css-transition-cut.mjs.map +1 -0
  145. package/dist/internal/{focus-visible.mjs → overlay/focus-visible.mjs} +1 -1
  146. package/dist/internal/overlay/focus-visible.mjs.map +1 -0
  147. package/dist/internal/{invokers.mjs → overlay/invokers.mjs} +1 -1
  148. package/dist/internal/overlay/invokers.mjs.map +1 -0
  149. package/dist/internal/{modal-registry.mjs → overlay/modal-registry.mjs} +1 -1
  150. package/dist/internal/overlay/modal-registry.mjs.map +1 -0
  151. package/dist/internal/{overlay-popup.mjs → overlay/overlay-popup.mjs} +3 -3
  152. package/dist/internal/overlay/overlay-popup.mjs.map +1 -0
  153. package/dist/internal/overlay/overlay-show.mjs +73 -0
  154. package/dist/internal/overlay/overlay-show.mjs.map +1 -0
  155. package/dist/internal/{popover-open.mjs → overlay/popover-open.mjs} +1 -1
  156. package/dist/internal/overlay/popover-open.mjs.map +1 -0
  157. package/dist/internal/{trigger-ref.mjs → overlay/trigger-ref.mjs} +1 -1
  158. package/dist/internal/overlay/trigger-ref.mjs.map +1 -0
  159. package/dist/internal/overlay/use-apply-open-state.mjs +44 -0
  160. package/dist/internal/overlay/use-apply-open-state.mjs.map +1 -0
  161. package/dist/internal/{use-exit-animation.mjs → overlay/use-exit-animation.mjs} +2 -2
  162. package/dist/internal/overlay/use-exit-animation.mjs.map +1 -0
  163. package/dist/internal/{use-interest-dismiss.mjs → overlay/use-interest-dismiss.mjs} +1 -1
  164. package/dist/internal/overlay/use-interest-dismiss.mjs.map +1 -0
  165. package/dist/internal/{use-modal-registration.mjs → overlay/use-modal-registration.mjs} +1 -1
  166. package/dist/internal/overlay/use-modal-registration.mjs.map +1 -0
  167. package/dist/internal/{use-overlay-close.mjs → overlay/use-overlay-close.mjs} +14 -13
  168. package/dist/internal/overlay/use-overlay-close.mjs.map +1 -0
  169. package/dist/internal/overlay/use-overlay-root.d.mts +2 -0
  170. package/dist/internal/{use-overlay-root.mjs → overlay/use-overlay-root.mjs} +44 -28
  171. package/dist/internal/overlay/use-overlay-root.mjs.map +1 -0
  172. package/dist/internal/{use-popover-popup.mjs → overlay/use-popover-popup.mjs} +74 -66
  173. package/dist/internal/overlay/use-popover-popup.mjs.map +1 -0
  174. package/dist/internal/{use-popover-trigger.d.mts → overlay/use-popover-trigger.d.mts} +3 -3
  175. package/dist/internal/overlay/use-popover-trigger.d.mts.map +1 -0
  176. package/dist/internal/{use-popover-trigger.mjs → overlay/use-popover-trigger.mjs} +47 -26
  177. package/dist/internal/overlay/use-popover-trigger.mjs.map +1 -0
  178. package/dist/internal/{use-resolved-placement.mjs → overlay/use-resolved-placement.mjs} +2 -2
  179. package/dist/internal/overlay/use-resolved-placement.mjs.map +1 -0
  180. package/dist/internal/render-element.mjs +47 -9
  181. package/dist/internal/render-element.mjs.map +1 -1
  182. package/dist/internal/transition-boundary.mjs +4 -8
  183. package/dist/internal/transition-boundary.mjs.map +1 -1
  184. package/dist/internal/use-mount-fixed.mjs +22 -0
  185. package/dist/internal/use-mount-fixed.mjs.map +1 -0
  186. package/dist/internal/use-register-count.mjs +4 -1
  187. package/dist/internal/use-register-count.mjs.map +1 -1
  188. package/dist/internal/use-render.mjs +2 -2
  189. package/dist/internal/use-render.mjs.map +1 -1
  190. package/dist/internal/use-roving-focus.mjs.map +1 -1
  191. package/dist/menu/menu-checkbox-item.mjs +2 -2
  192. package/dist/menu/menu-checkbox-item.mjs.map +1 -1
  193. package/dist/menu/menu-context.d.mts +1 -1
  194. package/dist/menu/menu-context.mjs.map +1 -1
  195. package/dist/menu/menu-gestures.mjs +1 -1
  196. package/dist/menu/menu-gestures.mjs.map +1 -1
  197. package/dist/menu/menu-item.d.mts.map +1 -1
  198. package/dist/menu/menu-item.mjs +9 -10
  199. package/dist/menu/menu-item.mjs.map +1 -1
  200. package/dist/menu/menu-outside.mjs +1 -1
  201. package/dist/menu/menu-outside.mjs.map +1 -1
  202. package/dist/menu/menu-popup.d.mts +1 -1
  203. package/dist/menu/menu-popup.d.mts.map +1 -1
  204. package/dist/menu/menu-popup.mjs +10 -6
  205. package/dist/menu/menu-popup.mjs.map +1 -1
  206. package/dist/menu/menu-radio-group.mjs +2 -2
  207. package/dist/menu/menu-radio-group.mjs.map +1 -1
  208. package/dist/menu/menu-root.mjs +2 -2
  209. package/dist/menu/menu-root.mjs.map +1 -1
  210. package/dist/menu/menu-submenu-trigger.mjs +3 -3
  211. package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
  212. package/dist/menu/menu-trigger.d.mts +1 -1
  213. package/dist/menu/menu-trigger.mjs +3 -3
  214. package/dist/menu/menu-trigger.mjs.map +1 -1
  215. package/dist/number-field/number-field-input.mjs +1 -1
  216. package/dist/number-field/number-field-input.mjs.map +1 -1
  217. package/dist/number-field/number-field-root.d.mts.map +1 -1
  218. package/dist/number-field/number-field-root.mjs +43 -107
  219. package/dist/number-field/number-field-root.mjs.map +1 -1
  220. package/dist/popover/popover-close.mjs +3 -3
  221. package/dist/popover/popover-close.mjs.map +1 -1
  222. package/dist/popover/popover-context.mjs.map +1 -1
  223. package/dist/popover/popover-popup.d.mts +1 -1
  224. package/dist/popover/popover-popup.mjs +3 -3
  225. package/dist/popover/popover-popup.mjs.map +1 -1
  226. package/dist/popover/popover-root.mjs +2 -2
  227. package/dist/popover/popover-root.mjs.map +1 -1
  228. package/dist/popover/popover-trigger.d.mts +1 -1
  229. package/dist/popover/popover-trigger.mjs +1 -1
  230. package/dist/popover/popover-trigger.mjs.map +1 -1
  231. package/dist/radio-group/radio-group-item.mjs +3 -3
  232. package/dist/radio-group/radio-group-item.mjs.map +1 -1
  233. package/dist/radio-group/radio-group-root.d.mts.map +1 -1
  234. package/dist/radio-group/radio-group-root.mjs +5 -5
  235. package/dist/radio-group/radio-group-root.mjs.map +1 -1
  236. package/dist/select/select-group-label.d.mts.map +1 -1
  237. package/dist/select/select-group-label.mjs +3 -1
  238. package/dist/select/select-group-label.mjs.map +1 -1
  239. package/dist/select/select-option.mjs +1 -1
  240. package/dist/select/select-option.mjs.map +1 -1
  241. package/dist/select/select-root.d.mts.map +1 -1
  242. package/dist/select/select-root.mjs +7 -7
  243. package/dist/select/select-root.mjs.map +1 -1
  244. package/dist/select/select-trigger.d.mts.map +1 -1
  245. package/dist/select/select-trigger.mjs +3 -1
  246. package/dist/select/select-trigger.mjs.map +1 -1
  247. package/dist/select/select-value.mjs +3 -6
  248. package/dist/select/select-value.mjs.map +1 -1
  249. package/dist/slider/slider-root.d.mts.map +1 -1
  250. package/dist/slider/slider-root.mjs +38 -104
  251. package/dist/slider/slider-root.mjs.map +1 -1
  252. package/dist/slider/use-thumb-registry.mjs.map +1 -1
  253. package/dist/switch/switch.mjs +1 -1
  254. package/dist/switch/switch.mjs.map +1 -1
  255. package/dist/tabs/tabs-panel.mjs +1 -1
  256. package/dist/tabs/tabs-panel.mjs.map +1 -1
  257. package/dist/tabs/tabs-root.d.mts.map +1 -1
  258. package/dist/tabs/tabs-root.mjs +4 -4
  259. package/dist/tabs/tabs-root.mjs.map +1 -1
  260. package/dist/{internal → tabs}/use-until-found.mjs +1 -1
  261. package/dist/tabs/use-until-found.mjs.map +1 -0
  262. package/dist/toast/toast-action.d.mts +13 -3
  263. package/dist/toast/toast-action.d.mts.map +1 -1
  264. package/dist/toast/toast-action.mjs +23 -13
  265. package/dist/toast/toast-action.mjs.map +1 -1
  266. package/dist/toast/toast-close.d.mts +13 -2
  267. package/dist/toast/toast-close.d.mts.map +1 -1
  268. package/dist/toast/toast-close.mjs +16 -6
  269. package/dist/toast/toast-close.mjs.map +1 -1
  270. package/dist/toast/toast-root.mjs +1 -1
  271. package/dist/toast/toast-root.mjs.map +1 -1
  272. package/dist/toast/toast-viewport.d.mts.map +1 -1
  273. package/dist/toast/toast-viewport.mjs +48 -143
  274. package/dist/toast/toast-viewport.mjs.map +1 -1
  275. package/dist/toast/use-modal-portal-host.mjs +1 -1
  276. package/dist/toast/use-modal-portal-host.mjs.map +1 -1
  277. package/dist/toast/use-toast-announcements.mjs +46 -0
  278. package/dist/toast/use-toast-announcements.mjs.map +1 -0
  279. package/dist/toast/use-toast-focus.mjs +75 -0
  280. package/dist/toast/use-toast-focus.mjs.map +1 -0
  281. package/dist/toast/use-toast-pauses.mjs +58 -0
  282. package/dist/toast/use-toast-pauses.mjs.map +1 -0
  283. package/dist/toggle/toggle.mjs +2 -2
  284. package/dist/toggle/toggle.mjs.map +1 -1
  285. package/dist/toggle-group/toggle-group-root.d.mts.map +1 -1
  286. package/dist/toggle-group/toggle-group-root.mjs +5 -5
  287. package/dist/toggle-group/toggle-group-root.mjs.map +1 -1
  288. package/dist/tooltip/tooltip-context.d.mts +1 -1
  289. package/dist/tooltip/tooltip-context.mjs.map +1 -1
  290. package/dist/tooltip/tooltip-popup.mjs +1 -1
  291. package/dist/tooltip/tooltip-popup.mjs.map +1 -1
  292. package/dist/tooltip/tooltip-root.d.mts.map +1 -1
  293. package/dist/tooltip/tooltip-root.mjs +9 -4
  294. package/dist/tooltip/tooltip-root.mjs.map +1 -1
  295. package/dist/tooltip/tooltip-trigger.mjs +1 -1
  296. package/dist/tooltip/tooltip-trigger.mjs.map +1 -1
  297. package/dist/{internal → tooltip}/tooltip-warm.mjs +1 -1
  298. package/dist/tooltip/tooltip-warm.mjs.map +1 -0
  299. package/dist/tooltip/use-tooltip-interaction.mjs +2 -2
  300. package/dist/tooltip/use-tooltip-interaction.mjs.map +1 -1
  301. package/package.json +1 -1
  302. package/skills/funstack-ui-knowledge/SKILL.md +1 -1
  303. package/dist/internal/action-details.mjs.map +0 -1
  304. package/dist/internal/anchor-position.d.mts.map +0 -1
  305. package/dist/internal/anchor-position.mjs.map +0 -1
  306. package/dist/internal/call-urgent-handler.mjs.map +0 -1
  307. package/dist/internal/content-focus-probe.mjs.map +0 -1
  308. package/dist/internal/css-transition-cut.mjs.map +0 -1
  309. package/dist/internal/field-context.d.mts.map +0 -1
  310. package/dist/internal/field-context.mjs.map +0 -1
  311. package/dist/internal/focus-first-invalid.mjs.map +0 -1
  312. package/dist/internal/focus-visible.mjs.map +0 -1
  313. package/dist/internal/form-status-watcher.mjs.map +0 -1
  314. package/dist/internal/group-member.mjs.map +0 -1
  315. package/dist/internal/invokers.mjs.map +0 -1
  316. package/dist/internal/modal-registry.mjs.map +0 -1
  317. package/dist/internal/overlay-popup.mjs.map +0 -1
  318. package/dist/internal/popover-open.mjs.map +0 -1
  319. package/dist/internal/report-dropped.mjs.map +0 -1
  320. package/dist/internal/sync-presence.mjs.map +0 -1
  321. package/dist/internal/tooltip-warm.mjs.map +0 -1
  322. package/dist/internal/trigger-ref.mjs.map +0 -1
  323. package/dist/internal/use-action-trigger.mjs.map +0 -1
  324. package/dist/internal/use-checkable-input.mjs.map +0 -1
  325. package/dist/internal/use-controllable-action.mjs.map +0 -1
  326. package/dist/internal/use-exit-animation.mjs.map +0 -1
  327. package/dist/internal/use-field-control.mjs.map +0 -1
  328. package/dist/internal/use-fieldset-group.mjs.map +0 -1
  329. package/dist/internal/use-form-owner-event.mjs.map +0 -1
  330. package/dist/internal/use-form-reset.mjs.map +0 -1
  331. package/dist/internal/use-interest-dismiss.mjs.map +0 -1
  332. package/dist/internal/use-modal-registration.mjs.map +0 -1
  333. package/dist/internal/use-native-checked.mjs.map +0 -1
  334. package/dist/internal/use-native-group-reconciliation.mjs.map +0 -1
  335. package/dist/internal/use-native-select-value.mjs.map +0 -1
  336. package/dist/internal/use-overlay-close.mjs.map +0 -1
  337. package/dist/internal/use-overlay-root.d.mts +0 -2
  338. package/dist/internal/use-overlay-root.mjs.map +0 -1
  339. package/dist/internal/use-popover-popup.mjs.map +0 -1
  340. package/dist/internal/use-popover-trigger.d.mts.map +0 -1
  341. package/dist/internal/use-popover-trigger.mjs.map +0 -1
  342. package/dist/internal/use-resolved-placement.mjs.map +0 -1
  343. package/dist/internal/use-until-found.mjs.map +0 -1
  344. package/dist/internal/validity.d.mts.map +0 -1
  345. package/dist/internal/validity.mjs.map +0 -1
@@ -1,16 +1,19 @@
1
1
  "use client";
2
- import { reportDropped, useConnected } from "./report-dropped.mjs";
3
- import { useLatest } from "./use-latest.mjs";
4
- import { addTransitionType, startTransition, useCallback, useEffect, useMemo, useOptimistic, useRef, useState, useTransition } from "react";
5
- //#region src/internal/use-controllable-action.ts
2
+ import { useDevWarning } from "../use-dev-warning.mjs";
3
+ import { reportDropped } from "./report-dropped.mjs";
4
+ import { useConnected } from "./use-connected.mjs";
5
+ import { useLatest } from "../use-latest.mjs";
6
+ import { addTransitionType, startTransition, useCallback, useMemo, useOptimistic, useRef, useState, useTransition } from "react";
7
+ //#region src/internal/action/use-controllable-action.ts
6
8
  const isDev = process.env.NODE_ENV !== "production";
7
9
  /**
8
10
  * What the user intends (conventions 3.8 rule 1): the latest in-flight dispatch's `next`, else
9
11
  * `optimistic`. An explicit null check, not `?.next ?? optimistic`, which would drop an in-flight
10
12
  * dispatch of a nullish value (a pending reset to "nothing checked"). Handlers and effects only.
13
+ * An absent `latestInFlight` (a hook option the caller may leave out) means nothing in flight.
11
14
  */
12
15
  function intendedValue(latestInFlight, optimistic) {
13
- const inFlight = latestInFlight();
16
+ const inFlight = latestInFlight === void 0 ? null : latestInFlight();
14
17
  return inFlight === null ? optimistic : inFlight.next;
15
18
  }
16
19
  function capitalize(s) {
@@ -138,29 +141,11 @@ function useControllableAction(options) {
138
141
  ]);
139
142
  }
140
143
  function useDevWarnings(isControlled, hasDefault, warn) {
141
- const initialMode = useRef(isControlled);
142
- const warnedBoth = useRef(false);
143
- const warnedSwitch = useRef(false);
144
- const component = warn?.component ?? "A component";
145
- const prop = warn?.prop ?? "value";
146
- useEffect(() => {
147
- if (!isDev) return;
148
- const defaultProp = `default${capitalize(prop)}`;
149
- if (isControlled && hasDefault && !warnedBoth.current) {
150
- warnedBoth.current = true;
151
- console.error(`${component}: both \`${prop}\` and \`${defaultProp}\` are set. Use \`${prop}\` for controlled mode or \`${defaultProp}\` for uncontrolled mode, not both.`);
152
- }
153
- if (initialMode.current !== isControlled && !warnedSwitch.current) {
154
- warnedSwitch.current = true;
155
- const from = initialMode.current ? "controlled" : "uncontrolled";
156
- console.error(`${component}: \`${prop}\` changed from ${from} to ${isControlled ? "controlled" : "uncontrolled"}. Switching modes after mount is not supported; keep \`${prop}\` either always defined or always undefined.`);
157
- }
158
- }, [
159
- component,
160
- prop,
161
- isControlled,
162
- hasDefault
163
- ]);
144
+ const [initialMode] = useState(isControlled);
145
+ const { component, prop } = warn;
146
+ const defaultProp = isDev && `default${capitalize(prop)}`;
147
+ useDevWarning(isControlled && hasDefault, isDev && `${component}: both \`${prop}\` and \`${defaultProp}\` are set. Use \`${prop}\` for controlled mode or \`${defaultProp}\` for uncontrolled mode, not both.`);
148
+ useDevWarning(initialMode !== isControlled, isDev && `${component}: \`${prop}\` changed from ${initialMode ? "controlled" : "uncontrolled"} to ${isControlled ? "controlled" : "uncontrolled"}. Switching modes after mount is not supported; keep \`${prop}\` either always defined or always undefined.`);
164
149
  }
165
150
  //#endregion
166
151
  export { intendedValue, useControllableAction };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-controllable-action.mjs","names":[],"sources":["../../../src/internal/action/use-controllable-action.ts"],"sourcesContent":["\"use client\";\nimport {\n addTransitionType,\n startTransition,\n useCallback,\n useMemo,\n useOptimistic,\n useRef,\n useState,\n useTransition,\n} from \"react\";\nimport type { ActionDetails, ChangeAction } from \"../types.js\";\nimport { useLatest } from \"../use-latest.js\";\nimport { reportDropped } from \"./report-dropped.js\";\nimport { useConnected } from \"./use-connected.js\";\nimport { useDevWarning } from \"../use-dev-warning.js\";\n\nexport interface UseControllableActionOptions<T, Details extends ActionDetails> {\n /** The controlled prop (`x`). `undefined` means uncontrolled. */\n controlled: T | undefined;\n /** The `defaultX` prop as the consumer passed it; `undefined` when omitted. */\n defaultValue: T | undefined;\n /** Initial uncontrolled value when neither `x` nor `defaultX` is given. */\n initialValue: T;\n /** The `xChangeAction` prop. Awaited inside this hook's transition. */\n action: ChangeAction<T, Details> | undefined;\n /**\n * View Transition types to attach to the commit that ends a dispatch. Receives the previous\n * committed value and the details object (Tabs derives next/prev direction from them).\n */\n transitionTypes?: (next: T, prev: T, details: Details) => readonly string[];\n /**\n * Optimistic reducer (conventions 3.4). Default: replace the value with `next`. Multi-item\n * states (Accordion's open set) pass a reducer keyed by item, reading the item from `details`,\n * so stacked optimistic patches re-base onto a changed committed value.\n *\n * With a reducer, uncontrolled state is also committed through it: once every overlapping\n * dispatch has settled, the dispatches that resolved are folded onto the committed value in\n * dispatch order, and a rejected one leaves no trace (#150). Without one, the latest dispatch's\n * `next` is committed when it resolves (the latest-dispatch guard). A dispatch made with\n * `{ whole: true }` bypasses the reducer: its `next` replaces the value in both places.\n */\n reducer?: (prev: T, next: T, details: Details) => T;\n /**\n * Names used in development warnings: `component` is the public part name the messages start\n * with (`\"Select.Root\"`, conventions 7.2), `prop` the controlled prop (`\"value\"`, `\"open\"`).\n */\n warn: { readonly component: string; readonly prop: string };\n}\n\nexport interface ControllableAction<T, Details extends ActionDetails> {\n /**\n * Committed value (`x` when it is not `undefined`, else internal state). Content regions\n * render this.\n */\n readonly committed: T;\n /** Optimistic value; trigger parts render this. */\n readonly optimistic: T;\n /** An action dispatched through this hook is in flight. */\n readonly pending: boolean;\n /**\n * Runs the action inside the hook's transition with optimistic feedback. `options.whole`\n * (internal, never part of a public details type): `next` replaces the value instead of going\n * through `reducer`, in the optimistic step and in the uncontrolled replay of the burst. For a\n * dispatch whose `next` is absolute rather than a per-item step (CheckboxGroup's form reset,\n * Accordion's mount reconciliation). Without a `reducer` every dispatch is already whole.\n */\n readonly dispatch: (next: T, details: Details, options?: DispatchOptions) => void;\n /**\n * The `next` of the most recent dispatch while any dispatch's action is still unsettled, else\n * `null`. Lets a component with a browser-owned path (Accordion's find-in-page reveal) build on\n * what the user already intends instead of on the DOM. Read it from handlers and effects only.\n */\n readonly latestInFlight: () => { readonly next: T } | null;\n /**\n * Uncontrolled mode only (a no-op when controlled): writes the committed value without calling\n * the action, without an optimistic step and without a transition. For a component that adopts\n * a default the browser chose (Select with neither `value` nor `defaultValue` takes the first\n * enabled option, design/components/select.md 5). Call it from a layout effect so the write is\n * flushed before paint.\n */\n readonly adopt: (next: T) => void;\n /**\n * A fact (#148, conventions 3.9.5): `next` is already true in the DOM\n * (the browser hid a popup the library did not hide). Supersedes every dispatch in flight (none\n * of them commits uncontrolled state; a later rejection is reported, not thrown), makes `next`\n * the in-flight intent, drops the optimistic patches of those dispatches, and in uncontrolled\n * mode writes the committed value. Never calls the action. Every write is urgent: call it from\n * the platform event's listener, outside any transition, so the change commits in that event's\n * own (discrete) commit. Advances `epoch`.\n */\n readonly adoptFact: (next: T) => void;\n /**\n * How many facts were adopted (`adoptFact`). It changes in the fact's commit even when nothing\n * else does (a controlled parent that keeps its value), so a memoised context that includes it\n * re-renders its consumers, and their effects can re-apply the value to the DOM.\n */\n readonly epoch: number;\n}\n\n/** Per-dispatch options of `ControllableAction.dispatch`. Internal. */\nexport interface DispatchOptions {\n /** Adopt `next` whole instead of applying `reducer` (see `dispatch`). Default `false`. */\n readonly whole?: boolean | undefined;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** One uncontrolled reducer-mode dispatch of a burst; `resolved` once its action resolved. */\ninterface BurstEntry<T, Details> {\n readonly next: T;\n readonly details: Details;\n readonly reducer: (prev: T, next: T, details: Details) => T;\n /** `next` is adopted whole (`DispatchOptions.whole`), not reduced. */\n readonly whole: boolean;\n resolved: boolean;\n}\n\n/**\n * What the user intends (conventions 3.8 rule 1): the latest in-flight dispatch's `next`, else\n * `optimistic`. An explicit null check, not `?.next ?? optimistic`, which would drop an in-flight\n * dispatch of a nullish value (a pending reset to \"nothing checked\"). Handlers and effects only.\n * An absent `latestInFlight` (a hook option the caller may leave out) means nothing in flight.\n */\nexport function intendedValue<T>(\n latestInFlight: (() => { readonly next: T } | null) | undefined,\n optimistic: T,\n): T {\n const inFlight = latestInFlight === undefined ? null : latestInFlight();\n return inFlight === null ? optimistic : inFlight.next;\n}\n\nfunction capitalize(s: string): string {\n return s.charAt(0).toUpperCase() + s.slice(1);\n}\n\n/**\n * The one place the state model of conventions section 3 is implemented: committed state,\n * optimistic state (`useOptimistic`, reducer form), the component's own transition, the\n * post-`await` write of uncontrolled state, the latest-dispatch guard, and the reporting of the\n * rejections React would drop: superseded ones, and the latest one once the owner left\n * (conventions 2.4).\n */\nexport function useControllableAction<T, Details extends ActionDetails = ActionDetails>(\n options: UseControllableActionOptions<T, Details>,\n): ControllableAction<T, Details> {\n const { controlled, defaultValue, initialValue, action, transitionTypes, reducer, warn } =\n options;\n\n const [internal, setInternal] = useState<T>(\n defaultValue === undefined ? initialValue : defaultValue,\n );\n const isControlled = controlled !== undefined;\n const committed = isControlled ? controlled : internal;\n // The fact epoch (`adoptFact`): urgent state. A patch carries the epoch of its dispatch and the\n // reducer of the render ignores it once the render's epoch is newer: React re-applies pending\n // optimistic updates on every render with that render's reducer, so one urgent `setEpoch` drops\n // every patch of a superseded dispatch in the fact's own commit (probed, issue-148 memo). The\n // passthrough stays the plain committed value: an object passthrough (`{ value, epoch }`, the\n // design's sketch) defeats React's bailout of a render whose state did not change, which an\n // inline ref re-run on every render turns into an update loop.\n const [epoch, setEpoch] = useState(0);\n const epochRef = useRef(0);\n const [optimistic, setOptimistic] = useOptimistic(\n committed,\n (prev: T, patch: { next: T; details: Details; epoch: number; whole: boolean }) =>\n patch.epoch < epoch\n ? prev\n : reducer && !patch.whole\n ? reducer(prev, patch.next, patch.details)\n : patch.next,\n );\n const [pending, startOwnTransition] = useTransition();\n const latest = useRef(0);\n const inFlight = useRef<{ count: number; next: T | undefined }>({ count: 0, next: undefined });\n /** The uncontrolled reducer-mode dispatches of the current burst (overlapping), in order. */\n const burst = useRef<BurstEntry<T, Details>[]>([]);\n const connected = useConnected();\n\n useDevWarnings(isControlled, defaultValue !== undefined, warn);\n\n // The functions below keep one identity for the hook's lifetime, so the returned object changes\n // only with `committed`, `optimistic` and `pending`, and the components' memoised context values\n // are reused across renders that change none of them. They read the props of the last\n // committed render through `props`; they run from handlers, actions and effects, never render.\n const props = useLatest({ committed, isControlled, action, transitionTypes, reducer });\n\n /**\n * Marks a dispatch settled. When it was the last one in flight, the uncontrolled reducer-mode\n * dispatches of the burst that resolved are committed, in dispatch order (see `reducer`).\n */\n const settle = useCallback((): void => {\n inFlight.current.count -= 1;\n if (inFlight.current.count > 0) return;\n inFlight.current.next = undefined;\n const resolved = burst.current.filter((entry) => entry.resolved);\n burst.current = [];\n if (resolved.length === 0) return;\n startTransition(() =>\n setInternal((prev) =>\n resolved.reduce(\n (value, entry) =>\n entry.whole ? entry.next : entry.reducer(value, entry.next, entry.details),\n prev,\n ),\n ),\n );\n }, []);\n\n const dispatch = useCallback(\n (next: T, details: Details, options?: DispatchOptions): void => {\n const whole = options?.whole ?? false;\n // Read once, at the call, as the per-render closure did: the action, the mode and the\n // previous value belong to the UI the user acted on, even after the `await`.\n const { committed: prev, isControlled, action, transitionTypes, reducer } = props.current;\n const id = ++latest.current;\n const dispatchEpoch = epochRef.current;\n inFlight.current.count += 1;\n inFlight.current.next = next;\n // Uncontrolled with a reducer: committed from the burst once every dispatch settled.\n const entry: BurstEntry<T, Details> | null =\n !isControlled && reducer ? { next, details, reducer, whole, resolved: false } : null;\n if (entry) burst.current.push(entry);\n startOwnTransition(async () => {\n for (const type of transitionTypes?.(next, prev, details) ?? []) addTransitionType(type);\n setOptimistic({ next, details, epoch: dispatchEpoch, whole });\n try {\n await action?.(next, details);\n } catch (error) {\n settle();\n // The latest dispatch's rejection takes React's own route to the boundary while the\n // owner is there to render it. React drops a superseded one (it keeps only the newest\n // thenable) and one whose owner unmounted or is hidden: reported instead (2.4, #152).\n if (id === latest.current && connected.current) throw error;\n reportDropped(error);\n return;\n }\n if (entry) entry.resolved = true;\n settle();\n if (!isControlled && !entry && id === latest.current) {\n startTransition(() => setInternal(next));\n }\n });\n },\n [props, settle, setOptimistic, connected],\n );\n\n const latestInFlight = useCallback((): { readonly next: T } | null => {\n const { count, next } = inFlight.current;\n return count > 0 ? { next: next as T } : null;\n }, []);\n\n const adopt = useCallback(\n (next: T): void => {\n if (!props.current.isControlled) setInternal(next);\n },\n [props],\n );\n\n const adoptFact = useCallback(\n (next: T): void => {\n // Supersede: no dispatch in flight is the latest any more, so none commits and a later\n // rejection is reported (2.4). Their settles still count down `inFlight`.\n latest.current += 1;\n if (inFlight.current.count > 0) inFlight.current.next = next;\n burst.current = [];\n epochRef.current += 1;\n setEpoch(epochRef.current);\n if (!props.current.isControlled) setInternal(next);\n },\n [props],\n );\n\n return useMemo(\n () => ({ committed, optimistic, pending, dispatch, latestInFlight, adopt, adoptFact, epoch }),\n [committed, optimistic, pending, dispatch, latestInFlight, adopt, adoptFact, epoch],\n );\n}\n\nfunction useDevWarnings(\n isControlled: boolean,\n hasDefault: boolean,\n warn: { readonly component: string; readonly prop: string },\n): void {\n const [initialMode] = useState(isControlled);\n const { component, prop } = warn;\n const defaultProp = isDev && `default${capitalize(prop)}`;\n\n useDevWarning(\n isControlled && hasDefault,\n isDev &&\n `${component}: both \\`${prop}\\` and \\`${defaultProp}\\` are set. ` +\n `Use \\`${prop}\\` for controlled mode or \\`${defaultProp}\\` for uncontrolled mode, not both.`,\n );\n useDevWarning(\n initialMode !== isControlled,\n isDev &&\n `${component}: \\`${prop}\\` changed from ${initialMode ? \"controlled\" : \"uncontrolled\"} to ` +\n `${isControlled ? \"controlled\" : \"uncontrolled\"}. Switching modes after mount ` +\n `is not supported; keep \\`${prop}\\` either always defined or always undefined.`,\n );\n}\n"],"mappings":"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"}
@@ -0,0 +1,34 @@
1
+ "use client";
2
+ import { dataAttr } from "../data-attr.mjs";
3
+ import { pendingAriaDisabled } from "../render-element.mjs";
4
+ import { useActionTrigger } from "./use-action-trigger.mjs";
5
+ //#region src/internal/action/use-pure-trigger.ts
6
+ /**
7
+ * The `whilePending` wiring of a pure trigger (`Button`, `Dialog.Close` / `Popover.Close`,
8
+ * `Menu.Item`, `Toast.Action`; conventions 2.5.1 and 3.6): resolves the part's default, passes
9
+ * `ignoreWhilePending` to `useActionTrigger`, and renders `aria-disabled` while pending if and
10
+ * only if the part is ignoring, plus `data-pending`.
11
+ */
12
+ function usePureTrigger(options) {
13
+ const ignoring = (options.whilePending ?? options.defaultWhilePending) === "ignore";
14
+ const { pending, run } = useActionTrigger({
15
+ openGeneration: options.openGeneration,
16
+ ignoreWhilePending: ignoring
17
+ });
18
+ return {
19
+ pending,
20
+ run,
21
+ ignoring,
22
+ runActivation: (event, work, then) => {
23
+ if (!run(work, then)) event.preventDefault();
24
+ },
25
+ pendingProps: (disabledProps, shown = pending) => ({
26
+ "aria-disabled": pendingAriaDisabled(disabledProps, shown && ignoring),
27
+ "data-pending": dataAttr(shown)
28
+ })
29
+ };
30
+ }
31
+ //#endregion
32
+ export { usePureTrigger };
33
+
34
+ //# sourceMappingURL=use-pure-trigger.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-pure-trigger.mjs","names":[],"sources":["../../../src/internal/action/use-pure-trigger.ts"],"sourcesContent":["\"use client\";\nimport { dataAttr } from \"../data-attr.js\";\nimport { pendingAriaDisabled } from \"../render-element.js\";\nimport type { DisabledButton } from \"../render-element.js\";\nimport type { WhilePending } from \"../types.js\";\nimport { useActionTrigger } from \"./use-action-trigger.js\";\nimport type { ActionTrigger } from \"./use-action-trigger.js\";\n\nexport interface PureTriggerOptions {\n /** The part's `whilePending` prop. */\n readonly whilePending: WhilePending | undefined;\n /**\n * The part's default when `whilePending` is omitted, which follows who owns the action\n * (conventions 2.5.1): `\"run\"` for `Button`, `\"ignore\"` for a Close part, by `closeOnActivate`\n * / `closeOnSettle` for `Menu.Item` / `Toast.Action`.\n */\n readonly defaultWhilePending: WhilePending;\n /** The overlay's open generation, for a `then` that closes it (`useActionTrigger`). */\n readonly openGeneration?: (() => number) | undefined;\n}\n\nexport interface PureTrigger extends ActionTrigger {\n /** The resolved `whilePending` is `\"ignore\"`: a run while one is in flight starts nothing. */\n readonly ignoring: boolean;\n /**\n * `run`, and `preventDefault()` on the activation when it was ignored, so an ignored click\n * does not navigate, submit or run a command either.\n */\n readonly runActivation: (\n event: { preventDefault(): void },\n work: () => unknown,\n then?: () => void,\n ) => void;\n /**\n * The owned pending keys (conventions 3.6): `aria-disabled` from the part's disabled branch\n * merged with `pending && ignoring` (`pendingAriaDisabled`: native `disabled` wins), and\n * `data-pending`. `pending` defaults to this hook's own; `Button` passes its own merged with\n * its form-channel pending.\n */\n readonly pendingProps: (\n disabledProps: DisabledButton[\"props\"],\n pending?: boolean,\n ) => { \"aria-disabled\": true | undefined; \"data-pending\": \"\" | undefined };\n}\n\n/**\n * The `whilePending` wiring of a pure trigger (`Button`, `Dialog.Close` / `Popover.Close`,\n * `Menu.Item`, `Toast.Action`; conventions 2.5.1 and 3.6): resolves the part's default, passes\n * `ignoreWhilePending` to `useActionTrigger`, and renders `aria-disabled` while pending if and\n * only if the part is ignoring, plus `data-pending`.\n */\nexport function usePureTrigger(options: PureTriggerOptions): PureTrigger {\n const ignoring = (options.whilePending ?? options.defaultWhilePending) === \"ignore\";\n const { pending, run } = useActionTrigger({\n openGeneration: options.openGeneration,\n ignoreWhilePending: ignoring,\n });\n return {\n pending,\n run,\n ignoring,\n runActivation: (event, work, then) => {\n if (!run(work, then)) event.preventDefault();\n },\n pendingProps: (disabledProps, shown = pending) => ({\n \"aria-disabled\": pendingAriaDisabled(disabledProps, shown && ignoring),\n \"data-pending\": dataAttr(shown),\n }),\n };\n}\n"],"mappings":";;;;;;;;;;;AAmDA,SAAgB,eAAe,SAA0C;CACvE,MAAM,YAAY,QAAQ,gBAAgB,QAAQ,yBAAyB;CAC3E,MAAM,EAAE,SAAS,QAAQ,iBAAiB;EACxC,gBAAgB,QAAQ;EACxB,oBAAoB;CACtB,CAAC;CACD,OAAO;EACL;EACA;EACA;EACA,gBAAgB,OAAO,MAAM,SAAS;GACpC,IAAI,CAAC,IAAI,MAAM,IAAI,GAAG,MAAM,eAAe;EAC7C;EACA,eAAe,eAAe,QAAQ,aAAa;GACjD,iBAAiB,oBAAoB,eAAe,SAAS,QAAQ;GACrE,gBAAgB,SAAS,KAAK;EAChC;CACF;AACF"}
@@ -0,0 +1,147 @@
1
+ "use client";
2
+ import { createActionDetails } from "./action-details.mjs";
3
+ import { useActionTrigger } from "./use-action-trigger.mjs";
4
+ import { useLatest } from "../use-latest.mjs";
5
+ import { useControllableAction } from "./use-controllable-action.mjs";
6
+ import { addTransitionType, useCallback, useMemo, useRef, useState } from "react";
7
+ //#region src/internal/action/use-step-commit.ts
8
+ /**
9
+ * The step and commit core of a continuous control (conventions 2.3 corollary; slider.md 2.2 to
10
+ * 2.4, number-field.md 2.2 to 2.4), shared by Slider and NumberField. Two channels: every step
11
+ * runs `stepAction` in its own transition (`useActionTrigger`, no re-entry guard), once per
12
+ * gesture `commitAction` is the action of `useControllableAction`. The value a gesture has
13
+ * reached is urgent state (`live`), shown while a pointer is captured, a step waits for its
14
+ * commit (`stepHeld`) or anything is in flight. A rejected commit in uncontrolled mode, for the
15
+ * latest commit only, leaves the transition and reports the revert as a `"dismiss"` step.
16
+ *
17
+ * `T` is the prop's value, `V` the value the control works with (Slider: an array per thumb),
18
+ * `S` the source of a gesture (Slider: the thumb index; NumberField: the button, key, wheel or
19
+ * input), `F` the component's `details` fields.
20
+ */
21
+ function useStepCommit(options) {
22
+ const { controlled, defaultValue, initialValue, commitAction, commitTypes, warn, toShown } = options;
23
+ /** The value the open gesture has reached, for rendering. */
24
+ const [live, setLive] = useState(null);
25
+ /**
26
+ * A step was taken and its gesture's commit has not been dispatched yet. Holds `live` on
27
+ * screen between a step and its commit when no step transition runs (no `stepAction`):
28
+ * otherwise react-dom restores a controlled input to the old value after its `input`, and
29
+ * Firefox then fires no `change` (slider.md 2.2).
30
+ */
31
+ const [stepHeld, setStepHeld] = useState(false);
32
+ const [pendingSource, setPendingSource] = useState(null);
33
+ /** The value of the latest step, read by the commit in the same or a later event. */
34
+ const liveRef = useRef(null);
35
+ /** The shown value when the open gesture began; `null` when no gesture is open. */
36
+ const gestureStart = useRef(null);
37
+ const commitSeq = useRef(0);
38
+ /**
39
+ * The reason of the latest change the user or the platform made, consumed by `takeEdit`:
40
+ * `"activate"` dismisses a shown server error, a rollback does not.
41
+ */
42
+ const lastReason = useRef(null);
43
+ const runCommit = async (next, details) => {
44
+ const seq = ++commitSeq.current;
45
+ try {
46
+ await commitAction?.(next, details);
47
+ } catch (error) {
48
+ if (controlled === void 0 && seq === commitSeq.current) {
49
+ await void 0;
50
+ step(toShown(committedRef.current), null, "dismiss", void 0);
51
+ }
52
+ throw error;
53
+ }
54
+ };
55
+ const commitState = useControllableAction({
56
+ controlled,
57
+ defaultValue,
58
+ initialValue,
59
+ action: runCommit,
60
+ transitionTypes: () => commitTypes,
61
+ warn
62
+ });
63
+ const { optimistic, committed, dispatch } = commitState;
64
+ const committedRef = useLatest(committed);
65
+ const { pending: stepPending, run: runStep } = useActionTrigger({ ignoreWhilePending: false });
66
+ const optimisticShown = useMemo(() => toShown(optimistic), [optimistic, toShown]);
67
+ const shown = (options.captured || stepHeld || stepPending || commitState.pending) && live !== null ? live.value : optimisticShown;
68
+ const pending = stepPending || commitState.pending;
69
+ const shownRef = useLatest(shown);
70
+ const latest = useLatest({
71
+ stepAction: options.stepAction,
72
+ stepTypes: options.stepTypes,
73
+ fromShown: options.fromShown,
74
+ equals: options.equals,
75
+ details: options.details,
76
+ normalize: options.normalize,
77
+ onStep: options.onStep,
78
+ onCommit: options.onCommit,
79
+ runStep
80
+ });
81
+ const step = useCallback((next, source, reason, event) => {
82
+ const { normalize, equals, onStep } = latest.current;
83
+ if (normalize !== void 0) next = normalize(next);
84
+ if (equals(next, shownRef.current)) return false;
85
+ const reached = { value: next };
86
+ liveRef.current = reached;
87
+ shownRef.current = next;
88
+ lastReason.current = reason;
89
+ setLive(reached);
90
+ setPendingSource(source);
91
+ onStep?.(next);
92
+ if (reason !== "dismiss") setStepHeld(true);
93
+ const { stepAction: action, stepTypes, fromShown, details, runStep: run } = latest.current;
94
+ if (action === void 0) return true;
95
+ run(() => {
96
+ for (const type of stepTypes) addTransitionType(type);
97
+ return action(fromShown(next), createActionDetails(event, details(reason, source)));
98
+ });
99
+ return true;
100
+ }, [latest, shownRef]);
101
+ const commit = useCallback((source, reason, event) => {
102
+ const start = gestureStart.current;
103
+ gestureStart.current = null;
104
+ setStepHeld(false);
105
+ const reached = liveRef.current;
106
+ const { equals, fromShown, details, onCommit } = latest.current;
107
+ if (start === null || reached === null || equals(reached.value, start.value)) return false;
108
+ const next = reached.value;
109
+ lastReason.current = reason;
110
+ setPendingSource(source);
111
+ dispatch(fromShown(next), createActionDetails(event, details(reason, source)));
112
+ onCommit?.(next, source, reason);
113
+ return true;
114
+ }, [dispatch, latest]);
115
+ const openGesture = useCallback(() => {
116
+ const start = { value: shownRef.current };
117
+ gestureStart.current = start;
118
+ liveRef.current = start;
119
+ }, [shownRef]);
120
+ return {
121
+ shown,
122
+ shownRef,
123
+ optimistic,
124
+ optimisticShown,
125
+ pending,
126
+ pendingSource,
127
+ step,
128
+ commit,
129
+ openGesture,
130
+ captureGesture: useCallback(() => {
131
+ openGesture();
132
+ setLive({ value: shownRef.current });
133
+ }, [openGesture, shownRef]),
134
+ markGestureStart: useCallback((start) => {
135
+ if (gestureStart.current === null) gestureStart.current = { value: start };
136
+ }, []),
137
+ takeEdit: useCallback(() => {
138
+ const edit = lastReason.current === "activate";
139
+ lastReason.current = null;
140
+ return edit;
141
+ }, [])
142
+ };
143
+ }
144
+ //#endregion
145
+ export { useStepCommit };
146
+
147
+ //# sourceMappingURL=use-step-commit.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-step-commit.mjs","names":[],"sources":["../../../src/internal/action/use-step-commit.ts"],"sourcesContent":["\"use client\";\nimport { addTransitionType, useCallback, useMemo, useRef, useState } from \"react\";\nimport type { RefObject } from \"react\";\nimport { createActionDetails } from \"./action-details.js\";\nimport type { ActionDetails, ChangeAction, ChangeReason } from \"../types.js\";\nimport { useActionTrigger } from \"./use-action-trigger.js\";\nimport { useControllableAction } from \"./use-controllable-action.js\";\nimport { useLatest } from \"../use-latest.js\";\n\n/** A value in a box: `null` is a value for some controls, so \"none\" is the box's absence. */\ninterface Boxed<V> {\n readonly value: V;\n}\n\nexport interface StepCommitOptions<T, V, S, F extends object> {\n /** The controlled value (`undefined`: uncontrolled). */\n readonly controlled: T | undefined;\n readonly defaultValue: T | undefined;\n readonly initialValue: T;\n /** `valueChangeAction`: run in the step transition on every step. */\n readonly stepAction: ChangeAction<T, F & ActionDetails> | undefined;\n /** `valueCommitAction`: the action of `useControllableAction`, once per gesture. */\n readonly commitAction: ChangeAction<T, F & ActionDetails> | undefined;\n /** The step transition's types (`transitionTypes(component, \"change\")`). */\n readonly stepTypes: readonly string[];\n /** The commit transition's types (`transitionTypes(component, \"commit\")`). */\n readonly commitTypes: readonly string[];\n /** `useControllableAction`'s mode-switch warning. */\n readonly warn: { readonly component: string; readonly prop: string };\n /** The value as the control works with it internally. Stable (a module-level function). */\n readonly toShown: (value: T) => V;\n /** Back to the prop's shape, for the actions. */\n readonly fromShown: (shown: V) => T;\n /** The no-op test of a step and of a commit (conventions 2.3 item 8). */\n readonly equals: (a: V, b: V) => boolean;\n /** The component's `details` fields for a step or a commit from `source`. */\n readonly details: (reason: ChangeReason, source: S | null) => F;\n /** A pointer is captured (a drag, a held button): holds `live` on screen by itself. */\n readonly captured: boolean;\n /** Applied to every step's value before the no-op test (NumberField's rounding). */\n readonly normalize?: ((next: V) => V) | undefined;\n /** Called by a step that changed the value, before its action runs. */\n readonly onStep?: ((next: V) => void) | undefined;\n /** Called by a commit that dispatched, after the dispatch. */\n readonly onCommit?: ((next: V, source: S | null, reason: ChangeReason) => void) | undefined;\n}\n\nexport interface StepCommit<T, V, S> {\n /** What the control shows: `live` while held, else the optimistic value. */\n readonly shown: V;\n /** `shown` for handlers; also written by `step` ahead of the render. */\n readonly shownRef: RefObject<V>;\n /** The optimistic value, in the prop's shape. */\n readonly optimistic: T;\n /** The optimistic value, through `toShown`. */\n readonly optimisticShown: V;\n /** A step or a commit is in flight. */\n readonly pending: boolean;\n /** The source of the latest step or commit (raw: not cleared when nothing is pending). */\n readonly pendingSource: S | null;\n /**\n * One step: a pointer move, a key press, a tick, a platform change, the `\"dismiss\"` revert.\n * Returns `false` when `next` equals what is shown (nothing happened).\n */\n readonly step: (\n next: V,\n source: S | null,\n reason: ChangeReason,\n event: Event | undefined,\n ) => boolean;\n /**\n * Ends the open gesture: dispatches the commit of the value its steps reached, unless no\n * gesture is open or the value is back where the gesture began. Returns whether it dispatched.\n */\n readonly commit: (source: S | null, reason: ChangeReason, event: Event | undefined) => boolean;\n /** Opens a gesture at the shown value. */\n readonly openGesture: () => void;\n /** Opens a gesture at the shown value and shows it as `live` (a pointer capture begins). */\n readonly captureGesture: () => void;\n /**\n * Opens a gesture that began at `start`, unless one is open; the value it reached is left as\n * the step that calls this wrote it (Slider's native `input`, whose `change` commits later).\n */\n readonly markGestureStart: (start: V) => void;\n /**\n * For `useFieldValueChange`: whether the latest change was the user's (`\"activate\"`); consumes\n * it, so a later change from elsewhere is not taken for an edit.\n */\n readonly takeEdit: () => boolean;\n}\n\n/**\n * The step and commit core of a continuous control (conventions 2.3 corollary; slider.md 2.2 to\n * 2.4, number-field.md 2.2 to 2.4), shared by Slider and NumberField. Two channels: every step\n * runs `stepAction` in its own transition (`useActionTrigger`, no re-entry guard), once per\n * gesture `commitAction` is the action of `useControllableAction`. The value a gesture has\n * reached is urgent state (`live`), shown while a pointer is captured, a step waits for its\n * commit (`stepHeld`) or anything is in flight. A rejected commit in uncontrolled mode, for the\n * latest commit only, leaves the transition and reports the revert as a `\"dismiss\"` step.\n *\n * `T` is the prop's value, `V` the value the control works with (Slider: an array per thumb),\n * `S` the source of a gesture (Slider: the thumb index; NumberField: the button, key, wheel or\n * input), `F` the component's `details` fields.\n */\nexport function useStepCommit<T, V, S, F extends object>(\n options: StepCommitOptions<T, V, S, F>,\n): StepCommit<T, V, S> {\n const { controlled, defaultValue, initialValue, commitAction, commitTypes, warn, toShown } =\n options;\n\n /** The value the open gesture has reached, for rendering. */\n const [live, setLive] = useState<Boxed<V> | null>(null);\n /**\n * A step was taken and its gesture's commit has not been dispatched yet. Holds `live` on\n * screen between a step and its commit when no step transition runs (no `stepAction`):\n * otherwise react-dom restores a controlled input to the old value after its `input`, and\n * Firefox then fires no `change` (slider.md 2.2).\n */\n const [stepHeld, setStepHeld] = useState(false);\n const [pendingSource, setPendingSource] = useState<S | null>(null);\n\n /** The value of the latest step, read by the commit in the same or a later event. */\n const liveRef = useRef<Boxed<V> | null>(null);\n /** The shown value when the open gesture began; `null` when no gesture is open. */\n const gestureStart = useRef<Boxed<V> | null>(null);\n const commitSeq = useRef(0);\n /**\n * The reason of the latest change the user or the platform made, consumed by `takeEdit`:\n * `\"activate\"` dismisses a shown server error, a rollback does not.\n */\n const lastReason = useRef<ChangeReason | null>(null);\n\n const runCommit = async (next: T, details: F & ActionDetails): Promise<void> => {\n const seq = ++commitSeq.current;\n try {\n await commitAction?.(next, details);\n } catch (error) {\n // In uncontrolled mode, tell the preview channel about the rollback, for the latest commit\n // only. Yield once to leave the commit's transition (conventions 2.6).\n if (controlled === undefined && seq === commitSeq.current) {\n await undefined;\n // `step` and `committedRef` are declared below; this runs long after the render.\n step(toShown(committedRef.current), null, \"dismiss\", undefined);\n }\n throw error;\n }\n };\n\n const commitState = useControllableAction<T, F & ActionDetails>({\n controlled,\n defaultValue,\n initialValue,\n action: runCommit,\n transitionTypes: () => commitTypes,\n warn,\n });\n const { optimistic, committed, dispatch } = commitState;\n const committedRef = useLatest(committed);\n\n // A step is not a re-entry: a continuous control dispatches one step per key press or pointer\n // move and every step must run (design/components/button.md 16.1), so no in-flight guard.\n const { pending: stepPending, run: runStep } = useActionTrigger({\n ignoreWhilePending: false,\n });\n\n const optimisticShown = useMemo(() => toShown(optimistic), [optimistic, toShown]);\n const held = options.captured || stepHeld || stepPending || commitState.pending;\n const shown = held && live !== null ? live.value : optimisticShown;\n const pending = stepPending || commitState.pending;\n\n const shownRef = useLatest(shown);\n\n const latest = useLatest({\n stepAction: options.stepAction,\n stepTypes: options.stepTypes,\n fromShown: options.fromShown,\n equals: options.equals,\n details: options.details,\n normalize: options.normalize,\n onStep: options.onStep,\n onCommit: options.onCommit,\n runStep,\n });\n\n const step = useCallback(\n (next: V, source: S | null, reason: ChangeReason, event: Event | undefined): boolean => {\n const { normalize, equals, onStep } = latest.current;\n if (normalize !== undefined) next = normalize(next);\n // No-op against what the user sees (conventions 2.3 item 8).\n if (equals(next, shownRef.current)) return false;\n const reached = { value: next };\n liveRef.current = reached;\n shownRef.current = next;\n // A controlled parent that adopts steps changes the optimistic value per step.\n lastReason.current = reason;\n setLive(reached);\n setPendingSource(source);\n onStep?.(next);\n // A revert has no commit after it: the optimistic value already shows the committed one.\n if (reason !== \"dismiss\") setStepHeld(true);\n const { stepAction: action, stepTypes, fromShown, details, runStep: run } = latest.current;\n // Without a step action there is nothing to run and no consumer update to keep\n // interruptible: no transition, so `data-pending` does not blink on every pointer move.\n if (action === undefined) return true;\n run(() => {\n for (const type of stepTypes) addTransitionType(type);\n return action(fromShown(next), createActionDetails(event, details(reason, source)));\n });\n return true;\n },\n [latest, shownRef],\n );\n\n const commit = useCallback(\n (source: S | null, reason: ChangeReason, event: Event | undefined): boolean => {\n const start = gestureStart.current;\n gestureStart.current = null;\n // The commit's own pending state holds `live` from here (set in this same batch).\n setStepHeld(false);\n const reached = liveRef.current;\n const { equals, fromShown, details, onCommit } = latest.current;\n // Nothing changed since the gesture began (a drag out and back, a trailing `change`).\n if (start === null || reached === null || equals(reached.value, start.value)) return false;\n const next = reached.value;\n lastReason.current = reason;\n setPendingSource(source);\n dispatch(fromShown(next), createActionDetails(event, details(reason, source)));\n onCommit?.(next, source, reason);\n return true;\n },\n [dispatch, latest],\n );\n\n const openGesture = useCallback(() => {\n const start = { value: shownRef.current };\n gestureStart.current = start;\n liveRef.current = start;\n }, [shownRef]);\n\n const captureGesture = useCallback(() => {\n openGesture();\n // A capture alone holds `live` on screen: start it from what is shown, not from the value\n // an earlier gesture left behind (a press that steps nothing).\n setLive({ value: shownRef.current });\n }, [openGesture, shownRef]);\n\n const markGestureStart = useCallback((start: V) => {\n if (gestureStart.current === null) gestureStart.current = { value: start };\n }, []);\n\n const takeEdit = useCallback(() => {\n const edit = lastReason.current === \"activate\";\n lastReason.current = null;\n return edit;\n }, []);\n\n return {\n shown,\n shownRef,\n optimistic,\n optimisticShown,\n pending,\n pendingSource,\n step,\n commit,\n openGesture,\n captureGesture,\n markGestureStart,\n takeEdit,\n };\n}\n"],"mappings":"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"}
@@ -1,5 +1,5 @@
1
1
  import { FieldValidity } from "./validity.mjs";
2
- //#region src/internal/field-context.d.ts
2
+ //#region src/internal/form/field-context.d.ts
3
3
  /** The state every Field part receives (design/components/field-form.md 4.1). */
4
4
  export interface FieldState {
5
5
  /** An error is shown: the control matches `:user-invalid`, or a server error for this field is shown. */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-context.d.mts","names":[],"sources":["../../../src/internal/form/field-context.ts"],"mappings":";;;iBAMiB;;WAEN;;WAEA;;WAEA,UAAU;;WAEV;;WAEA;;WAEA"}
@@ -1,7 +1,7 @@
1
1
  "use client";
2
- import { dataAttr } from "./data-attr.mjs";
2
+ import { dataAttr } from "../data-attr.mjs";
3
3
  import { createContext, use } from "react";
4
- //#region src/internal/field-context.ts
4
+ //#region src/internal/form/field-context.ts
5
5
  const FieldContext = createContext(null);
6
6
  function useFieldContext(part) {
7
7
  const ctx = use(FieldContext);
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-context.mjs","names":[],"sources":["../../../src/internal/form/field-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport { dataAttr } from \"../data-attr.js\";\nimport type { FieldValidity, FormErrors, ValidatableElement } from \"./validity.js\";\n\n/** The state every Field part receives (design/components/field-form.md 4.1). */\nexport interface FieldState {\n /** An error is shown: the control matches `:user-invalid`, or a server error for this field is shown. */\n readonly invalid: boolean;\n /** The messages shown: `[validationMessage]` for a native constraint, the strings `validate` returned for a custom one, the server's strings for a server error; `[]` while valid. */\n readonly messages: readonly string[];\n /** A snapshot of the control's `ValidityState` (all valid on the server and before the first read). */\n readonly validity: FieldValidity;\n /** `Field.Root disabled` or the control's own `disabled`. */\n readonly disabled: boolean;\n /** `Field.Root required` or the control's own `required`. */\n readonly required: boolean;\n /** The enclosing form's submission is in flight (`useFormStatus().pending`); `false` outside a form. */\n readonly pending: boolean;\n}\n\nexport interface FieldIds {\n readonly control: string;\n readonly label: string;\n readonly description: string;\n readonly error: string;\n}\n\n/** What a control reports to its Field (design 7.1). */\nexport interface FieldControlRegistration {\n /** The element the Field labels, describes and listens to (the input, or a group's fieldset). */\n readonly element: HTMLElement;\n /** `<label for>` can target it. Groups report `false`. */\n readonly labelable: boolean;\n /** The control's own `required` / `disabled` props (for the Field's `data-*` state). */\n readonly required: boolean;\n readonly disabled: boolean;\n /**\n * Where `validity`, `validationMessage` and the custom-validity slot are read and written when\n * that is not the registered element (NumberField: the hidden `input[type=number]` after the\n * visible text input). `:user-invalid`, the listeners and the focus target stay on `element`;\n * after writing the slot the Field mirrors this element's `validationMessage` into `element`\n * (design/components/field-form.md, `validityElement`). Resolved on every read.\n */\n readonly validityElement?: (() => ValidatableElement | null) | undefined;\n}\n\nexport interface FieldContextValue {\n readonly ids: FieldIds;\n /** `Field.Root name`. */\n readonly name: string | undefined;\n /** `Field.Root disabled` / `required` (the props, not the merged state). */\n readonly disabled: boolean;\n readonly required: boolean;\n readonly state: FieldState;\n /** The registered control is labelable (default `true`, also before any registration). */\n readonly labelable: boolean;\n /** Registers the Field's control; returns the unregister function. The first one wins. */\n readonly registerControl: (registration: FieldControlRegistration) => () => void;\n /** A `Field.Error` is mounted (the Field may cancel the platform bubble). */\n readonly registerError: () => () => void;\n /**\n * The control's value changed in the DOM without an `input` / `change` event the Field could\n * hear (a Combobox selection, a CheckboxGroup's derived `required`, a rolled-back optimistic\n * value): re-reads the slot and the mirror after the commit that wrote it, and refreshes the\n * other Fields of the `Form.Root` (cross-field rules). `edit`: the user made the change, so a\n * shown server error is dismissed as by an `input` event. Call from a layout effect.\n */\n readonly notifyChange: (edit: boolean) => void;\n}\n\nexport const FieldContext = createContext<FieldContextValue | null>(null);\n\nexport function useFieldContext(part: string): FieldContextValue {\n const ctx = use(FieldContext);\n if (ctx === null) throw new Error(`${part} must be rendered inside a Field.Root.`);\n return ctx;\n}\n\n/** What a Field registers with its Form (design 3.5). */\nexport interface FormFieldRegistration {\n /** The control, or a group's first enabled (or checked) member. */\n readonly getFocusTarget: () => HTMLElement | null;\n /** The Field shows a server error at the latest commit. */\n readonly showsServerError: () => boolean;\n /** The server messages shown, for an announcement when focus does not move. */\n readonly serverMessages: () => readonly string[];\n /** Re-runs `validate` and re-reads validity (another Field's control changed). */\n readonly refresh: () => void;\n}\n\nexport interface FormContextValue {\n readonly errors: FormErrors | undefined;\n readonly registerField: (registration: FormFieldRegistration) => () => void;\n /**\n * The `FormData` of the submission in flight when the Form ran it itself (the intercepted path),\n * else `null`: the stale-value suppression of design 3.2 item 2 is computed against it.\n */\n readonly submittedData: () => FormData | null;\n /** Refreshes every registered Field except `source` (a change no DOM event carried). */\n readonly refreshFields: (source: FormFieldRegistration | null) => void;\n}\n\nexport const FormContext = createContext<FormContextValue | null>(null);\n\n/** The four state attributes every Field part renders (design 6.1). */\nexport function fieldDataAttributes(state: FieldState) {\n return {\n \"data-invalid\": dataAttr(state.invalid),\n \"data-disabled\": dataAttr(state.disabled),\n \"data-required\": dataAttr(state.required),\n \"data-pending\": dataAttr(state.pending),\n };\n}\n"],"mappings":";;;;AAuEA,MAAa,eAAe,cAAwC,IAAI;AAExE,SAAgB,gBAAgB,MAAiC;CAC/D,MAAM,MAAM,IAAI,YAAY;CAC5B,IAAI,QAAQ,MAAM,MAAM,IAAI,MAAM,GAAG,KAAK,uCAAuC;CACjF,OAAO;AACT;AA0BA,MAAa,cAAc,cAAuC,IAAI;;AAGtE,SAAgB,oBAAoB,OAAmB;CACrD,OAAO;EACL,gBAAgB,SAAS,MAAM,OAAO;EACtC,iBAAiB,SAAS,MAAM,QAAQ;EACxC,iBAAiB,SAAS,MAAM,QAAQ;EACxC,gBAAgB,SAAS,MAAM,OAAO;CACxC;AACF"}
@@ -1,6 +1,6 @@
1
- import { sortByDocumentOrder } from "./dom-order.mjs";
2
- import { announce } from "./announce.mjs";
3
- //#region src/internal/focus-first-invalid.ts
1
+ import { sortByDocumentOrder } from "../dom-order.mjs";
2
+ import { announce } from "../announce.mjs";
3
+ //#region src/internal/form/focus-first-invalid.ts
4
4
  /** The submission attempt in progress: every target added during the current task. */
5
5
  let batch = null;
6
6
  /**
@@ -0,0 +1 @@
1
+ {"version":3,"file":"focus-first-invalid.mjs","names":[],"sources":["../../../src/internal/form/focus-first-invalid.ts"],"sourcesContent":["// Directive-free: the module-level first-invalid collector (design/components/field-form.md 2.5).\nimport { announce } from \"../announce.js\";\nimport { sortByDocumentOrder } from \"../dom-order.js\";\n\ninterface Batch {\n /** The elements whose `invalid` event was collected (a group's members, not its target). */\n readonly sources: Set<Element>;\n readonly targets: HTMLElement[];\n /** The message each target's Field shows, for the announcement when focus does not move. */\n readonly messages: Map<HTMLElement, string>;\n /** `document.activeElement` when the first target arrived. */\n readonly activeBefore: Element | null;\n /** The batch moved focus (later microtasks then re-focus, never announce). */\n moved: boolean;\n /** The target already announced. */\n announced: HTMLElement | null;\n}\n\n/** The submission attempt in progress: every target added during the current task. */\nlet batch: Batch | null = null;\n\n/**\n * Adds a control whose `invalid` event (fired on `source`) a Field cancelled during a submission\n * attempt, and focuses the first collected control in document order in a microtask, so the\n * result does not depend on the browser's dispatch order or on how many forms are on the page.\n *\n * The batch lives until the end of the task (a `setTimeout`), not just one microtask: when the\n * browser dispatches the `invalid` events itself (a click on a submit button), it runs a\n * microtask checkpoint after each listener, so the microtask of the first event runs before the\n * second event fires. Every add therefore queues a focus of the batch's first target; later ones\n * re-focus the same element, which is a no-op.\n *\n * A second `invalid` for the same `source` (the element the event fired on) starts a new batch:\n * one validation fires it once per element, so it belongs to the next attempt, even when that\n * attempt comes before the timer (two attempts in one task, or a test that does not yield to\n * timers between them). Joining the old batch would compare focus with the old attempt's.\n *\n * Skips the focus when focus moved during the attempt to an element that is not one of the\n * collected targets: a plain `<input required>` with no Field kept the platform's behaviour\n * (bubble and focus), and the library does not fight it.\n */\nexport function collectInvalid(target: HTMLElement | null, message: string, source: Element): void {\n if (target === null) return;\n if (batch !== null && batch.sources.has(source)) batch = null;\n if (batch === null) {\n const created: Batch = {\n sources: new Set(),\n targets: [],\n messages: new Map(),\n activeBefore: target.ownerDocument.activeElement,\n moved: false,\n announced: null,\n };\n batch = created;\n setTimeout(() => {\n if (batch === created) batch = null;\n }, 0);\n }\n const current = batch;\n current.sources.add(source);\n if (!current.targets.includes(target)) current.targets.push(target);\n current.messages.set(target, message);\n queueMicrotask(() => focusFirst(current));\n}\n\n/**\n * Tests only: forget the submission attempt in progress. Its timer is a task away, and the next\n * test can start before it runs (no task in between); its attempt would then join this one and\n * compare focus with an element of the previous test.\n */\nexport function resetInvalidBatch(): void {\n batch = null;\n}\n\nfunction focusFirst(current: Batch): void {\n const { targets, activeBefore } = current;\n const connected = targets.filter((t) => t.isConnected);\n if (connected.length === 0) return;\n const active = connected[0]!.ownerDocument.activeElement;\n if (active !== activeBefore && active !== null && !connected.includes(active as HTMLElement)) {\n return;\n }\n const first = sortByDocumentOrder(connected, (t) => t)[0]!;\n if (active !== first) {\n current.moved = true;\n first.focus();\n } else if (!current.moved && current.announced !== first) {\n // Focus was already on the first invalid control (an implicit submission with Enter): the\n // cancelled bubble was the only announcement, so speak the message instead.\n current.announced = first;\n announce(first, current.messages.get(first) ?? \"\");\n }\n}\n"],"mappings":";;;;AAmBA,IAAI,QAAsB;;;;;;;;;;;;;;;;;;;;;AAsB1B,SAAgB,eAAe,QAA4B,SAAiB,QAAuB;CACjG,IAAI,WAAW,MAAM;CACrB,IAAI,UAAU,QAAQ,MAAM,QAAQ,IAAI,MAAM,GAAG,QAAQ;CACzD,IAAI,UAAU,MAAM;EAClB,MAAM,UAAiB;GACrB,yBAAS,IAAI,IAAI;GACjB,SAAS,CAAC;GACV,0BAAU,IAAI,IAAI;GAClB,cAAc,OAAO,cAAc;GACnC,OAAO;GACP,WAAW;EACb;EACA,QAAQ;EACR,iBAAiB;GACf,IAAI,UAAU,SAAS,QAAQ;EACjC,GAAG,CAAC;CACN;CACA,MAAM,UAAU;CAChB,QAAQ,QAAQ,IAAI,MAAM;CAC1B,IAAI,CAAC,QAAQ,QAAQ,SAAS,MAAM,GAAG,QAAQ,QAAQ,KAAK,MAAM;CAClE,QAAQ,SAAS,IAAI,QAAQ,OAAO;CACpC,qBAAqB,WAAW,OAAO,CAAC;AAC1C;AAWA,SAAS,WAAW,SAAsB;CACxC,MAAM,EAAE,SAAS,iBAAiB;CAClC,MAAM,YAAY,QAAQ,QAAQ,MAAM,EAAE,WAAW;CACrD,IAAI,UAAU,WAAW,GAAG;CAC5B,MAAM,SAAS,UAAU,EAAE,CAAE,cAAc;CAC3C,IAAI,WAAW,gBAAgB,WAAW,QAAQ,CAAC,UAAU,SAAS,MAAqB,GACzF;CAEF,MAAM,QAAQ,oBAAoB,YAAY,MAAM,CAAC,CAAC,CAAC;CACvD,IAAI,WAAW,OAAO;EACpB,QAAQ,QAAQ;EAChB,MAAM,MAAM;CACd,OAAO,IAAI,CAAC,QAAQ,SAAS,QAAQ,cAAc,OAAO;EAGxD,QAAQ,YAAY;EACpB,SAAS,OAAO,QAAQ,SAAS,IAAI,KAAK,KAAK,EAAE;CACnD;AACF"}
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { useEffect, useRef } from "react";
3
3
  import { useFormStatus } from "react-dom";
4
- //#region src/internal/form-status-watcher.tsx
4
+ //#region src/internal/form/form-status-watcher.tsx
5
5
  /**
6
6
  * Observes React's form channel (Dialog design 8.1, Field/Form design 3.2): rendered inside a
7
7
  * `<form>`, `useFormStatus().pending` covers the action's whole transition, including the
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form-status-watcher.mjs","names":[],"sources":["../../../src/internal/form/form-status-watcher.tsx"],"sourcesContent":["\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { useFormStatus } from \"react-dom\";\n\nexport interface FormStatusWatcherProps {\n readonly onPendingChange: (pending: boolean) => void;\n readonly onSettled: () => void;\n}\n\n/**\n * Observes React's form channel (Dialog design 8.1, Field/Form design 3.2): rendered inside a\n * `<form>`, `useFormStatus().pending` covers the action's whole transition, including the\n * Suspense wait of what it re-renders. On `true → false` the submission settled without throwing\n * (a rejection unmounts the form through the nearest Error Boundary, so the edge is never seen).\n * Used by `Dialog.Form` and `Form.Root`.\n */\nexport function FormStatusWatcher({ onPendingChange, onSettled }: FormStatusWatcherProps) {\n const { pending } = useFormStatus();\n const previous = useRef(false);\n useEffect(() => {\n const was = previous.current;\n previous.current = pending;\n if (was === pending) return;\n onPendingChange(pending);\n if (was && !pending) onSettled();\n }, [pending, onPendingChange, onSettled]);\n return null;\n}\n"],"mappings":";;;;;;;;;;;AAgBA,SAAgB,kBAAkB,EAAE,iBAAiB,aAAqC;CACxF,MAAM,EAAE,YAAY,cAAc;CAClC,MAAM,WAAW,OAAO,KAAK;CAC7B,gBAAgB;EACd,MAAM,MAAM,SAAS;EACrB,SAAS,UAAU;EACnB,IAAI,QAAQ,SAAS;EACrB,gBAAgB,OAAO;EACvB,IAAI,OAAO,CAAC,SAAS,UAAU;CACjC,GAAG;EAAC;EAAS;EAAiB;CAAS,CAAC;CACxC,OAAO;AACT"}
@@ -1,7 +1,7 @@
1
1
  "use client";
2
- import { dataAttr } from "./data-attr.mjs";
2
+ import { dataAttr } from "../data-attr.mjs";
3
3
  import { guardCheckableChange } from "./use-native-checked.mjs";
4
- //#region src/internal/group-member.ts
4
+ //#region src/internal/form/group-member.ts
5
5
  /**
6
6
  * The owned layer (conventions 1.2) of a group Item's `<input>`: `type`, the group's `name` /
7
7
  * `form`, `value`, `checked` (the optimistic state), `defaultChecked` (never rendered), a
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-member.mjs","names":[],"sources":["../../../src/internal/form/group-member.ts"],"sourcesContent":["\"use client\";\nimport type { ChangeEvent, ComponentPropsWithRef } from \"react\";\nimport { dataAttr } from \"../data-attr.js\";\nimport type { DataAttributes } from \"../render-element.js\";\nimport { guardCheckableChange } from \"./use-native-checked.js\";\n\nexport interface GroupMemberPropsOptions {\n readonly type: \"radio\" | \"checkbox\";\n /** Dispatch-guard name (`\"RadioGroup.Item\"`). */\n readonly component: string;\n /** The group's shared `name` and `form`. */\n readonly name: string;\n readonly form: string | undefined;\n readonly value: string;\n readonly required: boolean;\n /** Optimistic. */\n readonly checked: boolean;\n readonly pending: boolean;\n /** Own `disabled` prop or the Root's: `data-disabled` and the click guard. */\n readonly effectiveDisabled: boolean;\n /** The member's own `disabled` prop only: the Root's reaches it through `<fieldset disabled>`. */\n readonly ownDisabled: boolean;\n /** CheckboxGroup inside a Field: the group's `aria-invalid` (the fieldset cannot carry it). */\n readonly invalid?: \"true\" | \"false\" | undefined;\n /** The user checked (radio) or toggled (checkbox) the input. */\n readonly activate: (event: Event) => void;\n}\n\n/**\n * The owned layer (conventions 1.2) of a group Item's `<input>`: `type`, the group's `name` /\n * `form`, `value`, `checked` (the optimistic state), `defaultChecked` (never rendered), a\n * checkbox's `aria-checked` (removed), `disabled`, `required`, the state `data-*` attributes,\n * and the guarded `onChange`.\n */\nexport function groupMemberProps(\n options: GroupMemberPropsOptions,\n): Partial<ComponentPropsWithRef<\"input\">> & DataAttributes {\n const { type, component, checked, pending, effectiveDisabled, invalid, activate } = options;\n return {\n type,\n name: options.name,\n value: options.value,\n checked,\n defaultChecked: undefined,\n ...(type === \"checkbox\" && { \"aria-checked\": undefined }),\n // Owned (Switch precedent) so that native disabledness, `data-disabled` and the click guard\n // agree. Only the Item's own prop: `Root disabled` reaches the input through the fieldset.\n disabled: options.ownDisabled,\n form: options.form,\n required: options.required,\n \"data-checked\": dataAttr(checked),\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(effectiveDisabled),\n ...(invalid !== undefined && { \"aria-invalid\": invalid }),\n onChange: (event: ChangeEvent<HTMLInputElement>) => {\n // A natively disabled input fires no click; this covers `render` elements that do not\n // honour `disabled`.\n if (effectiveDisabled) return;\n const nativeEvent = event.nativeEvent;\n guardCheckableChange(nativeEvent, () => activate(nativeEvent), component);\n },\n };\n}\n"],"mappings":";;;;;;;;;;AAkCA,SAAgB,iBACd,SAC0D;CAC1D,MAAM,EAAE,MAAM,WAAW,SAAS,SAAS,mBAAmB,SAAS,aAAa;CACpF,OAAO;EACL;EACA,MAAM,QAAQ;EACd,OAAO,QAAQ;EACf;EACA,gBAAgB,KAAA;EAChB,GAAI,SAAS,cAAc,EAAE,gBAAgB,KAAA,EAAU;EAGvD,UAAU,QAAQ;EAClB,MAAM,QAAQ;EACd,UAAU,QAAQ;EAClB,gBAAgB,SAAS,OAAO;EAChC,gBAAgB,SAAS,OAAO;EAChC,iBAAiB,SAAS,iBAAiB;EAC3C,GAAI,YAAY,KAAA,KAAa,EAAE,gBAAgB,QAAQ;EACvD,WAAW,UAAyC;GAGlD,IAAI,mBAAmB;GACvB,MAAM,cAAc,MAAM;GAC1B,qBAAqB,mBAAmB,SAAS,WAAW,GAAG,SAAS;EAC1E;CACF;AACF"}
@@ -1,4 +1,4 @@
1
- //#region src/internal/sync-presence.ts
1
+ //#region src/internal/form/sync-presence.ts
2
2
  /**
3
3
  * Makes a boolean attribute's presence match `present`. For group members that may hydrate after
4
4
  * their Root (`RadioGroup.Item`, `CheckboxGroup.Item` / `Parent`): hydration keeps server
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-presence.mjs","names":[],"sources":["../../../src/internal/form/sync-presence.ts"],"sourcesContent":["/**\n * Makes a boolean attribute's presence match `present`. For group members that may hydrate after\n * their Root (`RadioGroup.Item`, `CheckboxGroup.Item` / `Parent`): hydration keeps server\n * attributes that differ from the client render (React only warns), and a member hydrating late\n * can render a different state than the server did.\n *\n * No `\"use client\"` directive: no client-only API (conventions 7.1).\n */\nexport function syncPresence(el: Element, name: string, present: boolean): void {\n if (el.hasAttribute(name) !== present) {\n if (present) el.setAttribute(name, \"\");\n else el.removeAttribute(name);\n }\n}\n\n/** `syncPresence` for each entry of `attributes`, in order. */\nexport function syncPresences(el: Element, attributes: Readonly<Record<string, boolean>>): void {\n for (const [name, present] of Object.entries(attributes)) syncPresence(el, name, present);\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,aAAa,IAAa,MAAc,SAAwB;CAC9E,IAAI,GAAG,aAAa,IAAI,MAAM,SAAS;EACrC,IAAI,SAAS,GAAG,aAAa,MAAM,EAAE;OAChC,GAAG,gBAAgB,IAAI;CAC9B;AACF;;AAGA,SAAgB,cAAc,IAAa,YAAqD;CAC9F,KAAK,MAAM,CAAC,MAAM,YAAY,OAAO,QAAQ,UAAU,GAAG,aAAa,IAAI,MAAM,OAAO;AAC1F"}
@@ -1,11 +1,11 @@
1
1
  "use client";
2
- import { createActionDetails } from "./action-details.mjs";
3
- import { dataAttr } from "./data-attr.mjs";
4
- import { useControllableAction } from "./use-controllable-action.mjs";
5
- import { useMergedRefs } from "./use-merged-refs.mjs";
2
+ import { createActionDetails } from "../action/action-details.mjs";
3
+ import { dataAttr } from "../data-attr.mjs";
4
+ import { useControllableAction } from "../action/use-controllable-action.mjs";
5
+ import { useMergedRefs } from "../use-merged-refs.mjs";
6
6
  import { fieldInputProps, useFieldControl, useFieldValueChange } from "./use-field-control.mjs";
7
7
  import { guardCheckableChange, useNativeChecked } from "./use-native-checked.mjs";
8
- //#region src/internal/use-checkable-input.ts
8
+ //#region src/internal/form/use-checkable-input.ts
9
9
  /**
10
10
  * The single-checkbox machinery `Checkbox` and `Switch` share: the Field wiring, the
11
11
  * controllable action, the native `checked` re-apply and reconciliation (`useNativeChecked`),
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-checkable-input.mjs","names":[],"sources":["../../../src/internal/form/use-checkable-input.ts"],"sourcesContent":["\"use client\";\nimport type { ChangeEvent, ComponentPropsWithRef, Ref } from \"react\";\nimport { createActionDetails } from \"../action/action-details.js\";\nimport { dataAttr } from \"../data-attr.js\";\nimport type { DataAttributes } from \"../render-element.js\";\nimport type { ActionDetails, ChangeAction, ChangeReason } from \"../types.js\";\nimport { useControllableAction } from \"../action/use-controllable-action.js\";\nimport { fieldInputProps, useFieldControl, useFieldValueChange } from \"./use-field-control.js\";\nimport { useMergedRefs } from \"../use-merged-refs.js\";\nimport { guardCheckableChange, useNativeChecked } from \"./use-native-checked.js\";\n\n/** The details shape `Checkbox` and `Switch` share (each declares its own public name). */\nexport interface CheckableChangeDetails extends ActionDetails {\n readonly reason: ChangeReason;\n}\n\nexport interface UseCheckableInputOptions {\n /** Warning tag and dispatch-guard name. */\n readonly component: \"Checkbox\" | \"Switch\";\n readonly checked: boolean | undefined;\n readonly defaultChecked: boolean | undefined;\n readonly checkedChangeAction: ChangeAction<boolean, CheckableChangeDetails> | undefined;\n /** The `disabled` prop. */\n readonly disabled: boolean | undefined;\n /** The control's own `name` / `required` / `id` (the Field's \"own or the Field's\"). */\n readonly own: Pick<ComponentPropsWithRef<\"input\">, \"name\" | \"required\" | \"id\">;\n /** View Transition types of a dispatch of `next`. */\n readonly transitionTypes: (next: boolean) => readonly string[];\n /** Switch only: the owned `role`. */\n readonly role?: \"switch\" | undefined;\n /** Checkbox only: the `indeterminate` prop. `undefined` for a control with no mixed state. */\n readonly indeterminate?: boolean | undefined;\n}\n\nexport interface CheckableInput {\n readonly optimistic: boolean;\n readonly pending: boolean;\n /** Own `disabled` or the Field's. */\n readonly disabled: boolean;\n /** `indeterminate && !pending`. */\n readonly shownIndeterminate: boolean;\n readonly ref: Ref<HTMLInputElement> | undefined;\n /** The owned layer (conventions 1.2) of the input. */\n readonly libraryProps: Partial<ComponentPropsWithRef<\"input\">> & DataAttributes;\n}\n\n/**\n * The single-checkbox machinery `Checkbox` and `Switch` share: the Field wiring, the\n * controllable action, the native `checked` re-apply and reconciliation (`useNativeChecked`),\n * and the input's owned layer. The components keep their props, state, `useRender` call and\n * transition boundary.\n */\nexport function useCheckableInput(options: UseCheckableInputOptions): CheckableInput {\n const {\n component,\n checked,\n defaultChecked,\n checkedChangeAction,\n disabled: disabledProp,\n own,\n transitionTypes,\n role,\n indeterminate,\n } = options;\n // Inside a Field.Root (design/components/field-form.md 7.2) the Field owns the id and the ARIA\n // wiring, and `name` / `required` / `disabled` default from it.\n const field = useFieldControl({\n labelable: true,\n name: own.name,\n disabled: disabledProp,\n required: own.required,\n id: own.id,\n component,\n });\n const disabled = field.disabled;\n\n const { optimistic, pending, dispatch, latestInFlight } = useControllableAction<\n boolean,\n CheckableChangeDetails\n >({\n controlled: checked,\n defaultValue: defaultChecked,\n initialValue: false,\n action: checkedChangeAction,\n transitionTypes,\n warn: { component, prop: \"checked\" },\n });\n // Inside a Field: a value React writes with no event (a rejected action rolling back, a\n // controlled change) re-reads validity and `validate` after the commit.\n useFieldValueChange(optimistic);\n\n // Suspended while pending (conventions 4.1): the browser clears the property on the click, and\n // the parent may not have recomputed yet. Restored on settle if the parent still says mixed.\n const mixed = indeterminate !== undefined;\n const shownIndeterminate = indeterminate === true && !pending;\n\n const inputRef = useNativeChecked({\n type: \"checkbox\",\n component,\n checked: optimistic,\n // Uncontrolled: the latest prop is the reset target. Controlled: React's mount-time value.\n defaultChecked: checked === undefined ? (defaultChecked ?? false) : undefined,\n indeterminate: mixed ? shownIndeterminate : undefined,\n latestInFlight,\n onPlatformChange: (next, event) =>\n dispatch(next, createActionDetails(event, { reason: \"platform\" })),\n });\n\n const ref = useMergedRefs<HTMLInputElement>(inputRef, field.ref);\n\n const libraryProps = {\n ...fieldInputProps(field),\n type: \"checkbox\",\n ...(role !== undefined && { role }),\n // The DOM state is the optimistic state (conventions 3.2): react-dom restores a controlled\n // input to its props after every event, and only the sync-lane optimistic value survives.\n checked: optimistic,\n defaultChecked: undefined,\n // Not a DOM attribute; `useNativeChecked` sets the property. Owned so a `render` element's\n // own `indeterminate` prop (which react-dom would warn about) is stripped.\n ...(mixed && { indeterminate: undefined }),\n \"aria-checked\": undefined,\n // Owned so that native disabledness, `data-disabled` and the click guard always agree: a\n // `render` element cannot re-enable (`disabled={false}`) or disable the input on its own.\n disabled,\n \"data-checked\": dataAttr(optimistic),\n ...(mixed && { \"data-indeterminate\": dataAttr(shownIndeterminate) }),\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n onChange: (event: ChangeEvent<HTMLInputElement>) => {\n // A natively disabled input fires no click; this covers `render` elements that do not\n // honour `disabled`.\n if (disabled) return;\n const nativeEvent = event.nativeEvent;\n // `indeterminate` plays no part: the platform's rule is \"flip checked, clear mixed\".\n guardCheckableChange(\n nativeEvent,\n () => dispatch(!optimistic, createActionDetails(nativeEvent, { reason: \"activate\" })),\n component,\n );\n },\n };\n\n return { optimistic, pending, disabled, shownIndeterminate, ref, libraryProps };\n}\n"],"mappings":";;;;;;;;;;;;;;AAoDA,SAAgB,kBAAkB,SAAmD;CACnF,MAAM,EACJ,WACA,SACA,gBACA,qBACA,UAAU,cACV,KACA,iBACA,MACA,kBACE;CAGJ,MAAM,QAAQ,gBAAgB;EAC5B,WAAW;EACX,MAAM,IAAI;EACV,UAAU;EACV,UAAU,IAAI;EACd,IAAI,IAAI;EACR;CACF,CAAC;CACD,MAAM,WAAW,MAAM;CAEvB,MAAM,EAAE,YAAY,SAAS,UAAU,mBAAmB,sBAGxD;EACA,YAAY;EACZ,cAAc;EACd,cAAc;EACd,QAAQ;EACR;EACA,MAAM;GAAE;GAAW,MAAM;EAAU;CACrC,CAAC;CAGD,oBAAoB,UAAU;CAI9B,MAAM,QAAQ,kBAAkB,KAAA;CAChC,MAAM,qBAAqB,kBAAkB,QAAQ,CAAC;CAEtD,MAAM,WAAW,iBAAiB;EAChC,MAAM;EACN;EACA,SAAS;EAET,gBAAgB,YAAY,KAAA,IAAa,kBAAkB,QAAS,KAAA;EACpE,eAAe,QAAQ,qBAAqB,KAAA;EAC5C;EACA,mBAAmB,MAAM,UACvB,SAAS,MAAM,oBAAoB,OAAO,EAAE,QAAQ,WAAW,CAAC,CAAC;CACrE,CAAC;CAqCD,OAAO;EAAE;EAAY;EAAS;EAAU;EAAoB,KAnChD,cAAgC,UAAU,MAAM,GAmCE;EAAG,cAAA;GAhC/D,GAAG,gBAAgB,KAAK;GACxB,MAAM;GACN,GAAI,SAAS,KAAA,KAAa,EAAE,KAAK;GAGjC,SAAS;GACT,gBAAgB,KAAA;GAGhB,GAAI,SAAS,EAAE,eAAe,KAAA,EAAU;GACxC,gBAAgB,KAAA;GAGhB;GACA,gBAAgB,SAAS,UAAU;GACnC,GAAI,SAAS,EAAE,sBAAsB,SAAS,kBAAkB,EAAE;GAClE,gBAAgB,SAAS,OAAO;GAChC,iBAAiB,SAAS,QAAQ;GAClC,WAAW,UAAyC;IAGlD,IAAI,UAAU;IACd,MAAM,cAAc,MAAM;IAE1B,qBACE,mBACM,SAAS,CAAC,YAAY,oBAAoB,aAAa,EAAE,QAAQ,WAAW,CAAC,CAAC,GACpF,SACF;GACF;EAG0E;CAAE;AAChF"}
@@ -1,9 +1,9 @@
1
1
  "use client";
2
- import { dataAttr } from "./data-attr.mjs";
3
- import { useDevWarning } from "./use-dev-warning.mjs";
2
+ import { dataAttr } from "../data-attr.mjs";
3
+ import { useDevWarning } from "../use-dev-warning.mjs";
4
4
  import { FieldContext } from "./field-context.mjs";
5
5
  import { use, useCallback, useLayoutEffect, useRef } from "react";
6
- //#region src/internal/use-field-control.ts
6
+ //#region src/internal/form/use-field-control.ts
7
7
  const isDev = process.env.NODE_ENV !== "production";
8
8
  /**
9
9
  * "Own or the Field's" (design/components/field-form.md 7.1): `name` falls back to the Field's,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-field-control.mjs","names":[],"sources":["../../../src/internal/form/use-field-control.ts"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useLayoutEffect, useRef } from \"react\";\nimport type { RefCallback } from \"react\";\nimport { dataAttr } from \"../data-attr.js\";\nimport { FieldContext } from \"./field-context.js\";\nimport type { FieldContextValue, FieldState } from \"./field-context.js\";\nimport { useDevWarning } from \"../use-dev-warning.js\";\nimport type { ValidatableElement } from \"./validity.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport interface UseFieldControlOptions {\n /** `<label for>` can target the element (input, select, textarea). Groups pass `false`. */\n readonly labelable: boolean;\n /** The control's own props, so \"own or the Field's\" can be computed. */\n readonly name?: string | undefined;\n readonly disabled?: boolean | undefined;\n readonly required?: boolean | undefined;\n /** The consumer's own `id` prop: ignored inside a Field (the Field owns it), with a warning. */\n readonly id?: string | undefined;\n /** Dev warning tag. */\n readonly component: string;\n /**\n * The element whose validity is real when it is not the registered one (NumberField's hidden\n * number input; field-form.md `validityElement`). Keep its identity stable.\n */\n readonly validityElement?: (() => ValidatableElement | null) | undefined;\n}\n\n/** The ARIA and state attributes a part spreads into its owned layer. */\nexport interface FieldControlAttributes {\n /** Labelable controls only: the id `Field.Label`'s `for` points at. */\n id?: string;\n \"aria-labelledby\"?: string;\n \"aria-describedby\"?: string;\n \"aria-invalid\"?: \"true\" | \"false\";\n \"data-invalid\"?: \"\" | undefined;\n}\n\nexport interface FieldControlBinding {\n /** The control is inside a `Field.Root`. */\n readonly inField: boolean;\n /** Merge into the part's library ref: registers the element with the Field. `undefined` outside a Field. */\n readonly ref: RefCallback<HTMLElement> | undefined;\n /** The control id the Field's Label points at (labelable controls inside a Field), else the consumer's. */\n readonly id: string | undefined;\n /** Own `name` ?? the Field's. */\n readonly name: string | undefined;\n /** The Field's own `name` (`undefined` outside a Field or when it has none). */\n readonly fieldName: string | undefined;\n /** Own `disabled` || the Field's. */\n readonly disabled: boolean;\n /** Own `required` || the Field's. */\n readonly required: boolean;\n /**\n * Owned attributes: `id` (labelable controls), `aria-invalid`, `data-invalid`,\n * `aria-labelledby` (groups) and `aria-describedby` (both token-merged by the owned layer, the\n * consumer's tokens first). Empty outside a Field, so nothing is owned there.\n */\n readonly attributes: FieldControlAttributes;\n /** The Field's state, `undefined` outside a Field. */\n readonly state: FieldState | undefined;\n}\n\n/**\n * \"Own or the Field's\" (design/components/field-form.md 7.1): `name` falls back to the Field's,\n * `disabled` and `required` are either's. Outside a Field (`field === null`) the own props.\n */\nexport function resolveFieldDefaults(\n field: Pick<FieldContextValue, \"name\" | \"disabled\" | \"required\"> | null,\n own: {\n readonly name: string | undefined;\n readonly disabled: boolean;\n readonly required: boolean;\n },\n): { name: string | undefined; disabled: boolean; required: boolean } {\n if (field === null) return { name: own.name, disabled: own.disabled, required: own.required };\n return {\n name: own.name ?? field.name,\n disabled: own.disabled || field.disabled,\n required: own.required || field.required,\n };\n}\n\n/**\n * The owned props of a labelable native control (`<input>`, `<select>`) inside a Field: the\n * ARIA wiring plus `name` and `required` (\"own or the Field's\"). Empty outside a Field, so the\n * consumer's own `id` / `name` / `required` keep passing through untouched there.\n */\nexport function fieldInputProps(field: FieldControlBinding): FieldControlAttributes & {\n name?: string | undefined;\n required?: boolean;\n} {\n if (!field.inField) return {};\n return { ...field.attributes, name: field.name, required: field.required };\n}\n\n/**\n * The contract between a Field and its control (design/components/field-form.md 7.1), called by\n * `Field.Control` and by the owner part of every FUNSTACK form control. Outside a `Field.Root` it\n * returns the control's own props and nothing to merge.\n *\n * Inside a Field: registers the element from the returned ref (the Field attaches its listeners\n * and reads validity there; a group's `<fieldset>` makes `Field.Label` drop `for`), resolves \"own\n * or the Field's\" for `name` / `disabled` / `required`, and returns the owned ARIA wiring.\n */\nexport function useFieldControl(options: UseFieldControlOptions): FieldControlBinding {\n const {\n labelable,\n name,\n disabled = false,\n required = false,\n id,\n component,\n validityElement,\n } = options;\n const field = use(FieldContext);\n const registerControl = field?.registerControl;\n\n const ref = useCallback(\n (element: HTMLElement) => {\n if (registerControl === undefined) return () => {};\n return registerControl({ element, labelable, required, disabled, validityElement });\n },\n [registerControl, labelable, required, disabled, validityElement],\n );\n\n useDevWarning(\n field !== null && id !== undefined,\n isDev &&\n `${component}: the \\`id\\` prop is ignored inside a Field.Root; the Field owns the control's ` +\n \"id so that Field.Label can point at it.\",\n );\n useDevWarning(\n field !== null && name !== undefined && field.name !== undefined && name !== field.name,\n isDev &&\n `${component}: its \\`name\\` (\"${name}\") differs from the Field.Root's (\"${field?.name}\"). ` +\n \"The Field reads server errors and `validate`'s value by the Field's name.\",\n );\n\n if (field === null) {\n return {\n inField: false,\n ref: undefined,\n id,\n name,\n fieldName: undefined,\n disabled,\n required,\n attributes: {},\n state: undefined,\n };\n }\n\n const { ids, state } = field;\n const attributes: FieldControlAttributes = {\n \"aria-describedby\": state.invalid ? `${ids.description} ${ids.error}` : ids.description,\n \"aria-invalid\": state.invalid ? \"true\" : \"false\",\n \"data-invalid\": dataAttr(state.invalid),\n };\n if (labelable) attributes.id = ids.control;\n else attributes[\"aria-labelledby\"] = ids.label;\n\n return {\n inField: true,\n ref,\n id: labelable ? ids.control : undefined,\n ...resolveFieldDefaults(field, { name, disabled, required }),\n fieldName: field.name,\n attributes,\n state,\n };\n}\n\n/**\n * Tells the enclosing Field (if any) that the control's value changed, after the commit that\n * wrote it to the DOM (design/components/field-form.md 2.1: `validate` and the mirror follow the\n * value). Needed where the DOM changes without an `input` / `change` event the Field hears: a\n * Combobox selection (React writes the hidden input), a CheckboxGroup's derived `required`, a\n * Parent checking Items, a rejected action rolling the value back. Nothing at mount.\n *\n * `takeEdit` is read when the value changed: `true` when the user made this change (a shown\n * server error is dismissed, like an `input` event would). Native controls whose own events\n * already dismiss pass nothing.\n */\nexport function useFieldValueChange(value: unknown, takeEdit?: () => boolean): void {\n const notifyChange = use(FieldContext)?.notifyChange;\n const previous = useRef(value);\n // No deps: compares with the last committed value after every commit of the caller.\n useLayoutEffect(() => {\n if (Object.is(previous.current, value)) return;\n previous.current = value;\n const edit = takeEdit?.() ?? false;\n notifyChange?.(edit);\n });\n}\n"],"mappings":";;;;;;AASA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;AA2DvC,SAAgB,qBACd,OACA,KAKoE;CACpE,IAAI,UAAU,MAAM,OAAO;EAAE,MAAM,IAAI;EAAM,UAAU,IAAI;EAAU,UAAU,IAAI;CAAS;CAC5F,OAAO;EACL,MAAM,IAAI,QAAQ,MAAM;EACxB,UAAU,IAAI,YAAY,MAAM;EAChC,UAAU,IAAI,YAAY,MAAM;CAClC;AACF;;;;;;AAOA,SAAgB,gBAAgB,OAG9B;CACA,IAAI,CAAC,MAAM,SAAS,OAAO,CAAC;CAC5B,OAAO;EAAE,GAAG,MAAM;EAAY,MAAM,MAAM;EAAM,UAAU,MAAM;CAAS;AAC3E;;;;;;;;;;AAWA,SAAgB,gBAAgB,SAAsD;CACpF,MAAM,EACJ,WACA,MACA,WAAW,OACX,WAAW,OACX,IACA,WACA,oBACE;CACJ,MAAM,QAAQ,IAAI,YAAY;CAC9B,MAAM,kBAAkB,OAAO;CAE/B,MAAM,MAAM,aACT,YAAyB;EACxB,IAAI,oBAAoB,KAAA,GAAW,aAAa,CAAC;EACjD,OAAO,gBAAgB;GAAE;GAAS;GAAW;GAAU;GAAU;EAAgB,CAAC;CACpF,GACA;EAAC;EAAiB;EAAW;EAAU;EAAU;CAAe,CAClE;CAEA,cACE,UAAU,QAAQ,OAAO,KAAA,GACzB,SACE,GAAG,UAAU,uHAEjB;CACA,cACE,UAAU,QAAQ,SAAS,KAAA,KAAa,MAAM,SAAS,KAAA,KAAa,SAAS,MAAM,MACnF,SACE,GAAG,UAAU,mBAAmB,KAAK,qCAAqC,OAAO,KAAK,gFAE1F;CAEA,IAAI,UAAU,MACZ,OAAO;EACL,SAAS;EACT,KAAK,KAAA;EACL;EACA;EACA,WAAW,KAAA;EACX;EACA;EACA,YAAY,CAAC;EACb,OAAO,KAAA;CACT;CAGF,MAAM,EAAE,KAAK,UAAU;CACvB,MAAM,aAAqC;EACzC,oBAAoB,MAAM,UAAU,GAAG,IAAI,YAAY,GAAG,IAAI,UAAU,IAAI;EAC5E,gBAAgB,MAAM,UAAU,SAAS;EACzC,gBAAgB,SAAS,MAAM,OAAO;CACxC;CACA,IAAI,WAAW,WAAW,KAAK,IAAI;MAC9B,WAAW,qBAAqB,IAAI;CAEzC,OAAO;EACL,SAAS;EACT;EACA,IAAI,YAAY,IAAI,UAAU,KAAA;EAC9B,GAAG,qBAAqB,OAAO;GAAE;GAAM;GAAU;EAAS,CAAC;EAC3D,WAAW,MAAM;EACjB;EACA;CACF;AACF;;;;;;;;;;;;AAaA,SAAgB,oBAAoB,OAAgB,UAAgC;CAClF,MAAM,eAAe,IAAI,YAAY,CAAC,EAAE;CACxC,MAAM,WAAW,OAAO,KAAK;CAE7B,sBAAsB;EACpB,IAAI,OAAO,GAAG,SAAS,SAAS,KAAK,GAAG;EACxC,SAAS,UAAU;EACnB,MAAM,OAAO,WAAW,KAAK;EAC7B,eAAe,IAAI;CACrB,CAAC;AACH"}
@@ -1,9 +1,9 @@
1
1
  "use client";
2
- import { useElementCheck } from "./use-element-check.mjs";
3
- import { useMergedRefs } from "./use-merged-refs.mjs";
2
+ import { useElementCheck } from "../use-element-check.mjs";
3
+ import { useMergedRefs } from "../use-merged-refs.mjs";
4
4
  import { useFieldControl } from "./use-field-control.mjs";
5
5
  import { useCallback, useId, useRef } from "react";
6
- //#region src/internal/use-fieldset-group.ts
6
+ //#region src/internal/form/use-fieldset-group.ts
7
7
  const isDev = process.env.NODE_ENV !== "production";
8
8
  /**
9
9
  * The `<fieldset>` wiring of a native-input group Root (`RadioGroup.Root`,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-fieldset-group.mjs","names":[],"sources":["../../../src/internal/form/use-fieldset-group.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useId, useRef } from \"react\";\nimport type { Ref, RefObject } from \"react\";\nimport type { FieldControlBinding } from \"./use-field-control.js\";\nimport { useFieldControl } from \"./use-field-control.js\";\nimport { useElementCheck } from \"../use-element-check.js\";\nimport { useMergedRefs } from \"../use-merged-refs.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport interface UseFieldsetGroupOptions {\n /** Dev warning tag (`\"RadioGroup.Root\"`). */\n readonly component: string;\n /** The Root's own `name` / `disabled` / `required` props. */\n readonly name: string | undefined;\n readonly disabled: boolean | undefined;\n readonly required: boolean | undefined;\n}\n\nexport interface FieldsetGroup {\n readonly field: FieldControlBinding;\n /** Own `name`, else the Field's, else a `useId()` value. */\n readonly name: string;\n /** Own `required` or the Field's. */\n readonly required: boolean;\n /** Own `disabled` or the Field's. */\n readonly disabled: boolean;\n /** The rendered `<fieldset>`. */\n readonly fieldsetRef: RefObject<HTMLFieldSetElement | null>;\n /** The Root's library ref: fills `fieldsetRef`, checks the element, registers with the Field. */\n readonly rootRef: Ref<HTMLFieldSetElement> | undefined;\n}\n\n/**\n * The `<fieldset>` wiring of a native-input group Root (`RadioGroup.Root`,\n * `CheckboxGroup.Root`). Inside a `Field.Root` (design/components/field-form.md 7.2) the fieldset\n * is the Field's group control: `aria-labelledby` → `Field.Label`, the ARIA wiring, and `name` /\n * `required` / `disabled` defaulting from the Field.\n */\nexport function useFieldsetGroup(options: UseFieldsetGroupOptions): FieldsetGroup {\n const { component } = options;\n const field = useFieldControl({\n labelable: false,\n name: options.name,\n disabled: options.disabled,\n required: options.required,\n component,\n });\n const fallbackName = useId();\n const fieldsetRef = useRef<HTMLFieldSetElement | null>(null);\n\n const checkElement = useElementCheck<HTMLFieldSetElement>(\n isDev &&\n ((el) =>\n el.tagName !== \"FIELDSET\"\n ? `${component}: expected to render a <fieldset> element but got ` +\n `<${el.tagName.toLowerCase()}>. The platform semantics (legend naming, disabled ` +\n `inheritance, form reset) need a real <fieldset>.`\n : null),\n );\n const libraryRef = useCallback(\n (el: HTMLFieldSetElement) => {\n fieldsetRef.current = el;\n checkElement?.(el);\n return () => {\n fieldsetRef.current = null;\n };\n },\n [checkElement],\n );\n const rootRef = useMergedRefs<HTMLFieldSetElement>(libraryRef, field.ref);\n\n return {\n field,\n name: field.name ?? fallbackName,\n required: field.required,\n disabled: field.disabled,\n fieldsetRef,\n rootRef,\n };\n}\n"],"mappings":";;;;;;AAQA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;AA+BvC,SAAgB,iBAAiB,SAAiD;CAChF,MAAM,EAAE,cAAc;CACtB,MAAM,QAAQ,gBAAgB;EAC5B,WAAW;EACX,MAAM,QAAQ;EACd,UAAU,QAAQ;EAClB,UAAU,QAAQ;EAClB;CACF,CAAC;CACD,MAAM,eAAe,MAAM;CAC3B,MAAM,cAAc,OAAmC,IAAI;CAE3D,MAAM,eAAe,gBACnB,WACI,OACA,GAAG,YAAY,aACX,GAAG,UAAU,qDACT,GAAG,QAAQ,YAAY,EAAE,uGAE7B,KACV;CACA,MAAM,aAAa,aAChB,OAA4B;EAC3B,YAAY,UAAU;EACtB,eAAe,EAAE;EACjB,aAAa;GACX,YAAY,UAAU;EACxB;CACF,GACA,CAAC,YAAY,CACf;CACA,MAAM,UAAU,cAAmC,YAAY,MAAM,GAAG;CAExE,OAAO;EACL;EACA,MAAM,MAAM,QAAQ;EACpB,UAAU,MAAM;EAChB,UAAU,MAAM;EAChB;EACA;CACF;AACF"}
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { useEffectEvent, useLayoutEffect, useRef } from "react";
3
- //#region src/internal/use-form-owner-event.ts
3
+ //#region src/internal/form/use-form-owner-event.ts
4
4
  /**
5
5
  * Stable subscription to `type` on the form owner of `ref.current` (conventions 3.8 rule 4,
6
6
  * generalised for Field, design/components/field-form.md 14).
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-form-owner-event.mjs","names":[],"sources":["../../../src/internal/form/use-form-owner-event.ts"],"sourcesContent":["\"use client\";\nimport { useEffectEvent, useLayoutEffect, useRef } from \"react\";\nimport type { RefObject } from \"react\";\n\n/** A form-associated element whose form owner the hook follows. */\nexport type FormAssociatedElement =\n | HTMLInputElement\n | HTMLFieldSetElement\n | HTMLSelectElement\n | HTMLTextAreaElement;\n\ninterface Subscription {\n readonly form: HTMLFormElement;\n readonly listener: (event: Event) => void;\n}\n\n/**\n * Stable subscription to `type` on the form owner of `ref.current` (conventions 3.8 rule 4,\n * generalised for Field, design/components/field-form.md 14).\n *\n * - The owner (`element.form`, which honours the `form` attribute) is re-read after every commit,\n * but the listener is moved only when the owner changed. It is never removed and re-added on an\n * ordinary re-render: React's automatic reset after a successful `<form action>` runs in the\n * commit's mutation phase, between an effect's cleanup and its next run, so a subscription that\n * followed every commit would miss it.\n * - `handler` always sees the latest committed render's values (`useEffectEvent`).\n * - `ref.current` may be any element: one without a `form` property has no owner.\n */\nexport function useFormOwnerEvent(\n ref: RefObject<Element | null>,\n type: string,\n handler: (event: Event, form: HTMLFormElement) => void,\n): void {\n const handle = useEffectEvent((event: Event, form: HTMLFormElement) => {\n handler(event, form);\n });\n const subscription = useRef<Subscription | null>(null);\n\n // No deps on purpose: follows the form owner after every commit (a changed `form` attribute, the\n // element moved to another form), but re-subscribes only when the owner actually changed.\n useLayoutEffect(() => {\n const element = ref.current as Partial<FormAssociatedElement> | null;\n const form = element?.form ?? null;\n const current = subscription.current;\n if (current !== null && current.form === form) return;\n if (current !== null) current.form.removeEventListener(type, current.listener);\n subscription.current = null;\n if (form === null) return;\n const listener = (event: Event) => handle(event, form);\n form.addEventListener(type, listener);\n subscription.current = { form, listener };\n });\n\n // The only place the subscription is torn down: unmount (and StrictMode's simulated unmount,\n // after which the effect above subscribes again).\n useLayoutEffect(\n () => () => {\n const current = subscription.current;\n if (current !== null) current.form.removeEventListener(type, current.listener);\n subscription.current = null;\n },\n [type],\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AA4BA,SAAgB,kBACd,KACA,MACA,SACM;CACN,MAAM,SAAS,gBAAgB,OAAc,SAA0B;EACrE,QAAQ,OAAO,IAAI;CACrB,CAAC;CACD,MAAM,eAAe,OAA4B,IAAI;CAIrD,sBAAsB;EAEpB,MAAM,OADU,IAAI,SACE,QAAQ;EAC9B,MAAM,UAAU,aAAa;EAC7B,IAAI,YAAY,QAAQ,QAAQ,SAAS,MAAM;EAC/C,IAAI,YAAY,MAAM,QAAQ,KAAK,oBAAoB,MAAM,QAAQ,QAAQ;EAC7E,aAAa,UAAU;EACvB,IAAI,SAAS,MAAM;EACnB,MAAM,YAAY,UAAiB,OAAO,OAAO,IAAI;EACrD,KAAK,iBAAiB,MAAM,QAAQ;EACpC,aAAa,UAAU;GAAE;GAAM;EAAS;CAC1C,CAAC;CAID,4BACc;EACV,MAAM,UAAU,aAAa;EAC7B,IAAI,YAAY,MAAM,QAAQ,KAAK,oBAAoB,MAAM,QAAQ,QAAQ;EAC7E,aAAa,UAAU;CACzB,GACA,CAAC,IAAI,CACP;AACF"}
@@ -1,7 +1,8 @@
1
1
  "use client";
2
- import { useLatest } from "./use-latest.mjs";
2
+ import { useLatest } from "../use-latest.mjs";
3
3
  import { useFormOwnerEvent } from "./use-form-owner-event.mjs";
4
- //#region src/internal/use-form-reset.ts
4
+ import { useState } from "react";
5
+ //#region src/internal/form/use-form-reset.ts
5
6
  /**
6
7
  * Stable `reset` subscription on the form owner of `ref.current` (conventions 3.8).
7
8
  *
@@ -21,7 +22,18 @@ function useFormReset(ref, onReset, onResetEvent) {
21
22
  });
22
23
  });
23
24
  }
25
+ /**
26
+ * The form-reset target of a value prop by mode (conventions 3.8 rule 6): controlled
27
+ * (`value !== undefined`), the value it had at mount; uncontrolled, the latest `defaultValue`.
28
+ * `undefined` when that is absent: an uncontrolled Root with no `defaultValue`, or a Root that
29
+ * became controlled after it mounted uncontrolled. The caller supplies its own fallback
30
+ * (`?? null`, `?? value`, a platform default).
31
+ */
32
+ function useResetTarget(value, defaultValue) {
33
+ const [mountValue] = useState(value);
34
+ return value !== void 0 ? mountValue : defaultValue;
35
+ }
24
36
  //#endregion
25
- export { useFormReset };
37
+ export { useFormReset, useResetTarget };
26
38
 
27
39
  //# sourceMappingURL=use-form-reset.mjs.map