@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,7 +1,7 @@
1
1
  "use client";
2
2
  import { dataAttr } from "../internal/data-attr.mjs";
3
- import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
4
3
  import { useDevWarning } from "../internal/use-dev-warning.mjs";
4
+ import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
5
5
  import { useRender } from "../internal/use-render.mjs";
6
6
  import { useElementCheck } from "../internal/use-element-check.mjs";
7
7
  import { AccordionItemContext, AccordionRootContext } from "./accordion-context.mjs";
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { dataAttr } from "../internal/data-attr.mjs";
3
- import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
4
3
  import { useDevWarning } from "../internal/use-dev-warning.mjs";
4
+ import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
5
5
  import { useRender } from "../internal/use-render.mjs";
6
6
  import { AccordionItemContext } from "./accordion-context.mjs";
7
7
  import { use } from "react";
@@ -1 +1 @@
1
- {"version":3,"file":"accordion-root.d.mts","names":[],"sources":["../../src/accordion/accordion-root.tsx"],"mappings":";;;;;;;iBAsCiB;;WAEN;;WAEA;;;iBAIM,oCAAoC;;;;;;;WAO1C,QAAQ;;WAER;;WAEA;;UAGD,+BAA+B,KACvC;;;;;;EASA;;;;;;;;EAQA;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;iBASnC,mCAAmC;;;;;;EAMlD;;EAEA;;EAEA;;;;;;;;;;;;EAYA,oBAAoB,uBAAuB;;;;;;;;iBAS5B,oCAAoC;;;;;EAKnD;;EAEA;;EAEA;;EAEA,oBAAoB,4BAA4B;;;;;;;;;;;;YAatC,qBAAqB,6BAA6B;;;;;;;wBAqE9C,cAAc,OAAO,qCAAkB,IAAA;yBAAvC"}
1
+ {"version":3,"file":"accordion-root.d.mts","names":[],"sources":["../../src/accordion/accordion-root.tsx"],"mappings":";;;;;;;iBAmCiB;;WAEN;;WAEA;;;iBAIM,oCAAoC;;;;;;;WAO1C,QAAQ;;WAER;;WAEA;;UAGD,+BAA+B,KACvC;;;;;;EASA;;;;;;;;EAQA;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;iBASnC,mCAAmC;;;;;;EAMlD;;EAEA;;EAEA;;;;;;;;;;;;EAYA,oBAAoB,uBAAuB;;;;;;;;iBAS5B,oCAAoC;;;;;EAKnD;;EAEA;;EAEA;;EAEA,oBAAoB,4BAA4B;;;;;;;;;;;;YAatC,qBAAqB,6BAA6B;;;;;;;wBAmE9C,cAAc,OAAO,qCAAkB,IAAA;yBAAvC"}
@@ -1,32 +1,32 @@
1
1
  "use client";
2
- import { createActionDetails } from "../internal/action-details.mjs";
2
+ import { createActionDetails } from "../internal/action/action-details.mjs";
3
3
  import { dataAttr } from "../internal/data-attr.mjs";
4
- import { useDevWarning } from "../internal/use-dev-warning.mjs";
5
4
  import { resolveStateValue } from "../internal/render-element.mjs";
6
5
  import { useRender } from "../internal/use-render.mjs";
7
6
  import { transitionTypes } from "../internal/transition-types.mjs";
8
7
  import { useLatest } from "../internal/use-latest.mjs";
9
- import { useControllableAction } from "../internal/use-controllable-action.mjs";
10
- import { compareDocumentOrder } from "../internal/dom-order.mjs";
11
- import { EMPTY_SET, setsEqual } from "../internal/value-set.mjs";
8
+ import { intendedValue, useControllableAction } from "../internal/action/use-controllable-action.mjs";
9
+ import { compareDocumentOrder, sortByDocumentOrder } from "../internal/dom-order.mjs";
10
+ import { useMountFixed } from "../internal/use-mount-fixed.mjs";
11
+ import { EMPTY_SET, setsEqual, sortByOrder } from "../internal/value-set.mjs";
12
+ import { resolveArrowKey } from "../internal/arrow-keys.mjs";
12
13
  import { useValueSet } from "../internal/use-value-set.mjs";
13
14
  import { AccordionRootContext } from "./accordion-context.mjs";
