@funstack/ui 0.1.0-alpha.17 → 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 (347) 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 +35 -38
  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 +18 -11
  8. package/dist/button/button.d.mts.map +1 -1
  9. package/dist/button/button.mjs +32 -16
  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 +15 -12
  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 -161
  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/accordion.md +1 -1
  57. package/dist/docs/components/button.md +13 -10
  58. package/dist/docs/components/dialog.md +4 -4
  59. package/dist/docs/components/field.md +4 -3
  60. package/dist/docs/components/popover.md +4 -4
  61. package/dist/docs/components/toast.md +8 -5
  62. package/dist/docs/concepts/browser-owned-state.md +1 -1
  63. package/dist/docs/roadmap.md +9 -1
  64. package/dist/field/field-control.d.mts +1 -1
  65. package/dist/field/field-control.mjs +2 -2
  66. package/dist/field/field-control.mjs.map +1 -1
  67. package/dist/field/field-description.d.mts +1 -1
  68. package/dist/field/field-description.mjs +1 -1
  69. package/dist/field/field-description.mjs.map +1 -1
  70. package/dist/field/field-error.d.mts +1 -1
  71. package/dist/field/field-error.mjs +1 -1
  72. package/dist/field/field-error.mjs.map +1 -1
  73. package/dist/field/field-label.d.mts +1 -1
  74. package/dist/field/field-label.mjs +1 -1
  75. package/dist/field/field-label.mjs.map +1 -1
  76. package/dist/field/field-root.d.mts +2 -2
  77. package/dist/field/field-root.d.mts.map +1 -1
  78. package/dist/field/field-root.mjs +4 -4
  79. package/dist/field/field-root.mjs.map +1 -1
  80. package/dist/field/index.d.mts +2 -2
  81. package/dist/form/form-root.d.mts +1 -1
  82. package/dist/form/form-root.d.mts.map +1 -1
  83. package/dist/form/form-root.mjs +14 -4
  84. package/dist/form/form-root.mjs.map +1 -1
  85. package/dist/form/form-submit.d.mts +7 -3
  86. package/dist/form/form-submit.d.mts.map +1 -1
  87. package/dist/form/form-submit.mjs +11 -7
  88. package/dist/form/form-submit.mjs.map +1 -1
  89. package/dist/form/index.d.mts +1 -1
  90. package/dist/index.d.mts +2 -2
  91. package/dist/internal/{action-details.mjs → action/action-details.mjs} +1 -1
  92. package/dist/internal/action/action-details.mjs.map +1 -0
  93. package/dist/internal/{call-urgent-handler.mjs → action/call-urgent-handler.mjs} +5 -10
  94. package/dist/internal/action/call-urgent-handler.mjs.map +1 -0
  95. package/dist/internal/{report-dropped.mjs → action/report-dropped.mjs} +3 -21
  96. package/dist/internal/action/report-dropped.mjs.map +1 -0
  97. package/dist/internal/{use-action-trigger.mjs → action/use-action-trigger.mjs} +3 -2
  98. package/dist/internal/action/use-action-trigger.mjs.map +1 -0
  99. package/dist/internal/action/use-connected.mjs +24 -0
  100. package/dist/internal/action/use-connected.mjs.map +1 -0
  101. package/dist/internal/{use-controllable-action.mjs → action/use-controllable-action.mjs} +20 -32
  102. package/dist/internal/action/use-controllable-action.mjs.map +1 -0
  103. package/dist/internal/action/use-pure-trigger.mjs +34 -0
  104. package/dist/internal/action/use-pure-trigger.mjs.map +1 -0
  105. package/dist/internal/action/use-step-commit.mjs +147 -0
  106. package/dist/internal/action/use-step-commit.mjs.map +1 -0
  107. package/dist/internal/{field-context.d.mts → form/field-context.d.mts} +1 -1
  108. package/dist/internal/form/field-context.d.mts.map +1 -0
  109. package/dist/internal/{field-context.mjs → form/field-context.mjs} +2 -2
  110. package/dist/internal/form/field-context.mjs.map +1 -0
  111. package/dist/internal/{focus-first-invalid.mjs → form/focus-first-invalid.mjs} +3 -3
  112. package/dist/internal/form/focus-first-invalid.mjs.map +1 -0
  113. package/dist/internal/{form-status-watcher.mjs → form/form-status-watcher.mjs} +1 -1
  114. package/dist/internal/form/form-status-watcher.mjs.map +1 -0
  115. package/dist/internal/{group-member.mjs → form/group-member.mjs} +2 -2
  116. package/dist/internal/form/group-member.mjs.map +1 -0
  117. package/dist/internal/{sync-presence.mjs → form/sync-presence.mjs} +1 -1
  118. package/dist/internal/form/sync-presence.mjs.map +1 -0
  119. package/dist/internal/{use-checkable-input.mjs → form/use-checkable-input.mjs} +5 -5
  120. package/dist/internal/form/use-checkable-input.mjs.map +1 -0
  121. package/dist/internal/{use-field-control.mjs → form/use-field-control.mjs} +3 -3
  122. package/dist/internal/form/use-field-control.mjs.map +1 -0
  123. package/dist/internal/{use-fieldset-group.mjs → form/use-fieldset-group.mjs} +3 -3
  124. package/dist/internal/form/use-fieldset-group.mjs.map +1 -0
  125. package/dist/internal/{use-form-owner-event.mjs → form/use-form-owner-event.mjs} +1 -1
  126. package/dist/internal/form/use-form-owner-event.mjs.map +1 -0
  127. package/dist/internal/{use-form-reset.mjs → form/use-form-reset.mjs} +15 -3
  128. package/dist/internal/form/use-form-reset.mjs.map +1 -0
  129. package/dist/internal/{use-native-checked.mjs → form/use-native-checked.mjs} +5 -4
  130. package/dist/internal/form/use-native-checked.mjs.map +1 -0
  131. package/dist/internal/{use-native-group-reconciliation.mjs → form/use-native-group-reconciliation.mjs} +8 -8
  132. package/dist/internal/form/use-native-group-reconciliation.mjs.map +1 -0
  133. package/dist/internal/{use-native-select-value.mjs → form/use-native-select-value.mjs} +2 -2
  134. package/dist/internal/form/use-native-select-value.mjs.map +1 -0
  135. package/dist/internal/{validity.d.mts → form/validity.d.mts} +1 -1
  136. package/dist/internal/form/validity.d.mts.map +1 -0
  137. package/dist/internal/{validity.mjs → form/validity.mjs} +1 -1
  138. package/dist/internal/form/validity.mjs.map +1 -0
  139. package/dist/internal/{anchor-position.d.mts → overlay/anchor-position.d.mts} +1 -1
  140. package/dist/internal/overlay/anchor-position.d.mts.map +1 -0
  141. package/dist/internal/{anchor-position.mjs → overlay/anchor-position.mjs} +1 -1
  142. package/dist/internal/overlay/anchor-position.mjs.map +1 -0
  143. package/dist/internal/{content-focus-probe.mjs → overlay/content-focus-probe.mjs} +1 -1
  144. package/dist/internal/overlay/content-focus-probe.mjs.map +1 -0
  145. package/dist/internal/{css-transition-cut.mjs → overlay/css-transition-cut.mjs} +1 -1
  146. package/dist/internal/overlay/css-transition-cut.mjs.map +1 -0
  147. package/dist/internal/{focus-visible.mjs → overlay/focus-visible.mjs} +1 -1
  148. package/dist/internal/overlay/focus-visible.mjs.map +1 -0
  149. package/dist/internal/{invokers.mjs → overlay/invokers.mjs} +1 -1
  150. package/dist/internal/overlay/invokers.mjs.map +1 -0
  151. package/dist/internal/{modal-registry.mjs → overlay/modal-registry.mjs} +1 -1
  152. package/dist/internal/overlay/modal-registry.mjs.map +1 -0
  153. package/dist/internal/{overlay-popup.mjs → overlay/overlay-popup.mjs} +3 -3
  154. package/dist/internal/overlay/overlay-popup.mjs.map +1 -0
  155. package/dist/internal/overlay/overlay-show.mjs +73 -0
  156. package/dist/internal/overlay/overlay-show.mjs.map +1 -0
  157. package/dist/internal/{popover-open.mjs → overlay/popover-open.mjs} +1 -1
  158. package/dist/internal/overlay/popover-open.mjs.map +1 -0
  159. package/dist/internal/{trigger-ref.mjs → overlay/trigger-ref.mjs} +1 -1
  160. package/dist/internal/overlay/trigger-ref.mjs.map +1 -0
  161. package/dist/internal/overlay/use-apply-open-state.mjs +44 -0
  162. package/dist/internal/overlay/use-apply-open-state.mjs.map +1 -0
  163. package/dist/internal/{use-exit-animation.mjs → overlay/use-exit-animation.mjs} +2 -2
  164. package/dist/internal/overlay/use-exit-animation.mjs.map +1 -0
  165. package/dist/internal/{use-interest-dismiss.mjs → overlay/use-interest-dismiss.mjs} +1 -1
  166. package/dist/internal/overlay/use-interest-dismiss.mjs.map +1 -0
  167. package/dist/internal/{use-modal-registration.mjs → overlay/use-modal-registration.mjs} +1 -1
  168. package/dist/internal/overlay/use-modal-registration.mjs.map +1 -0
  169. package/dist/internal/{use-overlay-close.mjs → overlay/use-overlay-close.mjs} +14 -13
  170. package/dist/internal/overlay/use-overlay-close.mjs.map +1 -0
  171. package/dist/internal/overlay/use-overlay-root.d.mts +2 -0
  172. package/dist/internal/{use-overlay-root.mjs → overlay/use-overlay-root.mjs} +44 -28
  173. package/dist/internal/overlay/use-overlay-root.mjs.map +1 -0
  174. package/dist/internal/{use-popover-popup.mjs → overlay/use-popover-popup.mjs} +74 -63
  175. package/dist/internal/overlay/use-popover-popup.mjs.map +1 -0
  176. package/dist/internal/{use-popover-trigger.d.mts → overlay/use-popover-trigger.d.mts} +3 -3
  177. package/dist/internal/overlay/use-popover-trigger.d.mts.map +1 -0
  178. package/dist/internal/{use-popover-trigger.mjs → overlay/use-popover-trigger.mjs} +47 -26
  179. package/dist/internal/overlay/use-popover-trigger.mjs.map +1 -0
  180. package/dist/internal/{use-resolved-placement.mjs → overlay/use-resolved-placement.mjs} +2 -2
  181. package/dist/internal/overlay/use-resolved-placement.mjs.map +1 -0
  182. package/dist/internal/render-element.mjs +47 -9
  183. package/dist/internal/render-element.mjs.map +1 -1
  184. package/dist/internal/transition-boundary.mjs +4 -8
  185. package/dist/internal/transition-boundary.mjs.map +1 -1
  186. package/dist/internal/use-mount-fixed.mjs +22 -0
  187. package/dist/internal/use-mount-fixed.mjs.map +1 -0
  188. package/dist/internal/use-register-count.mjs +4 -1
  189. package/dist/internal/use-register-count.mjs.map +1 -1
  190. package/dist/internal/use-render.mjs +2 -2
  191. package/dist/internal/use-render.mjs.map +1 -1
  192. package/dist/internal/use-roving-focus.mjs.map +1 -1
  193. package/dist/menu/menu-checkbox-item.mjs +2 -2
  194. package/dist/menu/menu-checkbox-item.mjs.map +1 -1
  195. package/dist/menu/menu-context.d.mts +1 -1
  196. package/dist/menu/menu-context.mjs.map +1 -1
  197. package/dist/menu/menu-gestures.mjs +1 -1
  198. package/dist/menu/menu-gestures.mjs.map +1 -1
  199. package/dist/menu/menu-item.d.mts.map +1 -1
  200. package/dist/menu/menu-item.mjs +9 -10
  201. package/dist/menu/menu-item.mjs.map +1 -1
  202. package/dist/menu/menu-outside.mjs +1 -1
  203. package/dist/menu/menu-outside.mjs.map +1 -1
  204. package/dist/menu/menu-popup.d.mts +1 -1
  205. package/dist/menu/menu-popup.d.mts.map +1 -1
  206. package/dist/menu/menu-popup.mjs +10 -6
  207. package/dist/menu/menu-popup.mjs.map +1 -1
  208. package/dist/menu/menu-radio-group.mjs +2 -2
  209. package/dist/menu/menu-radio-group.mjs.map +1 -1
  210. package/dist/menu/menu-root.mjs +2 -2
  211. package/dist/menu/menu-root.mjs.map +1 -1
  212. package/dist/menu/menu-submenu-trigger.mjs +3 -3
  213. package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
  214. package/dist/menu/menu-trigger.d.mts +1 -1
  215. package/dist/menu/menu-trigger.mjs +3 -3
  216. package/dist/menu/menu-trigger.mjs.map +1 -1
  217. package/dist/number-field/number-field-input.mjs +1 -1
  218. package/dist/number-field/number-field-input.mjs.map +1 -1
  219. package/dist/number-field/number-field-root.d.mts.map +1 -1
  220. package/dist/number-field/number-field-root.mjs +43 -107
  221. package/dist/number-field/number-field-root.mjs.map +1 -1
  222. package/dist/popover/popover-close.mjs +3 -3
  223. package/dist/popover/popover-close.mjs.map +1 -1
  224. package/dist/popover/popover-context.mjs.map +1 -1
  225. package/dist/popover/popover-popup.d.mts +1 -1
  226. package/dist/popover/popover-popup.mjs +3 -3
  227. package/dist/popover/popover-popup.mjs.map +1 -1
  228. package/dist/popover/popover-root.mjs +2 -2
  229. package/dist/popover/popover-root.mjs.map +1 -1
  230. package/dist/popover/popover-trigger.d.mts +1 -1
  231. package/dist/popover/popover-trigger.mjs +1 -1
  232. package/dist/popover/popover-trigger.mjs.map +1 -1
  233. package/dist/radio-group/radio-group-item.mjs +3 -3
  234. package/dist/radio-group/radio-group-item.mjs.map +1 -1
  235. package/dist/radio-group/radio-group-root.d.mts.map +1 -1
  236. package/dist/radio-group/radio-group-root.mjs +5 -5
  237. package/dist/radio-group/radio-group-root.mjs.map +1 -1
  238. package/dist/select/select-group-label.d.mts.map +1 -1
  239. package/dist/select/select-group-label.mjs +3 -1
  240. package/dist/select/select-group-label.mjs.map +1 -1
  241. package/dist/select/select-option.mjs +1 -1
  242. package/dist/select/select-option.mjs.map +1 -1
  243. package/dist/select/select-root.d.mts.map +1 -1
  244. package/dist/select/select-root.mjs +7 -7
  245. package/dist/select/select-root.mjs.map +1 -1
  246. package/dist/select/select-trigger.d.mts.map +1 -1
  247. package/dist/select/select-trigger.mjs +3 -1
  248. package/dist/select/select-trigger.mjs.map +1 -1
  249. package/dist/select/select-value.mjs +3 -6
  250. package/dist/select/select-value.mjs.map +1 -1
  251. package/dist/slider/slider-root.d.mts.map +1 -1
  252. package/dist/slider/slider-root.mjs +38 -104
  253. package/dist/slider/slider-root.mjs.map +1 -1
  254. package/dist/slider/use-thumb-registry.mjs.map +1 -1
  255. package/dist/switch/switch.mjs +1 -1
  256. package/dist/switch/switch.mjs.map +1 -1
  257. package/dist/tabs/tabs-panel.mjs +1 -1
  258. package/dist/tabs/tabs-panel.mjs.map +1 -1
  259. package/dist/tabs/tabs-root.d.mts.map +1 -1
  260. package/dist/tabs/tabs-root.mjs +4 -4
  261. package/dist/tabs/tabs-root.mjs.map +1 -1
  262. package/dist/{internal → tabs}/use-until-found.mjs +1 -1
  263. package/dist/tabs/use-until-found.mjs.map +1 -0
  264. package/dist/toast/toast-action.d.mts +13 -3
  265. package/dist/toast/toast-action.d.mts.map +1 -1
  266. package/dist/toast/toast-action.mjs +23 -13
  267. package/dist/toast/toast-action.mjs.map +1 -1
  268. package/dist/toast/toast-close.d.mts +13 -2
  269. package/dist/toast/toast-close.d.mts.map +1 -1
  270. package/dist/toast/toast-close.mjs +16 -6
  271. package/dist/toast/toast-close.mjs.map +1 -1
  272. package/dist/toast/toast-root.mjs +1 -1
  273. package/dist/toast/toast-root.mjs.map +1 -1
  274. package/dist/toast/toast-viewport.d.mts.map +1 -1
  275. package/dist/toast/toast-viewport.mjs +48 -143
  276. package/dist/toast/toast-viewport.mjs.map +1 -1
  277. package/dist/toast/use-modal-portal-host.mjs +1 -1
  278. package/dist/toast/use-modal-portal-host.mjs.map +1 -1
  279. package/dist/toast/use-toast-announcements.mjs +46 -0
  280. package/dist/toast/use-toast-announcements.mjs.map +1 -0
  281. package/dist/toast/use-toast-focus.mjs +75 -0
  282. package/dist/toast/use-toast-focus.mjs.map +1 -0
  283. package/dist/toast/use-toast-pauses.mjs +58 -0
  284. package/dist/toast/use-toast-pauses.mjs.map +1 -0
  285. package/dist/toggle/toggle.mjs +2 -2
  286. package/dist/toggle/toggle.mjs.map +1 -1
  287. package/dist/toggle-group/toggle-group-root.d.mts.map +1 -1
  288. package/dist/toggle-group/toggle-group-root.mjs +5 -5
  289. package/dist/toggle-group/toggle-group-root.mjs.map +1 -1
  290. package/dist/tooltip/tooltip-context.d.mts +1 -1
  291. package/dist/tooltip/tooltip-context.mjs.map +1 -1
  292. package/dist/tooltip/tooltip-popup.mjs +1 -1
  293. package/dist/tooltip/tooltip-popup.mjs.map +1 -1
  294. package/dist/tooltip/tooltip-root.d.mts.map +1 -1
  295. package/dist/tooltip/tooltip-root.mjs +9 -4
  296. package/dist/tooltip/tooltip-root.mjs.map +1 -1
  297. package/dist/tooltip/tooltip-trigger.mjs +1 -1
  298. package/dist/tooltip/tooltip-trigger.mjs.map +1 -1
  299. package/dist/{internal → tooltip}/tooltip-warm.mjs +1 -1
  300. package/dist/tooltip/tooltip-warm.mjs.map +1 -0
  301. package/dist/tooltip/use-tooltip-interaction.mjs +2 -2
  302. package/dist/tooltip/use-tooltip-interaction.mjs.map +1 -1
  303. package/package.json +1 -1
  304. package/skills/funstack-ui-knowledge/SKILL.md +1 -1
  305. package/dist/internal/action-details.mjs.map +0 -1
  306. package/dist/internal/anchor-position.d.mts.map +0 -1
  307. package/dist/internal/anchor-position.mjs.map +0 -1
  308. package/dist/internal/call-urgent-handler.mjs.map +0 -1
  309. package/dist/internal/content-focus-probe.mjs.map +0 -1
  310. package/dist/internal/css-transition-cut.mjs.map +0 -1
  311. package/dist/internal/field-context.d.mts.map +0 -1
  312. package/dist/internal/field-context.mjs.map +0 -1
  313. package/dist/internal/focus-first-invalid.mjs.map +0 -1
  314. package/dist/internal/focus-visible.mjs.map +0 -1
  315. package/dist/internal/form-status-watcher.mjs.map +0 -1
  316. package/dist/internal/group-member.mjs.map +0 -1
  317. package/dist/internal/invokers.mjs.map +0 -1
  318. package/dist/internal/modal-registry.mjs.map +0 -1
  319. package/dist/internal/overlay-popup.mjs.map +0 -1
  320. package/dist/internal/popover-open.mjs.map +0 -1
  321. package/dist/internal/report-dropped.mjs.map +0 -1
  322. package/dist/internal/sync-presence.mjs.map +0 -1
  323. package/dist/internal/tooltip-warm.mjs.map +0 -1
  324. package/dist/internal/trigger-ref.mjs.map +0 -1
  325. package/dist/internal/use-action-trigger.mjs.map +0 -1
  326. package/dist/internal/use-checkable-input.mjs.map +0 -1
  327. package/dist/internal/use-controllable-action.mjs.map +0 -1
  328. package/dist/internal/use-exit-animation.mjs.map +0 -1
  329. package/dist/internal/use-field-control.mjs.map +0 -1
  330. package/dist/internal/use-fieldset-group.mjs.map +0 -1
  331. package/dist/internal/use-form-owner-event.mjs.map +0 -1
  332. package/dist/internal/use-form-reset.mjs.map +0 -1
  333. package/dist/internal/use-interest-dismiss.mjs.map +0 -1
  334. package/dist/internal/use-modal-registration.mjs.map +0 -1
  335. package/dist/internal/use-native-checked.mjs.map +0 -1
  336. package/dist/internal/use-native-group-reconciliation.mjs.map +0 -1
  337. package/dist/internal/use-native-select-value.mjs.map +0 -1
  338. package/dist/internal/use-overlay-close.mjs.map +0 -1
  339. package/dist/internal/use-overlay-root.d.mts +0 -2
  340. package/dist/internal/use-overlay-root.mjs.map +0 -1
  341. package/dist/internal/use-popover-popup.mjs.map +0 -1
  342. package/dist/internal/use-popover-trigger.d.mts.map +0 -1
  343. package/dist/internal/use-popover-trigger.mjs.map +0 -1
  344. package/dist/internal/use-resolved-placement.mjs.map +0 -1
  345. package/dist/internal/use-until-found.mjs.map +0 -1
  346. package/dist/internal/validity.d.mts.map +0 -1
  347. package/dist/internal/validity.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"render-element.mjs","names":[],"sources":["../../src/internal/render-element.ts"],"sourcesContent":["// No \"use client\": the pure half of `useRender`, usable from a directive-free part (a Root that\n// may run as a Server Component, design/components/progress.md 8.1 and implementation note 14.1).\nimport { cloneElement, createElement, isValidElement } from \"react\";\nimport type { CSSProperties, ReactNode, Ref } from \"react\";\nimport { mergeProps, mergeRefs } from \"./merge-props.js\";\nimport type { RenderProp, StateValue } from \"./types.js\";\n\nexport interface ElementLikeProps {\n className?: string | undefined;\n style?: CSSProperties | undefined;\n children?: ReactNode;\n ref?: Ref<unknown> | undefined;\n}\n\n/** `data-*` attributes are valid JSX but absent from the element prop types. */\nexport type DataAttributes = { [key: `data-${string}`]: string | undefined };\n\nexport interface RenderElementOptions<Props extends ElementLikeProps, State> {\n /** Intrinsic element rendered when `render` is not given. */\n defaultElement: string;\n render: RenderProp<Props, State> | undefined;\n state: State;\n className: StateValue<string | undefined, State> | undefined;\n style: StateValue<CSSProperties | undefined, State> | undefined;\n children: StateValue<ReactNode, State> | undefined;\n /**\n * The part's pass-through props for the element. A `render` element's own props win over\n * these. Their `ref` is replaced by `ref` below.\n */\n props: Omit<Props, \"className\" | \"style\" | \"children\"> & DataAttributes;\n /**\n * Library-controlled attributes the part computes (`role`, `aria-*` state, id wiring, `data-*`\n * state, the library's own event handlers). These win over a `render` element's props\n * (conventions 1.2).\n */\n libraryProps?: Partial<Omit<Props, \"className\" | \"style\" | \"children\">> & DataAttributes;\n /**\n * The element's ref, already merged from the library's ref, the consumer's `ref` and the\n * `render` element's ref. The `render` element's own ref is not attached separately.\n */\n ref: Ref<unknown> | undefined;\n}\n\nexport function resolveStateValue<T, State>(value: StateValue<T, State>, state: State): T {\n return typeof value === \"function\" ? (value as (state: State) => T)(state) : value;\n}\n\n/**\n * Whether a part whose default element is a `<button>` should add `type=\"button\"` (conventions\n * 1.2): no `render`, the function form (it receives button props and decides itself what to\n * spread), a host `<button>` element, or a **component** element (assumed to render a\n * `<button>`; if it renders a link, `type` is a harmless ignored attribute, while a missing\n * `type` on a `<button>` in a form is a silent submit). Only a host element of another tag (an\n * `<a>`) does not get it.\n */\nexport function rendersButton<Props, State>(render: RenderProp<Props, State> | undefined): boolean {\n if (render === undefined || typeof render === \"function\") return true;\n if (!isValidElement(render)) return false;\n return typeof render.type !== \"string\" || render.type === \"button\";\n}\n\n/**\n * Whether the rendered element is certainly a host `<button>`: no `render`, the function form, or\n * a host `\"button\"` element. The strict predicate for native `disabled`, which means nothing on a\n * link and would expose it as enabled to assistive technology; anything else (a link, a\n * component) takes the `aria-disabled` branch (design/components/button.md).\n */\nexport function isHostButton<Props, State>(render: RenderProp<Props, State> | undefined): boolean {\n if (render === undefined || typeof render === \"function\") return true;\n return isValidElement(render) && render.type === \"button\";\n}\n\nexport interface DisabledButton {\n /**\n * Owned keys, spread where `disabled` goes: `disabled` (owned as absent in the focusable\n * branch, where the element may not be a host `<button>` and the part's click handler refuses,\n * so a render element's own is removed), and in that branch only `aria-disabled` (a host\n * button keeps a consumer's own).\n */\n readonly props: {\n readonly disabled: boolean | undefined;\n readonly \"aria-disabled\"?: true | undefined;\n };\n /**\n * Whether an invoker part may render `popovertarget` or `commandfor` / `command`: not when disabled in the\n * focusable branch, where nothing native stops the command (a component render spreading onto\n * a real `<button>` would be a live invoker before hydration).\n */\n readonly invoker: boolean;\n}\n\n/**\n * The disabled rule of a button-like part that accepts an arbitrary `render`\n * (conventions 1.2, design/components/button.md 17): native `disabled` on a host `<button>`, or\n * where the browser handles the click (`handlesClick: false`: a JS-free command, which only\n * native `disabled` stops); `aria-disabled` otherwise. `alwaysFocusable` always takes the\n * `aria-disabled` branch (a menu item stays focusable).\n */\nexport function disabledButton<Props, State>(\n render: RenderProp<Props, State> | undefined,\n disabled: boolean,\n options: { readonly handlesClick?: boolean; readonly alwaysFocusable?: boolean } = {},\n): DisabledButton {\n const { handlesClick = true, alwaysFocusable = false } = options;\n const focusable = alwaysFocusable || (handlesClick && !isHostButton(render));\n return {\n props: {\n disabled: focusable ? undefined : disabled,\n ...(focusable && { \"aria-disabled\": disabled ? true : undefined }),\n },\n invoker: !(focusable && disabled),\n };\n}\n\n/**\n * The ref of a part with no library ref, merged from the consumer's `ref` and a `render`\n * element's ref without memoisation (a directive-free part cannot `useMemo`, design\n * progress.md 14.1). A fresh callback ref per render is correct because every merged callback\n * returns a cleanup; a single ref is passed through untouched.\n */\nexport function mergeRenderRef(\n consumerRef: Ref<unknown> | undefined,\n render: unknown,\n): Ref<unknown> | undefined {\n const elementRef = isValidElement<ElementLikeProps>(render) ? render.props.ref : undefined;\n if (consumerRef != null && elementRef != null) return mergeRefs(consumerRef, elementRef);\n return consumerRef ?? elementRef;\n}\n\n/**\n * Resolves `render` and the function-form `className` / `style` / `children` of a part against\n * its state and produces the element (conventions 1.2, 1.3, 1.4). Pure: the caller merges the\n * refs (`useRender` memoises the merge; a directive-free part merges unmemoised).\n */\nexport function renderElement<Props extends ElementLikeProps, State>(\n options: RenderElementOptions<Props, State>,\n): ReactNode {\n const { defaultElement, render, state, className, style, children, props, libraryProps, ref } =\n options;\n\n const partProps = {\n ...props,\n ref,\n className: resolveStateValue(className, state),\n style: resolveStateValue(style, state),\n children: resolveStateValue(children, state),\n } as Record<string, unknown>;\n const controlled = (libraryProps ?? {}) as Record<string, unknown>;\n\n if (isValidElement<ElementLikeProps>(render)) {\n // The element's ref is already part of `ref`.\n const { ref: _ignored, ...elementProps } = render.props as Record<string, unknown>;\n return cloneElement(render, mergeProps(partProps, elementProps, controlled) as Partial<Props>);\n }\n const resolved = mergeProps(partProps, {}, controlled) as unknown as Props;\n if (typeof render === \"function\") {\n return render(resolved, state);\n }\n return createElement(defaultElement, resolved);\n}\n"],"mappings":";;;AA2CA,SAAgB,kBAA4B,OAA6B,OAAiB;CACxF,OAAO,OAAO,UAAU,aAAc,MAA8B,KAAK,IAAI;AAC/E;;;;;;;;;AAUA,SAAgB,cAA4B,QAAuD;CACjG,IAAI,WAAW,KAAA,KAAa,OAAO,WAAW,YAAY,OAAO;CACjE,IAAI,CAAC,eAAe,MAAM,GAAG,OAAO;CACpC,OAAO,OAAO,OAAO,SAAS,YAAY,OAAO,SAAS;AAC5D;;;;;;;AAQA,SAAgB,aAA2B,QAAuD;CAChG,IAAI,WAAW,KAAA,KAAa,OAAO,WAAW,YAAY,OAAO;CACjE,OAAO,eAAe,MAAM,KAAK,OAAO,SAAS;AACnD;;;;;;;;AA4BA,SAAgB,eACd,QACA,UACA,UAAmF,CAAC,GACpE;CAChB,MAAM,EAAE,eAAe,MAAM,kBAAkB,UAAU;CACzD,MAAM,YAAY,mBAAoB,gBAAgB,CAAC,aAAa,MAAM;CAC1E,OAAO;EACL,OAAO;GACL,UAAU,YAAY,KAAA,IAAY;GAClC,GAAI,aAAa,EAAE,iBAAiB,WAAW,OAAO,KAAA,EAAU;EAClE;EACA,SAAS,EAAE,aAAa;CAC1B;AACF;;;;;;;AAQA,SAAgB,eACd,aACA,QAC0B;CAC1B,MAAM,aAAa,eAAiC,MAAM,IAAI,OAAO,MAAM,MAAM,KAAA;CACjF,IAAI,eAAe,QAAQ,cAAc,MAAM,OAAO,UAAU,aAAa,UAAU;CACvF,OAAO,eAAe;AACxB;;;;;;AAOA,SAAgB,cACd,SACW;CACX,MAAM,EAAE,gBAAgB,QAAQ,OAAO,WAAW,OAAO,UAAU,OAAO,cAAc,QACtF;CAEF,MAAM,YAAY;EAChB,GAAG;EACH;EACA,WAAW,kBAAkB,WAAW,KAAK;EAC7C,OAAO,kBAAkB,OAAO,KAAK;EACrC,UAAU,kBAAkB,UAAU,KAAK;CAC7C;CACA,MAAM,aAAc,gBAAgB,CAAC;CAErC,IAAI,eAAiC,MAAM,GAAG;EAE5C,MAAM,EAAE,KAAK,UAAU,GAAG,iBAAiB,OAAO;EAClD,OAAO,aAAa,QAAQ,WAAW,WAAW,cAAc,UAAU,CAAmB;CAC/F;CACA,MAAM,WAAW,WAAW,WAAW,CAAC,GAAG,UAAU;CACrD,IAAI,OAAO,WAAW,YACpB,OAAO,OAAO,UAAU,KAAK;CAE/B,OAAO,cAAc,gBAAgB,QAAQ;AAC/C"}
