@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,33 +1,27 @@
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 { useDevWarning } from "../internal/use-dev-warning.mjs";
5
5
  import { useRender } from "../internal/use-render.mjs";
6
6
  import { useLatest } from "../internal/use-latest.mjs";
7
- import { isPopoverOpen } from "../internal/popover-open.mjs";
7
+ import { isPopoverOpen } from "../internal/overlay/popover-open.mjs";
8
8
  import { DialogContext } from "../dialog/dialog-context.mjs";
9
- import { animationBaseline } from "../internal/use-exit-animation.mjs";
10
- import { callUrgentHandler } from "../internal/call-urgent-handler.mjs";
11
- import { announce } from "../internal/announce.mjs";
9
+ import { animationBaseline } from "../internal/overlay/use-exit-animation.mjs";
10
+ import { callUrgentHandler } from "../internal/action/call-urgent-handler.mjs";
12
11
  import { ToastViewportContext } from "./toast-context.mjs";
13
12
  import { toast, toastManagerInternals } from "./toast.mjs";
14
- import { DEFAULT_HOTKEY, matchesHotkey, regionLabel } from "./toast-hotkey.mjs";
13
+ import { DEFAULT_HOTKEY, regionLabel } from "./toast-hotkey.mjs";
15
14
  import { clearToastTimers, syncToastTimers } from "./toast-timers.mjs";
15
+ import { applyCommands, makeEntry, partition, withFlags } from "./toast-queue.mjs";
16
16
  import { useModalPortalHost } from "./use-modal-portal-host.mjs";
