@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 +0,0 @@
1
- {"version":3,"file":"use-native-group-reconciliation.mjs","names":[],"sources":["../../src/internal/use-native-group-reconciliation.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffectEvent, useLayoutEffect, useRef } from \"react\";\nimport type { RefObject } from \"react\";\nimport { useFormReset } from \"./use-form-reset.js\";\nimport type { FormAssociatedElement } from \"./use-form-owner-event.js\";\nimport { useLatest } from \"./use-latest.js\";\n\n/** Which residual path found the change: mount reconciliation (Root or late member) or form reset. */\nexport type NativeGroupPath = \"mount\" | \"reset\";\n\nexport interface UseNativeGroupReconciliationOptions<T> {\n /**\n * The group's form-associated element: `RadioGroup.Root`'s / `CheckboxGroup.Root`'s\n * `<fieldset>`, `Select.Root`'s `<select>` (whose options are the members), or any member\n * input when the Root renders no form-associated element (`Slider.Root` subscribes through its\n * first Thumb's `<input type=\"range\">`).\n */\n readonly element: RefObject<FormAssociatedElement | null>;\n /** The group's value as the DOM shows it now (`checked` of the members). */\n readonly readCurrent: () => T;\n /** The value the browser resets the group to (`defaultChecked` of the members, rule 5). */\n readonly readDefault: () => T;\n /**\n * What the user intends (rule 1): the latest in-flight dispatch's `next`, else the optimistic\n * value. `intendedValue` (use-controllable-action.ts) keeps an in-flight dispatch of a nullish\n * value (a pending reset to \"nothing checked\"), which `?.next ?? optimistic` would drop.\n */\n readonly base: () => T;\n /**\n * The browser changed the group's value on a residual path and it differs from `base()` (for a\n * form reset, also when equal while `dispatchEqualReset()` holds). `path` names the path:\n * `\"mount\"` for mount reconciliation (the Root's mount, or a member mounting later; `event` is\n * `undefined`), `\"reset\"` for a form reset (`event` is the `reset` event). CheckboxGroup reads\n * `path`, not `event`, to dispatch a reset as absolute (`DispatchOptions.whole`). The Root\n * dispatches once for the whole group with `reason: \"platform\"`.\n */\n readonly onPlatformChange: (next: T, event: Event | undefined, path: NativeGroupPath) => void;\n /**\n * Form reset only: dispatch the reset target even when it equals `base()`, while this returns\n * `true`. A set-valued group (CheckboxGroup) passes \"a dispatch is in flight\"\n * (`latestInFlight() !== null`): its reset is absolute in the uncontrolled replay (conventions\n * 3.3), so it must enter the burst even with an empty diff, or an earlier in-flight change that\n * rejects later would roll the group back past the reset (#151). Default: never.\n */\n readonly dispatchEqualReset?: (() => boolean) | undefined;\n /**\n * Equality between a read value and `base()`. Default `Object.is`, right for a primitive value\n * (RadioGroup's `string | null`); a group with a collection value (CheckboxGroup's\n * `ReadonlySet<string>`) passes structural equality, since every read builds a new object.\n */\n readonly equals?: ((a: T, b: T) => boolean) | undefined;\n /**\n * Passed through to `useFormReset`: called synchronously from the `reset` event, before the\n * reset algorithm runs. A group of controlled **value** inputs (Slider) writes each input's\n * `defaultValue` to the reset target here, because react-dom keeps that attribute equal to the\n * current value after every update (conventions 3.8 rule 6).\n */\n readonly onResetEvent?: ((event: Event) => void) | undefined;\n}\n\nexport interface UseNativeGroupReconciliationResult {\n /**\n * Stable. Pass it to every member, which hands it to\n * `useNativeChecked({ group: true, onItemMounted })`; the hook calls it from the member's mount\n * layout effect. A member that mounts after the Root's own mount reconciliation (inside a\n * Suspense boundary that hydrates later, selective hydration, or a member added on the client)\n * makes the adapter reconcile the group again: `readCurrent()` vs `base()`, in a microtask, once\n * for all members mounted in the same commit. Members mounting in the Root's own commit are\n * covered by the Root's mount reconciliation (their effects run before the Root's) and are\n * ignored. The member's element argument is not used here; the Root may use it (dev warnings).\n */\n readonly onItemMounted: (element?: Element | null) => void;\n}\n\n/**\n * Group adapter of the native-input machinery (conventions 3.8): one dispatch per group for the\n * residual browser paths, from the Root rather than once per member.\n *\n * - Mount reconciliation, once, in a layout effect: `readCurrent()` vs `base()`. The members'\n * `useNativeChecked({ group: true })` leaves `checked` alone in their mount commit, so this\n * effect, which runs after the members' (children first), still reads the hydrated DOM.\n * - Late members: a member mounting in a later commit (a Suspense boundary that hydrates after the\n * Root, where a click before hydration changed the DOM) reports through `onItemMounted`, and the\n * group is reconciled again the same way (see `UseNativeGroupReconciliationResult`).\n * - Form reset through `useFormReset` on the container: in a microtask after the reset,\n * `readDefault()` vs `base()` (or dispatched regardless while `dispatchEqualReset()` holds).\n *\n * Values are compared with `equals` (default `Object.is`).\n */\nexport function useNativeGroupReconciliation<T>(\n options: UseNativeGroupReconciliationOptions<T>,\n): UseNativeGroupReconciliationResult {\n const { element } = options;\n\n // The latest committed options, for the late reconciliation, which runs in a microtask outside\n // any effect (so it cannot go through an Effect Event).\n const latest = useLatest(options);\n\n /** The Root's own mount reconciliation has run (reset by its cleanup, StrictMode included). */\n const rootReconciled = useRef(false);\n /** A late reconciliation is queued; members mounting in the same commit share it. */\n const lateQueued = useRef(false);\n\n const reconcileMount = useEffectEvent(() => {\n if (element.current === null) return;\n reconcile(options, options.readCurrent(), \"mount\");\n });\n useLayoutEffect(() => {\n reconcileMount();\n rootReconciled.current = true;\n return () => {\n rootReconciled.current = false;\n };\n }, []);\n\n const onItemMounted = useCallback(() => {\n if (!rootReconciled.current || lateQueued.current) return;\n lateQueued.current = true;\n queueMicrotask(() => {\n lateQueued.current = false;\n if (!rootReconciled.current) return;\n const current = latest.current;\n if (current.element.current === null) return;\n reconcile(current, current.readCurrent(), \"mount\");\n });\n }, [latest]);\n\n useFormReset(\n element,\n (event) => {\n if (element.current === null) return;\n const next = options.readDefault();\n if (options.dispatchEqualReset?.()) options.onPlatformChange(next, event, \"reset\");\n else reconcile(options, next, \"reset\", event);\n },\n (event) => {\n if (element.current === null) return;\n options.onResetEvent?.(event);\n },\n );\n\n return { onItemMounted };\n}\n\nfunction reconcile<T>(\n options: UseNativeGroupReconciliationOptions<T>,\n next: T,\n path: NativeGroupPath,\n event?: Event,\n) {\n const equals = options.equals ?? Object.is;\n if (!equals(next, options.base())) options.onPlatformChange(next, event, path);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,6BACd,SACoC;CACpC,MAAM,EAAE,YAAY;CAIpB,MAAM,SAAS,UAAU,OAAO;;CAGhC,MAAM,iBAAiB,OAAO,KAAK;;CAEnC,MAAM,aAAa,OAAO,KAAK;CAE/B,MAAM,iBAAiB,qBAAqB;EAC1C,IAAI,QAAQ,YAAY,MAAM;EAC9B,UAAU,SAAS,QAAQ,YAAY,GAAG,OAAO;CACnD,CAAC;CACD,sBAAsB;EACpB,eAAe;EACf,eAAe,UAAU;EACzB,aAAa;GACX,eAAe,UAAU;EAC3B;CACF,GAAG,CAAC,CAAC;CAEL,MAAM,gBAAgB,kBAAkB;EACtC,IAAI,CAAC,eAAe,WAAW,WAAW,SAAS;EACnD,WAAW,UAAU;EACrB,qBAAqB;GACnB,WAAW,UAAU;GACrB,IAAI,CAAC,eAAe,SAAS;GAC7B,MAAM,UAAU,OAAO;GACvB,IAAI,QAAQ,QAAQ,YAAY,MAAM;GACtC,UAAU,SAAS,QAAQ,YAAY,GAAG,OAAO;EACnD,CAAC;CACH,GAAG,CAAC,MAAM,CAAC;CAEX,aACE,UACC,UAAU;EACT,IAAI,QAAQ,YAAY,MAAM;EAC9B,MAAM,OAAO,QAAQ,YAAY;EACjC,IAAI,QAAQ,qBAAqB,GAAG,QAAQ,iBAAiB,MAAM,OAAO,OAAO;OAC5E,UAAU,SAAS,MAAM,SAAS,KAAK;CAC9C,IACC,UAAU;EACT,IAAI,QAAQ,YAAY,MAAM;EAC9B,QAAQ,eAAe,KAAK;CAC9B,CACF;CAEA,OAAO,EAAE,cAAc;AACzB;AAEA,SAAS,UACP,SACA,MACA,MACA,OACA;CAEA,IAAI,EADW,QAAQ,UAAU,OAAO,GAAA,CAC5B,MAAM,QAAQ,KAAK,CAAC,GAAG,QAAQ,iBAAiB,MAAM,OAAO,IAAI;AAC/E"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-native-select-value.mjs","names":[],"sources":["../../src/internal/use-native-select-value.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffectEvent, useLayoutEffect, useMemo, useRef } from \"react\";\nimport type { RefObject } from \"react\";\nimport { useLatest } from \"./use-latest.js\";\nimport { useNativeGroupReconciliation } from \"./use-native-group-reconciliation.js\";\n\nexport interface UseNativeSelectValueOptions {\n /** The `<select>`. */\n readonly ref: RefObject<HTMLSelectElement | null>;\n /** The optimistic value (what the `<select>` renders). */\n readonly optimistic: string;\n /** From `useControllableAction`: the latest in-flight dispatch, if any. */\n readonly latestInFlight: () => { readonly next: string } | null;\n /**\n * The value a form reset must return to, mirrored into `option.defaultSelected` after every\n * commit: uncontrolled, the latest `defaultValue`; controlled, the Root's mount-time value.\n * Ignored in adopt mode (`adoptDefault` set), where the target is the value adopted at mount.\n */\n readonly resetTarget: string | undefined;\n /**\n * Uncontrolled without `defaultValue` (design/components/select.md 5): adopts the browser's\n * choice as the committed value, without a dispatch. `undefined` in every other mode.\n */\n readonly adoptDefault: AdoptDefault | undefined;\n /**\n * The browser changed the value on a residual path (pre-hydration pick, Firefox form-state\n * restoration, a late hydrated option, a form reset) and it differs from what the user intends.\n * `event` is the `reset` event or `undefined`. The Root dispatches once with\n * `reason: \"platform\"`.\n */\n readonly onPlatformChange: (next: string, event: Event | undefined) => void;\n}\n\nexport interface AdoptDefault {\n /** `adopt` of `useControllableAction`: writes the committed value, no action. */\n readonly adopt: (next: string) => void;\n /**\n * A dispatch (a pick or a platform change) has set the value. From then on the browser's\n * default is never adopted again: late options only get the re-apply, so options that suspend\n * again (a keyed boundary, a refetch) and come back keep the user's value.\n */\n readonly established: () => boolean;\n}\n\nexport interface UseNativeSelectValueResult {\n /**\n * Stable. Each `Select.Option` calls it from its mount layout effect with its element and\n * whether that render hydrated server HTML (`useHydratedMount`). Reports from the Root's own\n * commit are ignored (the Root's effects cover them). A later report re-applies the intended\n * option (React never selects options mounted after the select's own commit); a hydrated one\n * is also reconciled, from a DOM snapshot taken before the re-apply.\n */\n readonly optionMounted: (el: HTMLOptionElement | null, hydrated: boolean) => void;\n}\n\n/** The first option whose value is `value` (react-dom's `updateOptions` selects the first). */\nexport function findOption(select: HTMLSelectElement, value: string): HTMLOptionElement | null {\n for (const option of select.options) {\n if (option.value === value) return option;\n }\n return null;\n}\n\nfunction isEnabled(option: HTMLOptionElement): boolean {\n if (option.disabled) return false;\n const parent = option.parentElement;\n return !(parent?.tagName === \"OPTGROUP\" && (parent as HTMLOptGroupElement).disabled);\n}\n\nfunction firstEnabled(select: HTMLSelectElement): string {\n for (const option of select.options) {\n if (isEnabled(option)) return option.value;\n }\n return \"\";\n}\n\n/**\n * The spec's reset result for a single select: the last option whose `defaultSelected` is true,\n * else the first enabled option, else `\"\"` (nothing selected).\n */\nexport function readResetValue(select: HTMLSelectElement): string {\n let last: HTMLOptionElement | null = null;\n for (const option of select.options) {\n if (option.defaultSelected) last = option;\n }\n return last !== null ? last.value : firstEnabled(select);\n}\n\n/**\n * The option a `<select>` rendered with the value `\"\"` selects: an option whose value is `\"\"`\n * (react-dom's `updateOptions(\"\")` and Fizz's `selected` attribute both pick it, even when it is\n * disabled), else the first enabled option (the selectedness setting algorithm), else `\"\"`.\n */\nexport function implicitDefault(select: HTMLSelectElement): string {\n return findOption(select, \"\") !== null ? \"\" : firstEnabled(select);\n}\n\n/**\n * The reset-target mirror followed by the re-apply, in one synchronous step\n * (design/components/select.md 6.1). Writing `defaultSelected = true` on an option whose\n * dirtiness is false selects it, so the intended option is re-selected right after. Writes only\n * what differs: the common commit writes nothing.\n */\nexport function applySelection(\n select: HTMLSelectElement,\n target: string,\n resetTarget: string | undefined,\n): void {\n if (resetTarget !== undefined) {\n // Only the first match, the option react-dom would select for that value.\n const def = findOption(select, resetTarget);\n for (const option of select.options) {\n const want = option === def;\n if (option.defaultSelected !== want) option.defaultSelected = want;\n }\n }\n const option = findOption(select, target);\n if (option !== null && !option.selected) option.selected = true;\n}\n\ninterface Snapshot {\n readonly value: string;\n readonly index: number;\n}\n\nconst read = (select: HTMLSelectElement): Snapshot => ({\n value: select.value,\n index: select.selectedIndex,\n});\n\n/**\n * Native-`<select>` machinery for `Select.Root` (conventions 3.8, the select analogue of\n * `useNativeChecked`), on top of `useNativeGroupReconciliation`:\n *\n * 1. Adoption (uncontrolled without `defaultValue`): at mount the browser's default becomes the\n * committed value with no dispatch, and the mount reconciliation compares against it, so a\n * pre-hydration pick of another option still dispatches. It is also the reset target (the\n * value Fizz marks `selected` when it comes from a `\"\"` option). While no dispatch has set\n * the value, late options mounting without the state's option adopt again (loading).\n * 2. Mount reconciliation and form reset through the group adapter: one dispatch per Select, and\n * only when the intended option exists in the DOM (a value whose option is still loading is\n * never \"reconciled\" to the fallback).\n * 3. After every Root commit: the reset-target mirror, then the re-apply of the intended option.\n * 4. Late options: the same, once per commit; a hydrated late option is also reconciled, from a\n * snapshot of the selection taken before the re-apply.\n */\nexport function useNativeSelectValue(\n options: UseNativeSelectValueOptions,\n): UseNativeSelectValueResult {\n const { ref: elementRef } = options;\n // A `render` element that is not a <select> (dev warning in the Root) gets no DOM work.\n const ref = useMemo(\n () => ({\n get current(): HTMLSelectElement | null {\n const el = elementRef.current;\n // Tag, not `instanceof`: the element may come from another realm (an iframe).\n return el?.tagName === \"SELECT\" ? (el as HTMLSelectElement) : null;\n },\n }),\n [elementRef],\n );\n\n // The latest committed options. Written in the mutation phase (`useLatest`), so an Option's\n // mount layout effect, which runs before this Root's layout effects, already reads this commit's.\n const latest = useLatest(options);\n\n /**\n * A default adopted in this layout phase. Until the adoption's render (a sync update, flushed\n * right after this commit) the state still says the old value, so this is what the user\n * intends unless a dispatch is in flight. Cleared in a microtask, after that render.\n */\n const adopted = useRef<string | null>(null);\n const intended = (o: UseNativeSelectValueOptions): string => {\n const f = o.latestInFlight();\n if (f !== null) return f.next;\n return adopted.current ?? o.optimistic;\n };\n\n const adoptNow = (value: string, adopt: (next: string) => void) => {\n adopted.current = value;\n adopt(value);\n queueMicrotask(() => {\n adopted.current = null;\n });\n };\n\n /** Adopt mode: the value adopted at mount, the reset target (as the mount value is, controlled). */\n const mountAdopted = useRef<string | undefined>(undefined);\n const resetTargetOf = (o: UseNativeSelectValueOptions): string | undefined =>\n o.adoptDefault !== undefined ? mountAdopted.current : o.resetTarget;\n\n /** The selection read in the layout phase of a late-option commit (conventions 3.8 rule 3). */\n const lateSnapshot = useRef<Snapshot | null>(null);\n\n // 1. Adoption at mount. Declared before the adapter so that its mount reconciliation compares\n // the DOM against the adopted default.\n const adoptAtMount = useEffectEvent(() => {\n const select = ref.current;\n const adoptDefault = options.adoptDefault;\n // `established`: StrictMode's re-run after a mount reconciliation already dispatched.\n if (select === null || adoptDefault === undefined || adoptDefault.established()) return;\n const value = implicitDefault(select);\n // `\"\"` from a select with nothing selectable is no reset target (design 6.1): only a `\"\"`\n // option, the placeholder react-dom and Fizz select, is mirrored.\n mountAdopted.current = value === \"\" && findOption(select, \"\") === null ? undefined : value;\n adoptNow(value, adoptDefault.adopt);\n });\n useLayoutEffect(() => {\n adoptAtMount();\n }, []);\n\n // 2. Residual paths: one dispatch per Select.\n const { onItemMounted } = useNativeGroupReconciliation<string>({\n element: ref,\n readCurrent: () => {\n const select = ref.current;\n const snapshot = lateSnapshot.current;\n lateSnapshot.current = null;\n const base = intended(latest.current);\n if (select === null) return base;\n const current = snapshot ?? read(select);\n // The dispatch gate: nothing selected, or the intended option absent, is not a pick.\n if (current.index === -1 || findOption(select, base) === null) return base;\n return current.value;\n },\n readDefault: () => {\n const select = ref.current;\n return select === null ? intended(latest.current) : readResetValue(select);\n },\n base: () => intended(latest.current),\n onPlatformChange: (next, event) => latest.current.onPlatformChange(next, event),\n });\n\n // 3. After every commit. Declared after the adapter, so the mount commit's DOM is read by the\n // mount reconciliation before anything is re-applied.\n useLayoutEffect(() => {\n const select = ref.current;\n if (select === null) return;\n applySelection(select, intended(options), resetTargetOf(options));\n });\n\n /** The Root's own mount effects have run: later Option mounts are late. */\n const rootMounted = useRef(false);\n useLayoutEffect(() => {\n rootMounted.current = true;\n return () => {\n rootMounted.current = false;\n };\n }, []);\n /**\n * This commit's late options were handled (snapshot, adoption, re-apply). A microtask window,\n * not a per-commit flag: an Option's layout effect cannot tell which commit it belongs to (the\n * Root does not commit with a boundary that resolves inside it). A second commit in the same\n * task is covered by the per-report re-apply below; its hydrated options are reconciled against\n * the first commit's snapshot (theoretical: no part triggers such a commit).\n */\n const lateHandled = useRef(false);\n\n // 4. Late options.\n const optionMounted = useCallback(\n (el: HTMLOptionElement | null, hydrated: boolean) => {\n if (!rootMounted.current) return;\n const select = ref.current;\n if (select === null) return;\n if (!lateHandled.current) {\n lateHandled.current = true;\n // Every option of this commit is in the DOM already (the mutation phase precedes layout).\n lateSnapshot.current = read(select);\n const current = latest.current;\n const adoptDefault = current.adoptDefault;\n if (\n adoptDefault !== undefined &&\n !adoptDefault.established() &&\n current.latestInFlight() === null &&\n findOption(select, intended(current)) === null\n ) {\n // Still loading and nothing chosen yet (the fallback-only case): adopt the browser's\n // default. Never after a dispatch: that would overwrite the user's value silently.\n adoptNow(implicitDefault(select), adoptDefault.adopt);\n }\n applySelection(select, intended(current), resetTargetOf(current));\n // Cleared after the adapter's microtask, which a later report of this same commit may\n // queue after this point: two hops keep the snapshot for it.\n queueMicrotask(() =>\n queueMicrotask(() => {\n lateHandled.current = false;\n lateSnapshot.current = null;\n }),\n );\n } else if (el !== null) {\n // Per report, for an option that matters (cheap: at most the intended and the reset\n // target's options): a second commit within the window gets its re-apply too.\n const current = latest.current;\n if (el.value === intended(current) || el.value === resetTargetOf(current)) {\n applySelection(select, intended(current), resetTargetOf(current));\n }\n }\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E;EACA,IAAI,UAAU,cAAc,EAAE;CAChC,GACA;EAAC;EAAK;EAAQ;CAAa,CAGR,EAAE;AACzB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-overlay-close.mjs","names":[],"sources":["../../src/internal/use-overlay-close.ts"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, MouseEvent, ReactNode } from \"react\";\nimport { dataAttr } from \"./data-attr.js\";\nimport type { Action, ActionDetails, RenderProp, StateValue, WhilePending } from \"./types.js\";\nimport { useActionTrigger } from \"./use-action-trigger.js\";\nimport { useElementCheck } from \"./use-element-check.js\";\nimport { disabledButton, rendersButton, useRender } from \"./use-render.js\";\nimport type { DataAttributes } from \"./use-render.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** The state of Popover.Close and Dialog.Close. */\nexport interface OverlayCloseState {\n /** The `action` is in flight. */\n readonly pending: boolean;\n readonly disabled: boolean;\n}\n\nexport interface OverlayCloseOptions<Details extends ActionDetails> {\n /** Public name of the part (`\"Popover.Close\"`). */\n readonly part: string;\n /** What the part closes, for the development warning (`\"popover\"`). */\n readonly noun: string;\n readonly isLibrary: boolean;\n /** The popup's id (`commandfor`) and the native command. */\n readonly popupId: string;\n readonly command: \"hide-popover\" | \"request-close\";\n readonly openGeneration: () => number;\n readonly action: Action<[details: Details]> | undefined;\n /** The part's `whilePending` prop; `\"ignore\"` when omitted (conventions 2.5.1). */\n readonly whilePending: WhilePending | undefined;\n /** The `action`'s details, built at the click. */\n readonly details: (event: Event) => Details;\n /** The close after the action (or at once without one): through the Root, or natively. */\n readonly close: (event: Event) => void;\n /** Owned keys after `command` (Dialog.Close's `value`). */\n readonly ownProps?: ComponentPropsWithRef<\"button\">;\n readonly disabled: boolean;\n readonly className: StateValue<string | undefined, OverlayCloseState> | undefined;\n readonly style: StateValue<CSSProperties | undefined, OverlayCloseState> | undefined;\n readonly children: StateValue<ReactNode, OverlayCloseState> | undefined;\n readonly render: RenderProp<ComponentPropsWithRef<\"button\">, OverlayCloseState> | undefined;\n readonly rest: Omit<ComponentPropsWithRef<\"button\">, \"className\" | \"style\" | \"children\">;\n}\n\n/**\n * The Close part of a popover-like or dialog overlay (design/components/popover.md 3.4,\n * dialog.md 3.4): `<button type=\"button\" commandfor command>`. In JS-free mode without `action`\n * the browser runs the command. Otherwise the click is cancelled, refused while disabled, and\n * `close` runs, after the `action` when there is one, inside this part's own transition; a\n * second click meanwhile starts nothing (`whilePending`, default `\"ignore\"`) or runs the action\n * again (`\"run\"`; the close happens once, after the last run and only if the latest one\n * resolved), and a close whose open was superseded by a\n * newer one (dismissed and re-opened meanwhile) is dropped (the open-generation guard).\n */\nexport function useOverlayClose<Details extends ActionDetails>(\n options: OverlayCloseOptions<Details>,\n): ReactNode {\n const { part, noun, isLibrary, popupId, command, action, disabled, render } = options;\n // The library owns the close, so a Close ignores clicks while pending by default (2.5.1).\n const ignoring = (options.whilePending ?? \"ignore\") === \"ignore\";\n const { pending, run } = useActionTrigger({\n openGeneration: options.openGeneration,\n ignoreWhilePending: ignoring,\n });\n const installClick = isLibrary || action !== undefined;\n // JS-free mode without `action` is the browser's command, which only native `disabled` stops.\n const disabledProps = disabledButton(render, disabled, { handlesClick: installClick });\n\n const ref = useElementCheck(\n isDev &&\n ((element) =>\n !installClick && element.tagName !== \"BUTTON\"\n ? `${part}: rendered a <${element.tagName.toLowerCase()}> in JS-free mode without ` +\n `\\`action\\`. Only a <button> runs \\`command=\"${command}\"\\`; this element will not ` +\n `close the ${noun}.`\n : null),\n [installClick],\n );\n\n const onClick = (event: MouseEvent<HTMLElement>) => {\n // Cancelling the click cancels the command.\n event.preventDefault();\n if (disabled) return;\n const native = event.nativeEvent;\n if (action === undefined) {\n options.close(native);\n return;\n }\n const details = options.details(native);\n run(\n () => action(details),\n () => options.close(native),\n );\n };\n\n const libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes = {\n ...(rendersButton(render) && { type: \"button\" as const }),\n // Owned: a render element must not re-enable a disabled Close.\n disabled: disabledProps.props.disabled,\n // Only on a button (or a component, assumed to render one): another element is no invoker.\n // `disabledProps.invoker` itself stays the availability below.\n commandfor: disabledProps.invoker && rendersButton(render) ? popupId : undefined,\n command: disabledProps.invoker && rendersButton(render) ? command : undefined,\n ...options.ownProps,\n ...(installClick && { onClick }),\n // Exactly while `data-pending` when ignoring: a Close that will not act is unavailable to\n // AT; one that runs again is not. Owned, so an idle Close removes a render element's own.\n \"aria-disabled\": (pending && ignoring) || !disabledProps.invoker ? true : undefined,\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"button\">, OverlayCloseState>({\n defaultElement: \"button\",\n render,\n state: { pending, disabled },\n className: options.className,\n style: options.style,\n children: options.children,\n props: options.rest,\n libraryProps,\n ref,\n });\n}\n"],"mappings":";;;;;;;AASA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;AA8CvC,SAAgB,gBACd,SACW;CACX,MAAM,EAAE,MAAM,MAAM,WAAW,SAAS,SAAS,QAAQ,UAAU,WAAW;CAE9E,MAAM,YAAY,QAAQ,gBAAgB,cAAc;CACxD,MAAM,EAAE,SAAS,QAAQ,iBAAiB;EACxC,gBAAgB,QAAQ;EACxB,oBAAoB;CACtB,CAAC;CACD,MAAM,eAAe,aAAa,WAAW,KAAA;CAE7C,MAAM,gBAAgB,eAAe,QAAQ,UAAU,EAAE,cAAc,aAAa,CAAC;CAErF,MAAM,MAAM,gBACV,WACI,YACA,CAAC,gBAAgB,QAAQ,YAAY,WACjC,GAAG,KAAK,gBAAgB,QAAQ,QAAQ,YAAY,EAAE,wEACP,QAAQ,uCAC1C,KAAK,KAClB,OACR,CAAC,YAAY,CACf;CAEA,MAAM,WAAW,UAAmC;EAElD,MAAM,eAAe;EACrB,IAAI,UAAU;EACd,MAAM,SAAS,MAAM;EACrB,IAAI,WAAW,KAAA,GAAW;GACxB,QAAQ,MAAM,MAAM;GACpB;EACF;EACA,MAAM,UAAU,QAAQ,QAAQ,MAAM;EACtC,UACQ,OAAO,OAAO,SACd,QAAQ,MAAM,MAAM,CAC5B;CACF;CAEA,MAAM,eAAiE;EACrE,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;EAEvD,UAAU,cAAc,MAAM;EAG9B,YAAY,cAAc,WAAW,cAAc,MAAM,IAAI,UAAU,KAAA;EACvE,SAAS,cAAc,WAAW,cAAc,MAAM,IAAI,UAAU,KAAA;EACpE,GAAG,QAAQ;EACX,GAAI,gBAAgB,EAAE,QAAQ;EAG9B,iBAAkB,WAAW,YAAa,CAAC,cAAc,UAAU,OAAO,KAAA;EAC1E,gBAAgB,SAAS,OAAO;EAChC,iBAAiB,SAAS,QAAQ;CACpC;CAEA,OAAO,UAA8D;EACnE,gBAAgB;EAChB;EACA,OAAO;GAAE;GAAS;EAAS;EAC3B,WAAW,QAAQ;EACnB,OAAO,QAAQ;EACf,UAAU,QAAQ;EAClB,OAAO,QAAQ;EACf;EACA;CACF,CAAC;AACH"}
@@ -1,2 +0,0 @@
1
- import "./types.mjs";
2
- import { RefObject } from "react";
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-overlay-root.mjs","names":[],"sources":["../../src/internal/use-overlay-root.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useId, useMemo, useRef, useState } from \"react\";\nimport type { RefObject } from \"react\";\nimport { createActionDetails } from \"./action-details.js\";\nimport { callUrgentHandler } from \"./call-urgent-handler.js\";\nimport { isPopoverOpen } from \"./popover-open.js\";\nimport { transitionTypes } from \"./transition-types.js\";\nimport type { ActionDetails, ChangeAction, ChangeReason, UrgentChangeHandler } from \"./types.js\";\nimport { useControllableAction } from \"./use-controllable-action.js\";\nimport { useDevWarning } from \"./use-dev-warning.js\";\nimport { useLatest } from \"./use-latest.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * \"static\": JS-free mode, the browser owns open and close through Invoker Commands. \"library\":\n * opening and part-initiated closing are library-owned requests (transitions keyed on committed\n * state, `openChangeAction`); dismissals are the browser's facts, adopted urgently and reported to\n * `onOpenChange` (design/components/popover.md section 2, overlay-open-change.md).\n */\nexport type OverlayMode = \"static\" | \"library\";\n\n/**\n * What caused the next close, recorded just before it happens (design 2.3). The `toggle` event\n * names no cause beyond its invoker (`ToggleEvent.source`: a `popovertarget`, `commandfor` or\n * `interestfor` button); without an intent a close is a `\"dismiss\"`.\n */\nexport interface OverlayCloseIntent {\n readonly reason: ChangeReason;\n readonly event: Event | undefined;\n}\n\n/**\n * The `details` every overlay `openChangeAction` and `onOpenChange` receives (Dialog's adds\n * `returnValue`).\n */\nexport interface OverlayDetails extends ActionDetails {\n readonly reason: ChangeReason;\n}\n\n/**\n * The Root's state and machinery, shared by Popover, Menu, Combobox (design 14) and Dialog. The\n * component puts it in its own context; `usePopoverTrigger` and `usePopoverPopup` take it as their\n * first argument. `Popup` is the popup element's type; `CloseArgs` are the extra arguments of a\n * close (Dialog's `returnValue`), passed on to the `details` builder.\n */\nexport interface OverlayRootValue<Popup extends HTMLElement, CloseArgs extends unknown[]> {\n readonly mode: OverlayMode;\n /** `useId`-based ids: the popup, its Title and its Description. */\n readonly ids: { readonly popup: string; readonly title: string; readonly description: string };\n /** Committed open state (library mode); `false` in JS-free mode. */\n readonly committed: boolean;\n /** Optimistic open state (library mode); `false` in JS-free mode. */\n readonly optimistic: boolean;\n /**\n * The popup is in the top layer, mirrored from its `toggle` (urgent, conventions 3.5): what\n * `aria-expanded` renders on a non-button Trigger and the Combobox Input (a `<button>`\n * Trigger renders none). Written by a popover Popup in library mode; Dialog does not\n * maintain it, and its context omits it.\n */\n readonly shown: boolean;\n /** Writes `shown` from the DOM (`:popover-open`); the Popup's `toggle`, ref attach and detach. */\n readonly setShown: (shown: boolean) => void;\n /** The Root's transition is pending (library mode). */\n readonly pending: boolean;\n /**\n * Grows with every fact (`notifyClosed`). Part of the memoised value so that a fact always\n * re-renders the parts, even when a controlled parent keeps `open={true}` and nothing else\n * changed: the Popup's apply effect then re-opens the popup (design 2.4).\n */\n readonly epoch: number;\n /**\n * What the user already intends: the latest in-flight dispatch's `next`, else the optimistic\n * value of the last commit. Safe to call from handlers and effects (layout effects included,\n * also in the commit that changed it), and after an `await`. Not during render.\n */\n readonly intended: () => boolean;\n /**\n * A counter that grows with every open (a requested open, or the popup being shown). A part\n * whose close runs after an `await` records it first and drops the close when it changed: the\n * user dismissed and re-opened meanwhile (Popover.Close, design 3.4). Handlers only.\n */\n readonly openGeneration: () => number;\n /** Advance `openGeneration` (the Popup's `beforetoggle` for an open). */\n readonly nextOpenGeneration: () => void;\n /**\n * Open through the Root's transition (library mode): a Trigger click, a foreign open caught at\n * `beforetoggle`, or mount reconciliation. A no-op when `true` is already intended.\n */\n readonly requestOpen: (event: Event | undefined, reason: ChangeReason) => void;\n /**\n * A library-owned close (library mode): a Trigger click while open, a Close part, Menu's item\n * activation. `openChangeAction(false)` is awaited and the popup hides in the commit. A no-op\n * when `false` is already intended.\n */\n readonly requestClose: (\n event: Event | undefined,\n reason: ChangeReason,\n ...args: CloseArgs\n ) => void;\n /**\n * A fact (#148, overlay-open-change.md 2.2): the browser hid the popup and the library did not\n * hide it (the caller has already excluded the library's own hide). Supersedes every request in\n * flight, writes committed `false` urgently (uncontrolled), and calls `onOpenChange(false,\n * details)` synchronously through the handler rule (`callUrgentHandler`). Call it from the\n * platform event's listener (`toggle` / `close`), never inside a transition.\n */\n readonly notifyClosed: (\n event: Event | undefined,\n reason: ChangeReason,\n ...args: CloseArgs\n ) => void;\n /** From `useControllableAction`: the latest in-flight intent, or `null`. */\n readonly latestInFlight: () => { readonly next: boolean } | null;\n /**\n * The popup was shown at its last `toggle` and the DOM has it hidden now: the browser hid it\n * and its `toggle` has not arrived yet. A non-button Trigger's click lands in that window after\n * light dismiss hid the popup at `pointerup` (#115): it records an `\"activate\"` intent for the\n * fact instead of requesting a close. Handlers only.\n */\n readonly hiddenBeforeToggle: () => boolean;\n /** The registered Trigger: `showPopover({ source })` and the focus-return fallback. */\n readonly triggerRef: RefObject<HTMLElement | null>;\n /** The popup element, set by the Popup's ref; how Close reaches `hidePopover()` / `close()`. */\n readonly popupRef: RefObject<Popup | null>;\n /**\n * Record what causes the next close. Cleared after a task if the popover did not close.\n * `unlessRecorded`: keep an intent already recorded for this close (the `command` listener runs\n * before the `beforetoggle` of the same click).\n */\n readonly recordCloseIntent: (\n intent: OverlayCloseIntent | undefined,\n options?: { readonly unlessRecorded?: boolean },\n ) => void;\n /** Read and clear the recorded intent (the Popup's `toggle` listener). */\n readonly takeCloseIntent: () => OverlayCloseIntent | undefined;\n}\n\n/** The root value of the popover-like components (Popover, Menu, Combobox). */\nexport type PopoverRootValue = OverlayRootValue<HTMLElement, []>;\n\nexport interface UseOverlayRootOptions<\n Details extends ActionDetails,\n Popup extends HTMLElement = HTMLElement,\n CloseArgs extends unknown[] = [],\n> {\n /** Transition types and messages: `\"popover\"` gives `fsui-popover`, `fsui-popover-open`, … */\n readonly component: string;\n /** Public name of the Root part for development warnings (`\"Popover.Root\"`). */\n readonly part: string;\n readonly open: boolean | undefined;\n readonly defaultOpen: boolean | undefined;\n readonly openChangeAction: ChangeAction<boolean, Details> | undefined;\n /** The fact handler (#148): called for a hide the library did not perform. */\n readonly onOpenChange: UrgentChangeHandler<boolean, Details> | undefined;\n /**\n * `\"library\"` forces library mode whatever the props (Menu, which has no JS-free mode). Default:\n * detected from `open` / `defaultOpen` / `openChangeAction` / `onOpenChange` on the first\n * render.\n */\n readonly mode?: \"library\";\n /**\n * Called synchronously for every dispatch, before the action runs, and for every fact, before\n * `onOpenChange` (Menu: cancel hover timers, read the open cause).\n */\n readonly onDispatch?: (next: boolean, details: Details) => void;\n /** Builds the `details` of a dispatch (`popoverDetails`: `{ reason }`); an open passes no args. */\n readonly details: (\n event: Event | undefined,\n reason: ChangeReason,\n ...args: CloseArgs | []\n ) => Details;\n /** Whether the popup is shown, for a stale close intent. Default: `:popover-open`. */\n readonly isShown?: (popup: Popup) => boolean;\n}\n\n/** How long a recorded close intent survives when the popup did not close (design 2.3). */\nfunction clearLater<Popup extends HTMLElement>(\n intentRef: { current: OverlayCloseIntent | undefined },\n intent: OverlayCloseIntent,\n popupRef: { current: Popup | null },\n isShown: (popup: Popup) => boolean,\n): void {\n setTimeout(() => {\n // Closed: its `toggle` / `close` event (queued as a task) consumes the intent. Still open: the\n // close was cancelled or invalid, so the intent is stale.\n const popup = popupRef.current;\n if (intentRef.current === intent && popup !== null && isShown(popup)) {\n intentRef.current = undefined;\n }\n }, 0);\n}\n\n/** What the popup is called in the controlled-without-`onOpenChange` warning. */\nconst nouns: Record<string, string> = { combobox: \"listbox\" };\n\n/** The `details` of a popover-like component: `{ reason }` (and `event`). */\nexport const popoverDetails = (event: Event | undefined, reason: ChangeReason): OverlayDetails =>\n createActionDetails(event, { reason });\n\n/**\n * The Root of an overlay without its public props: mode detection (once, from the first\n * render), `useControllableAction<boolean>`, ids, refs, close intents, the open generation and\n * the intent-aware `requestOpen` / `requestClose`, and `notifyClosed` for facts.\n */\nexport function useOverlayRoot<\n Details extends ActionDetails,\n Popup extends HTMLElement = HTMLElement,\n CloseArgs extends unknown[] = [],\n>(options: UseOverlayRootOptions<Details, Popup, CloseArgs>): OverlayRootValue<Popup, CloseArgs> {\n const {\n component,\n part,\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n details,\n onDispatch,\n } = options;\n\n // Mode is decided once, from the first render's props (design 2).\n const isLibraryNow =\n options.mode === \"library\" ||\n open !== undefined ||\n defaultOpen !== undefined ||\n openChangeAction !== undefined ||\n onOpenChange !== undefined;\n const [mode] = useState<OverlayMode>(isLibraryNow ? \"library\" : \"static\");\n const isLibrary = mode === \"library\";\n useDevWarning(\n isLibrary !== isLibraryNow,\n isDev &&\n `${part}: the mode changed after mount (\\`open\\`, \\`defaultOpen\\`, \\`openChangeAction\\` ` +\n \"and `onOpenChange` were all absent on one render and present on another). Switching \" +\n \"between JS-free and library mode is not supported.\",\n );\n // W1 (overlay-open-change.md 9): React's `value` without `onChange`. Static only: a handler\n // that adopts late (in a transition, after an `await`) cannot be told from an intentional\n // re-open, so nothing at runtime warns.\n const noun = nouns[component] ?? component;\n useDevWarning(\n isLibrary && open !== undefined && onOpenChange === undefined,\n isDev &&\n `${part}: \\`open\\` is set without \\`onOpenChange\\`. The browser can close this ${noun} ` +\n \"without asking (Escape, a click outside), and `onOpenChange` is where a controlled Root \" +\n `is told. Without it the ${noun} re-opens after every dismissal. Pass ` +\n \"`onOpenChange={setOpen}`, or `onOpenChange={() => {}}` if re-opening is what you want.\",\n );\n\n // Hooks cannot be conditional: JS-free mode calls the hook too and never dispatches.\n const { committed, optimistic, pending, dispatch, latestInFlight, adoptFact, epoch } =\n useControllableAction<boolean, Details>({\n controlled: isLibrary ? open : undefined,\n defaultValue: isLibrary ? defaultOpen : undefined,\n initialValue: false,\n action: isLibrary ? openChangeAction : undefined,\n transitionTypes: (next) => transitionTypes(component, next ? \"open\" : \"close\"),\n warn: { component: part, prop: \"open\" },\n });\n\n const id = useId();\n const triggerRef = useRef<HTMLElement | null>(null);\n const popupRef = useRef<Popup | null>(null);\n const closeIntent = useRef<OverlayCloseIntent | undefined>(undefined);\n\n // The optimistic value of the last commit, for callers that run after an `await` (a Close\n // action's continuation) and would otherwise read the value of the render they were created in.\n // An insertion effect runs in the mutation phase, before any layout effect of the same commit\n // (a child's included), so `intended()` is current there too.\n const committedOptimistic = useLatest(optimistic);\n // `details`, `onDispatch` and `isShown` are usually inline functions: read the committed render's\n // through a ref so that the functions below, and with them the returned value, stay stable.\n const callbacks = useLatest({ details, onDispatch, onOpenChange, isShown: options.isShown });\n const generation = useRef(0);\n const openGeneration = useCallback(() => generation.current, []);\n const nextOpenGeneration = useCallback(() => {\n generation.current++;\n }, []);\n\n const recordCloseIntent = useCallback(\n (intent: OverlayCloseIntent | undefined, options?: { readonly unlessRecorded?: boolean }) => {\n if (options?.unlessRecorded === true && closeIntent.current !== undefined) return;\n closeIntent.current = intent;\n if (intent !== undefined) {\n clearLater(closeIntent, intent, popupRef, callbacks.current.isShown ?? isPopoverOpen);\n }\n },\n [callbacks],\n );\n const takeCloseIntent = useCallback(() => {\n const intent = closeIntent.current;\n closeIntent.current = undefined;\n return intent;\n }, []);\n\n // Conventions 3.8 rule 1: judge no-ops against what the user already intends. That also\n // deduplicates the StrictMode re-run of the mount reconciliation and recognises the library's\n // own `hidePopover()` echoing back through `toggle`.\n const intended = useCallback(\n (): boolean => latestInFlight()?.next ?? committedOptimistic.current,\n [latestInFlight, committedOptimistic],\n );\n\n const send = useCallback(\n (next: boolean, event: Event | undefined, reason: ChangeReason, args: CloseArgs | []): void => {\n const { details, onDispatch } = callbacks.current;\n const built = details(event, reason, ...args);\n if (next) nextOpenGeneration();\n onDispatch?.(next, built);\n dispatch(next, built);\n },\n [callbacks, nextOpenGeneration, dispatch],\n );\n\n const requestOpen = useCallback(\n (event: Event | undefined, reason: ChangeReason): void => {\n if (!isLibrary || intended()) return;\n send(true, event, reason, []);\n },\n [isLibrary, intended, send],\n );\n\n const requestClose = useCallback(\n (event: Event | undefined, reason: ChangeReason, ...args: CloseArgs): void => {\n if (!isLibrary || !intended()) return;\n send(false, event, reason, args);\n },\n [isLibrary, intended, send],\n );\n\n const [shown, setShownState] = useState(false);\n // The last value written, for handlers (`hiddenBeforeToggle`).\n const shownNow = useRef(false);\n const setShown = useCallback((next: boolean) => {\n shownNow.current = next;\n setShownState(next);\n }, []);\n const hiddenBeforeToggle = useCallback((): boolean => {\n const popup = popupRef.current;\n return (\n shownNow.current && popup !== null && !(callbacks.current.isShown ?? isPopoverOpen)(popup)\n );\n }, [callbacks]);\n\n const notifyClosed = useCallback(\n (event: Event | undefined, reason: ChangeReason, ...args: CloseArgs): void => {\n if (!isLibrary) return;\n const { details, onDispatch, onOpenChange } = callbacks.current;\n const built = details(event, reason, ...args);\n onDispatch?.(false, built);\n // Supersede the requests in flight and write committed `false` (urgent), then tell the\n // consumer; both in the platform event, so one discrete commit follows (design 2.3).\n adoptFact(false);\n callUrgentHandler(onOpenChange, false, built);\n },\n [isLibrary, callbacks, adoptFact],\n );\n\n const ids = useMemo(\n () => ({ popup: id, title: `${id}-title`, description: `${id}-description` }),\n [id],\n );\n\n // Memoised: every function above is stable, so the value changes only with the open state and\n // pending, and the components' context values built on it are reused otherwise.\n return useMemo(\n () => ({\n mode,\n ids,\n committed: isLibrary && committed,\n optimistic: isLibrary && optimistic,\n shown,\n setShown,\n pending: isLibrary && pending,\n epoch,\n intended,\n openGeneration,\n nextOpenGeneration,\n requestOpen,\n requestClose,\n notifyClosed,\n latestInFlight,\n hiddenBeforeToggle,\n triggerRef,\n popupRef,\n recordCloseIntent,\n takeCloseIntent,\n }),\n [\n mode,\n ids,\n isLibrary,\n committed,\n optimistic,\n shown,\n setShown,\n pending,\n epoch,\n intended,\n openGeneration,\n nextOpenGeneration,\n requestOpen,\n requestClose,\n notifyClosed,\n latestInFlight,\n hiddenBeforeToggle,\n recordCloseIntent,\n takeCloseIntent,\n ],\n );\n}\n"],"mappings":";;;;;;;;;;AAYA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAqKvC,SAAS,WACP,WACA,QACA,UACA,SACM;CACN,iBAAiB;EAGf,MAAM,QAAQ,SAAS;EACvB,IAAI,UAAU,YAAY,UAAU,UAAU,QAAQ,QAAQ,KAAK,GACjE,UAAU,UAAU,KAAA;CAExB,GAAG,CAAC;AACN;;AAGA,MAAM,QAAgC,EAAE,UAAU,UAAU;;AAG5D,MAAa,kBAAkB,OAA0B,WACvD,oBAAoB,OAAO,EAAE,OAAO,CAAC;;;;;;AAOvC,SAAgB,eAId,SAA+F;CAC/F,MAAM,EACJ,WACA,MACA,MACA,aACA,kBACA,cACA,SACA,eACE;CAGJ,MAAM,eACJ,QAAQ,SAAS,aACjB,SAAS,KAAA,KACT,gBAAgB,KAAA,KAChB,qBAAqB,KAAA,KACrB,iBAAiB,KAAA;CACnB,MAAM,CAAC,QAAQ,SAAsB,eAAe,YAAY,QAAQ;CACxE,MAAM,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AAkB,cAAc,OAAO,KAAK;CAC9C,GACA;EAAC;EAAW;EAAW;CAAS,CAClC;CAEA,MAAM,MAAM,eACH;EAAE,OAAO;EAAI,OAAO,GAAG,GAAG;EAAS,aAAa,GAAG,GAAG;CAAc,IAC3E,CAAC,EAAE,CACL;CAIA,OAAO,eACE;EACL;EACA;EACA,WAAW,aAAa;EACxB,YAAY,aAAa;EACzB;EACA;EACA,SAAS,aAAa;EACtB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,IACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-popover-popup.mjs","names":[],"sources":["../../src/internal/use-popover-popup.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffectEvent, useLayoutEffect, useRef } from \"react\";\nimport type { ReactNode, RefObject, ViewTransitionClass } from \"react\";\nimport { useContentFocusProbe } from \"./content-focus-probe.js\";\nimport { withCssTransitionCut } from \"./css-transition-cut.js\";\nimport { closedByPopoverTarget } from \"./invokers.js\";\nimport { supportsFocusVisibleOption } from \"./focus-visible.js\";\nimport type { QuietFocusTarget } from \"./focus-visible.js\";\nimport {\n commandOf,\n renderOverlayContent,\n resolveInitialFocus,\n returnFocusToTrigger,\n useCloseHold,\n useInitialFocusTarget,\n} from \"./overlay-popup.js\";\nimport { isPopoverOpen } from \"./popover-open.js\";\nimport { useElementCheck } from \"./use-element-check.js\";\nimport { useInterestDismiss } from \"./use-interest-dismiss.js\";\nimport { useLatest } from \"./use-latest.js\";\nimport { useShownNameWarning } from \"./use-name-warning.js\";\nimport type { PopoverRootValue } from \"./use-overlay-root.js\";\n\nexport interface UsePopoverPopupOptions {\n /** Public name of the part for development warnings (`\"Popover.Popup\"`). */\n readonly part: string;\n /** Element to focus on open: a ref, or a selector resolved inside the popup (design 6.1). */\n readonly initialFocus?: RefObject<HTMLElement | null> | string | undefined;\n /**\n * Replaces `initialFocus` with a function called right before each library open (Menu: the\n * first or last item by open cause). `null` leaves the choice to the platform. A\n * `QuietFocusTarget` asks for focus without the focus ring (a pointer-opened menu).\n */\n readonly resolveInitialFocus?: (popup: HTMLElement) => HTMLElement | QuietFocusTarget | null;\n /** The consumer's `keepMounted`: `renderContent` keeps the children in an `<Activity>`. */\n readonly keepMounted?: boolean | undefined;\n /** The consumer's `transition`; decides how a library-driven close keeps its content (4.4). */\n readonly transition: ViewTransitionClass | undefined;\n /**\n * Installs listeners that live while the popup is shown (Menu: the outside right-click\n * listeners; Menu and Combobox: the foreign invoker press guard) and returns their cleanup.\n * Called at the `toggle` that finds the popup shown, and again when the ref attaches to a\n * shown popup; the cleanup runs at the `toggle` of the close and when the element detaches.\n */\n readonly whileShown?: ((popup: HTMLElement) => () => void) | undefined;\n /**\n * The `source` of each library `showPopover({ source })`, read right before the call. Default:\n * the registered Trigger. Menu passes the ContextTrigger region for a point open\n * (design/components/context-menu.md 14).\n */\n readonly source?: () => HTMLElement | null;\n}\n\nexport interface PopoverPopupHook {\n /** Callback ref for the popup element; pass as `useRender`'s `ref`. */\n readonly setElement: (element: HTMLElement) => () => void;\n /**\n * Whether the children are shown: committed open, or held while the hide animates (4.4).\n * Library mode only; JS-free mode always renders them.\n */\n readonly visible: boolean;\n /**\n * The popup's children by mode, `visible` and `keepMounted` (`renderOverlayContent`), inside\n * the focus probe: when a close commit unmounts the content while it holds focus (a\n * library-driven close with `transition`), the hide that follows returns focus to the Trigger\n * (design 6.2).\n */\n readonly renderContent: (children: () => ReactNode) => ReactNode;\n /**\n * Re-shows a shown popup in place (`hidePopover()` + `showPopover({ source })` under the\n * opening flag, initial focus resolved again): Menu's move to a new point\n * (design/components/context-menu.md 4.3). The platform coalesces the two toggles into one\n * `toggle` (`open` to `open`), so nothing is dispatched. No-op (`false`) when the popup is not\n * shown.\n */\n readonly reshow: () => boolean;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** The popup roles that require a name (a listbox's name is checked on the List). */\nfunction needsName(element: Element): boolean {\n const role = element.getAttribute(\"role\");\n return role === \"dialog\" || role === \"alertdialog\" || role === \"menu\";\n}\n\n/** Whether `element` sits inside a popover that is not shown (an outer popup that closed). */\nfunction insideHiddenPopover(element: Element): boolean {\n for (let node = element.parentElement; node !== null; node = node.parentElement) {\n if (node.hasAttribute(\"popover\") && !isPopoverOpen(node)) return true;\n }\n return false;\n}\n\n/**\n * Everything in a popover-like Popup except rendering (design/components/popover.md 14.2): mount\n * reconciliation, the apply effect, the native `beforetoggle` / `toggle` / `command` listeners\n * (and `interest` / `loseinterest`), close intents, the focus-return fallback, the JS-free\n * `data-open` sync, the deferred unmount while a hide animates, and `initialFocus`. Shared by\n * Popover, Menu and Combobox.\n */\nexport function usePopoverPopup(\n ctx: PopoverRootValue,\n options: UsePopoverPopupOptions,\n): PopoverPopupHook {\n const { part, initialFocus, transition } = options;\n const isLibrary = ctx.mode === \"library\";\n // The library's own shows and hides cut the popup's CSS transitions while a view transition\n // runs (conventions 5.1).\n const hasTransition = transition !== undefined;\n const { popupRef, triggerRef, setShown } = ctx;\n\n // The opening `beforetoggle` lets this one through: the library's own `showPopover()`.\n const opening = useRef(false);\n // Set across `reshow()`: the show is not a new open.\n const reshowing = useRef(false);\n // Set by the synchronous `beforetoggle` of a close, cleared by `toggle` a task later: the\n // popup is hidden but its `toggle` has not arrived, so the apply effect must not re-open it\n // from a commit that lands in between (design 2.5).\n const awaitingClose = useRef(false);\n // Set right before the library's own `hidePopover()` (the apply effect), consumed by the next\n // `toggle`: that hide is the library's, every other is a fact (overlay-open-change.md 2.2). The\n // echo is recognised by its source, as Dialog's `libraryClose`, not by what is intended: a\n // dismissal during a pending part close is a fact and must be reported.\n const libraryHide = useRef(false);\n // Whether focus was inside the popup when its last close began (design 6.2 rule 1).\n const focusWasInside = useRef(false);\n // Set when a fact hid the popup, cleared once a commit has `committed` false (the fact was\n // adopted): a show while it is set is the re-open of a dismissal a controlled parent refused,\n // which leaves focus where the dismissal put it (no initial focus; #155: otherwise Tab and\n // Escape could never leave a menu whose parent keeps `open={true}`).\n const refusedFact = useRef(false);\n const initialFocusTarget = useInitialFocusTarget(part, \"popup\");\n // `interestfor` (library mode, popover.md lost-interest amendment).\n const interest = useInterestDismiss(ctx);\n // The cleanup of `whileShown` while the popup is shown.\n const stopWhileShown = useRef<(() => void) | null>(null);\n const stopListeningWhileShown = (): void => {\n stopWhileShown.current?.();\n stopWhileShown.current = null;\n };\n\n // `held`: children stay mounted while the hide animates (design 4.4).\n const exit = useCloseHold(ctx.committed, isLibrary, transition);\n\n // Whether the content unmounted while holding focus since the popup was last shown.\n const contentProbe = useContentFocusProbe(popupRef);\n const { wrapContent } = contentProbe;\n\n const syncOpen = (element: HTMLElement): void => {\n // JS-free mode only (design 9): read the DOM, not `newState`, so a stale task cannot\n // lie.\n triggerRef.current?.toggleAttribute(\"data-open\", isPopoverOpen(element));\n };\n\n // Design 6.2 rule 2, for a close that began with focus inside; not to a Trigger inside a\n // hidden popover.\n const returnFocus = (element: HTMLElement): void =>\n returnFocusToTrigger(element, triggerRef.current, (trigger) => !insideHiddenPopover(trigger));\n\n // --- Opening ------------------------------------------------------------------------------\n\n // The initial focus target inside the popup, and whether it is focused without the focus ring.\n const resolveFocusTarget = (\n element: HTMLElement,\n ): { readonly target: HTMLElement; readonly quiet: boolean } | null => {\n if (options.resolveInitialFocus !== undefined) {\n const resolved = options.resolveInitialFocus(element);\n if (resolved === null) return null;\n const target = resolved instanceof HTMLElement ? resolved : resolved.element;\n if (!element.contains(target)) return null;\n // A pointer open asks for no focus ring: `focus({ focusVisible: false })` after the show,\n // where the engine reads that option (QuietFocusTarget).\n const quiet =\n !(resolved instanceof HTMLElement) && supportsFocusVisibleOption(element.ownerDocument);\n return { target, quiet };\n }\n const target = initialFocusTarget(element, initialFocus);\n return target === null ? null : { target, quiet: false };\n };\n\n const showPopup = (element: HTMLElement): void => {\n // A refused re-open never moves focus (#155, #156): no initial focus target, and the popup is\n // `inert` for the duration of the call, so the popover focusing steps find nothing focusable\n // and do nothing: neither the dialog focusing steps of a `<dialog>` (Popover's default) nor a\n // consumer's own `autofocus` in any popup. The element the dismissal focused sees no blur.\n // A consumer's own `inert` is left alone.\n const refused = refusedFact.current;\n refusedFact.current = false;\n const inerted = refused && !element.hasAttribute(\"inert\");\n if (inerted) element.setAttribute(\"inert\", \"\");\n const focus = refused ? null : resolveFocusTarget(element);\n // Otherwise the popover focusing steps honour `autofocus` (and run the dialog focusing steps\n // for a <dialog>, in every engine); React drops `autoFocus` on client-rendered content.\n // Never `.focus()` (6.1) except for the quiet target above.\n const autofocused =\n focus !== null && !focus.quiet && !focus.target.hasAttribute(\"autofocus\")\n ? focus.target\n : null;\n autofocused?.setAttribute(\"autofocus\", \"\");\n opening.current = true;\n try {\n const source = options.source !== undefined ? options.source() : triggerRef.current;\n withCssTransitionCut(element, hasTransition, () =>\n element.showPopover(source != null && source.isConnected ? { source } : undefined),\n );\n } finally {\n opening.current = false;\n autofocused?.removeAttribute(\"autofocus\");\n if (inerted) element.removeAttribute(\"inert\");\n }\n if (focus?.quiet === true && isPopoverOpen(element) && element.contains(focus.target)) {\n focus.target.focus({ focusVisible: false } as FocusOptions);\n }\n };\n\n const reshow = (): boolean => {\n const element = popupRef.current;\n if (!isLibrary || element === null || !isPopoverOpen(element)) return false;\n // The hide half's `beforetoggle` records `awaitingClose` / `focusWasInside`; the coalesced\n // `toggle` finds the popup open again, so it clears `awaitingClose`, returns no focus and\n // notifies nothing. The show half runs under `showPopup`'s opening flag (conventions 3.5, the\n // move); the hide half needs none, only an opening `beforetoggle` reads it.\n reshowing.current = true;\n try {\n // One cut around both halves (the show's own cut, nested, does nothing).\n withCssTransitionCut(element, hasTransition, () => {\n element.hidePopover();\n showPopup(element);\n });\n } finally {\n reshowing.current = false;\n }\n // Whether or not the engine fires the coalesced `toggle`, the close bookkeeping of the hide\n // half is void: the popup is open again.\n awaitingClose.current = false;\n focusWasInside.current = false;\n return isPopoverOpen(element);\n };\n\n // Mount reconciliation (design 2.4): a click before hydration opened the popover natively.\n // Runs before the apply effect; the dispatch makes the apply effect wait for it.\n const reconcileOnMount = useEffectEvent(() => {\n const element = popupRef.current;\n if (element === null) return;\n if (!isLibrary) {\n syncOpen(element);\n return;\n }\n if (isPopoverOpen(element)) ctx.requestOpen(undefined, \"platform\");\n });\n useLayoutEffect(() => {\n reconcileOnMount();\n }, []);\n\n // The apply effect (design 2.5): after every commit that re-renders the Popup, once nothing is\n // in flight, the DOM follows committed state. One effect covers the normal open, `defaultOpen`,\n // a controlled open or close, a library-driven close after `openChangeAction(false)` settled,\n // the re-open of a dismissal a controlled parent refused (in the fact's own commit, or once the\n // requests it superseded settled: overlay-open-change.md 2.4), and the close after a refused or\n // failed pre-hydration open. The Root's value is memoised, so an unrelated Root render does not\n // re-render the Popup and does not run this; every path that makes the DOM diverge from state\n // goes through a dispatch, whose `pending` flips do, or a fact, whose `epoch` does. Do not rely\n // on an unrelated render to re-apply state.\n useLayoutEffect(() => {\n if (!isLibrary) return;\n const element = popupRef.current;\n if (element === null || !element.isConnected) return;\n // The fact was adopted (or anything else closed the popup in state): a later show is a new\n // open, with initial focus.\n if (!ctx.committed) refusedFact.current = false;\n if (!ctx.pending && ctx.latestInFlight() === null) {\n const shown = isPopoverOpen(element);\n if (ctx.committed && !shown) {\n if (!awaitingClose.current) showPopup(element);\n } else if (!ctx.committed && shown) {\n // The library's own hide: the `toggle` listener recognises it by `libraryHide` and\n // reports nothing.\n ctx.recordCloseIntent(undefined);\n libraryHide.current = true;\n withCssTransitionCut(element, hasTransition, () => element.hidePopover());\n // The close commit may have unmounted the focused content before the hide: the\n // platform restores focus only from inside the popover, so do it now.\n if (focusWasInside.current) returnFocus(element);\n }\n }\n // Content that unmounted while the popup stays open (not a close): forget it.\n if (ctx.committed && isPopoverOpen(element)) contentProbe.forget();\n exit.releaseIfIdle(ctx.committed, awaitingClose.current, isPopoverOpen(element));\n });\n\n // --- Native listeners (conventions 7.4; filtered on target: React 19.3.1 emulates bubbling\n // of `toggle`, and a nested popover's events reach this element through the real DOM too) ---\n\n const onBeforeToggle = (event: Event): void => {\n const element = popupRef.current;\n if (element === null || event.target !== element) return;\n const toggle = event as ToggleEvent;\n if (toggle.newState === \"open\") {\n // Every open the library did not start itself is routed through the Root (design 2.2):\n // a foreign `show-popover` / `toggle-popover` invoker, a script `showPopover()`.\n if (isLibrary && !opening.current) {\n event.preventDefault();\n interest.noteOpen(toggle);\n ctx.requestOpen(event, \"activate\");\n } else if (!reshowing.current) {\n // A Close action that resolves after this open must not close it (design 3.4). A re-show\n // (Menu's move) is the same open: an item action pending across it still closes.\n ctx.nextOpenGeneration();\n }\n contentProbe.forget();\n } else {\n // A foreign `popovertarget` invoker closing the popup (design 2.3): `source` is the\n // button, and `null` for Escape, light dismiss and script. The library's own parts never\n // get here with a source (their clicks are cancelled; their closes are `hidePopover()`). A\n // button with `commandfor` as well runs its command, whose intent comes first and stays.\n if (isLibrary && closedByPopoverTarget(toggle, element)) {\n ctx.recordCloseIntent({ reason: \"activate\", event }, { unlessRecorded: true });\n }\n awaitingClose.current = true;\n exit.recordBaseline(element);\n const active = element.ownerDocument.activeElement;\n focusWasInside.current =\n (active !== null && element.contains(active)) || contentProbe.hadFocus();\n contentProbe.forget();\n }\n };\n\n const onToggle = (event: Event): void => {\n const element = popupRef.current;\n if (element === null || event.target !== element) return;\n awaitingClose.current = false;\n // Consumed by every `toggle`, whatever it reports: a hide the engine coalesced with a show\n // must not mark a later dismissal as the library's.\n const echo = libraryHide.current;\n libraryHide.current = false;\n const lostInterest = interest.takeLostInterest();\n // JS-free mode writes the Trigger's `data-open`; library mode mirrors into the Root, which\n // non-button Triggers and the Combobox Input render as `aria-expanded`.\n if (isLibrary) setShown(isPopoverOpen(element));\n else syncOpen(element);\n\n if (!isPopoverOpen(element)) {\n interest.noteClosed();\n // Focus return for what the platform leaves out (design 6.2): a nested popover restores\n // nothing, and an opener that is gone leaves focus inside the hidden popup. Not after a\n // lost-interest hide: the platform never focuses the invoker there, and focusing a Trigger\n // with `interestfor` would give it interest again and re-open the popup.\n const wasInside = focusWasInside.current;\n focusWasInside.current = false;\n if (wasInside && !lostInterest) returnFocus(element);\n\n const intent = ctx.takeCloseIntent();\n if (isLibrary) {\n exit.afterClose(element, echo);\n // Anything but the library's own hide is a fact: committed `false` now (urgent, this\n // event's commit) and `onOpenChange(false)` (overlay-open-change.md 2.3).\n if (!echo) {\n refusedFact.current = true;\n ctx.notifyClosed(intent?.event ?? event, intent?.reason ?? \"dismiss\");\n }\n }\n }\n const { newState } = event as ToggleEvent;\n if (newState === \"open\" && isPopoverOpen(element)) {\n stopWhileShown.current ??= options.whileShown?.(element) ?? null;\n } else if (newState === \"closed\") {\n stopListeningWhileShown();\n }\n };\n\n const onCommand = (event: Event): void => {\n const element = popupRef.current;\n if (element === null || event.target !== element || event.defaultPrevented) return;\n const command = commandOf(event);\n // A foreign `commandfor` invoker closing the popup (design 2.3). Opens are caught at\n // `beforetoggle`.\n // The `command` event fires whatever the popover's state (HTML): a `hide-popover` at a\n // hidden popup closes nothing and must leave no intent for a later close.\n if ((command === \"hide-popover\" || command === \"toggle-popover\") && isPopoverOpen(element)) {\n ctx.recordCloseIntent({ reason: \"activate\", event });\n }\n };\n\n // The listeners the callback ref attaches call the latest render's handlers. An insertion\n // effect publishes them before refs attach and before any layout effect (whose\n // `hidePopover()` dispatches `beforetoggle` synchronously).\n const handlers = useLatest({\n onBeforeToggle,\n onToggle,\n onCommand,\n onInterest: interest.onInterest,\n onLoseInterest: interest.onLoseInterest,\n });\n const latestWhileShown = useLatest(options.whileShown);\n\n // --- Element ------------------------------------------------------------------------------\n\n // The listeners attach in the callback ref, so they are in place from the commit that mounts\n // the element (no passive-effect window, no extra render). JS-free mode: there is no \"right\n // before showPopover()\" (the browser runs the command), so the `autofocus` attribute stays on\n // the `initialFocus` target while it is mounted (as Dialog).\n const checkElement = useElementCheck(\n isDev &&\n ((element) =>\n element.tagName !== \"DIALOG\" && element.tagName !== \"DIV\"\n ? `${part}: expected to render a <dialog> or a <div> but got ` +\n `<${element.tagName.toLowerCase()}>.`\n : null),\n );\n const resetInterest = interest.reset;\n const setElement = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n popupRef.current = element;\n const listeners: [string, EventListener][] = [\n [\"beforetoggle\", (event) => handlers.current.onBeforeToggle(event)],\n [\"toggle\", (event) => handlers.current.onToggle(event)],\n [\"command\", (event) => handlers.current.onCommand(event)],\n // Fired only where `interestfor` exists (Chromium).\n [\"interest\", (event) => handlers.current.onInterest(event)],\n [\"loseinterest\", (event) => handlers.current.onLoseInterest(event)],\n ];\n for (const [type, listener] of listeners) element.addEventListener(type, listener);\n // A pre-hydration open is shown from the first commit; a popup removed while open fires no\n // `toggle`, so the detach clears the mirror.\n if (isLibrary) setShown(isPopoverOpen(element));\n // The ref re-runs whenever the merged ref changes (an inline consumer `ref`), and its detach\n // stopped the listeners: a popup that is still shown gets them back, as no `toggle` comes.\n if (isPopoverOpen(element)) {\n stopWhileShown.current ??= latestWhileShown.current?.(element) ?? null;\n }\n\n let autofocused: HTMLElement | null = null;\n if (!isLibrary && initialFocus !== undefined) {\n const target = resolveInitialFocus(element, initialFocus);\n if (target !== null && element.contains(target) && !target.hasAttribute(\"autofocus\")) {\n target.setAttribute(\"autofocus\", \"\");\n autofocused = target;\n }\n }\n\n return () => {\n for (const [type, listener] of listeners) element.removeEventListener(type, listener);\n resetInterest();\n stopListeningWhileShown();\n if (isLibrary) setShown(false);\n autofocused?.removeAttribute(\"autofocus\");\n if (popupRef.current === element) popupRef.current = null;\n };\n },\n [\n checkElement,\n popupRef,\n setShown,\n handlers,\n latestWhileShown,\n isLibrary,\n initialFocus,\n resetInterest,\n ],\n );\n\n // Development check (design 9): a `dialog`, `alertdialog` or `menu` role needs a name once the\n // popup is (or can be) shown.\n useShownNameWarning(\n popupRef,\n !isLibrary || ctx.committed,\n isDev &&\n `${part}: the popup has no accessible name. Render a Title, or give the Popup an ` +\n \"`aria-label`.\",\n needsName,\n );\n\n const visible = ctx.committed || exit.held;\n const renderContent = (children: () => ReactNode): ReactNode =>\n renderOverlayContent(\n { isLibrary, keepMounted: options.keepMounted, visible, wrapContent },\n children,\n );\n return { setElement, visible, renderContent, reshow };\n}\n"],"mappings":";;;;;;;;;;;;;AA8EA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAGvC,SAAS,UAAU,SAA2B;CAC5C,MAAM,OAAO,QAAQ,aAAa,MAAM;CACxC,OAAO,SAAS,YAAY,SAAS,iBAAiB,SAAS;AACjE;;AAGA,SAAS,oBAAoB,SAA2B;CACtD,KAAK,IAAI,OAAO,QAAQ,eAAe,SAAS,MAAM,OAAO,KAAK,eAChE,IAAI,KAAK,aAAa,SAAS,KAAK,CAAC,cAAc,IAAI,GAAG,OAAO;CAEnE,OAAO;AACT;;;;;;;;AASA,SAAgB,gBACd,KACA,SACkB;CAClB,MAAM,EAAE,MAAM,cAAc,eAAe;CAC3C,MAAM,YAAY,IAAI,SAAS;CAG/B,MAAM,gBAAgB,eAAe,KAAA;CACrC,MAAM,EAAE,UAAU,YAAY,aAAa;CAG3C,MAAM,UAAU,OAAO,KAAK;CAE5B,MAAM,YAAY,OAAO,KAAK;CAI9B,MAAM,gBAAgB,OAAO,KAAK;CAKlC,MAAM,cAAc,OAAO,KAAK;CAEhC,MAAM,iBAAiB,OAAO,KAAK;CAKnC,MAAM,cAAc,OAAO,KAAK;CAChC,MAAM,qBAAqB,sBAAsB,MAAM,OAAO;CAE9D,MAAM,WAAW,mBAAmB,GAAG;CAEvC,MAAM,iBAAiB,OAA4B,IAAI;CACvD,MAAM,gCAAsC;EAC1C,eAAe,UAAU;EACzB,eAAe,UAAU;CAC3B;CAGA,MAAM,OAAO,aAAa,IAAI,WAAW,WAAW,UAAU;CAG9D,MAAM,eAAe,qBAAqB,QAAQ;CAClD,MAAM,EAAE,gBAAgB;CAExB,MAAM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C;EAG9C,IAAI,cAAc,OAAO,GACvB,eAAe,YAAY,iBAAiB,UAAU,OAAO,KAAK;EAGpE,IAAI,cAAkC;EACtC,IAAI,CAAC,aAAa,iBAAiB,KAAA,GAAW;GAC5C,MAAM,SAAS,oBAAoB,SAAS,YAAY;GACxD,IAAI,WAAW,QAAQ,QAAQ,SAAS,MAAM,KAAK,CAAC,OAAO,aAAa,WAAW,GAAG;IACpF,OAAO,aAAa,aAAa,EAAE;IACnC,cAAc;GAChB;EACF;EAEA,aAAa;GACX,KAAK,MAAM,CAAC,MAAM,aAAa,WAAW,QAAQ,oBAAoB,MAAM,QAAQ;GACpF,cAAc;GACd,wBAAwB;GACxB,IAAI,WAAW,SAAS,KAAK;GAC7B,aAAa,gBAAgB,WAAW;GACxC,IAAI,SAAS,YAAY,SAAS,SAAS,UAAU;EACvD;CACF,GACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CAIA,oBACE,UACA,CAAC,aAAa,IAAI,WAClB,SACE,GAAG,KAAK,2FAEV,SACF;CAEA,MAAM,UAAU,IAAI,aAAa,KAAK;CACtC,MAAM,iBAAiB,aACrB,qBACE;EAAE;EAAW,aAAa,QAAQ;EAAa;EAAS;CAAY,GACpE,QACF;CACF,OAAO;EAAE;EAAY;EAAS;EAAe;CAAO;AACtD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-popover-trigger.d.mts","names":[],"sources":["../../src/internal/use-popover-trigger.ts"],"mappings":";;;;;;iBA8CiB;;WAEN;;WAEA;;WAEA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-popover-trigger.mjs","names":[],"sources":["../../src/internal/use-popover-trigger.ts"],"sourcesContent":["\"use client\";\nimport { useCallback } from \"react\";\nimport type { ComponentPropsWithRef, DOMAttributes, MouseEvent } from \"react\";\nimport { dataAttr } from \"./data-attr.js\";\nimport { isPopoverOpen } from \"./popover-open.js\";\nimport { registerTrigger } from \"./trigger-ref.js\";\nimport type { RenderProp } from \"./types.js\";\nimport { useElementCheck } from \"./use-element-check.js\";\nimport { disabledButton, rendersButton } from \"./use-render.js\";\nimport type { DataAttributes } from \"./use-render.js\";\nimport type { PopoverRootValue } from \"./use-overlay-root.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * Owned and never written on an overlay Trigger (Popover, Menu, Combobox): the default\n * `popovertarget` action, which a render element must not change, and an Invoker Command, which\n * would take precedence over `popovertarget` and act on another element.\n */\nexport const RESERVED_INVOKER_KEYS = {\n popoverTargetAction: undefined,\n commandfor: undefined,\n command: undefined,\n} as const;\n\n/**\n * The library-mode dev warning for a Trigger rendered as another element than a `<button>`: only\n * an invoker button is spared by the popover's light dismiss, so a press while the popup is open\n * hides it before the click. `popover` and `popup` are the nouns the text uses for it.\n */\nexport function nonInvokerMessage(\n part: string,\n tag: string,\n popover: string,\n popup: string,\n): string {\n return (\n `${part}: rendered a <${tag}>. Only a <button> is the ${popover}'s invoker: a press on ` +\n `this element while the ${popup} is open closes it through light dismiss before the ` +\n \"click, so the close is a dismissal (reported to onOpenChange) rather than a request: \" +\n \"openChangeAction(false) is not called, cannot veto it and there is no view transition. \" +\n \"Render a <button>.\"\n );\n}\n\n/** The state of an overlay Trigger (Popover.Trigger, Menu.Trigger and its siblings). */\nexport interface PopoverTriggerHookState {\n /** Optimistic open state. A Popover in JS-free mode (the browser owns it) reports `false`. */\n readonly open: boolean;\n /** The Root's transition is pending: an open or a part-initiated close (never a dismissal). */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/** Event handlers a component layers onto the Trigger's own (Menu's keys and hover intent). */\nexport type PopoverTriggerHandlers = Pick<\n DOMAttributes<HTMLButtonElement>,\n \"onClick\" | \"onKeyDown\" | \"onMouseDown\" | \"onPointerMove\" | \"onPointerEnter\" | \"onPointerLeave\"\n>;\n\nexport interface UsePopoverTriggerOptions<State> {\n /** Public name of the part for development warnings (`\"Popover.Trigger\"`). */\n readonly part: string;\n readonly disabled: boolean;\n readonly render: RenderProp<ComponentPropsWithRef<\"button\">, State> | undefined;\n /**\n * Extra handlers, merged in front of the Trigger's own: for a key both define, the extra one\n * runs first (the consumer's pass-through handler still runs before both, conventions 1.2).\n */\n readonly handlers?: PopoverTriggerHandlers;\n /**\n * What a click does in library mode, after the command has been cancelled and `disabled`\n * checked, replacing the default toggle against `intended()` (`requestOpen` / `requestClose`).\n * Menu's SubmenuTrigger opens, or moves focus into an already open submenu, and never closes;\n * so with `activate` the library-mode non-button warning says a press while open dismisses the\n * popup instead of moving focus into it.\n */\n readonly activate?: (event: MouseEvent<HTMLElement>) => void;\n /** Runs right before the default toggle's `requestOpen` (Menu.Trigger: the open cause). */\n readonly beforeOpen?: (event: MouseEvent<HTMLElement>) => void;\n /**\n * How `disabled` is rendered. `\"native\"` (default): the `disabled` attribute, so the button is\n * no invoker at all; in library mode a link or component `render` still gets the `\"aria\"`\n * branch, because native `disabled` means nothing on a link and the installed click handler is\n * what refuses. `\"aria\"`: `aria-disabled=\"true\"` and no `disabled` (a menu item stays\n * focusable); the click handler still refuses.\n */\n readonly disabledAs?: \"native\" | \"aria\";\n}\n\nexport interface PopoverTriggerHook {\n readonly state: PopoverTriggerHookState;\n /** Owned props (conventions 1.2) for `useRender`'s `libraryProps`. */\n readonly libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes;\n /** Registers the element as the Root's Trigger; pass as `useRender`'s `ref`. */\n readonly ref: (element: HTMLElement) => () => void;\n}\n\n/**\n * The Trigger of a popover-like component (design/components/popover.md 14.3):\n * `button[popoverTarget]`, with no `aria-expanded` on an invoker: every engine exposes the\n * popover's shown state from the invoker relationship. In JS-free mode the browser toggles\n * the popover and the Popup keeps `data-open` current on the element. In library mode the click\n * is cancelled (so the activation does not run) and toggles against what the user already\n * intends: an open through `requestOpen`, a library-owned close through `requestClose`. There\n * `data-open` and `state.open` are optimistic; a non-button `render` (no invoker) renders\n * `aria-expanded` from whether the popup is shown (in the top layer).\n *\n * Menu adds `aria-haspopup=\"menu\"` and its own key handling on top.\n */\nexport function usePopoverTrigger<State>(\n ctx: PopoverRootValue,\n options: UsePopoverTriggerOptions<State>,\n): PopoverTriggerHook {\n const { part, disabled, render, handlers, activate, beforeOpen, disabledAs = \"native\" } = options;\n const isLibrary = ctx.mode === \"library\";\n const { ids, triggerRef, popupRef } = ctx;\n\n const state: PopoverTriggerHookState = {\n open: ctx.optimistic,\n // Opens and part-initiated closes belong to the Trigger (4.2); a dismissal is a fact and\n // pends nothing (overlay-open-change.md 2.7).\n pending: ctx.pending,\n disabled,\n };\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) => {\n if (element.tagName === \"BUTTON\") return null;\n const tag = element.tagName.toLowerCase();\n // Library mode: the click handler works, but only an invoker button is spared by the\n // popover's light dismiss, so a press while open hides the popup before the click.\n if (isLibrary && activate !== undefined) {\n return (\n `${part}: rendered a <${tag}>. Only a <button> is the popover's invoker: a press on ` +\n \"this element while its popup is open dismisses the popup through light dismiss \" +\n \"instead of moving focus into it. Render a <button>.\"\n );\n }\n return isLibrary\n ? nonInvokerMessage(part, tag, \"popover\", \"popup\")\n : `${part}: rendered a <${tag}> in JS-free mode. Only a <button> is a ` +\n \"`popovertarget` invoker; this trigger will not open the popover. Render a \" +\n \"<button>, or put the component in library mode (`defaultOpen={false}`).\";\n }),\n );\n const ref = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n const unregister = registerTrigger(triggerRef, element, part);\n // JS-free mode: the DOM owns `data-open` (design 9). A Trigger that mounts after the\n // Popup (or is re-created) picks up the current state here.\n if (!isLibrary && popupRef.current !== null) {\n element.toggleAttribute(\"data-open\", isPopoverOpen(popupRef.current));\n }\n return unregister;\n },\n [isLibrary, checkElement, triggerRef, popupRef, part],\n );\n\n const onClick = (event: MouseEvent<HTMLElement>) => {\n // Cancelling the click cancels the popover toggle (it runs as the button's activation\n // behaviour, only if the click was not cancelled). Enter and Space synthesise the same click.\n event.preventDefault();\n if (disabled) return;\n if (activate !== undefined) {\n activate(event);\n return;\n }\n const native = event.nativeEvent;\n if (ctx.intended()) {\n if (ctx.hiddenBeforeToggle()) {\n // A non-button Trigger (#115): light dismiss hid the popup at `pointerup`, before this\n // click. The hide is a fact, reported by its pending `toggle`; this click only names its\n // cause (overlay-open-change.md 3.2).\n ctx.recordCloseIntent({ reason: \"activate\", event: native });\n return;\n }\n ctx.requestClose(native, \"activate\");\n } else {\n // First: what it records (Menu's open cause) must be in place before anything can show the\n // popup. Today the show waits for the apply effect, so the order is not observable.\n beforeOpen?.(event);\n ctx.requestOpen(native, \"activate\");\n }\n };\n\n // The component's handlers first, then the Trigger's (design/components/menu.md 14). The click\n // handler is only owned when installed, so a render element keeps its own `onClick` in JS-free\n // mode.\n const merged: PopoverTriggerHandlers = { ...handlers };\n if (isLibrary) {\n const extra = handlers?.onClick;\n merged.onClick =\n extra === undefined\n ? onClick\n : (event) => {\n extra(event);\n onClick(event);\n };\n }\n // The click handler is installed in library mode only; in JS-free mode the activation needs\n // native `disabled` to stop it.\n const disabledProps = disabledButton(render, disabled, {\n handlesClick: isLibrary,\n alwaysFocusable: disabledAs === \"aria\",\n });\n\n const invoker = disabledProps.invoker && rendersButton(render);\n\n const libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes = {\n // `type` only applies to a <button>; on any other element the key is not owned.\n ...(rendersButton(render) && { type: \"button\" as const }),\n // Owned: a render element must not re-enable a disabled Trigger (in JS-free mode the browser\n // would toggle the popover).\n ...disabledProps.props,\n // Only on a button (or a component, assumed to render one): another element is no invoker,\n // and the attribute would claim otherwise.\n popoverTarget: invoker ? ids.popup : undefined,\n ...RESERVED_INVOKER_KEYS,\n // No `aria-expanded` on an invoker: every engine exposes the popover's shown state from\n // `popovertarget`, and ARIA in HTML forbids the attribute there. Otherwise nothing else\n // exposes the state: library mode renders shown (the popup is in the top layer; `data-open`\n // is the optimistic one), JS-free mode cannot know it and renders \"false\".\n \"aria-expanded\": invoker ? undefined : isLibrary ? ctx.shown : false,\n ...merged,\n \"data-open\": dataAttr(state.open),\n \"data-pending\": dataAttr(state.pending),\n // Every mode: the styling hook agrees with the rendered `disabled` / `aria-disabled`\n // (conventions 1.2).\n \"data-disabled\": dataAttr(disabled),\n };\n\n return { state, libraryProps, ref };\n}\n"],"mappings":";;;;;;;;AAYA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;AAOvC,MAAa,wBAAwB;CACnC,qBAAqB,KAAA;CACrB,YAAY,KAAA;CACZ,SAAS,KAAA;AACX;;;;;;AAOA,SAAgB,kBACd,MACA,KACA,SACA,OACQ;CACR,OACE,GAAG,KAAK,gBAAgB,IAAI,4BAA4B,QAAQ,gDACtC,MAAM;AAKpC;;;;;;;;;;;;;AAoEA,SAAgB,kBACd,KACA,SACoB;CACpB,MAAM,EAAE,MAAM,UAAU,QAAQ,UAAU,UAAU,YAAY,aAAa,aAAa;CAC1F,MAAM,YAAY,IAAI,SAAS;CAC/B,MAAM,EAAE,KAAK,YAAY,aAAa;CAEtC,MAAM,QAAiC;EACrC,MAAM,IAAI;EAGV,SAAS,IAAI;EACb;CACF;CAEA,MAAM,eAAe,gBACnB,WACI,YAAY;EACZ,IAAI,QAAQ,YAAY,UAAU,OAAO;EACzC,MAAM,MAAM,QAAQ,QAAQ,YAAY;EAGxC,IAAI,aAAa,aAAa,KAAA,GAC5B,OACE,GAAG,KAAK,gBAAgB,IAAI;EAKhC,OAAO,YACH,kBAAkB,MAAM,KAAK,WAAW,OAAO,IAC/C,GAAG,KAAK,gBAAgB,IAAI;CAGlC,EACJ;CACA,MAAM,MAAM,aACT,YAAyB;EACxB,eAAe,OAAO;EACtB,MAAM,aAAa,gBAAgB,YAAY,SAAS,IAAI;EAG5D,IAAI,CAAC,aAAa,SAAS,YAAY,MACrC,QAAQ,gBAAgB,aAAa,cAAc,SAAS,OAAO,CAAC;EAEtE,OAAO;CACT,GACA;EAAC;EAAW;EAAc;EAAY;EAAU;CAAI,CACtD;CAEA,MAAM,WAAW,UAAmC;EAGlD,MAAM,eAAe;EACrB,IAAI,UAAU;EACd,IAAI,aAAa,KAAA,GAAW;GAC1B,SAAS,KAAK;GACd;EACF;EACA,MAAM,SAAS,MAAM;EACrB,IAAI,IAAI,SAAS,GAAG;GAClB,IAAI,IAAI,mBAAmB,GAAG;IAI5B,IAAI,kBAAkB;KAAE,QAAQ;KAAY,OAAO;IAAO,CAAC;IAC3D;GACF;GACA,IAAI,aAAa,QAAQ,UAAU;EACrC,OAAO;GAGL,aAAa,KAAK;GAClB,IAAI,YAAY,QAAQ,UAAU;EACpC;CACF;CAKA,MAAM,SAAiC,EAAE,GAAG,SAAS;CACrD,IAAI,WAAW;EACb,MAAM,QAAQ,UAAU;EACxB,OAAO,UACL,UAAU,KAAA,IACN,WACC,UAAU;GACT,MAAM,KAAK;GACX,QAAQ,KAAK;EACf;CACR;CAGA,MAAM,gBAAgB,eAAe,QAAQ,UAAU;EACrD,cAAc;EACd,iBAAiB,eAAe;CAClC,CAAC;CAED,MAAM,UAAU,cAAc,WAAW,cAAc,MAAM;CAyB7D,OAAO;EAAE;EAAO,cAAA;GArBd,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;GAGvD,GAAG,cAAc;GAGjB,eAAe,UAAU,IAAI,QAAQ,KAAA;GACrC,GAAG;GAKH,iBAAiB,UAAU,KAAA,IAAY,YAAY,IAAI,QAAQ;GAC/D,GAAG;GACH,aAAa,SAAS,MAAM,IAAI;GAChC,gBAAgB,SAAS,MAAM,OAAO;GAGtC,iBAAiB,SAAS,QAAQ;EAGT;EAAG;CAAI;AACpC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-resolved-placement.mjs","names":[],"sources":["../../src/internal/use-resolved-placement.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useLayoutEffect, useRef, useState } from \"react\";\nimport type { CSSProperties, RefCallback } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { parsePositionArea, POSITION_TRY_FALLBACKS, positionArea } from \"./anchor-position.js\";\nimport type {\n AnchorAlign,\n AnchorSide,\n Direction,\n PhysicalSide,\n ResolvedPlacement,\n} from \"./anchor-position.js\";\nimport { isPopoverOpen } from \"./popover-open.js\";\nimport { resolveStateValue } from \"./render-element.js\";\nimport type { DataAttributes } from \"./render-element.js\";\nimport type { StateValue } from \"./types.js\";\n\nexport interface PlacementRequest<Side extends AnchorSide> {\n /** The requested side; `null` when the stylesheet owns placement (the hook is idle). */\n readonly side: Side | null;\n readonly align: AnchorAlign;\n}\n\nexport interface PlacementResult<Side extends AnchorSide> {\n /** The resolved physical side while the popup is shown, else the requested side. */\n readonly side: Side | PhysicalSide | null;\n /** The resolved alignment while shown, else the requested one. */\n readonly align: AnchorAlign;\n /** Merge into the popup element's ref. Stable. */\n readonly ref: RefCallback<HTMLElement>;\n}\n\nconst toDirection = (value: string): Direction => (value === \"rtl\" ? \"rtl\" : \"ltr\");\n\n/**\n * Where the browser actually placed an anchored popup (design/conventions.md 13.2): the\n * `position-try-fallbacks` option it applied, read from the computed `position-area` while the\n * popup is shown. Observation only; runs whatever opened the popup (`interestfor`, `popovertarget` and\n * `commandfor` included). Read on a `ResizeObserver` (hidden to shown is a resize, delivered\n * before paint), `toggle`, and while shown document `scroll` and window `resize` plus the next\n * two frames. Written urgently (`flushSync`), and only when the rendered pair changes: an open\n * where it was asked costs no render. Hidden again, it resets once the popup no longer renders\n * (an exit animation keeps the resolved side). Idle with `side: null`.\n */\nexport function useResolvedPlacement<Side extends AnchorSide>(\n request: PlacementRequest<Side>,\n): PlacementResult<Side> {\n const { side, align } = request;\n const [resolved, setResolved] = useState<ResolvedPlacement | null>(null);\n // What the state holds (or is about to hold), so an unchanged read schedules nothing.\n const written = useRef<ResolvedPlacement | null>(null);\n // The request the element is rendered with (kept by the layout effect below).\n const requested = useRef<PlacementRequest<Side>>(request);\n // The mounted element's read, for the layout effect below.\n const sync = useRef<((urgent: boolean) => void) | null>(null);\n\n const ref = useCallback((element: HTMLElement | null) => {\n if (element === null) return;\n const doc = element.ownerDocument;\n const win = doc.defaultView ?? window;\n\n const write = (value: ResolvedPlacement | null, urgent: boolean) => {\n // Where it was asked to be: the requested values say so already, no state needed.\n const next =\n value !== null &&\n value.side === requested.current.side &&\n value.align === requested.current.align\n ? null\n : value;\n const previous = written.current;\n if (\n previous === next ||\n (previous !== null &&\n next !== null &&\n previous.side === next.side &&\n previous.align === next.align)\n ) {\n return;\n }\n written.current = next;\n if (urgent) flushSync(() => setResolved(next));\n else setResolved(next);\n };\n\n let listening = false;\n const listen = (on: boolean) => {\n if (on === listening) return;\n listening = on;\n if (on) {\n doc.addEventListener(\"scroll\", onMove, { capture: true, passive: true });\n win.addEventListener(\"resize\", onMove);\n } else {\n doc.removeEventListener(\"scroll\", onMove, { capture: true });\n win.removeEventListener(\"resize\", onMove);\n cancelFrames();\n }\n };\n\n // Both engines (Chromium 156, Firefox 157) apply the scroll-dependent anchoring state, the\n // option and the scroll-compensated geometry alike, in the layout of the frame after the\n // `scroll` event: a read in the handler, or in a rAF registered from it (which runs before\n // that layout), sees the old option even after a forced layout. The timing is unspecified\n // (css-anchor-position-1 §3.3 issue), so read again in the next two frames; a scroll that\n // arrives while that is pending restarts it at the end, so the last scroll is always followed.\n // Separately, Chromium 156 keeps an overflowing option for a top-layer popover once the first\n // frames after the show have passed (a bug, §6.5; upstream item #92): then no frame reads a\n // new option, and `data-side` correctly keeps reporting the applied one. Do not drop the\n // frame reads \"because Chromium does not re-choose\": when it does, it lags like Firefox.\n let frame = 0;\n let again = false;\n const cancelFrames = () => {\n if (frame !== 0) win.cancelAnimationFrame(frame);\n frame = 0;\n again = false;\n };\n const readLater = () => {\n if (frame !== 0) {\n again = true;\n return;\n }\n frame = win.requestAnimationFrame(() => {\n read(true);\n // The popup was found hidden (or `side` turned null): `listen(false)` ended the pair.\n if (!listening) return;\n frame = win.requestAnimationFrame(() => {\n frame = 0;\n read(true);\n if (again && listening) {\n again = false;\n readLater();\n }\n });\n });\n };\n\n const read = (urgent: boolean) => {\n if (requested.current.side === null) {\n listen(false);\n write(null, urgent);\n return;\n }\n if (element.isConnected && isPopoverOpen(element)) {\n listen(true);\n const style = getComputedStyle(element);\n const placement = parsePositionArea(\n style.positionArea,\n toDirection(style.direction),\n () => toDirection(getComputedStyle(doc.documentElement).direction),\n style.writingMode || \"horizontal-tb\",\n );\n write(placement, urgent);\n return;\n }\n listen(false);\n // Hidden, but still rendered while an exit animation runs: keep the resolved side to the\n // end of it. The ResizeObserver sees the box go and resets then.\n // Nothing written, nothing to reset: skip the forced layout (every mount and request change\n // of a hidden popup comes through here).\n if (\n written.current !== null &&\n (!element.isConnected || element.getClientRects().length === 0)\n ) {\n write(null, urgent);\n }\n };\n\n function onEvent() {\n read(true);\n }\n function onMove() {\n // In every Chromium 156 / Firefox 157 probe this read still saw the old option (see the\n // frame reads above); kept as cover for WebKit, which was not probed, at the cost of one\n // style read per scroll event.\n read(true);\n if (listening) readLater();\n }\n\n sync.current = read;\n const observer = typeof ResizeObserver === \"function\" ? new ResizeObserver(onEvent) : null;\n observer?.observe(element);\n element.addEventListener(\"toggle\", onEvent);\n return () => {\n observer?.disconnect();\n element.removeEventListener(\"toggle\", onEvent);\n listen(false);\n if (sync.current === read) sync.current = null;\n };\n }, []);\n\n // A changed request while shown places the popup differently: read again (a layout effect, so\n // the corrected attribute is in the same frame). Also how `side={null}` turns the hook off.\n useLayoutEffect(() => {\n requested.current = { side, align };\n sync.current?.(false);\n }, [side, align]);\n\n if (side === null) return { side: null, align, ref };\n return resolved === null ? { side, align, ref } : { ...resolved, ref };\n}\n\nexport interface AnchoredPlacementRequest<Side extends AnchorSide> extends PlacementRequest<Side> {\n /** `position-try-fallbacks`. Default: flip on both axes. */\n readonly fallbacks?: string;\n}\n\nexport interface AnchoredPlacement<Side extends AnchorSide> extends PlacementResult<Side> {\n /** `data-side` / `data-align` (resolved); no keys when the side is `null` (not owned then). */\n readonly dataAttributes: DataAttributes;\n /**\n * The popup's `style`: the requested inline placement (the browser keeps choosing from it)\n * under the consumer's style, so the consumer wins. The consumer's style alone for `side: null`.\n */\n readonly style: <State>(\n consumer: StateValue<CSSProperties | undefined, State>,\n ) => StateValue<CSSProperties | undefined, State>;\n}\n\n/**\n * An anchored popup's placement (Popover, Tooltip and Menu Popup): `useResolvedPlacement` plus\n * the data attributes and the inline `position-area` / `position-try-fallbacks` it renders.\n */\nexport function useAnchoredPlacement<Side extends AnchorSide>(\n request: AnchoredPlacementRequest<Side>,\n): AnchoredPlacement<Side> {\n const {\n side: requestedSide,\n align: requestedAlign,\n fallbacks = POSITION_TRY_FALLBACKS,\n } = request;\n const placement = useResolvedPlacement({ side: requestedSide, align: requestedAlign });\n const { side, align } = placement;\n const dataAttributes: DataAttributes =\n side !== null ? { \"data-side\": side, \"data-align\": align } : {};\n const style = <State>(\n consumer: StateValue<CSSProperties | undefined, State>,\n ): StateValue<CSSProperties | undefined, State> =>\n requestedSide === null\n ? consumer\n : (s: State) => ({\n positionArea: positionArea(requestedSide, requestedAlign),\n positionTryFallbacks: fallbacks,\n ...resolveStateValue(consumer, s),\n });\n return { ...placement, dataAttributes, style };\n}\n"],"mappings":";;;;;;;AAgCA,MAAM,eAAe,UAA8B,UAAU,QAAQ,QAAQ;;;;;;;;;;;AAY7E,SAAgB,qBACd,SACuB;CACvB,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,CAAC,UAAU,eAAe,SAAmC,IAAI;CAEvE,MAAM,UAAU,OAAiC,IAAI;CAErD,MAAM,YAAY,OAA+B,OAAO;CAExD,MAAM,OAAO,OAA2C,IAAI;CAE5D,MAAM,MAAM,aAAa,YAAgC;EACvD,IAAI,YAAY,MAAM;EACtB,MAAM,MAAM,QAAQ;EACpB,MAAM,MAAM,IAAI,eAAe;EAE/B,MAAM,SAAS,OAAiC,WAAoB;GAElE,MAAM,OACJ,UAAU,QACV,MAAM,SAAS,UAAU,QAAQ,QACjC,MAAM,UAAU,UAAU,QAAQ,QAC9B,OACA;GACN,MAAM,WAAW,QAAQ;GACzB,IACE,aAAa,QACZ,aAAa,QACZ,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C"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-until-found.mjs","names":[],"sources":["../../src/internal/use-until-found.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useEffectEvent, useLayoutEffect, useRef } from \"react\";\nimport type { RefObject } from \"react\";\n\nexport interface UseUntilFoundOptions {\n /**\n * The element should currently be `hidden=\"until-found\"`. The part renders a boolean `hidden`\n * itself as well, so server-rendered HTML hides it (as `hidden=\"\"`) before hydration.\n *\n * Pass `false` while a change the element itself triggered (its `beforematch`) is pending:\n * the browser has already revealed it, and re-asserting would hide it again until the commit.\n * When that change is rejected the owner's optimistic state reverts, `active` becomes `true`\n * again and the next commit re-hides it.\n */\n active: boolean;\n /** Called with the `beforematch` event when find-in-page or a text fragment reveals it. */\n onMatch: (event: Event) => void;\n}\n\n/**\n * The single home of the `hidden=\"until-found\"` workaround (conventions 7.4).\n *\n * react-dom 19.3 serialises `hidden` as a boolean attribute (`hidden=\"\"` on client and server),\n * so the part renders a boolean `hidden` and this hook upgrades the attribute to `\"until-found\"`\n * through a ref in a layout effect. The upgrade is re-asserted after **every** commit while\n * `active`: when the browser reveals the element it removes the attribute itself, and if the\n * resulting action is rejected React sees no prop change (the boolean `hidden` stayed `true`\n * throughout) and would leave the element visible.\n *\n * `beforematch` has no React prop, so a native listener is attached in an effect through the\n * returned ref (conventions 2.6, 7.4). Attach the ref to the element that renders the boolean\n * `hidden`.\n */\nexport function useUntilFound<E extends HTMLElement>(\n options: UseUntilFoundOptions,\n): RefObject<E | null> {\n const { active } = options;\n const node = useRef<E | null>(null);\n const onMatch = useEffectEvent((event: Event) => {\n options.onMatch(event);\n });\n\n // No dependency array on purpose: re-assert after every commit of the owner (see above).\n useLayoutEffect(() => {\n const element = node.current;\n if (element !== null && active && element.getAttribute(\"hidden\") !== \"until-found\") {\n element.setAttribute(\"hidden\", \"until-found\");\n }\n });\n\n // Re-subscribed after every commit so a swapped element (a changed `render`) is covered.\n useEffect(() => {\n const element = node.current;\n if (element === null) return;\n const listener = (event: Event) => onMatch(event);\n element.addEventListener(\"beforematch\", listener);\n return () => element.removeEventListener(\"beforematch\", listener);\n });\n\n return node;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiCA,SAAgB,cACd,SACqB;CACrB,MAAM,EAAE,WAAW;CACnB,MAAM,OAAO,OAAiB,IAAI;CAClC,MAAM,UAAU,gBAAgB,UAAiB;EAC/C,QAAQ,QAAQ,KAAK;CACvB,CAAC;CAGD,sBAAsB;EACpB,MAAM,UAAU,KAAK;EACrB,IAAI,YAAY,QAAQ,UAAU,QAAQ,aAAa,QAAQ,MAAM,eACnE,QAAQ,aAAa,UAAU,aAAa;CAEhD,CAAC;CAGD,gBAAgB;EACd,MAAM,UAAU,KAAK;EACrB,IAAI,YAAY,MAAM;EACtB,MAAM,YAAY,UAAiB,QAAQ,KAAK;EAChD,QAAQ,iBAAiB,eAAe,QAAQ;EAChD,aAAa,QAAQ,oBAAoB,eAAe,QAAQ;CAClE,CAAC;CAED,OAAO;AACT"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"validity.d.mts","names":[],"sources":["../../src/internal/validity.ts"],"mappings":";;YAIY;;YAGA,aAAa,SAAS,eAAe;;;;;iBAMhC;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"validity.mjs","names":[],"sources":["../../src/internal/validity.ts"],"sourcesContent":["// Directive-free helpers for Field and Form (design/components/field-form.md 2, 14): the validity\n// snapshot, error-value normalisation, the `:user-invalid` read and the element resolution.\n\n/** A field error: a message, several messages, or nothing (`\"\"`, `[]`, `null`, `undefined`). */\nexport type FieldErrorValue = string | readonly string[] | null | undefined;\n\n/** Field errors keyed by field `name` (usually `state.errors` from `useActionState`). */\nexport type FormErrors = Readonly<Record<string, FieldErrorValue>>;\n\n/**\n * A plain, serialisable snapshot of the control's `ValidityState` (all `false` and\n * `valid: true` on the server and before the first read).\n */\nexport interface FieldValidity {\n /** A required control has no value. */\n readonly valueMissing: boolean;\n /** The value does not match the `type` (email, url). */\n readonly typeMismatch: boolean;\n /** The value does not match `pattern`. */\n readonly patternMismatch: boolean;\n /** The value is longer than `maxLength`. */\n readonly tooLong: boolean;\n /** The value is shorter than `minLength`. */\n readonly tooShort: boolean;\n /** The value is below `min`. */\n readonly rangeUnderflow: boolean;\n /** The value is above `max`. */\n readonly rangeOverflow: boolean;\n /** The value is not on the `step` grid. */\n readonly stepMismatch: boolean;\n /** The browser cannot convert the input to a value. */\n readonly badInput: boolean;\n /** A custom message is set (`validate` or a shown server error). */\n readonly customError: boolean;\n /** No constraint is violated. */\n readonly valid: boolean;\n}\n\nconst VALIDITY_KEYS = [\n \"valueMissing\",\n \"typeMismatch\",\n \"patternMismatch\",\n \"tooLong\",\n \"tooShort\",\n \"rangeUnderflow\",\n \"rangeOverflow\",\n \"stepMismatch\",\n \"badInput\",\n \"customError\",\n \"valid\",\n] as const satisfies readonly (keyof FieldValidity)[];\n\nexport const VALID: FieldValidity = Object.freeze({\n valueMissing: false,\n typeMismatch: false,\n patternMismatch: false,\n tooLong: false,\n tooShort: false,\n rangeUnderflow: false,\n rangeOverflow: false,\n stepMismatch: false,\n badInput: false,\n customError: false,\n valid: true,\n});\n\nexport function snapshotValidity(validity: ValidityState): FieldValidity {\n const result = {} as Record<keyof FieldValidity, boolean>;\n for (const key of VALIDITY_KEYS) result[key] = validity[key];\n return result;\n}\n\nexport function validityEquals(a: FieldValidity, b: FieldValidity): boolean {\n return VALIDITY_KEYS.every((key) => a[key] === b[key]);\n}\n\nconst NONE: readonly string[] = Object.freeze([]);\n\n/** `\"\"`, `[]`, `null` and `undefined` mean no error; empty strings inside an array are dropped. */\nexport function normaliseErrorValue(value: FieldErrorValue): readonly string[] {\n if (value === null || value === undefined || value === \"\") return NONE;\n if (typeof value === \"string\") return [value];\n const list = value.filter((v) => typeof v === \"string\" && v !== \"\");\n return list.length === 0 ? NONE : list;\n}\n\n/** Some entry of `errors` is a non-empty error. */\nexport function hasAnyError(errors: FormErrors | undefined): boolean {\n if (errors === undefined) return false;\n return Object.values(errors).some((v) => normaliseErrorValue(v).length > 0);\n}\n\nlet userInvalidSupport: boolean | undefined;\n\n/**\n * Whether the environment implements `:user-invalid` (every engine the library supports does).\n * Decided once per module, so the read is not on a hot path.\n *\n * Detected with `CSS.supports(\"selector(:user-invalid)\")` rather than by `matches()` throwing:\n * jsdom 30's selector engine knows the name and silently answers `false` (it does not throw), and\n * its `CSS.supports` reports `false`, so the fallback engages there and nowhere else\n * (memo/developer/field-form.md).\n */\nexport function supportsUserInvalid(): boolean {\n if (userInvalidSupport === undefined) {\n try {\n userInvalidSupport =\n typeof CSS !== \"undefined\" &&\n typeof CSS.supports === \"function\" &&\n CSS.supports(\"selector(:user-invalid)\");\n } catch {\n userInvalidSupport = false;\n }\n }\n return userInvalidSupport;\n}\n\n/** An element that takes part in constraint validation. */\nexport type ValidatableElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;\n\nfunction isValidatable(el: Element): el is ValidatableElement {\n return (\n el instanceof HTMLInputElement ||\n el instanceof HTMLSelectElement ||\n el instanceof HTMLTextAreaElement\n );\n}\n\n/**\n * Where `validity`, `validationMessage`, `:user-invalid` and `setCustomValidity` are read and\n * written (design 7.1): the element itself when it is a form control, else the first named\n * `willValidate` member of a `<fieldset>` (a group's first enabled item, not a CheckboxGroup\n * Parent, which has no name), else the first `input` / `select` / `textarea` inside.\n */\nexport function validityElementOf(el: Element | null): ValidatableElement | null {\n if (el === null) return null;\n if (isValidatable(el)) return el;\n const members =\n el instanceof HTMLFieldSetElement\n ? [...el.elements]\n : [...el.querySelectorAll(\"input, select, textarea\")];\n const controls = members.filter(isValidatable);\n return (\n controls.find((c) => c.willValidate && c.name !== \"\") ??\n controls.find((c) => c.willValidate) ??\n controls[0] ??\n null\n );\n}\n\n/**\n * What the Field focuses (design 2.5): the control itself, or for a group the checked radio if\n * any, else the first enabled named member (a group's first item, not a CheckboxGroup Parent,\n * which has no name), else the first enabled member.\n */\nexport function focusTargetOf(el: Element | null): HTMLElement | null {\n if (el === null) return null;\n if (isValidatable(el)) return el;\n const members = (\n el instanceof HTMLFieldSetElement\n ? [...el.elements]\n : [...el.querySelectorAll(\"input, select, textarea, button\")]\n ).filter(\n (m): m is HTMLElement =>\n m instanceof HTMLElement &&\n !(m as HTMLInputElement).disabled &&\n (m as HTMLInputElement).type !== \"hidden\",\n );\n const checkedRadio = members.find(\n (m) => m instanceof HTMLInputElement && m.type === \"radio\" && m.checked,\n );\n return (\n checkedRadio ??\n members.find((m) => isValidatable(m) && m.name !== \"\") ??\n members.find(isValidatable) ??\n members[0] ??\n null\n );\n}\n"],"mappings":";AAsCA,MAAM,gBAAgB;CACpB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,QAAuB,OAAO,OAAO;CAChD,cAAc;CACd,cAAc;CACd,iBAAiB;CACjB,SAAS;CACT,UAAU;CACV,gBAAgB;CAChB,eAAe;CACf,cAAc;CACd,UAAU;CACV,aAAa;CACb,OAAO;AACT,CAAC;AAED,SAAgB,iBAAiB,UAAwC;CACvE,MAAM,SAAS,CAAC;CAChB,KAAK,MAAM,OAAO,eAAe,OAAO,OAAO,SAAS;CACxD,OAAO;AACT;AAEA,SAAgB,eAAe,GAAkB,GAA2B;CAC1E,OAAO,cAAc,OAAO,QAAQ,EAAE,SAAS,EAAE,IAAI;AACvD;AAEA,MAAM,OAA0B,OAAO,OAAO,CAAC,CAAC;;AAGhD,SAAgB,oBAAoB,OAA2C;CAC7E,IAAI,UAAU,QAAQ,UAAU,KAAA,KAAa,UAAU,IAAI,OAAO;CAClE,IAAI,OAAO,UAAU,UAAU,OAAO,CAAC,KAAK;CAC5C,MAAM,OAAO,MAAM,QAAQ,MAAM,OAAO,MAAM,YAAY,MAAM,EAAE;CAClE,OAAO,KAAK,WAAW,IAAI,OAAO;AACpC;;AAGA,SAAgB,YAAY,QA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