1
+ {"version":3,"file":"render-element.mjs","names":[],"sources":["../../src/internal/render-element.ts"],"sourcesContent":["// No \"use client\": the pure half of `useRender`, usable from a directive-free part (a Root that\n// may run as a Server Component, design/components/progress.md 8.1 and implementation note 14.1).\nimport { cloneElement, createElement, isValidElement } from \"react\";\nimport type { CSSProperties, ReactNode, Ref } from \"react\";\nimport { mergeProps, mergeRefs } from \"./merge-props.js\";\nimport type { RenderProp, StateValue } from \"./types.js\";\n\nexport interface ElementLikeProps {\n className?: string | undefined;\n style?: CSSProperties | undefined;\n children?: ReactNode;\n ref?: Ref<unknown> | undefined;\n}\n\n/** `data-*` attributes are valid JSX but absent from the element prop types. */\nexport type DataAttributes = { [key: `data-${string}`]: string | undefined };\n\nexport interface RenderElementOptions<Props extends ElementLikeProps, State> {\n /** Intrinsic element rendered when `render` is not given. */\n defaultElement: string;\n render: RenderProp<Props, State> | undefined;\n state: State;\n className: StateValue<string | undefined, State> | undefined;\n style: StateValue<CSSProperties | undefined, State> | undefined;\n children: StateValue<ReactNode, State> | undefined;\n /**\n * The part's pass-through props for the element. A `render` element's own props win over\n * these. Their `ref` is replaced by `ref` below.\n */\n props: Omit<Props, \"className\" | \"style\" | \"children\"> & DataAttributes;\n /**\n * Library-controlled attributes the part computes (`role`, `aria-*` state, id wiring, `data-*`\n * state, the library's own event handlers). These win over a `render` element's props\n * (conventions 1.2).\n */\n libraryProps?: Partial<Omit<Props, \"className\" | \"style\" | \"children\">> & DataAttributes;\n /**\n * The element's ref, already merged from the library's ref, the consumer's `ref` and the\n * `render` element's ref. The `render` element's own ref is not attached separately.\n */\n ref: Ref<unknown> | undefined;\n}\n\nexport function resolveStateValue<T, State>(value: StateValue<T, State>, state: State): T {\n return typeof value === \"function\" ? (value as (state: State) => T)(state) : value;\n}\n\n/**\n * Whether a part whose default element is a `<button>` should add `type=\"button\"` (conventions\n * 1.2): no `render`, the function form (it receives button props and decides itself what to\n * spread), a host `<button>` element, or a **component** element (assumed to render a\n * `<button>`; if it renders a link, `type` is a harmless ignored attribute, while a missing\n * `type` on a `<button>` in a form is a silent submit). Only a host element of another tag (an\n * `<a>`) does not get it.\n */\nexport function rendersButton<Props, State>(render: RenderProp<Props, State> | undefined): boolean {\n if (render === undefined || typeof render === \"function\") return true;\n if (!isValidElement(render)) return false;\n return typeof render.type !== \"string\" || render.type === \"button\";\n}\n\n/**\n * Whether the rendered element is certainly a host `<button>`: no `render`, the function form, or\n * a host `\"button\"` element. The strict predicate for native `disabled`, which means nothing on a\n * link and would expose it as enabled to assistive technology; anything else (a link, a\n * component) takes the `aria-disabled` branch (design/components/button.md).\n */\nexport function isHostButton<Props, State>(render: RenderProp<Props, State> | undefined): boolean {\n if (render === undefined || typeof render === \"function\") return true;\n return isValidElement(render) && render.type === \"button\";\n}\n\nexport interface DisabledButton {\n /**\n * Owned keys, spread where `disabled` goes: `disabled` (owned as absent in the focusable\n * branch, where the element may not be a host `<button>` and the part's click handler refuses,\n * so a render element's own is removed), and in that branch only `aria-disabled` (a host\n * button keeps a consumer's own).\n */\n readonly props: {\n readonly disabled: boolean | undefined;\n readonly \"aria-disabled\"?: true | undefined;\n };\n /**\n * Whether an invoker part may render `popovertarget` or `commandfor` / `command`: not when disabled in the\n * focusable branch, where nothing native stops the command (a component render spreading onto\n * a real `<button>` would be a live invoker before hydration).\n */\n readonly invoker: boolean;\n}\n\n/**\n * Whether the rendered element certainly cannot be natively disabled: a host element of a tag\n * other than `<button>` / `<input>` (an `<a>`, a `<div>`). No `render`, the function form and a\n * component element may render a button.\n */\nfunction certainlyNotDisableable<Props, State>(\n render: RenderProp<Props, State> | undefined,\n): boolean {\n if (rendersButton(render)) return false;\n return !(isValidElement(render) && render.type === \"input\");\n}\n\n/**\n * The disabled rule of a button-like part that accepts an arbitrary `render` (conventions 1.2,\n * design/components/button.md 17). Native `disabled` on a host `<button>` (the function form\n * included), and wherever the element may be a button and the click's effect is the browser's\n * own (`handlesClick: false`: a submitter, a reset button, a JS-free invoker; only native\n * `disabled` stops those before hydration). `aria-disabled`, which the part's click handler\n * honours by cancelling the click, otherwise: on an element that certainly cannot be natively\n * disabled (a host `<a>`, `<div>`), on a component or other non-button render whose own handler\n * is the action (`handlesClick: true`, the default), and with `alwaysFocusable` (an opt-in\n * focusable disabled control: a menu item, a Toolbar or `focusableWhenDisabled` Button). A part\n * that installs no click handler of its own (`Form.Submit`, a JS-free command part on a host\n * link) installs `cancelClick` while `invoker` is `false`, so the click is cancelled there too.\n *\n * When `disabled` and the part's pending `aria-disabled` meet, the native `disabled` wins:\n * `pendingAriaDisabled` below.\n */\nexport function disabledButton<Props, State>(\n render: RenderProp<Props, State> | undefined,\n disabled: boolean,\n options: { readonly handlesClick?: boolean; readonly alwaysFocusable?: boolean } = {},\n): DisabledButton {\n const { handlesClick = true, alwaysFocusable = false } = options;\n const focusable =\n alwaysFocusable || (handlesClick ? !isHostButton(render) : certainlyNotDisableable(render));\n return {\n props: {\n disabled: focusable ? undefined : disabled,\n ...(focusable && { \"aria-disabled\": disabled ? true : undefined }),\n },\n invoker: !(focusable && disabled),\n };\n}\n\n/**\n * The click handler of a disabled part in the `aria-disabled` branch that has no click handler\n * of its own (`Form.Submit`, a JS-free command Trigger / Close on a host link): cancels the\n * click, so a disabled link does not navigate after hydration (conventions 1.2). Installed only\n * while disabled: an enabled render element keeps its own `onClick` as the only one.\n */\nexport function cancelClick(event: { preventDefault(): void }): void {\n event.preventDefault();\n}\n\n/**\n * The owned `aria-disabled` of a pure trigger that also renders it while pending (conventions\n * 3.6): the focusable-disabled branch's `true`; nothing while natively disabled (native\n * `disabled` wins, a second unavailable state on the same element says nothing new); otherwise\n * `true` while pending exactly when the part ignores activations (`ignoringPending`).\n */\nexport function pendingAriaDisabled(\n disabledProps: DisabledButton[\"props\"],\n ignoringPending: boolean,\n): true | undefined {\n if (disabledProps.disabled === true) return undefined;\n if (disabledProps[\"aria-disabled\"] === true) return true;\n return ignoringPending ? true : undefined;\n}\n\n/**\n * The ref of a part with no library ref, merged from the consumer's `ref` and a `render`\n * element's ref without memoisation (the directive-free half of `use-render.tsx`,\n * progress.md 8.1). A fresh callback ref per render is correct because every merged callback\n * returns a cleanup; a single ref is passed through untouched.\n */\nexport function mergeRenderRef(\n consumerRef: Ref<unknown> | undefined,\n render: unknown,\n): Ref<unknown> | undefined {\n const elementRef = isValidElement<ElementLikeProps>(render) ? render.props.ref : undefined;\n if (consumerRef != null && elementRef != null) return mergeRefs(consumerRef, elementRef);\n return consumerRef ?? elementRef;\n}\n\n/**\n * Resolves `render` and the function-form `className` / `style` / `children` of a part against\n * its state and produces the element (conventions 1.2, 1.3, 1.4). Pure: the caller merges the\n * refs (`useRender` memoises the merge; a directive-free part merges unmemoised).\n */\nexport function renderElement<Props extends ElementLikeProps, State>(\n options: RenderElementOptions<Props, State>,\n): ReactNode {\n const { defaultElement, render, state, className, style, children, props, libraryProps, ref } =\n options;\n\n const partProps = {\n ...props,\n ref,\n className: resolveStateValue(className, state),\n style: resolveStateValue(style, state),\n children: resolveStateValue(children, state),\n } as Record<string, unknown>;\n const controlled = (libraryProps ?? {}) as Record<string, unknown>;\n\n if (isValidElement<ElementLikeProps>(render)) {\n // The element's ref is already part of `ref`.\n const { ref: _ignored, ...elementProps } = render.props as Record<string, unknown>;\n return cloneElement(render, mergeProps(partProps, elementProps, controlled) as Partial<Props>);\n }\n const resolved = mergeProps(partProps, {}, controlled) as unknown as Props;\n if (typeof render === \"function\") {\n return render(resolved, state);\n }\n return createElement(defaultElement, resolved);\n}\n"],"mappings":";;;AA2CA,SAAgB,kBAA4B,OAA6B,OAAiB;CACxF,OAAO,OAAO,UAAU,aAAc,MAA8B,KAAK,IAAI;AAC/E;;;;;;;;;AAUA,SAAgB,cAA4B,QAAuD;CACjG,IAAI,WAAW,KAAA,KAAa,OAAO,WAAW,YAAY,OAAO;CACjE,IAAI,CAAC,eAAe,MAAM,GAAG,OAAO;CACpC,OAAO,OAAO,OAAO,SAAS,YAAY,OAAO,SAAS;AAC5D;;;;;;;AAQA,SAAgB,aAA2B,QAAuD;CAChG,IAAI,WAAW,KAAA,KAAa,OAAO,WAAW,YAAY,OAAO;CACjE,OAAO,eAAe,MAAM,KAAK,OAAO,SAAS;AACnD;;;;;;AA0BA,SAAS,wBACP,QACS;CACT,IAAI,cAAc,MAAM,GAAG,OAAO;CAClC,OAAO,EAAE,eAAe,MAAM,KAAK,OAAO,SAAS;AACrD;;;;;;;;;;;;;;;;;AAkBA,SAAgB,eACd,QACA,UACA,UAAmF,CAAC,GACpE;CAChB,MAAM,EAAE,eAAe,MAAM,kBAAkB,UAAU;CACzD,MAAM,YACJ,oBAAoB,eAAe,CAAC,aAAa,MAAM,IAAI,wBAAwB,MAAM;CAC3F,OAAO;EACL,OAAO;GACL,UAAU,YAAY,KAAA,IAAY;GAClC,GAAI,aAAa,EAAE,iBAAiB,WAAW,OAAO,KAAA,EAAU;EAClE;EACA,SAAS,EAAE,aAAa;CAC1B;AACF;;;;;;;AAQA,SAAgB,YAAY,OAAyC;CACnE,MAAM,eAAe;AACvB;;;;;;;AAQA,SAAgB,oBACd,eACA,iBACkB;CAClB,IAAI,cAAc,aAAa,MAAM,OAAO,KAAA;CAC5C,IAAI,cAAc,qBAAqB,MAAM,OAAO;CACpD,OAAO,kBAAkB,OAAO,KAAA;AAClC;;;;;;;AAQA,SAAgB,eACd,aACA,QAC0B;CAC1B,MAAM,aAAa,eAAiC,MAAM,IAAI,OAAO,MAAM,MAAM,KAAA;CACjF,IAAI,eAAe,QAAQ,cAAc,MAAM,OAAO,UAAU,aAAa,UAAU;CACvF,OAAO,eAAe;AACxB;;;;;;AAOA,SAAgB,cACd,SACW;CACX,MAAM,EAAE,gBAAgB,QAAQ,OAAO,WAAW,OAAO,UAAU,OAAO,cAAc,QACtF;CAEF,MAAM,YAAY;EAChB,GAAG;EACH;EACA,WAAW,kBAAkB,WAAW,KAAK;EAC7C,OAAO,kBAAkB,OAAO,KAAK;EACrC,UAAU,kBAAkB,UAAU,KAAK;CAC7C;CACA,MAAM,aAAc,gBAAgB,CAAC;CAErC,IAAI,eAAiC,MAAM,GAAG;EAE5C,MAAM,EAAE,KAAK,UAAU,GAAG,iBAAiB,OAAO;EAClD,OAAO,aAAa,QAAQ,WAAW,WAAW,cAAc,UAAU,CAAmB;CAC/F;CACA,MAAM,WAAW,WAAW,WAAW,CAAC,GAAG,UAAU;CACrD,IAAI,OAAO,WAAW,YACpB,OAAO,OAAO,UAAU,KAAK;CAE/B,OAAO,cAAc,gBAAgB,QAAQ;AAC/C"}
@@ -1,5 +1,6 @@
1
1
  "use client";