17
- import { applyCommands, makeEntry, partition, plainText, withFlags } from "./toast-queue.mjs";
17
+ import { useToastAnnouncements } from "./use-toast-announcements.mjs";
18
+ import { useToastFocus, useToastHotkey } from "./use-toast-focus.mjs";
19
+ import { useToastPauses } from "./use-toast-pauses.mjs";
18
20
  import { use, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
19
21
  import { createPortal } from "react-dom";
20
22
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
21
23
  //#region src/toast/toast-viewport.tsx
22
24
  const isDev = process.env.NODE_ENV !== "production";
23
- /** Document order. */
24
- function byDocumentPosition(a, b) {
25
- if (a === b) return 0;
26
- return a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
27
- }
28
- function anyPause(sources) {
29
- return sources.hover || sources.focus || sources.hidden || sources.blurred;
30
- }
31
25
  /**
32
26
  * The toast region: a `<section popover="manual">` named "Notifications (F8)", shown in the top
33
27
  * layer while it has toasts. Owns the queue (urgent state fed by `toast()`), the timers and their
@@ -39,7 +33,7 @@ function anyPause(sources) {
39
33
  *
40
34
  * @see https://ui.funstack.work/components/toast
41
35
  */
42
- function ToastViewport({ manager = toast, limit = 3, duration = 5e3, hotkey = DEFAULT_HOTKEY, announce: announce$1, children, className, style, render, ...rest }) {
36
+ function ToastViewport({ manager = toast, limit = 3, duration = 5e3, hotkey = DEFAULT_HOTKEY, announce, children, className, style, render, ...rest }) {
43
37
  const [entries, setEntries] = useState([]);
44
38
  const entriesRef = useRef(entries);
45
39
  const listener = useRef(null);
@@ -49,30 +43,29 @@ function ToastViewport({ manager = toast, limit = 3, duration = 5e3, hotkey = DE
49
43
  retain: () => handlers.current.retain()
50
44
  };
51
45
  const [rejected, setRejected] = useState(() => toastManagerInternals(manager).isTaken(listener.current));
46
+ const [duplicate, setDuplicate] = useState(false);
52
47
  const regionRef = useRef(null);
53
48
  const roots = useRef(/* @__PURE__ */ new Map());
54
49
  const suspended = useRef(/* @__PURE__ */ new Set());
55
50
  const timers = useRef(/* @__PURE__ */ new Map());
56
- const pauses = useRef({
57
- hover: false,
58
- focus: false,
59
- hidden: false,
60
- blurred: false
51
+ const pauses = useToastPauses(() => syncTimers());
52
+ const { paused, setPause, watch } = pauses;
53
+ const focus = useToastFocus({
54
+ entriesRef,
55
+ roots,
56
+ regionRef
61
57
  });
62
- const [paused, setPaused] = useState(false);
63
- /** Where focus goes back to once the last toast holding it leaves (design 7). */
64
- const returnTarget = useRef(null);
65
- const lastAnnounced = useRef(/* @__PURE__ */ new Map());
58
+ const { returnTargetRef, sortedRoots, moveFocusOut } = focus;
59
+ const { lastAnnouncedRef, queueAnnouncement, announceQueued } = useToastAnnouncements(regionRef);
66
60
  /** Per closing toast: the animations already running before `data-ending` applied. */
67
61
  const exitBaselines = useRef(/* @__PURE__ */ new Map());
68
- const announceBatch = useRef([]);
69
62
  const addedSinceEffect = useRef(false);
70
63
  const mounted = useRef(false);
71
64
  const latest = useLatest({
72
65
  limit,
73
66
  duration,
74
67
  hotkey,
75
- announce: announce$1
68
+ announce
76
69
  });
77
70
  const write = (next) => {
78
71
  entriesRef.current = next;
@@ -80,56 +73,12 @@ function ToastViewport({ manager = toast, limit = 3, duration = 5e3, hotkey = DE
80
73
  };
81
74
  const syncTimers = () => {
82
75
  syncToastTimers(timers.current, partition(entriesRef.current, latest.current.limit).visible, {
83
- halted: !mounted.current || anyPause(pauses.current),
76
+ halted: !mounted.current || pauses.anyHeld(),
84
77
  suspended: suspended.current,
85
78
  defaultDuration: latest.current.duration,
86
79
  expire: (id) => close([id], "timeout", void 0)
87
80
  });
88
81
  };
89
- const setPause = (source, value) => {
90
- if (pauses.current[source] === value) return;
91
- pauses.current[source] = value;
92
- syncTimers();
93
- setPaused(anyPause(pauses.current));
94
- };
95
- /** Open toasts' Root elements in document order. */
96
- const sortedRoots = (exclude) => {
97
- const open = new Set(entriesRef.current.filter((e) => !e.ending).map((e) => e.options.id));
98
- const list = [];
99
- for (const [id, element] of roots.current) {
100
- if (!open.has(id) || exclude?.has(id) || !element.isConnected) continue;
101
- list.push({
102
- id,
103
- element
104
- });
105
- }
106
- return list.sort((a, b) => byDocumentPosition(a.element, b.element));
107
- };
108
- /**
109
- * Before toasts close: if focus is inside one of them, move it to the next toast, else the
110
- * previous one, else where it was before the region was entered, else the body (design 7).
111
- */
112
- const moveFocusOut = (closing) => {
113
- const doc = regionRef.current?.ownerDocument ?? document;
114
- const active = doc.activeElement;
115
- if (!(active instanceof HTMLElement)) return;
116
- const all = sortedRoots();
117
- const index = all.findIndex(({ element }) => element.contains(active));
118
- if (index === -1 || !closing.has(all[index].id)) return;
119
- const after = all.slice(index + 1).find(({ id }) => !closing.has(id));
120
- const before = all.slice(0, index).reverse().find(({ id }) => !closing.has(id));
121
- const target = after ?? before;
122
- if (target !== void 0) {
123
- target.element.focus();
124
- return;
125
- }
126
- const stored = returnTarget.current;
127
- if (stored !== null && stored.isConnected && !regionRef.current?.contains(stored)) {
128
- stored.focus();
129
- if (doc.activeElement === stored) return;
130
- }
131
- active.blur();
132
- };
133
82
  /**
134
83
  * Records the animations running in each closing toast before `data-ending` applies: the exit
135
84
  * waits only for the ones the ending state started, not for a running progress bar.
@@ -171,7 +120,7 @@ function ToastViewport({ manager = toast, limit = 3, duration = 5e3, hotkey = DE
171
120
  const drop = (id) => {
172
121
  const next = entriesRef.current.filter((e) => !(e.ending && e.options.id === id));
173
122
  if (next.length === entriesRef.current.length) return;
174
- lastAnnounced.current.delete(id);
123
+ lastAnnouncedRef.current.delete(id);
175
124
  exitBaselines.current.delete(id);
176
125
  write(next);
177
126
  };
@@ -179,7 +128,7 @@ function ToastViewport({ manager = toast, limit = 3, duration = 5e3, hotkey = DE
179
128
  const result = applyCommands(entriesRef.current, commands, (id) => roots.current.has(id));
180
129
  for (const id of result.replaced) clearToastTimers(timers.current, id);
181
130
  for (const id of result.forgotten) {
182
- lastAnnounced.current.delete(id);
131
+ lastAnnouncedRef.current.delete(id);
183
132
  exitBaselines.current.delete(id);
184
133
  }
185
134
  if (result.added) addedSinceEffect.current = true;
@@ -203,27 +152,9 @@ function ToastViewport({ manager = toast, limit = 3, duration = 5e3, hotkey = DE
203
152
  next[index] = withFlags(entry, { actionPending: pending });
204
153
  write(next);
205
154
  };
206
- const flushAnnouncements = () => {
207
- const batch = announceBatch.current;
208
- announceBatch.current = [];
209
- if (batch.length === 0) return;
210
- const priority = batch.some((a) => a.priority === "high") ? "high" : "normal";
211
- announce(regionRef.current?.ownerDocument ?? document, batch.map((a) => a.text).join(" "), priority);
212
- };
213
- const queueAnnouncement = (id, text, priority) => {
214
- const map = lastAnnounced.current;
215
- if (map.has(id) && map.get(id) === text) return;
216
- map.set(id, text);
217
- if (text === null || text.trim() === "") return;
218
- if (announceBatch.current.length === 0) queueMicrotask(flushAnnouncements);
219
- announceBatch.current.push({
220
- text,
221
- priority
222
- });
223
- };
224
155
  const restore = (toasts) => {
225
156
  if (entriesRef.current.length > 0) return;
226
- for (const t of toasts) if (t.announced !== void 0) lastAnnounced.current.set(t.options.id, t.announced);
157
+ for (const t of toasts) if (t.announced !== void 0) lastAnnouncedRef.current.set(t.options.id, t.announced);
227
158
  write(toasts.map((t) => makeEntry(t.options, {
228
159
  promisePending: t.pending,
229
160
  actionPending: false,
@@ -232,7 +163,7 @@ function ToastViewport({ manager = toast, limit = 3, duration = 5e3, hotkey = DE
232
163
  addedSinceEffect.current = true;
233
164
  };
234
165
  const retain = () => {
235
- const announced = lastAnnounced.current;
166
+ const announced = lastAnnouncedRef.current;
236
167
  return entriesRef.current.filter((e) => !e.ending).map((e) => ({
237
168
  options: e.options,
238
169
  pending: e.promisePending,
@@ -243,7 +174,7 @@ function ToastViewport({ manager = toast, limit = 3, duration = 5e3, hotkey = DE
243
174
  const reset = () => {
244
175
  moveFocusOut(new Set(entriesRef.current.filter((e) => !e.ending).map((e) => e.options.id)));
245
176
  clearToastTimers(timers.current);
246
- lastAnnounced.current.clear();
177
+ lastAnnouncedRef.current.clear();
247
178
  exitBaselines.current.clear();
248
179
  write([]);
249
180
  };
@@ -256,7 +187,6 @@ function ToastViewport({ manager = toast, limit = 3, duration = 5e3, hotkey = DE
256
187
  drop,
257
188
  setActionPending,
258
189
  queueAnnouncement,
259
- setPause,
260
190
  syncTimers
261
191
  });
262
192
  const context = useMemo(() => ({
@@ -289,62 +219,42 @@ function ToastViewport({ manager = toast, limit = 3, duration = 5e3, hotkey = DE
289
219
  const unsubscribe = toastManagerInternals(manager).subscribe(listener.current);
290
220
  if (unsubscribe === null) {
291
221
  setRejected(true);
292
- if (isDev) console.error("Toast.Viewport: another Toast.Viewport already renders this manager; this one renders nothing. Use one Viewport per manager, or `createToastManager()` for a second queue.");
222
+ setDuplicate(true);
293
223
  return;
294
224
  }
295
225
  setRejected(false);
226
+ setDuplicate(false);
296
227
  return unsubscribe;
297
228
  }, [manager, handlers]);
298
229
  useEffect(() => {
299
230
  if (rejected) return;
300
231
  mounted.current = true;
301
232
  const doc = regionRef.current?.ownerDocument ?? document;
302
- const view = doc.defaultView ?? window;
303
- pauses.current.hidden = doc.visibilityState === "hidden";
304
- const onVisibility = () => handlers.current.setPause("hidden", doc.visibilityState === "hidden");
305
- const onWindowBlur = (event) => {
306
- if (!(event.target instanceof Node)) handlers.current.setPause("blurred", true);
307
- };
308
- const onWindowFocus = (event) => {
309
- if (!(event.target instanceof Node)) handlers.current.setPause("blurred", false);
310
- };
311
- doc.addEventListener("visibilitychange", onVisibility);
312
- view.addEventListener("blur", onWindowBlur);
313
- view.addEventListener("focus", onWindowFocus);
233
+ const unwatch = watch(doc);
314
234
  handlers.current.syncTimers();
315
- setPaused(anyPause(pauses.current));
316
235
  const map = timers.current;
317
236
  return () => {
318
237
  mounted.current = false;
319
- doc.removeEventListener("visibilitychange", onVisibility);
320
- view.removeEventListener("blur", onWindowBlur);
321
- view.removeEventListener("focus", onWindowFocus);
238
+ unwatch();
322
239
  clearToastTimers(map);
323
240
  };
324
- }, [handlers, rejected]);
325
- const hotkeyKey = hotkey === null ? null : hotkey.join("\0");
326
- useEffect(() => {
327
- if (hotkeyKey === null || rejected) return;
328
- const keys = hotkeyKey.split("\0");
329
- const doc = regionRef.current?.ownerDocument ?? document;
330
- const onKeyDown = (event) => {
331
- if (event.defaultPrevented || !matchesHotkey(keys, event)) return;
332
- const newest = sortedRoots().at(-1);
333
- if (newest === void 0) return;
334
- event.preventDefault();
335
- const active = doc.activeElement;
336
- if (active instanceof HTMLElement && !regionRef.current?.contains(active)) returnTarget.current = active;
337
- newest.element.focus();
338
- };
339
- doc.addEventListener("keydown", onKeyDown);
340
- return () => doc.removeEventListener("keydown", onKeyDown);
341
- }, [hotkeyKey, rejected]);
241
+ }, [
242
+ handlers,
243
+ rejected,
244
+ watch
245
+ ]);
246
+ useToastHotkey({
247
+ hotkey,
248
+ rejected,
249
+ regionRef,
250
+ focus
251
+ });
342
252
  const { portalled, host, anchorRef } = useModalPortalHost(() => setPause("hover", false));
343
253
  useLayoutEffect(() => {
344
254
  const region = regionRef.current;
345
255
  const current = entriesRef.current;
346
- if (pauses.current.focus && (region === null || !region.contains(region.ownerDocument.activeElement))) {
347
- returnTarget.current = null;
256
+ if (pauses.holding("focus") && (region === null || !region.contains(region.ownerDocument.activeElement))) {
257
+ returnTargetRef.current = null;
348
258
  setPause("focus", false);
349
259
  }
350
260
  if (region !== null && region.isConnected && region.hasAttribute("popover")) {
@@ -359,19 +269,14 @@ function ToastViewport({ manager = toast, limit = 3, duration = 5e3, hotkey = DE
359
269
  } else if (open) region.hidePopover();
360
270
  } catch {}
361
271
  }
362
- if (current.length === 0 && pauses.current.hover) setPause("hover", false);
272
+ if (current.length === 0 && pauses.holding("hover")) setPause("hover", false);
363
273
  addedSinceEffect.current = false;
364
274
  const { visible, queued } = partition(current, latest.current.limit);
365
- for (const entry of queued) {
366
- const id = entry.options.id;
367
- if (lastAnnounced.current.has(id)) continue;
368
- const resolver = entry.options.announce ?? latest.current.announce;
369
- const text = resolver ? resolver(entry.item) : [plainText(entry.options.title), plainText(entry.options.description)].filter((t) => t !== "").join(" ");
370
- queueAnnouncement(id, text, entry.options.priority ?? "normal");
371
- }
275
+ announceQueued(queued, latest.current.announce);
372
276
  for (const entry of visible) if (entry.ending && !roots.current.has(entry.options.id)) drop(entry.options.id);
373
277
  syncTimers();
374
278
  });
279
+ useDevWarning(duplicate, isDev && "Toast.Viewport: another Toast.Viewport already renders this manager; this one renders nothing. Use one Viewport per manager, or `createToastManager()` for a second queue.");
375
280
  const insideDialog = use(DialogContext) !== null;
376
281
  useDevWarning(insideDialog, isDev && "Toast.Viewport: rendered inside a Dialog. The region would close with the dialog; render the Viewport once near the root of the app (it moves into open modal Dialogs by itself).");
377
282
  const { visible, queued } = partition(entries, limit);
@@ -391,13 +296,13 @@ function ToastViewport({ manager = toast, limit = 3, duration = 5e3, hotkey = DE
391
296
  const onFocus = (event) => {
392
297
  const region = event.currentTarget;
393
298
  const from = event.relatedTarget;
394
- if (!(from instanceof Node) || !region.contains(from)) returnTarget.current ??= from instanceof HTMLElement ? from : null;
299
+ if (!(from instanceof Node) || !region.contains(from)) returnTargetRef.current ??= from instanceof HTMLElement ? from : null;
395
300
  setPause("focus", true);
396
301
  };
397
302
  const onBlur = (event) => {
398
303
  const to = event.relatedTarget;
399
304
  if (to instanceof Node && event.currentTarget.contains(to)) return;
400
- returnTarget.current = null;
305
+ returnTargetRef.current = null;
401
306
  setPause("focus", false);
402
307
  };
403
308
  const libraryProps = {
@@ -1 +1 @@
1
- {"version":3,"file":"toast-viewport.mjs","names":["defaultManager"],"sources":["../../src/toast/toast-viewport.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, FocusEvent, ReactNode } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { DialogContext } from \"../dialog/dialog-context.js\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { announce as speak } from \"../internal/announce.js\";\nimport { callUrgentHandler } from \"../internal/call-urgent-handler.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { isPopoverOpen } from \"../internal/popover-open.js\";\nimport type { ChangeReason, RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { animationBaseline } from \"../internal/use-exit-animation.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { toast as defaultManager, toastManagerInternals } from \"./toast.js\";\nimport type {\n RetainedToast,\n ToastCommand,\n ToastItem,\n ToastListener,\n ToastManager,\n ToastPriority,\n} from \"./toast.js\";\nimport { ToastViewportContext } from \"./toast-context.js\";\nimport type { ToastViewportContextValue } from \"./toast-context.js\";\nimport { DEFAULT_HOTKEY, matchesHotkey, regionLabel } from \"./toast-hotkey.js\";\nimport { clearToastTimers, syncToastTimers } from \"./toast-timers.js\";\nimport type { ToastTimer } from \"./toast-timers.js\";\nimport { useModalPortalHost } from \"./use-modal-portal-host.js\";\nimport { applyCommands, makeEntry, partition, plainText, withFlags } from \"./toast-queue.js\";\nimport type { Entry } from \"./toast-queue.js\";\n\n/**\n * State of `Toast.Viewport`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface ToastViewportState {\n /** Rendered toasts, chronological (oldest first), exiting ones included. */\n readonly toasts: readonly ToastItem[];\n /** Toasts waiting beyond `limit`. */\n readonly queued: number;\n /** A viewport-wide pause holds (pointer over the region, focus inside, hidden document, blurred window). */\n readonly paused: boolean;\n}\n\n/**\n * Props of `Toast.Viewport`.\n *\n * @see https://ui.funstack.work/components/toast\n */\nexport interface ToastViewportProps extends Omit<\n ComponentPropsWithRef<\"section\">,\n | \"popover\"\n | \"className\"\n | \"style\"\n | \"children\"\n | \"onPointerEnter\"\n | \"onPointerLeave\"\n | \"onFocus\"\n | \"onBlur\"\n | \"onKeyDown\"\n> {\n /**\n * The queue to render (from `createToastManager()`).\n *\n * @defaultValue the module-level `toast`\n */\n manager?: ToastManager;\n /**\n * Toasts rendered at once; further ones wait in order (never dropped).\n *\n * @defaultValue `3`\n */\n limit?: number;\n /**\n * Default `duration` of a toast in milliseconds; `null` for persistent.\n *\n * @defaultValue `5000`\n */\n duration?: number | null;\n /**\n * Keys that focus the newest toast: `event.code` values and modifier names (`\"altKey\"`,\n * `\"ctrlKey\"`, `\"metaKey\"`, `\"shiftKey\"`), all of which must match, with no other modifier\n * held. `null` installs no listener.\n *\n * @defaultValue `[\"F8\"]`\n */\n hotkey?: readonly string[] | null;\n /**\n * The text `document.ariaNotify()` speaks for a toast (localisation); `null` announces nothing.\n * A toast's own `announce` wins.\n *\n * @defaultValue the text of the toast's Title and Description\n */\n announce?: (toast: ToastItem) => string | null;\n /** Usually a function of the state mapping `state.toasts` to `Toast.Root`s. */\n children?: StateValue<ReactNode, ToastViewportState>;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ToastViewportState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ToastViewportState>;\n /** Must render an element that can carry `popover` (a `<section>` by default). */\n render?: RenderProp<ComponentPropsWithRef<\"section\">, ToastViewportState>;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** Document order. */\nfunction byDocumentPosition(a: Element, b: Element): number {\n if (a === b) return 0;\n return a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;\n}\n\ninterface PauseSources {\n hover: boolean;\n focus: boolean;\n hidden: boolean;\n blurred: boolean;\n}\n\nfunction anyPause(sources: PauseSources): boolean {\n return sources.hover || sources.focus || sources.hidden || sources.blurred;\n}\n\n/**\n * The toast region: a `<section popover=\"manual\">` named \"Notifications (F8)\", shown in the top\n * layer while it has toasts. Owns the queue (urgent state fed by `toast()`), the timers and their\n * pausing, the hotkey, focus return, announcements through `document.ariaNotify()`, and the move\n * into the topmost open modal `Dialog` (a region outside it would be inert).\n *\n * Owned keys (conventions 1.2): `popover`, `aria-label` (the consumer's own `aria-label` wins\n * verbatim), `data-paused`, `data-empty`, and the pointer / focus handlers.\n *\n * @see https://ui.funstack.work/components/toast\n */\nexport function ToastViewport({\n manager = defaultManager,\n limit = 3,\n duration = 5000,\n hotkey = DEFAULT_HOTKEY,\n announce,\n children,\n className,\n style,\n render,\n ...rest\n}: ToastViewportProps) {\n // --- The queue: urgent state, written only from handlers, microtasks and effects -----------\n const [entries, setEntries] = useState<readonly Entry[]>([]);\n // The latest queue, written together with every `setEntries`: the dispatchers read and write\n // it synchronously so a burst of commands composes (and side effects stay out of updaters).\n const entriesRef = useRef<readonly Entry[]>(entries);\n const listener = useRef<ToastListener | null>(null);\n listener.current ??= {\n restore: (toasts: readonly RetainedToast[]) => handlers.current.restore(toasts),\n apply: (commands: readonly ToastCommand[]) => handlers.current.apply(commands),\n retain: () => handlers.current.retain(),\n };\n // A second Viewport on a taken manager renders nothing from its first render on (the effect\n // below confirms or clears it once the subscription is attempted).\n const [rejected, setRejected] = useState(() =>\n toastManagerInternals(manager).isTaken(listener.current!),\n );\n\n const regionRef = useRef<HTMLElement | null>(null);\n const roots = useRef(new Map<string, HTMLElement>());\n const suspended = useRef(new Set<string>());\n const timers = useRef(new Map<string, ToastTimer>());\n const pauses = useRef<PauseSources>({\n hover: false,\n focus: false,\n hidden: false,\n blurred: false,\n });\n const [paused, setPaused] = useState(false);\n /** Where focus goes back to once the last toast holding it leaves (design 7). */\n const returnTarget = useRef<HTMLElement | null>(null);\n const lastAnnounced = useRef(new Map<string, string | null>());\n /** Per closing toast: the animations already running before `data-ending` applied. */\n const exitBaselines = useRef(new Map<string, ReadonlySet<Animation>>());\n const announceBatch = useRef<{ text: string; priority: ToastPriority }[]>([]);\n const addedSinceEffect = useRef(false);\n const mounted = useRef(false);\n\n const latest = useLatest({ limit, duration, hotkey, announce });\n\n const write = (next: readonly Entry[]): void => {\n entriesRef.current = next;\n setEntries(next);\n };\n\n // --- Timers (design 6) ----------------------------------------------------------------------\n\n const syncTimers = (): void => {\n syncToastTimers(timers.current, partition(entriesRef.current, latest.current.limit).visible, {\n halted: !mounted.current || anyPause(pauses.current),\n suspended: suspended.current,\n defaultDuration: latest.current.duration,\n expire: (id) => close([id], \"timeout\", undefined),\n });\n };\n\n const setPause = (source: keyof PauseSources, value: boolean): void => {\n if (pauses.current[source] === value) return;\n pauses.current[source] = value;\n // Applied synchronously in the event, before any timer callback can run (design 14 item 9).\n syncTimers();\n setPaused(anyPause(pauses.current));\n };\n\n // --- Focus ----------------------------------------------------------------------------------\n\n /** Open toasts' Root elements in document order. */\n const sortedRoots = (exclude?: ReadonlySet<string>): { id: string; element: HTMLElement }[] => {\n const open = new Set(entriesRef.current.filter((e) => !e.ending).map((e) => e.options.id));\n const list: { id: string; element: HTMLElement }[] = [];\n for (const [id, element] of roots.current) {\n if (!open.has(id) || exclude?.has(id) || !element.isConnected) continue;\n list.push({ id, element });\n }\n return list.sort((a, b) => byDocumentPosition(a.element, b.element));\n };\n\n /**\n * Before toasts close: if focus is inside one of them, move it to the next toast, else the\n * previous one, else where it was before the region was entered, else the body (design 7).\n */\n const moveFocusOut = (closing: ReadonlySet<string>): void => {\n const doc = regionRef.current?.ownerDocument ?? document;\n const active = doc.activeElement;\n if (!(active instanceof HTMLElement)) return;\n const all = sortedRoots();\n const index = all.findIndex(({ element }) => element.contains(active));\n if (index === -1 || !closing.has(all[index]!.id)) return;\n const after = all.slice(index + 1).find(({ id }) => !closing.has(id));\n const before = all\n .slice(0, index)\n .reverse()\n .find(({ id }) => !closing.has(id));\n const target = after ?? before;\n if (target !== undefined) {\n target.element.focus();\n return;\n }\n const stored = returnTarget.current;\n if (stored !== null && stored.isConnected && !regionRef.current?.contains(stored)) {\n stored.focus();\n if (doc.activeElement === stored) return;\n }\n active.blur();\n };\n\n // --- Queue writes ---------------------------------------------------------------------------\n\n /**\n * Records the animations running in each closing toast before `data-ending` applies: the exit\n * waits only for the ones the ending state started, not for a running progress bar.\n */\n const snapshotExitBaselines = (ids: Iterable<string>): void => {\n for (const id of ids) {\n const element = roots.current.get(id);\n if (element === undefined) continue;\n exitBaselines.current.set(id, animationBaseline(element));\n }\n };\n\n /**\n * A toast's `onClose` (#148: a handler, not an action): called synchronously where the close is\n * applied to the queue, after the entry is marked ending, outside any transition, and not\n * awaited (`callUrgentHandler`: a throw or a returned promise's rejection goes to\n * `reportError`, the queue write above stands).\n */\n const callCloseHandlers = (\n closed: readonly Entry[],\n reason: ChangeReason,\n event: Event | undefined,\n ): void => {\n for (const entry of closed) {\n const onClose = entry.options.onClose;\n if (onClose === undefined) continue;\n callUrgentHandler(onClose, createActionDetails(event, { id: entry.options.id, reason }));\n }\n };\n\n const close = (ids: readonly string[], reason: ChangeReason, event: Event | undefined): void => {\n const wanted = new Set(ids);\n const closing = entriesRef.current.filter((e) => !e.ending && wanted.has(e.options.id));\n if (closing.length === 0) return;\n const closingIds = new Set(closing.map((e) => e.options.id));\n moveFocusOut(closingIds);\n snapshotExitBaselines(closingIds);\n write(\n entriesRef.current.map((e) =>\n closingIds.has(e.options.id) ? withFlags(e, { ending: true }) : e,\n ),\n );\n syncTimers();\n callCloseHandlers(closing, reason, event);\n };\n\n const drop = (id: string): void => {\n const next = entriesRef.current.filter((e) => !(e.ending && e.options.id === id));\n if (next.length === entriesRef.current.length) return;\n lastAnnounced.current.delete(id);\n exitBaselines.current.delete(id);\n write(next);\n };\n\n const apply = (commands: readonly ToastCommand[]): void => {\n const result = applyCommands(entriesRef.current, commands, (id) => roots.current.has(id));\n for (const id of result.replaced) clearToastTimers(timers.current, id);\n for (const id of result.forgotten) {\n lastAnnounced.current.delete(id);\n exitBaselines.current.delete(id);\n }\n if (result.added) addedSinceEffect.current = true;\n if (isDev) {\n for (const id of result.missing) {\n console.error(`toast.update: no toast with id \"${id}\"; the update is ignored.`);\n }\n }\n if (result.dismissed.length === 0) {\n write(result.next);\n return;\n }\n moveFocusOut(result.leaving);\n snapshotExitBaselines(result.leaving);\n write(result.next);\n syncTimers();\n callCloseHandlers(result.dismissed, \"dismiss\", undefined);\n };\n\n const setActionPending = (id: string, pending: boolean): void => {\n const index = entriesRef.current.findIndex((e) => e.options.id === id);\n if (index === -1) return;\n const entry = entriesRef.current[index]!;\n if (entry.actionPending === pending) return;\n const next = [...entriesRef.current];\n next[index] = withFlags(entry, { actionPending: pending });\n write(next);\n };\n\n // --- Announcements (design 5) ---------------------------------------------------------------\n\n const flushAnnouncements = (): void => {\n const batch = announceBatch.current;\n announceBatch.current = [];\n if (batch.length === 0) return;\n const priority = batch.some((a) => a.priority === \"high\") ? \"high\" : \"normal\";\n speak(\n regionRef.current?.ownerDocument ?? document,\n batch.map((a) => a.text).join(\" \"),\n priority,\n );\n };\n\n const queueAnnouncement = (id: string, text: string | null, priority: ToastPriority): void => {\n const map = lastAnnounced.current;\n if (map.has(id) && map.get(id) === text) return;\n map.set(id, text);\n if (text === null || text.trim() === \"\") return;\n if (announceBatch.current.length === 0) queueMicrotask(flushAnnouncements);\n announceBatch.current.push({ text, priority });\n };\n\n // The callbacks below read only refs, so one context value serves the Viewport's whole life.\n const restore = (toasts: readonly RetainedToast[]): void => {\n if (entriesRef.current.length > 0) return;\n // Already announced by the previous Viewport: not again on every remount.\n for (const t of toasts) {\n if (t.announced !== undefined) lastAnnounced.current.set(t.options.id, t.announced);\n }\n write(\n toasts.map((t) =>\n makeEntry(t.options, { promisePending: t.pending, actionPending: false, ending: false }),\n ),\n );\n addedSinceEffect.current = true;\n };\n\n const retain = (): readonly RetainedToast[] => {\n const announced = lastAnnounced.current;\n return entriesRef.current\n .filter((e) => !e.ending)\n .map((e) => ({\n options: e.options,\n pending: e.promisePending,\n announced: announced.has(e.options.id) ? announced.get(e.options.id) : undefined,\n }));\n };\n\n /** Forgets the queue of the previous manager (its own copy is retained by that manager). */\n const reset = (): void => {\n moveFocusOut(new Set(entriesRef.current.filter((e) => !e.ending).map((e) => e.options.id)));\n clearToastTimers(timers.current);\n lastAnnounced.current.clear();\n exitBaselines.current.clear();\n write([]);\n };\n\n const handlers = useLatest({\n apply,\n restore,\n retain,\n reset,\n close,\n drop,\n setActionPending,\n queueAnnouncement,\n setPause,\n syncTimers,\n });\n\n const context = useMemo<ToastViewportContextValue>(\n () => ({\n close: (ids, reason, event) => handlers.current.close(ids, reason, event),\n drop: (id) => handlers.current.drop(id),\n setActionPending: (id, pending) => handlers.current.setActionPending(id, pending),\n setSuspended: (id, value) => {\n if (value) suspended.current.add(id);\n else suspended.current.delete(id);\n handlers.current.syncTimers();\n },\n registerRoot: (id, element) => {\n if (element === null) roots.current.delete(id);\n else roots.current.set(id, element);\n },\n focusSibling: (id, direction) => {\n const all = sortedRoots();\n const index = all.findIndex((r) => r.id === id);\n if (index === -1) return;\n all[index + direction]?.element.focus();\n },\n announce: (id, text, priority) => handlers.current.queueAnnouncement(id, text, priority),\n exitBaseline: (id) => exitBaselines.current.get(id),\n announcer: () => latest.current.announce,\n }),\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- refs only (`sortedRoots` reads refs)\n [handlers, latest],\n );\n\n // --- Subscription ---------------------------------------------------------------------------\n\n const subscribedManager = useRef<ToastManager | null>(null);\n useEffect(() => {\n // A new `manager`: the previous one kept its toasts on unsubscribe (the previous run's\n // cleanup); start empty so the new one's retained toasts are restored and no command of\n // one queue reaches the other's toasts. The same manager again (StrictMode, Activity) keeps\n // the entries.\n if (subscribedManager.current !== null && subscribedManager.current !== manager) {\n handlers.current.reset();\n }\n subscribedManager.current = manager;\n const unsubscribe = toastManagerInternals(manager).subscribe(listener.current!);\n if (unsubscribe === null) {\n setRejected(true);\n if (isDev) {\n console.error(\n \"Toast.Viewport: another Toast.Viewport already renders this manager; this one renders \" +\n \"nothing. Use one Viewport per manager, or `createToastManager()` for a second queue.\",\n );\n }\n return;\n }\n setRejected(false);\n return unsubscribe;\n }, [manager, handlers]);\n\n // --- Lifecycle, pause sources, hotkey --------------------------------------------------------\n\n useEffect(() => {\n if (rejected) return;\n mounted.current = true;\n const doc = regionRef.current?.ownerDocument ?? document;\n const view = doc.defaultView ?? window;\n pauses.current.hidden = doc.visibilityState === \"hidden\";\n const onVisibility = (): void =>\n handlers.current.setPause(\"hidden\", doc.visibilityState === \"hidden\");\n // The window's own focus and blur; an element's (which do not bubble) never reach here.\n const onWindowBlur = (event: Event): void => {\n if (!(event.target instanceof Node)) handlers.current.setPause(\"blurred\", true);\n };\n const onWindowFocus = (event: Event): void => {\n if (!(event.target instanceof Node)) handlers.current.setPause(\"blurred\", false);\n };\n doc.addEventListener(\"visibilitychange\", onVisibility);\n view.addEventListener(\"blur\", onWindowBlur);\n view.addEventListener(\"focus\", onWindowFocus);\n handlers.current.syncTimers();\n setPaused(anyPause(pauses.current));\n const map = timers.current;\n return () => {\n mounted.current = false;\n doc.removeEventListener(\"visibilitychange\", onVisibility);\n view.removeEventListener(\"blur\", onWindowBlur);\n view.removeEventListener(\"focus\", onWindowFocus);\n // Unmounting stops the timers; the queue itself is retained by the manager.\n clearToastTimers(map);\n };\n }, [handlers, rejected]);\n\n const hotkeyKey = hotkey === null ? null : hotkey.join(\"\\u0000\");\n useEffect(() => {\n if (hotkeyKey === null || rejected) return;\n const keys = hotkeyKey.split(\"\\u0000\");\n const doc = regionRef.current?.ownerDocument ?? document;\n const onKeyDown = (event: KeyboardEvent): void => {\n if (event.defaultPrevented || !matchesHotkey(keys, event)) return;\n const all = sortedRoots();\n const newest = all.at(-1);\n if (newest === undefined) return;\n event.preventDefault();\n const active = doc.activeElement;\n if (active instanceof HTMLElement && !regionRef.current?.contains(active)) {\n returnTarget.current = active;\n }\n newest.element.focus();\n };\n doc.addEventListener(\"keydown\", onKeyDown);\n return () => doc.removeEventListener(\"keydown\", onKeyDown);\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- `sortedRoots` reads refs only\n }, [hotkeyKey, rejected]);\n\n // --- The portal host (design 4.3) ------------------------------------------------------------\n\n // Keep this call before the region layout effect below: the host's move hides the popover\n // (removal steps), which that effect shows again in the same commit. A moved region gets no\n // `pointerleave`: drop the hover pause; a pointer still over it enters it again on its next move.\n const { portalled, host, anchorRef } = useModalPortalHost(() => setPause(\"hover\", false));\n\n // --- After every commit: region, timers, queued announcements, orphan exits ----------------\n\n useLayoutEffect(() => {\n const region = regionRef.current;\n const current = entriesRef.current;\n // Focus that left with a remount (a move into or out of a dialog) fires no `focusout`.\n if (\n pauses.current.focus &&\n (region === null || !region.contains(region.ownerDocument.activeElement))\n ) {\n returnTarget.current = null;\n setPause(\"focus\", false);\n }\n if (region !== null && region.isConnected && region.hasAttribute(\"popover\")) {\n const open = isPopoverOpen(region);\n try {\n if (current.length > 0) {\n if (!open) region.showPopover();\n else if (addedSinceEffect.current) {\n // Re-raise to the top of the top layer, above a menu or popover opened since\n // (design 4.2). No style flush in between, so nothing is re-created.\n region.hidePopover();\n region.showPopover();\n }\n } else if (open) {\n region.hidePopover();\n }\n } catch {\n // A render element without popover support; nothing to show.\n }\n }\n // An emptied region is hidden, often right under the pointer (its last toast's Close), and\n // a hidden element gets no `pointerleave`: the next toast must not start paused.\n if (current.length === 0 && pauses.current.hover) setPause(\"hover\", false);\n addedSinceEffect.current = false;\n\n const { visible, queued } = partition(current, latest.current.limit);\n // Queued toasts are announced on add (design 5): from their plain-text fields, since they\n // have no DOM yet. Visible ones announce from their Root once their content committed.\n for (const entry of queued) {\n const id = entry.options.id;\n if (lastAnnounced.current.has(id)) continue;\n const resolver = entry.options.announce ?? latest.current.announce;\n const text = resolver\n ? resolver(entry.item)\n : [plainText(entry.options.title), plainText(entry.options.description)]\n .filter((t) => t !== \"\")\n .join(\" \");\n queueAnnouncement(id, text, entry.options.priority ?? \"normal\");\n }\n // An ending toast without a Root (the consumer did not render one) has nothing to animate.\n for (const entry of visible) {\n if (entry.ending && !roots.current.has(entry.options.id)) drop(entry.options.id);\n }\n syncTimers();\n });\n\n // --- Development checks ---------------------------------------------------------------------\n\n // A Viewport inside a library Dialog would close (and unmount) with it.\n const insideDialog = use(DialogContext) !== null;\n useDevWarning(\n insideDialog,\n isDev &&\n \"Toast.Viewport: rendered inside a Dialog. The region would close with the dialog; render \" +\n \"the Viewport once near the root of the app (it moves into open modal Dialogs by itself).\",\n );\n\n // --- Render ---------------------------------------------------------------------------------\n\n const { visible, queued } = partition(entries, limit);\n const state: ToastViewportState = {\n toasts: visible.map((e) => e.item),\n queued: queued.length,\n paused,\n };\n\n const regionCallbackRef = useCallback((element: HTMLElement) => {\n regionRef.current = element;\n return () => {\n if (regionRef.current === element) regionRef.current = null;\n };\n }, []);\n\n // Touch lifts the pointer at once (`pointerleave` follows `pointerup`), so a tap never sticks.\n const onPointerEnter = (): void => setPause(\"hover\", true);\n const onPointerLeave = (): void => setPause(\"hover\", false);\n const onFocus = (event: FocusEvent<HTMLElement>): void => {\n const region = event.currentTarget;\n const from = event.relatedTarget;\n if (!(from instanceof Node) || !region.contains(from)) {\n returnTarget.current ??= from instanceof HTMLElement ? from : null;\n }\n setPause(\"focus\", true);\n };\n const onBlur = (event: FocusEvent<HTMLElement>): void => {\n const to = event.relatedTarget;\n if (to instanceof Node && event.currentTarget.contains(to)) return;\n returnTarget.current = null;\n setPause(\"focus\", false);\n };\n\n const libraryProps: ComponentPropsWithRef<\"section\"> & DataAttributes = {\n popover: \"manual\",\n \"aria-label\": rest[\"aria-label\"] ?? regionLabel(hotkey),\n \"data-paused\": dataAttr(paused),\n \"data-empty\": dataAttr(state.toasts.length === 0),\n onPointerEnter,\n onPointerLeave,\n onFocus,\n onBlur,\n };\n\n const region = useRender<ComponentPropsWithRef<\"section\">, ToastViewportState>({\n defaultElement: \"section\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps,\n ref: regionCallbackRef,\n });\n\n if (rejected) return null;\n const content = <ToastViewportContext value={context}>{region}</ToastViewportContext>;\n if (!portalled || host === null) return content;\n return (\n <>\n <div ref={anchorRef} style={ANCHOR_STYLE} />\n {createPortal(content, host)}\n </>\n );\n}\n\nconst ANCHOR_STYLE: CSSProperties = { display: \"contents\" };\n\nToastViewport.displayName = \"ToastViewport\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA2GA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAGvC,SAAS,mBAAmB,GAAY,GAAoB;CAC1D,IAAI,MAAM,GAAG,OAAO;CACpB,OAAO,EAAE,wBAAwB,CAAC,IAAI,KAAK,8BAA8B,KAAK;AAChF;AASA,SAAS,SAAS,SAAgC;CAChD,OAAO,QAAQ,SAAS,QAAQ,SAAS,QAAQ,UAAU,QAAQ;AACrE;;;;;;;;;;;;AAaA,SAAgB,cAAc,EAC5B,UAAUA,OACV,QAAQ,GACR,WAAW,KACX,SAAS,gBACT,UAAA,YACA,UACA,WACA,OACA,QACA,GAAG,QACkB;CAErB,MAAM,CAAC,SAAS,cAAc,SAA2B,CAAC,CAAC;CAG3D,MAAM,aAAa,OAAyB,OAAO;CACnD,MAAM,WAAW,OAA6B,IAAI;CAClD,SAAS,YAAY;EACnB,UAAU,WAAqC,SAAS,QAAQ,QAAQ,MAAM;EAC9E,QAAQ,aAAsC,SAAS,QAAQ,MAAM,QAAQ;EAC7E,cAAc,SAAS,QAAQ,OAAO;CACxC;CAGA,MAAM,CAAC,UAAU,eAAe,eAC9B,sBAAsB,OAAO,CAAC,CAAC,QAAQ,SAAS,OAAQ,CAC1D;CAEA,MAAM,YAAY,OAA2B,IAAI;CACjD,MAAM,QAAQ,uBAAO,IAAI,IAAyB,CAAC;CACnD,MAAM,YAAY,uBAAO,IAAI,IAAY,CAAC;CAC1C,MAAM,SAAS,uBAAO,IAAI,IAAwB,CAAC;CACnD,MAAM,SAAS,OAAqB;EAClC,OAAO;EACP,OAAO;EACP,QAAQ;EACR,SAAS;CACX,CAAC;CACD,MAAM,CAAC,QAAQ,aAAa,SAAS,KAAK;;CAE1C,MAAM,eAAe,OAA2B,IAAI;CACpD,MAAM,gB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;CAC1D,MAAM,WAAW,UAAyC;EACxD,MAAM,SAAS,MAAM;EACrB,MAAM,OAAO,MAAM;EACnB,IAAI,EAAE,gBAAgB,SAAS,CAAC,OAAO,SAAS,IAAI,GAClD,aAAa,YAAY,gBAAgB,cAAc,OAAO;EAEhE,SAAS,SAAS,IAAI;CACxB;CACA,MAAM,UAAU,UAAyC;EACvD,MAAM,KAAK,MAAM;EACjB,IAAI,cAAc,QAAQ,MAAM,cAAc,SAAS,EAAE,GAAG;EAC5D,aAAa,UAAU;EACvB,SAAS,SAAS,KAAK;CACzB;CAEA,MAAM,eAAkE;EACtE,SAAS;EACT,cAAc,KAAK,iBAAiB,YAAY,MAAM;EACtD,eAAe,SAAS,MAAM;EAC9B,cAAc,SAAS,MAAM,OAAO,WAAW,CAAC;EAChD;EACA;EACA;EACA;CACF;CAEA,MAAM,SAAS,UAAgE;EAC7E,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;EACA,KAAK;CACP,CAAC;CAED,IAAI,UAAU,OAAO;CACrB,MAAM,UAAU,oBAAC,sBAAD;EAAsB,OAAO;EAAU,UAAA;CAA6B,CAAA;CACpF,IAAI,CAAC,aAAa,SAAS,MAAM,OAAO;CACxC,OACE,qBAAA,UAAA,EAAA,UAAA,CACE,oBAAC,OAAD;EAAK,KAAK;EAAW,OAAO;CAAe,CAAA,GAC1C,aAAa,SAAS,IAAI,CAC3B,EAAA,CAAA;AAEN;AAEA,MAAM,eAA8B,EAAE,SAAS,WAAW;AAE1D,cAAc,cAAc"}
1
+ {"version":3,"file":"toast-viewport.mjs","names":["defaultManager"],"sources":["../../src/toast/toast-viewport.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, FocusEvent, ReactNode } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { DialogContext } from \"../dialog/dialog-context.js\";\nimport { createActionDetails } from \"../internal/action/action-details.js\";\nimport { callUrgentHandler } from \"../internal/action/call-urgent-handler.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { isPopoverOpen } from \"../internal/overlay/popover-open.js\";\nimport type { ChangeReason, RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { animationBaseline } from \"../internal/overlay/use-exit-animation.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { toast as defaultManager, toastManagerInternals } from \"./toast.js\";\nimport type {\n RetainedToast,\n ToastCommand,\n ToastItem,\n ToastListener,\n ToastManager,\n} from \"./toast.js\";\nimport { ToastViewportContext } from \"./toast-context.js\";\nimport type { ToastViewportContextValue } from \"./toast-context.js\";\nimport { DEFAULT_HOTKEY, regionLabel } from \"./toast-hotkey.js\";\nimport { clearToastTimers, syncToastTimers } from \"./toast-timers.js\";\nimport type { ToastTimer } from \"./toast-timers.js\";\nimport { applyCommands, makeEntry, partition, withFlags } from \"./toast-queue.js\";\nimport type { Entry } from \"./toast-queue.js\";\nimport { useModalPortalHost } from \"./use-modal-portal-host.js\";\nimport { useToastAnnouncements } from \"./use-toast-announcements.js\";\nimport { useToastFocus, useToastHotkey } from \"./use-toast-focus.js\";\nimport { useToastPauses } from \"./use-toast-pauses.js\";\n\n/**\n * State of `Toast.Viewport`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface ToastViewportState {\n /** Rendered toasts, chronological (oldest first), exiting ones included. */\n readonly toasts: readonly ToastItem[];\n /** Toasts waiting beyond `limit`. */\n readonly queued: number;\n /** A viewport-wide pause holds (pointer over the region, focus inside, hidden document, blurred window). */\n readonly paused: boolean;\n}\n\n/**\n * Props of `Toast.Viewport`.\n *\n * @see https://ui.funstack.work/components/toast\n */\nexport interface ToastViewportProps extends Omit<\n ComponentPropsWithRef<\"section\">,\n | \"popover\"\n | \"className\"\n | \"style\"\n | \"children\"\n | \"onPointerEnter\"\n | \"onPointerLeave\"\n | \"onFocus\"\n | \"onBlur\"\n | \"onKeyDown\"\n> {\n /**\n * The queue to render (from `createToastManager()`).\n *\n * @defaultValue the module-level `toast`\n */\n manager?: ToastManager;\n /**\n * Toasts rendered at once; further ones wait in order (never dropped).\n *\n * @defaultValue `3`\n */\n limit?: number;\n /**\n * Default `duration` of a toast in milliseconds; `null` for persistent.\n *\n * @defaultValue `5000`\n */\n duration?: number | null;\n /**\n * Keys that focus the newest toast: `event.code` values and modifier names (`\"altKey\"`,\n * `\"ctrlKey\"`, `\"metaKey\"`, `\"shiftKey\"`), all of which must match, with no other modifier\n * held. `null` installs no listener.\n *\n * @defaultValue `[\"F8\"]`\n */\n hotkey?: readonly string[] | null;\n /**\n * The text `document.ariaNotify()` speaks for a toast (localisation); `null` announces nothing.\n * A toast's own `announce` wins.\n *\n * @defaultValue the text of the toast's Title and Description\n */\n announce?: (toast: ToastItem) => string | null;\n /** Usually a function of the state mapping `state.toasts` to `Toast.Root`s. */\n children?: StateValue<ReactNode, ToastViewportState>;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ToastViewportState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ToastViewportState>;\n /** Must render an element that can carry `popover` (a `<section>` by default). */\n render?: RenderProp<ComponentPropsWithRef<\"section\">, ToastViewportState>;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * The toast region: a `<section popover=\"manual\">` named \"Notifications (F8)\", shown in the top\n * layer while it has toasts. Owns the queue (urgent state fed by `toast()`), the timers and their\n * pausing, the hotkey, focus return, announcements through `document.ariaNotify()`, and the move\n * into the topmost open modal `Dialog` (a region outside it would be inert).\n *\n * Owned keys (conventions 1.2): `popover`, `aria-label` (the consumer's own `aria-label` wins\n * verbatim), `data-paused`, `data-empty`, and the pointer / focus handlers.\n *\n * @see https://ui.funstack.work/components/toast\n */\nexport function ToastViewport({\n manager = defaultManager,\n limit = 3,\n duration = 5000,\n hotkey = DEFAULT_HOTKEY,\n announce,\n children,\n className,\n style,\n render,\n ...rest\n}: ToastViewportProps) {\n // --- The queue: urgent state, written only from handlers, microtasks and effects -----------\n const [entries, setEntries] = useState<readonly Entry[]>([]);\n // The latest queue, written together with every `setEntries`: the dispatchers read and write\n // it synchronously so a burst of commands composes (and side effects stay out of updaters).\n const entriesRef = useRef<readonly Entry[]>(entries);\n const listener = useRef<ToastListener | null>(null);\n listener.current ??= {\n restore: (toasts: readonly RetainedToast[]) => handlers.current.restore(toasts),\n apply: (commands: readonly ToastCommand[]) => handlers.current.apply(commands),\n retain: () => handlers.current.retain(),\n };\n // A second Viewport on a taken manager renders nothing from its first render on (the effect\n // below confirms or clears it once the subscription is attempted).\n const [rejected, setRejected] = useState(() =>\n toastManagerInternals(manager).isTaken(listener.current!),\n );\n // The subscription itself was refused: the manager has another Viewport. Not `rejected`, a\n // render-time guess that is also true for the replacement of a Viewport in one commit (a `key`\n // change, a move between parents), rendered while the old instance is still subscribed.\n const [duplicate, setDuplicate] = useState(false);\n\n const regionRef = useRef<HTMLElement | null>(null);\n const roots = useRef(new Map<string, HTMLElement>());\n const suspended = useRef(new Set<string>());\n const timers = useRef(new Map<string, ToastTimer>());\n\n // --- Pause sources, focus, announcements (design 5, 6, 7) ---------------------------------\n // `syncTimers` is declared below; the callback only runs from events and effects, after render.\n const pauses = useToastPauses(() => syncTimers());\n const { paused, setPause, watch } = pauses;\n const focus = useToastFocus({ entriesRef, roots, regionRef });\n const { returnTargetRef, sortedRoots, moveFocusOut } = focus;\n const { lastAnnouncedRef, queueAnnouncement, announceQueued } = useToastAnnouncements(regionRef);\n\n /** Per closing toast: the animations already running before `data-ending` applied. */\n const exitBaselines = useRef(new Map<string, ReadonlySet<Animation>>());\n const addedSinceEffect = useRef(false);\n const mounted = useRef(false);\n\n const latest = useLatest({ limit, duration, hotkey, announce });\n\n const write = (next: readonly Entry[]): void => {\n entriesRef.current = next;\n setEntries(next);\n };\n\n // --- Timers (design 6) ----------------------------------------------------------------------\n\n const syncTimers = (): void => {\n syncToastTimers(timers.current, partition(entriesRef.current, latest.current.limit).visible, {\n halted: !mounted.current || pauses.anyHeld(),\n suspended: suspended.current,\n defaultDuration: latest.current.duration,\n expire: (id) => close([id], \"timeout\", undefined),\n });\n };\n\n // --- Queue writes ---------------------------------------------------------------------------\n\n /**\n * Records the animations running in each closing toast before `data-ending` applies: the exit\n * waits only for the ones the ending state started, not for a running progress bar.\n */\n const snapshotExitBaselines = (ids: Iterable<string>): void => {\n for (const id of ids) {\n const element = roots.current.get(id);\n if (element === undefined) continue;\n exitBaselines.current.set(id, animationBaseline(element));\n }\n };\n\n /**\n * A toast's `onClose` (#148: a handler, not an action): called synchronously where the close is\n * applied to the queue, after the entry is marked ending, outside any transition, and not\n * awaited (`callUrgentHandler`: a throw or a returned promise's rejection goes to\n * `reportError`, the queue write above stands).\n */\n const callCloseHandlers = (\n closed: readonly Entry[],\n reason: ChangeReason,\n event: Event | undefined,\n ): void => {\n for (const entry of closed) {\n const onClose = entry.options.onClose;\n if (onClose === undefined) continue;\n callUrgentHandler(onClose, createActionDetails(event, { id: entry.options.id, reason }));\n }\n };\n\n const close = (ids: readonly string[], reason: ChangeReason, event: Event | undefined): void => {\n const wanted = new Set(ids);\n const closing = entriesRef.current.filter((e) => !e.ending && wanted.has(e.options.id));\n if (closing.length === 0) return;\n const closingIds = new Set(closing.map((e) => e.options.id));\n moveFocusOut(closingIds);\n snapshotExitBaselines(closingIds);\n write(\n entriesRef.current.map((e) =>\n closingIds.has(e.options.id) ? withFlags(e, { ending: true }) : e,\n ),\n );\n syncTimers();\n callCloseHandlers(closing, reason, event);\n };\n\n const drop = (id: string): void => {\n const next = entriesRef.current.filter((e) => !(e.ending && e.options.id === id));\n if (next.length === entriesRef.current.length) return;\n lastAnnouncedRef.current.delete(id);\n exitBaselines.current.delete(id);\n write(next);\n };\n\n const apply = (commands: readonly ToastCommand[]): void => {\n const result = applyCommands(entriesRef.current, commands, (id) => roots.current.has(id));\n for (const id of result.replaced) clearToastTimers(timers.current, id);\n for (const id of result.forgotten) {\n lastAnnouncedRef.current.delete(id);\n exitBaselines.current.delete(id);\n }\n if (result.added) addedSinceEffect.current = true;\n if (isDev) {\n for (const id of result.missing) {\n console.error(`toast.update: no toast with id \"${id}\"; the update is ignored.`);\n }\n }\n if (result.dismissed.length === 0) {\n write(result.next);\n return;\n }\n moveFocusOut(result.leaving);\n snapshotExitBaselines(result.leaving);\n write(result.next);\n syncTimers();\n callCloseHandlers(result.dismissed, \"dismiss\", undefined);\n };\n\n const setActionPending = (id: string, pending: boolean): void => {\n const index = entriesRef.current.findIndex((e) => e.options.id === id);\n if (index === -1) return;\n const entry = entriesRef.current[index]!;\n if (entry.actionPending === pending) return;\n const next = [...entriesRef.current];\n next[index] = withFlags(entry, { actionPending: pending });\n write(next);\n };\n\n // The callbacks below read only refs, so one context value serves the Viewport's whole life.\n const restore = (toasts: readonly RetainedToast[]): void => {\n if (entriesRef.current.length > 0) return;\n // Already announced by the previous Viewport: not again on every remount.\n for (const t of toasts) {\n if (t.announced !== undefined) lastAnnouncedRef.current.set(t.options.id, t.announced);\n }\n write(\n toasts.map((t) =>\n makeEntry(t.options, { promisePending: t.pending, actionPending: false, ending: false }),\n ),\n );\n addedSinceEffect.current = true;\n };\n\n const retain = (): readonly RetainedToast[] => {\n const announced = lastAnnouncedRef.current;\n return entriesRef.current\n .filter((e) => !e.ending)\n .map((e) => ({\n options: e.options,\n pending: e.promisePending,\n announced: announced.has(e.options.id) ? announced.get(e.options.id) : undefined,\n }));\n };\n\n /** Forgets the queue of the previous manager (its own copy is retained by that manager). */\n const reset = (): void => {\n moveFocusOut(new Set(entriesRef.current.filter((e) => !e.ending).map((e) => e.options.id)));\n clearToastTimers(timers.current);\n lastAnnouncedRef.current.clear();\n exitBaselines.current.clear();\n write([]);\n };\n\n const handlers = useLatest({\n apply,\n restore,\n retain,\n reset,\n close,\n drop,\n setActionPending,\n queueAnnouncement,\n syncTimers,\n });\n\n const context = useMemo<ToastViewportContextValue>(\n () => ({\n close: (ids, reason, event) => handlers.current.close(ids, reason, event),\n drop: (id) => handlers.current.drop(id),\n setActionPending: (id, pending) => handlers.current.setActionPending(id, pending),\n setSuspended: (id, value) => {\n if (value) suspended.current.add(id);\n else suspended.current.delete(id);\n handlers.current.syncTimers();\n },\n registerRoot: (id, element) => {\n if (element === null) roots.current.delete(id);\n else roots.current.set(id, element);\n },\n focusSibling: (id, direction) => {\n const all = sortedRoots();\n const index = all.findIndex((r) => r.id === id);\n if (index === -1) return;\n all[index + direction]?.element.focus();\n },\n announce: (id, text, priority) => handlers.current.queueAnnouncement(id, text, priority),\n exitBaseline: (id) => exitBaselines.current.get(id),\n announcer: () => latest.current.announce,\n }),\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- refs only (`sortedRoots` reads refs)\n [handlers, latest],\n );\n\n // --- Subscription ---------------------------------------------------------------------------\n\n const subscribedManager = useRef<ToastManager | null>(null);\n useEffect(() => {\n // A new `manager`: the previous one kept its toasts on unsubscribe (the previous run's\n // cleanup); start empty so the new one's retained toasts are restored and no command of\n // one queue reaches the other's toasts. The same manager again (StrictMode, Activity) keeps\n // the entries.\n if (subscribedManager.current !== null && subscribedManager.current !== manager) {\n handlers.current.reset();\n }\n subscribedManager.current = manager;\n const unsubscribe = toastManagerInternals(manager).subscribe(listener.current!);\n if (unsubscribe === null) {\n setRejected(true);\n setDuplicate(true);\n return;\n }\n setRejected(false);\n setDuplicate(false);\n return unsubscribe;\n }, [manager, handlers]);\n\n // --- Lifecycle, pause sources, hotkey --------------------------------------------------------\n\n useEffect(() => {\n if (rejected) return;\n mounted.current = true;\n const doc = regionRef.current?.ownerDocument ?? document;\n const unwatch = watch(doc);\n handlers.current.syncTimers();\n const map = timers.current;\n return () => {\n mounted.current = false;\n unwatch();\n // Unmounting stops the timers; the queue itself is retained by the manager.\n clearToastTimers(map);\n };\n }, [handlers, rejected, watch]);\n\n useToastHotkey({ hotkey, rejected, regionRef, focus });\n\n // --- The portal host (design 4.3) ------------------------------------------------------------\n\n // Keep this call before the region layout effect below: the host's move hides the popover\n // (removal steps), which that effect shows again in the same commit. A moved region gets no\n // `pointerleave`: drop the hover pause; a pointer still over it enters it again on its next move.\n const { portalled, host, anchorRef } = useModalPortalHost(() => setPause(\"hover\", false));\n\n // --- After every commit: region, timers, queued announcements, orphan exits ----------------\n\n useLayoutEffect(() => {\n const region = regionRef.current;\n const current = entriesRef.current;\n // Focus that left with a remount (a move into or out of a dialog) fires no `focusout`.\n if (\n pauses.holding(\"focus\") &&\n (region === null || !region.contains(region.ownerDocument.activeElement))\n ) {\n returnTargetRef.current = null;\n setPause(\"focus\", false);\n }\n if (region !== null && region.isConnected && region.hasAttribute(\"popover\")) {\n const open = isPopoverOpen(region);\n try {\n if (current.length > 0) {\n if (!open) region.showPopover();\n else if (addedSinceEffect.current) {\n // Re-raise to the top of the top layer, above a menu or popover opened since\n // (design 4.2). No style flush in between, so nothing is re-created.\n region.hidePopover();\n region.showPopover();\n }\n } else if (open) {\n region.hidePopover();\n }\n } catch {\n // A render element without popover support; nothing to show.\n }\n }\n // An emptied region is hidden, often right under the pointer (its last toast's Close), and\n // a hidden element gets no `pointerleave`: the next toast must not start paused.\n if (current.length === 0 && pauses.holding(\"hover\")) setPause(\"hover\", false);\n addedSinceEffect.current = false;\n\n const { visible, queued } = partition(current, latest.current.limit);\n // Queued toasts are announced on add (design 5); visible ones announce from their Root\n // once their content committed.\n announceQueued(queued, latest.current.announce);\n // An ending toast without a Root (the consumer did not render one) has nothing to animate.\n for (const entry of visible) {\n if (entry.ending && !roots.current.has(entry.options.id)) drop(entry.options.id);\n }\n syncTimers();\n });\n\n // --- Development checks ---------------------------------------------------------------------\n\n // A second Viewport on a taken manager renders nothing (`duplicate`, set above).\n useDevWarning(\n duplicate,\n isDev &&\n \"Toast.Viewport: another Toast.Viewport already renders this manager; this one renders \" +\n \"nothing. Use one Viewport per manager, or `createToastManager()` for a second queue.\",\n );\n\n // A Viewport inside a library Dialog would close (and unmount) with it.\n const insideDialog = use(DialogContext) !== null;\n useDevWarning(\n insideDialog,\n isDev &&\n \"Toast.Viewport: rendered inside a Dialog. The region would close with the dialog; render \" +\n \"the Viewport once near the root of the app (it moves into open modal Dialogs by itself).\",\n );\n\n // --- Render ---------------------------------------------------------------------------------\n\n const { visible, queued } = partition(entries, limit);\n const state: ToastViewportState = {\n toasts: visible.map((e) => e.item),\n queued: queued.length,\n paused,\n };\n\n const regionCallbackRef = useCallback((element: HTMLElement) => {\n regionRef.current = element;\n return () => {\n if (regionRef.current === element) regionRef.current = null;\n };\n }, []);\n\n // Touch lifts the pointer at once (`pointerleave` follows `pointerup`), so a tap never sticks.\n const onPointerEnter = (): void => setPause(\"hover\", true);\n const onPointerLeave = (): void => setPause(\"hover\", false);\n const onFocus = (event: FocusEvent<HTMLElement>): void => {\n const region = event.currentTarget;\n const from = event.relatedTarget;\n if (!(from instanceof Node) || !region.contains(from)) {\n returnTargetRef.current ??= from instanceof HTMLElement ? from : null;\n }\n setPause(\"focus\", true);\n };\n const onBlur = (event: FocusEvent<HTMLElement>): void => {\n const to = event.relatedTarget;\n if (to instanceof Node && event.currentTarget.contains(to)) return;\n returnTargetRef.current = null;\n setPause(\"focus\", false);\n };\n\n const libraryProps: ComponentPropsWithRef<\"section\"> & DataAttributes = {\n popover: \"manual\",\n \"aria-label\": rest[\"aria-label\"] ?? regionLabel(hotkey),\n \"data-paused\": dataAttr(paused),\n \"data-empty\": dataAttr(state.toasts.length === 0),\n onPointerEnter,\n onPointerLeave,\n onFocus,\n onBlur,\n };\n\n const region = useRender<ComponentPropsWithRef<\"section\">, ToastViewportState>({\n defaultElement: \"section\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps,\n ref: regionCallbackRef,\n });\n\n if (rejected) return null;\n const content = <ToastViewportContext value={context}>{region}</ToastViewportContext>;\n if (!portalled || host === null) return content;\n return (\n <>\n <div ref={anchorRef} style={ANCHOR_STYLE} />\n {createPortal(content, host)}\n </>\n );\n}\n\nconst ANCHOR_STYLE: CSSProperties = { display: \"contents\" };\n\nToastViewport.displayName = \"ToastViewport\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA4GA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;AAavC,SAAgB,cAAc,EAC5B,UAAUA,OACV,QAAQ,GACR,WAAW,KACX,SAAS,gBACT,UACA,UACA,WACA,OACA,QACA,GAAG,QACkB;CAErB,MAAM,CAAC,SAAS,cAAc,SAA2B,CAAC,CAAC;CAG3D,MAAM,aAAa,OAAyB,OAAO;CACnD,MAAM,WAAW,OAA6B,IAAI;CAClD,SAAS,YAAY;EACnB,UAAU,WAAqC,SAAS,QAAQ,QAAQ,MAAM;EAC9E,QAAQ,aAAsC,SAAS,QAAQ,MAAM,QAAQ;EAC7E,cAAc,SAAS,QAAQ,OAAO;CACxC;CAGA,MAAM,CAAC,UAAU,eAAe,eAC9B,sBAAsB,OAAO,CAAC,CAAC,QAAQ,SAAS,OAAQ,CAC1D;CAIA,MAAM,CAAC,WAAW,gBAAgB,SAAS,KAAK;CAEhD,MAAM,YAAY,OAA2B,IAAI;CACjD,MAAM,QAAQ,uBAAO,IAAI,IAAyB,CAAC;CACnD,MAAM,YAAY,uBAAO,IAAI,IAAY,CAAC;CAC1C,MAAM,SAAS,uBAAO,IAAI,IAAwB,CAAC;CAInD,MAAM,SAAS,qBAAqB,WAAW,CAAC;CAChD,MAAM,EAAE,QAAQ,UAAU,UAAU;CACpC,MAAM,QAAQ,cAAc;EAAE;EAAY;EAAO;CAAU,CAAC;CAC5D,MAAM,EAAE,iBAAiB,aAAa,iBAAiB;CACvD,MAAM,EAAE,kBAAkB,mBAAmB,mBAAmB,sBAAsB,SAAS;;CAG/F,MAAM,gBAAgB,uBAAO,IAAI,IAAoC,CAAC;CACtE,MAAM,mBAAmB,OAAO,KAAK;CACrC,MAAM,UAAU,OAAO,KAAK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X,IAAI,UAAU,YAAY,SAAS,UAAU,UAAU;EACzD;CACF,GAAG,CAAC,CAAC;CAGL,MAAM,uBAA6B,SAAS,SAAS,IAAI;CACzD,MAAM,uBAA6B,SAAS,SAAS,KAAK;CAC1D,MAAM,WAAW,UAAyC;EACxD,MAAM,SAAS,MAAM;EACrB,MAAM,OAAO,MAAM;EACnB,IAAI,EAAE,gBAAgB,SAAS,CAAC,OAAO,SAAS,IAAI,GAClD,gBAAgB,YAAY,gBAAgB,cAAc,OAAO;EAEnE,SAAS,SAAS,IAAI;CACxB;CACA,MAAM,UAAU,UAAyC;EACvD,MAAM,KAAK,MAAM;EACjB,IAAI,cAAc,QAAQ,MAAM,cAAc,SAAS,EAAE,GAAG;EAC5D,gBAAgB,UAAU;EAC1B,SAAS,SAAS,KAAK;CACzB;CAEA,MAAM,eAAkE;EACtE,SAAS;EACT,cAAc,KAAK,iBAAiB,YAAY,MAAM;EACtD,eAAe,SAAS,MAAM;EAC9B,cAAc,SAAS,MAAM,OAAO,WAAW,CAAC;EAChD;EACA;EACA;EACA;CACF;CAEA,MAAM,SAAS,UAAgE;EAC7E,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;EACA,KAAK;CACP,CAAC;CAED,IAAI,UAAU,OAAO;CACrB,MAAM,UAAU,oBAAC,sBAAD;EAAsB,OAAO;EAAU,UAAA;CAA6B,CAAA;CACpF,IAAI,CAAC,aAAa,SAAS,MAAM,OAAO;CACxC,OACE,qBAAA,UAAA,EAAA,UAAA,CACE,oBAAC,OAAD;EAAK,KAAK;EAAW,OAAO;CAAe,CAAA,GAC1C,aAAa,SAAS,IAAI,CAC3B,EAAA,CAAA;AAEN;AAEA,MAAM,eAA8B,EAAE,SAAS,WAAW;AAE1D,cAAc,cAAc"}
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { getServerTopmostModal, getTopmostModal, subscribeModals } from "../internal/modal-registry.mjs";
2
+ import { getServerTopmostModal, getTopmostModal, subscribeModals } from "../internal/overlay/modal-registry.mjs";
3
3
  import { useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
4
4
  //#region src/toast/use-modal-portal-host.ts
5
5
  /** No store: `useSyncExternalStore` only tells the hydration render from a client render. */
@@ -1 +1 @@
1
- {"version":3,"file":"use-modal-portal-host.mjs","names":[],"sources":["../../src/toast/use-modal-portal-host.ts"],"sourcesContent":["\"use client\";\nimport { useLayoutEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { RefObject } from \"react\";\nimport {\n getServerTopmostModal,\n getTopmostModal,\n subscribeModals,\n} from \"../internal/modal-registry.js\";\n\n/** No store: `useSyncExternalStore` only tells the hydration render from a client render. */\nconst subscribeNothing = (): (() => void) => () => {};\nconst onClient = (): boolean => true;\nconst onServerOrHydrating = (): boolean => false;\n\n/**\n * The element the region is portalled into for its whole client life. The library moves this\n * element (between its inline anchor and the topmost modal dialog); React never sees the move, so\n * the toasts keep their state (an Undo in flight stays pending). `display: contents`: no box.\n */\nfunction createHost(): HTMLElement | null {\n if (typeof document === \"undefined\") return null;\n const host = document.createElement(\"div\");\n host.style.display = \"contents\";\n return host;\n}\n\nexport interface ModalPortalHost {\n /** `false` for the hydration render (and on the server): render the region inline. */\n readonly portalled: boolean;\n /** Portal into it when `portalled`; `null` without a document. */\n readonly host: HTMLElement | null;\n /** For the inline anchor element the host sits in while no modal is open. */\n readonly anchorRef: RefObject<HTMLDivElement | null>;\n}\n\n/**\n * The Viewport's portal host (design/components/toast.md 4.3): in the topmost open modal\n * `Dialog` (a region outside it would be inert), else at its inline anchor. Its layout effect\n * moves the host and must run before the Viewport's region effect: a move hides the popover\n * (removal steps), which that effect shows again in the same commit. `onMove` runs after a move.\n */\nexport function useModalPortalHost(onMove: () => void): ModalPortalHost {\n const container = useSyncExternalStore(subscribeModals, getTopmostModal, getServerTopmostModal);\n // The hydration render matches the server's inline region; every later render portals into\n // `host`, whose place the library changes without React noticing.\n const portalled = useSyncExternalStore(subscribeNothing, onClient, onServerOrHydrating);\n const [host] = useState(createHost);\n const anchorRef = useRef<HTMLDivElement | null>(null);\n\n useLayoutEffect(() => {\n if (host === null) return;\n return () => host.remove();\n }, [host]);\n\n useLayoutEffect(() => {\n if (host === null || !portalled) return;\n const target = container ?? anchorRef.current;\n if (target === null || host.parentNode === target) return;\n const moved = host.parentNode !== null;\n target.append(host);\n if (moved) onMove();\n });\n\n return { portalled, host, anchorRef };\n}\n"],"mappings":";;;;;AAUA,MAAM,+BAA6C,CAAC;AACpD,MAAM,iBAA0B;AAChC,MAAM,4BAAqC;;;;;;AAO3C,SAAS,aAAiC;CACxC,IAAI,OAAO,aAAa,aAAa,OAAO;CAC5C,MAAM,OAAO,SAAS,cAAc,KAAK;CACzC,KAAK,MAAM,UAAU;CACrB,OAAO;AACT;;;;;;;AAiBA,SAAgB,mBAAmB,QAAqC;CACtE,MAAM,YAAY,qBAAqB,iBAAiB,iBAAiB,qBAAqB;CAG9F,MAAM,YAAY,qBAAqB,kBAAkB,UAAU,mBAAmB;CACtF,MAAM,CAAC,QAAQ,SAAS,UAAU;CAClC,MAAM,YAAY,OAA8B,IAAI;CAEpD,sBAAsB;EACpB,IAAI,SAAS,MAAM;EACnB,aAAa,KAAK,OAAO;CAC3B,GAAG,CAAC,IAAI,CAAC;CAET,sBAAsB;EACpB,IAAI,SAAS,QAAQ,CAAC,WAAW;EACjC,MAAM,SAAS,aAAa,UAAU;EACtC,IAAI,WAAW,QAAQ,KAAK,eAAe,QAAQ;EACnD,MAAM,QAAQ,KAAK,eAAe;EAClC,OAAO,OAAO,IAAI;EAClB,IAAI,OAAO,OAAO;CACpB,CAAC;CAED,OAAO;EAAE;EAAW;EAAM;CAAU;AACtC"}
1
+ {"version":3,"file":"use-modal-portal-host.mjs","names":[],"sources":["../../src/toast/use-modal-portal-host.ts"],"sourcesContent":["\"use client\";\nimport { useLayoutEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { RefObject } from \"react\";\nimport {\n getServerTopmostModal,\n getTopmostModal,\n subscribeModals,\n} from \"../internal/overlay/modal-registry.js\";\n\n/** No store: `useSyncExternalStore` only tells the hydration render from a client render. */\nconst subscribeNothing = (): (() => void) => () => {};\nconst onClient = (): boolean => true;\nconst onServerOrHydrating = (): boolean => false;\n\n/**\n * The element the region is portalled into for its whole client life. The library moves this\n * element (between its inline anchor and the topmost modal dialog); React never sees the move, so\n * the toasts keep their state (an Undo in flight stays pending). `display: contents`: no box.\n */\nfunction createHost(): HTMLElement | null {\n if (typeof document === \"undefined\") return null;\n const host = document.createElement(\"div\");\n host.style.display = \"contents\";\n return host;\n}\n\nexport interface ModalPortalHost {\n /** `false` for the hydration render (and on the server): render the region inline. */\n readonly portalled: boolean;\n /** Portal into it when `portalled`; `null` without a document. */\n readonly host: HTMLElement | null;\n /** For the inline anchor element the host sits in while no modal is open. */\n readonly anchorRef: RefObject<HTMLDivElement | null>;\n}\n\n/**\n * The Viewport's portal host (design/components/toast.md 4.3): in the topmost open modal\n * `Dialog` (a region outside it would be inert), else at its inline anchor. Its layout effect\n * moves the host and must run before the Viewport's region effect: a move hides the popover\n * (removal steps), which that effect shows again in the same commit. `onMove` runs after a move.\n */\nexport function useModalPortalHost(onMove: () => void): ModalPortalHost {\n const container = useSyncExternalStore(subscribeModals, getTopmostModal, getServerTopmostModal);\n // The hydration render matches the server's inline region; every later render portals into\n // `host`, whose place the library changes without React noticing.\n const portalled = useSyncExternalStore(subscribeNothing, onClient, onServerOrHydrating);\n const [host] = useState(createHost);\n const anchorRef = useRef<HTMLDivElement | null>(null);\n\n useLayoutEffect(() => {\n if (host === null) return;\n return () => host.remove();\n }, [host]);\n\n useLayoutEffect(() => {\n if (host === null || !portalled) return;\n const target = container ?? anchorRef.current;\n if (target === null || host.parentNode === target) return;\n const moved = host.parentNode !== null;\n target.append(host);\n if (moved) onMove();\n });\n\n return { portalled, host, anchorRef };\n}\n"],"mappings":";;;;;AAUA,MAAM,+BAA6C,CAAC;AACpD,MAAM,iBAA0B;AAChC,MAAM,4BAAqC;;;;;;AAO3C,SAAS,aAAiC;CACxC,IAAI,OAAO,aAAa,aAAa,OAAO;CAC5C,MAAM,OAAO,SAAS,cAAc,KAAK;CACzC,KAAK,MAAM,UAAU;CACrB,OAAO;AACT;;;;;;;AAiBA,SAAgB,mBAAmB,QAAqC;CACtE,MAAM,YAAY,qBAAqB,iBAAiB,iBAAiB,qBAAqB;CAG9F,MAAM,YAAY,qBAAqB,kBAAkB,UAAU,mBAAmB;CACtF,MAAM,CAAC,QAAQ,SAAS,UAAU;CAClC,MAAM,YAAY,OAA8B,IAAI;CAEpD,sBAAsB;EACpB,IAAI,SAAS,MAAM;EACnB,aAAa,KAAK,OAAO;CAC3B,GAAG,CAAC,IAAI,CAAC;CAET,sBAAsB;EACpB,IAAI,SAAS,QAAQ,CAAC,WAAW;EACjC,MAAM,SAAS,aAAa,UAAU;EACtC,IAAI,WAAW,QAAQ,KAAK,eAAe,QAAQ;EACnD,MAAM,QAAQ,KAAK,eAAe;EAClC,OAAO,OAAO,IAAI;EAClB,IAAI,OAAO,OAAO;CACpB,CAAC;CAED,OAAO;EAAE;EAAW;EAAM;CAAU;AACtC"}
@@ -0,0 +1,46 @@
1
+ "use client";
2
+ import { announce } from "../internal/announce.mjs";
3
+ import { plainText } from "./toast-queue.mjs";
4
+ import { useRef } from "react";
5
+ //#region src/toast/use-toast-announcements.ts
6
+ /** `Toast.Viewport`'s announcements through `document.ariaNotify()` (design/components/toast.md 5). */
7
+ function useToastAnnouncements(regionRef) {
8
+ const lastAnnouncedRef = useRef(/* @__PURE__ */ new Map());
9
+ const announceBatch = useRef([]);
10
+ const flushAnnouncements = () => {
11
+ const batch = announceBatch.current;
12
+ announceBatch.current = [];
13
+ if (batch.length === 0) return;
14
+ const priority = batch.some((a) => a.priority === "high") ? "high" : "normal";
15
+ announce(regionRef.current?.ownerDocument ?? document, batch.map((a) => a.text).join(" "), priority);
16
+ };
17
+ const queueAnnouncement = (id, text, priority) => {
18
+ const map = lastAnnouncedRef.current;
19
+ if (map.has(id) && map.get(id) === text) return;
20
+ map.set(id, text);
21
+ if (text === null || text.trim() === "") return;
22
+ if (announceBatch.current.length === 0) queueMicrotask(flushAnnouncements);
23
+ announceBatch.current.push({
24
+ text,
25
+ priority
26
+ });
27
+ };
28
+ const announceQueued = (queued, fallback) => {
29
+ for (const entry of queued) {
30
+ const id = entry.options.id;
31
+ if (lastAnnouncedRef.current.has(id)) continue;
32
+ const resolver = entry.options.announce ?? fallback;
33
+ const text = resolver ? resolver(entry.item) : [plainText(entry.options.title), plainText(entry.options.description)].filter((t) => t !== "").join(" ");
34
+ queueAnnouncement(id, text, entry.options.priority ?? "normal");
35
+ }
36
+ };
37
+ return {
38
+ lastAnnouncedRef,
39
+ queueAnnouncement,
40
+ announceQueued
41
+ };
42
+ }
43
+ //#endregion
44
+ export { useToastAnnouncements };
45
+
46
+ //# sourceMappingURL=use-toast-announcements.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-toast-announcements.mjs","names":[],"sources":["../../src/toast/use-toast-announcements.ts"],"sourcesContent":["\"use client\";\nimport { useRef } from \"react\";\nimport type { RefObject } from \"react\";\nimport { announce as speak } from \"../internal/announce.js\";\nimport type { ToastItem, ToastPriority } from \"./toast.js\";\nimport { plainText } from \"./toast-queue.js\";\nimport type { Entry } from \"./toast-queue.js\";\n\nexport interface ToastAnnouncements {\n /** Per toast: the text last announced for it (`null`: nothing). The queue writes forget ids. */\n readonly lastAnnouncedRef: RefObject<Map<string, string | null>>;\n /**\n * Queues a toast's text, unless it is what was last announced for it. The texts queued in one\n * task are spoken together in a microtask, at the highest priority among them.\n */\n readonly queueAnnouncement: (id: string, text: string | null, priority: ToastPriority) => void;\n /**\n * Queued toasts are announced on add (design 5): from their plain-text fields, since they have\n * no DOM yet. `fallback` is the Viewport's `announce`.\n */\n readonly announceQueued: (\n queued: readonly Entry[],\n fallback: ((toast: ToastItem) => string | null) | undefined,\n ) => void;\n}\n\n/** `Toast.Viewport`'s announcements through `document.ariaNotify()` (design/components/toast.md 5). */\nexport function useToastAnnouncements(\n regionRef: RefObject<HTMLElement | null>,\n): ToastAnnouncements {\n const lastAnnouncedRef = useRef(new Map<string, string | null>());\n const announceBatch = useRef<{ text: string; priority: ToastPriority }[]>([]);\n\n const flushAnnouncements = (): void => {\n const batch = announceBatch.current;\n announceBatch.current = [];\n if (batch.length === 0) return;\n const priority = batch.some((a) => a.priority === \"high\") ? \"high\" : \"normal\";\n speak(\n regionRef.current?.ownerDocument ?? document,\n batch.map((a) => a.text).join(\" \"),\n priority,\n );\n };\n\n const queueAnnouncement = (id: string, text: string | null, priority: ToastPriority): void => {\n const map = lastAnnouncedRef.current;\n if (map.has(id) && map.get(id) === text) return;\n map.set(id, text);\n if (text === null || text.trim() === \"\") return;\n if (announceBatch.current.length === 0) queueMicrotask(flushAnnouncements);\n announceBatch.current.push({ text, priority });\n };\n\n const announceQueued = (\n queued: readonly Entry[],\n fallback: ((toast: ToastItem) => string | null) | undefined,\n ): void => {\n for (const entry of queued) {\n const id = entry.options.id;\n if (lastAnnouncedRef.current.has(id)) continue;\n const resolver = entry.options.announce ?? fallback;\n const text = resolver\n ? resolver(entry.item)\n : [plainText(entry.options.title), plainText(entry.options.description)]\n .filter((t) => t !== \"\")\n .join(\" \");\n queueAnnouncement(id, text, entry.options.priority ?? \"normal\");\n }\n };\n\n return { lastAnnouncedRef, queueAnnouncement, announceQueued };\n}\n"],"mappings":";;;;;;AA2BA,SAAgB,sBACd,WACoB;CACpB,MAAM,mBAAmB,uBAAO,IAAI,IAA2B,CAAC;CAChE,MAAM,gBAAgB,OAAoD,CAAC,CAAC;CAE5E,MAAM,2BAAiC;EACrC,MAAM,QAAQ,cAAc;EAC5B,cAAc,UAAU,CAAC;EACzB,IAAI,MAAM,WAAW,GAAG;EACxB,MAAM,WAAW,MAAM,MAAM,MAAM,EAAE,aAAa,MAAM,IAAI,SAAS;EACrE,SACE,UAAU,SAAS,iBAAiB,UACpC,MAAM,KAAK,MAAM,EAAE,IAA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