14
- import { useCallback, useEffectEvent, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
15
+ import { useCallback, useEffectEvent, useId, useLayoutEffect, useMemo, useRef } from "react";
15
16
  import { jsx } from "react/jsx-runtime";
16
17
  //#region src/accordion/accordion-root.tsx
17
18
  const isDev = process.env.NODE_ENV !== "production";
18
19
  /**
19
- * Converts the open set back to the public value. Multiple mode lists the items in registration
20
- * order (the order the Items mounted, which is document order for a list rendered top to bottom),
21
- * not in the order they were opened; unregistered values keep their insertion order at the end.
20
+ * Converts the open set back to the public value. Multiple mode lists the items in `order` (the
21
+ * registered Items' values in document order, design 2.3), not in the order they were opened;
22
+ * unregistered values keep their insertion order at the end.
22
23
  */
23
24
  function fromSet(set, exclusive, order) {
24
25
  if (exclusive) {
25
26
  const [first] = set;
26
27
  return first ?? null;
27
28
  }
28
- const index = new Map(order.map((v, i) => [v, i]));
29
- return [...set].sort((a, b) => (index.get(a) ?? Infinity) - (index.get(b) ?? Infinity));
29
+ return sortByOrder(set, order);
30
30
  }
31
31
  /** The optimistic reducer of design 4.1: add/remove one item, or replace when exclusive. */
32
32
  function reduce(set, item, open, exclusive) {
@@ -39,12 +39,6 @@ function reduce(set, item, open, exclusive) {
39
39
  if (exclusive) return /* @__PURE__ */ new Set([item]);
40
40
  return set.has(item) ? set : new Set(set).add(item);
41
41
  }
42
- const NAV_KEYS = /* @__PURE__ */ new Set([
43
- "ArrowDown",
44
- "ArrowUp",
45
- "Home",
46
- "End"
47
- ]);
48
42
  /** Writes `open` to the DOM; it fires `toggle`, whose handler sees DOM === committed and returns. */
49
43
  function applyOpen(element, open) {
50
44
  if (element.open !== open) element.open = open;
@@ -53,17 +47,18 @@ function isEnabledTrigger(el) {
53
47
  return el.getAttribute("aria-disabled") !== "true";
54
48
  }
55
49
  /**
56
- * Picks the trigger to focus for an arrow/Home/End key: `sorted` is every registered trigger in
57
- * document order; disabled ones are skipped; arrows wrap. Works when `current` is itself disabled
58
- * (disabled triggers stay focusable).
50
+ * Picks the trigger to focus for a move (ArrowDown / ArrowUp / Home / End, `resolveArrowKey` on
51
+ * the vertical axis): `sorted` is every registered trigger in document order; disabled ones are
52
+ * skipped; arrows wrap. Works when `current` is itself disabled (disabled triggers stay
53
+ * focusable), which is why this is not the roving engine's index arithmetic.
59
54
  */
60
- function nextTrigger(sorted, current, key) {
55
+ function nextTrigger(sorted, current, move) {
61
56
  const enabled = sorted.filter(isEnabledTrigger);
62
57
  if (enabled.length === 0) return void 0;
63
- if (key === "Home") return enabled[0];
64
- if (key === "End") return enabled[enabled.length - 1];
58
+ if (move === "first") return enabled[0];
59
+ if (move === "last") return enabled[enabled.length - 1];
65
60
  const position = sorted.indexOf(current);
66
- if (key === "ArrowDown") return enabled.find((el) => sorted.indexOf(el) > position) ?? enabled[0];
61
+ if (move === "next") return enabled.find((el) => sorted.indexOf(el) > position) ?? enabled[0];
67
62
  return enabled.findLast((el) => sorted.indexOf(el) < position) ?? enabled[enabled.length - 1];
68
63
  }
69
64
  /**
@@ -74,17 +69,16 @@ function nextTrigger(sorted, current, key) {
74
69
  */
75
70
  function AccordionRoot(props) {
76
71
  const { exclusive: exclusiveProp = false, value, defaultValue, valueChangeAction, disabled = false, experimental_interpolateSize = false, className, style, children, render, ...rest } = props;
77
- const isLibraryNow = value !== void 0 || defaultValue !== void 0 || valueChangeAction !== void 0;
78
- const [mode] = useState(isLibraryNow ? "library" : "static");
79
- useDevWarning(mode === "library" !== isLibraryNow, isDev && "Accordion.Root: the mode changed after mount (`value`, `defaultValue` and `valueChangeAction` were all absent on one render and present on another). Switching between JS-free and library mode is not supported.");
80
- const [exclusive] = useState(exclusiveProp);
81
- useDevWarning(exclusive !== exclusiveProp, isDev && "Accordion.Root: `exclusive` changed after mount. Switching between exclusive and multiple mode is not supported; the accordion keeps the mode it mounted with.");
72
+ const mode = useMountFixed(value !== void 0 || defaultValue !== void 0 || valueChangeAction !== void 0 ? "library" : "static", isDev && "Accordion.Root: the mode changed after mount (`value`, `defaultValue` and `valueChangeAction` were all absent on one render and present on another). Switching between JS-free and library mode is not supported.");
73
+ const exclusive = useMountFixed(exclusiveProp, isDev && "Accordion.Root: `exclusive` changed after mount. Switching between exclusive and multiple mode is not supported; the accordion keeps the mode it mounted with.");
82
74
  const action = valueChangeAction;
83
75
  const controlledSet = useValueSet(value);
84
76
  const defaultSet = useValueSet(defaultValue);
85
77
  const items = useRef(/* @__PURE__ */ new Map());
86
78
  const triggers = useRef(/* @__PURE__ */ new Set());
87
- const registeredValues = () => [...items.current.values()];
79
+ /** The registered Items in document order. Reads the DOM: handlers and effects only. */
80
+ const sortedItems = () => sortByDocumentOrder([...items.current], ([element]) => element);
81
+ const registeredValues = () => sortedItems().map(([, v]) => v);
88
82
  const { committed, optimistic, pending, dispatch, latestInFlight } = useControllableAction({
89
83
  controlled: controlledSet,
90
84
  defaultValue: defaultSet,
@@ -126,7 +120,7 @@ function AccordionRoot(props) {
126
120
  }, [dispatchChange, latest]);
127
121
  const dispatchFromDom = useCallback((item, open, event) => {
128
122
  const { optimistic, exclusive } = latest.current;
129
- const base = latestInFlight()?.next ?? optimistic;
123
+ const base = intendedValue(latestInFlight, optimistic);
130
124
  const next = reduce(base, item, open, exclusive);
131
125
  if (setsEqual(next, base)) return;
132
126
  dispatchChange(next, item, open, "platform", event);
@@ -137,9 +131,9 @@ function AccordionRoot(props) {
137
131
  ]);
138
132
  const isLibrary = mode === "library";
139
133
  const reconcileOnMount = useEffectEvent(() => {
140
- const base = latestInFlight()?.next ?? optimistic;
134
+ const base = intendedValue(latestInFlight, optimistic);
141
135
  const mismatches = [];
142
- for (const [element, item] of items.current) {
136
+ for (const [element, item] of sortedItems()) {
143
137
  const want = committed.has(item);
144
138
  if (element.open === want) continue;
145
139
  if (element.hasAttribute("data-disabled")) applyOpen(element, want);
@@ -168,10 +162,11 @@ function AccordionRoot(props) {
168
162
  latestInFlight
169
163
  ]);
170
164
  function onKeyDown(event) {
171
- if (!NAV_KEYS.has(event.key)) return;
165
+ const move = resolveArrowKey(event.key, "vertical", false);
166
+ if (move === null) return;
172
167
  const target = event.target;
173
168
  if (!(target instanceof HTMLElement) || !triggers.current.has(target)) return;
174
- const next = nextTrigger([...triggers.current].sort(compareDocumentOrder), target, event.key);
169
+ const next = nextTrigger([...triggers.current].sort(compareDocumentOrder), target, move);
175
170
  if (next === void 0) return;
176
171
  event.preventDefault();
177
172
  event.stopPropagation();
@@ -1 +1 @@
1
- {"version":3,"file":"accordion-root.mjs","names":[],"sources":["../../src/accordion/accordion-root.tsx"],"sourcesContent":["\"use client\";\nimport {\n useCallback,\n useEffectEvent,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, KeyboardEvent, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { compareDocumentOrder } from \"../internal/dom-order.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n RenderProp,\n StateValue,\n} from \"../internal/types.js\";\nimport { useControllableAction } from \"../internal/use-controllable-action.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport { useValueSet } from \"../internal/use-value-set.js\";\nimport { EMPTY_SET, setsEqual } from \"../internal/value-set.js\";\nimport type { ValueSet } from \"../internal/value-set.js\";\nimport { AccordionRootContext } from \"./accordion-context.js\";\nimport type { AccordionMode, AccordionRootContextValue } from \"./accordion-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `Accordion.Root`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface AccordionRootState {\n /** An action dispatched through this Accordion is in flight (library mode only). */\n readonly pending: boolean;\n /** The Root's `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/** Details passed as the second argument of `valueChangeAction`. */\nexport interface AccordionValueChangeDetails extends ActionDetails {\n /**\n * The shared vocabulary (conventions 2.2); Accordion dispatches two of its values.\n * `\"activate\"`: the user activated a Trigger. `\"platform\"`: the browser changed `open` itself\n * (find-in-page, a text fragment, a click before hydration); `event` is then the `toggle`\n * event, or `undefined` when the mismatch was found on mount.\n */\n readonly reason: ChangeReason;\n /** The item whose open state changed. */\n readonly item: string;\n /** That item's new open state. */\n readonly open: boolean;\n}\n\ninterface AccordionRootBaseProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n // `defaultValue` is also a native HTMLAttributes member; the Accordion's own definition wins.\n \"onKeyDown\" | \"defaultValue\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Disables every item: triggers render `aria-disabled` and never dispatch.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Renders `interpolate-size: allow-keywords` on the root so `::details-content` can transition\n * `height` to `auto`. Chromium-only polish today; use the `grid-template-rows` form for a\n * cross-engine animation. Merged with `style`; the consumer's declaration wins.\n *\n * @defaultValue `false`\n */\n experimental_interpolateSize?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, AccordionRootState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, AccordionRootState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, AccordionRootState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, AccordionRootState>;\n}\n\n/**\n * Props of `Accordion.Root` in multiple mode (the default): any number of items open, `value` is\n * a `string[]`.\n *\n * @see https://ui.funstack.work/components/accordion\n */\nexport interface AccordionRootMultipleProps extends AccordionRootBaseProps {\n /**\n * Any number of items may be open.\n *\n * @defaultValue `false`\n */\n exclusive?: false;\n /** Controlled open items. `undefined` means uncontrolled; `[]` means none open. */\n value?: string[];\n /** Initial open items in uncontrolled library mode. */\n defaultValue?: string[];\n /**\n * Called with the next open items on every change. Runs inside the Root's transition; may be\n * sync or async (also a Server Function). Rejections reach the nearest Error Boundary.\n *\n * May also be called with `details.reason === \"platform\"` when the browser opened an item\n * itself (find-in-page, a click before hydration); committed state is re-applied to the DOM\n * once the action settles.\n *\n * A `setState` placed after your own `await` is not a Transition update; wrap it in\n * `startTransition` (React limitation).\n */\n valueChangeAction?: ChangeAction<string[], AccordionValueChangeDetails>;\n}\n\n/**\n * Props of `Accordion.Root` in exclusive mode (`exclusive`): at most one item open, `value` is\n * `string | null`.\n *\n * @see https://ui.funstack.work/components/accordion\n */\nexport interface AccordionRootExclusiveProps extends AccordionRootBaseProps {\n /**\n * At most one item open. JS-free mode: renders the same `name` on every `<details>` (the\n * platform's exclusive group). Library mode: the value is a single item or `null`.\n */\n exclusive: true;\n /** Controlled open item. `undefined` means uncontrolled; `null` means none open. */\n value?: string | null;\n /** Initial open item in uncontrolled library mode. */\n defaultValue?: string | null;\n /** See {@link AccordionRootMultipleProps.valueChangeAction}. */\n valueChangeAction?: ChangeAction<string | null, AccordionValueChangeDetails>;\n}\n\n/**\n * Props of `Accordion.Root`, discriminated on `exclusive`.\n *\n * Without `value`, `defaultValue` and `valueChangeAction` the Accordion runs in **JS-free mode**:\n * the browser owns each `<details open>`, nothing runs on toggle, and `exclusive` renders `name`.\n * With any of them it runs in **library mode**: the summary click is intercepted, `open` is driven\n * by committed state inside a transition, and triggers show optimistic `data-open`.\n *\n * @see https://ui.funstack.work/components/accordion\n */\nexport type AccordionRootProps = AccordionRootMultipleProps | AccordionRootExclusiveProps;\n\ntype AccordionValue = string[] | string | null;\ntype OpenSet = ValueSet;\n\n/**\n * Converts the open set back to the public value. Multiple mode lists the items in registration\n * order (the order the Items mounted, which is document order for a list rendered top to bottom),\n * not in the order they were opened; unregistered values keep their insertion order at the end.\n */\nfunction fromSet(set: OpenSet, exclusive: boolean, order: readonly string[]): AccordionValue {\n if (exclusive) {\n const [first] = set;\n return first ?? null;\n }\n const index = new Map(order.map((v, i) => [v, i] as const));\n return [...set].sort((a, b) => (index.get(a) ?? Infinity) - (index.get(b) ?? Infinity));\n}\n\n/** The optimistic reducer of design 4.1: add/remove one item, or replace when exclusive. */\nfunction reduce(set: OpenSet, item: string, open: boolean, exclusive: boolean): OpenSet {\n if (!open) {\n if (!set.has(item)) return set;\n const next = new Set(set);\n next.delete(item);\n return next;\n }\n if (exclusive) return new Set([item]);\n return set.has(item) ? set : new Set(set).add(item);\n}\n\nconst NAV_KEYS = new Set([\"ArrowDown\", \"ArrowUp\", \"Home\", \"End\"]);\n\n/** Writes `open` to the DOM; it fires `toggle`, whose handler sees DOM === committed and returns. */\nfunction applyOpen(element: HTMLDetailsElement, open: boolean): void {\n if (element.open !== open) element.open = open;\n}\n\nfunction isEnabledTrigger(el: HTMLElement): boolean {\n return el.getAttribute(\"aria-disabled\") !== \"true\";\n}\n\n/**\n * Picks the trigger to focus for an arrow/Home/End key: `sorted` is every registered trigger in\n * document order; disabled ones are skipped; arrows wrap. Works when `current` is itself disabled\n * (disabled triggers stay focusable).\n */\nfunction nextTrigger(\n sorted: readonly HTMLElement[],\n current: HTMLElement,\n key: string,\n): HTMLElement | undefined {\n const enabled = sorted.filter(isEnabledTrigger);\n if (enabled.length === 0) return undefined;\n if (key === \"Home\") return enabled[0];\n if (key === \"End\") return enabled[enabled.length - 1];\n const position = sorted.indexOf(current);\n if (key === \"ArrowDown\") {\n return enabled.find((el) => sorted.indexOf(el) > position) ?? enabled[0];\n }\n return enabled.findLast((el) => sorted.indexOf(el) < position) ?? enabled[enabled.length - 1];\n}\n\n/**\n * The accordion container: a `div` that owns the open state, the transition, the context the\n * other parts read, and ArrowUp/ArrowDown/Home/End navigation between triggers.\n *\n * @see https://ui.funstack.work/components/accordion\n */\nexport function AccordionRoot(props: AccordionRootProps) {\n const {\n exclusive: exclusiveProp = false,\n value,\n defaultValue,\n valueChangeAction,\n disabled = false,\n experimental_interpolateSize = false,\n className,\n style,\n children,\n render,\n ...rest\n } = props;\n\n // Mode is decided once, from the first render's props (design 12).\n const isLibraryNow =\n value !== undefined || defaultValue !== undefined || valueChangeAction !== undefined;\n const [mode] = useState<AccordionMode>(isLibraryNow ? \"library\" : \"static\");\n useDevWarning(\n (mode === \"library\") !== isLibraryNow,\n isDev &&\n \"Accordion.Root: the mode changed after mount (`value`, `defaultValue` and `valueChangeAction` \" +\n \"were all absent on one render and present on another). Switching between JS-free and \" +\n \"library mode is not supported.\",\n );\n\n // Exclusive or multiple is decided once too, like ToggleGroup's mode (design 12): the reducer,\n // the value shape handed to the action and the static `name` all follow the mounted mode.\n const [exclusive] = useState(exclusiveProp);\n useDevWarning(\n exclusive !== exclusiveProp,\n isDev &&\n \"Accordion.Root: `exclusive` changed after mount. Switching between exclusive and \" +\n \"multiple mode is not supported; the accordion keeps the mode it mounted with.\",\n );\n\n // Both prop variants are narrowed by `exclusive` at the call site; internally one signature.\n const action = valueChangeAction as\n | ChangeAction<AccordionValue, AccordionValueChangeDetails>\n | undefined;\n\n const controlledSet = useValueSet(value);\n const defaultSet = useValueSet(defaultValue);\n\n const items = useRef(new Map<HTMLDetailsElement, string>());\n const triggers = useRef(new Set<HTMLElement>());\n const registeredValues = () => [...items.current.values()];\n\n const { committed, optimistic, pending, dispatch, latestInFlight } = useControllableAction<\n OpenSet,\n AccordionValueChangeDetails\n >({\n controlled: controlledSet,\n defaultValue: defaultSet,\n initialValue: EMPTY_SET,\n action:\n action && ((next, details) => action(fromSet(next, exclusive, registeredValues()), details)),\n transitionTypes: (_next, _prev, details) =>\n transitionTypes(\"accordion\", details.open ? \"expand\" : \"collapse\"),\n // Multiple: one item per dispatch, re-based on the committed set; it is also how the\n // uncontrolled commit is folded over the resolved dispatches (#150). Exclusive is\n // single-valued: no reducer, so the optimistic value is `next` and the latest dispatch\n // commits it, like Tabs.\n //\n // The mount reconciliation folds every pre-hydration click into one `next` and is dispatched\n // with `whole` (adopted whole, bypassing the reducer). It never sits in a burst behind a\n // click whose action later rejects: it runs only from the Root's mount layout effect, the\n // Root's first possible dispatch (children do not dispatch from layout effects, and no user\n // event can run between a commit and its layout effects). It runs again only when an\n // `<Activity>` re-shows the Root; a pending click's item then has DOM `open` equal to the\n // optimistic value, so `next` equals the intended value and nothing is dispatched.\n reducer: exclusive\n ? undefined\n : (prev, _next, details) => reduce(prev, details.item, details.open, false),\n warn: { component: \"Accordion.Root\", prop: \"value\" },\n });\n\n const registerItem = useCallback((itemValue: string, element: HTMLDetailsElement) => {\n items.current.set(element, itemValue);\n return () => {\n items.current.delete(element);\n };\n }, []);\n\n const registerTrigger = useCallback((element: HTMLElement) => {\n triggers.current.add(element);\n return () => {\n triggers.current.delete(element);\n };\n }, []);\n\n const dispatchChange = useCallback(\n (\n next: OpenSet,\n item: string,\n open: boolean,\n reason: ChangeReason,\n event: Event | undefined,\n whole = false,\n ): void => {\n dispatch(next, createActionDetails(event, { reason, item, open }), { whole });\n },\n [dispatch],\n );\n\n // The two dispatchers below read the last committed optimistic set through `latest`, so they\n // keep one identity and the Items' contexts are reused across open-state changes: a\n // handler only ever runs against the committed UI, so this is the set it closed over before.\n const latest = useLatest({ optimistic, exclusive });\n\n const dispatchFromTrigger = useCallback<AccordionRootContextValue[\"dispatch\"]>(\n (item, open, event) => {\n const { optimistic, exclusive } = latest.current;\n // `next` comes from the optimistic set: what the user sees and intends (design 2.2).\n dispatchChange(reduce(optimistic, item, open, exclusive), item, open, \"activate\", event);\n },\n [dispatchChange, latest],\n );\n\n const dispatchFromDom = useCallback<AccordionRootContextValue[\"dispatchFromDom\"]>(\n (item, open, event) => {\n const { optimistic, exclusive } = latest.current;\n // The browser flipped one item (design 2.3). `next` builds on what the user already\n // intends (the latest in-flight dispatch, else the optimistic set), never on the DOM: a\n // pending optimistic open would otherwise be lost to latest-wins. Exclusive mode therefore\n // lets the toggled item win when it opened (design walkthrough 9.6).\n const base = latestInFlight()?.next ?? optimistic;\n const next = reduce(base, item, open, exclusive);\n if (setsEqual(next, base)) return;\n dispatchChange(next, item, open, \"platform\", event);\n },\n [dispatchChange, latestInFlight, latest],\n );\n\n const isLibrary = mode === \"library\";\n\n // Mount reconciliation (design 2.3): clicks before hydration left some `<details open>` out of\n // step with committed state. Every mismatch is folded into ONE dispatch with reason \"platform\"\n // and no event; disabled items are simply put back. Runs once per mount; the StrictMode re-run\n // is deduplicated against the dispatch just made.\n const reconcileOnMount = useEffectEvent(() => {\n const base = latestInFlight()?.next ?? optimistic;\n const mismatches: { item: string; open: boolean }[] = [];\n for (const [element, item] of items.current) {\n const want = committed.has(item);\n if (element.open === want) continue;\n if (element.hasAttribute(\"data-disabled\")) applyOpen(element, want);\n else mismatches.push({ item, open: element.open });\n }\n if (mismatches.length === 0) return;\n // Exclusive mode: the first opened item in registration order wins (the others are re-closed\n // by the re-apply effect); otherwise fold every flip onto the base.\n const opened = exclusive ? mismatches.find((m) => m.open) : undefined;\n const chosen = opened ?? mismatches[0]!;\n const next = opened\n ? new Set([opened.item])\n : mismatches.reduce((set, m) => reduce(set, m.item, m.open, exclusive), base);\n if (setsEqual(next, base)) return;\n dispatchChange(next, chosen.item, chosen.open, \"platform\", undefined, true);\n });\n useLayoutEffect(() => {\n if (isLibrary) reconcileOnMount();\n }, [isLibrary]);\n\n // Re-apply committed state to the DOM once nothing is in flight: closes what find-in-page\n // revealed and the parent refused, or what a rejected action left open. Writing `open` fires\n // `toggle`, whose handler sees DOM === committed and does nothing.\n useLayoutEffect(() => {\n if (!isLibrary || pending || latestInFlight() !== null) return;\n for (const [element, item] of items.current) applyOpen(element, committed.has(item));\n }, [isLibrary, pending, committed, latestInFlight]);\n\n function onKeyDown(event: KeyboardEvent<HTMLDivElement>): void {\n if (!NAV_KEYS.has(event.key)) return;\n const target = event.target;\n if (!(target instanceof HTMLElement) || !triggers.current.has(target)) return;\n const sorted = [...triggers.current].sort(compareDocumentOrder);\n const next = nextTrigger(sorted, target, event.key);\n if (next === undefined) return;\n event.preventDefault();\n // A nested Root handles its own triggers; the outer one must not move focus again.\n event.stopPropagation();\n next.focus();\n }\n\n const id = useId();\n const name = !isLibrary && exclusive ? id : undefined;\n const rootPending = isLibrary && pending;\n const state: AccordionRootState = { pending: rootPending, disabled };\n const contextCommitted = isLibrary ? committed : EMPTY_SET;\n const contextOptimistic = isLibrary ? optimistic : EMPTY_SET;\n\n // Memoised (design 12): the dispatchers are stable, so this changes only with the open\n // sets, pending and the props below.\n const context = useMemo<AccordionRootContextValue>(\n () => ({\n mode,\n exclusive,\n name,\n disabled,\n pending: rootPending,\n committed: contextCommitted,\n optimistic: contextOptimistic,\n dispatch: dispatchFromTrigger,\n dispatchFromDom,\n registerItem,\n registerTrigger,\n }),\n [\n mode,\n exclusive,\n name,\n disabled,\n rootPending,\n contextCommitted,\n contextOptimistic,\n dispatchFromTrigger,\n dispatchFromDom,\n registerItem,\n registerTrigger,\n ],\n );\n\n const resolvedStyle = resolveStateValue(style, state);\n const finalStyle: CSSProperties | undefined = experimental_interpolateSize\n ? { interpolateSize: \"allow-keywords\", ...resolvedStyle }\n : resolvedStyle;\n\n const element = useRender<ComponentPropsWithRef<\"div\">, AccordionRootState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n style: finalStyle,\n children,\n props: rest,\n // Library-controlled layer: wins over a `render` element's props (conventions 1.2).\n libraryProps: {\n \"data-pending\": dataAttr(state.pending),\n \"data-disabled\": dataAttr(disabled),\n onKeyDown,\n },\n });\n\n return <AccordionRootContext value={context}>{element}</AccordionR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Ac,aAAa;CACjC,MAAM,QAA4B;EAAE,SAAS;EAAa;CAAS;CACnE,MAAM,mBAAmB,YAAY,YAAY;CACjD,MAAM,oBAAoB,YAAY,aAAa;CAInD,MAAM,UAAU,eACP;EACL;EACA;EACA;EACA;EACA,SAAS;EACT,WAAW;EACX,YAAY;EACZ,UAAU;EACV;EACA;EACA;CACF,IACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CAEA,MAAM,gBAAgB,kBAAkB,OAAO,KAAK;CACpD,MAAM,aAAwC,+BAC1C;EAAE,iBAAiB;EAAkB,GAAG;CAAc,IACtD;CAEJ,MAAM,UAAU,UAA4D;EAC1E,gBAAgB;EAChB;EACA;EACA;EACA,OAAO;EACP;EACA,OAAO;EAEP,cAAc;GACZ,gBAAgB,SAAS,MAAM,OAAO;GACtC,iBAAiB,SAAS,QAAQ;GAClC;EACF;CACF,CAAC;CAED,OAAO,oBAAC,sBAAD;EAAsB,OAAO;EAAU,UAAA;CAA8B,CAAA;AAC9E;AAEA,cAAc,cAAc"}
1
+ {"version":3,"file":"accordion-root.mjs","names":[],"sources":["../../src/accordion/accordion-root.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffectEvent, useId, useLayoutEffect, useMemo, useRef } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, KeyboardEvent, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action/action-details.js\";\nimport { resolveArrowKey } from \"../internal/arrow-keys.js\";\nimport type { ArrowMove } from \"../internal/arrow-keys.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { compareDocumentOrder, sortByDocumentOrder } from \"../internal/dom-order.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n RenderProp,\n StateValue,\n} from \"../internal/types.js\";\nimport {\n intendedValue,\n useControllableAction,\n} from \"../internal/action/use-controllable-action.js\";\nimport { useMountFixed } from \"../internal/use-mount-fixed.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport { useValueSet } from \"../internal/use-value-set.js\";\nimport { EMPTY_SET, setsEqual, sortByOrder } from \"../internal/value-set.js\";\nimport type { ValueSet } from \"../internal/value-set.js\";\nimport { AccordionRootContext } from \"./accordion-context.js\";\nimport type { AccordionMode, AccordionRootContextValue } from \"./accordion-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `Accordion.Root`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface AccordionRootState {\n /** An action dispatched through this Accordion is in flight (library mode only). */\n readonly pending: boolean;\n /** The Root's `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/** Details passed as the second argument of `valueChangeAction`. */\nexport interface AccordionValueChangeDetails extends ActionDetails {\n /**\n * The shared vocabulary (conventions 2.2); Accordion dispatches two of its values.\n * `\"activate\"`: the user activated a Trigger. `\"platform\"`: the browser changed `open` itself\n * (find-in-page, a text fragment, a click before hydration); `event` is then the `toggle`\n * event, or `undefined` when the mismatch was found on mount.\n */\n readonly reason: ChangeReason;\n /** The item whose open state changed. */\n readonly item: string;\n /** That item's new open state. */\n readonly open: boolean;\n}\n\ninterface AccordionRootBaseProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n // `defaultValue` is also a native HTMLAttributes member; the Accordion's own definition wins.\n \"onKeyDown\" | \"defaultValue\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Disables every item: triggers render `aria-disabled` and never dispatch.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Renders `interpolate-size: allow-keywords` on the root so `::details-content` can transition\n * `height` to `auto`. Chromium-only polish today; use the `grid-template-rows` form for a\n * cross-engine animation. Merged with `style`; the consumer's declaration wins.\n *\n * @defaultValue `false`\n */\n experimental_interpolateSize?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, AccordionRootState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, AccordionRootState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, AccordionRootState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, AccordionRootState>;\n}\n\n/**\n * Props of `Accordion.Root` in multiple mode (the default): any number of items open, `value` is\n * a `string[]`.\n *\n * @see https://ui.funstack.work/components/accordion\n */\nexport interface AccordionRootMultipleProps extends AccordionRootBaseProps {\n /**\n * Any number of items may be open.\n *\n * @defaultValue `false`\n */\n exclusive?: false;\n /** Controlled open items. `undefined` means uncontrolled; `[]` means none open. */\n value?: string[];\n /** Initial open items in uncontrolled library mode. */\n defaultValue?: string[];\n /**\n * Called with the next open items on every change. Runs inside the Root's transition; may be\n * sync or async (also a Server Function). Rejections reach the nearest Error Boundary.\n *\n * May also be called with `details.reason === \"platform\"` when the browser opened an item\n * itself (find-in-page, a click before hydration); committed state is re-applied to the DOM\n * once the action settles.\n *\n * A `setState` placed after your own `await` is not a Transition update; wrap it in\n * `startTransition` (React limitation).\n */\n valueChangeAction?: ChangeAction<string[], AccordionValueChangeDetails>;\n}\n\n/**\n * Props of `Accordion.Root` in exclusive mode (`exclusive`): at most one item open, `value` is\n * `string | null`.\n *\n * @see https://ui.funstack.work/components/accordion\n */\nexport interface AccordionRootExclusiveProps extends AccordionRootBaseProps {\n /**\n * At most one item open. JS-free mode: renders the same `name` on every `<details>` (the\n * platform's exclusive group). Library mode: the value is a single item or `null`.\n */\n exclusive: true;\n /** Controlled open item. `undefined` means uncontrolled; `null` means none open. */\n value?: string | null;\n /** Initial open item in uncontrolled library mode. */\n defaultValue?: string | null;\n /** See {@link AccordionRootMultipleProps.valueChangeAction}. */\n valueChangeAction?: ChangeAction<string | null, AccordionValueChangeDetails>;\n}\n\n/**\n * Props of `Accordion.Root`, discriminated on `exclusive`.\n *\n * Without `value`, `defaultValue` and `valueChangeAction` the Accordion runs in **JS-free mode**:\n * the browser owns each `<details open>`, nothing runs on toggle, and `exclusive` renders `name`.\n * With any of them it runs in **library mode**: the summary click is intercepted, `open` is driven\n * by committed state inside a transition, and triggers show optimistic `data-open`.\n *\n * @see https://ui.funstack.work/components/accordion\n */\nexport type AccordionRootProps = AccordionRootMultipleProps | AccordionRootExclusiveProps;\n\ntype AccordionValue = string[] | string | null;\ntype OpenSet = ValueSet;\n\n/**\n * Converts the open set back to the public value. Multiple mode lists the items in `order` (the\n * registered Items' values in document order, design 2.3), not in the order they were opened;\n * unregistered values keep their insertion order at the end.\n */\nfunction fromSet(set: OpenSet, exclusive: boolean, order: readonly string[]): AccordionValue {\n if (exclusive) {\n const [first] = set;\n return first ?? null;\n }\n return sortByOrder(set, order);\n}\n\n/** The optimistic reducer of design 4.1: add/remove one item, or replace when exclusive. */\nfunction reduce(set: OpenSet, item: string, open: boolean, exclusive: boolean): OpenSet {\n if (!open) {\n if (!set.has(item)) return set;\n const next = new Set(set);\n next.delete(item);\n return next;\n }\n if (exclusive) return new Set([item]);\n return set.has(item) ? set : new Set(set).add(item);\n}\n\n/** Writes `open` to the DOM; it fires `toggle`, whose handler sees DOM === committed and returns. */\nfunction applyOpen(element: HTMLDetailsElement, open: boolean): void {\n if (element.open !== open) element.open = open;\n}\n\nfunction isEnabledTrigger(el: HTMLElement): boolean {\n return el.getAttribute(\"aria-disabled\") !== \"true\";\n}\n\n/**\n * Picks the trigger to focus for a move (ArrowDown / ArrowUp / Home / End, `resolveArrowKey` on\n * the vertical axis): `sorted` is every registered trigger in document order; disabled ones are\n * skipped; arrows wrap. Works when `current` is itself disabled (disabled triggers stay\n * focusable), which is why this is not the roving engine's index arithmetic.\n */\nfunction nextTrigger(\n sorted: readonly HTMLElement[],\n current: HTMLElement,\n move: ArrowMove,\n): HTMLElement | undefined {\n const enabled = sorted.filter(isEnabledTrigger);\n if (enabled.length === 0) return undefined;\n if (move === \"first\") return enabled[0];\n if (move === \"last\") return enabled[enabled.length - 1];\n const position = sorted.indexOf(current);\n if (move === \"next\") {\n return enabled.find((el) => sorted.indexOf(el) > position) ?? enabled[0];\n }\n return enabled.findLast((el) => sorted.indexOf(el) < position) ?? enabled[enabled.length - 1];\n}\n\n/**\n * The accordion container: a `div` that owns the open state, the transition, the context the\n * other parts read, and ArrowUp/ArrowDown/Home/End navigation between triggers.\n *\n * @see https://ui.funstack.work/components/accordion\n */\nexport function AccordionRoot(props: AccordionRootProps) {\n const {\n exclusive: exclusiveProp = false,\n value,\n defaultValue,\n valueChangeAction,\n disabled = false,\n experimental_interpolateSize = false,\n className,\n style,\n children,\n render,\n ...rest\n } = props;\n\n // Mode is decided once, from the first render's props (design 12).\n const isLibraryNow =\n value !== undefined || defaultValue !== undefined || valueChangeAction !== undefined;\n const mode = useMountFixed<AccordionMode>(\n isLibraryNow ? \"library\" : \"static\",\n isDev &&\n \"Accordion.Root: the mode changed after mount (`value`, `defaultValue` and `valueChangeAction` \" +\n \"were all absent on one render and present on another). Switching between JS-free and \" +\n \"library mode is not supported.\",\n );\n\n // Exclusive or multiple is decided once too, like ToggleGroup's mode (design 12): the reducer,\n // the value shape handed to the action and the static `name` all follow the mounted mode.\n const exclusive = useMountFixed(\n exclusiveProp,\n isDev &&\n \"Accordion.Root: `exclusive` changed after mount. Switching between exclusive and \" +\n \"multiple mode is not supported; the accordion keeps the mode it mounted with.\",\n );\n\n // Both prop variants are narrowed by `exclusive` at the call site; internally one signature.\n const action = valueChangeAction as\n | ChangeAction<AccordionValue, AccordionValueChangeDetails>\n | undefined;\n\n const controlledSet = useValueSet(value);\n const defaultSet = useValueSet(defaultValue);\n\n const items = useRef(new Map<HTMLDetailsElement, string>());\n const triggers = useRef(new Set<HTMLElement>());\n /** The registered Items in document order. Reads the DOM: handlers and effects only. */\n const sortedItems = (): [HTMLDetailsElement, string][] =>\n sortByDocumentOrder([...items.current], ([element]) => element);\n const registeredValues = () => sortedItems().map(([, v]) => v);\n\n const { committed, optimistic, pending, dispatch, latestInFlight } = useControllableAction<\n OpenSet,\n AccordionValueChangeDetails\n >({\n controlled: controlledSet,\n defaultValue: defaultSet,\n initialValue: EMPTY_SET,\n action:\n action && ((next, details) => action(fromSet(next, exclusive, registeredValues()), details)),\n transitionTypes: (_next, _prev, details) =>\n transitionTypes(\"accordion\", details.open ? \"expand\" : \"collapse\"),\n // Multiple: one item per dispatch, re-based on the committed set; it is also how the\n // uncontrolled commit is folded over the resolved dispatches (#150). Exclusive is\n // single-valued: no reducer, so the optimistic value is `next` and the latest dispatch\n // commits it, like Tabs.\n //\n // The mount reconciliation folds every pre-hydration click into one `next` and is dispatched\n // with `whole` (adopted whole, bypassing the reducer). It never sits in a burst behind a\n // click whose action later rejects: it runs only from the Root's mount layout effect, the\n // Root's first possible dispatch (children do not dispatch from layout effects, and no user\n // event can run between a commit and its layout effects). It runs again only when an\n // `<Activity>` re-shows the Root; a pending click's item then has DOM `open` equal to the\n // optimistic value, so `next` equals the intended value and nothing is dispatched.\n reducer: exclusive\n ? undefined\n : (prev, _next, details) => reduce(prev, details.item, details.open, false),\n warn: { component: \"Accordion.Root\", prop: \"value\" },\n });\n\n const registerItem = useCallback((itemValue: string, element: HTMLDetailsElement) => {\n items.current.set(element, itemValue);\n return () => {\n items.current.delete(element);\n };\n }, []);\n\n const registerTrigger = useCallback((element: HTMLElement) => {\n triggers.current.add(element);\n return () => {\n triggers.current.delete(element);\n };\n }, []);\n\n const dispatchChange = useCallback(\n (\n next: OpenSet,\n item: string,\n open: boolean,\n reason: ChangeReason,\n event: Event | undefined,\n whole = false,\n ): void => {\n dispatch(next, createActionDetails(event, { reason, item, open }), { whole });\n },\n [dispatch],\n );\n\n // The two dispatchers below read the last committed optimistic set through `latest`, so they\n // keep one identity and the Items' contexts are reused across open-state changes: a\n // handler only ever runs against the committed UI, so this is the set it closed over before.\n const latest = useLatest({ optimistic, exclusive });\n\n const dispatchFromTrigger = useCallback<AccordionRootContextValue[\"dispatch\"]>(\n (item, open, event) => {\n const { optimistic, exclusive } = latest.current;\n // `next` comes from the optimistic set: what the user sees and intends (design 2.2).\n dispatchChange(reduce(optimistic, item, open, exclusive), item, open, \"activate\", event);\n },\n [dispatchChange, latest],\n );\n\n const dispatchFromDom = useCallback<AccordionRootContextValue[\"dispatchFromDom\"]>(\n (item, open, event) => {\n const { optimistic, exclusive } = latest.current;\n // The browser flipped one item (design 2.3). `next` builds on what the user already\n // intends (the latest in-flight dispatch, else the optimistic set), never on the DOM: a\n // pending optimistic open would otherwise be lost to latest-wins. Exclusive mode therefore\n // lets the toggled item win when it opened (design walkthrough 9.6).\n const base = intendedValue(latestInFlight, optimistic);\n const next = reduce(base, item, open, exclusive);\n if (setsEqual(next, base)) return;\n dispatchChange(next, item, open, \"platform\", event);\n },\n [dispatchChange, latestInFlight, latest],\n );\n\n const isLibrary = mode === \"library\";\n\n // Mount reconciliation (design 2.3): clicks before hydration left some `<details open>` out of\n // step with committed state. Every mismatch is folded into ONE dispatch with reason \"platform\"\n // and no event; disabled items are simply put back. Runs once per mount; the StrictMode re-run\n // is deduplicated against the dispatch just made.\n const reconcileOnMount = useEffectEvent(() => {\n const base = intendedValue(latestInFlight, optimistic);\n const mismatches: { item: string; open: boolean }[] = [];\n for (const [element, item] of sortedItems()) {\n const want = committed.has(item);\n if (element.open === want) continue;\n if (element.hasAttribute(\"data-disabled\")) applyOpen(element, want);\n else mismatches.push({ item, open: element.open });\n }\n if (mismatches.length === 0) return;\n // Exclusive mode: the first opened item in document order wins (the others are re-closed\n // by the re-apply effect); otherwise fold every flip onto the base.\n const opened = exclusive ? mismatches.find((m) => m.open) : undefined;\n const chosen = opened ?? mismatches[0]!;\n const next = opened\n ? new Set([opened.item])\n : mismatches.reduce((set, m) => reduce(set, m.item, m.open, exclusive), base);\n if (setsEqual(next, base)) return;\n dispatchChange(next, chosen.item, chosen.open, \"platform\", undefined, true);\n });\n useLayoutEffect(() => {\n if (isLibrary) reconcileOnMount();\n }, [isLibrary]);\n\n // Re-apply committed state to the DOM once nothing is in flight: closes what find-in-page\n // revealed and the parent refused, or what a rejected action left open. Writing `open` fires\n // `toggle`, whose handler sees DOM === committed and does nothing.\n useLayoutEffect(() => {\n if (!isLibrary || pending || latestInFlight() !== null) return;\n for (const [element, item] of items.current) applyOpen(element, committed.has(item));\n }, [isLibrary, pending, committed, latestInFlight]);\n\n function onKeyDown(event: KeyboardEvent<HTMLDivElement>): void {\n // Vertical only, so no RTL mirroring: ArrowLeft / ArrowRight are not navigation keys.\n const move = resolveArrowKey(event.key, \"vertical\", false);\n if (move === null) return;\n const target = event.target;\n if (!(target instanceof HTMLElement) || !triggers.current.has(target)) return;\n const sorted = [...triggers.current].sort(compareDocumentOrder);\n const next = nextTrigger(sorted, target, move);\n if (next === undefined) return;\n event.preventDefault();\n // A nested Root handles its own triggers; the outer one must not move focus again.\n event.stopPropagation();\n next.focus();\n }\n\n const id = useId();\n const name = !isLibrary && exclusive ? id : undefined;\n const rootPending = isLibrary && pending;\n const state: AccordionRootState = { pending: rootPending, disabled };\n const contextCommitted = isLibrary ? committed : EMPTY_SET;\n const contextOptimistic = isLibrary ? optimistic : EMPTY_SET;\n\n // Memoised (design 12): the dispatchers are stable, so this changes only with the open\n // sets, pending and the props below.\n const context = useMemo<AccordionRootContextValue>(\n () => ({\n mode,\n exclusive,\n name,\n disabled,\n pending: rootPending,\n committed: contextCommitted,\n optimistic: contextOptimistic,\n dispatch: dispatchFromTrigger,\n dispatchFromDom,\n registerItem,\n registerTrigger,\n }),\n [\n mode,\n exclusive,\n name,\n disabled,\n rootPending,\n contextCommitted,\n contextOptimistic,\n dispatchFromTrigger,\n dispatchFromDom,\n registerItem,\n registerTrigger,\n ],\n );\n\n const resolvedStyle = resolveStateValue(style, state);\n const finalStyle: CSSProperties | undefined = experimental_interpolateSize\n ? { interpolateSize: \"allow-keywords\", ...resolvedStyle }\n : resolvedStyle;\n\n const element = useRender<ComponentPropsWithRef<\"div\">, AccordionRootState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n style: finalStyle,\n children,\n props: rest,\n // Library-controlled layer: wins over a `render` element's props (conventions 1.2).\n libraryProps: {\n \"data-pending\": dataAttr(state.pending),\n \"data-disabled\": dataAttr(disabled),\n onKeyDown,\n },\n });\n\n return <AccordionRootContext value={context}>{element}</AccordionRootContext>;\n}\n\nAccordionRoot.displayName = \"AccordionRoot\";\n"],"mappings":";;;;;;;;;;;;;;;;;AA6BA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;AAgIvC,SAAS,QAAQ,KAAc,WAAoB,OAA0C;CAC3F,IAAI,WAAW;EACb,MAAM,CAAC,SAAS;EAChB,OAAO,SAAS;CAClB;CACA,OAAO,YAAY,KAAK,KAAK;AAC/B;;AAGA,SAAS,OAAO,KAAc,MAAc,MAAe,WAA6B;CACtF,IAAI,CAAC,MAAM;EACT,IAAI,CAAC,IAAI,IAAI,IAAI,GAAG,OAAO;EAC3B,MAAM,OAAO,IAAI,IAAI,GAAG;EACxB,KAAK,OAAO,IAAI;EAChB,OAAO;CACT;CACA,IAAI,WAAW,uBAAO,IAAI,IAAI,CAAC,IAAI,CAAC;CACpC,OAAO,IAAI,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI;AACpD;;AAGA,SAAS,UAAU,SAA6B,MAAqB;CACnE,IAAI,QAAQ,SAAS,MAAM,QAAQ,OAAO;AAC5C;AAEA,SAAS,iBAAiB,IAA0B;CAClD,OAAO,GAAG,aAAa,eAAe,MAAM;AAC9C;;;;;;;AAQA,SAAS,YACP,QACA,SACA,MACyB;CACzB,MAAM,UAAU,OAAO,OAAO,gBAAgB;CAC9C,IAAI,QAAQ,WAAW,GAAG,OAAO,KAAA;CACjC,IAAI,SAAS,SAAS,OAAO,QAAQ;CACrC,IAAI,SAAS,QAAQ,OAAO,QAAQ,QAAQ,SAAS;CACrD,MAAM,WAAW,OAAO,QAAQ,OAAO;CACvC,IAAI,SAAS,QACX,OAAO,QAAQ,MAAM,OAAO,OAAO,QAAQ,EAAE,IAA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jD,MAAM,oBAAoB,YAAY,aAAa;CAInD,MAAM,UAAU,eACP;EACL;EACA;EACA;EACA;EACA,SAAS;EACT,WAAW;EACX,YAAY;EACZ,UAAU;EACV;EACA;EACA;CACF,IACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CAEA,MAAM,gBAAgB,kBAAkB,OAAO,KAAK;CACpD,MAAM,aAAwC,+BAC1C;EAAE,iBAAiB;EAAkB,GAAG;CAAc,IACtD;CAEJ,MAAM,UAAU,UAA4D;EAC1E,gBAAgB;EAChB;EACA;EACA;EACA,OAAO;EACP;EACA,OAAO;EAEP,cAAc;GACZ,gBAAgB,SAAS,MAAM,OAAO;GACtC,iBAAiB,SAAS,QAAQ;GAClC;EACF;CACF,CAAC;CAED,OAAO,oBAAC,sBAAD;EAAsB,OAAO;EAAU,UAAA;CAA8B,CAAA;AAC9E;AAEA,cAAc,cAAc"}
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { dataAttr } from "../internal/data-attr.mjs";
3
- import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
4
3
  import { useDevWarning } from "../internal/use-dev-warning.mjs";
4
+ import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
5
5
  import { useRender } from "../internal/use-render.mjs";
6
6
  import { useElementCheck } from "../internal/use-element-check.mjs";
7
7
  import { AccordionItemContext } from "./accordion-context.mjs";
@@ -59,19 +59,24 @@ export interface ButtonProps extends Omit<ComponentPropsWithRef<"button">, "onCl
59
59
  type?: "button" | "submit" | "reset";
60
60
  /**
61
61
  * Native `disabled` (owned; a `render` element cannot re-enable it) and `data-disabled`.
62
- * Never dispatches. With `focusableWhenDisabled`, inside a `Toolbar.Root`, or when the
63
- * rendered element is not a host `<button>` (`render={<a href />}`, a component), renders
64
- * `aria-disabled="true"` instead.
62
+ * Never dispatches. With `focusableWhenDisabled` or inside a `Toolbar.Root`, renders
63
+ * `aria-disabled="true"` instead and cancels the click. So does a host element of another tag
64
+ * (`render={<a href />}`), and a component `render` whose click only the Button acts on. A
65
+ * component or `<input>` `render` whose click the browser also acts on (`type="submit"` /
66
+ * `"reset"`, the `formAction` default, `commandfor` / `popoverTarget`; with or without
67
+ * `action`) keeps native `disabled`: only that stops a submission or command before
68
+ * hydration. Native `disabled`
69
+ * wins over the pending `aria-disabled`.
65
70
  *
66
71
  * @defaultValue `false`
67
72
  */
68
73
  disabled?: boolean;
69
74
  /**
70
75
  * Keep a disabled Button focusable: `aria-disabled="true"` instead of native `disabled`, so
71
- * keyboard and screen-reader users still find it and a Tooltip on it still opens.
76
+ * keyboard and screen-reader users still find it and a Tooltip on it still opens. Before
77
+ * hydration a focusable disabled submitter still submits (nothing native stops it).
72
78
  *
73
- * @defaultValue `false`; implied `true` inside a `Toolbar.Root` (APG Toolbar) and for a `render`
74
- * element that is not a host `<button>`
79
+ * @defaultValue `false`; implied `true` inside a `Toolbar.Root` (APG Toolbar)
75
80
  */
76
81
  focusableWhenDisabled?: boolean;
77
82
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"button.d.mts","names":[],"sources":["../../src/button/button.tsx"],"mappings":";;;;iBA4BiB,4BAA4B;;;;iBAK5B;;;;;WAKN;;WAEA;;;;;;;iBAQM,oBAAoB,KACnC;;;;;;;EASA,SAAS,QAAQ,SAAS;;;;;;;;;;EAU1B,aAAa;;;;;;;;;;;EAWb,eAAe;;;;;;;;EAQf;;;;;;;;;EASA;;;;;;;;EAQA;;;;;;;;EAQA,aAAa;;EAEb,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;;wBAiBvC,SACd,QACA,YACA,cACA,MACA,UACA,uBACA,YACA,WACA,OACA,UACA,WACG,QACF,cAAW;yBAbE"}
1
+ {"version":3,"file":"button.d.mts","names":[],"sources":["../../src/button/button.tsx"],"mappings":";;;;iBA4BiB,4BAA4B;;;;iBAK5B;;;;;WAKN;;WAEA;;;;;;;iBAQM,oBAAoB,KACnC;;;;;;;EASA,SAAS,QAAQ,SAAS;;;;;;;;;;EAU1B,aAAa;;;;;;;;;;;EAWb,eAAe;;;;;;;;EAQf;;;;;;;;;;;;;;EAcA;;;;;;;;EAQA;;;;;;;;EAQA,aAAa;;EAEb,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;;wBAiBvC,SACd,QACA,YACA,cACA,MACA,UACA,uBACA,YACA,WACA,OACA,UACA,WACG,QACF,cAAW;yBAbE"}
@@ -1,13 +1,13 @@
1
1
  "use client";
2
- import { createActionDetails } from "../internal/action-details.mjs";
2
+ import { createActionDetails } from "../internal/action/action-details.mjs";
3
3
  import { dataAttr } from "../internal/data-attr.mjs";
4
4
  import { useToolbarContext } from "../internal/toolbar-context.mjs";
5
- import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
6
- import { useActionTrigger } from "../internal/use-action-trigger.mjs";
7
5
  import { useDevWarning } from "../internal/use-dev-warning.mjs";
8
- import { isHostButton, rendersButton } from "../internal/render-element.mjs";
6
+ import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
7
+ import { disabledButton, rendersButton } from "../internal/render-element.mjs";
8
+ import { usePureTrigger } from "../internal/action/use-pure-trigger.mjs";
9
9
  import { useRender } from "../internal/use-render.mjs";
10
- import { useRef, useState } from "react";
10
+ import { isValidElement, useRef, useState } from "react";
11
11
  import { useFormStatus } from "react-dom";
12
12
  //#region src/button/button.tsx
13
13
  const isDev = process.env.NODE_ENV !== "production";
@@ -27,9 +27,21 @@ const isDev = process.env.NODE_ENV !== "production";
27
27
  */
28
28
  function Button({ action, formAction, whilePending, type, disabled = false, focusableWhenDisabled = false, transition, className, style, children, render, ...rest }) {
29
29
  const toolbar = useToolbarContext();
30
- const focusable = focusableWhenDisabled || toolbar !== null || !isHostButton(render);
31
- const ignoring = (whilePending ?? "run") === "ignore";
32
- const { pending: ownPending, run } = useActionTrigger({ ignoreWhilePending: ignoring });
30
+ const resolvedType = type ?? (formAction !== void 0 ? "submit" : "button");
31
+ const browserRun = (isValidElement(render) && render.type === "input" ? [
32
+ "submit",
33
+ "image",
34
+ "reset"
35
+ ].includes(String(render.props.type)) ? "submit" : "button" : resolvedType) !== "button" || rest.commandfor !== void 0 || rest.popoverTarget !== void 0;
36
+ const disabledProps = disabledButton(render, disabled, {
37
+ handlesClick: !browserRun,
38
+ alwaysFocusable: focusableWhenDisabled || toolbar !== null
39
+ }).props;
40
+ const trigger = usePureTrigger({
41
+ whilePending,
42
+ defaultWhilePending: "run"
43
+ });
44
+ const { ignoring } = trigger;
33
45
  const status = useFormStatus();
34
46
  const submittedWith = useRef(void 0);
35
47
  const [submitted, setSubmitted] = useState(false);
@@ -37,7 +49,7 @@ function Button({ action, formAction, whilePending, type, disabled = false, focu
37
49
  if (named && !submitted) setSubmitted(true);
38
50
  if (!status.pending && submitted) setSubmitted(false);
39
51
  const formPending = typeof formAction === "function" && (named || status.pending && submitted);
40
- const pending = ownPending || formPending;
52
+ const pending = trigger.pending || formPending;
41
53
  useDevWarning(action !== void 0 && formAction !== void 0, isDev && "Button: `action` and `formAction` were both given. One click would run two actions; the Button runs `action` and leaves `formAction` to the form submission. Pass one of them.");
42
54
  useDevWarning(action !== void 0 && (type === "submit" || type === "reset"), isDev && `Button: \`action\` together with type="${type}". One click would run \`action\` in a transition and ${type === "reset" ? "reset" : "submit"} the form. Use \`formAction\` for a submitter, or drop \`type\`.`);
43
55
  const element = useRender({
@@ -55,10 +67,9 @@ function Button({ action, formAction, whilePending, type, disabled = false, focu
55
67
  formAction
56
68
  },
57
69
  libraryProps: {
58
- ...rendersButton(render) && { type: type ?? (formAction !== void 0 ? "submit" : "button") },
59
- disabled: disabled && !focusable ? true : void 0,
60
- "aria-disabled": pending && ignoring || disabled && focusable ? true : void 0,
61
- "data-pending": dataAttr(pending),
70
+ ...rendersButton(render) && { type: resolvedType },
71
+ disabled: disabledProps.disabled === true ? true : void 0,
72
+ ...trigger.pendingProps(disabledProps, pending),
62
73
  "data-disabled": dataAttr(disabled),
63
74
  onClick: (event) => {
64
75
  if (disabled) {
@@ -74,7 +85,7 @@ function Button({ action, formAction, whilePending, type, disabled = false, focu
74
85
  return;
75
86
  }
76
87
  const details = createActionDetails(event.nativeEvent, {});
77
- if (!run(() => action(details))) event.preventDefault();
88
+ trigger.runActivation(event, () => action(details));
78
89
  }
79
90
  }
80
91
  });
@@ -1 +1 @@
1
- {"version":3,"file":"button.mjs","names":[],"sources":["../../src/button/button.tsx"],"sourcesContent":["\"use client\";\nimport { useRef, useState } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent,\n ReactNode,\n ViewTransitionClass,\n} from \"react\";\nimport { useFormStatus } from \"react-dom\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { useToolbarContext } from \"../internal/toolbar-context.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type {\n Action,\n ActionDetails,\n RenderProp,\n StateValue,\n WhilePending,\n} from \"../internal/types.js\";\nimport { useActionTrigger } from \"../internal/use-action-trigger.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { isHostButton, rendersButton, useRender } from \"../internal/use-render.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** Details passed to `Button`'s `action`. Serialisable; `event` is virtual (conventions 2.2). */\nexport interface ButtonActionDetails extends ActionDetails {}\n\n/**\n * State of `Button`, passed to the function forms of `className`, `style`, `children` and `render`.\n */\nexport interface ButtonState {\n /**\n * This Button's own `action` is in flight, or it submitted the form through its own function\n * `formAction` and the form's submissions have not all finished yet.\n */\n readonly pending: boolean;\n /** The `disabled` prop. Not set by pending. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Button`.\n *\n * @see https://ui.funstack.work/components/button\n */\nexport interface ButtonProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"aria-disabled\" | \"className\" | \"style\" | \"children\" | \"type\" | \"formAction\"\n> {\n /**\n * Runs inside this Button's own transition on click, Enter or Space (`data-pending`\n * meanwhile). Sync or async; may be a Server Function. A rejection reaches the nearest Error\n * Boundary above the Button. A click while it is pending runs it again unless `whilePending`\n * is `\"ignore\"`. Not combinable with `formAction` (development error).\n */\n action?: Action<[details: ButtonActionDetails]>;\n /**\n * React's `formAction`: a function (a Server Function, a `useActionState` dispatch, a client\n * function) or a URL, run by React instead of the form's `action` when this Button submits the\n * form. With a function, the Button is `pending` from its own submission until the form's\n * submissions have all finished (never for another submitter's alone) and defaults to\n * `type=\"submit\"`. A click meanwhile submits again\n * unless `whilePending` is `\"ignore\"`; React drops the rejection of an older overlapping\n * submission, so use `\"ignore\"` (or `useActionState`) for a submission that must not overlap.\n */\n formAction?: ComponentPropsWithRef<\"button\">[\"formAction\"];\n /**\n * What a click, Enter or Space does while this Button's own `action` (or its own function\n * `formAction` submission) is pending. `\"run\"`: it runs as well; the Button shows\n * `data-pending` until every run has settled. `\"ignore\"`: it starts nothing, its default action\n * is cancelled (no second submission, navigation or command), and the Button renders\n * `aria-disabled=\"true\"` while pending. Use `\"ignore\"` for an action that must not run twice\n * (Save, Pay, Delete). No effect on a Button with neither `action` nor a function `formAction`.\n *\n * @defaultValue `\"run\"`\n */\n whilePending?: WhilePending;\n /**\n * Owned on a `<button>` and on a component `render` element (set it here, not on the element; a\n * component should spread it); omitted for a host element of another tag (`<a>`). `action`\n * together with `\"submit\"` / `\"reset\"` warns in development: one click would do two things.\n *\n * @defaultValue `\"button\"`, or `\"submit\"` when `formAction` is given\n */\n type?: \"button\" | \"submit\" | \"reset\";\n /**\n * Native `disabled` (owned; a `render` element cannot re-enable it) and `data-disabled`.\n * Never dispatches. With `focusableWhenDisabled`, inside a `Toolbar.Root`, or when the\n * rendered element is not a host `<button>` (`render={<a href />}`, a component), renders\n * `aria-disabled=\"true\"` instead.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Keep a disabled Button focusable: `aria-disabled=\"true\"` instead of native `disabled`, so\n * keyboard and screen-reader users still find it and a Tooltip on it still opens.\n *\n * @defaultValue `false`; implied `true` inside a `Toolbar.Root` (APG Toolbar) and for a `render`\n * element that is not a host `<button>`\n */\n focusableWhenDisabled?: boolean;\n /**\n * Forwarded as `default` to the Button's `<ViewTransition>`: animates the commit that ends the\n * action (content keyed on `pending`), not a click.\n * Static: setting or unsetting it remounts the element. Any value, `\"none\"` included, makes a\n * mount or `<Activity>` reveal inside a transition start a document view transition (a ~250 ms\n * page cross-fade that the next transition waits for).\n */\n transition?: ViewTransitionClass;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ButtonState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ButtonState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, ButtonState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, ButtonState>;\n}\n\n/**\n * A button whose click is a transition (design/components/button.md): `<button type=\"button\">`\n * that runs `action` in its own transition, with `data-pending` while it runs. A click meanwhile\n * runs it again, or with `whilePending=\"ignore\"` is ignored while the Button is `aria-disabled`\n * (conventions 2.5.1). With a function\n * `formAction` it is a form submitter, pending from its own submission until the form's\n * submissions have all finished. Inside a\n * `Toolbar.Root` a disabled Button stays focusable (`aria-disabled`).\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>` only), `disabled`, `aria-disabled`,\n * `data-pending`, `data-disabled`, `onClick`.\n *\n * @see https://ui.funstack.work/components/button\n */\nexport function Button({\n action,\n formAction,\n whilePending,\n type,\n disabled = false,\n focusableWhenDisabled = false,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: ButtonProps) {\n const toolbar = useToolbarContext();\n // Not a host <button> (a link, a component): native `disabled` would mean nothing to the\n // browser and hide the state from AT, so the focusable-disabled branch.\n const focusable = focusableWhenDisabled || toolbar !== null || !isHostButton(render);\n // Button is the fully user-owned trigger: every activation runs unless the consumer opts in\n // (conventions 2.5.1, design 18).\n const ignoring = (whilePending ?? \"run\") === \"ignore\";\n const { pending: ownPending, run } = useActionTrigger({ ignoreWhilePending: ignoring });\n\n // Per-submitter pending (design 6.2): React reports the latest submitter's function as\n // `status.action`. `submittedWith` keeps the function this Button last submitted with, so an\n // inline `formAction` whose identity changes during the submission still matches. Another\n // submission overwrites `status.action` while this one still runs, so `submitted` latches the\n // first render that named this Button and holds until the form status is idle: pending from its\n // own submission until the form's submissions have all finished (#154).\n const status = useFormStatus();\n const submittedWith = useRef<unknown>(undefined);\n const [submitted, setSubmitted] = useState(false);\n const named =\n status.pending &&\n typeof formAction === \"function\" &&\n // Written only by the click handler, before the submission whose status this render shows,\n // so the render that reads it is never stale for that submission.\n // oxlint-disable-next-line react/refs\n (status.action === formAction || status.action === submittedWith.current);\n // Derived state, updated during render (React re-renders this component before committing).\n if (named && !submitted) setSubmitted(true);\n if (!status.pending && submitted) setSubmitted(false);\n // Gated as a whole: a latch left from a function `formAction` that became a URL or `action`\n // must not keep the Button pending (a URL has no pending and no guard, 6.2).\n const formPending = typeof formAction === \"function\" && (named || (status.pending && submitted));\n const pending = ownPending || formPending;\n\n useDevWarning(\n action !== undefined && formAction !== undefined,\n isDev &&\n \"Button: `action` and `formAction` were both given. One click would run two actions; the \" +\n \"Button runs `action` and leaves `formAction` to the form submission. Pass one of them.\",\n );\n useDevWarning(\n action !== undefined && (type === \"submit\" || type === \"reset\"),\n isDev &&\n `Button: \\`action\\` together with type=\"${type}\". One click would run \\`action\\` in a ` +\n `transition and ${type === \"reset\" ? \"reset\" : \"submit\"} the form. Use \\`formAction\\` ` +\n `for a submitter, or drop \\`type\\`.`,\n );\n\n const state: ButtonState = { pending, disabled };\n\n const element = useRender<ComponentPropsWithRef<\"button\">, ButtonState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: formAction === undefined ? rest : { ...rest, formAction },\n libraryProps: {\n ...(rendersButton(render) && {\n type: type ?? (formAction !== undefined ? \"submit\" : \"button\"),\n }),\n // `undefined` (not `false`) in the focusable case, so the owned key removes a render\n // element's `disabled` too.\n disabled: disabled && !focusable ? true : undefined,\n // While pending only when ignoring: a Button that still acts is not unavailable (3.6).\n \"aria-disabled\": (pending && ignoring) || (disabled && focusable) ? true : undefined,\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n onClick: (event: MouseEvent<HTMLButtonElement>) => {\n // `event.defaultPrevented` is never read: an outer part (`Dialog.Trigger`) cancels the\n // click as part of its own mechanism and the Button must still run (design 5.1).\n if (disabled) {\n // A disabled link must not navigate either.\n event.preventDefault();\n return;\n }\n if (action === undefined) {\n // A native button (a `formAction` submitter, a command, a link): only the guard.\n if (ignoring && formPending) {\n event.preventDefault();\n return;\n }\n submittedWith.current = formAction;\n return;\n }\n const details: ButtonActionDetails = createActionDetails(event.nativeEvent, {});\n // Ignored while pending (`\"ignore\"` only): do not navigate, submit or run a command either.\n if (!run(() => action(details))) event.preventDefault();\n },\n },\n });\n\n return useTransitionBoundary(\"Button\", transition, element);\n}\n\nButton.displayName = \"Button\";\n"],"mappings":";;;;;;;;;;;;AAyBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;AAgHvC,SAAgB,OAAO,EACrB,QACA,YACA,cACA,MACA,WAAW,OACX,wBAAwB,OACxB,YACA,WACA,OACA,UACA,QACA,GAAG,QACW;CACd,MAAM,UAAU,kBAAkB;CAGlC,MAAM,YAAY,yBAAyB,YAAY,QAAQ,CAAC,aAAa,MAAM;CAGnF,MAAM,YAAY,gBAAgB,WAAW;CAC7C,MAAM,EAAE,SAAS,YAAY,QAAQ,iBAAiB,EAAE,oBAAoB,SAAS,CAAC;CAQtF,MAAM,SAAS,cAAc;CAC7B,MAAM,gBAAgB,OAAgB,KAAA,CAAS;CAC/C,MAAM,C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1
+ {"version":3,"file":"button.mjs","names":[],"sources":["../../src/button/button.tsx"],"sourcesContent":["\"use client\";\nimport { isValidElement, useRef, useState } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent,\n ReactNode,\n ViewTransitionClass,\n} from \"react\";\nimport { useFormStatus } from \"react-dom\";\nimport { createActionDetails } from \"../internal/action/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { useToolbarContext } from \"../internal/toolbar-context.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type {\n Action,\n ActionDetails,\n RenderProp,\n StateValue,\n WhilePending,\n} from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { usePureTrigger } from \"../internal/action/use-pure-trigger.js\";\nimport { disabledButton, rendersButton, useRender } from \"../internal/use-render.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** Details passed to `Button`'s `action`. Serialisable; `event` is virtual (conventions 2.2). */\nexport interface ButtonActionDetails extends ActionDetails {}\n\n/**\n * State of `Button`, passed to the function forms of `className`, `style`, `children` and `render`.\n */\nexport interface ButtonState {\n /**\n * This Button's own `action` is in flight, or it submitted the form through its own function\n * `formAction` and the form's submissions have not all finished yet.\n */\n readonly pending: boolean;\n /** The `disabled` prop. Not set by pending. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Button`.\n *\n * @see https://ui.funstack.work/components/button\n */\nexport interface ButtonProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"aria-disabled\" | \"className\" | \"style\" | \"children\" | \"type\" | \"formAction\"\n> {\n /**\n * Runs inside this Button's own transition on click, Enter or Space (`data-pending`\n * meanwhile). Sync or async; may be a Server Function. A rejection reaches the nearest Error\n * Boundary above the Button. A click while it is pending runs it again unless `whilePending`\n * is `\"ignore\"`. Not combinable with `formAction` (development error).\n */\n action?: Action<[details: ButtonActionDetails]>;\n /**\n * React's `formAction`: a function (a Server Function, a `useActionState` dispatch, a client\n * function) or a URL, run by React instead of the form's `action` when this Button submits the\n * form. With a function, the Button is `pending` from its own submission until the form's\n * submissions have all finished (never for another submitter's alone) and defaults to\n * `type=\"submit\"`. A click meanwhile submits again\n * unless `whilePending` is `\"ignore\"`; React drops the rejection of an older overlapping\n * submission, so use `\"ignore\"` (or `useActionState`) for a submission that must not overlap.\n */\n formAction?: ComponentPropsWithRef<\"button\">[\"formAction\"];\n /**\n * What a click, Enter or Space does while this Button's own `action` (or its own function\n * `formAction` submission) is pending. `\"run\"`: it runs as well; the Button shows\n * `data-pending` until every run has settled. `\"ignore\"`: it starts nothing, its default action\n * is cancelled (no second submission, navigation or command), and the Button renders\n * `aria-disabled=\"true\"` while pending. Use `\"ignore\"` for an action that must not run twice\n * (Save, Pay, Delete). No effect on a Button with neither `action` nor a function `formAction`.\n *\n * @defaultValue `\"run\"`\n */\n whilePending?: WhilePending;\n /**\n * Owned on a `<button>` and on a component `render` element (set it here, not on the element; a\n * component should spread it); omitted for a host element of another tag (`<a>`). `action`\n * together with `\"submit\"` / `\"reset\"` warns in development: one click would do two things.\n *\n * @defaultValue `\"button\"`, or `\"submit\"` when `formAction` is given\n */\n type?: \"button\" | \"submit\" | \"reset\";\n /**\n * Native `disabled` (owned; a `render` element cannot re-enable it) and `data-disabled`.\n * Never dispatches. With `focusableWhenDisabled` or inside a `Toolbar.Root`, renders\n * `aria-disabled=\"true\"` instead and cancels the click. So does a host element of another tag\n * (`render={<a href />}`), and a component `render` whose click only the Button acts on. A\n * component or `<input>` `render` whose click the browser also acts on (`type=\"submit\"` /\n * `\"reset\"`, the `formAction` default, `commandfor` / `popoverTarget`; with or without\n * `action`) keeps native `disabled`: only that stops a submission or command before\n * hydration. Native `disabled`\n * wins over the pending `aria-disabled`.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Keep a disabled Button focusable: `aria-disabled=\"true\"` instead of native `disabled`, so\n * keyboard and screen-reader users still find it and a Tooltip on it still opens. Before\n * hydration a focusable disabled submitter still submits (nothing native stops it).\n *\n * @defaultValue `false`; implied `true` inside a `Toolbar.Root` (APG Toolbar)\n */\n focusableWhenDisabled?: boolean;\n /**\n * Forwarded as `default` to the Button's `<ViewTransition>`: animates the commit that ends the\n * action (content keyed on `pending`), not a click.\n * Static: setting or unsetting it remounts the element. Any value, `\"none\"` included, makes a\n * mount or `<Activity>` reveal inside a transition start a document view transition (a ~250 ms\n * page cross-fade that the next transition waits for).\n */\n transition?: ViewTransitionClass;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ButtonState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ButtonState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, ButtonState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, ButtonState>;\n}\n\n/**\n * A button whose click is a transition (design/components/button.md): `<button type=\"button\">`\n * that runs `action` in its own transition, with `data-pending` while it runs. A click meanwhile\n * runs it again, or with `whilePending=\"ignore\"` is ignored while the Button is `aria-disabled`\n * (conventions 2.5.1). With a function\n * `formAction` it is a form submitter, pending from its own submission until the form's\n * submissions have all finished. Inside a\n * `Toolbar.Root` a disabled Button stays focusable (`aria-disabled`).\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>` only), `disabled`, `aria-disabled`,\n * `data-pending`, `data-disabled`, `onClick`.\n *\n * @see https://ui.funstack.work/components/button\n */\nexport function Button({\n action,\n formAction,\n whilePending,\n type,\n disabled = false,\n focusableWhenDisabled = false,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: ButtonProps) {\n const toolbar = useToolbarContext();\n const resolvedType = type ?? (formAction !== undefined ? \"submit\" : \"button\");\n // The browser acts on the click (with or without `action`) when it submits, resets or runs a\n // JS-free invoker command. Then an element that may be a button keeps native `disabled`, the\n // only state that stops it before hydration (conventions 1.2, #158). Otherwise the Button's\n // handler is all the click does, and a link or component render takes `aria-disabled` with\n // the cancelled click. A host `<input>` render keeps its own `type` (the Button owns `type` on\n // a button only), so that is the type the browser acts on.\n const clickType =\n isValidElement<{ type?: unknown }>(render) && render.type === \"input\"\n ? [\"submit\", \"image\", \"reset\"].includes(String(render.props.type))\n ? \"submit\"\n : \"button\"\n : resolvedType;\n const browserRun =\n clickType !== \"button\" || rest.commandfor !== undefined || rest.popoverTarget !== undefined;\n // `focusableWhenDisabled` and a Toolbar opt into the focusable disabled control (APG Toolbar).\n const disabledProps = disabledButton(render, disabled, {\n handlesClick: !browserRun,\n alwaysFocusable: focusableWhenDisabled || toolbar !== null,\n }).props;\n // Button is the fully user-owned trigger: every activation runs unless the consumer opts in\n // (conventions 2.5.1, design 18).\n const trigger = usePureTrigger({ whilePending, defaultWhilePending: \"run\" });\n const { ignoring } = trigger;\n\n // Per-submitter pending (design 6.2): React reports the latest submitter's function as\n // `status.action`. `submittedWith` keeps the function this Button last submitted with, so an\n // inline `formAction` whose identity changes during the submission still matches. Another\n // submission overwrites `status.action` while this one still runs, so `submitted` latches the\n // first render that named this Button and holds until the form status is idle: pending from its\n // own submission until the form's submissions have all finished (#154).\n const status = useFormStatus();\n const submittedWith = useRef<unknown>(undefined);\n const [submitted, setSubmitted] = useState(false);\n const named =\n status.pending &&\n typeof formAction === \"function\" &&\n // Written only by the click handler, before the submission whose status this render shows,\n // so the render that reads it is never stale for that submission.\n // oxlint-disable-next-line react/refs\n (status.action === formAction || status.action === submittedWith.current);\n // Derived state, updated during render (React re-renders this component before committing).\n if (named && !submitted) setSubmitted(true);\n if (!status.pending && submitted) setSubmitted(false);\n // Gated as a whole: a latch left from a function `formAction` that became a URL or `action`\n // must not keep the Button pending (a URL has no pending and no guard, 6.2).\n const formPending = typeof formAction === \"function\" && (named || (status.pending && submitted));\n const pending = trigger.pending || formPending;\n\n useDevWarning(\n action !== undefined && formAction !== undefined,\n isDev &&\n \"Button: `action` and `formAction` were both given. One click would run two actions; the \" +\n \"Button runs `action` and leaves `formAction` to the form submission. Pass one of them.\",\n );\n useDevWarning(\n action !== undefined && (type === \"submit\" || type === \"reset\"),\n isDev &&\n `Button: \\`action\\` together with type=\"${type}\". One click would run \\`action\\` in a ` +\n `transition and ${type === \"reset\" ? \"reset\" : \"submit\"} the form. Use \\`formAction\\` ` +\n `for a submitter, or drop \\`type\\`.`,\n );\n\n const state: ButtonState = { pending, disabled };\n\n const element = useRender<ComponentPropsWithRef<\"button\">, ButtonState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: formAction === undefined ? rest : { ...rest, formAction },\n libraryProps: {\n ...(rendersButton(render) && { type: resolvedType }),\n // `undefined` (not `false`) when enabled or in the focusable branch, so the owned key\n // removes a render element's `disabled` too.\n disabled: disabledProps.disabled === true ? true : undefined,\n // `aria-disabled` while pending only when ignoring: a Button that still acts is not\n // unavailable (3.6). Native `disabled` wins over it. Both channels' pending.\n ...trigger.pendingProps(disabledProps, pending),\n \"data-disabled\": dataAttr(disabled),\n onClick: (event: MouseEvent<HTMLButtonElement>) => {\n // `event.defaultPrevented` is never read: an outer part (`Dialog.Trigger`) cancels the\n // click as part of its own mechanism and the Button must still run (design 5.1).\n if (disabled) {\n // A disabled link must not navigate either.\n event.preventDefault();\n return;\n }\n if (action === undefined) {\n // A native button (a `formAction` submitter, a command, a link): only the guard.\n if (ignoring && formPending) {\n event.preventDefault();\n return;\n }\n submittedWith.current = formAction;\n return;\n }\n const details: ButtonActionDetails = createActionDetails(event.nativeEvent, {});\n // Ignored while pending (`\"ignore\"` only): do not navigate, submit or run a command either.\n trigger.runActivation(event, () => action(details));\n },\n },\n });\n\n return useTransitionBoundary(\"Button\", transition, element);\n}\n\nButton.displayName = \"Button\";\n"],"mappings":";;;;;;;;;;;;AAyBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;AAqHvC,SAAgB,OAAO,EACrB,QACA,YACA,cACA,MACA,WAAW,OACX,wBAAwB,OACxB,YACA,WACA,OACA,UACA,QACA,GAAG,QACW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GAGlD,UAAU,cAAc,aAAa,OAAO,OAAO,KAAA;GAGnD,GAAG,QAAQ,aAAa,eAAe,OAAO;GAC9C,iBAAiB,SAAS,QAAQ;GAClC,UAAU,UAAyC;IAGjD,IAAI,UAAU;KAEZ,MAAM,eAAe;KACrB;IACF;IACA,IAAI,WAAW,KAAA,GAAW;KAExB,IAAI,YAAY,aAAa;MAC3B,MAAM,eAAe;MACrB;KACF;KACA,cAAc,UAAU;KACxB;IACF;IACA,MAAM,UAA+B,oBAAoB,MAAM,aAAa,CAAC,CAAC;IAE9E,QAAQ,cAAc,aAAa,OAAO,OAAO,CAAC;GACpD;EACF;CACF,CAAC;CAED,OAAO,sBAAsB,UAAU,YAAY,OAAO;AAC5D;AAEA,OAAO,cAAc"}
@@ -2,7 +2,7 @@
2
2
  import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
3
3
  import { useRender } from "../internal/use-render.mjs";
4
4
  import { transitionTypes } from "../internal/transition-types.mjs";
5
- import { useCheckableInput } from "../internal/use-checkable-input.mjs";
5
+ import { useCheckableInput } from "../internal/form/use-checkable-input.mjs";
6
6
  //#region src/checkbox/checkbox.tsx
7
7
  /**
8
8
  * A checkbox (WAI-ARIA "Checkbox" pattern, dual- and mixed-state). Renders
@@ -1 +1 @@
1
- {"version":3,"file":"checkbox.mjs","names":[],"sources":["../../src/checkbox/checkbox.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, ViewTransitionClass } from \"react\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n RenderProp,\n StateValue,\n} from \"../internal/types.js\";\nimport { useCheckableInput } from \"../internal/use-checkable-input.js\";\nimport { useRender } from \"../internal/use-render.js\";\n\n/** State of `Checkbox`, passed to the function forms of `className`, `style` and `render`. */\nexport interface CheckboxState {\n /** Optimistic checked state: what the user sees, including an in-flight change. */\n readonly checked: boolean;\n /**\n * The `indeterminate` prop, suspended while an action is in flight: `false` whenever `pending`\n * is true, so that the attribute, the DOM property and `:indeterminate` always agree.\n */\n readonly indeterminate: boolean;\n /** An action dispatched by this Checkbox is in flight (including the resulting render). */\n readonly pending: boolean;\n /** The `disabled` prop (or the enclosing `Field.Root`'s). */\n readonly disabled: boolean;\n}\n\n/** Details passed as the second argument of `checkedChangeAction`. */\nexport interface CheckboxCheckedChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user toggled the box (click, Space, label click); `event` is the native\n * `click` event. `\"platform\"`: the browser changed the value itself: a form reset (`event` is\n * the `reset` event) or a click before hydration / Firefox form-state restoration found on\n * mount (`event` is `undefined`).\n */\n readonly reason: ChangeReason;\n}\n\n/**\n * Props of `Checkbox`.\n *\n * @see https://ui.funstack.work/components/checkbox\n */\nexport interface CheckboxProps extends Omit<\n ComponentPropsWithRef<\"input\">,\n | \"type\"\n | \"checked\"\n | \"defaultChecked\"\n | \"onChange\"\n | \"aria-checked\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** Controlled checked state. `undefined` means uncontrolled. */\n checked?: boolean;\n /**\n * Initial checked state in uncontrolled mode. Also the value a form reset\n * returns to: the latest prop value is mirrored into the input's `defaultChecked`.\n *\n * @defaultValue `false`\n */\n defaultChecked?: boolean;\n /**\n * Controlled-only mixed state (APG tri-state checkbox), derived by the parent from other state;\n * there is no `defaultIndeterminate` and no action. Rendered as `el.indeterminate`,\n * `data-indeterminate` and `:indeterminate`, except while an action is pending. Clicking a\n * mixed box dispatches `checked: true` (for the usual unchecked + mixed representation). Does\n * not affect what the form submits.\n *\n * @defaultValue `false`\n */\n indeterminate?: boolean;\n /**\n * Called with the next checked state on every change. Runs inside the Checkbox's transition;\n * may be sync or async (also a Server Function). Rejections reach the nearest Error Boundary.\n * Also called with `details.reason === \"platform\"` for a form reset or a pre-hydration click.\n *\n * A `setState` placed after your own `await` is not a Transition update; wrap it in\n * `startTransition` (React limitation). `details.event.preventDefault()` is not a veto and is\n * unsupported here; use controlled mode to veto a change.\n */\n checkedChangeAction?: ChangeAction<boolean, CheckboxCheckedChangeDetails>;\n /**\n * Renders a natively disabled input; never dispatches.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Submitted as the input's value when checked.\n *\n * @defaultValue `\"on\"` (platform)\n */\n value?: string;\n /**\n * Forwarded as `default` to the Checkbox's `<ViewTransition>`. Default: no boundary. Animates the\n * commit that ends an action, not the optimistic flip; animate the flip with CSS on `:checked`.\n *\n * Static: setting or unsetting it remounts the element. Any value, `\"none\"` included, makes a\n * mount or `<Activity>` reveal inside a transition start a document view transition (a ~250 ms\n * page cross-fade that the next transition waits for).\n */\n transition?: ViewTransitionClass;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, CheckboxState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, CheckboxState>;\n /**\n * Replace the rendered element (element form) or take over rendering (function form). Must keep\n * an `<input type=\"checkbox\">`.\n */\n render?: RenderProp<ComponentPropsWithRef<\"input\">, CheckboxState>;\n}\n\n/**\n * A checkbox (WAI-ARIA \"Checkbox\" pattern, dual- and mixed-state). Renders\n * `<input type=\"checkbox\">` whose DOM `checked` is the optimistic state; the input carries\n * `data-pending` while `checkedChangeAction` is in flight and takes part in forms natively.\n *\n * Owned keys (a `render` element's value is overridden): `type`, `checked`, `defaultChecked`,\n * `indeterminate` (stripped), `aria-checked` (always removed), `disabled`, `data-checked`,\n * `data-indeterminate`, `data-pending`, `data-disabled`; inside a `Field.Root` also `id`,\n * `name`, `required`, `aria-invalid`, `aria-describedby` (token-merged) and `data-invalid`, and\n * `disabled` / `name` / `required` default from the Field. `role` passes through. Event handlers\n * are merged rather than owned: a `render` element's own `onChange` (or `onClick`) runs first,\n * then the library's; an `onClick` that calls `preventDefault()` cancels the change (nothing is\n * dispatched).\n *\n * @see https://ui.funstack.work/components/checkbox\n */\nexport function Checkbox({\n checked,\n defaultChecked,\n indeterminate = false,\n checkedChangeAction,\n disabled,\n transition,\n className,\n style,\n render,\n ...rest\n}: CheckboxProps) {\n const input = useCheckableInput({\n component: \"Checkbox\",\n checked,\n defaultChecked,\n checkedChangeAction,\n disabled,\n own: rest,\n transitionTypes: (next) => transitionTypes(\"checkbox\", next ? \"check\" : \"uncheck\"),\n indeterminate,\n });\n\n const state: CheckboxState = {\n checked: input.optimistic,\n indeterminate: input.shownIndeterminate,\n pending: input.pending,\n disabled: input.disabled,\n };\n\n const element = useRender<ComponentPropsWithRef<\"input\">, CheckboxState>({\n defaultElement: \"input\",\n render,\n state,\n className,\n style,\n children: undefined,\n ref: input.ref,\n // Pass-through layer: a `render` element's own props win over these (`role` included).\n props: rest,\n libraryProps: input.libraryProps,\n });\n\n return useTransitionBoundary(\"Checkbox\", transition, element);\n}\n\nCheckbox.displayName = \"Checkbox\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAqIA,SAAgB,SAAS,EACvB,SACA,gBACA,gBAAgB,OAChB,qBACA,UACA,YACA,WACA,OACA,QACA,GAAG,QACa;CAChB,MAAM,QAAQ,kBAAkB;EAC9B,WAAW;EACX;EACA;EACA;EACA;EACA,KAAK;EACL,kBAAkB,SAAS,gBAAgB,YAAY,OAAO,UAAU,SAAS;EACjF;CACF,CAAC;CAED,MAAM,QAAuB;EAC3B,SAAS,MAAM;EACf,eAAe,MAAM;EACrB,SAAS,MAAM;EACf,UAAU,MAAM;CAClB;CAEA,MAAM,UAAU,UAAyD;EACvE,gBAAgB;EAChB;EACA;EACA;EACA;EACA,UAAU,KAAA;EACV,KAAK,MAAM;EAEX,OAAO;EACP,cAAc,MAAM;CACtB,CAAC;CAED,OAAO,sBAAsB,YAAY,YAAY,OAAO;AAC9D;AAEA,SAAS,cAAc"}
1
+ {"version":3,"file":"checkbox.mjs","names":[],"sources":["../../src/checkbox/checkbox.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, ViewTransitionClass } from \"react\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n RenderProp,\n StateValue,\n} from \"../internal/types.js\";\nimport { useCheckableInput } from \"../internal/form/use-checkable-input.js\";\nimport { useRender } from \"../internal/use-render.js\";\n\n/** State of `Checkbox`, passed to the function forms of `className`, `style` and `render`. */\nexport interface CheckboxState {\n /** Optimistic checked state: what the user sees, including an in-flight change. */\n readonly checked: boolean;\n /**\n * The `indeterminate` prop, suspended while an action is in flight: `false` whenever `pending`\n * is true, so that the attribute, the DOM property and `:indeterminate` always agree.\n */\n readonly indeterminate: boolean;\n /** An action dispatched by this Checkbox is in flight (including the resulting render). */\n readonly pending: boolean;\n /** The `disabled` prop (or the enclosing `Field.Root`'s). */\n readonly disabled: boolean;\n}\n\n/** Details passed as the second argument of `checkedChangeAction`. */\nexport interface CheckboxCheckedChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user toggled the box (click, Space, label click); `event` is the native\n * `click` event. `\"platform\"`: the browser changed the value itself: a form reset (`event` is\n * the `reset` event) or a click before hydration / Firefox form-state restoration found on\n * mount (`event` is `undefined`).\n */\n readonly reason: ChangeReason;\n}\n\n/**\n * Props of `Checkbox`.\n *\n * @see https://ui.funstack.work/components/checkbox\n */\nexport interface CheckboxProps extends Omit<\n ComponentPropsWithRef<\"input\">,\n | \"type\"\n | \"checked\"\n | \"defaultChecked\"\n | \"onChange\"\n | \"aria-checked\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** Controlled checked state. `undefined` means uncontrolled. */\n checked?: boolean;\n /**\n * Initial checked state in uncontrolled mode. Also the value a form reset\n * returns to: the latest prop value is mirrored into the input's `defaultChecked`.\n *\n * @defaultValue `false`\n */\n defaultChecked?: boolean;\n /**\n * Controlled-only mixed state (APG tri-state checkbox), derived by the parent from other state;\n * there is no `defaultIndeterminate` and no action. Rendered as `el.indeterminate`,\n * `data-indeterminate` and `:indeterminate`, except while an action is pending. Clicking a\n * mixed box dispatches `checked: true` (for the usual unchecked + mixed representation). Does\n * not affect what the form submits.\n *\n * @defaultValue `false`\n */\n indeterminate?: boolean;\n /**\n * Called with the next checked state on every change. Runs inside the Checkbox's transition;\n * may be sync or async (also a Server Function). Rejections reach the nearest Error Boundary.\n * Also called with `details.reason === \"platform\"` for a form reset or a pre-hydration click.\n *\n * A `setState` placed after your own `await` is not a Transition update; wrap it in\n * `startTransition` (React limitation). `details.event.preventDefault()` is not a veto and is\n * unsupported here; use controlled mode to veto a change.\n */\n checkedChangeAction?: ChangeAction<boolean, CheckboxCheckedChangeDetails>;\n /**\n * Renders a natively disabled input; never dispatches.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Submitted as the input's value when checked.\n *\n * @defaultValue `\"on\"` (platform)\n */\n value?: string;\n /**\n * Forwarded as `default` to the Checkbox's `<ViewTransition>`. Default: no boundary. Animates the\n * commit that ends an action, not the optimistic flip; animate the flip with CSS on `:checked`.\n *\n * Static: setting or unsetting it remounts the element. Any value, `\"none\"` included, makes a\n * mount or `<Activity>` reveal inside a transition start a document view transition (a ~250 ms\n * page cross-fade that the next transition waits for).\n */\n transition?: ViewTransitionClass;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, CheckboxState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, CheckboxState>;\n /**\n * Replace the rendered element (element form) or take over rendering (function form). Must keep\n * an `<input type=\"checkbox\">`.\n */\n render?: RenderProp<ComponentPropsWithRef<\"input\">, CheckboxState>;\n}\n\n/**\n * A checkbox (WAI-ARIA \"Checkbox\" pattern, dual- and mixed-state). Renders\n * `<input type=\"checkbox\">` whose DOM `checked` is the optimistic state; the input carries\n * `data-pending` while `checkedChangeAction` is in flight and takes part in forms natively.\n *\n * Owned keys (a `render` element's value is overridden): `type`, `checked`, `defaultChecked`,\n * `indeterminate` (stripped), `aria-checked` (always removed), `disabled`, `data-checked`,\n * `data-indeterminate`, `data-pending`, `data-disabled`; inside a `Field.Root` also `id`,\n * `name`, `required`, `aria-invalid`, `aria-describedby` (token-merged) and `data-invalid`, and\n * `disabled` / `name` / `required` default from the Field. `role` passes through. Event handlers\n * are merged rather than owned: a `render` element's own `onChange` (or `onClick`) runs first,\n * then the library's; an `onClick` that calls `preventDefault()` cancels the change (nothing is\n * dispatched).\n *\n * @see https://ui.funstack.work/components/checkbox\n */\nexport function Checkbox({\n checked,\n defaultChecked,\n indeterminate = false,\n checkedChangeAction,\n disabled,\n transition,\n className,\n style,\n render,\n ...rest\n}: CheckboxProps) {\n const input = useCheckableInput({\n component: \"Checkbox\",\n checked,\n defaultChecked,\n checkedChangeAction,\n disabled,\n own: rest,\n transitionTypes: (next) => transitionTypes(\"checkbox\", next ? \"check\" : \"uncheck\"),\n indeterminate,\n });\n\n const state: CheckboxState = {\n checked: input.optimistic,\n indeterminate: input.shownIndeterminate,\n pending: input.pending,\n disabled: input.disabled,\n };\n\n const element = useRender<ComponentPropsWithRef<\"input\">, CheckboxState>({\n defaultElement: \"input\",\n render,\n state,\n className,\n style,\n children: undefined,\n ref: input.ref,\n // Pass-through layer: a `render` element's own props win over these (`role` included).\n props: rest,\n libraryProps: input.libraryProps,\n });\n\n return useTransitionBoundary(\"Checkbox\", transition, element);\n}\n\nCheckbox.displayName = \"Checkbox\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAqIA,SAAgB,SAAS,EACvB,SACA,gBACA,gBAAgB,OAChB,qBACA,UACA,YACA,WACA,OACA,QACA,GAAG,QACa;CAChB,MAAM,QAAQ,kBAAkB;EAC9B,WAAW;EACX;EACA;EACA;EACA;EACA,KAAK;EACL,kBAAkB,SAAS,gBAAgB,YAAY,OAAO,UAAU,SAAS;EACjF;CACF,CAAC;CAED,MAAM,QAAuB;EAC3B,SAAS,MAAM;EACf,eAAe,MAAM;EACrB,SAAS,MAAM;EACf,UAAU,MAAM;CAClB;CAEA,MAAM,UAAU,UAAyD;EACvE,gBAAgB;EAChB;EACA;EACA;EACA;EACA,UAAU,KAAA;EACV,KAAK,MAAM;EAEX,OAAO;EACP,cAAc,MAAM;CACtB,CAAC;CAED,OAAO,sBAAsB,YAAY,YAAY,OAAO;AAC9D;AAEA,SAAS,cAAc"}
@@ -1,9 +1,9 @@
1
1
  "use client";
2
2
  import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
3
3
  import { useRender } from "../internal/use-render.mjs";
4
- import { syncPresences } from "../internal/sync-presence.mjs";
5
- import { useNativeChecked } from "../internal/use-native-checked.mjs";
6
- import { groupMemberProps } from "../internal/group-member.mjs";
4
+ import { syncPresences } from "../internal/form/sync-presence.mjs";
5
+ import { useNativeChecked } from "../internal/form/use-native-checked.mjs";
6
+ import { groupMemberProps } from "../internal/form/group-member.mjs";
7
7
  import { useCheckboxGroupContext } from "./checkbox-group-context.mjs";
8
8
  import { useLayoutEffect } from "react";
9
9
  //#region src/checkbox-group/checkbox-group-item.tsx
@@ -1 +1 @@
1
- {"version":3,"file":"checkbox-group-item.mjs","names":[],"sources":["../../src/checkbox-group/checkbox-group-item.tsx"],"sourcesContent":["\"use client\";\nimport { useLayoutEffect } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ViewTransitionClass } from \"react\";\nimport { groupMemberProps } from \"../internal/group-member.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useNativeChecked } from \"../internal/use-native-checked.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { useCheckboxGroupContext } from \"./checkbox-group-context.js\";\nimport { syncPresences } from \"../internal/sync-presence.js\";\n\n/**\n * State of `CheckboxGroup.Item`, passed to the function forms of `className`, `style` and `render`.\n */\nexport interface CheckboxGroupItemState {\n /** The Item's `value` prop. */\n readonly value: string;\n /** Optimistic: true as soon as the user checks this box, before the action settles. */\n readonly checked: boolean;\n /** The Root is pending and this box's optimistic state differs from its committed state. */\n readonly pending: boolean;\n /** Disabled by its own prop or by `Root disabled`. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `CheckboxGroup.Item`.\n *\n * @see https://ui.funstack.work/components/checkbox-group\n */\nexport interface CheckboxGroupItemProps extends Omit<\n ComponentPropsWithRef<\"input\">,\n | \"type\"\n | \"name\"\n | \"value\"\n | \"checked\"\n | \"defaultChecked\"\n | \"defaultValue\"\n | \"form\"\n | \"required\"\n | \"aria-checked\"\n | \"onChange\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** The value this box contributes when checked. Must be unique within the Root. */\n value: string;\n /**\n * Native `disabled`: unfocusable, never dispatches, barred from constraint validation. A\n * `Parent` leaves a disabled Item's value alone and derives its state without it; a checked\n * disabled Item does not satisfy the group's `required`.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Forwarded to the Item's `<ViewTransition default>`. Default: no boundary. Fires only on the\n * commit that settles the action (or rolls it back), never on the optimistic check; animate the\n * check itself with CSS on `:checked`.\n *\n * Static: setting or unsetting it remounts the element. Any value, `\"none\"` included, makes a\n * mount or `<Activity>` reveal inside a transition start a document view transition (a ~250 ms\n * page cross-fade that the next transition waits for).\n */\n transition?: ViewTransitionClass;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, CheckboxGroupItemState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, CheckboxGroupItemState>;\n /** Replace the rendered element. Must keep an `<input>`; the library sets `type=\"checkbox\"`. */\n render?: RenderProp<ComponentPropsWithRef<\"input\">, CheckboxGroupItemState>;\n}\n\n/**\n * One `<input type=\"checkbox\">` of the group, checked while its `value` is in the group's set.\n * Its DOM `checked` is the optimistic state (`checked={optimistic.has(value)}`): react-dom\n * restores a controlled input to its props after every event, and only the sync-lane optimistic\n * value survives that restore.\n *\n * Owned keys (conventions 1.2; a `render` element's value is overridden): `type`, `name`,\n * `value`, `checked`, `defaultChecked` (never rendered), `disabled`, `form`, `required`\n * (computed by the Root from its `required` prop), `aria-checked` (removed), `data-checked`,\n * `data-pending`, `data-disabled`; inside a `Field.Root` also `aria-invalid` (the Field's).\n * `onChange` is merged: a `render` element's own handler runs\n * first, then the library's. `role` passes through.\n *\n * @see https://ui.funstack.work/components/checkbox-group\n */\nexport function CheckboxGroupItem({\n value,\n disabled: disabledProp = false,\n transition,\n className,\n style,\n render,\n ...rest\n}: CheckboxGroupItemProps) {\n const ctx = useCheckboxGroupContext(\"CheckboxGroup.Item\");\n const checked = ctx.optimistic.has(value);\n const pending = ctx.state.pending && checked !== ctx.committed.has(value);\n const disabled = ctx.state.disabled || disabledProp;\n const required = ctx.required;\n\n // The Root needs every Item's own `disabled` for the Parents and `required` (design 6.2, 7).\n const { registerItem } = ctx;\n useLayoutEffect(() => registerItem(value, disabledProp), [registerItem, value, disabledProp]);\n\n // Group mode: element check and re-apply only; the Root reports the residual paths once.\n const inputRef = useNativeChecked({\n type: \"checkbox\",\n component: \"CheckboxGroup.Item\",\n checked,\n group: true,\n onItemMounted: (el) => {\n // Hydration keeps server attributes that differ from the client render (React only warns).\n // An Item hydrating after its Root can render a different state than the server did (a\n // click on an already hydrated box), and stale attributes would stay until the next change.\n if (el !== null) {\n syncPresences(el, {\n \"data-checked\": checked,\n \"data-pending\": pending,\n \"data-disabled\": disabled,\n required,\n });\n }\n ctx.onItemMounted(el);\n },\n defaultChecked: ctx.defaultValue === undefined ? undefined : ctx.defaultValue.has(value),\n });\n\n const state: CheckboxGroupItemState = { value, checked, pending, disabled };\n\n const element = useRender<ComponentPropsWithRef<\"input\">, CheckboxGroupItemState>({\n defaultElement: \"input\",\n render,\n state,\n className,\n style,\n children: undefined,\n ref: inputRef,\n // Pass-through layer: a `render` element's own props win over these.\n props: rest,\n libraryProps: groupMemberProps({\n type: \"checkbox\",\n component: \"CheckboxGroup.Item\",\n name: ctx.name,\n form: ctx.form,\n value,\n required,\n checked,\n pending,\n effectiveDisabled: disabled,\n ownDisabled: disabledProp,\n // Inside a Field (owned there): the group's invalid state, since the fieldset cannot carry it.\n invalid: ctx.fieldInvalid,\n activate: (event) => ctx.toggle(value, !checked, event),\n }),\n });\n\n return useTransitionBoundary(\"CheckboxGroup.Item\", transition, element);\n}\n\nCheckboxGroupItem.displayName = \"CheckboxGroupItem\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,kBAAkB,EAChC,OACA,UAAU,eAAe,OACzB,YACA,WACA,OACA,QACA,GAAG,QACsB;CACzB,MAAM,MAAM,wBAAwB,oBAAoB;CACxD,MAAM,UAAU,IAAI,WAAW,IAAI,KAAK;CACxC,MAAM,UAAU,IAAI,MAAM,WAAW,YAAY,IAAI,UAAU,IAAI,KAAK;CACxE,MAAM,WAAW,IAAI,MAAM,YAAY;CACvC,MAAM,WAAW,IAAI;CAGrB,MAAM,EAAE,iBAAiB;CACzB,sBAAsB,aAAa,OAAO,YAAY,GAAG;EAAC;EAAc;EAAO;CAAY,CAAC;CAG5F,MAAM,WAAW,iBAAiB;EAChC,MAAM;EACN,WAAW;EACX;EACA,OAAO;EACP,gBAAgB,OAAO;GAIrB,IAAI,OAAO,MACT,cAAc,IAAI;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,iBAAiB;IACjB;GACF,CAAC;GAEH,IAAI,cAAc,EAAE;EACtB;EACA,gBAAgB,IAAI,iBAAiB,KAAA,IAAY,KAAA,IAAY,IAAI,aAAa,IAAI,KAAK;CACzF,CAAC;CAID,MAAM,UAAU,UAAkE;EAChF,gBAAgB;EAChB;EACA,OAAA;GALsC;GAAO;GAAS;GAAS;EAK3D;EACJ;EACA;EACA,UAAU,KAAA;EACV,KAAK;EAEL,OAAO;EACP,cAAc,iBAAiB;GAC7B,MAAM;GACN,WAAW;GACX,MAAM,IAAI;GACV,MAAM,IAAI;GACV;GACA;GACA;GACA;GACA,mBAAmB;GACnB,aAAa;GAEb,SAAS,IAAI;GACb,WAAW,UAAU,IAAI,OAAO,OAAO,CAAC,SAAS,KAAK;EACxD,CAAC;CACH,CAAC;CAED,OAAO,sBAAsB,sBAAsB,YAAY,OAAO;AACxE;AAEA,kBAAkB,cAAc"}
1
+ {"version":3,"file":"checkbox-group-item.mjs","names":[],"sources":["../../src/checkbox-group/checkbox-group-item.tsx"],"sourcesContent":["\"use client\";\nimport { useLayoutEffect } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ViewTransitionClass } from \"react\";\nimport { groupMemberProps } from \"../internal/form/group-member.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useNativeChecked } from \"../internal/form/use-native-checked.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { useCheckboxGroupContext } from \"./checkbox-group-context.js\";\nimport { syncPresences } from \"../internal/form/sync-presence.js\";\n\n/**\n * State of `CheckboxGroup.Item`, passed to the function forms of `className`, `style` and `render`.\n */\nexport interface CheckboxGroupItemState {\n /** The Item's `value` prop. */\n readonly value: string;\n /** Optimistic: true as soon as the user checks this box, before the action settles. */\n readonly checked: boolean;\n /** The Root is pending and this box's optimistic state differs from its committed state. */\n readonly pending: boolean;\n /** Disabled by its own prop or by `Root disabled`. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `CheckboxGroup.Item`.\n *\n * @see https://ui.funstack.work/components/checkbox-group\n */\nexport interface CheckboxGroupItemProps extends Omit<\n ComponentPropsWithRef<\"input\">,\n | \"type\"\n | \"name\"\n | \"value\"\n | \"checked\"\n | \"defaultChecked\"\n | \"defaultValue\"\n | \"form\"\n | \"required\"\n | \"aria-checked\"\n | \"onChange\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** The value this box contributes when checked. Must be unique within the Root. */\n value: string;\n /**\n * Native `disabled`: unfocusable, never dispatches, barred from constraint validation. A\n * `Parent` leaves a disabled Item's value alone and derives its state without it; a checked\n * disabled Item does not satisfy the group's `required`.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Forwarded to the Item's `<ViewTransition default>`. Default: no boundary. Fires only on the\n * commit that settles the action (or rolls it back), never on the optimistic check; animate the\n * check itself with CSS on `:checked`.\n *\n * Static: setting or unsetting it remounts the element. Any value, `\"none\"` included, makes a\n * mount or `<Activity>` reveal inside a transition start a document view transition (a ~250 ms\n * page cross-fade that the next transition waits for).\n */\n transition?: ViewTransitionClass;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, CheckboxGroupItemState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, CheckboxGroupItemState>;\n /** Replace the rendered element. Must keep an `<input>`; the library sets `type=\"checkbox\"`. */\n render?: RenderProp<ComponentPropsWithRef<\"input\">, CheckboxGroupItemState>;\n}\n\n/**\n * One `<input type=\"checkbox\">` of the group, checked while its `value` is in the group's set.\n * Its DOM `checked` is the optimistic state (`checked={optimistic.has(value)}`): react-dom\n * restores a controlled input to its props after every event, and only the sync-lane optimistic\n * value survives that restore.\n *\n * Owned keys (conventions 1.2; a `render` element's value is overridden): `type`, `name`,\n * `value`, `checked`, `defaultChecked` (never rendered), `disabled`, `form`, `required`\n * (computed by the Root from its `required` prop), `aria-checked` (removed), `data-checked`,\n * `data-pending`, `data-disabled`; inside a `Field.Root` also `aria-invalid` (the Field's).\n * `onChange` is merged: a `render` element's own handler runs\n * first, then the library's. `role` passes through.\n *\n * @see https://ui.funstack.work/components/checkbox-group\n */\nexport function CheckboxGroupItem({\n value,\n disabled: disabledProp = false,\n transition,\n className,\n style,\n render,\n ...rest\n}: CheckboxGroupItemProps) {\n const ctx = useCheckboxGroupContext(\"CheckboxGroup.Item\");\n const checked = ctx.optimistic.has(value);\n const pending = ctx.state.pending && checked !== ctx.committed.has(value);\n const disabled = ctx.state.disabled || disabledProp;\n const required = ctx.required;\n\n // The Root needs every Item's own `disabled` for the Parents and `required` (design 6.2, 7).\n const { registerItem } = ctx;\n useLayoutEffect(() => registerItem(value, disabledProp), [registerItem, value, disabledProp]);\n\n // Group mode: element check and re-apply only; the Root reports the residual paths once.\n const inputRef = useNativeChecked({\n type: \"checkbox\",\n component: \"CheckboxGroup.Item\",\n checked,\n group: true,\n onItemMounted: (el) => {\n // Hydration keeps server attributes that differ from the client render (React only warns).\n // An Item hydrating after its Root can render a different state than the server did (a\n // click on an already hydrated box), and stale attributes would stay until the next change.\n if (el !== null) {\n syncPresences(el, {\n \"data-checked\": checked,\n \"data-pending\": pending,\n \"data-disabled\": disabled,\n required,\n });\n }\n ctx.onItemMounted(el);\n },\n defaultChecked: ctx.defaultValue === undefined ? undefined : ctx.defaultValue.has(value),\n });\n\n const state: CheckboxGroupItemState = { value, checked, pending, disabled };\n\n const element = useRender<ComponentPropsWithRef<\"input\">, CheckboxGroupItemState>({\n defaultElement: \"input\",\n render,\n state,\n className,\n style,\n children: undefined,\n ref: inputRef,\n // Pass-through layer: a `render` element's own props win over these.\n props: rest,\n libraryProps: groupMemberProps({\n type: \"checkbox\",\n component: \"CheckboxGroup.Item\",\n name: ctx.name,\n form: ctx.form,\n value,\n required,\n checked,\n pending,\n effectiveDisabled: disabled,\n ownDisabled: disabledProp,\n // Inside a Field (owned there): the group's invalid state, since the fieldset cannot carry it.\n invalid: ctx.fieldInvalid,\n activate: (event) => ctx.toggle(value, !checked, event),\n }),\n });\n\n return useTransitionBoundary(\"CheckboxGroup.Item\", transition, element);\n}\n\nCheckboxGroupItem.displayName = \"CheckboxGroupItem\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,kBAAkB,EAChC,OACA,UAAU,eAAe,OACzB,YACA,WACA,OACA,QACA,GAAG,QACsB;CACzB,MAAM,MAAM,wBAAwB,oBAAoB;CACxD,MAAM,UAAU,IAAI,WAAW,IAAI,KAAK;CACxC,MAAM,UAAU,IAAI,MAAM,WAAW,YAAY,IAAI,UAAU,IAAI,KAAK;CACxE,MAAM,WAAW,IAAI,MAAM,YAAY;CACvC,MAAM,WAAW,IAAI;CAGrB,MAAM,EAAE,iBAAiB;CACzB,sBAAsB,aAAa,OAAO,YAAY,GAAG;EAAC;EAAc;EAAO;CAAY,CAAC;CAG5F,MAAM,WAAW,iBAAiB;EAChC,MAAM;EACN,WAAW;EACX;EACA,OAAO;EACP,gBAAgB,OAAO;GAIrB,IAAI,OAAO,MACT,cAAc,IAAI;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,iBAAiB;IACjB;GACF,CAAC;GAEH,IAAI,cAAc,EAAE;EACtB;EACA,gBAAgB,IAAI,iBAAiB,KAAA,IAAY,KAAA,IAAY,IAAI,aAAa,IAAI,KAAK;CACzF,CAAC;CAID,MAAM,UAAU,UAAkE;EAChF,gBAAgB;EAChB;EACA,OAAA;GALsC;GAAO;GAAS;GAAS;EAK3D;EACJ;EACA;EACA,UAAU,KAAA;EACV,KAAK;EAEL,OAAO;EACP,cAAc,iBAAiB;GAC7B,MAAM;GACN,WAAW;GACX,MAAM,IAAI;GACV,MAAM,IAAI;GACV;GACA;GACA;GACA;GACA,mBAAmB;GACnB,aAAa;GAEb,SAAS,IAAI;GACb,WAAW,UAAU,IAAI,OAAO,OAAO,CAAC,SAAS,KAAK;EACxD,CAAC;CACH,CAAC;CAED,OAAO,sBAAsB,sBAAsB,YAAY,OAAO;AACxE;AAEA,kBAAkB,cAAc"}