2
- import { ViewTransition, useEffect, useRef } from "react";
2
+ import { useDevWarning } from "./use-dev-warning.mjs";
3
+ import { ViewTransition, useState } from "react";
3
4
  import { jsx } from "react/jsx-runtime";
4
5
  //#region src/internal/transition-boundary.tsx
5
6
  const isDev = process.env.NODE_ENV !== "production";
@@ -37,13 +38,8 @@ function transitionBoundary(transition, node) {
37
38
  */
38
39
  function useTransitionBoundary(part, transition, node) {
39
40
  const hasBoundary = transition !== void 0;
40
- const initial = useRef(hasBoundary);
41
- const warned = useRef(false);
42
- useEffect(() => {
43
- if (!isDev || warned.current || hasBoundary === initial.current) return;
44
- warned.current = true;
45
- console.error(`${part}: \`transition\` changed between undefined and a value after mount. The part renders a <ViewTransition> only when \`transition\` is given, so this remounts its subtree (DOM and state are lost). Keep \`transition\` static; use \`transition="none"\` to switch animation off without removing the boundary.`);
46
- }, [hasBoundary, part]);
41
+ const [initial] = useState(hasBoundary);
42
+ useDevWarning(hasBoundary !== initial, isDev && `${part}: \`transition\` changed between undefined and a value after mount. The part renders a <ViewTransition> only when \`transition\` is given, so this remounts its subtree (DOM and state are lost). Keep \`transition\` static; use \`transition="none"\` to switch animation off without removing the boundary.`);
47
43
  return transitionBoundary(transition, node);
48
44
  }
49
45
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"transition-boundary.mjs","names":[],"sources":["../../src/internal/transition-boundary.tsx"],"sourcesContent":["\"use client\";\nimport { useEffect, useRef, ViewTransition } from \"react\";\nimport type { ReactNode, ViewTransitionClass } from \"react\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * Wraps a part's output in `<ViewTransition default={transition}>` **only when the consumer\n * passed `transition`** (conventions 5.1). With `transition === undefined` the node is returned\n * unwrapped and the part renders no boundary at all.\n *\n * Reason (docs/research/view-transition-mount-cost.md): react-dom 19.3 starts a\n * document view transition whenever a `<ViewTransition>` mounts or is revealed by `<Activity>` in\n * a transition-lane commit, whatever its class resolves to (`\"none\"` included). The browser's\n * 250 ms root cross-fade then runs and every later transition commit waits for it. Exits and\n * updates of a `\"none\"` boundary are free, so an explicit `transition=\"none\"` keeps the boundary\n * and lets a consumer switch between `\"none\"` and a class without remounting.\n *\n * The boundary stays the outermost node of the part's output, so a part that is the top of an\n * inserted subtree gets enter / exit. A plain function (not a component), so it adds no fiber\n * between the boundary and the element.\n */\nexport function transitionBoundary(\n transition: ViewTransitionClass | undefined,\n node: ReactNode,\n): ReactNode {\n if (transition === undefined) return node;\n return <ViewTransition default={transition}>{node}</ViewTransition>;\n}\n\n/**\n * {@link transitionBoundary} plus the development warning for a non-static `transition`\n * (conventions 5.1): changing it between `undefined` and a value changes the element type at the\n * part's root, so React remounts the part's subtree (DOM and state lost). Warns once per\n * instance, from an effect. `part` is the public name used in the message (`\"Tabs.Panel\"`).\n *\n * Pass the *effective* value: a part that ignores `transition` in some mode (Accordion, Dialog\n * JS-free mode) passes `undefined` there.\n */\nexport function useTransitionBoundary(\n part: string,\n transition: ViewTransitionClass | undefined,\n node: ReactNode,\n): ReactNode {\n const hasBoundary = transition !== undefined;\n const initial = useRef(hasBoundary);\n const warned = useRef(false);\n useEffect(() => {\n if (!isDev || warned.current || hasBoundary === initial.current) return;\n warned.current = true;\n console.error(\n `${part}: \\`transition\\` changed between undefined and a value after mount. The part ` +\n \"renders a <ViewTransition> only when `transition` is given, so this remounts its \" +\n 'subtree (DOM and state are lost). Keep `transition` static; use `transition=\"none\"` ' +\n \"to switch animation off without removing the boundary.\",\n );\n }, [hasBoundary, part]);\n return transitionBoundary(transition, node);\n}\n"],"mappings":";;;;AAIA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;;;AAkBvC,SAAgB,mBACd,YACA,MACW;CACX,IAAI,eAAe,KAAA,GAAW,OAAO;CACrC,OAAO,oBAAC,gBAAD;EAAgB,SAAS;EAAa,UAAA;CAAqB,CAAA;AACpE;;;;;;;;;;AAWA,SAAgB,sBACd,MACA,YACA,MACW;CACX,MAAM,cAAc,eAAe,KAAA;CACnC,MAAM,UAAU,OAAO,WAAW;CAClC,MAAM,SAAS,OAAO,KAAK;CAC3B,gBAAgB;EACd,IAAI,CAAC,SAAS,OAAO,WAAW,gBAAgB,QAAQ,SAAS;EACjE,OAAO,UAAU;EACjB,QAAQ,MACN,GAAG,KAAK,+SAIV;CACF,GAAG,CAAC,aAAa,IAAI,CAAC;CACtB,OAAO,mBAAmB,YAAY,IAAI;AAC5C"}
1
+ {"version":3,"file":"transition-boundary.mjs","names":[],"sources":["../../src/internal/transition-boundary.tsx"],"sourcesContent":["\"use client\";\nimport { useState, ViewTransition } from \"react\";\nimport type { ReactNode, ViewTransitionClass } from \"react\";\n\nimport { useDevWarning } from \"./use-dev-warning.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * Wraps a part's output in `<ViewTransition default={transition}>` **only when the consumer\n * passed `transition`** (conventions 5.1). With `transition === undefined` the node is returned\n * unwrapped and the part renders no boundary at all.\n *\n * Reason (docs/research/view-transition-mount-cost.md): react-dom 19.3 starts a\n * document view transition whenever a `<ViewTransition>` mounts or is revealed by `<Activity>` in\n * a transition-lane commit, whatever its class resolves to (`\"none\"` included). The browser's\n * 250 ms root cross-fade then runs and every later transition commit waits for it. Exits and\n * updates of a `\"none\"` boundary are free, so an explicit `transition=\"none\"` keeps the boundary\n * and lets a consumer switch between `\"none\"` and a class without remounting.\n *\n * The boundary stays the outermost node of the part's output, so a part that is the top of an\n * inserted subtree gets enter / exit. A plain function (not a component), so it adds no fiber\n * between the boundary and the element.\n */\nexport function transitionBoundary(\n transition: ViewTransitionClass | undefined,\n node: ReactNode,\n): ReactNode {\n if (transition === undefined) return node;\n return <ViewTransition default={transition}>{node}</ViewTransition>;\n}\n\n/**\n * {@link transitionBoundary} plus the development warning for a non-static `transition`\n * (conventions 5.1): changing it between `undefined` and a value changes the element type at the\n * part's root, so React remounts the part's subtree (DOM and state lost). Warns once per\n * instance, from an effect. `part` is the public name used in the message (`\"Tabs.Panel\"`).\n *\n * Pass the *effective* value: a part that ignores `transition` in some mode (Accordion, Dialog\n * JS-free mode) passes `undefined` there.\n */\nexport function useTransitionBoundary(\n part: string,\n transition: ViewTransitionClass | undefined,\n node: ReactNode,\n): ReactNode {\n const hasBoundary = transition !== undefined;\n const [initial] = useState(hasBoundary);\n useDevWarning(\n hasBoundary !== initial,\n isDev &&\n `${part}: \\`transition\\` changed between undefined and a value after mount. The part ` +\n \"renders a <ViewTransition> only when `transition` is given, so this remounts its \" +\n 'subtree (DOM and state are lost). Keep `transition` static; use `transition=\"none\"` ' +\n \"to switch animation off without removing the boundary.\",\n );\n return transitionBoundary(transition, node);\n}\n"],"mappings":";;;;;AAMA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;;;AAkBvC,SAAgB,mBACd,YACA,MACW;CACX,IAAI,eAAe,KAAA,GAAW,OAAO;CACrC,OAAO,oBAAC,gBAAD;EAAgB,SAAS;EAAa,UAAA;CAAqB,CAAA;AACpE;;;;;;;;;;AAWA,SAAgB,sBACd,MACA,YACA,MACW;CACX,MAAM,cAAc,eAAe,KAAA;CACnC,MAAM,CAAC,WAAW,SAAS,WAAW;CACtC,cACE,gBAAgB,SAChB,SACE,GAAG,KAAK,+SAIZ;CACA,OAAO,mBAAmB,YAAY,IAAI;AAC5C"}
@@ -0,0 +1,22 @@
1
+ "use client";
2
+ import { useDevWarning } from "./use-dev-warning.mjs";
3
+ import { useState } from "react";
4
+ //#region src/internal/use-mount-fixed.ts
5
+ /**
6
+ * A prop the component reads once, at mount: returns the first render's `value` for the life of
7
+ * the instance, and logs `message` once (`useDevWarning`) the first time a later render's `value`
8
+ * differs (`!==`). For the mode switches the library does not support: JS-free versus library
9
+ * mode (the overlay Roots, Accordion), exclusive versus multiple (ToggleGroup, Accordion).
10
+ *
11
+ * Pass the message as `isDev && "..."` with the calling module's own `isDev` constant
12
+ * (`use-dev-warning.ts`).
13
+ */
14
+ function useMountFixed(value, message) {
15
+ const [mounted] = useState(value);
16
+ useDevWarning(mounted !== value, message);
17
+ return mounted;
18
+ }
19
+ //#endregion
20
+ export { useMountFixed };
21
+
22
+ //# sourceMappingURL=use-mount-fixed.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-mount-fixed.mjs","names":[],"sources":["../../src/internal/use-mount-fixed.ts"],"sourcesContent":["\"use client\";\nimport { useState } from \"react\";\nimport { useDevWarning } from \"./use-dev-warning.js\";\n\n/**\n * A prop the component reads once, at mount: returns the first render's `value` for the life of\n * the instance, and logs `message` once (`useDevWarning`) the first time a later render's `value`\n * differs (`!==`). For the mode switches the library does not support: JS-free versus library\n * mode (the overlay Roots, Accordion), exclusive versus multiple (ToggleGroup, Accordion).\n *\n * Pass the message as `isDev && \"...\"` with the calling module's own `isDev` constant\n * (`use-dev-warning.ts`).\n */\nexport function useMountFixed<T>(value: T, message: string | false): T {\n const [mounted] = useState(value);\n useDevWarning(mounted !== value, message);\n return mounted;\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,cAAiB,OAAU,SAA4B;CACrE,MAAM,CAAC,WAAW,SAAS,KAAK;CAChC,cAAc,YAAY,OAAO,OAAO;CACxC,OAAO;AACT"}
@@ -1,7 +1,10 @@
1
1
  "use client";
2
2
  import { useCallback, useRef, useState } from "react";
3
3
  //#region src/internal/use-register-count.ts
4
- /** Counts the mounted instances of an optional part (Slider's and NumberField's Labels). */
4
+ /**
5
+ * Counts the mounted instances of an optional part: the Labels of Slider, NumberField and Combobox,
6
+ * Combobox's Statuses.
7
+ */
5
8
  function useRegisterCount() {
6
9
  const [count, setCount] = useState(0);
7
10
  const countRef = useRef(0);
@@ -1 +1 @@
1
- {"version":3,"file":"use-register-count.mjs","names":[],"sources":["../../src/internal/use-register-count.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useRef, useState } from \"react\";\nimport type { RefObject } from \"react\";\n\nexport interface RegisterCount {\n /** How many parts are registered, as of this render. */\n readonly count: number;\n /** Stable. Call from a layout effect (`useLayoutEffect(register, [register])`); returns the unregistration. */\n readonly register: () => () => void;\n /** The same count, current before the re-render a registration scheduled (effects only). */\n readonly countRef: RefObject<number>;\n}\n\n/** Counts the mounted instances of an optional part (Slider's and NumberField's Labels). */\nexport function useRegisterCount(): RegisterCount {\n const [count, setCount] = useState(0);\n const countRef = useRef(0);\n const register = useCallback(() => {\n countRef.current += 1;\n setCount((c) => c + 1);\n return () => {\n countRef.current -= 1;\n setCount((c) => c - 1);\n };\n }, []);\n return { count, register, countRef };\n}\n"],"mappings":";;;;AAcA,SAAgB,mBAAkC;CAChD,MAAM,CAAC,OAAO,YAAY,SAAS,CAAC;CACpC,MAAM,WAAW,OAAO,CAAC;CASzB,OAAO;EAAE;EAAO,UARC,kBAAkB;GACjC,SAAS,WAAW;GACpB,UAAU,MAAM,IAAI,CAAC;GACrB,aAAa;IACX,SAAS,WAAW;IACpB,UAAU,MAAM,IAAI,CAAC;GACvB;EACF,GAAG,CAAC,CACmB;EAAG;CAAS;AACrC"}
1
+ {"version":3,"file":"use-register-count.mjs","names":[],"sources":["../../src/internal/use-register-count.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useRef, useState } from \"react\";\nimport type { RefObject } from \"react\";\n\nexport interface RegisterCount {\n /** How many parts are registered, as of this render. */\n readonly count: number;\n /** Stable. Call from a layout effect (`useLayoutEffect(register, [register])`); returns the unregistration. */\n readonly register: () => () => void;\n /** The same count, current before the re-render a registration scheduled (effects only). */\n readonly countRef: RefObject<number>;\n}\n\n/**\n * Counts the mounted instances of an optional part: the Labels of Slider, NumberField and Combobox,\n * Combobox's Statuses.\n */\nexport function useRegisterCount(): RegisterCount {\n const [count, setCount] = useState(0);\n const countRef = useRef(0);\n const register = useCallback(() => {\n countRef.current += 1;\n setCount((c) => c + 1);\n return () => {\n countRef.current -= 1;\n setCount((c) => c - 1);\n };\n }, []);\n return { count, register, countRef };\n}\n"],"mappings":";;;;;;;AAiBA,SAAgB,mBAAkC;CAChD,MAAM,CAAC,OAAO,YAAY,SAAS,CAAC;CACpC,MAAM,WAAW,OAAO,CAAC;CASzB,OAAO;EAAE;EAAO,UARC,kBAAkB;GACjC,SAAS,WAAW;GACpB,UAAU,MAAM,IAAI,CAAC;GACrB,aAAa;IACX,SAAS,WAAW;IACpB,UAAU,MAAM,IAAI,CAAC;GACvB;EACF,GAAG,CAAC,CACmB;EAAG;CAAS;AACrC"}
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { mergeRefs } from "./merge-props.mjs";
3
- import { disabledButton, isHostButton, renderElement, rendersButton, resolveStateValue } from "./render-element.mjs";
3
+ import { cancelClick, disabledButton, renderElement, rendersButton, resolveStateValue } from "./render-element.mjs";
4
4
  import { isValidElement, useMemo } from "react";
5
5
  //#region src/internal/use-render.tsx
6
6
  /**
@@ -23,6 +23,6 @@ function useRender(options) {
23
23
  });
24
24
  }
25
25
  //#endregion
26
- export { disabledButton, isHostButton, rendersButton, resolveStateValue, useRender };
26
+ export { cancelClick, disabledButton, rendersButton, resolveStateValue, useRender };
27
27
 
28
28
  //# sourceMappingURL=use-render.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-render.mjs","names":[],"sources":["../../src/internal/use-render.tsx"],"sourcesContent":["\"use client\";\nimport { isValidElement, useMemo } from \"react\";\nimport type { ReactNode, Ref } from \"react\";\nimport { mergeRefs } from \"./merge-props.js\";\nimport { renderElement } from \"./render-element.js\";\nimport type { ElementLikeProps, RenderElementOptions } from \"./render-element.js\";\n\nexport {\n disabledButton,\n isHostButton,\n rendersButton,\n resolveStateValue,\n} from \"./render-element.js\";\nexport type { DataAttributes } from \"./render-element.js\";\n\nexport interface UseRenderOptions<Props extends ElementLikeProps, State> extends Omit<\n RenderElementOptions<Props, State>,\n \"ref\"\n> {\n /** The library's own ref, if the part needs the DOM node. */\n ref?: Ref<unknown> | undefined;\n}\n\n/**\n * Resolves `render` and the function-form `className` / `style` / `children` of a part against\n * its state and produces the element (conventions 1.2, 1.3, 1.4). The pure work is\n * `renderElement` (`render-element.ts`); this hook adds the memoised ref merge.\n */\nexport function useRender<Props extends ElementLikeProps, State>(\n options: UseRenderOptions<Props, State>,\n): ReactNode {\n const { render, props, ref } = options;\n\n const consumerRef = (props as ElementLikeProps).ref;\n const elementRef = isValidElement<ElementLikeProps>(render) ? render.props.ref : undefined;\n // Memoised so that the callback ref keeps its identity across renders and React does not\n // detach and re-attach the node every time.\n const mergedRef = useMemo(\n () => mergeRefs(ref, consumerRef, elementRef),\n [ref, consumerRef, elementRef],\n );\n\n return renderElement<Props, State>({ ...options, ref: mergedRef });\n}\n"],"mappings":";;;;;;;;;;AA4BA,SAAgB,UACd,SACW;CACX,MAAM,EAAE,QAAQ,OAAO,QAAQ;CAE/B,MAAM,cAAe,MAA2B;CAChD,MAAM,aAAa,eAAiC,MAAM,IAAI,OAAO,MAAM,MAAM,KAAA;CAGjF,MAAM,YAAY,cACV,UAAU,KAAK,aAAa,UAAU,GAC5C;EAAC;EAAK;EAAa;CAAU,CAC/B;CAEA,OAAO,cAA4B;EAAE,GAAG;EAAS,KAAK;CAAU,CAAC;AACnE"}
1
+ {"version":3,"file":"use-render.mjs","names":[],"sources":["../../src/internal/use-render.tsx"],"sourcesContent":["\"use client\";\nimport { isValidElement, useMemo } from \"react\";\nimport type { ReactNode, Ref } from \"react\";\nimport { mergeRefs } from \"./merge-props.js\";\nimport { renderElement } from \"./render-element.js\";\nimport type { ElementLikeProps, RenderElementOptions } from \"./render-element.js\";\n\nexport {\n cancelClick,\n disabledButton,\n isHostButton,\n rendersButton,\n resolveStateValue,\n} from \"./render-element.js\";\nexport type { DataAttributes } from \"./render-element.js\";\n\nexport interface UseRenderOptions<Props extends ElementLikeProps, State> extends Omit<\n RenderElementOptions<Props, State>,\n \"ref\"\n> {\n /** The library's own ref, if the part needs the DOM node. */\n ref?: Ref<unknown> | undefined;\n}\n\n/**\n * Resolves `render` and the function-form `className` / `style` / `children` of a part against\n * its state and produces the element (conventions 1.2, 1.3, 1.4). The pure work is\n * `renderElement` (`render-element.ts`); this hook adds the memoised ref merge.\n */\nexport function useRender<Props extends ElementLikeProps, State>(\n options: UseRenderOptions<Props, State>,\n): ReactNode {\n const { render, props, ref } = options;\n\n const consumerRef = (props as ElementLikeProps).ref;\n const elementRef = isValidElement<ElementLikeProps>(render) ? render.props.ref : undefined;\n // Memoised so that the callback ref keeps its identity across renders and React does not\n // detach and re-attach the node every time.\n const mergedRef = useMemo(\n () => mergeRefs(ref, consumerRef, elementRef),\n [ref, consumerRef, elementRef],\n );\n\n return renderElement<Props, State>({ ...options, ref: mergedRef });\n}\n"],"mappings":";;;;;;;;;;AA6BA,SAAgB,UACd,SACW;CACX,MAAM,EAAE,QAAQ,OAAO,QAAQ;CAE/B,MAAM,cAAe,MAA2B;CAChD,MAAM,aAAa,eAAiC,MAAM,IAAI,OAAO,MAAM,MAAM,KAAA;CAGjF,MAAM,YAAY,cACV,UAAU,KAAK,aAAa,UAAU,GAC5C;EAAC;EAAK;EAAa;CAAU,CAC/B;CAEA,OAAO,cAA4B;EAAE,GAAG;EAAS,KAAK;CAAU,CAAC;AACnE"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-roving-focus.mjs","names":[],"sources":["../../src/internal/use-roving-focus.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useInsertionEffect, useLayoutEffect, useState } from \"react\";\nimport type { FocusEvent, KeyboardEvent, PointerEvent, RefObject } from \"react\";\nimport { focusWithRing, resolveArrowKey } from \"./arrow-keys.js\";\nimport type { Orientation } from \"./types.js\";\n\n// The roving-focus engine shared by `Toolbar.Root` and a standalone `ToggleGroup.Root`\n// (design/components/toggle-group.md section 6, conventions 3.2 and 7.4). Items are the focusable\n// descendants of the container, found in the DOM; which one is the Tab stop is urgent library\n// state kept outside React and written to the items as `tabindex` through the DOM.\n\nexport type RovingOrientation = Orientation;\n\nexport interface RovingFocusOptions {\n /** `false`: the engine writes nothing and handles nothing (a ToggleGroup inside a Toolbar). Default `true`. */\n readonly enabled?: boolean;\n readonly orientation: RovingOrientation;\n readonly loop: boolean;\n /** The native `focusgroup` path is active: write no `tabindex`, handle no navigation key. */\n readonly native: boolean;\n /** Which item is the Tab stop when there is no usable memory. */\n readonly entry: (items: readonly HTMLElement[]) => HTMLElement | undefined;\n /**\n * `true`: the last focused item stays the Tab stop after focus leaves (Toolbar). `false`: while\n * focus is inside, the focused item is the stop (so Tab and Shift+Tab leave the container);\n * once it leaves, the stop is re-derived from `entry` (ToggleGroup: the pressed Item).\n */\n readonly memory: boolean;\n}\n\nexport interface RovingFocusHandlers {\n readonly onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;\n readonly onFocus: (event: FocusEvent<HTMLElement>) => void;\n readonly onBlur: (event: FocusEvent<HTMLElement>) => void;\n readonly onPointerDown: (event: PointerEvent<HTMLElement>) => void;\n}\n\nconst FOCUSABLE = [\n \"button\",\n \"a[href]\",\n 'input:not([type=\"hidden\"])',\n \"select\",\n \"textarea\",\n \"summary\",\n '[contenteditable]:not([contenteditable=\"false\"])',\n \"[tabindex]\",\n].join(\",\");\n\nfunction isVisible(el: HTMLElement): boolean {\n // jsdom has no `checkVisibility`; `hidden` is the part of it a test can observe there.\n if (typeof el.checkVisibility === \"function\") return el.checkVisibility();\n return el.closest(\"[hidden]\") === null;\n}\n\n/**\n * Whether `el` or an ancestor below `root` takes it out of `root`'s sequence: a nested toolbar\n * (its own sequence), a popover or a dialog rendered inside the container (a `Menu.Popup`'s items\n * are the menu's).\n */\nfunction isNestedOut(el: HTMLElement, root: HTMLElement): boolean {\n for (let node: Element | null = el; node !== null && node !== root; node = node.parentElement) {\n if (\n node.getAttribute(\"role\") === \"toolbar\" ||\n node.hasAttribute(\"popover\") ||\n node.tagName === \"DIALOG\"\n ) {\n return true;\n }\n }\n return false;\n}\n\nfunction isRadio(el: Element): el is HTMLInputElement {\n return el instanceof HTMLInputElement && el.type === \"radio\";\n}\n\n/** The items of a container, with native radio groups collapsed into units (design 17.2). */\nexport interface RovingItems {\n /** The toolbar's own destinations in DOM order; a radio unit appears as its representative. */\n readonly items: HTMLElement[];\n /**\n * Every native radio among the candidates → the radios of its unit (same `name` under the\n * container, DOM order). A radio without a `name` is a unit of one.\n */\n readonly units: Map<HTMLElement, readonly HTMLInputElement[]>;\n}\n\n/** The unit's representative: its checked radio, else its first (design 17.2 item 2). */\nfunction representative(unit: readonly HTMLInputElement[]): HTMLInputElement {\n return unit.find((radio) => radio.checked) ?? unit[0]!;\n}\n\n/**\n * The items of `root` (design 6.2 and 17.2): its focusable descendants minus `:disabled`,\n * `inert`, invisible, nested-toolbar / popover / dialog content, and elements whose own\n * `tabindex=\"-1\"` was not written by this engine (`managed`). `aria-disabled` elements are items.\n * Native radios that share a `name` form one unit, represented in `items` by its checked radio\n * (else its first), at the position of the unit's first radio.\n */\nexport function collectItems(\n root: HTMLElement,\n managed: { has(el: Element): boolean },\n): RovingItems {\n const candidates: HTMLElement[] = [];\n const byName = new Map<string, HTMLInputElement[]>();\n const units = new Map<HTMLElement, readonly HTMLInputElement[]>();\n for (const el of root.querySelectorAll<HTMLElement>(FOCUSABLE)) {\n if (el.matches(\":disabled\")) continue;\n if (el.closest(\"[inert]\") !== null) continue;\n if (el.getAttribute(\"tabindex\") === \"-1\" && !managed.has(el)) continue;\n if (isNestedOut(el, root)) continue;\n if (!isVisible(el)) continue;\n if (isRadio(el)) {\n // Same form owner assumed: a `form=` attribute that splits a `name` is not handled (v1).\n const unit = el.name === \"\" ? undefined : byName.get(el.name);\n if (unit !== undefined) {\n unit.push(el);\n units.set(el, unit);\n continue;\n }\n const created = [el];\n if (el.name !== \"\") byName.set(el.name, created);\n units.set(el, created);\n }\n candidates.push(el);\n }\n // `candidates` holds each unit's first radio in its place; swap in the representative.\n const items = candidates.map((el) => {\n const unit = units.get(el);\n return unit === undefined ? el : representative(unit);\n });\n return { items, units };\n}\n\n/** {@link collectItems}'s `items`: the container's destinations in DOM order. */\nexport function itemsOf(root: HTMLElement, managed: { has(el: Element): boolean }): HTMLElement[] {\n return collectItems(root, managed).items;\n}\n\nconst BUTTON_LIKE_INPUTS = new Set([\n \"button\",\n \"submit\",\n \"reset\",\n \"checkbox\",\n \"image\",\n \"color\",\n \"file\",\n]);\nconst ARROW_OWNING_ROLES = new Set([\"textbox\", \"combobox\", \"spinbutton\", \"slider\"]);\n\n/**\n * An item that owns the arrow keys (design 6.3 and 17.2): text-like `input`s, `textarea`,\n * `select`, `[contenteditable]`, `role` `textbox` / `combobox` / `spinbutton` / `slider`, and a\n * native `input[type=radio]` (its group's own arrows check as they move). A custom\n * `[role=\"radio\"]` is an ordinary item, as it is under native `focusgroup`.\n */\nexport function ownsArrows(el: Element): boolean {\n const role = el.getAttribute(\"role\");\n if (role !== null && ARROW_OWNING_ROLES.has(role)) return true;\n if (el instanceof HTMLInputElement) return !BUTTON_LIKE_INPUTS.has(el.type);\n if (el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement) return true;\n const editable = el.getAttribute(\"contenteditable\");\n if (editable !== null && editable !== \"false\") return true;\n return el instanceof HTMLElement && el.isContentEditable === true;\n}\n\ninterface Engine {\n /** The options of the last committed render (written from an insertion effect). */\n readonly setOptions: (options: RovingFocusOptions) => void;\n /**\n * Re-derives the Tab stop of `root` and writes `tabindex`. `focused`: the element focus is on,\n * if any.\n */\n readonly apply: (root: HTMLElement | null, focused: Element | null) => void;\n readonly handlers: RovingFocusHandlers;\n}\n\nfunction createEngine(): Engine {\n let current: HTMLElement | null = null;\n let latestOptions: RovingFocusOptions | null = null;\n /**\n * Elements this engine wrote `tabindex` on, with the attribute value they had before the first\n * write (`null`: none). Restored when the engine lets go of an element (native path, element\n * left the container): React does not re-write a `tabIndex` prop it believes it rendered, so a\n * `[tabindex=\"0\"]` widget would otherwise become unreachable.\n */\n const managed = new Map<HTMLElement, string | null>();\n\n const restore = (el: HTMLElement) => {\n const original = managed.get(el);\n managed.delete(el);\n if (!el.isConnected || original === undefined) return;\n if (original === null) el.removeAttribute(\"tabindex\");\n else el.setAttribute(\"tabindex\", original);\n };\n\n const active = (options: RovingFocusOptions | null): options is RovingFocusOptions =>\n options !== null && options.enabled !== false;\n\n /** Native path: give back every `tabindex` this engine wrote (a hydration render may have). */\n const release = () => {\n for (const el of [...managed.keys()]) restore(el);\n current = null;\n };\n\n const apply = (root: HTMLElement | null, focused: Element | null) => {\n const options = latestOptions;\n if (root === null || !active(options)) return;\n if (options.native) {\n release();\n return;\n }\n const { items, units } = collectItems(root, managed);\n /** Every element the engine writes: the items and the other radios of their units. */\n const all = new Set<HTMLElement>(items);\n for (const radio of units.keys()) all.add(radio);\n /** The item standing for `el`: its unit's representative for a radio, else itself. */\n const itemOf = (el: HTMLElement): HTMLElement => {\n const unit = units.get(el);\n return unit === undefined ? el : representative(unit);\n };\n if (!options.memory) {\n current =\n focused instanceof HTMLElement && all.has(focused)\n ? focused\n : (options.entry(items) ?? null);\n } else if (current === null || !all.has(current) || !items.includes(itemOf(current))) {\n current = options.entry(items) ?? null;\n }\n // `current` may be any radio of its unit (focus landed on an unchecked one): `0` on it, `-1`\n // on the unit's other radios and on every other element (design 17.2 item 5).\n for (const el of all) {\n if (!managed.has(el)) managed.set(el, el.getAttribute(\"tabindex\"));\n const want = el === current ? \"0\" : \"-1\";\n if (el.getAttribute(\"tabindex\") !== want) el.setAttribute(\"tabindex\", want);\n }\n // Elements written before that are no longer items: a stale `0` must not stay a Tab stop\n // (it would be one again when re-enabled); one that left the container gets its own back.\n for (const el of [...managed.keys()]) {\n if (all.has(el)) continue;\n if (!root.contains(el)) {\n restore(el);\n } else if (el.getAttribute(\"tabindex\") !== \"-1\") {\n el.setAttribute(\"tabindex\", \"-1\");\n }\n }\n };\n\n const onFocus = (event: FocusEvent<HTMLElement>) => {\n const options = latestOptions;\n if (!active(options) || options.native) return;\n const target = event.target;\n if (!(target instanceof HTMLElement)) return;\n const { items, units } = collectItems(event.currentTarget, managed);\n if (!items.includes(target) && !units.has(target)) return;\n current = target;\n apply(event.currentTarget, target);\n };\n\n const onBlur = (event: FocusEvent<HTMLElement>) => {\n const options = latestOptions;\n if (!active(options) || options.native || options.memory) return;\n // Focus moving to another item is handled by its focus event.\n const next = event.relatedTarget;\n if (next instanceof Node && event.currentTarget.contains(next)) return;\n apply(event.currentTarget, null);\n };\n\n const onPointerDown = (event: PointerEvent<HTMLElement>) => {\n const options = latestOptions;\n if (!active(options) || options.native) return;\n const target = event.target;\n if (!(target instanceof Node)) return;\n const { items, units } = collectItems(event.currentTarget, managed);\n // Safari does not focus a button on click; the pointer still makes it the stop.\n const item = [...items, ...units.keys()].find((el) => el.contains(target));\n if (item === undefined) return;\n current = item;\n apply(\n event.currentTarget,\n options.memory ? item : event.currentTarget.ownerDocument.activeElement,\n );\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {\n if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;\n const options = latestOptions;\n // The browser moves focus itself where `focusgroup` is implemented.\n if (!active(options) || options.native) return;\n const root = event.currentTarget;\n const target = event.target;\n if (!(target instanceof HTMLElement)) return;\n const { items, units } = collectItems(root, managed);\n const unit = units.get(target);\n // A radio stands in `items` through its unit's representative.\n const index = items.indexOf(unit === undefined ? target : representative(unit));\n if (index < 0) return;\n\n if (ownsArrows(target)) {\n // The item keeps its arrows, Home and End; Tab / Shift+Tab move to the next / previous item\n // while one exists, as Chromium's `focusgroup=\"toolbar\"` does (design 6.3, 17.2 item 4).\n if (event.key !== \"Tab\") return;\n // From an unchecked radio whose sibling is checked: that sibling first (only the checked\n // radio of a group is sequentially focusable natively).\n const checked = unit?.find((radio) => radio.checked);\n if (checked !== undefined && checked !== target) {\n event.preventDefault();\n focusWithRing(checked);\n return;\n }\n const next = items[index + (event.shiftKey ? -1 : 1)];\n if (next === undefined) return;\n event.preventDefault();\n focusWithRing(next);\n return;\n }\n\n const rtl = options.orientation === \"horizontal\" && getComputedStyle(root).direction === \"rtl\";\n const move = resolveArrowKey(event.key, options.orientation, rtl);\n if (move === null) return;\n event.preventDefault();\n const last = items.length - 1;\n let nextIndex: number;\n switch (move) {\n case \"first\":\n nextIndex = 0;\n break;\n case \"last\":\n nextIndex = last;\n break;\n case \"next\":\n nextIndex = index >= last ? (options.loop ? 0 : last) : index + 1;\n break;\n case \"prev\":\n nextIndex = index <= 0 ? (options.loop ? last : 0) : index - 1;\n break;\n }\n const next = items[nextIndex];\n if (next !== undefined && next !== target) focusWithRing(next);\n };\n\n return {\n setOptions: (options) => {\n latestOptions = options;\n },\n apply,\n handlers: { onFocus, onBlur, onPointerDown, onKeyDown },\n };\n}\n\n/**\n * Roving focus over the focusable descendants of `ref`'s element (design 6.2). Writes `tabindex`\n * (`0` on the Tab stop, `-1` on the other items) from a layout effect after every commit of the\n * calling component, from a `MutationObserver` on the subtree and from focus / pointer events;\n * the items render none. Returns the container's handlers for its library props.\n */\nexport function useRovingFocus(\n ref: RefObject<HTMLElement | null>,\n options: RovingFocusOptions,\n): RovingFocusHandlers {\n const [engine] = useState(createEngine);\n // Before every layout effect of the same commit (as `useLatest`): handlers and the observer\n // read the options of the last committed render.\n useInsertionEffect(() => {\n engine.setOptions(options);\n });\n const enabled = options.enabled !== false;\n\n // After every commit of the container (a deps-less layout effect).\n useLayoutEffect(() => {\n const root = ref.current;\n engine.apply(root, root?.ownerDocument.activeElement ?? null);\n });\n\n // Children that change without the container re-rendering.\n useEffect(() => {\n const root = ref.current;\n if (!enabled || root === null) return;\n const observer = new MutationObserver(() => {\n engine.apply(root, root.ownerDocument.activeElement);\n });\n observer.observe(root, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: [\"disabled\", \"hidden\", \"inert\", \"aria-disabled\"],\n });\n return () => {\n observer.disconnect();\n };\n }, [engine, enabled, ref]);\n\n return engine.handlers;\n}\n"],"mappings":";;;;AAqCA,MAAM,YAAY;CAChB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,GAAG;AAEV,SAAS,UAAU,IAA0B;CAE3C,IAAI,OAAO,GAAG,oBAAoB,YAAY,OAAO,GAAG,gBAAgB;CACxE,OAAO,GAAG,QAAQ,UAAU,MAAM;AACpC;;;;;;AAOA,SAAS,YAAY,IAAiB,MAA4B;CAChE,KAAK,IAAI,OAAuB,IAAI,SAAS,QAAQ,SAAS,MAAM,OAAO,KAAK,eAC9E,IACE,KAAK,aAAa,MAAM,MAAM,aAC9B,KAAK,aAAa,SAAS,KAC3B,KAAK,YAAY,UAEjB,OAAO;CAGX,OAAO;AACT;AAEA,SAAS,QAAQ,IAAqC;CACpD,OAAO,cAAc,oBAAoB,GAAG,SAAS;AACvD;;AAcA,SAAS,e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use-roving-focus.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useInsertionEffect, useLayoutEffect, useState } from \"react\";\nimport type { FocusEvent, KeyboardEvent, PointerEvent, RefObject } from \"react\";\nimport { focusWithRing, resolveArrowKey } from \"./arrow-keys.js\";\nimport type { Orientation } from \"./types.js\";\n\n// The roving-focus engine shared by `Toolbar.Root` and a standalone `ToggleGroup.Root`\n// (design/components/toggle-group.md section 6, conventions 3.2 and 7.4). Items are the focusable\n// descendants of the container, found in the DOM; which one is the Tab stop is urgent library\n// state kept outside React and written to the items as `tabindex` through the DOM.\n\nexport type RovingOrientation = Orientation;\n\nexport interface RovingFocusOptions {\n /** `false`: the engine writes nothing and handles nothing (a ToggleGroup inside a Toolbar). Default `true`. */\n readonly enabled?: boolean;\n readonly orientation: RovingOrientation;\n readonly loop: boolean;\n /** The native `focusgroup` path is active: write no `tabindex`, handle no navigation key. */\n readonly native: boolean;\n /** Which item is the Tab stop when there is no usable memory. */\n readonly entry: (items: readonly HTMLElement[]) => HTMLElement | undefined;\n /**\n * `true`: the last focused item stays the Tab stop after focus leaves (Toolbar). `false`: while\n * focus is inside, the focused item is the stop (so Tab and Shift+Tab leave the container);\n * once it leaves, the stop is re-derived from `entry` (ToggleGroup: the pressed Item).\n */\n readonly memory: boolean;\n}\n\nexport interface RovingFocusHandlers {\n readonly onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;\n readonly onFocus: (event: FocusEvent<HTMLElement>) => void;\n readonly onBlur: (event: FocusEvent<HTMLElement>) => void;\n readonly onPointerDown: (event: PointerEvent<HTMLElement>) => void;\n}\n\n// What may hold the roving tab stop; narrower than Menu's and Tooltip's selectors on purpose.\nconst FOCUSABLE = [\n \"button\",\n \"a[href]\",\n 'input:not([type=\"hidden\"])',\n \"select\",\n \"textarea\",\n \"summary\",\n '[contenteditable]:not([contenteditable=\"false\"])',\n \"[tabindex]\",\n].join(\",\");\n\nfunction isVisible(el: HTMLElement): boolean {\n // jsdom has no `checkVisibility`; `hidden` is the part of it a test can observe there.\n if (typeof el.checkVisibility === \"function\") return el.checkVisibility();\n return el.closest(\"[hidden]\") === null;\n}\n\n/**\n * Whether `el` or an ancestor below `root` takes it out of `root`'s sequence: a nested toolbar\n * (its own sequence), a popover or a dialog rendered inside the container (a `Menu.Popup`'s items\n * are the menu's).\n */\nfunction isNestedOut(el: HTMLElement, root: HTMLElement): boolean {\n for (let node: Element | null = el; node !== null && node !== root; node = node.parentElement) {\n if (\n node.getAttribute(\"role\") === \"toolbar\" ||\n node.hasAttribute(\"popover\") ||\n node.tagName === \"DIALOG\"\n ) {\n return true;\n }\n }\n return false;\n}\n\nfunction isRadio(el: Element): el is HTMLInputElement {\n return el instanceof HTMLInputElement && el.type === \"radio\";\n}\n\n/** The items of a container, with native radio groups collapsed into units (design 17.2). */\nexport interface RovingItems {\n /** The toolbar's own destinations in DOM order; a radio unit appears as its representative. */\n readonly items: HTMLElement[];\n /**\n * Every native radio among the candidates → the radios of its unit (same `name` under the\n * container, DOM order). A radio without a `name` is a unit of one.\n */\n readonly units: Map<HTMLElement, readonly HTMLInputElement[]>;\n}\n\n/** The unit's representative: its checked radio, else its first (design 17.2 item 2). */\nfunction representative(unit: readonly HTMLInputElement[]): HTMLInputElement {\n return unit.find((radio) => radio.checked) ?? unit[0]!;\n}\n\n/**\n * The items of `root` (design 6.2 and 17.2): its focusable descendants minus `:disabled`,\n * `inert`, invisible, nested-toolbar / popover / dialog content, and elements whose own\n * `tabindex=\"-1\"` was not written by this engine (`managed`). `aria-disabled` elements are items.\n * Native radios that share a `name` form one unit, represented in `items` by its checked radio\n * (else its first), at the position of the unit's first radio.\n */\nexport function collectItems(\n root: HTMLElement,\n managed: { has(el: Element): boolean },\n): RovingItems {\n const candidates: HTMLElement[] = [];\n const byName = new Map<string, HTMLInputElement[]>();\n const units = new Map<HTMLElement, readonly HTMLInputElement[]>();\n for (const el of root.querySelectorAll<HTMLElement>(FOCUSABLE)) {\n if (el.matches(\":disabled\")) continue;\n if (el.closest(\"[inert]\") !== null) continue;\n if (el.getAttribute(\"tabindex\") === \"-1\" && !managed.has(el)) continue;\n if (isNestedOut(el, root)) continue;\n if (!isVisible(el)) continue;\n if (isRadio(el)) {\n // Same form owner assumed: a `form=` attribute that splits a `name` is not handled (v1).\n const unit = el.name === \"\" ? undefined : byName.get(el.name);\n if (unit !== undefined) {\n unit.push(el);\n units.set(el, unit);\n continue;\n }\n const created = [el];\n if (el.name !== \"\") byName.set(el.name, created);\n units.set(el, created);\n }\n candidates.push(el);\n }\n // `candidates` holds each unit's first radio in its place; swap in the representative.\n const items = candidates.map((el) => {\n const unit = units.get(el);\n return unit === undefined ? el : representative(unit);\n });\n return { items, units };\n}\n\n/** {@link collectItems}'s `items`: the container's destinations in DOM order. */\nexport function itemsOf(root: HTMLElement, managed: { has(el: Element): boolean }): HTMLElement[] {\n return collectItems(root, managed).items;\n}\n\nconst BUTTON_LIKE_INPUTS = new Set([\n \"button\",\n \"submit\",\n \"reset\",\n \"checkbox\",\n \"image\",\n \"color\",\n \"file\",\n]);\nconst ARROW_OWNING_ROLES = new Set([\"textbox\", \"combobox\", \"spinbutton\", \"slider\"]);\n\n/**\n * An item that owns the arrow keys (design 6.3 and 17.2): text-like `input`s, `textarea`,\n * `select`, `[contenteditable]`, `role` `textbox` / `combobox` / `spinbutton` / `slider`, and a\n * native `input[type=radio]` (its group's own arrows check as they move). A custom\n * `[role=\"radio\"]` is an ordinary item, as it is under native `focusgroup`.\n */\nexport function ownsArrows(el: Element): boolean {\n const role = el.getAttribute(\"role\");\n if (role !== null && ARROW_OWNING_ROLES.has(role)) return true;\n if (el instanceof HTMLInputElement) return !BUTTON_LIKE_INPUTS.has(el.type);\n if (el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement) return true;\n const editable = el.getAttribute(\"contenteditable\");\n if (editable !== null && editable !== \"false\") return true;\n return el instanceof HTMLElement && el.isContentEditable === true;\n}\n\ninterface Engine {\n /** The options of the last committed render (written from an insertion effect). */\n readonly setOptions: (options: RovingFocusOptions) => void;\n /**\n * Re-derives the Tab stop of `root` and writes `tabindex`. `focused`: the element focus is on,\n * if any.\n */\n readonly apply: (root: HTMLElement | null, focused: Element | null) => void;\n readonly handlers: RovingFocusHandlers;\n}\n\nfunction createEngine(): Engine {\n let current: HTMLElement | null = null;\n let latestOptions: RovingFocusOptions | null = null;\n /**\n * Elements this engine wrote `tabindex` on, with the attribute value they had before the first\n * write (`null`: none). Restored when the engine lets go of an element (native path, element\n * left the container): React does not re-write a `tabIndex` prop it believes it rendered, so a\n * `[tabindex=\"0\"]` widget would otherwise become unreachable.\n */\n const managed = new Map<HTMLElement, string | null>();\n\n const restore = (el: HTMLElement) => {\n const original = managed.get(el);\n managed.delete(el);\n if (!el.isConnected || original === undefined) return;\n if (original === null) el.removeAttribute(\"tabindex\");\n else el.setAttribute(\"tabindex\", original);\n };\n\n const active = (options: RovingFocusOptions | null): options is RovingFocusOptions =>\n options !== null && options.enabled !== false;\n\n /** Native path: give back every `tabindex` this engine wrote (a hydration render may have). */\n const release = () => {\n for (const el of [...managed.keys()]) restore(el);\n current = null;\n };\n\n const apply = (root: HTMLElement | null, focused: Element | null) => {\n const options = latestOptions;\n if (root === null || !active(options)) return;\n if (options.native) {\n release();\n return;\n }\n const { items, units } = collectItems(root, managed);\n /** Every element the engine writes: the items and the other radios of their units. */\n const all = new Set<HTMLElement>(items);\n for (const radio of units.keys()) all.add(radio);\n /** The item standing for `el`: its unit's representative for a radio, else itself. */\n const itemOf = (el: HTMLElement): HTMLElement => {\n const unit = units.get(el);\n return unit === undefined ? el : representative(unit);\n };\n if (!options.memory) {\n current =\n focused instanceof HTMLElement && all.has(focused)\n ? focused\n : (options.entry(items) ?? null);\n } else if (current === null || !all.has(current) || !items.includes(itemOf(current))) {\n current = options.entry(items) ?? null;\n }\n // `current` may be any radio of its unit (focus landed on an unchecked one): `0` on it, `-1`\n // on the unit's other radios and on every other element (design 17.2 item 5).\n for (const el of all) {\n if (!managed.has(el)) managed.set(el, el.getAttribute(\"tabindex\"));\n const want = el === current ? \"0\" : \"-1\";\n if (el.getAttribute(\"tabindex\") !== want) el.setAttribute(\"tabindex\", want);\n }\n // Elements written before that are no longer items: a stale `0` must not stay a Tab stop\n // (it would be one again when re-enabled); one that left the container gets its own back.\n for (const el of [...managed.keys()]) {\n if (all.has(el)) continue;\n if (!root.contains(el)) {\n restore(el);\n } else if (el.getAttribute(\"tabindex\") !== \"-1\") {\n el.setAttribute(\"tabindex\", \"-1\");\n }\n }\n };\n\n const onFocus = (event: FocusEvent<HTMLElement>) => {\n const options = latestOptions;\n if (!active(options) || options.native) return;\n const target = event.target;\n if (!(target instanceof HTMLElement)) return;\n const { items, units } = collectItems(event.currentTarget, managed);\n if (!items.includes(target) && !units.has(target)) return;\n current = target;\n apply(event.currentTarget, target);\n };\n\n const onBlur = (event: FocusEvent<HTMLElement>) => {\n const options = latestOptions;\n if (!active(options) || options.native || options.memory) return;\n // Focus moving to another item is handled by its focus event.\n const next = event.relatedTarget;\n if (next instanceof Node && event.currentTarget.contains(next)) return;\n apply(event.currentTarget, null);\n };\n\n const onPointerDown = (event: PointerEvent<HTMLElement>) => {\n const options = latestOptions;\n if (!active(options) || options.native) return;\n const target = event.target;\n if (!(target instanceof Node)) return;\n const { items, units } = collectItems(event.currentTarget, managed);\n // Safari does not focus a button on click; the pointer still makes it the stop.\n const item = [...items, ...units.keys()].find((el) => el.contains(target));\n if (item === undefined) return;\n current = item;\n apply(\n event.currentTarget,\n options.memory ? item : event.currentTarget.ownerDocument.activeElement,\n );\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {\n if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;\n const options = latestOptions;\n // The browser moves focus itself where `focusgroup` is implemented.\n if (!active(options) || options.native) return;\n const root = event.currentTarget;\n const target = event.target;\n if (!(target instanceof HTMLElement)) return;\n const { items, units } = collectItems(root, managed);\n const unit = units.get(target);\n // A radio stands in `items` through its unit's representative.\n const index = items.indexOf(unit === undefined ? target : representative(unit));\n if (index < 0) return;\n\n if (ownsArrows(target)) {\n // The item keeps its arrows, Home and End; Tab / Shift+Tab move to the next / previous item\n // while one exists, as Chromium's `focusgroup=\"toolbar\"` does (design 6.3, 17.2 item 4).\n if (event.key !== \"Tab\") return;\n // From an unchecked radio whose sibling is checked: that sibling first (only the checked\n // radio of a group is sequentially focusable natively).\n const checked = unit?.find((radio) => radio.checked);\n if (checked !== undefined && checked !== target) {\n event.preventDefault();\n focusWithRing(checked);\n return;\n }\n const next = items[index + (event.shiftKey ? -1 : 1)];\n if (next === undefined) return;\n event.preventDefault();\n focusWithRing(next);\n return;\n }\n\n const rtl = options.orientation === \"horizontal\" && getComputedStyle(root).direction === \"rtl\";\n const move = resolveArrowKey(event.key, options.orientation, rtl);\n if (move === null) return;\n event.preventDefault();\n const last = items.length - 1;\n let nextIndex: number;\n switch (move) {\n case \"first\":\n nextIndex = 0;\n break;\n case \"last\":\n nextIndex = last;\n break;\n case \"next\":\n nextIndex = index >= last ? (options.loop ? 0 : last) : index + 1;\n break;\n case \"prev\":\n nextIndex = index <= 0 ? (options.loop ? last : 0) : index - 1;\n break;\n }\n const next = items[nextIndex];\n if (next !== undefined && next !== target) focusWithRing(next);\n };\n\n return {\n setOptions: (options) => {\n latestOptions = options;\n },\n apply,\n handlers: { onFocus, onBlur, onPointerDown, onKeyDown },\n };\n}\n\n/**\n * Roving focus over the focusable descendants of `ref`'s element (design 6.2). Writes `tabindex`\n * (`0` on the Tab stop, `-1` on the other items) from a layout effect after every commit of the\n * calling component, from a `MutationObserver` on the subtree and from focus / pointer events;\n * the items render none. Returns the container's handlers for its library props.\n */\nexport function useRovingFocus(\n ref: RefObject<HTMLElement | null>,\n options: RovingFocusOptions,\n): RovingFocusHandlers {\n const [engine] = useState(createEngine);\n // Before every layout effect of the same commit (as `useLatest`): handlers and the observer\n // read the options of the last committed render.\n useInsertionEffect(() => {\n engine.setOptions(options);\n });\n const enabled = options.enabled !== false;\n\n // After every commit of the container (a deps-less layout effect).\n useLayoutEffect(() => {\n const root = ref.current;\n engine.apply(root, root?.ownerDocument.activeElement ?? null);\n });\n\n // Children that change without the container re-rendering.\n useEffect(() => {\n const root = ref.current;\n if (!enabled || root === null) return;\n const observer = new MutationObserver(() => {\n engine.apply(root, root.ownerDocument.activeElement);\n });\n observer.observe(root, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: [\"disabled\", \"hidden\", \"inert\", \"aria-disabled\"],\n });\n return () => {\n observer.disconnect();\n };\n }, [engine, enabled, ref]);\n\n return engine.handlers;\n}\n"],"mappings":";;;;AAsCA,MAAM,YAAY;CAChB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,GAAG;AAEV,SAAS,UAAU,IAA0B;CAE3C,IAAI,OAAO,GAAG,oBAAoB,YAAY,OAAO,GAAG,gBAAgB;CACxE,OAAO,GAAG,QAAQ,UAAU,MAAM;AACpC;;;;;;AAOA,SAAS,YAAY,IAAiB,MAA4B;CAChE,KAAK,IAAI,OAAuB,IAAI,SAAS,QAAQ,SAAS,MAAM,OAAO,KAAK,eAC9E,IACE,KAAK,aAAa,MAAM,MAAM,aAC9B,KAAK,aAAa,SAAS,KAC3B,KAAK,YAAY,UAEjB,OAAO;CAGX,OAAO;AACT;AAEA,SAAS,QAAQ,IAAqC;CACpD,OAAO,cAAc,oBAAoB,GAAG,SAAS;AACvD;;AAcA,SAAS,eAAe,MAAqD;CAC3E,OAAO,KAAK,MAAM,UAAU,MAAM,OAAO,KAAK,KAAK;AACrD;;;;;;;;AASA,SAAgB,aACd,MACA,SACa;CACb,MAAM,aAA4B,CAAC;CACnC,MAAM,yBAAS,IAAI,IAAgC;CACnD,MAAM,wBAAQ,IAAI,IAA8C;CAChE,KAAK,MAAM,MAAM,KAAK,iBAA8B,SAAS,GAAG;EAC9D,IAAI,GAAG,QAAQ,WAAW,GAAG;EAC7B,IAAI,GAAG,QAAQ,SAAS,MAAM,MAAM;EACpC,IAAI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EAEjE;EACA,MAAM,OAAO,MAAM;EACnB,IAAI,SAAS,KAAA,KAAa,SAAS,QAAQ,cAAc,IAAI;CAC/D;CAEA,OAAO;EACL,aAAa,YAAY;GACvB,gBAAgB;EAClB;EACA;EACA,UAAU;GAAE;GAAS;GAAQ;GAAe;EAAU;CACxD;AACF;;;;;;;AAQA,SAAgB,eACd,KACA,SACqB;CACrB,MAAM,CAAC,UAAU,SAAS,YAAY;CAGtC,yBAAyB;EACvB,OAAO,WAAW,OAAO;CAC3B,CAAC;CACD,MAAM,UAAU,QAAQ,YAAY;CAGpC,sBAAsB;EACpB,MAAM,OAAO,IAAI;EACjB,OAAO,MAAM,MAAM,MAAM,cAAc,iBAAiB,IAAI;CAC9D,CAAC;CAGD,gBAAgB;EACd,MAAM,OAAO,IAAI;EACjB,IAAI,CAAC,WAAW,SAAS,MAAM;EAC/B,MAAM,WAAW,IAAI,uBAAuB;GAC1C,OAAO,MAAM,MAAM,KAAK,cAAc,aAAa;EACrD,CAAC;EACD,SAAS,QAAQ,MAAM;GACrB,WAAW;GACX,SAAS;GACT,YAAY;GACZ,iBAAiB;IAAC;IAAY;IAAU;IAAS;GAAe;EAClE,CAAC;EACD,aAAa;GACX,SAAS,WAAW;EACtB;CACF,GAAG;EAAC;EAAQ;EAAS;CAAG,CAAC;CAEzB,OAAO,OAAO;AAChB"}
@@ -1,10 +1,10 @@
1
1
  "use client";
2
- import { createActionDetails } from "../internal/action-details.mjs";
2
+ import { createActionDetails } from "../internal/action/action-details.mjs";
3
3
  import { dataAttr } from "../internal/data-attr.mjs";
4
4
  import { rendersButton } from "../internal/render-element.mjs";
5
5
  import { useRender } from "../internal/use-render.mjs";
6
6
  import { transitionTypes } from "../internal/transition-types.mjs";
7
- import { useControllableAction } from "../internal/use-controllable-action.mjs";
7
+ import { useControllableAction } from "../internal/action/use-controllable-action.mjs";
8
8
  import { closeStackLater, useMenuContext } from "./menu-context.mjs";
9
9
  import { useMenuItem } from "./use-menu-item.mjs";
10
10
  import { useRef } from "react";
@@ -1 +1 @@
1
- {"version":3,"file":"menu-checkbox-item.mjs","names":[],"sources":["../../src/menu/menu-checkbox-item.tsx"],"sourcesContent":["\"use client\";\nimport { useRef } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type { ChangeAction, RenderProp, StateValue } from \"../internal/types.js\";\nimport { useControllableAction } from \"../internal/use-controllable-action.js\";\nimport { rendersButton, useRender } from \"../internal/use-render.js\";\nimport { closeStackLater, useMenuContext } from \"./menu-context.js\";\nimport type { MenuItemProps } from \"./menu-item.js\";\nimport { useMenuItem } from \"./use-menu-item.js\";\n\n/**\n * State of `Menu.CheckboxItem`, passed to the function forms of `className`, `style`, `children`\n * and `render`.\n */\nexport interface MenuCheckboxItemState {\n /** Optimistic checked state (`aria-checked`). */\n readonly checked: boolean;\n /** `checkedChangeAction` is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Menu.CheckboxItem`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport interface MenuCheckboxItemProps extends Omit<\n MenuItemProps,\n \"action\" | \"closeOnActivate\" | \"whilePending\" | \"className\" | \"style\" | \"children\" | \"render\"\n> {\n /** Controlled checked state. `undefined` means uncontrolled. */\n checked?: boolean;\n /**\n * Initial checked state when uncontrolled.\n *\n * @defaultValue `false`\n */\n defaultChecked?: boolean;\n /**\n * Awaited inside the item's transition; `aria-checked` flips at once and rolls back on\n * rejection (which reaches the nearest Error Boundary above the item). May be a Server\n * Function.\n */\n checkedChangeAction?: ChangeAction<boolean>;\n /**\n * Close the whole menu once the change settles. When `false` the menu stays open.\n *\n * @defaultValue `false`\n */\n closeOnActivate?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MenuCheckboxItemState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MenuCheckboxItemState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, MenuCheckboxItemState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MenuCheckboxItemState>;\n}\n\n/**\n * A checkable menu item: `<button type=\"button\" role=\"menuitemcheckbox\" aria-checked>`. Click,\n * Enter or Space toggles it through its own transition with optimistic `aria-checked` /\n * `data-checked` and `data-pending`; the menu stays open unless `closeOnActivate`.\n *\n * Owned keys (conventions 1.2): those of `Menu.Item`, plus `aria-checked` and `data-checked`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuCheckboxItem({\n checked,\n defaultChecked,\n checkedChangeAction,\n closeOnActivate = false,\n disabled = false,\n label,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuCheckboxItemProps) {\n const menu = useMenuContext(\"Menu.CheckboxItem\");\n // The close to run after a dispatch's action resolved, keyed by the dispatch's details.\n const after = useRef(new WeakMap<object, () => void>());\n const { optimistic, pending, dispatch } = useControllableAction<boolean>({\n controlled: checked,\n defaultValue: defaultChecked,\n initialValue: false,\n action: async (next, details) => {\n await checkedChangeAction?.(next, details);\n after.current.get(details)?.();\n },\n transitionTypes: (next) => transitionTypes(\"menu\", next ? \"check\" : \"uncheck\"),\n warn: { component: \"Menu.CheckboxItem\", prop: \"checked\" },\n });\n\n const { libraryProps } = useMenuItem({\n part: \"Menu.CheckboxItem\",\n role: \"menuitemcheckbox\",\n disabled,\n label,\n activate: (event) => {\n const details = createActionDetails(event, {});\n if (closeOnActivate) after.current.set(details, closeStackLater(menu, event));\n dispatch(!optimistic, details);\n },\n });\n\n const state: MenuCheckboxItemState = { checked: optimistic, pending, disabled };\n\n return useRender<ComponentPropsWithRef<\"button\">, MenuCheckboxItemState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n ...(rendersButton(render) && { type: \"button\" as const }),\n ...libraryProps,\n \"aria-checked\": optimistic,\n \"data-checked\": dataAttr(optimistic),\n \"data-pending\": dataAttr(pending),\n },\n });\n}\n\nMenuCheckboxItem.displayName = \"MenuCheckboxItem\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA0EA,SAAgB,iBAAiB,EAC/B,SACA,gBACA,qBACA,kBAAkB,OAClB,WAAW,OACX,OACA,WACA,OACA,UACA,QACA,GAAG,QACqB;CACxB,MAAM,OAAO,eAAe,mBAAmB;CAE/C,MAAM,QAAQ,uBAAO,IAAI,QAA4B,CAAC;CACtD,MAAM,EAAE,YAAY,SAAS,aAAa,sBAA+B;EACvE,YAAY;EACZ,cAAc;EACd,cAAc;EACd,QAAQ,OAAO,MAAM,YAAY;GAC/B,MAAM,sBAAsB,MAAM,OAAO;GACzC,MAAM,QAAQ,IAAI,OAAO,CAAC,GAAG;EAC/B;EACA,kBAAkB,SAAS,gBAAgB,QAAQ,OAAO,UAAU,SAAS;EAC7E,MAAM;GAAE,WAAW;GAAqB,MAAM;EAAU;CAC1D,CAAC;CAED,MAAM,EAAE,iBAAiB,YAAY;EACnC,MAAM;EACN,MAAM;EACN;EACA;EACA,WAAW,UAAU;GACnB,MAAM,UAAU,oBAAoB,OAAO,CAAC,CAAC;GAC7C,IAAI,iBAAiB,MAAM,QAAQ,IAAI,SAAS,gBAAgB,MAAM,KAAK,CAAC;GAC5E,SAAS,CAAC,YAAY,OAAO;EAC/B;CACF,CAAC;CAID,OAAO,UAAkE;EACvE,gBAAgB;EAChB;EACA,OAAA;GALqC,SAAS;GAAY;GAAS;EAK/D;EACJ;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;GACvD,GAAG;GACH,gBAAgB;GAChB,gBAAgB,SAAS,UAAU;GACnC,gBAAgB,SAAS,OAAO;EAClC;CACF,CAAC;AACH;AAEA,iBAAiB,cAAc"}
1
+ {"version":3,"file":"menu-checkbox-item.mjs","names":[],"sources":["../../src/menu/menu-checkbox-item.tsx"],"sourcesContent":["\"use client\";\nimport { useRef } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type { ChangeAction, RenderProp, StateValue } from \"../internal/types.js\";\nimport { useControllableAction } from \"../internal/action/use-controllable-action.js\";\nimport { rendersButton, useRender } from \"../internal/use-render.js\";\nimport { closeStackLater, useMenuContext } from \"./menu-context.js\";\nimport type { MenuItemProps } from \"./menu-item.js\";\nimport { useMenuItem } from \"./use-menu-item.js\";\n\n/**\n * State of `Menu.CheckboxItem`, passed to the function forms of `className`, `style`, `children`\n * and `render`.\n */\nexport interface MenuCheckboxItemState {\n /** Optimistic checked state (`aria-checked`). */\n readonly checked: boolean;\n /** `checkedChangeAction` is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Menu.CheckboxItem`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport interface MenuCheckboxItemProps extends Omit<\n MenuItemProps,\n \"action\" | \"closeOnActivate\" | \"whilePending\" | \"className\" | \"style\" | \"children\" | \"render\"\n> {\n /** Controlled checked state. `undefined` means uncontrolled. */\n checked?: boolean;\n /**\n * Initial checked state when uncontrolled.\n *\n * @defaultValue `false`\n */\n defaultChecked?: boolean;\n /**\n * Awaited inside the item's transition; `aria-checked` flips at once and rolls back on\n * rejection (which reaches the nearest Error Boundary above the item). May be a Server\n * Function.\n */\n checkedChangeAction?: ChangeAction<boolean>;\n /**\n * Close the whole menu once the change settles. When `false` the menu stays open.\n *\n * @defaultValue `false`\n */\n closeOnActivate?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MenuCheckboxItemState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MenuCheckboxItemState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, MenuCheckboxItemState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MenuCheckboxItemState>;\n}\n\n/**\n * A checkable menu item: `<button type=\"button\" role=\"menuitemcheckbox\" aria-checked>`. Click,\n * Enter or Space toggles it through its own transition with optimistic `aria-checked` /\n * `data-checked` and `data-pending`; the menu stays open unless `closeOnActivate`.\n *\n * Owned keys (conventions 1.2): those of `Menu.Item`, plus `aria-checked` and `data-checked`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuCheckboxItem({\n checked,\n defaultChecked,\n checkedChangeAction,\n closeOnActivate = false,\n disabled = false,\n label,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuCheckboxItemProps) {\n const menu = useMenuContext(\"Menu.CheckboxItem\");\n // The close to run after a dispatch's action resolved, keyed by the dispatch's details.\n const after = useRef(new WeakMap<object, () => void>());\n const { optimistic, pending, dispatch } = useControllableAction<boolean>({\n controlled: checked,\n defaultValue: defaultChecked,\n initialValue: false,\n action: async (next, details) => {\n await checkedChangeAction?.(next, details);\n after.current.get(details)?.();\n },\n transitionTypes: (next) => transitionTypes(\"menu\", next ? \"check\" : \"uncheck\"),\n warn: { component: \"Menu.CheckboxItem\", prop: \"checked\" },\n });\n\n const { libraryProps } = useMenuItem({\n part: \"Menu.CheckboxItem\",\n role: \"menuitemcheckbox\",\n disabled,\n label,\n activate: (event) => {\n const details = createActionDetails(event, {});\n if (closeOnActivate) after.current.set(details, closeStackLater(menu, event));\n dispatch(!optimistic, details);\n },\n });\n\n const state: MenuCheckboxItemState = { checked: optimistic, pending, disabled };\n\n return useRender<ComponentPropsWithRef<\"button\">, MenuCheckboxItemState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n ...(rendersButton(render) && { type: \"button\" as const }),\n ...libraryProps,\n \"aria-checked\": optimistic,\n \"data-checked\": dataAttr(optimistic),\n \"data-pending\": dataAttr(pending),\n },\n });\n}\n\nMenuCheckboxItem.displayName = \"MenuCheckboxItem\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA0EA,SAAgB,iBAAiB,EAC/B,SACA,gBACA,qBACA,kBAAkB,OAClB,WAAW,OACX,OACA,WACA,OACA,UACA,QACA,GAAG,QACqB;CACxB,MAAM,OAAO,eAAe,mBAAmB;CAE/C,MAAM,QAAQ,uBAAO,IAAI,QAA4B,CAAC;CACtD,MAAM,EAAE,YAAY,SAAS,aAAa,sBAA+B;EACvE,YAAY;EACZ,cAAc;EACd,cAAc;EACd,QAAQ,OAAO,MAAM,YAAY;GAC/B,MAAM,sBAAsB,MAAM,OAAO;GACzC,MAAM,QAAQ,IAAI,OAAO,CAAC,GAAG;EAC/B;EACA,kBAAkB,SAAS,gBAAgB,QAAQ,OAAO,UAAU,SAAS;EAC7E,MAAM;GAAE,WAAW;GAAqB,MAAM;EAAU;CAC1D,CAAC;CAED,MAAM,EAAE,iBAAiB,YAAY;EACnC,MAAM;EACN,MAAM;EACN;EACA;EACA,WAAW,UAAU;GACnB,MAAM,UAAU,oBAAoB,OAAO,CAAC,CAAC;GAC7C,IAAI,iBAAiB,MAAM,QAAQ,IAAI,SAAS,gBAAgB,MAAM,KAAK,CAAC;GAC5E,SAAS,CAAC,YAAY,OAAO;EAC/B;CACF,CAAC;CAID,OAAO,UAAkE;EACvE,gBAAgB;EAChB;EACA,OAAA;GALqC,SAAS;GAAY;GAAS;EAK/D;EACJ;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;GACvD,GAAG;GACH,gBAAgB;GAChB,gBAAgB,SAAS,UAAU;GACnC,gBAAgB,SAAS,OAAO;EAClC;CACF,CAAC;AACH;AAEA,iBAAiB,cAAc"}
@@ -1 +1 @@
1
- import "../internal/use-overlay-root.mjs";
1
+ import "../internal/overlay/use-overlay-root.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"menu-context.mjs","names":[],"sources":["../../src/menu/menu-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { DelayedPair } from \"../internal/use-delayed-pair.js\";\nimport type { PopoverRootValue } from \"../internal/use-overlay-root.js\";\n\n/**\n * Where focus goes when the menu opens (design/components/menu.md 6.1): the first enabled item,\n * the last one (ArrowUp on the Trigger), or nowhere (a hover-opened submenu keeps focus on its\n * SubmenuTrigger).\n */\nexport type MenuOpenCause = \"first\" | \"last\" | \"none\";\n\n/** How the open being shown should place focus (design 6.1). */\nexport interface MenuOpenFocus {\n readonly cause: MenuOpenCause;\n /**\n * The open came from a pointer click (`detail > 0`): the item is focused without the focus\n * ring where the engine supports `focus({ focusVisible: false })`.\n */\n readonly pointer: boolean;\n}\n\n/**\n * How the current open is placed (design/components/context-menu.md 3.1): against the Trigger\n * (`anchor`: a Menu.Trigger, a foreign invoker, a controlled or platform open), or at a point\n * (`point`: a Menu.ContextTrigger). `generation` grows with every point open or move, so a second\n * right-click at a new point is a state change while the menu is open (4.3).\n */\nexport type MenuPlacement =\n | { readonly kind: \"anchor\" }\n | {\n readonly kind: \"point\";\n readonly x: number;\n readonly y: number;\n readonly generation: number;\n /** The region that opened: the `source` of `showPopover({ source })` (nesting). */\n readonly source: HTMLElement;\n /** The pointer held down at the open, re-captured after a move's re-show (2.1). */\n readonly pointerId: number | undefined;\n /**\n * The popup's computed `direction` at this open or move (4.6): which edge of the menu\n * sits at the point. Read once by `openAt`, never during render.\n */\n readonly direction: \"ltr\" | \"rtl\";\n /**\n * A touch or pen open (4.7): the menu is placed above the point with\n * `--menu-point-gap`, so it does not open under the finger.\n */\n readonly offset: boolean;\n };\n\nexport const ANCHOR_PLACEMENT: MenuPlacement = { kind: \"anchor\" };\n\n/** What a ContextTrigger passes to `openAt`. */\nexport interface MenuOpenAtOptions {\n readonly source: HTMLElement;\n /** The `contextmenu` event, or the long-press `pointerdown` (`details.event`). */\n readonly event: Event;\n /** A pointer opened (quiet focus); `false` for the keyboard (focus ring). */\n readonly pointer: boolean;\n readonly pointerId: number | undefined;\n /** A touch or pen open: placed above the point (4.7). */\n readonly offset: boolean;\n}\n\n/** One menu level: what its Root provides to its Trigger, Popup and items. */\nexport interface MenuContextValue {\n /** The shared popover machinery (`useOverlayRoot`). */\n readonly popover: PopoverRootValue;\n /** This Root is nested in a `Menu.Popup`. */\n readonly submenu: boolean;\n /** The top-level menu: item activation closes the whole stack through it (design 2.2). */\n readonly root: MenuContextValue;\n /** The enclosing menu of a submenu; `null` at the top level. */\n readonly parent: MenuContextValue | null;\n readonly loop: boolean;\n readonly delay: number;\n readonly closeDelay: number;\n /** The Trigger's id (`aria-labelledby` of the Popup). */\n readonly triggerId: string;\n /** Record the focus target of the next open (and whether a pointer asked for it). */\n readonly setOpenCause: (cause: MenuOpenCause, pointer?: boolean) => void;\n /** Read and clear the focus target of the open being shown (default `\"first\"`, keyboard). */\n readonly takeOpenCause: () => MenuOpenFocus;\n /** Submenu hover-intent timers, shared by the SubmenuTrigger and the Popup. */\n readonly timers: DelayedPair;\n /** Placement of the current (or last) open (context-menu.md 3.1). */\n readonly placement: MenuPlacement;\n /**\n * A ContextTrigger opens the menu at `point`, or moves it there when it is already open (no\n * dispatch, 4.3).\n */\n readonly openAt: (\n point: { readonly x: number; readonly y: number },\n options: MenuOpenAtOptions,\n ) => void;\n /**\n * Back to the anchored placement once a point open has been shown and hidden (the popup is no\n * longer visible): the next open that is not a ContextTrigger's (controlled, platform, foreign\n * invoker) places against the Trigger. Ignored when a newer point was recorded meanwhile.\n */\n readonly resetPlacement: (generation: number) => void;\n}\n\nexport const MenuContext = createContext<MenuContextValue | null>(null);\n\n/**\n * `true` inside a `Menu.ContextTrigger`: a `Menu.Root` there is a nested context region's own\n * top-level menu (context-menu.md 2.4), not a misplaced submenu.\n */\nexport const MenuRegionContext = createContext(false);\n\n/**\n * `contextmenu` events a ContextTrigger handled (opened or moved its menu), with the top-level\n * menu they belong to: that menu's document listener leaves its menu open for them\n * (context-menu.md 5 and 14).\n */\nconst handledEvents = new WeakMap<Event, object>();\n\n/**\n * `pointerdown` events that are not a long-press of an enclosing region: claimed by the innermost\n * region that started its timer for them (nested regions), and by every `Menu.Popup` for the\n * presses inside it (a menu inside a region). As `contextmenu`'s `defaultPrevented`\n * rule (context-menu.md 2.4).\n */\nconst claimedPresses = new WeakSet<Event>();\n\nexport function claimPress(event: Event): void {\n claimedPresses.add(event);\n}\n\nexport function isPressClaimed(event: Event): boolean {\n return claimedPresses.has(event);\n}\n\n/**\n * What a hit on a `Menu.SubmenuTrigger` during a press-drag-release gesture does (context-menu.md\n * 2.6): the hover intent a real `pointerenter` / `pointerleave` would start. Registered by the\n * SubmenuTrigger on its element; the gesture runs under pointer capture, so the element never\n * receives boundary events itself.\n */\nexport interface SubmenuHover {\n readonly enter: (event: Event) => void;\n readonly leave: (event: Event) => void;\n /**\n * The submenu's popup, for the gesture's \"still over the submenu\" test (not `popovertarget`: a\n * non-button SubmenuTrigger has none).\n */\n readonly popup: () => HTMLElement | null;\n}\n\nconst submenuHovers = new WeakMap<Element, SubmenuHover>();\n\nexport function registerSubmenuHover(element: Element, hover: SubmenuHover): () => void {\n submenuHovers.set(element, hover);\n return () => {\n if (submenuHovers.get(element) === hover) submenuHovers.delete(element);\n };\n}\n\nexport function submenuHover(element: Element): SubmenuHover | undefined {\n return submenuHovers.get(element);\n}\n\n/** The top-level menu's identity: its popup ref object, stable for the Root's lifetime. */\nconst menuKey = (menu: MenuContextValue): object => menu.root.popover.popupRef;\n\nexport function markHandled(event: Event, menu: MenuContextValue): void {\n handledEvents.set(event, menuKey(menu));\n}\n\nexport function isHandledBy(event: Event, menu: MenuContextValue): boolean {\n return handledEvents.get(event) === menuKey(menu);\n}\n\n/**\n * The close an activated item runs once its action settled: the whole stack, through the\n * top-level Root (design 2.2). Recorded at activation: if the menu was dismissed and opened again\n * meanwhile, the close belongs to the previous opening and does nothing (as `useActionTrigger`).\n */\nexport function closeStackLater(menu: MenuContextValue, event: Event): () => void {\n const { popover } = menu.root;\n const generation = popover.openGeneration();\n return () => {\n if (popover.openGeneration() === generation) popover.requestClose(event, \"activate\");\n };\n}\n\nexport function useMenuContext(part: string): MenuContextValue {\n const context = use(MenuContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a Menu.Root.`);\n }\n return context;\n}\n\n/** What a `Menu.Popup` tells the items rendered in it. */\nexport interface MenuListContextValue {\n /** The menu this popup belongs to. */\n readonly menu: MenuContextValue;\n /**\n * `experimental_focusgroup` is on and the engine implements it: items render no `tabindex`\n * (Chromium leaves `tabindex=\"-1\"` elements out of a focusgroup) and the JS arrow keys step\n * aside.\n */\n readonly nativeFocusgroup: boolean;\n /** A typeahead buffer is active: Space is a character, not an activation (design 5.1). */\n readonly typingAhead: () => boolean;\n}\n\nexport const MenuListContext = createContext<MenuListContextValue | null>(null);\n\n/** `Menu.Group` / `Menu.RadioGroup`: the id their `Menu.GroupLabel` renders. */\nexport interface MenuGroupContextValue {\n readonly labelId: string;\n}\n\nexport const MenuGroupContext = createContext<MenuGroupContextValue | null>(null);\n\n/** `Menu.RadioGroup`'s state for its `Menu.RadioItem`s. */\nexport interface MenuRadioGroupContextValue {\n /** Optimistic value. */\n readonly value: string | null;\n readonly pending: boolean;\n /**\n * Dispatch `value` through the group's transition; `then` runs once the change action\n * resolved (an item's `closeOnActivate`).\n */\n readonly select: (value: string, event: Event, then: (() => void) | undefined) => void;\n}\n\nexport const MenuRadioGroupContext = createContext<MenuRadioGroupContextValue | null>(null);\n"],"mappings":";;;AAmDA,MAAa,mBAAkC,EAAE,MAAM,SAAS;AAqDhE,MAAa,cAAc,cAAuC,IAAI;;;;;AAMtE,MAAa,oBAAoB,cAAc,KAAK;;;;;;AAOpD,MAAM,gCAAgB,IAAI,QAAuB;;;;;;;AAQjD,MAAM,iCAAiB,IAAI,QAAe;AAE1C,SAAgB,WAAW,OAAoB;CAC7C,eAAe,IAAI,KAAK;AAC1B;AAEA,SAAgB,eAAe,OAAuB;CACpD,OAAO,eAAe,IAAI,KAAK;AACjC;AAkBA,MAAM,gCAAgB,IAAI,QAA+B;AAEzD,SAAgB,qBAAqB,SAAkB,OAAiC;CACtF,cAAc,IAAI,SAAS,KAAK;CAChC,aAAa;EACX,IAAI,cAAc,IAAI,OAAO,MAAM,OAAO,cAAc,OAAO,OAAO;CACxE;AACF;AAEA,SAAgB,aAAa,SAA4C;CACvE,OAAO,cAAc,IAAI,OAAO;AAClC;;AAGA,MAAM,WAAW,SAAmC,KAAK,KAAK,QAAQ;AAEtE,SAAgB,YAAY,OAAc,MAA8B;CACtE,cAAc,IAAI,OAAO,QAAQ,IAAI,CAAC;AACxC;AAEA,SAAgB,YAAY,OAAc,MAAiC;CACzE,OAAO,cAAc,IAAI,KAAK,MAAM,QAAQ,IAAI;AAClD;;;;;;AAOA,SAAgB,gBAAgB,MAAwB,OAA0B;CAChF,MAAM,EAAE,YAAY,KAAK;CACzB,MAAM,aAAa,QAAQ,eAAe;CAC1C,aAAa;EACX,IAAI,QAAQ,eAAe,MAAM,YAAY,QAAQ,aAAa,OAAO,UAAU;CACrF;AACF;AAEA,SAAgB,eAAe,MAAgC;CAC7D,MAAM,UAAU,IAAI,WAAW;CAC/B,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,GAAG,KAAK,sCAAsC;CAEhE,OAAO;AACT;AAgBA,MAAa,kBAAkB,cAA2C,IAAI;AAO9E,MAAa,mBAAmB,cAA4C,IAAI;AAchF,MAAa,wBAAwB,cAAiD,IAAI"}
1
+ {"version":3,"file":"menu-context.mjs","names":[],"sources":["../../src/menu/menu-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { DelayedPair } from \"../internal/use-delayed-pair.js\";\nimport type { PopoverRootValue } from \"../internal/overlay/use-overlay-root.js\";\n\n/**\n * Where focus goes when the menu opens (design/components/menu.md 6.1): the first enabled item,\n * the last one (ArrowUp on the Trigger), or nowhere (a hover-opened submenu keeps focus on its\n * SubmenuTrigger).\n */\nexport type MenuOpenCause = \"first\" | \"last\" | \"none\";\n\n/** How the open being shown should place focus (design 6.1). */\nexport interface MenuOpenFocus {\n readonly cause: MenuOpenCause;\n /**\n * The open came from a pointer click (`detail > 0`): the item is focused without the focus\n * ring where the engine supports `focus({ focusVisible: false })`.\n */\n readonly pointer: boolean;\n}\n\n/**\n * How the current open is placed (design/components/context-menu.md 3.1): against the Trigger\n * (`anchor`: a Menu.Trigger, a foreign invoker, a controlled or platform open), or at a point\n * (`point`: a Menu.ContextTrigger). `generation` grows with every point open or move, so a second\n * right-click at a new point is a state change while the menu is open (4.3).\n */\nexport type MenuPlacement =\n | { readonly kind: \"anchor\" }\n | {\n readonly kind: \"point\";\n readonly x: number;\n readonly y: number;\n readonly generation: number;\n /** The region that opened: the `source` of `showPopover({ source })` (nesting). */\n readonly source: HTMLElement;\n /** The pointer held down at the open, re-captured after a move's re-show (2.1). */\n readonly pointerId: number | undefined;\n /**\n * The popup's computed `direction` at this open or move (4.6): which edge of the menu\n * sits at the point. Read once by `openAt`, never during render.\n */\n readonly direction: \"ltr\" | \"rtl\";\n /**\n * A touch or pen open (4.7): the menu is placed above the point with\n * `--menu-point-gap`, so it does not open under the finger.\n */\n readonly offset: boolean;\n };\n\nexport const ANCHOR_PLACEMENT: MenuPlacement = { kind: \"anchor\" };\n\n/** What a ContextTrigger passes to `openAt`. */\nexport interface MenuOpenAtOptions {\n readonly source: HTMLElement;\n /** The `contextmenu` event, or the long-press `pointerdown` (`details.event`). */\n readonly event: Event;\n /** A pointer opened (quiet focus); `false` for the keyboard (focus ring). */\n readonly pointer: boolean;\n readonly pointerId: number | undefined;\n /** A touch or pen open: placed above the point (4.7). */\n readonly offset: boolean;\n}\n\n/** One menu level: what its Root provides to its Trigger, Popup and items. */\nexport interface MenuContextValue {\n /** The shared popover machinery (`usePopoverRoot`). */\n readonly popover: PopoverRootValue;\n /** This Root is nested in a `Menu.Popup`. */\n readonly submenu: boolean;\n /** The top-level menu: item activation closes the whole stack through it (design 2.2). */\n readonly root: MenuContextValue;\n /** The enclosing menu of a submenu; `null` at the top level. */\n readonly parent: MenuContextValue | null;\n readonly loop: boolean;\n readonly delay: number;\n readonly closeDelay: number;\n /** The Trigger's id (`aria-labelledby` of the Popup). */\n readonly triggerId: string;\n /** Record the focus target of the next open (and whether a pointer asked for it). */\n readonly setOpenCause: (cause: MenuOpenCause, pointer?: boolean) => void;\n /** Read and clear the focus target of the open being shown (default `\"first\"`, keyboard). */\n readonly takeOpenCause: () => MenuOpenFocus;\n /** Submenu hover-intent timers, shared by the SubmenuTrigger and the Popup. */\n readonly timers: DelayedPair;\n /** Placement of the current (or last) open (context-menu.md 3.1). */\n readonly placement: MenuPlacement;\n /**\n * A ContextTrigger opens the menu at `point`, or moves it there when it is already open (no\n * dispatch, 4.3).\n */\n readonly openAt: (\n point: { readonly x: number; readonly y: number },\n options: MenuOpenAtOptions,\n ) => void;\n /**\n * Back to the anchored placement once a point open has been shown and hidden (the popup is no\n * longer visible): the next open that is not a ContextTrigger's (controlled, platform, foreign\n * invoker) places against the Trigger. Ignored when a newer point was recorded meanwhile.\n */\n readonly resetPlacement: (generation: number) => void;\n}\n\nexport const MenuContext = createContext<MenuContextValue | null>(null);\n\n/**\n * `true` inside a `Menu.ContextTrigger`: a `Menu.Root` there is a nested context region's own\n * top-level menu (context-menu.md 2.4), not a misplaced submenu.\n */\nexport const MenuRegionContext = createContext(false);\n\n/**\n * `contextmenu` events a ContextTrigger handled (opened or moved its menu), with the top-level\n * menu they belong to: that menu's document listener leaves its menu open for them\n * (context-menu.md 5 and 14).\n */\nconst handledEvents = new WeakMap<Event, object>();\n\n/**\n * `pointerdown` events that are not a long-press of an enclosing region: claimed by the innermost\n * region that started its timer for them (nested regions), and by every `Menu.Popup` for the\n * presses inside it (a menu inside a region). As `contextmenu`'s `defaultPrevented`\n * rule (context-menu.md 2.4).\n */\nconst claimedPresses = new WeakSet<Event>();\n\nexport function claimPress(event: Event): void {\n claimedPresses.add(event);\n}\n\nexport function isPressClaimed(event: Event): boolean {\n return claimedPresses.has(event);\n}\n\n/**\n * What a hit on a `Menu.SubmenuTrigger` during a press-drag-release gesture does (context-menu.md\n * 2.6): the hover intent a real `pointerenter` / `pointerleave` would start. Registered by the\n * SubmenuTrigger on its element; the gesture runs under pointer capture, so the element never\n * receives boundary events itself.\n */\nexport interface SubmenuHover {\n readonly enter: (event: Event) => void;\n readonly leave: (event: Event) => void;\n /**\n * The submenu's popup, for the gesture's \"still over the submenu\" test (not `popovertarget`: a\n * non-button SubmenuTrigger has none).\n */\n readonly popup: () => HTMLElement | null;\n}\n\nconst submenuHovers = new WeakMap<Element, SubmenuHover>();\n\nexport function registerSubmenuHover(element: Element, hover: SubmenuHover): () => void {\n submenuHovers.set(element, hover);\n return () => {\n if (submenuHovers.get(element) === hover) submenuHovers.delete(element);\n };\n}\n\nexport function submenuHover(element: Element): SubmenuHover | undefined {\n return submenuHovers.get(element);\n}\n\n/** The top-level menu's identity: its popup ref object, stable for the Root's lifetime. */\nconst menuKey = (menu: MenuContextValue): object => menu.root.popover.popupRef;\n\nexport function markHandled(event: Event, menu: MenuContextValue): void {\n handledEvents.set(event, menuKey(menu));\n}\n\nexport function isHandledBy(event: Event, menu: MenuContextValue): boolean {\n return handledEvents.get(event) === menuKey(menu);\n}\n\n/**\n * The close an activated item runs once its action settled: the whole stack, through the\n * top-level Root (design 2.2). Recorded at activation: if the menu was dismissed and opened again\n * meanwhile, the close belongs to the previous opening and does nothing (as `useActionTrigger`).\n */\nexport function closeStackLater(menu: MenuContextValue, event: Event): () => void {\n const { popover } = menu.root;\n const generation = popover.openGeneration();\n return () => {\n if (popover.openGeneration() === generation) popover.requestClose(event, \"activate\");\n };\n}\n\nexport function useMenuContext(part: string): MenuContextValue {\n const context = use(MenuContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a Menu.Root.`);\n }\n return context;\n}\n\n/** What a `Menu.Popup` tells the items rendered in it. */\nexport interface MenuListContextValue {\n /** The menu this popup belongs to. */\n readonly menu: MenuContextValue;\n /**\n * `experimental_focusgroup` is on and the engine implements it: items render no `tabindex`\n * (Chromium leaves `tabindex=\"-1\"` elements out of a focusgroup) and the JS arrow keys step\n * aside.\n */\n readonly nativeFocusgroup: boolean;\n /** A typeahead buffer is active: Space is a character, not an activation (design 5.1). */\n readonly typingAhead: () => boolean;\n}\n\nexport const MenuListContext = createContext<MenuListContextValue | null>(null);\n\n/** `Menu.Group` / `Menu.RadioGroup`: the id their `Menu.GroupLabel` renders. */\nexport interface MenuGroupContextValue {\n readonly labelId: string;\n}\n\nexport const MenuGroupContext = createContext<MenuGroupContextValue | null>(null);\n\n/** `Menu.RadioGroup`'s state for its `Menu.RadioItem`s. */\nexport interface MenuRadioGroupContextValue {\n /** Optimistic value. */\n readonly value: string | null;\n readonly pending: boolean;\n /**\n * Dispatch `value` through the group's transition; `then` runs once the change action\n * resolved (an item's `closeOnActivate`).\n */\n readonly select: (value: string, event: Event, then: (() => void) | undefined) => void;\n}\n\nexport const MenuRadioGroupContext = createContext<MenuRadioGroupContextValue | null>(null);\n"],"mappings":";;;AAmDA,MAAa,mBAAkC,EAAE,MAAM,SAAS;AAqDhE,MAAa,cAAc,cAAuC,IAAI;;;;;AAMtE,MAAa,oBAAoB,cAAc,KAAK;;;;;;AAOpD,MAAM,gCAAgB,IAAI,QAAuB;;;;;;;AAQjD,MAAM,iCAAiB,IAAI,QAAe;AAE1C,SAAgB,WAAW,OAAoB;CAC7C,eAAe,IAAI,KAAK;AAC1B;AAEA,SAAgB,eAAe,OAAuB;CACpD,OAAO,eAAe,IAAI,KAAK;AACjC;AAkBA,MAAM,gCAAgB,IAAI,QAA+B;AAEzD,SAAgB,qBAAqB,SAAkB,OAAiC;CACtF,cAAc,IAAI,SAAS,KAAK;CAChC,aAAa;EACX,IAAI,cAAc,IAAI,OAAO,MAAM,OAAO,cAAc,OAAO,OAAO;CACxE;AACF;AAEA,SAAgB,aAAa,SAA4C;CACvE,OAAO,cAAc,IAAI,OAAO;AAClC;;AAGA,MAAM,WAAW,SAAmC,KAAK,KAAK,QAAQ;AAEtE,SAAgB,YAAY,OAAc,MAA8B;CACtE,cAAc,IAAI,OAAO,QAAQ,IAAI,CAAC;AACxC;AAEA,SAAgB,YAAY,OAAc,MAAiC;CACzE,OAAO,cAAc,IAAI,KAAK,MAAM,QAAQ,IAAI;AAClD;;;;;;AAOA,SAAgB,gBAAgB,MAAwB,OAA0B;CAChF,MAAM,EAAE,YAAY,KAAK;CACzB,MAAM,aAAa,QAAQ,eAAe;CAC1C,aAAa;EACX,IAAI,QAAQ,eAAe,MAAM,YAAY,QAAQ,aAAa,OAAO,UAAU;CACrF;AACF;AAEA,SAAgB,eAAe,MAAgC;CAC7D,MAAM,UAAU,IAAI,WAAW;CAC/B,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,GAAG,KAAK,sCAAsC;CAEhE,OAAO;AACT;AAgBA,MAAa,kBAAkB,cAA2C,IAAI;AAO9E,MAAa,mBAAmB,cAA4C,IAAI;AAchF,MAAa,wBAAwB,cAAiD,IAAI"}
@@ -1,4 +1,4 @@
1
- import { isPopoverOpen } from "../internal/popover-open.mjs";
1
+ import { isPopoverOpen } from "../internal/overlay/popover-open.mjs";
2
2
  import { submenuHover } from "./menu-context.mjs";
3
3
  import { isDisabledItem } from "./menu-dom.mjs";
4
4
  //#region src/menu/menu-gestures.ts
@@ -1 +1 @@
1
- {"version":3,"file":"menu-gestures.mjs","names":[],"sources":["../../src/menu/menu-gestures.ts"],"sourcesContent":["// The pointer gestures of Menu.ContextTrigger (design/components/context-menu.md 2.2, 2.6). No\n// \"use client\" directive: DOM listeners only (conventions 7.1).\nimport { isPopoverOpen } from \"../internal/popover-open.js\";\nimport { submenuHover } from \"./menu-context.js\";\nimport { isDisabledItem, ITEM_SELECTOR } from \"./menu-dom.js\";\n\n/** Movement that cancels a long-press (Base UI's slop); also a touch drag's activation slop. */\nexport const LONG_PRESS_SLOP = 10;\n/**\n * Movement a mouse or pen press-drag-release needs before a release activates or dismisses\n * (Chromium's `kMaximumLengthMovedToActivate`, macOS's \"moved\"; context-menu.md 2.6).\n */\nexport const DRAG_SLOP = 4;\n/** A release outside the menu dismisses it only this long after the open (GTK, Base UI). */\nconst DRAG_DISMISS_DELAY = 500;\n\ninterface DragOptions {\n readonly pointerId: number;\n /** The open point: the slop is measured from it. */\n readonly x: number;\n readonly y: number;\n readonly slop: number;\n /**\n * Activates `item` for a release: through `item.click()`, with the click swallow of a long-press\n * out of the way and armed again for the click an engine may synthesise from this release.\n */\n readonly activate: (item: HTMLElement) => void;\n}\n\nexport const isTouchLike = (pointerType: string) =>\n pointerType === \"touch\" || pointerType === \"pen\";\n\n/**\n * Press-drag-release (context-menu.md 2.6). The popup holds the capture of `pointerId`, so its\n * items see no boundary events and the gesture hit-tests with `elementFromPoint`. A move focuses\n * the item under the pointer without the ring (a SubmenuTrigger starts its hover intent); a\n * release beyond the slop activates an enabled, non-submenu item through `click()`, or dismisses\n * when outside every popup of the tree at least 500 ms after the popup was shown (not after the\n * press: an async open appears late). Ends at the release, `pointercancel`,\n * `lostpointercapture` or the close. Returns the cleanup.\n */\nexport function startDrag(popup: HTMLElement, options: DragOptions): () => void {\n const doc = popup.ownerDocument;\n // `performance.now()` at the first open `toggle`; null until the popup has been shown.\n let shownAt: number | null = isPopoverOpen(popup) ? performance.now() : null;\n // The SubmenuTrigger the pointer is over, whose hover intent is running.\n let submenuTrigger: HTMLElement | null = null;\n\n const ours = (event: Event) => (event as globalThis.PointerEvent).pointerId === options.pointerId;\n const hitTest = (event: globalThis.PointerEvent): Element | null =>\n typeof doc.elementFromPoint === \"function\"\n ? doc.elementFromPoint(event.clientX, event.clientY)\n : null;\n /** The item under the pointer, inside this menu's tree (submenus are DOM descendants). */\n const itemAt = (target: Element | null): HTMLElement | null => {\n const item = target?.closest<HTMLElement>(ITEM_SELECTOR) ?? null;\n return item !== null && popup.contains(item) ? item : null;\n };\n /** The pointer is over the submenu `trigger` opens (its popup, registered with its hover). */\n const inSubmenuOf = (trigger: HTMLElement, target: Element | null) => {\n const submenu = submenuHover(trigger)?.popup() ?? null;\n return submenu !== null && target !== null && submenu.contains(target);\n };\n const hoverSubmenu = (next: HTMLElement | null, event: Event) => {\n if (next === submenuTrigger) return;\n if (submenuTrigger !== null) submenuHover(submenuTrigger)?.leave(event);\n submenuTrigger = next;\n if (next !== null) submenuHover(next)?.enter(event);\n };\n\n const onMove = (event: globalThis.PointerEvent) => {\n if (!ours(event)) return;\n const target = hitTest(event);\n const item = itemAt(target);\n // Menu 6.2's pointer focus, without the ring: keyboard and pointer agree on the current item.\n if (item !== null && doc.activeElement !== item) {\n item.focus({ focusVisible: false } as FocusOptions);\n }\n if (item !== null && submenuHover(item) !== undefined) hoverSubmenu(item, event);\n else if (submenuTrigger !== null && !inSubmenuOf(submenuTrigger, target)) {\n hoverSubmenu(null, event);\n }\n };\n const onUp = (event: globalThis.PointerEvent) => {\n if (!ours(event)) return;\n end();\n const moved = Math.hypot(event.clientX - options.x, event.clientY - options.y) > options.slop;\n // Time alone never activates or dismisses: a stationary release keeps the menu open.\n if (!moved) return;\n const target = hitTest(event);\n if (target !== null && popup.contains(target)) {\n const item = itemAt(target);\n // A disabled item, a SubmenuTrigger (native menus activate nothing there), a separator or\n // padding: the menu stays open.\n if (item === null || isDisabledItem(item) || item.hasAttribute(\"aria-haspopup\")) return;\n options.activate(item);\n return;\n }\n if (\n shownAt !== null &&\n performance.now() - shownAt >= DRAG_DISMISS_DELAY &&\n isPopoverOpen(popup)\n ) {\n popup.hidePopover();\n }\n };\n const onEnd = (event: Event) => {\n if (ours(event)) end();\n };\n const onToggle = () => {\n if (!isPopoverOpen(popup)) end();\n else shownAt ??= performance.now();\n };\n const end = () => {\n popup.removeEventListener(\"pointermove\", onMove);\n popup.removeEventListener(\"pointerup\", onUp);\n popup.removeEventListener(\"pointercancel\", onEnd);\n popup.removeEventListener(\"lostpointercapture\", onEnd);\n popup.removeEventListener(\"toggle\", onToggle);\n submenuTrigger = null;\n };\n popup.addEventListener(\"pointermove\", onMove);\n popup.addEventListener(\"pointerup\", onUp);\n popup.addEventListener(\"pointercancel\", onEnd);\n popup.addEventListener(\"lostpointercapture\", onEnd);\n popup.addEventListener(\"toggle\", onToggle);\n return end;\n}\n\n/** How long the touch guard waits for the `touchend` that follows the finger's `pointerup`. */\nconst TOUCH_END_WAIT = 250;\n\n/**\n * The touch guard while the finger that opened a menu is down (context-menu.md 2.2): a\n * non-passive `touchmove` listener keeps its drag from becoming a pan (`pointercancel`), and the\n * lift's `touchend` is prevented so no click is synthesised (it would light-dismiss the menu or\n * activate an item twice). Only that finger's lift ends it, recognised by order (its\n * `pointerup` comes first; pointer events carry no `Touch.identifier`); other fingers'\n * `touchend`s are prevented too. Also ends at `touchcancel`, the pointer's `pointercancel`, and\n * shortly after its `pointerup` when no touch event follows. Returns the cleanup.\n */\nexport function guardTouch(doc: Document, pointerId: number): () => void {\n let fallback: ReturnType<typeof setTimeout> | undefined;\n // The gesture's pointer has lifted: the next `touchend` is its own.\n let lifted = false;\n const onTouchMove = (event: Event) => {\n if (event.cancelable) event.preventDefault();\n };\n const onTouchEnd = (event: Event) => {\n if (event.cancelable) event.preventDefault();\n if (lifted) end();\n };\n const onPointerUp = (event: Event) => {\n if ((event as globalThis.PointerEvent).pointerId !== pointerId) return;\n lifted = true;\n fallback ??= setTimeout(end, TOUCH_END_WAIT);\n };\n const onPointerCancel = (event: Event) => {\n if ((event as globalThis.PointerEvent).pointerId === pointerId) end();\n };\n const end = () => {\n if (fallback !== undefined) clearTimeout(fallback);\n doc.removeEventListener(\"touchmove\", onTouchMove);\n doc.removeEventListener(\"touchend\", onTouchEnd);\n doc.removeEventListener(\"touchcancel\", end, true);\n doc.removeEventListener(\"pointerup\", onPointerUp, true);\n doc.removeEventListener(\"pointercancel\", onPointerCancel, true);\n };\n doc.addEventListener(\"touchmove\", onTouchMove, { passive: false });\n doc.addEventListener(\"touchend\", onTouchEnd, { passive: false });\n doc.addEventListener(\"touchcancel\", end, true);\n doc.addEventListener(\"pointerup\", onPointerUp, true);\n doc.addEventListener(\"pointercancel\", onPointerCancel, true);\n return end;\n}\n\n/**\n * One-shot swallow of the `click` an engine may synthesise when the long-press ends (2.2),\n * scoped to that release: the click comes in the same task as the `pointerup` of\n * `pointerId`, so the swallow ends one task after that `pointerup` (or `pointercancel`), and at\n * once on any `keydown`, the next `pointerdown`, or the menu closing. iOS synthesises no click\n * after a long-press; a swallow left armed would eat the next keyboard activation\n * (`element.click()`). `slot` holds the disarm of the armed swallow (one per region).\n */\nexport function armClickSwallow(\n slot: { current: (() => void) | null },\n doc: Document,\n pointerId: number,\n releasing = false,\n): void {\n slot.current?.();\n let released: ReturnType<typeof setTimeout> | undefined;\n const onClick = (event: Event) => {\n event.preventDefault();\n event.stopPropagation();\n disarm();\n };\n const onRelease = (event: Event) => {\n if ((event as globalThis.PointerEvent).pointerId !== pointerId) return;\n if (released === undefined) released = setTimeout(disarm, 0);\n };\n const disarm = () => {\n if (released !== undefined) clearTimeout(released);\n doc.removeEventListener(\"click\", onClick, true);\n doc.removeEventListener(\"pointerdown\", disarm, true);\n doc.removeEventListener(\"keydown\", disarm, true);\n doc.removeEventListener(\"pointerup\", onRelease, true);\n doc.removeEventListener(\"pointercancel\", onRelease, true);\n if (slot.current === disarm) slot.current = null;\n };\n doc.addEventListener(\"click\", onClick, true);\n doc.addEventListener(\"pointerdown\", disarm, true);\n doc.addEventListener(\"keydown\", disarm, true);\n doc.addEventListener(\"pointerup\", onRelease, true);\n doc.addEventListener(\"pointercancel\", onRelease, true);\n slot.current = disarm;\n // Armed from inside the release itself (a drag activation): the click comes in this task.\n if (releasing) released = setTimeout(disarm, 0);\n}\n"],"mappings":";;;;;AAcA,MAAM,qBAAqB;AAe3B,MAAa,eAAe,gBAC1B,gBAAgB,WAAW,gBAAgB;;;;;;;;;;AAW7C,SAAgB,UAAU,OAAoB,SAAkC;CAC9E,MAAM,MAAM,MA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3C,IAAI,iBAAiB,eAAe,QAAQ,IAAI;CAChD,IAAI,iBAAiB,WAAW,QAAQ,IAAI;CAC5C,IAAI,iBAAiB,aAAa,WAAW,IAAI;CACjD,IAAI,iBAAiB,iBAAiB,WAAW,IAAI;CACrD,KAAK,UAAU;CAEf,IAAI,WAAW,WAAW,WAAW,QAAQ,CAAC;AAChD"}
1
+ {"version":3,"file":"menu-gestures.mjs","names":[],"sources":["../../src/menu/menu-gestures.ts"],"sourcesContent":["// The pointer gestures of Menu.ContextTrigger (design/components/context-menu.md 2.2, 2.6). No\n// \"use client\" directive: DOM listeners only (conventions 7.1).\nimport { isPopoverOpen } from \"../internal/overlay/popover-open.js\";\nimport { submenuHover } from \"./menu-context.js\";\nimport { isDisabledItem, ITEM_SELECTOR } from \"./menu-dom.js\";\n\n/** Movement that cancels a long-press (Base UI's slop); also a touch drag's activation slop. */\nexport const LONG_PRESS_SLOP = 10;\n/**\n * Movement a mouse or pen press-drag-release needs before a release activates or dismisses\n * (Chromium's `kMaximumLengthMovedToActivate`, macOS's \"moved\"; context-menu.md 2.6).\n */\nexport const DRAG_SLOP = 4;\n/** A release outside the menu dismisses it only this long after the open (GTK, Base UI). */\nconst DRAG_DISMISS_DELAY = 500;\n\ninterface DragOptions {\n readonly pointerId: number;\n /** The open point: the slop is measured from it. */\n readonly x: number;\n readonly y: number;\n readonly slop: number;\n /**\n * Activates `item` for a release: through `item.click()`, with the click swallow of a long-press\n * out of the way and armed again for the click an engine may synthesise from this release.\n */\n readonly activate: (item: HTMLElement) => void;\n}\n\nexport const isTouchLike = (pointerType: string) =>\n pointerType === \"touch\" || pointerType === \"pen\";\n\n/**\n * Press-drag-release (context-menu.md 2.6). The popup holds the capture of `pointerId`, so its\n * items see no boundary events and the gesture hit-tests with `elementFromPoint`. A move focuses\n * the item under the pointer without the ring (a SubmenuTrigger starts its hover intent); a\n * release beyond the slop activates an enabled, non-submenu item through `click()`, or dismisses\n * when outside every popup of the tree at least 500 ms after the popup was shown (not after the\n * press: an async open appears late). Ends at the release, `pointercancel`,\n * `lostpointercapture` or the close. Returns the cleanup.\n */\nexport function startDrag(popup: HTMLElement, options: DragOptions): () => void {\n const doc = popup.ownerDocument;\n // `performance.now()` at the first open `toggle`; null until the popup has been shown.\n let shownAt: number | null = isPopoverOpen(popup) ? performance.now() : null;\n // The SubmenuTrigger the pointer is over, whose hover intent is running.\n let submenuTrigger: HTMLElement | null = null;\n\n const ours = (event: Event) => (event as globalThis.PointerEvent).pointerId === options.pointerId;\n const hitTest = (event: globalThis.PointerEvent): Element | null =>\n typeof doc.elementFromPoint === \"function\"\n ? doc.elementFromPoint(event.clientX, event.clientY)\n : null;\n /** The item under the pointer, inside this menu's tree (submenus are DOM descendants). */\n const itemAt = (target: Element | null): HTMLElement | null => {\n const item = target?.closest<HTMLElement>(ITEM_SELECTOR) ?? null;\n return item !== null && popup.contains(item) ? item : null;\n };\n /** The pointer is over the submenu `trigger` opens (its popup, registered with its hover). */\n const inSubmenuOf = (trigger: HTMLElement, target: Element | null) => {\n const submenu = submenuHover(trigger)?.popup() ?? null;\n return submenu !== null && target !== null && submenu.contains(target);\n };\n const hoverSubmenu = (next: HTMLElement | null, event: Event) => {\n if (next === submenuTrigger) return;\n if (submenuTrigger !== null) submenuHover(submenuTrigger)?.leave(event);\n submenuTrigger = next;\n if (next !== null) submenuHover(next)?.enter(event);\n };\n\n const onMove = (event: globalThis.PointerEvent) => {\n if (!ours(event)) return;\n const target = hitTest(event);\n const item = itemAt(target);\n // Menu 6.2's pointer focus, without the ring: keyboard and pointer agree on the current item.\n if (item !== null && doc.activeElement !== item) {\n item.focus({ focusVisible: false } as FocusOptions);\n }\n if (item !== null && submenuHover(item) !== undefined) hoverSubmenu(item, event);\n else if (submenuTrigger !== null && !inSubmenuOf(submenuTrigger, target)) {\n hoverSubmenu(null, event);\n }\n };\n const onUp = (event: globalThis.PointerEvent) => {\n if (!ours(event)) return;\n end();\n const moved = Math.hypot(event.clientX - options.x, event.clientY - options.y) > options.slop;\n // Time alone never activates or dismisses: a stationary release keeps the menu open.\n if (!moved) return;\n const target = hitTest(event);\n if (target !== null && popup.contains(target)) {\n const item = itemAt(target);\n // A disabled item, a SubmenuTrigger (native menus activate nothing there), a separator or\n // padding: the menu stays open.\n if (item === null || isDisabledItem(item) || item.hasAttribute(\"aria-haspopup\")) return;\n options.activate(item);\n return;\n }\n if (\n shownAt !== null &&\n performance.now() - shownAt >= DRAG_DISMISS_DELAY &&\n isPopoverOpen(popup)\n ) {\n popup.hidePopover();\n }\n };\n const onEnd = (event: Event) => {\n if (ours(event)) end();\n };\n const onToggle = () => {\n if (!isPopoverOpen(popup)) end();\n else shownAt ??= performance.now();\n };\n const end = () => {\n popup.removeEventListener(\"pointermove\", onMove);\n popup.removeEventListener(\"pointerup\", onUp);\n popup.removeEventListener(\"pointercancel\", onEnd);\n popup.removeEventListener(\"lostpointercapture\", onEnd);\n popup.removeEventListener(\"toggle\", onToggle);\n submenuTrigger = null;\n };\n popup.addEventListener(\"pointermove\", onMove);\n popup.addEventListener(\"pointerup\", onUp);\n popup.addEventListener(\"pointercancel\", onEnd);\n popup.addEventListener(\"lostpointercapture\", onEnd);\n popup.addEventListener(\"toggle\", onToggle);\n return end;\n}\n\n/** How long the touch guard waits for the `touchend` that follows the finger's `pointerup`. */\nconst TOUCH_END_WAIT = 250;\n\n/**\n * The touch guard while the finger that opened a menu is down (context-menu.md 2.2): a\n * non-passive `touchmove` listener keeps its drag from becoming a pan (`pointercancel`), and the\n * lift's `touchend` is prevented so no click is synthesised (it would light-dismiss the menu or\n * activate an item twice). Only that finger's lift ends it, recognised by order (its\n * `pointerup` comes first; pointer events carry no `Touch.identifier`); other fingers'\n * `touchend`s are prevented too. Also ends at `touchcancel`, the pointer's `pointercancel`, and\n * shortly after its `pointerup` when no touch event follows. Returns the cleanup.\n */\nexport function guardTouch(doc: Document, pointerId: number): () => void {\n let fallback: ReturnType<typeof setTimeout> | undefined;\n // The gesture's pointer has lifted: the next `touchend` is its own.\n let lifted = false;\n const onTouchMove = (event: Event) => {\n if (event.cancelable) event.preventDefault();\n };\n const onTouchEnd = (event: Event) => {\n if (event.cancelable) event.preventDefault();\n if (lifted) end();\n };\n const onPointerUp = (event: Event) => {\n if ((event as globalThis.PointerEvent).pointerId !== pointerId) return;\n lifted = true;\n fallback ??= setTimeout(end, TOUCH_END_WAIT);\n };\n const onPointerCancel = (event: Event) => {\n if ((event as globalThis.PointerEvent).pointerId === pointerId) end();\n };\n const end = () => {\n if (fallback !== undefined) clearTimeout(fallback);\n doc.removeEventListener(\"touchmove\", onTouchMove);\n doc.removeEventListener(\"touchend\", onTouchEnd);\n doc.removeEventListener(\"touchcancel\", end, true);\n doc.removeEventListener(\"pointerup\", onPointerUp, true);\n doc.removeEventListener(\"pointercancel\", onPointerCancel, true);\n };\n doc.addEventListener(\"touchmove\", onTouchMove, { passive: false });\n doc.addEventListener(\"touchend\", onTouchEnd, { passive: false });\n doc.addEventListener(\"touchcancel\", end, true);\n doc.addEventListener(\"pointerup\", onPointerUp, true);\n doc.addEventListener(\"pointercancel\", onPointerCancel, true);\n return end;\n}\n\n/**\n * One-shot swallow of the `click` an engine may synthesise when the long-press ends (2.2),\n * scoped to that release: the click comes in the same task as the `pointerup` of\n * `pointerId`, so the swallow ends one task after that `pointerup` (or `pointercancel`), and at\n * once on any `keydown`, the next `pointerdown`, or the menu closing. iOS synthesises no click\n * after a long-press; a swallow left armed would eat the next keyboard activation\n * (`element.click()`). `slot` holds the disarm of the armed swallow (one per region).\n */\nexport function armClickSwallow(\n slot: { current: (() => void) | null },\n doc: Document,\n pointerId: number,\n releasing = false,\n): void {\n slot.current?.();\n let released: ReturnType<typeof setTimeout> | undefined;\n const onClick = (event: Event) => {\n event.preventDefault();\n event.stopPropagation();\n disarm();\n };\n const onRelease = (event: Event) => {\n if ((event as globalThis.PointerEvent).pointerId !== pointerId) return;\n if (released === undefined) released = setTimeout(disarm, 0);\n };\n const disarm = () => {\n if (released !== undefined) clearTimeout(released);\n doc.removeEventListener(\"click\", onClick, true);\n doc.removeEventListener(\"pointerdown\", disarm, true);\n doc.removeEventListener(\"keydown\", disarm, true);\n doc.removeEventListener(\"pointerup\", onRelease, true);\n doc.removeEventListener(\"pointercancel\", onRelease, true);\n if (slot.current === disarm) slot.current = null;\n };\n doc.addEventListener(\"click\", onClick, true);\n doc.addEventListener(\"pointerdown\", disarm, true);\n doc.addEventListener(\"keydown\", disarm, true);\n doc.addEventListener(\"pointerup\", onRelease, true);\n doc.addEventListener(\"pointercancel\", onRelease, true);\n slot.current = disarm;\n // Armed from inside the release itself (a drag activation): the click comes in this task.\n if (releasing) released = setTimeout(disarm, 0);\n}\n"],"mappings":";;;;;AAcA,MAAM,qBAAqB;AAe3B,MAAa,eAAe,gBAC1B,gBAAgB,WAAW,gBAAgB;;;;;;;;;;AAW7C,SAAgB,UAAU,OAAoB,SAAkC;CAC9E,MAAM,MAAM,MAAM;CAElB,IAAI,UAAyB,cAAc,KAAK,IAAI,YAAY,IAAI,IAAI;CAExE,IAAI,iBAAqC;CAEzC,MAAM,QAAQ,UAAkB,MAAkC,cAAc,QAAQ;CACxF,MAAM,WAAW,UACf,OAAO,IAAI,qBAAqB,aAC5B,IAAI,iBAAiB,MAAM,SAAS,MAAM,OAAO,IACjD;;CAEN,MAAM,UAAU,WAA+C;EAC7D,MAAM,OAAO,QAAQ,QAAA,4EAAkC,KAAK;EAC5D,OAAO,SAAS,QAAQ,MAAM,SAAS,IAAI,IAAI,OAAO;CACxD;;CAEA,MAAM,eAAe,SAAsB,WAA2B;EACpE,MAAM,UAAU,aAAa,OAAO,CAAC,EAAE,MAAM,KAAK;EAClD,OAAO,YAAY,QAAQ,WAAW,QAAQ,QAAQ,SAAS,MAAM;CACvE;CACA,MAAM,gBAAgB,MAA0B,UAAiB;EAC/D,IAAI,SAAS,gBAAgB;EAC7B,IAAI,mBAAmB,MAAM,aAAa,cAAc,CAAC,EAAE,MAAM,KAAK;EACtE,iBAAiB;EACjB,IAAI,S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gBAAa;yBAXA"}
1
+ {"version":3,"file":"menu-item.d.mts","names":[],"sources":["../../src/menu/menu-item.tsx"],"mappings":";;;;iBAgBiB,wBAAwB;;;;;iBAMxB;;WAEN;;WAEA;;;;;;;iBAQM,sBAAsB,KACrC;;;;;;;EASA,SAAS,QAAQ,SAAS;;;;;;EAM1B;;;;;;;;;;EAUA,eAAe;;;;;;;EAOf;;EAEA;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;;wBAiBvC,WACd,QACA,iBACA,cACA,UACA,OACA,WACA,OACA,UACA,WACG,QACF,gBAAa;yBAXA"}
@@ -1,8 +1,7 @@
1
1
  "use client";
2
- import { createActionDetails } from "../internal/action-details.mjs";
3
- import { dataAttr } from "../internal/data-attr.mjs";
4
- import { useActionTrigger } from "../internal/use-action-trigger.mjs";
2
+ import { createActionDetails } from "../internal/action/action-details.mjs";
5
3
  import { rendersButton } from "../internal/render-element.mjs";
4
+ import { usePureTrigger } from "../internal/action/use-pure-trigger.mjs";
6
5
  import { useRender } from "../internal/use-render.mjs";
7
6
  import { useMenuContext } from "./menu-context.mjs";
8
7
  import { useMenuItem } from "./use-menu-item.mjs";
@@ -23,11 +22,12 @@ import { useMenuItem } from "./use-menu-item.mjs";
23
22
  */
24
23
  function MenuItem({ action, closeOnActivate = true, whilePending, disabled = false, label, className, style, children, render, ...rest }) {
25
24
  const menu = useMenuContext("Menu.Item");
26
- const ignoring = (whilePending ?? (closeOnActivate ? "ignore" : "run")) === "ignore";
27
- const { pending, run } = useActionTrigger({
28
- openGeneration: menu.root.popover.openGeneration,
29
- ignoreWhilePending: ignoring
25
+ const trigger = usePureTrigger({
26
+ whilePending,
27
+ defaultWhilePending: closeOnActivate ? "ignore" : "run",
28
+ openGeneration: menu.root.popover.openGeneration
30
29
  });
30
+ const { pending } = trigger;
31
31
  const { libraryProps } = useMenuItem({
32
32
  part: "Menu.Item",
33
33
  role: "menuitem",
@@ -35,7 +35,7 @@ function MenuItem({ action, closeOnActivate = true, whilePending, disabled = fal
35
35
  label,
36
36
  activate: (event) => {
37
37
  const details = createActionDetails(event, {});
38
- if (!run(() => action?.(details), closeOnActivate ? () => menu.root.popover.requestClose(event, "activate") : void 0)) event.preventDefault();
38
+ trigger.runActivation(event, () => action?.(details), closeOnActivate ? () => menu.root.popover.requestClose(event, "activate") : void 0);
39
39
  }
40
40
  });
41
41
  return useRender({
@@ -52,8 +52,7 @@ function MenuItem({ action, closeOnActivate = true, whilePending, disabled = fal
52
52
  libraryProps: {
53
53
  ...rendersButton(render) && { type: "button" },
54
54
  ...libraryProps,
55
- "aria-disabled": disabled || pending && ignoring ? true : void 0,
56
- "data-pending": dataAttr(pending)
55
+ ...trigger.pendingProps(libraryProps)
57
56
  }
58
57
  });
59
58
  }
@@ -1 +1 @@
1
- {"version":3,"file":"menu-item.mjs","names":[],"sources":["../../src/menu/menu-item.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type {\n Action,\n ActionDetails,\n RenderProp,\n StateValue,\n WhilePending,\n} from \"../internal/types.js\";\nimport { useActionTrigger } from \"../internal/use-action-trigger.js\";\nimport { rendersButton, useRender } from \"../internal/use-render.js\";\nimport { useMenuContext } from \"./menu-context.js\";\nimport { useMenuItem } from \"./use-menu-item.js\";\n\n/** Details passed to `Menu.Item`'s `action`. */\nexport interface MenuItemDetails extends ActionDetails {}\n\n/**\n * State of `Menu.Item`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface MenuItemState {\n /** This item's `action` is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Menu.Item`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport interface MenuItemProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"onKeyDown\" | \"onPointerMove\" | \"disabled\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Runs inside this item's own transition (`data-pending` on the item); the menu stays open\n * until it settles, then the whole menu closes (`closeOnActivate`). May be a Server Function\n * (`details.event` is virtual). A rejection leaves the menu open and reaches the nearest Error\n * Boundary above the item. Without `action`, activation only closes.\n */\n action?: Action<[details: MenuItemDetails]>;\n /**\n * Close the whole menu once `action` settles.\n *\n * @defaultValue `true`\n */\n closeOnActivate?: boolean;\n /**\n * What a click, Enter or Space does while this item's `action` is pending. `\"ignore\"`:\n * nothing (the event is cancelled, `aria-disabled=\"true\"` meanwhile). `\"run\"`: the action runs\n * again (`data-pending` until every run has settled); a closing item closes the menu once,\n * when the last run settles and only if the latest run resolved (a rejection keeps the menu\n * open, as in `\"ignore\"` mode). No effect without `action`.\n *\n * @defaultValue `\"ignore\"`, or `\"run\"` with `closeOnActivate={false}`\n */\n whilePending?: WhilePending;\n /**\n * Renders `aria-disabled` and `data-disabled`: the item stays focusable and never activates.\n * It is an ordinary item for navigation; only the open focus skips items with `disabled`.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** Text typeahead matches when the item's text content is not representative (an icon). */\n label?: string;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MenuItemState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MenuItemState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, MenuItemState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MenuItemState>;\n}\n\n/**\n * A menu command: `<button type=\"button\" role=\"menuitem\" tabindex=\"-1\">`. Click, Enter or Space\n * runs `action` in the item's own transition (`data-pending` on the item; a second activation\n * meanwhile is ignored and the item `aria-disabled`, unless `whilePending` is `\"run\"`, the\n * default of a `closeOnActivate={false}` item); once it resolves the whole menu stack closes\n * through the top-level Root (`openChangeAction(false, { reason: \"activate\" })` awaited, view\n * transition if set). Hovering the item focuses it.\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>`), `role`, `tabIndex`, `disabled`\n * (always absent), `aria-disabled`, `onClick`, `onKeyDown`, `onPointerMove`, `data-pending`,\n * `data-disabled`, `data-typeahead`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuItem({\n action,\n closeOnActivate = true,\n whilePending,\n disabled = false,\n label,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuItemProps) {\n const menu = useMenuContext(\"Menu.Item\");\n // The close belongs to the top-level menu, so its open generation guards it.\n // Mixed ownership (conventions 2.5.1): an item the library closes the menu after ignores by\n // default; a keep-open item is a user-owned trigger and runs every activation.\n const ignoring = (whilePending ?? (closeOnActivate ? \"ignore\" : \"run\")) === \"ignore\";\n const { pending, run } = useActionTrigger({\n openGeneration: menu.root.popover.openGeneration,\n ignoreWhilePending: ignoring,\n });\n\n const { libraryProps } = useMenuItem({\n part: \"Menu.Item\",\n role: \"menuitem\",\n disabled,\n label,\n activate: (event) => {\n const details: MenuItemDetails = createActionDetails(event, {});\n // When ignoring, a second activation while this item's own run is in flight starts\n // nothing and is cancelled (the hook's guard): a link does not navigate, a composed\n // command does not run. Enter / Space reach here through the element's click, their keydown is cancelled.\n const started = run(\n () => action?.(details),\n closeOnActivate ? () => menu.root.popover.requestClose(event, \"activate\") : undefined,\n );\n if (!started) event.preventDefault();\n },\n });\n\n const state: MenuItemState = { pending, disabled };\n\n return useRender<ComponentPropsWithRef<\"button\">, MenuItemState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n ...(rendersButton(render) && { type: \"button\" as const }),\n ...libraryProps,\n // Also while pending when ignoring: an item that will not act is unavailable to AT.\n // Navigation keys on `data-disabled` (the `disabled` prop), so a pending item is still an\n // enabled item.\n \"aria-disabled\": disabled || (pending && ignoring) ? true : undefined,\n \"data-pending\": dataAttr(pending),\n },\n });\n}\n\nMenuItem.displayName = \"MenuItem\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA+FA,SAAgB,SAAS,EACvB,QACA,kBAAkB,MAClB,cACA,WAAW,OACX,OACA,WACA,OACA,UACA,QACA,GAAG,QACa;CAChB,MAAM,OAAO,eAAe,WAAW;CAIvC,MAAM,YAAY,iBAAiB,kBAAkB,WAAW,YAAY;CAC5E,MAAM,EAAE,SAAS,QAAQ,iBAAiB;EACxC,gBAAgB,KAAK,KAAK,QAAQ;EAClC,oBAAoB;CACtB,CAAC;CAED,MAAM,EAAE,iBAAiB,YAAY;EACnC,MAAM;EACN,MAAM;EACN;EACA;EACA,WAAW,UAAU;GACnB,MAAM,UAA2B,oBAAoB,OAAO,CAAC,CAAC;GAQ9D,IAAI,CAJY,UACR,SAAS,OAAO,GACtB,wBAAwB,KAAK,KAAK,QAAQ,aAAa,OAAO,UAAU,IAAI,KAAA,CAEnE,GAAG,MAAM,eAAe;EACrC;CACF,CAAC;CAID,OAAO,UAA0D;EAC/D,gBAAgB;EAChB;EACA,OAAA;GAL6B;GAAS;EAKlC;EACJ;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;GACvD,GAAG;GAIH,iBAAiB,YAAa,WAAW,WAAY,OAAO,KAAA;GAC5D,gBAAgB,SAAS,OAAO;EAClC;CACF,CAAC;AACH;AAEA,SAAS,cAAc"}
1
+ {"version":3,"file":"menu-item.mjs","names":[],"sources":["../../src/menu/menu-item.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action/action-details.js\";\nimport type {\n Action,\n ActionDetails,\n RenderProp,\n StateValue,\n WhilePending,\n} from \"../internal/types.js\";\nimport { usePureTrigger } from \"../internal/action/use-pure-trigger.js\";\nimport { rendersButton, useRender } from \"../internal/use-render.js\";\nimport { useMenuContext } from \"./menu-context.js\";\nimport { useMenuItem } from \"./use-menu-item.js\";\n\n/** Details passed to `Menu.Item`'s `action`. */\nexport interface MenuItemDetails extends ActionDetails {}\n\n/**\n * State of `Menu.Item`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface MenuItemState {\n /** This item's `action` is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Menu.Item`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport interface MenuItemProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"onKeyDown\" | \"onPointerMove\" | \"disabled\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Runs inside this item's own transition (`data-pending` on the item); the menu stays open\n * until it settles, then the whole menu closes (`closeOnActivate`). May be a Server Function\n * (`details.event` is virtual). A rejection leaves the menu open and reaches the nearest Error\n * Boundary above the item. Without `action`, activation only closes.\n */\n action?: Action<[details: MenuItemDetails]>;\n /**\n * Close the whole menu once `action` settles.\n *\n * @defaultValue `true`\n */\n closeOnActivate?: boolean;\n /**\n * What a click, Enter or Space does while this item's `action` is pending. `\"ignore\"`:\n * nothing (the event is cancelled, `aria-disabled=\"true\"` meanwhile). `\"run\"`: the action runs\n * again (`data-pending` until every run has settled); a closing item closes the menu once,\n * when the last run settles and only if the latest run resolved (a rejection keeps the menu\n * open, as in `\"ignore\"` mode). No effect without `action`.\n *\n * @defaultValue `\"ignore\"`, or `\"run\"` with `closeOnActivate={false}`\n */\n whilePending?: WhilePending;\n /**\n * Renders `aria-disabled` and `data-disabled`: the item stays focusable and never activates.\n * It is an ordinary item for navigation; only the open focus skips items with `disabled`.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** Text typeahead matches when the item's text content is not representative (an icon). */\n label?: string;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MenuItemState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MenuItemState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, MenuItemState>;\n /** Replace the default `<button>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MenuItemState>;\n}\n\n/**\n * A menu command: `<button type=\"button\" role=\"menuitem\" tabindex=\"-1\">`. Click, Enter or Space\n * runs `action` in the item's own transition (`data-pending` on the item; a second activation\n * meanwhile is ignored and the item `aria-disabled`, unless `whilePending` is `\"run\"`, the\n * default of a `closeOnActivate={false}` item); once it resolves the whole menu stack closes\n * through the top-level Root (`openChangeAction(false, { reason: \"activate\" })` awaited, view\n * transition if set). Hovering the item focuses it.\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>`), `role`, `tabIndex`, `disabled`\n * (always absent), `aria-disabled`, `onClick`, `onKeyDown`, `onPointerMove`, `data-pending`,\n * `data-disabled`, `data-typeahead`.\n *\n * @see https://ui.funstack.work/components/menu\n */\nexport function MenuItem({\n action,\n closeOnActivate = true,\n whilePending,\n disabled = false,\n label,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuItemProps) {\n const menu = useMenuContext(\"Menu.Item\");\n // The close belongs to the top-level menu, so its open generation guards it.\n // Mixed ownership (conventions 2.5.1): an item the library closes the menu after ignores by\n // default; a keep-open item is a user-owned trigger and runs every activation.\n const trigger = usePureTrigger({\n whilePending,\n defaultWhilePending: closeOnActivate ? \"ignore\" : \"run\",\n openGeneration: menu.root.popover.openGeneration,\n });\n const { pending } = trigger;\n\n const { libraryProps } = useMenuItem({\n part: \"Menu.Item\",\n role: \"menuitem\",\n disabled,\n label,\n activate: (event) => {\n const details: MenuItemDetails = createActionDetails(event, {});\n // When ignoring, a second activation while this item's own run is in flight starts\n // nothing and is cancelled (the hook's guard): a link does not navigate, a composed\n // command does not run. Enter / Space reach here through the element's click, their keydown is cancelled.\n trigger.runActivation(\n event,\n () => action?.(details),\n closeOnActivate ? () => menu.root.popover.requestClose(event, \"activate\") : undefined,\n );\n },\n });\n\n const state: MenuItemState = { pending, disabled };\n\n return useRender<ComponentPropsWithRef<\"button\">, MenuItemState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n ...(rendersButton(render) && { type: \"button\" as const }),\n ...libraryProps,\n // Also while pending when ignoring: an item that will not act is unavailable to AT. The\n // item is never natively disabled (`useMenuItem`'s focusable branch). Navigation keys on\n // `data-disabled` (the `disabled` prop), so a pending item is still an enabled item.\n // `libraryProps` stands in for a `disabledButton` result: its `disabled` (always\n // `undefined`) and `aria-disabled` (the `disabled` prop) are the item's disabled branch.\n ...trigger.pendingProps(libraryProps),\n },\n });\n}\n\nMenuItem.displayName = \"MenuItem\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA8FA,SAAgB,SAAS,EACvB,QACA,kBAAkB,MAClB,cACA,WAAW,OACX,OACA,WACA,OACA,UACA,QACA,GAAG,QACa;CAChB,MAAM,OAAO,eAAe,WAAW;CAIvC,MAAM,UAAU,eAAe;EAC7B;EACA,qBAAqB,kBAAkB,WAAW;EAClD,gBAAgB,KAAK,KAAK,QAAQ;CACpC,CAAC;CACD,MAAM,EAAE,YAAY;CAEpB,MAAM,EAAE,iBAAiB,YAAY;EACnC,MAAM;EACN,MAAM;EACN;EACA;EACA,WAAW,UAAU;GACnB,MAAM,UAA2B,oBAAoB,OAAO,CAAC,CAAC;GAI9D,QAAQ,cACN,aACM,SAAS,OAAO,GACtB,wBAAwB,KAAK,KAAK,QAAQ,aAAa,OAAO,UAAU,IAAI,KAAA,CAC9E;EACF;CACF,CAAC;CAID,OAAO,UAA0D;EAC/D,gBAAgB;EAChB;EACA,OAAA;GAL6B;GAAS;EAKlC;EACJ;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;GACvD,GAAG;GAMH,GAAG,QAAQ,aAAa,YAAY;EACtC;CACF,CAAC;AACH;AAEA,SAAS,cAAc"}
@@ -1,4 +1,4 @@
1
- import { isPopoverOpen } from "../internal/popover-open.mjs";
1
+ import { isPopoverOpen } from "../internal/overlay/popover-open.mjs";
2
2
  import { isHandledBy } from "./menu-context.mjs";
3
3
  //#region src/menu/menu-outside.ts
4
4
  /**