@funstack/ui 0.1.0-alpha.11 → 0.1.0-alpha.12

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 (401) hide show
  1. package/dist/accordion/accordion-context.mjs.map +1 -1
  2. package/dist/accordion/accordion-item.d.mts +3 -4
  3. package/dist/accordion/accordion-item.d.mts.map +1 -1
  4. package/dist/accordion/accordion-item.mjs +10 -4
  5. package/dist/accordion/accordion-item.mjs.map +1 -1
  6. package/dist/accordion/accordion-panel.d.mts +3 -4
  7. package/dist/accordion/accordion-panel.d.mts.map +1 -1
  8. package/dist/accordion/accordion-panel.mjs +2 -1
  9. package/dist/accordion/accordion-panel.mjs.map +1 -1
  10. package/dist/accordion/accordion-root.d.mts +3 -3
  11. package/dist/accordion/accordion-root.d.mts.map +1 -1
  12. package/dist/accordion/accordion-root.mjs +8 -19
  13. package/dist/accordion/accordion-root.mjs.map +1 -1
  14. package/dist/accordion/accordion-trigger.d.mts +3 -4
  15. package/dist/accordion/accordion-trigger.d.mts.map +1 -1
  16. package/dist/accordion/accordion-trigger.mjs +5 -3
  17. package/dist/accordion/accordion-trigger.mjs.map +1 -1
  18. package/dist/button/button.d.mts +4 -2
  19. package/dist/button/button.d.mts.map +1 -1
  20. package/dist/button/button.mjs +3 -2
  21. package/dist/button/button.mjs.map +1 -1
  22. package/dist/checkbox/checkbox.d.mts +4 -5
  23. package/dist/checkbox/checkbox.d.mts.map +1 -1
  24. package/dist/checkbox/checkbox.mjs +16 -59
  25. package/dist/checkbox/checkbox.mjs.map +1 -1
  26. package/dist/checkbox-group/checkbox-group-context.mjs.map +1 -1
  27. package/dist/checkbox-group/checkbox-group-item.d.mts +3 -4
  28. package/dist/checkbox-group/checkbox-group-item.d.mts.map +1 -1
  29. package/dist/checkbox-group/checkbox-group-item.mjs +21 -27
  30. package/dist/checkbox-group/checkbox-group-item.mjs.map +1 -1
  31. package/dist/checkbox-group/checkbox-group-label.mjs +1 -6
  32. package/dist/checkbox-group/checkbox-group-label.mjs.map +1 -1
  33. package/dist/checkbox-group/checkbox-group-parent.d.mts +3 -4
  34. package/dist/checkbox-group/checkbox-group-parent.d.mts.map +1 -1
  35. package/dist/checkbox-group/checkbox-group-parent.mjs +12 -10
  36. package/dist/checkbox-group/checkbox-group-parent.mjs.map +1 -1
  37. package/dist/checkbox-group/checkbox-group-root.d.mts +1 -1
  38. package/dist/checkbox-group/checkbox-group-root.d.mts.map +1 -1
  39. package/dist/checkbox-group/checkbox-group-root.mjs +74 -101
  40. package/dist/checkbox-group/checkbox-group-root.mjs.map +1 -1
  41. package/dist/combobox/combobox-clear.d.mts.map +1 -1
  42. package/dist/combobox/combobox-clear.mjs +5 -6
  43. package/dist/combobox/combobox-clear.mjs.map +1 -1
  44. package/dist/combobox/combobox-context.mjs.map +1 -1
  45. package/dist/combobox/combobox-group.d.mts.map +1 -1
  46. package/dist/combobox/combobox-group.mjs +2 -1
  47. package/dist/combobox/combobox-group.mjs.map +1 -1
  48. package/dist/combobox/combobox-input.d.mts.map +1 -1
  49. package/dist/combobox/combobox-input.mjs +14 -7
  50. package/dist/combobox/combobox-input.mjs.map +1 -1
  51. package/dist/combobox/combobox-list.d.mts.map +1 -1
  52. package/dist/combobox/combobox-list.mjs +6 -10
  53. package/dist/combobox/combobox-list.mjs.map +1 -1
  54. package/dist/combobox/combobox-option.d.mts.map +1 -1
  55. package/dist/combobox/combobox-option.mjs +2 -1
  56. package/dist/combobox/combobox-option.mjs.map +1 -1
  57. package/dist/combobox/combobox-popup.d.mts.map +1 -1
  58. package/dist/combobox/combobox-popup.mjs +9 -25
  59. package/dist/combobox/combobox-popup.mjs.map +1 -1
  60. package/dist/combobox/combobox-root.d.mts.map +1 -1
  61. package/dist/combobox/combobox-root.mjs +30 -102
  62. package/dist/combobox/combobox-root.mjs.map +1 -1
  63. package/dist/combobox/combobox-trigger.d.mts.map +1 -1
  64. package/dist/combobox/combobox-trigger.mjs +6 -25
  65. package/dist/combobox/combobox-trigger.mjs.map +1 -1
  66. package/dist/combobox/index.mjs +1 -1
  67. package/dist/combobox/use-combobox-form.mjs +56 -0
  68. package/dist/combobox/use-combobox-form.mjs.map +1 -0
  69. package/dist/combobox/use-option-registry.mjs +62 -0
  70. package/dist/combobox/use-option-registry.mjs.map +1 -0
  71. package/dist/dialog/dialog-close.d.mts.map +1 -1
  72. package/dist/dialog/dialog-close.mjs +29 -62
  73. package/dist/dialog/dialog-close.mjs.map +1 -1
  74. package/dist/dialog/dialog-context.mjs.map +1 -1
  75. package/dist/dialog/dialog-form.d.mts.map +1 -1
  76. package/dist/dialog/dialog-form.mjs +5 -4
  77. package/dist/dialog/dialog-form.mjs.map +1 -1
  78. package/dist/dialog/dialog-popup.d.mts +3 -4
  79. package/dist/dialog/dialog-popup.d.mts.map +1 -1
  80. package/dist/dialog/dialog-popup.mjs +37 -98
  81. package/dist/dialog/dialog-popup.mjs.map +1 -1
  82. package/dist/dialog/dialog-root.d.mts.map +1 -1
  83. package/dist/dialog/dialog-root.mjs +30 -118
  84. package/dist/dialog/dialog-root.mjs.map +1 -1
  85. package/dist/dialog/dialog-trigger.d.mts.map +1 -1
  86. package/dist/dialog/dialog-trigger.mjs +13 -16
  87. package/dist/dialog/dialog-trigger.mjs.map +1 -1
  88. package/dist/field/field-control.mjs +6 -13
  89. package/dist/field/field-control.mjs.map +1 -1
  90. package/dist/field/field-description.d.mts.map +1 -1
  91. package/dist/field/field-description.mjs +1 -2
  92. package/dist/field/field-description.mjs.map +1 -1
  93. package/dist/field/field-error.d.mts.map +1 -1
  94. package/dist/field/field-error.mjs +1 -2
  95. package/dist/field/field-error.mjs.map +1 -1
  96. package/dist/field/field-label.d.mts.map +1 -1
  97. package/dist/field/field-label.mjs +3 -11
  98. package/dist/field/field-label.mjs.map +1 -1
  99. package/dist/field/field-root.mjs +21 -41
  100. package/dist/field/field-root.mjs.map +1 -1
  101. package/dist/field/index.mjs +1 -1
  102. package/dist/field/use-server-error-visibility.mjs +44 -0
  103. package/dist/field/use-server-error-visibility.mjs.map +1 -0
  104. package/dist/form/form-root.d.mts.map +1 -1
  105. package/dist/form/form-root.mjs +6 -7
  106. package/dist/form/form-root.mjs.map +1 -1
  107. package/dist/form/form-submit.d.mts +1 -1
  108. package/dist/form/form-submit.mjs +4 -10
  109. package/dist/form/form-submit.mjs.map +1 -1
  110. package/dist/index.d.mts +2 -2
  111. package/dist/internal/anchor-position.mjs +1 -59
  112. package/dist/internal/anchor-position.mjs.map +1 -1
  113. package/dist/internal/announce.mjs.map +1 -1
  114. package/dist/internal/arrow-keys.mjs +21 -0
  115. package/dist/internal/arrow-keys.mjs.map +1 -0
  116. package/dist/internal/decimal.mjs +7 -1
  117. package/dist/internal/decimal.mjs.map +1 -1
  118. package/dist/internal/dom-order.mjs +17 -0
  119. package/dist/internal/dom-order.mjs.map +1 -0
  120. package/dist/internal/field-context.d.mts.map +1 -1
  121. package/dist/internal/field-context.mjs +11 -1
  122. package/dist/internal/field-context.mjs.map +1 -1
  123. package/dist/internal/focus-first-invalid.mjs +1 -1
  124. package/dist/internal/focus-first-invalid.mjs.map +1 -1
  125. package/dist/internal/group-member.mjs +37 -0
  126. package/dist/internal/group-member.mjs.map +1 -0
  127. package/dist/internal/overlay-popup.mjs +103 -0
  128. package/dist/internal/overlay-popup.mjs.map +1 -0
  129. package/dist/internal/popover-open.mjs +18 -0
  130. package/dist/internal/popover-open.mjs.map +1 -0
  131. package/dist/internal/render-element.d.mts +2 -0
  132. package/dist/internal/render-element.mjs +20 -2
  133. package/dist/internal/render-element.mjs.map +1 -1
  134. package/dist/internal/shipped-styles.mjs +14 -0
  135. package/dist/internal/shipped-styles.mjs.map +1 -0
  136. package/dist/internal/sync-presence.mjs +5 -1
  137. package/dist/internal/sync-presence.mjs.map +1 -1
  138. package/dist/internal/toolbar-context.mjs.map +1 -1
  139. package/dist/internal/tooltip-warm.mjs +1 -1
  140. package/dist/internal/tooltip-warm.mjs.map +1 -1
  141. package/dist/internal/transition-boundary.mjs +1 -1
  142. package/dist/internal/transition-boundary.mjs.map +1 -1
  143. package/dist/internal/types.d.mts +2 -0
  144. package/dist/internal/types.d.mts.map +1 -1
  145. package/dist/internal/use-action-trigger.mjs +5 -23
  146. package/dist/internal/use-action-trigger.mjs.map +1 -1
  147. package/dist/internal/use-checkable-input.mjs +79 -0
  148. package/dist/internal/use-checkable-input.mjs.map +1 -0
  149. package/dist/internal/use-controllable-action.mjs +16 -24
  150. package/dist/internal/use-controllable-action.mjs.map +1 -1
  151. package/dist/internal/use-dev-warning.mjs +8 -4
  152. package/dist/internal/use-dev-warning.mjs.map +1 -1
  153. package/dist/internal/use-element-check.mjs +39 -0
  154. package/dist/internal/use-element-check.mjs.map +1 -0
  155. package/dist/internal/use-exit-animation.mjs +1 -1
  156. package/dist/internal/use-exit-animation.mjs.map +1 -1
  157. package/dist/internal/use-field-control.mjs +28 -12
  158. package/dist/internal/use-field-control.mjs.map +1 -1
  159. package/dist/internal/use-fieldset-group.mjs +46 -0
  160. package/dist/internal/use-fieldset-group.mjs.map +1 -0
  161. package/dist/internal/use-form-reset.mjs +1 -5
  162. package/dist/internal/use-form-reset.mjs.map +1 -1
  163. package/dist/internal/use-item-order.mjs +42 -0
  164. package/dist/internal/use-item-order.mjs.map +1 -0
  165. package/dist/internal/use-latest.mjs +4 -8
  166. package/dist/internal/use-latest.mjs.map +1 -1
  167. package/dist/internal/use-merged-refs.mjs +19 -0
  168. package/dist/internal/use-merged-refs.mjs.map +1 -0
  169. package/dist/internal/use-name-warning.mjs +84 -0
  170. package/dist/internal/use-name-warning.mjs.map +1 -0
  171. package/dist/internal/use-native-checked.mjs +4 -6
  172. package/dist/internal/use-native-checked.mjs.map +1 -1
  173. package/dist/internal/use-native-focusgroup.mjs +19 -0
  174. package/dist/internal/use-native-focusgroup.mjs.map +1 -0
  175. package/dist/internal/use-native-group-reconciliation.mjs.map +1 -1
  176. package/dist/internal/use-overlay-close.mjs +63 -0
  177. package/dist/internal/use-overlay-close.mjs.map +1 -0
  178. package/dist/internal/{use-popover-root.mjs → use-overlay-root.mjs} +28 -39
  179. package/dist/internal/use-overlay-root.mjs.map +1 -0
  180. package/dist/internal/use-popover-popup.mjs +32 -78
  181. package/dist/internal/use-popover-popup.mjs.map +1 -1
  182. package/dist/internal/use-popover-trigger.d.mts +15 -0
  183. package/dist/internal/use-popover-trigger.d.mts.map +1 -0
  184. package/dist/internal/use-popover-trigger.mjs +13 -17
  185. package/dist/internal/use-popover-trigger.mjs.map +1 -1
  186. package/dist/internal/use-register-count.mjs +24 -0
  187. package/dist/internal/use-register-count.mjs.map +1 -0
  188. package/dist/internal/use-render.d.mts +2 -0
  189. package/dist/internal/use-render.mjs +2 -2
  190. package/dist/internal/use-render.mjs.map +1 -1
  191. package/dist/internal/use-resolved-placement.mjs +38 -22
  192. package/dist/internal/use-resolved-placement.mjs.map +1 -1
  193. package/dist/internal/use-roving-focus.mjs +5 -18
  194. package/dist/internal/use-roving-focus.mjs.map +1 -1
  195. package/dist/internal/use-superseded-rejection.mjs +47 -0
  196. package/dist/internal/use-superseded-rejection.mjs.map +1 -0
  197. package/dist/internal/validity.mjs +1 -13
  198. package/dist/internal/validity.mjs.map +1 -1
  199. package/dist/internal/value-set.mjs +41 -0
  200. package/dist/internal/value-set.mjs.map +1 -0
  201. package/dist/menu/index.d.mts +1 -1
  202. package/dist/menu/menu-checkbox-item.mjs.map +1 -1
  203. package/dist/menu/menu-context-trigger.d.mts +2 -7
  204. package/dist/menu/menu-context-trigger.d.mts.map +1 -1
  205. package/dist/menu/menu-context-trigger.mjs +10 -187
  206. package/dist/menu/menu-context-trigger.mjs.map +1 -1
  207. package/dist/menu/menu-context.d.mts +1 -1
  208. package/dist/menu/menu-context.mjs +1 -1
  209. package/dist/menu/menu-context.mjs.map +1 -1
  210. package/dist/menu/menu-dom.mjs +1 -2
  211. package/dist/menu/menu-dom.mjs.map +1 -1
  212. package/dist/menu/menu-gestures.mjs +167 -0
  213. package/dist/menu/menu-gestures.mjs.map +1 -0
  214. package/dist/menu/menu-group.d.mts.map +1 -1
  215. package/dist/menu/menu-group.mjs +2 -1
  216. package/dist/menu/menu-group.mjs.map +1 -1
  217. package/dist/menu/menu-hover.mjs +0 -1
  218. package/dist/menu/menu-hover.mjs.map +1 -1
  219. package/dist/menu/menu-item.mjs.map +1 -1
  220. package/dist/menu/menu-outside.mjs +101 -0
  221. package/dist/menu/menu-outside.mjs.map +1 -0
  222. package/dist/menu/menu-point.mjs +85 -0
  223. package/dist/menu/menu-point.mjs.map +1 -0
  224. package/dist/menu/menu-popup.d.mts +6 -7
  225. package/dist/menu/menu-popup.d.mts.map +1 -1
  226. package/dist/menu/menu-popup.mjs +37 -248
  227. package/dist/menu/menu-popup.mjs.map +1 -1
  228. package/dist/menu/menu-radio-group.mjs.map +1 -1
  229. package/dist/menu/menu-root.d.mts +10 -0
  230. package/dist/menu/menu-root.d.mts.map +1 -1
  231. package/dist/menu/menu-root.mjs +10 -8
  232. package/dist/menu/menu-root.mjs.map +1 -1
  233. package/dist/menu/menu-submenu-trigger.d.mts.map +1 -1
  234. package/dist/menu/menu-submenu-trigger.mjs +6 -6
  235. package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
  236. package/dist/menu/menu-trigger.d.mts +4 -9
  237. package/dist/menu/menu-trigger.d.mts.map +1 -1
  238. package/dist/menu/menu-trigger.mjs +8 -6
  239. package/dist/menu/menu-trigger.mjs.map +1 -1
  240. package/dist/menu/use-menu-item.mjs +14 -16
  241. package/dist/menu/use-menu-item.mjs.map +1 -1
  242. package/dist/menu/use-menu-keyboard.mjs +88 -0
  243. package/dist/menu/use-menu-keyboard.mjs.map +1 -0
  244. package/dist/meter/meter-root.mjs +1 -1
  245. package/dist/number-field/index.d.mts +2 -1
  246. package/dist/number-field/index.d.mts.map +1 -1
  247. package/dist/number-field/index.mjs +2 -2
  248. package/dist/number-field/index.mjs.map +1 -1
  249. package/dist/number-field/number-field-arithmetic.mjs +30 -11
  250. package/dist/number-field/number-field-arithmetic.mjs.map +1 -1
  251. package/dist/number-field/number-field-context.d.mts +6 -1
  252. package/dist/number-field/number-field-context.d.mts.map +1 -0
  253. package/dist/number-field/number-field-context.mjs.map +1 -1
  254. package/dist/number-field/number-field-decrement.d.mts +1 -1
  255. package/dist/number-field/number-field-decrement.mjs +1 -1
  256. package/dist/number-field/number-field-decrement.mjs.map +1 -1
  257. package/dist/number-field/number-field-increment.d.mts +2 -22
  258. package/dist/number-field/number-field-increment.d.mts.map +1 -1
  259. package/dist/number-field/number-field-increment.mjs +2 -53
  260. package/dist/number-field/number-field-increment.mjs.map +1 -1
  261. package/dist/number-field/number-field-input.d.mts.map +1 -1
  262. package/dist/number-field/number-field-input.mjs +18 -22
  263. package/dist/number-field/number-field-input.mjs.map +1 -1
  264. package/dist/number-field/number-field-label.d.mts.map +1 -1
  265. package/dist/number-field/number-field-label.mjs +3 -9
  266. package/dist/number-field/number-field-label.mjs.map +1 -1
  267. package/dist/number-field/number-field-root.d.mts +2 -1
  268. package/dist/number-field/number-field-root.d.mts.map +1 -1
  269. package/dist/number-field/number-field-root.mjs +81 -91
  270. package/dist/number-field/number-field-root.mjs.map +1 -1
  271. package/dist/number-field/use-number-field-dev-warnings.mjs +28 -0
  272. package/dist/number-field/use-number-field-dev-warnings.mjs.map +1 -0
  273. package/dist/number-field/use-step-button.d.mts +24 -0
  274. package/dist/number-field/use-step-button.d.mts.map +1 -0
  275. package/dist/number-field/use-step-button.mjs +57 -3
  276. package/dist/number-field/use-step-button.mjs.map +1 -1
  277. package/dist/popover/popover-close.d.mts.map +1 -1
  278. package/dist/popover/popover-close.mjs +28 -67
  279. package/dist/popover/popover-close.mjs.map +1 -1
  280. package/dist/popover/popover-context.mjs.map +1 -1
  281. package/dist/popover/popover-popup.d.mts +9 -6
  282. package/dist/popover/popover-popup.d.mts.map +1 -1
  283. package/dist/popover/popover-popup.mjs +13 -36
  284. package/dist/popover/popover-popup.mjs.map +1 -1
  285. package/dist/popover/popover-root.mjs +4 -3
  286. package/dist/popover/popover-root.mjs.map +1 -1
  287. package/dist/popover/popover-trigger.d.mts +4 -8
  288. package/dist/popover/popover-trigger.d.mts.map +1 -1
  289. package/dist/popover/popover-trigger.mjs +2 -1
  290. package/dist/popover/popover-trigger.mjs.map +1 -1
  291. package/dist/progress/progress-root.mjs +1 -1
  292. package/dist/radio-group/radio-group-context.mjs.map +1 -1
  293. package/dist/radio-group/radio-group-item.d.mts +3 -4
  294. package/dist/radio-group/radio-group-item.d.mts.map +1 -1
  295. package/dist/radio-group/radio-group-item.mjs +20 -25
  296. package/dist/radio-group/radio-group-item.mjs.map +1 -1
  297. package/dist/radio-group/radio-group-label.mjs +1 -6
  298. package/dist/radio-group/radio-group-label.mjs.map +1 -1
  299. package/dist/radio-group/radio-group-root.d.mts +1 -1
  300. package/dist/radio-group/radio-group-root.d.mts.map +1 -1
  301. package/dist/radio-group/radio-group-root.mjs +21 -40
  302. package/dist/radio-group/radio-group-root.mjs.map +1 -1
  303. package/dist/select/select-dom.mjs +9 -18
  304. package/dist/select/select-dom.mjs.map +1 -1
  305. package/dist/select/select-option.mjs +1 -1
  306. package/dist/select/select-root.mjs +3 -2
  307. package/dist/select/select-root.mjs.map +1 -1
  308. package/dist/slider/slider-arithmetic.mjs +74 -13
  309. package/dist/slider/slider-arithmetic.mjs.map +1 -1
  310. package/dist/slider/slider-context.mjs.map +1 -1
  311. package/dist/slider/slider-label.d.mts.map +1 -1
  312. package/dist/slider/slider-label.mjs +3 -9
  313. package/dist/slider/slider-label.mjs.map +1 -1
  314. package/dist/slider/slider-root.d.mts +2 -2
  315. package/dist/slider/slider-root.d.mts.map +1 -1
  316. package/dist/slider/slider-root.mjs +36 -116
  317. package/dist/slider/slider-root.mjs.map +1 -1
  318. package/dist/slider/slider-thumb.d.mts.map +1 -1
  319. package/dist/slider/slider-thumb.mjs +8 -6
  320. package/dist/slider/slider-thumb.mjs.map +1 -1
  321. package/dist/slider/slider-value.d.mts.map +1 -1
  322. package/dist/slider/slider-value.mjs +2 -1
  323. package/dist/slider/slider-value.mjs.map +1 -1
  324. package/dist/slider/use-slider-dev-warnings.mjs +29 -0
  325. package/dist/slider/use-slider-dev-warnings.mjs.map +1 -0
  326. package/dist/slider/use-thumb-registry.mjs +51 -0
  327. package/dist/slider/use-thumb-registry.mjs.map +1 -0
  328. package/dist/switch/switch.d.mts +4 -5
  329. package/dist/switch/switch.d.mts.map +1 -1
  330. package/dist/switch/switch.mjs +15 -55
  331. package/dist/switch/switch.mjs.map +1 -1
  332. package/dist/tabs/tabs-context.d.mts +2 -3
  333. package/dist/tabs/tabs-context.d.mts.map +1 -1
  334. package/dist/tabs/tabs-context.mjs.map +1 -1
  335. package/dist/tabs/tabs-list.d.mts.map +1 -1
  336. package/dist/tabs/tabs-list.mjs +9 -22
  337. package/dist/tabs/tabs-list.mjs.map +1 -1
  338. package/dist/tabs/tabs-panel.d.mts +3 -4
  339. package/dist/tabs/tabs-panel.d.mts.map +1 -1
  340. package/dist/tabs/tabs-panel.mjs.map +1 -1
  341. package/dist/tabs/tabs-root.d.mts +4 -3
  342. package/dist/tabs/tabs-root.d.mts.map +1 -1
  343. package/dist/tabs/tabs-root.mjs +2 -1
  344. package/dist/tabs/tabs-root.mjs.map +1 -1
  345. package/dist/tabs/tabs-tab.d.mts +3 -4
  346. package/dist/tabs/tabs-tab.d.mts.map +1 -1
  347. package/dist/tabs/tabs-tab.mjs.map +1 -1
  348. package/dist/toast/toast-action.mjs.map +1 -1
  349. package/dist/toast/toast-close.d.mts.map +1 -1
  350. package/dist/toast/toast-close.mjs +2 -8
  351. package/dist/toast/toast-close.mjs.map +1 -1
  352. package/dist/toast/toast-context.mjs.map +1 -1
  353. package/dist/toast/toast-hotkey.mjs +27 -0
  354. package/dist/toast/toast-hotkey.mjs.map +1 -0
  355. package/dist/toast/toast-queue.mjs +137 -0
  356. package/dist/toast/toast-queue.mjs.map +1 -0
  357. package/dist/toast/toast-timers.mjs +65 -0
  358. package/dist/toast/toast-timers.mjs.map +1 -0
  359. package/dist/toast/toast-viewport.d.mts.map +1 -1
  360. package/dist/toast/toast-viewport.mjs +30 -235
  361. package/dist/toast/toast-viewport.mjs.map +1 -1
  362. package/dist/toast/toast.mjs +1 -1
  363. package/dist/toast/toast.mjs.map +1 -1
  364. package/dist/toast/use-modal-portal-host.mjs +52 -0
  365. package/dist/toast/use-modal-portal-host.mjs.map +1 -0
  366. package/dist/toggle/toggle.d.mts +3 -4
  367. package/dist/toggle/toggle.d.mts.map +1 -1
  368. package/dist/toggle/toggle.mjs +7 -10
  369. package/dist/toggle/toggle.mjs.map +1 -1
  370. package/dist/toggle-group/toggle-group-context.d.mts +2 -1
  371. package/dist/toggle-group/toggle-group-context.d.mts.map +1 -1
  372. package/dist/toggle-group/toggle-group-context.mjs.map +1 -1
  373. package/dist/toggle-group/toggle-group-item.d.mts +5 -3
  374. package/dist/toggle-group/toggle-group-item.d.mts.map +1 -1
  375. package/dist/toggle-group/toggle-group-item.mjs +5 -7
  376. package/dist/toggle-group/toggle-group-item.mjs.map +1 -1
  377. package/dist/toggle-group/toggle-group-root.d.mts.map +1 -1
  378. package/dist/toggle-group/toggle-group-root.mjs +29 -64
  379. package/dist/toggle-group/toggle-group-root.mjs.map +1 -1
  380. package/dist/toolbar/toolbar-root.d.mts +2 -2
  381. package/dist/toolbar/toolbar-root.d.mts.map +1 -1
  382. package/dist/toolbar/toolbar-root.mjs +3 -4
  383. package/dist/toolbar/toolbar-root.mjs.map +1 -1
  384. package/dist/tooltip/tooltip-context.d.mts +1 -1
  385. package/dist/tooltip/tooltip-context.mjs.map +1 -1
  386. package/dist/tooltip/tooltip-popup.d.mts.map +1 -1
  387. package/dist/tooltip/tooltip-popup.mjs +6 -15
  388. package/dist/tooltip/tooltip-popup.mjs.map +1 -1
  389. package/dist/tooltip/tooltip-root.mjs +2 -2
  390. package/dist/tooltip/tooltip-root.mjs.map +1 -1
  391. package/dist/tooltip/tooltip-trigger.d.mts +2 -1
  392. package/dist/tooltip/tooltip-trigger.d.mts.map +1 -1
  393. package/dist/tooltip/tooltip-trigger.mjs +3 -2
  394. package/dist/tooltip/tooltip-trigger.mjs.map +1 -1
  395. package/dist/tooltip/use-tooltip-interaction.mjs +4 -3
  396. package/dist/tooltip/use-tooltip-interaction.mjs.map +1 -1
  397. package/package.json +3 -2
  398. package/dist/accordion/accordion-context.d.mts +0 -5
  399. package/dist/accordion/accordion-context.d.mts.map +0 -1
  400. package/dist/internal/use-popover-root.mjs.map +0 -1
  401. /package/dist/internal/{use-popover-root.d.mts → use-overlay-root.d.mts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"number-field-root.mjs","names":[],"sources":["../../src/number-field/number-field-root.tsx"],"sourcesContent":["\"use client\";\nimport {\n addTransitionType,\n use,\n useCallback,\n useEffect,\n useId,\n useInsertionEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode, RefObject } from \"react\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { announce as speak } from \"../internal/announce.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { FieldContext } from \"../internal/field-context.js\";\nimport { mergeTokenLists } from \"../internal/merge-props.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n RenderProp,\n StateValue,\n} from \"../internal/types.js\";\nimport { useActionTrigger } from \"../internal/use-action-trigger.js\";\nimport { useControllableAction } from \"../internal/use-controllable-action.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useFieldValueChange } from \"../internal/use-field-control.js\";\nimport type { FormAssociatedElement } from \"../internal/use-form-reset.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useNativeGroupReconciliation } from \"../internal/use-native-group-reconciliation.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { boundValue, stepBy, stepValue } from \"./number-field-arithmetic.js\";\nimport type { StepBounds } from \"./number-field-arithmetic.js\";\nimport { NumberFieldContext } from \"./number-field-context.js\";\nimport type {\n NumberFieldContextValue,\n NumberFieldSource,\n StepDirection,\n} from \"./number-field-context.js\";\nimport { createNumberFormatter, formatKey } from \"./number-field-format.js\";\n\n/** Details passed as the second argument of both NumberField actions. */\nexport interface NumberFieldValueChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user typed, pressed a key, a button or turned the wheel (`details.event` is\n * the `focusout` / Enter `keydown` of a typed value, the `keydown` of a key, the `pointerdown` /\n * `pointerup` of a button (`undefined` for the repeats of a held button and for a hold that\n * ended at its bound), the `wheel` event). `\"platform\"`: a form reset (the `reset`\n * event) or text typed before hydration (`undefined`). `\"dismiss\"`: the commit action rejected\n * and the field reverted to the committed value (uncontrolled; `valueChangeAction` only).\n */\n readonly reason: ChangeReason;\n /** What produced the value: typed text, a button, a key, the wheel; `null` for \"platform\" and \"dismiss\". */\n readonly source: \"input\" | \"increment\" | \"decrement\" | \"keyboard\" | \"wheel\" | null;\n}\n\n/** The state every NumberField part's function props receive (one object, Field's precedent). */\nexport interface NumberFieldState {\n /** The shown value: the gesture's value while one is open or in flight, else the optimistic value; `null` when empty. */\n readonly value: number | null;\n /** The shown text: the draft while the user is editing, else `value` formatted. */\n readonly text: string;\n /** A step or commit dispatched through this NumberField is in flight. */\n readonly pending: boolean;\n readonly disabled: boolean;\n readonly readOnly: boolean;\n readonly required: boolean;\n}\n\nexport interface NumberFieldRootProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"defaultValue\" | \"role\" | \"className\" | \"style\" | \"children\"\n> {\n /** Controlled value; `null` is empty, `undefined` uncontrolled. */\n value?: number | null;\n /** Initial value in uncontrolled mode, and its form-reset target (latest). Default `null` (empty). */\n defaultValue?: number | null;\n /**\n * Runs inside the Root's step transition on every step: the parse of typed text at commit,\n * each key press, each tick of a hold, each wheel event, each platform change, and the revert\n * after a rejected commit (`reason: \"dismiss\"`, uncontrolled). Keep it cheap: adopt the value\n * (`setValue(next)` in the sync prefix is a transition update), start a deferred render.\n */\n valueChangeAction?: ChangeAction<number | null, NumberFieldValueChangeDetails>;\n /**\n * Runs inside the Root's commit transition once per gesture: a typed text's blur or Enter, a\n * hold's release, each key press, each wheel event, a form reset, text typed before hydration.\n * Where the save goes; uncontrolled state is committed when it resolves and reverts when it\n * rejects. May be a Server Function.\n */\n valueCommitAction?: ChangeAction<number | null, NumberFieldValueChangeDetails>;\n /** Native `min` on the hidden input (a constraint) and the lower bound of stepping. */\n min?: number;\n /** Native `max` on the hidden input (a constraint) and the upper bound of stepping. */\n max?: number;\n /** Native `step` and the stepping grid from `min` (else `0`). Default `1`, or `0.01` when `format.style` is `\"percent\"`. */\n step?: number;\n /** PageUp / PageDown and Shift+Arrow. Default `10 × step`. */\n largeStep?: number;\n /**\n * `Intl.NumberFormatOptions` for the text: `style` `\"decimal\"` (default), `\"percent\"`,\n * `\"currency\"` (with `currency`), `\"unit\"` (with `unit`); fraction digits, grouping, sign\n * display. `notation: \"compact\"` is a dev warning (unparsable).\n */\n format?: Intl.NumberFormatOptions;\n /**\n * BCP 47 tag(s). Default: the runtime's locale (`Intl.NumberFormat().resolvedOptions().locale`).\n * Pass the page's `lang`; a dev warning fires when `document.documentElement.lang` disagrees\n * and this prop is absent.\n */\n locale?: string | readonly string[];\n /** Step with the mouse wheel while the input is focused. Default `false`. */\n stepOnWheel?: boolean;\n /** Native `name` on the hidden input; defaults to the Field's `name` inside a `Field.Root`. */\n name?: string;\n /** Native `form` on the hidden input. */\n form?: string;\n /** Disables both inputs and the buttons; inherited by every part. */\n disabled?: boolean;\n /** Native `readonly` on both inputs; no stepping (buttons disabled, keys and wheel inert). */\n readOnly?: boolean;\n /** Native `required` on the hidden input (empty is `valueMissing`); or the Field's. */\n required?: boolean;\n /**\n * What is announced (`ariaNotify()`, else a live region) after a key press, a wheel event, a\n * click activation and a hold's release. Default: `(_, state) => state.text`. Return `null` to\n * announce nothing.\n */\n announce?: (value: number | null, state: NumberFieldState) => string | null;\n className?: StateValue<string | undefined, NumberFieldState>;\n style?: StateValue<CSSProperties | undefined, NumberFieldState>;\n children?: StateValue<ReactNode, NumberFieldState>;\n render?: RenderProp<ComponentPropsWithRef<\"div\">, NumberFieldState>;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nconst STEP_TYPES = transitionTypes(\"number-field\", \"change\");\nconst COMMIT_TYPES = transitionTypes(\"number-field\", \"commit\");\n\n/** A finite number, or `null` (`NaN` / `Infinity` are treated as empty). */\nfunction sanitize(value: number | null | undefined): number | null | undefined {\n if (value === undefined || value === null) return value;\n return Number.isFinite(value) ? value : null;\n}\n\n/** The hidden input's value for `value`. */\nexport function hiddenText(value: number | null): string {\n return value === null ? \"\" : String(value);\n}\n\nfunction languageOf(tag: string): string {\n return tag.split(\"-\")[0]?.toLowerCase() ?? \"\";\n}\n\n/**\n * Owns the number field's state (design/components/number-field.md 2): the committed value\n * through `useControllableAction` with `valueCommitAction` (once per gesture), each step through\n * its own transition (`valueChangeAction`), the urgent draft text, the urgent value of the open\n * gesture (`live`), the press-and-hold, the formatter and parser, the announcements, mount\n * reconciliation and form reset (through the hidden input the Input renders).\n *\n * Owned keys (conventions 1.2): `role=\"group\"`, `aria-labelledby` (token-merged: the consumer's,\n * then `NumberField.Label`'s id while one is mounted, then a Field's label id), `data-pending`,\n * `data-disabled`, `data-invalid` (inside a Field).\n */\nexport function NumberFieldRoot(props: NumberFieldRootProps) {\n const {\n value: valueProp,\n defaultValue: defaultValueProp,\n valueChangeAction,\n valueCommitAction,\n min,\n max,\n step: stepProp,\n largeStep: largeStepProp,\n format,\n locale,\n stepOnWheel = false,\n name: nameProp,\n form,\n disabled: disabledProp = false,\n readOnly = false,\n required: requiredProp = false,\n announce,\n className,\n style,\n children,\n render,\n ...rest\n } = props;\n\n const value = sanitize(valueProp);\n const defaultValue = sanitize(defaultValueProp);\n\n // --- Format, bounds -----------------------------------------------------------------------\n\n const key = formatKey(format);\n const localeKey = locale === undefined ? \"\" : JSON.stringify(locale);\n // Memoised on the content of `format` and `locale`, not their identity (an inline object).\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const formatter = useMemo(() => createNumberFormatter(locale, format), [localeKey, key]);\n const defaultStep = formatter.percent ? 0.01 : 1;\n const stepValid = stepProp === undefined || (Number.isFinite(stepProp) && stepProp > 0);\n const stepSize = stepProp !== undefined && stepValid ? stepProp : defaultStep;\n const largeStepValid =\n largeStepProp === undefined || (Number.isFinite(largeStepProp) && largeStepProp > 0);\n const largeStep = largeStepProp !== undefined && largeStepValid ? largeStepProp : 10 * stepSize;\n const bounds = useMemo<StepBounds>(\n () => ({\n min: Number.isFinite(min) ? min : undefined,\n max: Number.isFinite(max) ? max : undefined,\n step: stepSize,\n }),\n [min, max, stepSize],\n );\n\n // --- Field ----------------------------------------------------------------------------------\n\n const fieldContext = use(FieldContext);\n const disabled = disabledProp || (fieldContext?.disabled ?? false);\n const required = requiredProp || (fieldContext?.required ?? false);\n const name = nameProp ?? fieldContext?.name;\n const fieldInvalid = fieldContext === null ? undefined : fieldContext.state.invalid;\n\n const id = useId();\n const inputId = fieldContext?.ids.control ?? `${id}-input`;\n const labelId = `${id}-label`;\n\n // --- State (design 2) -----------------------------------------------------------------------\n\n const [draft, setDraft] = useState<string | null>(null);\n const draftRef = useRef<string | null>(null);\n /** The value the open gesture has reached (`null` inside: an empty value). */\n const [live, setLive] = useState<{ readonly value: number | null } | null>(null);\n const [hold, setHold] = useState<StepDirection | null>(null);\n const [stepHeld, setStepHeld] = useState(false);\n const [pendingSource, setPendingSource] = useState<NumberFieldSource>(null);\n\n const liveRef = useRef<number | null>(null);\n /** The shown value when the open gesture began; `null` when no gesture is open. */\n const gestureStart = useRef<{ readonly value: number | null } | null>(null);\n /** The value the next tick of a hold steps from. */\n const holdBase = useRef<number | null>(null);\n const holdRef = useRef<StepDirection | null>(null);\n const commitSeq = useRef(0);\n const lastReason = useRef<ChangeReason | null>(null);\n const shownRef = useRef<number | null>(null);\n const visibleRef = useRef<HTMLInputElement | null>(null);\n const hiddenRef = useRef<HTMLInputElement | null>(null);\n\n const clearDraft = useCallback(() => {\n if (draftRef.current === null) return;\n draftRef.current = null;\n setDraft(null);\n }, []);\n\n /** The visible input is invalid exactly when the hidden one is (6.2). */\n const mirror = useCallback(() => {\n const hidden = hiddenRef.current;\n const visible = visibleRef.current;\n if (hidden === null || visible === null) return;\n const message = hidden.validationMessage;\n if (visible.validationMessage !== message) visible.setCustomValidity(message);\n }, []);\n\n const writeHidden = useCallback(\n (next: number | null) => {\n const hidden = hiddenRef.current;\n if (hidden !== null) {\n const text = hiddenText(next);\n if (hidden.value !== text) hidden.value = text;\n }\n mirror();\n },\n [mirror],\n );\n\n // A step is not a re-entry: a continuous control dispatches one step per key press or pointer\n // move and every step must run (design/components/button.md 16.1), so no in-flight guard.\n const { pending: stepPending, run: runStep } = useActionTrigger({ ignoreWhilePending: false });\n\n const runCommit = async (\n next: number | null,\n details: NumberFieldValueChangeDetails,\n ): Promise<void> => {\n const seq = ++commitSeq.current;\n try {\n await valueCommitAction?.(next, details);\n } catch (error) {\n // Design 2.4: in uncontrolled mode, tell the preview channel about the rollback, for the\n // latest commit only. Yield once to leave the commit's transition (conventions 2.6).\n if (valueProp === undefined && seq === commitSeq.current) {\n await undefined;\n // `step` and `committedRef` are declared below; this runs long after the render.\n step(committedRef.current, null, \"dismiss\", undefined);\n }\n throw error;\n }\n };\n\n const commitState = useControllableAction<number | null, NumberFieldValueChangeDetails>({\n controlled: value,\n defaultValue,\n initialValue: null,\n action: runCommit,\n transitionTypes: () => COMMIT_TYPES,\n warn: { component: \"NumberField.Root\", prop: \"value\" },\n });\n const { optimistic, committed, dispatch } = commitState;\n const committedRef = useLatest(committed);\n\n const held = hold !== null || stepHeld || stepPending || commitState.pending;\n const shown = held && live !== null ? live.value : optimistic;\n const pending = stepPending || commitState.pending;\n const text = draft ?? formatter.format(shown);\n // The value a button press steps from (4.3 step 3): the parsed draft while one is open.\n const parsedDraft = draft === null ? undefined : formatter.parse(draft);\n const stepBase = parsedDraft === undefined ? shown : parsedDraft;\n useInsertionEffect(() => {\n shownRef.current = shown;\n });\n\n const state = useMemo<NumberFieldState>(\n () => ({ value: shown, text, pending, disabled, readOnly, required }),\n [shown, text, pending, disabled, readOnly, required],\n );\n\n // A step, a key and a typed commit fire no `input` / `change` on the element the Field hears\n // for the value (the hidden input is written by script): tell it at the commit (design 7.2).\n useFieldValueChange(optimistic, () => {\n const edit = lastReason.current === \"activate\";\n lastReason.current = null;\n return edit;\n });\n\n const latest = useLatest({\n valueChangeAction,\n runStep,\n formatter,\n bounds,\n largeStep,\n disabled,\n readOnly,\n announce,\n state,\n });\n\n // --- Step and commit (design 2.4) -----------------------------------------------------------\n\n const step = useCallback(\n (\n next: number | null,\n source: NumberFieldSource,\n reason: ChangeReason,\n event: Event | undefined,\n ): boolean => {\n // What the text can show is what the form posts (5.4): a step finer than the format's\n // digits is rounded like a typed value.\n const { formatter: f } = latest.current;\n if (next !== null) next = f.round(next);\n // No-op against what the user sees (conventions 2.3 item 8).\n if (Object.is(next, shownRef.current)) return false;\n liveRef.current = next;\n shownRef.current = next;\n lastReason.current = reason;\n setLive({ value: next });\n clearDraft();\n setPendingSource(source);\n writeHidden(next);\n // A revert has no commit after it: the optimistic value already shows the committed one.\n if (reason !== \"dismiss\") setStepHeld(true);\n const { valueChangeAction: action, runStep: run } = latest.current;\n // Without a step action nothing runs and no transition starts (Slider M2).\n if (action === undefined) return true;\n run(() => {\n for (const type of STEP_TYPES) addTransitionType(type);\n return action(next, createActionDetails(event, { reason, source }));\n });\n return true;\n },\n [clearDraft, latest, writeHidden],\n );\n\n const announceValue = useCallback(\n (next: number | null) => {\n const visible = visibleRef.current;\n if (visible === null) return;\n const { announce: compose, formatter: f, state: s } = latest.current;\n const nextState: NumberFieldState = { ...s, value: next, text: f.format(next) };\n const message = compose === undefined ? nextState.text : compose(next, nextState);\n if (message !== null) speak(visible, message);\n },\n [latest],\n );\n\n const commit = useCallback(\n (source: NumberFieldSource, reason: ChangeReason, event: Event | undefined): boolean => {\n const start = gestureStart.current;\n gestureStart.current = null;\n // The commit's own pending state holds `live` from here (set in this same batch).\n setStepHeld(false);\n const next = liveRef.current;\n // Nothing changed since the gesture began (a hold that returned to its start).\n if (start === null || Object.is(next, start.value)) return false;\n lastReason.current = reason;\n setPendingSource(source);\n dispatch(next, createActionDetails(event, { reason, source }));\n if (reason === \"activate\" && source !== \"input\" && source !== null) announceValue(next);\n return true;\n },\n [announceValue, dispatch],\n );\n\n /** Opens a gesture at the shown value. */\n const openGesture = useCallback(() => {\n gestureStart.current = { value: shownRef.current };\n liveRef.current = shownRef.current;\n }, []);\n\n /** The value a key or a button steps from: the parsed draft if one is open, else the shown value. */\n const resolveBase = useCallback((): number | null => {\n const open = draftRef.current;\n if (open !== null) {\n const parsed = latest.current.formatter.parse(open);\n clearDraft();\n if (parsed !== undefined) return parsed;\n }\n return shownRef.current;\n }, [clearDraft, latest]);\n\n /** A one-step gesture: a key press, a wheel event, a click activation. */\n const oneStep = useCallback(\n (compute: (base: number | null) => number | null, source: NumberFieldSource, event: Event) => {\n const base = resolveBase();\n openGesture();\n step(compute(base), source, \"activate\", event);\n commit(source, \"activate\", event);\n },\n [commit, openGesture, resolveBase, step],\n );\n\n // --- Typing (design 4.1) ----------------------------------------------------------------------\n\n const typed = useCallback((next: string) => {\n draftRef.current = next;\n setDraft(next);\n }, []);\n\n const commitDraft = useCallback(\n (event: Event) => {\n const open = draftRef.current;\n if (open === null) return;\n const { formatter: f, disabled: off, readOnly: ro } = latest.current;\n if (off || ro) {\n clearDraft();\n return;\n }\n const parsed = f.parse(open);\n // Unparsable: revert to the committed value's text, no dispatch, no error.\n if (parsed === undefined || Object.is(parsed, shownRef.current)) {\n clearDraft();\n return;\n }\n openGesture();\n step(parsed, \"input\", \"activate\", event);\n commit(\"input\", \"activate\", event);\n },\n [clearDraft, commit, latest, openGesture, step],\n );\n\n // --- Keyboard and wheel (design 4.2, 4.4) ----------------------------------------------------\n\n const keyDown = useCallback(\n (event: KeyboardEvent) => {\n const { disabled: off, readOnly: ro, bounds: b, largeStep: large } = latest.current;\n // WebKit fires `compositionend` before the confirming keydown, which then has\n // `isComposing === false` and `keyCode === 229` (Combobox's guard).\n if (off || ro || event.isComposing || event.keyCode === 229) return;\n if (event.key === \"Enter\") {\n commitDraft(event);\n return;\n }\n if (event.altKey || event.ctrlKey || event.metaKey) return;\n let compute: ((base: number | null) => number | null) | null = null;\n switch (event.key) {\n case \"ArrowUp\":\n compute = event.shiftKey ? (v) => stepBy(v, large, b) : (v) => stepValue(v, 1, b);\n break;\n case \"ArrowDown\":\n compute = event.shiftKey ? (v) => stepBy(v, -large, b) : (v) => stepValue(v, -1, b);\n break;\n case \"PageUp\":\n compute = (v) => stepBy(v, large, b);\n break;\n case \"PageDown\":\n compute = (v) => stepBy(v, -large, b);\n break;\n case \"Home\": {\n // Shift+Home / Shift+End are text selection.\n if (event.shiftKey) break;\n const target = boundValue(\"min\", b);\n if (target !== undefined) compute = () => target;\n break;\n }\n case \"End\": {\n if (event.shiftKey) break;\n const target = boundValue(\"max\", b);\n if (target !== undefined) compute = () => target;\n break;\n }\n default:\n break;\n }\n if (compute === null) return;\n event.preventDefault();\n oneStep(compute, \"keyboard\", event);\n },\n [commitDraft, latest, oneStep],\n );\n\n const wheel = useCallback(\n (event: WheelEvent) => {\n const { disabled: off, readOnly: ro, bounds: b } = latest.current;\n const visible = visibleRef.current;\n if (off || ro || visible === null || event.deltaY === 0) return;\n // Only while the input is focused; unfocused, the page scrolls.\n if (visible.ownerDocument.activeElement !== visible) return;\n event.preventDefault();\n const n = event.deltaY < 0 ? 1 : -1;\n oneStep((v) => stepValue(v, n, b), \"wheel\", event);\n },\n [latest, oneStep],\n );\n\n // --- Buttons (design 4.3) ---------------------------------------------------------------------\n\n const endHold = useCallback(\n (direction: StepDirection, event: Event | undefined) => {\n if (holdRef.current !== direction) return;\n holdRef.current = null;\n setHold(null);\n commit(direction, \"activate\", event);\n },\n [commit],\n );\n\n const tickHold = useCallback(\n (direction: StepDirection, event: Event | undefined): boolean => {\n if (holdRef.current !== direction) return false;\n const { bounds: b } = latest.current;\n const n = direction === \"increment\" ? 1 : -1;\n const next = stepValue(holdBase.current, n, b);\n holdBase.current = next;\n step(next, direction, \"activate\", event);\n // At the bound: end the hold now, before the button re-renders disabled (a disabled\n // element may not deliver the release).\n if (stepValue(next, n, b) === next) {\n endHold(direction, event);\n return false;\n }\n return true;\n },\n [endHold, latest, step],\n );\n\n const beginHold = useCallback(\n (direction: StepDirection, event: Event): boolean => {\n const { disabled: off, readOnly: ro } = latest.current;\n if (off || ro || holdRef.current !== null) return false;\n const base = resolveBase();\n openGesture();\n // A capture alone holds `live` on screen: start it from what is shown.\n setLive({ value: shownRef.current });\n holdBase.current = base;\n holdRef.current = direction;\n setHold(direction);\n return tickHold(direction, event);\n },\n [latest, openGesture, resolveBase, tickHold],\n );\n\n const activate = useCallback(\n (direction: StepDirection, event: Event) => {\n const { disabled: off, readOnly: ro, bounds: b } = latest.current;\n if (off || ro || holdRef.current !== null) return;\n const n = direction === \"increment\" ? 1 : -1;\n oneStep((v) => stepValue(v, n, b), direction, event);\n },\n [latest, oneStep],\n );\n\n // --- Labels ---------------------------------------------------------------------------------\n\n const [labelCount, setLabelCount] = useState(0);\n const registerLabel = useCallback(() => {\n setLabelCount((count) => count + 1);\n return () => setLabelCount((count) => count - 1);\n }, []);\n\n // --- Residual browser paths: mount reconciliation and form reset (design 4.5, 6.4) ----------\n\n const [mountValue] = useState(value);\n const resetTarget = (): number | null =>\n valueProp !== undefined ? (mountValue ?? null) : (defaultValue ?? null);\n const resetTargetText = hiddenText(resetTarget());\n\n const { onItemMounted } = useNativeGroupReconciliation<number | null>({\n element: hiddenRef as RefObject<FormAssociatedElement | null>,\n readCurrent: () => {\n const visible = visibleRef.current;\n const current = shownRef.current;\n if (visible === null) return current;\n const domText = visible.value;\n if (domText === formatter.format(current)) return current;\n if (visible.ownerDocument.activeElement === visible) {\n // Still typing (even a partial `12,` or `-`): adopted as the draft, never overwritten\n // under the caret. The blur commits it, or reverts it by the ordinary rule.\n draftRef.current = domText;\n setDraft(domText);\n return current;\n }\n const parsed = formatter.parse(domText);\n if (parsed === undefined || Object.is(parsed, current)) {\n // Another locale's formatting of the same value, or text that is no number: show the\n // client's text (react-dom kept the hydrated DOM value).\n visible.value = formatter.format(current);\n return current;\n }\n return parsed;\n },\n readDefault: () => {\n // A reset clears an open draft whatever the target.\n clearDraft();\n return resetTarget();\n },\n base: () => shownRef.current,\n onPlatformChange: (next, event) => {\n openGesture();\n step(next, null, \"platform\", event);\n commit(null, \"platform\", event);\n },\n onResetEvent: () => {\n // react-dom rewrites a controlled text input's `defaultValue` after every update; the\n // visible text's reset target is written right before the reset algorithm reads it.\n const visible = visibleRef.current;\n if (visible !== null) visible.defaultValue = formatter.format(resetTarget());\n },\n });\n\n // --- Development warnings -------------------------------------------------------------------\n\n useDevWarning(\n (valueProp !== undefined && valueProp !== null && !Number.isFinite(valueProp)) ||\n (defaultValueProp !== undefined &&\n defaultValueProp !== null &&\n !Number.isFinite(defaultValueProp)),\n \"NumberField.Root: `value` / `defaultValue` must be a finite number or `null`; \" +\n `got ${String(valueProp ?? defaultValueProp)}, treated as empty.`,\n );\n useDevWarning(\n bounds.min !== undefined && bounds.max !== undefined && bounds.min > bounds.max,\n `NumberField.Root: \\`min\\` (${String(min)}) is greater than \\`max\\` (${String(max)}).`,\n );\n useDevWarning(\n !stepValid || !largeStepValid,\n \"NumberField.Root: `step` and `largeStep` must be positive numbers; using the defaults.\",\n );\n useDevWarning(formatter.warning !== null, `NumberField.Root: ${formatter.warning ?? \"\"}`);\n const warnedLang = useRef(false);\n useEffect(() => {\n if (!isDev || warnedLang.current || locale !== undefined) return;\n const lang = document.documentElement.lang;\n if (lang === \"\" || languageOf(lang) === languageOf(formatter.locale)) return;\n warnedLang.current = true;\n console.error(\n `NumberField.Root: the page is \\`lang=\"${lang}\"\\` but NumberField formats as ` +\n `\\`${formatter.locale}\\` (the runtime's locale); pass \\`locale\\`.`,\n );\n }, [locale, formatter]);\n\n // An unmount mid-hold leaves nothing behind (the buttons detach their own listeners).\n useEffect(\n () => () => {\n holdRef.current = null;\n },\n [],\n );\n\n // --- Render ---------------------------------------------------------------------------------\n\n const context = useMemo<NumberFieldContextValue>(\n () => ({\n state,\n bounds,\n stepBase,\n pendingSource: pending ? pendingSource : null,\n inputId,\n labelId,\n name,\n form,\n allowsFractions: formatter.allowsFractions || !Number.isInteger(stepSize),\n stepOnWheel,\n resetTargetText,\n fieldInvalid,\n visibleRef,\n hiddenRef,\n typed,\n commitDraft,\n keyDown,\n wheel,\n beginHold,\n tickHold,\n endHold,\n activate,\n mirror,\n registerLabel,\n onInputMounted: onItemMounted,\n }),\n [\n state,\n bounds,\n stepBase,\n pending,\n pendingSource,\n inputId,\n labelId,\n name,\n form,\n formatter,\n stepSize,\n stepOnWheel,\n resetTargetText,\n fieldInvalid,\n typed,\n commitDraft,\n keyDown,\n wheel,\n beginHold,\n tickHold,\n endHold,\n activate,\n mirror,\n registerLabel,\n onItemMounted,\n ],\n );\n\n const labelledBy = mergeTokenLists(labelCount > 0 ? labelId : undefined, fieldContext?.ids.label);\n const libraryProps: Partial<ComponentPropsWithRef<\"div\">> & DataAttributes = {\n role: \"group\",\n ...(labelledBy !== \"\" ? { \"aria-labelledby\": labelledBy } : {}),\n ...(fieldContext !== null ? { \"data-invalid\": dataAttr(fieldInvalid === true) } : {}),\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, NumberFieldState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps,\n });\n\n return <NumberFieldContext value={context}>{element}</NumberFieldContext>;\n}\n\nNumberFieldRoot.displayName = \"NumberFieldRoot\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2IA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAEvC,MAAM,a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ACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CAEA,MAAM,aAAa,gBAAgB,aAAa,IAAI,UAAU,KAAA,GAAW,cAAc,IAAI,KAAK;CAChG,MAAM,eAAuE;EAC3E,MAAM;EACN,GAAI,eAAe,KAAK,EAAE,mBAAmB,WAAW,IAAI,CAAC;EAC7D,GAAI,iBAAiB,OAAO,EAAE,gBAAgB,SAAS,iBAAiB,IAAI,EAAE,IAAI,CAAC;EACnF,gBAAgB,SAAS,OAAO;EAChC,iBAAiB,SAAS,QAAQ;CACpC;CAEA,MAAM,UAAU,UAA0D;EACxE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;CACF,CAAC;CAED,OAAO,oBAAC,oBAAD;EAAoB,OAAO;EAAU,UAAA;CAA4B,CAAA;AAC1E;AAEA,gBAAgB,cAAc"}
1
+ {"version":3,"file":"number-field-root.mjs","names":[],"sources":["../../src/number-field/number-field-root.tsx"],"sourcesContent":["\"use client\";\nimport {\n addTransitionType,\n use,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode, RefObject } from \"react\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { announce as speak } from \"../internal/announce.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { FieldContext } from \"../internal/field-context.js\";\nimport { mergeTokenLists } from \"../internal/merge-props.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n RenderProp,\n StateValue,\n} from \"../internal/types.js\";\nimport { useActionTrigger } from \"../internal/use-action-trigger.js\";\nimport { useControllableAction } from \"../internal/use-controllable-action.js\";\nimport { resolveFieldDefaults, useFieldValueChange } from \"../internal/use-field-control.js\";\nimport type { FormAssociatedElement } from \"../internal/use-form-owner-event.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useNativeGroupReconciliation } from \"../internal/use-native-group-reconciliation.js\";\nimport { useSupersededRejection } from \"../internal/use-superseded-rejection.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { keyStep, stepValue } from \"./number-field-arithmetic.js\";\nimport type { StepBounds } from \"./number-field-arithmetic.js\";\nimport { NumberFieldContext } from \"./number-field-context.js\";\nimport type {\n NumberFieldContextValue,\n NumberFieldSource,\n StepDirection,\n} from \"./number-field-context.js\";\nimport { createNumberFormatter, formatKey } from \"./number-field-format.js\";\nimport type { NumberFormatter } from \"./number-field-format.js\";\nimport { useNumberFieldDevWarnings } from \"./use-number-field-dev-warnings.js\";\n\n/** Details passed as the second argument of both NumberField actions. */\nexport interface NumberFieldValueChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user typed, pressed a key, a button or turned the wheel (`details.event` is\n * the `focusout` / Enter `keydown` of a typed value, the `keydown` of a key, the `pointerdown` /\n * `pointerup` of a button (`undefined` for the repeats of a held button and for a hold that\n * ended at its bound), the `wheel` event). `\"platform\"`: a form reset (the `reset`\n * event) or text typed before hydration (`undefined`). `\"dismiss\"`: the commit action rejected\n * and the field reverted to the committed value (uncontrolled; `valueChangeAction` only).\n */\n readonly reason: ChangeReason;\n /** What produced the value: typed text, a button, a key, the wheel; `null` for \"platform\" and \"dismiss\". */\n readonly source: NumberFieldSource;\n}\n\n/** The state every NumberField part's function props receive (one object, Field's precedent). */\nexport interface NumberFieldState {\n /** The shown value: the gesture's value while one is open or in flight, else the optimistic value; `null` when empty. */\n readonly value: number | null;\n /** The shown text: the draft while the user is editing, else `value` formatted. */\n readonly text: string;\n /** A step or commit dispatched through this NumberField is in flight. */\n readonly pending: boolean;\n readonly disabled: boolean;\n readonly readOnly: boolean;\n readonly required: boolean;\n}\n\nexport interface NumberFieldRootProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"defaultValue\" | \"role\" | \"className\" | \"style\" | \"children\"\n> {\n /** Controlled value; `null` is empty, `undefined` uncontrolled. */\n value?: number | null;\n /** Initial value in uncontrolled mode, and its form-reset target (latest). Default `null` (empty). */\n defaultValue?: number | null;\n /**\n * Runs inside the Root's step transition on every step: the parse of typed text at commit,\n * each key press, each tick of a hold, each wheel event, each platform change, and the revert\n * after a rejected commit (`reason: \"dismiss\"`, uncontrolled). Keep it cheap: adopt the value\n * (`setValue(next)` in the sync prefix is a transition update), start a deferred render.\n */\n valueChangeAction?: ChangeAction<number | null, NumberFieldValueChangeDetails>;\n /**\n * Runs inside the Root's commit transition once per gesture: a typed text's blur or Enter, a\n * hold's release, each key press, each wheel event, a form reset, text typed before hydration.\n * Where the save goes; uncontrolled state is committed when it resolves and reverts when it\n * rejects. May be a Server Function.\n */\n valueCommitAction?: ChangeAction<number | null, NumberFieldValueChangeDetails>;\n /** Native `min` on the hidden input (a constraint) and the lower bound of stepping. */\n min?: number;\n /** Native `max` on the hidden input (a constraint) and the upper bound of stepping. */\n max?: number;\n /** Native `step` and the stepping grid from `min` (else `0`). Default `1`, or `0.01` when `format.style` is `\"percent\"`. */\n step?: number;\n /** PageUp / PageDown and Shift+Arrow. Default `10 × step`. */\n largeStep?: number;\n /**\n * `Intl.NumberFormatOptions` for the text: `style` `\"decimal\"` (default), `\"percent\"`,\n * `\"currency\"` (with `currency`), `\"unit\"` (with `unit`); fraction digits, grouping, sign\n * display. `notation: \"compact\"` is a dev warning (unparsable).\n */\n format?: Intl.NumberFormatOptions;\n /**\n * BCP 47 tag(s). Default: the runtime's locale (`Intl.NumberFormat().resolvedOptions().locale`).\n * Pass the page's `lang`; a dev warning fires when `document.documentElement.lang` disagrees\n * and this prop is absent.\n */\n locale?: string | readonly string[];\n /** Step with the mouse wheel while the input is focused. Default `false`. */\n stepOnWheel?: boolean;\n /** Native `name` on the hidden input; defaults to the Field's `name` inside a `Field.Root`. */\n name?: string;\n /** Native `form` on the hidden input. */\n form?: string;\n /** Disables both inputs and the buttons; inherited by every part. */\n disabled?: boolean;\n /** Native `readonly` on both inputs; no stepping (buttons disabled, keys and wheel inert). */\n readOnly?: boolean;\n /** Native `required` on the hidden input (empty is `valueMissing`); or the Field's. */\n required?: boolean;\n /**\n * What is announced (`ariaNotify()`, else a live region) after a key press, a wheel event, a\n * click activation and a hold's release. Default: `(_, state) => state.text`. Return `null` to\n * announce nothing.\n */\n announce?: (value: number | null, state: NumberFieldState) => string | null;\n className?: StateValue<string | undefined, NumberFieldState>;\n style?: StateValue<CSSProperties | undefined, NumberFieldState>;\n children?: StateValue<ReactNode, NumberFieldState>;\n render?: RenderProp<ComponentPropsWithRef<\"div\">, NumberFieldState>;\n}\n\nconst STEP_TYPES = transitionTypes(\"number-field\", \"change\");\nconst COMMIT_TYPES = transitionTypes(\"number-field\", \"commit\");\n\n/** A finite number, or `null` (`NaN` / `Infinity` are treated as empty). */\nfunction sanitize(value: number | null | undefined): number | null | undefined {\n if (value === undefined || value === null) return value;\n return Number.isFinite(value) ? value : null;\n}\n\n/** The hidden input's value for `value`. */\nfunction hiddenText(value: number | null): string {\n return value === null ? \"\" : String(value);\n}\n\n/**\n * Mount reconciliation's read of the visible input (design 4.5): the value the hydrated text\n * means. The client's own formatting of `current` is `current`. Focused text is still being typed\n * (even a partial `12,` or `-`): handed to `adoptDraft`, never overwritten under the caret; the\n * blur commits or reverts it by the ordinary rule. Otherwise the parsed text, or, for another\n * locale's formatting of the same value or text that is no number, `current` with the client's\n * text written back (react-dom kept the hydrated DOM value).\n */\nfunction readVisible(\n visible: HTMLInputElement | null,\n current: number | null,\n formatter: NumberFormatter,\n adoptDraft: (text: string) => void,\n): number | null {\n if (visible === null) return current;\n const domText = visible.value;\n if (domText === formatter.format(current)) return current;\n if (visible.ownerDocument.activeElement === visible) {\n adoptDraft(domText);\n return current;\n }\n const parsed = formatter.parse(domText);\n if (parsed === undefined || Object.is(parsed, current)) {\n visible.value = formatter.format(current);\n return current;\n }\n return parsed;\n}\n\n/**\n * Owns the number field's state (design/components/number-field.md 2): the committed value\n * through `useControllableAction` with `valueCommitAction` (once per gesture), each step through\n * its own transition (`valueChangeAction`), the urgent draft text, the urgent value of the open\n * gesture (`live`), the press-and-hold, the formatter and parser, the announcements, mount\n * reconciliation and form reset (through the hidden input the Input renders).\n *\n * Owned keys (conventions 1.2): `role=\"group\"`, `aria-labelledby` (token-merged: the consumer's,\n * then `NumberField.Label`'s id while one is mounted, then a Field's label id), `data-pending`,\n * `data-disabled`, `data-invalid` (inside a Field).\n */\nexport function NumberFieldRoot(props: NumberFieldRootProps) {\n const {\n value: valueProp,\n defaultValue: defaultValueProp,\n valueChangeAction,\n valueCommitAction,\n min,\n max,\n step: stepProp,\n largeStep: largeStepProp,\n format,\n locale,\n stepOnWheel = false,\n name: nameProp,\n form,\n disabled: disabledProp = false,\n readOnly = false,\n required: requiredProp = false,\n announce,\n className,\n style,\n children,\n render,\n ...rest\n } = props;\n\n const value = sanitize(valueProp);\n const defaultValue = sanitize(defaultValueProp);\n\n // --- Format, bounds -----------------------------------------------------------------------\n\n const key = formatKey(format);\n const localeKey = locale === undefined ? \"\" : JSON.stringify(locale);\n // Memoised on the content of `format` and `locale`, not their identity (an inline object).\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const formatter = useMemo(() => createNumberFormatter(locale, format), [localeKey, key]);\n const defaultStep = formatter.percent ? 0.01 : 1;\n const stepValid = stepProp === undefined || (Number.isFinite(stepProp) && stepProp > 0);\n const stepSize = stepProp !== undefined && stepValid ? stepProp : defaultStep;\n const largeStepValid =\n largeStepProp === undefined || (Number.isFinite(largeStepProp) && largeStepProp > 0);\n const largeStep = largeStepProp !== undefined && largeStepValid ? largeStepProp : 10 * stepSize;\n const bounds = useMemo<StepBounds>(\n () => ({\n min: Number.isFinite(min) ? min : undefined,\n max: Number.isFinite(max) ? max : undefined,\n step: stepSize,\n }),\n [min, max, stepSize],\n );\n\n // --- Field ----------------------------------------------------------------------------------\n\n // NumberField.Input registers the control (design 7.1); the Root only resolves the defaults.\n const fieldContext = use(FieldContext);\n const { disabled, required, name } = resolveFieldDefaults(fieldContext, {\n name: nameProp,\n disabled: disabledProp,\n required: requiredProp,\n });\n const fieldInvalid = fieldContext === null ? undefined : fieldContext.state.invalid;\n\n const id = useId();\n const inputId = fieldContext?.ids.control ?? `${id}-input`;\n const labelId = `${id}-label`;\n\n // --- State (design 2) -----------------------------------------------------------------------\n\n const [draft, setDraft] = useState<string | null>(null);\n const draftRef = useRef<string | null>(null);\n /** The value the open gesture has reached (`null` inside: an empty value). */\n const [live, setLive] = useState<{ readonly value: number | null } | null>(null);\n const [hold, setHold] = useState<StepDirection | null>(null);\n const [stepHeld, setStepHeld] = useState(false);\n const [pendingSource, setPendingSource] = useState<NumberFieldSource>(null);\n\n const liveRef = useRef<number | null>(null);\n /** The shown value when the open gesture began; `null` when no gesture is open. */\n const gestureStart = useRef<{ readonly value: number | null } | null>(null);\n /** The value the next tick of a hold steps from. */\n const holdBase = useRef<number | null>(null);\n const holdRef = useRef<StepDirection | null>(null);\n const commitSeq = useRef(0);\n const lastReason = useRef<ChangeReason | null>(null);\n const visibleRef = useRef<HTMLInputElement | null>(null);\n const hiddenRef = useRef<HTMLInputElement | null>(null);\n\n const clearDraft = useCallback(() => {\n if (draftRef.current === null) return;\n draftRef.current = null;\n setDraft(null);\n }, []);\n\n /**\n * Writes `next` into the hidden input, then mirrors its validity onto the visible input, which\n * is invalid exactly when the hidden one is (6.2).\n */\n const syncHidden = useCallback((next: number | null) => {\n const hidden = hiddenRef.current;\n if (hidden !== null) {\n const text = hiddenText(next);\n if (hidden.value !== text) hidden.value = text;\n }\n const visible = visibleRef.current;\n if (hidden === null || visible === null) return;\n const message = hidden.validationMessage;\n if (visible.validationMessage !== message) visible.setCustomValidity(message);\n }, []);\n\n // One capture for both channels, before both transitions (see `captureSuperseded`).\n const captureSuperseded = useSupersededRejection();\n\n // A step is not a re-entry: a continuous control dispatches one step per key press or pointer\n // move and every step must run (design/components/button.md 16.1), so no in-flight guard.\n const { pending: stepPending, run: runStep } = useActionTrigger({\n ignoreWhilePending: false,\n captureSuperseded,\n });\n\n const runCommit = async (\n next: number | null,\n details: NumberFieldValueChangeDetails,\n ): Promise<void> => {\n const seq = ++commitSeq.current;\n try {\n await valueCommitAction?.(next, details);\n } catch (error) {\n // Design 2.4: in uncontrolled mode, tell the preview channel about the rollback, for the\n // latest commit only. Yield once to leave the commit's transition (conventions 2.6).\n if (valueProp === undefined && seq === commitSeq.current) {\n await undefined;\n // `step` and `committedRef` are declared below; this runs long after the render.\n step(committedRef.current, null, \"dismiss\", undefined);\n }\n throw error;\n }\n };\n\n const commitState = useControllableAction<number | null, NumberFieldValueChangeDetails>({\n controlled: value,\n defaultValue,\n initialValue: null,\n action: runCommit,\n transitionTypes: () => COMMIT_TYPES,\n warn: { component: \"NumberField.Root\", prop: \"value\" },\n captureSuperseded,\n });\n const { optimistic, committed, dispatch } = commitState;\n const committedRef = useLatest(committed);\n\n const held = hold !== null || stepHeld || stepPending || commitState.pending;\n const shown = held && live !== null ? live.value : optimistic;\n const pending = stepPending || commitState.pending;\n const text = draft ?? formatter.format(shown);\n // The value a button press steps from (4.3 step 3): the parsed draft while one is open.\n const parsedDraft = draft === null ? undefined : formatter.parse(draft);\n const stepBase = parsedDraft === undefined ? shown : parsedDraft;\n /** What the input shows, for handlers; also written by `step` ahead of the render. */\n const shownRef = useLatest(shown);\n\n const state = useMemo<NumberFieldState>(\n () => ({ value: shown, text, pending, disabled, readOnly, required }),\n [shown, text, pending, disabled, readOnly, required],\n );\n\n // A step, a key and a typed commit fire no `input` / `change` on the element the Field hears\n // for the value (the hidden input is written by script): tell it at the commit (design 7.2).\n useFieldValueChange(optimistic, () => {\n const edit = lastReason.current === \"activate\";\n lastReason.current = null;\n return edit;\n });\n\n const latest = useLatest({\n valueChangeAction,\n runStep,\n formatter,\n bounds,\n largeStep,\n disabled,\n readOnly,\n announce,\n state,\n });\n\n // --- Step and commit (design 2.4) -----------------------------------------------------------\n\n const step = useCallback(\n (\n next: number | null,\n source: NumberFieldSource,\n reason: ChangeReason,\n event: Event | undefined,\n ): boolean => {\n // What the text can show is what the form posts (5.4): a step finer than the format's\n // digits is rounded like a typed value.\n const { formatter: f } = latest.current;\n if (next !== null) next = f.round(next);\n // No-op against what the user sees (conventions 2.3 item 8).\n if (Object.is(next, shownRef.current)) return false;\n liveRef.current = next;\n shownRef.current = next;\n lastReason.current = reason;\n setLive({ value: next });\n clearDraft();\n setPendingSource(source);\n syncHidden(next);\n // A revert has no commit after it: the optimistic value already shows the committed one.\n if (reason !== \"dismiss\") setStepHeld(true);\n const { valueChangeAction: action, runStep: run } = latest.current;\n // Without a step action nothing runs and no transition starts (as Slider).\n if (action === undefined) return true;\n run(() => {\n for (const type of STEP_TYPES) addTransitionType(type);\n return action(next, createActionDetails(event, { reason, source }));\n });\n return true;\n },\n [clearDraft, latest, shownRef, syncHidden],\n );\n\n const announceValue = useCallback(\n (next: number | null) => {\n const visible = visibleRef.current;\n if (visible === null) return;\n const { announce: compose, formatter: f, state: s } = latest.current;\n const nextState: NumberFieldState = { ...s, value: next, text: f.format(next) };\n const message = compose === undefined ? nextState.text : compose(next, nextState);\n if (message !== null) speak(visible, message);\n },\n [latest],\n );\n\n const commit = useCallback(\n (source: NumberFieldSource, reason: ChangeReason, event: Event | undefined): boolean => {\n const start = gestureStart.current;\n gestureStart.current = null;\n // The commit's own pending state holds `live` from here (set in this same batch).\n setStepHeld(false);\n const next = liveRef.current;\n // Nothing changed since the gesture began (a hold that returned to its start).\n if (start === null || Object.is(next, start.value)) return false;\n lastReason.current = reason;\n setPendingSource(source);\n dispatch(next, createActionDetails(event, { reason, source }));\n if (reason === \"activate\" && source !== \"input\" && source !== null) announceValue(next);\n return true;\n },\n [announceValue, dispatch],\n );\n\n /** Opens a gesture at the shown value. */\n const openGesture = useCallback(() => {\n gestureStart.current = { value: shownRef.current };\n liveRef.current = shownRef.current;\n }, [shownRef]);\n\n /** The value a key or a button steps from: the parsed draft if one is open, else the shown value. */\n const resolveBase = useCallback((): number | null => {\n const open = draftRef.current;\n if (open !== null) {\n const parsed = latest.current.formatter.parse(open);\n clearDraft();\n if (parsed !== undefined) return parsed;\n }\n return shownRef.current;\n }, [clearDraft, latest, shownRef]);\n\n /** A one-step gesture: a key press, a wheel event, a click activation. */\n const oneStep = useCallback(\n (compute: (base: number | null) => number | null, source: NumberFieldSource, event: Event) => {\n const base = resolveBase();\n openGesture();\n step(compute(base), source, \"activate\", event);\n commit(source, \"activate\", event);\n },\n [commit, openGesture, resolveBase, step],\n );\n\n // --- Typing (design 4.1) ----------------------------------------------------------------------\n\n const typed = useCallback((next: string) => {\n draftRef.current = next;\n setDraft(next);\n }, []);\n\n const commitDraft = useCallback(\n (event: Event) => {\n const open = draftRef.current;\n if (open === null) return;\n const { formatter: f, disabled: off, readOnly: ro } = latest.current;\n if (off || ro) {\n clearDraft();\n return;\n }\n const parsed = f.parse(open);\n // Unparsable: revert to the committed value's text, no dispatch, no error.\n if (parsed === undefined || Object.is(parsed, shownRef.current)) {\n clearDraft();\n return;\n }\n openGesture();\n step(parsed, \"input\", \"activate\", event);\n commit(\"input\", \"activate\", event);\n },\n [clearDraft, commit, latest, openGesture, shownRef, step],\n );\n\n // --- Keyboard and wheel (design 4.2, 4.4) ----------------------------------------------------\n\n const keyDown = useCallback(\n (event: KeyboardEvent) => {\n const { disabled: off, readOnly: ro, bounds: b, largeStep: large } = latest.current;\n // WebKit fires `compositionend` before the confirming keydown, which then has\n // `isComposing === false` and `keyCode === 229` (Combobox's guard).\n if (off || ro || event.isComposing || event.keyCode === 229) return;\n if (event.key === \"Enter\") {\n commitDraft(event);\n return;\n }\n if (event.altKey || event.ctrlKey || event.metaKey) return;\n const compute = keyStep(event.key, event.shiftKey, b, large);\n if (compute === null) return;\n event.preventDefault();\n oneStep(compute, \"keyboard\", event);\n },\n [commitDraft, latest, oneStep],\n );\n\n const wheel = useCallback(\n (event: WheelEvent) => {\n const { disabled: off, readOnly: ro, bounds: b } = latest.current;\n const visible = visibleRef.current;\n if (off || ro || visible === null || event.deltaY === 0) return;\n // Only while the input is focused; unfocused, the page scrolls.\n if (visible.ownerDocument.activeElement !== visible) return;\n event.preventDefault();\n const n = event.deltaY < 0 ? 1 : -1;\n oneStep((v) => stepValue(v, n, b), \"wheel\", event);\n },\n [latest, oneStep],\n );\n\n // --- Buttons (design 4.3) ---------------------------------------------------------------------\n\n const endHold = useCallback(\n (direction: StepDirection, event: Event | undefined) => {\n if (holdRef.current !== direction) return;\n holdRef.current = null;\n setHold(null);\n commit(direction, \"activate\", event);\n },\n [commit],\n );\n\n const tickHold = useCallback(\n (direction: StepDirection, event: Event | undefined): boolean => {\n if (holdRef.current !== direction) return false;\n const { bounds: b } = latest.current;\n const n = direction === \"increment\" ? 1 : -1;\n const next = stepValue(holdBase.current, n, b);\n holdBase.current = next;\n step(next, direction, \"activate\", event);\n // At the bound: end the hold now, before the button re-renders disabled (a disabled\n // element may not deliver the release).\n if (stepValue(next, n, b) === next) {\n endHold(direction, event);\n return false;\n }\n return true;\n },\n [endHold, latest, step],\n );\n\n const beginHold = useCallback(\n (direction: StepDirection, event: Event): boolean => {\n const { disabled: off, readOnly: ro } = latest.current;\n if (off || ro || holdRef.current !== null) return false;\n const base = resolveBase();\n openGesture();\n // A capture alone holds `live` on screen: start it from what is shown.\n setLive({ value: shownRef.current });\n holdBase.current = base;\n holdRef.current = direction;\n setHold(direction);\n return tickHold(direction, event);\n },\n [latest, openGesture, resolveBase, shownRef, tickHold],\n );\n\n const activate = useCallback(\n (direction: StepDirection, event: Event) => {\n const { disabled: off, readOnly: ro, bounds: b } = latest.current;\n if (off || ro || holdRef.current !== null) return;\n const n = direction === \"increment\" ? 1 : -1;\n oneStep((v) => stepValue(v, n, b), direction, event);\n },\n [latest, oneStep],\n );\n\n // --- Labels ---------------------------------------------------------------------------------\n\n const [labelCount, setLabelCount] = useState(0);\n const registerLabel = useCallback(() => {\n setLabelCount((count) => count + 1);\n return () => setLabelCount((count) => count - 1);\n }, []);\n\n // --- Residual browser paths: mount reconciliation and form reset (design 4.5, 6.4) ----------\n\n const [mountValue] = useState(value);\n const resetTarget = (): number | null =>\n valueProp !== undefined ? (mountValue ?? null) : (defaultValue ?? null);\n const resetTargetText = hiddenText(resetTarget());\n\n const { onItemMounted } = useNativeGroupReconciliation<number | null>({\n element: hiddenRef as RefObject<FormAssociatedElement | null>,\n readCurrent: () =>\n readVisible(visibleRef.current, shownRef.current, formatter, (text) => {\n draftRef.current = text;\n setDraft(text);\n }),\n readDefault: () => {\n // A reset clears an open draft whatever the target.\n clearDraft();\n return resetTarget();\n },\n base: () => shownRef.current,\n onPlatformChange: (next, event) => {\n openGesture();\n step(next, null, \"platform\", event);\n commit(null, \"platform\", event);\n },\n onResetEvent: () => {\n // react-dom rewrites a controlled text input's `defaultValue` after every update; the\n // visible text's reset target is written right before the reset algorithm reads it.\n const visible = visibleRef.current;\n if (visible !== null) visible.defaultValue = formatter.format(resetTarget());\n },\n });\n\n // --- Development warnings -------------------------------------------------------------------\n\n useNumberFieldDevWarnings({\n value: valueProp,\n defaultValue: defaultValueProp,\n min,\n max,\n bounds,\n stepValid,\n largeStepValid,\n formatter,\n locale,\n });\n\n // An unmount mid-hold leaves nothing behind (the buttons detach their own listeners).\n useEffect(\n () => () => {\n holdRef.current = null;\n },\n [],\n );\n\n // --- Render ---------------------------------------------------------------------------------\n\n const context = useMemo<NumberFieldContextValue>(\n () => ({\n state,\n bounds,\n stepBase,\n pendingSource: pending ? pendingSource : null,\n inputId,\n labelId,\n name,\n form,\n allowsFractions: formatter.allowsFractions || !Number.isInteger(stepSize),\n stepOnWheel,\n resetTargetText,\n fieldInvalid,\n visibleRef,\n hiddenRef,\n typed,\n commitDraft,\n keyDown,\n wheel,\n beginHold,\n tickHold,\n endHold,\n activate,\n syncHidden,\n registerLabel,\n onItemMounted,\n }),\n [\n state,\n bounds,\n stepBase,\n pending,\n pendingSource,\n inputId,\n labelId,\n name,\n form,\n formatter,\n stepSize,\n stepOnWheel,\n resetTargetText,\n fieldInvalid,\n typed,\n commitDraft,\n keyDown,\n wheel,\n beginHold,\n tickHold,\n endHold,\n activate,\n syncHidden,\n registerLabel,\n onItemMounted,\n ],\n );\n\n const labelledBy = mergeTokenLists(labelCount > 0 ? labelId : undefined, fieldContext?.ids.label);\n const libraryProps: Partial<ComponentPropsWithRef<\"div\">> & DataAttributes = {\n role: \"group\",\n ...(labelledBy !== \"\" ? { \"aria-labelledby\": labelledBy } : {}),\n ...(fieldContext !== null ? { \"data-invalid\": dataAttr(fieldInvalid === true) } : {}),\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, NumberFieldState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps,\n });\n\n return <NumberFieldContext value={context}>{element}</NumberFieldContext>;\n}\n\nNumberFieldRoot.displayName = \"NumberFieldRoot\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA4IA,MAAM,aAAa,gBAAgB,gBAAgB,QAAQ;AAC3D,MAAM,eAAe,gBAAgB,gBAAgB,QAAQ;;AAG7D,SAAS,SAAS,OAA6D;CAC7E,IAAI,UAAU,KAAA,KAAa,UAAU,MAAM,OAAO;CAClD,OAAO,OAAO,SAAS,KAAK,IAAI,QAAQ;AAC1C;;AAGA,SAAS,WAAW,OAA8B;CAChD,OAAO,UAAU,OAAO,KAAK,OAAO,KAAK;AAC3C;;;;;;;;;AAUA,SAAS,YACP,SACA,SACA,WACA,YACe;CACf,IAAI,YAAY,MAAM,OAAO;CAC7B,MAAM,UAAU,QAAQ;CACxB,IAAI,YAAY,UAAU,OAAO,OAAO,GAAG,OAAO;CAClD,IAAI,QAAQ,cAAc,kBAAkB,SAAS;EACnD,WAAW,OAAO;EAClB,OAAO;CACT;CACA,MAAM,SAAS,UAAU,MAAM,OAAO;CACtC,IAAI,WAAW,KAAA,KAAa,OAAO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MAAM,YAAY,KAAK;GAClC,OAAO,MAAM,YAAY,KAAK;EAChC;EACA,oBAAoB;GAGlB,MAAM,UAAU,WAAW;GAC3B,IAAI,YAAY,MAAM,QAAQ,eAAe,UAAU,OAAO,YAAY,CAAC;EAC7E;CACF,CAAC;CAID,0BAA0B;EACxB,OAAO;EACP,cAAc;EACd;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAGD,sBACc;EACV,QAAQ,UAAU;CACpB,GACA,CAAC,CACH;CAIA,MAAM,UAAU,eACP;EACL;EACA;EACA;EACA,eAAe,UAAU,gBAAgB;EACzC;EACA;EACA;EACA;EACA,iBAAiB,UAAU,mBAAmB,CAAC,OAAO,UAAU,QAAQ;EACxE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,IACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CAEA,MAAM,aAAa,gBAAgB,aAAa,IAAI,UAAU,KAAA,GAAW,cAAc,IAAI,KAAK;CAChG,MAAM,eAAuE;EAC3E,MAAM;EACN,GAAI,eAAe,KAAK,EAAE,mBAAmB,WAAW,IAAI,CAAC;EAC7D,GAAI,iBAAiB,OAAO,EAAE,gBAAgB,SAAS,iBAAiB,IAAI,EAAE,IAAI,CAAC;EACnF,gBAAgB,SAAS,OAAO;EAChC,iBAAiB,SAAS,QAAQ;CACpC;CAEA,MAAM,UAAU,UAA0D;EACxE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;CACF,CAAC;CAED,OAAO,oBAAC,oBAAD;EAAoB,OAAO;EAAU,UAAA;CAA4B,CAAA;AAC1E;AAEA,gBAAgB,cAAc"}
@@ -0,0 +1,28 @@
1
+ "use client";
2
+ import { useDevWarning } from "../internal/use-dev-warning.mjs";
3
+ import { useEffect, useRef } from "react";
4
+ //#region src/number-field/use-number-field-dev-warnings.ts
5
+ const isDev = process.env.NODE_ENV !== "production";
6
+ function languageOf(tag) {
7
+ return tag.split("-")[0]?.toLowerCase() ?? "";
8
+ }
9
+ /** `NumberField.Root`'s development warnings about its props (design 3.1, 8). */
10
+ function useNumberFieldDevWarnings(options) {
11
+ const { value, defaultValue, min, max, bounds, formatter, locale } = options;
12
+ useDevWarning(value !== void 0 && value !== null && !Number.isFinite(value) || defaultValue !== void 0 && defaultValue !== null && !Number.isFinite(defaultValue), isDev && `NumberField.Root: \`value\` / \`defaultValue\` must be a finite number or \`null\`; got ${String(value ?? defaultValue)}, treated as empty.`);
13
+ useDevWarning(bounds.min !== void 0 && bounds.max !== void 0 && bounds.min > bounds.max, isDev && `NumberField.Root: \`min\` (${String(min)}) is greater than \`max\` (${String(max)}).`);
14
+ useDevWarning(!options.stepValid || !options.largeStepValid, isDev && "NumberField.Root: `step` and `largeStep` must be positive numbers; using the defaults.");
15
+ useDevWarning(formatter.warning !== null, isDev && `NumberField.Root: ${formatter.warning ?? ""}`);
16
+ const warnedLang = useRef(false);
17
+ useEffect(() => {
18
+ if (!isDev || warnedLang.current || locale !== void 0) return;
19
+ const lang = document.documentElement.lang;
20
+ if (lang === "" || languageOf(lang) === languageOf(formatter.locale)) return;
21
+ warnedLang.current = true;
22
+ console.error(`NumberField.Root: the page is \`lang="${lang}"\` but NumberField formats as \`${formatter.locale}\` (the runtime's locale); pass \`locale\`.`);
23
+ }, [locale, formatter]);
24
+ }
25
+ //#endregion
26
+ export { useNumberFieldDevWarnings };
27
+
28
+ //# sourceMappingURL=use-number-field-dev-warnings.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-number-field-dev-warnings.mjs","names":[],"sources":["../../src/number-field/use-number-field-dev-warnings.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport type { StepBounds } from \"./number-field-arithmetic.js\";\nimport type { NumberFormatter } from \"./number-field-format.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nfunction languageOf(tag: string): string {\n return tag.split(\"-\")[0]?.toLowerCase() ?? \"\";\n}\n\n/** The Root's props (as given) and derived values the warnings read. */\nexport interface NumberFieldDevWarningsOptions {\n readonly value: number | null | undefined;\n readonly defaultValue: number | null | undefined;\n readonly min: number | undefined;\n readonly max: number | undefined;\n readonly bounds: StepBounds;\n readonly stepValid: boolean;\n readonly largeStepValid: boolean;\n readonly formatter: NumberFormatter;\n readonly locale: string | readonly string[] | undefined;\n}\n\n/** `NumberField.Root`'s development warnings about its props (design 3.1, 8). */\nexport function useNumberFieldDevWarnings(options: NumberFieldDevWarningsOptions): void {\n const { value, defaultValue, min, max, bounds, formatter, locale } = options;\n useDevWarning(\n (value !== undefined && value !== null && !Number.isFinite(value)) ||\n (defaultValue !== undefined && defaultValue !== null && !Number.isFinite(defaultValue)),\n isDev &&\n \"NumberField.Root: `value` / `defaultValue` must be a finite number or `null`; \" +\n `got ${String(value ?? defaultValue)}, treated as empty.`,\n );\n useDevWarning(\n bounds.min !== undefined && bounds.max !== undefined && bounds.min > bounds.max,\n isDev && `NumberField.Root: \\`min\\` (${String(min)}) is greater than \\`max\\` (${String(max)}).`,\n );\n useDevWarning(\n !options.stepValid || !options.largeStepValid,\n isDev &&\n \"NumberField.Root: `step` and `largeStep` must be positive numbers; using the defaults.\",\n );\n useDevWarning(\n formatter.warning !== null,\n isDev && `NumberField.Root: ${formatter.warning ?? \"\"}`,\n );\n const warnedLang = useRef(false);\n useEffect(() => {\n if (!isDev || warnedLang.current || locale !== undefined) return;\n const lang = document.documentElement.lang;\n if (lang === \"\" || languageOf(lang) === languageOf(formatter.locale)) return;\n warnedLang.current = true;\n console.error(\n `NumberField.Root: the page is \\`lang=\"${lang}\"\\` but NumberField formats as ` +\n `\\`${formatter.locale}\\` (the runtime's locale); pass \\`locale\\`.`,\n );\n }, [locale, formatter]);\n}\n"],"mappings":";;;;AAMA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAEvC,SAAS,WAAW,KAAqB;CACvC,OAAO,IAAI,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,YAAY,KAAK;AAC7C;;AAgBA,SAAgB,0BAA0B,SAA8C;CACtF,MAAM,EAAE,OAAO,cAAc,KAAK,KAAK,QAAQ,WAAW,WAAW;CACrE,cACG,UAAU,KAAA,KAAa,UAAU,QAAQ,CAAC,OAAO,SAAS,KAAK,KAC7D,iBAAiB,KAAA,KAAa,iBAAiB,QAAQ,CAAC,OAAO,SAAS,YAAY,GACvF,SACE,2FACS,OAAO,SAAS,YAAY,EAAE,oBAC3C;CACA,cACE,OAAO,QAAQ,KAAA,KAAa,OAAO,QAAQ,KAAA,KAAa,OAAO,MAAM,OAAO,KAC5E,SAAS,8BAA8B,OAAO,GAAG,EAAE,6BAA6B,OAAO,GAAG,EAAE,GAC9F;CACA,cACE,CAAC,QAAQ,aAAa,CAAC,QAAQ,gBAC/B,SACE,wFACJ;CACA,cACE,UAAU,YAAY,MACtB,SAAS,qBAAqB,UAAU,WAAW,IACrD;CACA,MAAM,aAAa,OAAO,KAAK;CAC/B,gBAAgB;EACd,IAAI,CAAC,SAAS,WAAW,WAAW,WAAW,KAAA,GAAW;EAC1D,MAAM,OAAO,SAAS,gBAAgB;EACtC,IAAI,SAAS,MAAM,WAAW,IAAI,MAAM,WAAW,UAAU,MAAM,GAAG;EACtE,WAAW,UAAU;EACrB,QAAQ,MACN,yCAAyC,KAAK,mCACvC,UAAU,OAAO,4CAC1B;CACF,GAAG,CAAC,QAAQ,SAAS,CAAC;AACxB"}
@@ -0,0 +1,24 @@
1
+ import { RenderProp, StateValue } from "../internal/types.mjs";
2
+ import "./number-field-context.mjs";
3
+ import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
4
+ //#region src/number-field/use-step-button.d.ts
5
+ export interface NumberFieldButtonState {
6
+ /** The Root is pending and the latest step or commit came from this button. */
7
+ readonly pending: boolean;
8
+ /** The prop, the Root's `disabled` or `readOnly`, or the next step would change nothing. */
9
+ readonly disabled: boolean;
10
+ }
11
+ export interface NumberFieldIncrementProps extends Omit<ComponentPropsWithRef<"button">, "type" | "tabIndex" | "disabled" | "onPointerDown" | "onClick" | "onContextMenu" | "aria-controls" | "className" | "style" | "children"> {
12
+ /**
13
+ * Never steps. Native `disabled` on a `<button>` (also at the bound and under `readOnly`); with
14
+ * a link or component `render`, `aria-disabled="true"` instead.
15
+ */
16
+ disabled?: boolean;
17
+ className?: StateValue<string | undefined, NumberFieldButtonState>;
18
+ style?: StateValue<CSSProperties | undefined, NumberFieldButtonState>;
19
+ children?: StateValue<ReactNode, NumberFieldButtonState>;
20
+ render?: RenderProp<ComponentPropsWithRef<"button">, NumberFieldButtonState>;
21
+ }
22
+ export type NumberFieldDecrementProps = NumberFieldIncrementProps;
23
+ //#endregion
24
+ //# sourceMappingURL=use-step-button.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-step-button.d.mts","names":[],"sources":["../../src/number-field/use-step-button.ts"],"mappings":";;;;iBA0JiB;;WAEN;;WAEA;;iBAGM,kCAAkC,KACjD;;;;;EAgBA;EACA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,iCAAiC;;YAG3C,4BAA4B"}
@@ -1,5 +1,16 @@
1
1
  "use client";
2
+ import { dataAttr } from "../internal/data-attr.mjs";
3
+ import { useDevWarning } from "../internal/use-dev-warning.mjs";
4
+ import { disabledButton, rendersButton } from "../internal/render-element.mjs";
5
+ import { useRender } from "../internal/use-render.mjs";
6
+ import { isAtBound } from "./number-field-arithmetic.mjs";
7
+ import { useNumberFieldContext } from "./number-field-context.mjs";
2
8
  import { useEffect, useRef } from "react";
9
+ //#region src/number-field/use-step-button.ts
10
+ const isDev = process.env.NODE_ENV !== "production";
11
+ /** First repeat after the press, then the interval between repeats (Base UI, React Aria). */
12
+ const HOLD_DELAY = 400;
13
+ const HOLD_INTERVAL = 60;
3
14
  /**
4
15
  * The press-and-hold of `NumberField.Increment` / `Decrement` (design 4.3): one step at
5
16
  * `pointerdown`, a repeat after 400 ms then every 60 ms, one commit at the release
@@ -68,7 +79,7 @@ function useStepButton(ctx, direction, disabled) {
68
79
  timer = void 0;
69
80
  if (latest.current.ctx.tickHold(direction, void 0)) tick();
70
81
  else detach();
71
- }, 60);
82
+ }, HOLD_INTERVAL);
72
83
  };
73
84
  if (!ctx.beginHold(direction, native)) {
74
85
  detach();
@@ -86,7 +97,7 @@ function useStepButton(ctx, direction, disabled) {
86
97
  timer = void 0;
87
98
  if (latest.current.ctx.tickHold(direction, void 0)) tick();
88
99
  else detach();
89
- }, 400);
100
+ }, HOLD_DELAY);
90
101
  };
91
102
  const onClick = (event) => {
92
103
  if (disabled) event.preventDefault();
@@ -106,7 +117,50 @@ function useStepButton(ctx, direction, disabled) {
106
117
  onContextMenu
107
118
  };
108
119
  }
120
+ const LABELS = {
121
+ increment: "Increase",
122
+ decrement: "Decrease"
123
+ };
124
+ /** Shared by `NumberField.Increment` and `NumberField.Decrement` (design 3.3, 4.3). */
125
+ function useStepButtonElement(direction, part, props) {
126
+ const { disabled: disabledProp = false, className, style, children, render, ...rest } = props;
127
+ const ctx = useNumberFieldContext(part);
128
+ const { state } = ctx;
129
+ const atBound = isAtBound(ctx.stepBase, direction === "increment" ? 1 : -1, ctx.bounds);
130
+ const disabled = disabledProp || state.disabled || state.readOnly || atBound;
131
+ const pending = ctx.pendingSource === direction;
132
+ const buttonState = {
133
+ pending,
134
+ disabled
135
+ };
136
+ const handlers = useStepButton(ctx, direction, disabled);
137
+ useDevWarning(rest["aria-label"] === "", isDev && `${part}: \`aria-label=""\` leaves the button without a name. Pass the label text instead (the default is "${LABELS[direction]}").`);
138
+ const props$ = {
139
+ ...rest["aria-labelledby"] === void 0 ? { "aria-label": LABELS[direction] } : {},
140
+ ...rest
141
+ };
142
+ return useRender({
143
+ defaultElement: "button",
144
+ render,
145
+ state: buttonState,
146
+ className,
147
+ style,
148
+ children,
149
+ props: props$,
150
+ libraryProps: {
151
+ ...rendersButton(render) ? { type: "button" } : {},
152
+ tabIndex: -1,
153
+ "aria-controls": ctx.inputId,
154
+ ...disabledButton(render, disabled).props,
155
+ onPointerDown: handlers.onPointerDown,
156
+ onClick: handlers.onClick,
157
+ onContextMenu: handlers.onContextMenu,
158
+ "data-pending": dataAttr(pending),
159
+ "data-disabled": dataAttr(disabled)
160
+ }
161
+ });
162
+ }
109
163
  //#endregion
110
- export { useStepButton };
164
+ export { useStepButton, useStepButtonElement };
111
165
 
112
166
  //# sourceMappingURL=use-step-button.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-step-button.mjs","names":[],"sources":["../../src/number-field/use-step-button.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport type { MouseEvent as ReactMouseEvent, PointerEvent as ReactPointerEvent } from \"react\";\nimport type { NumberFieldContextValue, StepDirection } from \"./number-field-context.js\";\n\n/** First repeat after the press, then the interval between repeats (Base UI, React Aria). */\nexport const HOLD_DELAY = 400;\nexport const HOLD_INTERVAL = 60;\n\ninterface ActiveHold {\n readonly pointerId: number;\n readonly detach: () => void;\n}\n\nexport interface StepButtonHandlers {\n readonly onPointerDown: (event: ReactPointerEvent<HTMLElement>) => void;\n readonly onClick: (event: ReactMouseEvent<HTMLElement>) => void;\n readonly onContextMenu: (event: ReactMouseEvent<HTMLElement>) => void;\n}\n\n/**\n * The press-and-hold of `NumberField.Increment` / `Decrement` (design 4.3): one step at\n * `pointerdown`, a repeat after 400 ms then every 60 ms, one commit at the release\n * (`pointerup`, `pointercancel`, `lostpointercapture`, or `blur` on the window). The press is\n * `preventDefault()`ed so focus stays where it is. A `click` with no pointer gesture before it\n * (assistive technology: `detail === 0`) is a one-step gesture.\n */\nexport function useStepButton(\n ctx: NumberFieldContextValue,\n direction: StepDirection,\n disabled: boolean,\n): StepButtonHandlers {\n const active = useRef<ActiveHold | null>(null);\n /** A pointer gesture started on this button; the click that follows it is not an activation. */\n const pointerSeen = useRef(false);\n const latest = useRef({ ctx, disabled });\n useEffect(() => {\n latest.current = { ctx, disabled };\n });\n\n // An unmount mid-hold leaves no timer or listener behind.\n useEffect(\n () => () => {\n active.current?.detach();\n active.current = null;\n },\n [],\n );\n\n const onPointerDown = (event: ReactPointerEvent<HTMLElement>): void => {\n if (event.button !== 0 || !event.isPrimary) return;\n if (disabled) {\n // A focusable disabled render (`aria-disabled`, #83) must not take focus from the input\n // either; native `disabled` focused nothing.\n event.preventDefault();\n return;\n }\n if (active.current !== null) return;\n const element = event.currentTarget;\n const native = event.nativeEvent;\n // No focus move off the input, no touch keyboard, no text selection.\n event.preventDefault();\n pointerSeen.current = true;\n const pointerId = native.pointerId;\n try {\n element.setPointerCapture(pointerId);\n } catch {\n // An inactive pointer id (a synthetic event): the hold still follows the element.\n }\n\n let timer: ReturnType<typeof setTimeout> | undefined;\n const view = element.ownerDocument.defaultView;\n const detach = (): void => {\n if (timer !== undefined) clearTimeout(timer);\n timer = undefined;\n element.removeEventListener(\"pointerup\", onEnd);\n element.removeEventListener(\"pointercancel\", onEnd);\n element.removeEventListener(\"lostpointercapture\", onEnd);\n view?.removeEventListener(\"blur\", onBlur);\n if (active.current?.pointerId === pointerId) active.current = null;\n // A click that follows this release (same task, or a touch tap later) is ignored; an\n // activation without a pointer afterwards is not.\n setTimeout(() => {\n pointerSeen.current = false;\n }, 0);\n };\n function onEnd(endEvent: Event): void {\n if ((endEvent as PointerEvent).pointerId !== pointerId) return;\n detach();\n latest.current.ctx.endHold(direction, endEvent);\n }\n function onBlur(blurEvent: Event): void {\n detach();\n latest.current.ctx.endHold(direction, blurEvent);\n }\n const tick = (): void => {\n timer = setTimeout(() => {\n timer = undefined;\n if (latest.current.ctx.tickHold(direction, undefined)) tick();\n else detach();\n }, HOLD_INTERVAL);\n };\n\n if (!ctx.beginHold(direction, native)) {\n // The first step reached the bound: the hold already committed.\n detach();\n return;\n }\n element.addEventListener(\"pointerup\", onEnd);\n element.addEventListener(\"pointercancel\", onEnd);\n element.addEventListener(\"lostpointercapture\", onEnd);\n view?.addEventListener(\"blur\", onBlur);\n active.current = { pointerId, detach };\n timer = setTimeout(() => {\n timer = undefined;\n if (latest.current.ctx.tickHold(direction, undefined)) tick();\n else detach();\n }, HOLD_DELAY);\n };\n\n const onClick = (event: ReactMouseEvent<HTMLElement>): void => {\n // A disabled link or component render (`aria-disabled`, #83) must not navigate either.\n if (disabled) event.preventDefault();\n if (pointerSeen.current || active.current !== null || event.detail !== 0) {\n pointerSeen.current = false;\n return;\n }\n if (disabled) return;\n ctx.activate(direction, event.nativeEvent);\n };\n\n const onContextMenu = (event: ReactMouseEvent<HTMLElement>): void => {\n // A touch long-press would open the context menu mid-hold.\n if (active.current !== null) event.preventDefault();\n };\n\n return { onPointerDown, onClick, onContextMenu };\n}\n"],"mappings":";;;;;;;;;AA2BA,SAAgB,cACd,KACA,WACA,UACoB;CACpB,MAAM,SAAS,OAA0B,IAAI;;CAE7C,MAAM,cAAc,OAAO,KAAK;CAChC,MAAM,SAAS,OAAO;EAAE;EAAK;CAAS,CAAC;CACvC,gBAAgB;EACd,OAAO,UAAU;GAAE;GAAK;EAAS;CACnC,CAAC;CAGD,sBACc;EACV,OAAO,SAAS,OAAO;EACvB,OAAO,UAAU;CACnB,GACA,CAAC,CACH;CAEA,MAAM,iBAAiB,UAAgD;EACrE,IAAI,MAAM,WAAW,KAAK,CAAC,MAAM,WAAW;EAC5C,IAAI,UAAU;GAGZ,MAAM,eAAe;GACrB;EACF;EACA,IAAI,OAAO,YAAY,MAAM;EAC7B,MAAM,UAAU,MAAM;EACtB,MAAM,SAAS,MAAM;EAErB,MAAM,eAAe;EACrB,YAAY,UAAU;EACtB,MAAM,YAAY,OAAO;EACzB,IAAI;GACF,QAAQ,kBAAkB,SAAS;EACrC,QAAQ,CAER;EAEA,IAAI;EACJ,MAAM,OAAO,QAAQ,cAAc;EACnC,MA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EACd,IAAI,SAAS,WAAW,MAAM,WAAW;CAC3C;CAEA,MAAM,iBAAiB,UAA8C;EAEnE,IAAI,OAAO,YAAY,MAAM,MAAM,eAAe;CACpD;CAEA,OAAO;EAAE;EAAe;EAAS;CAAc;AACjD"}
1
+ {"version":3,"file":"use-step-button.mjs","names":[],"sources":["../../src/number-field/use-step-button.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent as ReactMouseEvent,\n PointerEvent as ReactPointerEvent,\n ReactNode,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { disabledButton, rendersButton, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { isAtBound } from \"./number-field-arithmetic.js\";\nimport { useNumberFieldContext } from \"./number-field-context.js\";\nimport type { NumberFieldContextValue, StepDirection } from \"./number-field-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** First repeat after the press, then the interval between repeats (Base UI, React Aria). */\nconst HOLD_DELAY = 400;\nconst HOLD_INTERVAL = 60;\n\ninterface ActiveHold {\n readonly pointerId: number;\n readonly detach: () => void;\n}\n\nexport interface StepButtonHandlers {\n readonly onPointerDown: (event: ReactPointerEvent<HTMLElement>) => void;\n readonly onClick: (event: ReactMouseEvent<HTMLElement>) => void;\n readonly onContextMenu: (event: ReactMouseEvent<HTMLElement>) => void;\n}\n\n/**\n * The press-and-hold of `NumberField.Increment` / `Decrement` (design 4.3): one step at\n * `pointerdown`, a repeat after 400 ms then every 60 ms, one commit at the release\n * (`pointerup`, `pointercancel`, `lostpointercapture`, or `blur` on the window). The press is\n * `preventDefault()`ed so focus stays where it is. A `click` with no pointer gesture before it\n * (assistive technology: `detail === 0`) is a one-step gesture.\n */\nexport function useStepButton(\n ctx: NumberFieldContextValue,\n direction: StepDirection,\n disabled: boolean,\n): StepButtonHandlers {\n const active = useRef<ActiveHold | null>(null);\n /** A pointer gesture started on this button; the click that follows it is not an activation. */\n const pointerSeen = useRef(false);\n const latest = useRef({ ctx, disabled });\n useEffect(() => {\n latest.current = { ctx, disabled };\n });\n\n // An unmount mid-hold leaves no timer or listener behind.\n useEffect(\n () => () => {\n active.current?.detach();\n active.current = null;\n },\n [],\n );\n\n const onPointerDown = (event: ReactPointerEvent<HTMLElement>): void => {\n if (event.button !== 0 || !event.isPrimary) return;\n if (disabled) {\n // A focusable disabled render (`aria-disabled`) must not take focus from the input\n // either; native `disabled` focused nothing.\n event.preventDefault();\n return;\n }\n if (active.current !== null) return;\n const element = event.currentTarget;\n const native = event.nativeEvent;\n // No focus move off the input, no touch keyboard, no text selection.\n event.preventDefault();\n pointerSeen.current = true;\n const pointerId = native.pointerId;\n try {\n element.setPointerCapture(pointerId);\n } catch {\n // An inactive pointer id (a synthetic event): the hold still follows the element.\n }\n\n let timer: ReturnType<typeof setTimeout> | undefined;\n const view = element.ownerDocument.defaultView;\n const detach = (): void => {\n if (timer !== undefined) clearTimeout(timer);\n timer = undefined;\n element.removeEventListener(\"pointerup\", onEnd);\n element.removeEventListener(\"pointercancel\", onEnd);\n element.removeEventListener(\"lostpointercapture\", onEnd);\n view?.removeEventListener(\"blur\", onBlur);\n if (active.current?.pointerId === pointerId) active.current = null;\n // A click that follows this release (same task, or a touch tap later) is ignored; an\n // activation without a pointer afterwards is not.\n setTimeout(() => {\n pointerSeen.current = false;\n }, 0);\n };\n function onEnd(endEvent: Event): void {\n if ((endEvent as PointerEvent).pointerId !== pointerId) return;\n detach();\n latest.current.ctx.endHold(direction, endEvent);\n }\n function onBlur(blurEvent: Event): void {\n detach();\n latest.current.ctx.endHold(direction, blurEvent);\n }\n const tick = (): void => {\n timer = setTimeout(() => {\n timer = undefined;\n if (latest.current.ctx.tickHold(direction, undefined)) tick();\n else detach();\n }, HOLD_INTERVAL);\n };\n\n if (!ctx.beginHold(direction, native)) {\n // The first step reached the bound: the hold already committed.\n detach();\n return;\n }\n element.addEventListener(\"pointerup\", onEnd);\n element.addEventListener(\"pointercancel\", onEnd);\n element.addEventListener(\"lostpointercapture\", onEnd);\n view?.addEventListener(\"blur\", onBlur);\n active.current = { pointerId, detach };\n timer = setTimeout(() => {\n timer = undefined;\n if (latest.current.ctx.tickHold(direction, undefined)) tick();\n else detach();\n }, HOLD_DELAY);\n };\n\n const onClick = (event: ReactMouseEvent<HTMLElement>): void => {\n // A disabled link or component render (`aria-disabled`) must not navigate either.\n if (disabled) event.preventDefault();\n if (pointerSeen.current || active.current !== null || event.detail !== 0) {\n pointerSeen.current = false;\n return;\n }\n if (disabled) return;\n ctx.activate(direction, event.nativeEvent);\n };\n\n const onContextMenu = (event: ReactMouseEvent<HTMLElement>): void => {\n // A touch long-press would open the context menu mid-hold.\n if (active.current !== null) event.preventDefault();\n };\n\n return { onPointerDown, onClick, onContextMenu };\n}\n\nexport interface NumberFieldButtonState {\n /** The Root is pending and the latest step or commit came from this button. */\n readonly pending: boolean;\n /** The prop, the Root's `disabled` or `readOnly`, or the next step would change nothing. */\n readonly disabled: boolean;\n}\n\nexport interface NumberFieldIncrementProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n | \"type\"\n | \"tabIndex\"\n | \"disabled\"\n | \"onPointerDown\"\n | \"onClick\"\n | \"onContextMenu\"\n | \"aria-controls\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * Never steps. Native `disabled` on a `<button>` (also at the bound and under `readOnly`); with\n * a link or component `render`, `aria-disabled=\"true\"` instead.\n */\n disabled?: boolean;\n className?: StateValue<string | undefined, NumberFieldButtonState>;\n style?: StateValue<CSSProperties | undefined, NumberFieldButtonState>;\n children?: StateValue<ReactNode, NumberFieldButtonState>;\n render?: RenderProp<ComponentPropsWithRef<\"button\">, NumberFieldButtonState>;\n}\n\nexport type NumberFieldDecrementProps = NumberFieldIncrementProps;\n\nconst LABELS: Record<StepDirection, string> = { increment: \"Increase\", decrement: \"Decrease\" };\n\n/** Shared by `NumberField.Increment` and `NumberField.Decrement` (design 3.3, 4.3). */\nexport function useStepButtonElement(\n direction: StepDirection,\n part: string,\n props: NumberFieldIncrementProps,\n): ReactNode {\n const { disabled: disabledProp = false, className, style, children, render, ...rest } = props;\n const ctx = useNumberFieldContext(part);\n const { state } = ctx;\n const atBound = isAtBound(ctx.stepBase, direction === \"increment\" ? 1 : -1, ctx.bounds);\n const disabled = disabledProp || state.disabled || state.readOnly || atBound;\n const pending = ctx.pendingSource === direction;\n const buttonState: NumberFieldButtonState = { pending, disabled };\n const handlers = useStepButton(ctx, direction, disabled);\n\n useDevWarning(\n rest[\"aria-label\"] === \"\",\n isDev &&\n `${part}: \\`aria-label=\"\"\\` leaves the button without a name. Pass the label text instead ` +\n `(the default is \"${LABELS[direction]}\").`,\n );\n\n // The built-in name is a default the consumer's `aria-label` or `aria-labelledby` replaces.\n const props$ = {\n ...(rest[\"aria-labelledby\"] === undefined ? { \"aria-label\": LABELS[direction] } : {}),\n ...rest,\n };\n\n return useRender<ComponentPropsWithRef<\"button\">, NumberFieldButtonState>({\n defaultElement: \"button\",\n render,\n state: buttonState,\n className,\n style,\n children,\n props: props$,\n libraryProps: {\n ...(rendersButton(render) ? { type: \"button\" as const } : {}),\n tabIndex: -1,\n \"aria-controls\": ctx.inputId,\n // A link or component render: native `disabled` would mean nothing on a link; the press and\n // click handlers refuse, so `aria-disabled`. The at-bound case follows the same branch.\n ...disabledButton(render, disabled).props,\n onPointerDown: handlers.onPointerDown,\n onClick: handlers.onClick,\n onContextMenu: handlers.onContextMenu,\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n } as Partial<ComponentPropsWithRef<\"button\">> & DataAttributes,\n });\n}\n"],"mappings":";;;;;;;;;AAkBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAGvC,MAAM,aAAa;AACnB,MAAM,gBAAgB;;;;;;;;AAoBtB,SAAgB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,KAAK,WAAW,QAAQ;CAEvD,cACE,KAAK,kBAAkB,IACvB,SACE,GAAG,KAAK,qGACc,OAAO,WAAW,IAC5C;CAGA,MAAM,SAAS;EACb,GAAI,KAAK,uBAAuB,KAAA,IAAY,EAAE,cAAc,OAAO,WAAW,IAAI,CAAC;EACnF,GAAG;CACL;CAEA,OAAO,UAAmE;EACxE,gBAAgB;EAChB;EACA,OAAO;EACP;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAI,cAAc,MAAM,IAAI,EAAE,MAAM,SAAkB,IAAI,CAAC;GAC3D,UAAU;GACV,iBAAiB,IAAI;GAGrB,GAAG,eAAe,QAAQ,QAAQ,CAAC,CAAC;GACpC,eAAe,SAAS;GACxB,SAAS,SAAS;GAClB,eAAe,SAAS;GACxB,gBAAgB,SAAS,OAAO;GAChC,iBAAiB,SAAS,QAAQ;EACpC;CACF,CAAC;AACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"popover-close.d.mts","names":[],"sources":["../../src/popover/popover-close.tsx"],"mappings":";;;iBAWiB;;WAEN;WACA;;iBAGM,0BAA0B,KACzC;;;;;;;;;EAWA,SAAS,QAAQ,SAAS;;;;;;EAM1B;EACA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;wBAyBvC,eACd,QACA,UACA,WACA,OACA,UACA,WACG,QACF,oBAAiB;yBARJ"}
1
+ {"version":3,"file":"popover-close.d.mts","names":[],"sources":["../../src/popover/popover-close.tsx"],"mappings":";;;iBAQiB;;WAEN;WACA;;iBAGM,0BAA0B,KACzC;;;;;;;;;EAWA,SAAS,QAAQ,SAAS;;;;;;EAM1B;EACA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;wBAevC,eACd,QACA,UACA,WACA,OACA,UACA,WACG,QACF,oBAAiB;yBARJ"}
@@ -1,20 +1,9 @@
1
1
  "use client";
2
2
  import { createActionDetails } from "../internal/action-details.mjs";
3
- import { dataAttr } from "../internal/data-attr.mjs";
4
- import { useActionTrigger } from "../internal/use-action-trigger.mjs";
5
- import { isHostButton, rendersButton } from "../internal/render-element.mjs";
6
- import { useRender } from "../internal/use-render.mjs";
3
+ import { isPopoverOpen } from "../internal/popover-open.mjs";
4
+ import { useOverlayClose } from "../internal/use-overlay-close.mjs";
7
5
  import { usePopoverContext } from "./popover-context.mjs";
8
- import { useCallback } from "react";
9
6
  //#region src/popover/popover-close.tsx
10
- const isDev = process.env.NODE_ENV !== "production";
11
- function isPopoverOpen(element) {
12
- try {
13
- return element.matches(":popover-open");
14
- } catch {
15
- return false;
16
- }
17
- }
18
7
  /**
19
8
  * A close button: `<button type="button" commandfor command="hide-popover">`. In JS-free mode
20
9
  * without `action` the browser hides the popover. In library mode the click is always cancelled
@@ -29,64 +18,36 @@ function isPopoverOpen(element) {
29
18
  */
30
19
  function PopoverClose({ action, disabled = false, className, style, children, render, ...rest }) {
31
20
  const ctx = usePopoverContext("Popover.Close");
32
- const { ids, popupRef, recordCloseIntent, openGeneration } = ctx;
33
- const { pending, run } = useActionTrigger({ openGeneration });
21
+ const { popupRef, recordCloseIntent } = ctx;
34
22
  const isLibrary = ctx.mode === "library";
35
- const installClick = isLibrary || action !== void 0;
36
- const focusable = installClick && !isHostButton(render);
37
- const noInvoker = focusable && disabled;
38
- const state = {
39
- pending,
40
- disabled
41
- };
42
- const devRef = useCallback((element) => {
43
- if (isDev && !installClick && element.tagName !== "BUTTON") console.error(`Popover.Close: rendered a <${element.tagName.toLowerCase()}> in JS-free mode without \`action\`. Only a <button> runs \`command="hide-popover"\`; this element will not close the popover.`);
44
- return () => {};
45
- }, [installClick]);
46
- const close = (event) => {
47
- if (isLibrary) {
48
- ctx.requestClose(event, "activate");
49
- return;
50
- }
51
- const popup = popupRef.current;
52
- if (popup === null || !popup.isConnected || !isPopoverOpen(popup)) return;
53
- recordCloseIntent({
54
- reason: "activate",
55
- event
56
- });
57
- popup.hidePopover();
58
- };
59
- const onClick = (event) => {
60
- event.preventDefault();
61
- if (disabled) return;
62
- const native = event.nativeEvent;
63
- if (action === void 0) {
64
- close(native);
65
- return;
66
- }
67
- const details = createActionDetails(native, {});
68
- run(() => action(details), () => close(native));
69
- };
70
- const libraryProps = {
71
- ...rendersButton(render) && { type: "button" },
72
- disabled: focusable ? void 0 : disabled,
73
- commandfor: noInvoker ? void 0 : ids.popup,
74
- command: noInvoker ? void 0 : "hide-popover",
75
- ...installClick && { onClick },
76
- "aria-disabled": pending || focusable && disabled ? true : void 0,
77
- "data-pending": dataAttr(pending),
78
- "data-disabled": dataAttr(disabled)
79
- };
80
- return useRender({
81
- defaultElement: "button",
82
- render,
83
- state,
23
+ return useOverlayClose({
24
+ part: "Popover.Close",
25
+ noun: "popover",
26
+ isLibrary,
27
+ popupId: ctx.ids.popup,
28
+ command: "hide-popover",
29
+ openGeneration: ctx.openGeneration,
30
+ action,
31
+ details: (event) => createActionDetails(event, {}),
32
+ close: (event) => {
33
+ if (isLibrary) {
34
+ ctx.requestClose(event, "activate");
35
+ return;
36
+ }
37
+ const popup = popupRef.current;
38
+ if (popup === null || !popup.isConnected || !isPopoverOpen(popup)) return;
39
+ recordCloseIntent({
40
+ reason: "activate",
41
+ event
42
+ });
43
+ popup.hidePopover();
44
+ },
45
+ disabled,
84
46
  className,
85
47
  style,
86
48
  children,
87
- props: rest,
88
- libraryProps,
89
- ref: devRef
49
+ render,
50
+ rest
90
51
  });
91
52
  }
92
53
  PopoverClose.displayName = "PopoverClose";
@@ -1 +1 @@
1
- {"version":3,"file":"popover-close.mjs","names":[],"sources":["../../src/popover/popover-close.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, MouseEvent, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { Action, ActionDetails, RenderProp, StateValue } from \"../internal/types.js\";\nimport { useActionTrigger } from \"../internal/use-action-trigger.js\";\nimport { isHostButton, rendersButton, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { usePopoverContext } from \"./popover-context.js\";\n\nexport interface PopoverCloseState {\n /** The `action` is in flight. */\n readonly pending: boolean;\n readonly disabled: boolean;\n}\n\nexport interface PopoverCloseProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Runs inside this part's own transition (`data-pending` on the button), then closes the\n * popover: in library mode through the Root (`openChangeAction(false)` awaited, view\n * transition if set), in JS-free mode with `hidePopover()`. A rejection reaches the nearest\n * Error Boundary above the Close part and leaves the popover open. If the popover was\n * dismissed and opened again while the action ran, the close is dropped. Without `action` in JS-free\n * mode the button is a native `command=\"hide-popover\"` invoker.\n */\n action?: Action<[details: ActionDetails]>;\n /**\n * Never closes. Native `disabled` on a `<button>`; owned, so a `render` element cannot\n * re-enable it. With a link or component `render` whose click this part handles (library mode,\n * or with `action`), `aria-disabled=\"true\"` instead: the element stays focusable.\n */\n disabled?: boolean;\n className?: StateValue<string | undefined, PopoverCloseState>;\n style?: StateValue<CSSProperties | undefined, PopoverCloseState>;\n children?: StateValue<ReactNode, PopoverCloseState>;\n render?: RenderProp<ComponentPropsWithRef<\"button\">, PopoverCloseState>;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nfunction isPopoverOpen(element: Element): boolean {\n try {\n return element.matches(\":popover-open\");\n } catch {\n return false;\n }\n}\n\n/**\n * A close button: `<button type=\"button\" commandfor command=\"hide-popover\">`. In JS-free mode\n * without `action` the browser hides the popover. In library mode the click is always cancelled\n * and the close goes through the Root (`openChangeAction(false)` awaited, `hidePopover()` in the\n * commit). With `action` the action runs first in this part's own transition (`data-pending` on\n * the button, with `aria-disabled`; a second click meanwhile is ignored); a rejection leaves the\n * popover open.\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>` only), `disabled`, `commandfor`,\n * `command`, `onClick` (library mode, or with `action`), `aria-disabled`, `data-pending`,\n * `data-disabled`.\n */\nexport function PopoverClose({\n action,\n disabled = false,\n className,\n style,\n children,\n render,\n ...rest\n}: PopoverCloseProps) {\n const ctx = usePopoverContext(\"Popover.Close\");\n const { ids, popupRef, recordCloseIntent, openGeneration } = ctx;\n const { pending, run } = useActionTrigger({ openGeneration });\n const isLibrary = ctx.mode === \"library\";\n const hasAction = action !== undefined;\n const installClick = isLibrary || hasAction;\n // A link or component render whose click this part handles: `aria-disabled`, enforced by the\n // handler (#83). JS-free mode without `action` is the browser's `hide-popover` command,\n // which only native `disabled` stops.\n const focusable = installClick && !isHostButton(render);\n // Disabled in the `aria-disabled` branch: no `commandfor` / `command` either. Without native\n // `disabled` the element would still be a live invoker before hydration (a component render\n // spreading onto a real <button>), and the command would run (wave 9 review M1).\n const noInvoker = focusable && disabled;\n\n const state: PopoverCloseState = { pending, disabled };\n\n const devRef = useCallback(\n (element: HTMLElement) => {\n if (isDev && !installClick && element.tagName !== \"BUTTON\") {\n console.error(\n `Popover.Close: rendered a <${element.tagName.toLowerCase()}> in JS-free mode without ` +\n '`action`. Only a <button> runs `command=\"hide-popover\"`; this element will not ' +\n \"close the popover.\",\n );\n }\n // A cleanup, so the merged ref never calls back with `null`.\n return () => {};\n },\n [installClick],\n );\n\n const close = (event: Event): void => {\n if (isLibrary) {\n // A library-owned close (design 2.3): awaited, then hidden in the commit.\n ctx.requestClose(event, \"activate\");\n return;\n }\n // JS-free mode with `action`: a browser-owned close; there is no Root state to notify.\n const popup = popupRef.current;\n if (popup === null || !popup.isConnected || !isPopoverOpen(popup)) return;\n recordCloseIntent({ reason: \"activate\", event });\n popup.hidePopover();\n };\n\n const onClick = (event: MouseEvent<HTMLElement>) => {\n // Cancelling the click cancels the command.\n event.preventDefault();\n if (disabled) return;\n const native = event.nativeEvent;\n if (action === undefined) {\n close(native);\n return;\n }\n const details = createActionDetails(native, {});\n // A second activation while this Close's own run is in flight starts nothing (the hook's\n // guard; the click is already cancelled above, #81). A close whose open was superseded by a\n // newer one (dismissed and re-opened meanwhile) is dropped by the hook.\n run(\n () => action(details),\n () => close(native),\n );\n };\n\n const libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes = {\n ...(rendersButton(render) && { type: \"button\" as const }),\n // Owned: a render element must not re-enable a disabled Close. Absent in the focusable branch.\n disabled: focusable ? undefined : disabled,\n commandfor: noInvoker ? undefined : ids.popup,\n command: noInvoker ? undefined : \"hide-popover\",\n ...(installClick && { onClick }),\n // Exactly while `data-pending` (#81): a Close that will not act is unavailable to AT. Owned,\n // so an idle Close removes a render element's own `aria-disabled`.\n \"aria-disabled\": pending || (focusable && disabled) ? true : undefined,\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"button\">, PopoverCloseState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps,\n ref: devRef,\n });\n}\n\nPopoverClose.displayName = \"PopoverClose\";\n"],"mappings":";;;;;;;;;AA0CA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAEvC,SAAS,cAAc,SAA2B;CAChD,IAAI;EACF,OAAO,QAAQ,QAAQ,eAAe;CACxC,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;;;;;;;AAcA,SAAgB,aAAa,EAC3B,QACA,WAAW,OACX,WACA,OACA,UACA,QACA,GAAG,QACiB;CACpB,MAAM,MAAM,kBAAkB,eAAe;CAC7C,MAAM,EAAE,KAAK,UAAU,mBAAmB,mBAAmB;CAC7D,MAAM,EAAE,SAAS,QAAQ,iBAAiB,EAAE,eAAe,CAAC;CAC5D,MAAM,YAAY,IAAI,SAAS;CAE/B,MAAM,eAAe,aADH,WAAW,KAAA;CAK7B,MAAM,YAAY,gBAAgB,CAAC,aAAa,MAAM;CAItD,MAAM,YAAY,aAAa;CAE/B,MAAM,QAA2B;EAAE;EAAS;CAAS;CAErD,MAAM,SAAS,aACZ,YAAyB;EACxB,IAAI,SAAS,CAAC,gBAAgB,QAAQ,YAAY,UAChD,QAAQ,MACN,8BAA8B,QAAQ,QAAQ,YAAY,EAAE,gIAG9D;EAGF,aAAa,CAAC;CAChB,GACA,CAAC,YAAY,CACf;CAEA,MAAM,SAAS,UAAuB;EACpC,IAAI,WAAW;GAEb,IAAI,aAAa,OAAO,UAAU;GAClC;EACF;EAEA,MAAM,QAAQ,SAAS;EACvB,IAAI,UAAU,QAAQ,CAAC,MAAM,eAAe,CAAC,cAAc,KAAK,GAAG;EACnE,kBAAkB;GAAE,QAAQ;GAAY;EAAM,CAAC;EAC/C,MAAM,YAAY;CACpB;CAEA,MAAM,WAAW,UAAmC;EAElD,MAAM,eAAe;EACrB,IAAI,UAAU;EACd,MAAM,SAAS,MAAM;EACrB,IAAI,WAAW,KAAA,GAAW;GACxB,MAAM,MAAM;GACZ;EACF;EACA,MAAM,UAAU,oBAAoB,QAAQ,CAAC,CAAC;EAI9C,UACQ,OAAO,OAAO,SACd,MAAM,MAAM,CACpB;CACF;CAEA,MAAM,eAAiE;EACrE,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;EAEvD,UAAU,YAAY,KAAA,IAAY;EAClC,YAAY,YAAY,KAAA,IAAY,IAAI;EACxC,SAAS,YAAY,KAAA,IAAY;EACjC,GAAI,gBAAgB,EAAE,QAAQ;EAG9B,iBAAiB,WAAY,aAAa,WAAY,OAAO,KAAA;EAC7D,gBAAgB,SAAS,OAAO;EAChC,iBAAiB,SAAS,QAAQ;CACpC;CAEA,OAAO,UAA8D;EACnE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;EACA,KAAK;CACP,CAAC;AACH;AAEA,aAAa,cAAc"}
1
+ {"version":3,"file":"popover-close.mjs","names":[],"sources":["../../src/popover/popover-close.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { createActionDetails } from \"../internal/action-details.js\";\nimport { isPopoverOpen } from \"../internal/popover-open.js\";\nimport type { Action, ActionDetails, RenderProp, StateValue } from \"../internal/types.js\";\nimport { useOverlayClose } from \"../internal/use-overlay-close.js\";\nimport { usePopoverContext } from \"./popover-context.js\";\n\nexport interface PopoverCloseState {\n /** The `action` is in flight. */\n readonly pending: boolean;\n readonly disabled: boolean;\n}\n\nexport interface PopoverCloseProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Runs inside this part's own transition (`data-pending` on the button), then closes the\n * popover: in library mode through the Root (`openChangeAction(false)` awaited, view\n * transition if set), in JS-free mode with `hidePopover()`. A rejection reaches the nearest\n * Error Boundary above the Close part and leaves the popover open. If the popover was\n * dismissed and opened again while the action ran, the close is dropped. Without `action` in JS-free\n * mode the button is a native `command=\"hide-popover\"` invoker.\n */\n action?: Action<[details: ActionDetails]>;\n /**\n * Never closes. Native `disabled` on a `<button>`; owned, so a `render` element cannot\n * re-enable it. With a link or component `render` whose click this part handles (library mode,\n * or with `action`), `aria-disabled=\"true\"` instead: the element stays focusable.\n */\n disabled?: boolean;\n className?: StateValue<string | undefined, PopoverCloseState>;\n style?: StateValue<CSSProperties | undefined, PopoverCloseState>;\n children?: StateValue<ReactNode, PopoverCloseState>;\n render?: RenderProp<ComponentPropsWithRef<\"button\">, PopoverCloseState>;\n}\n\n/**\n * A close button: `<button type=\"button\" commandfor command=\"hide-popover\">`. In JS-free mode\n * without `action` the browser hides the popover. In library mode the click is always cancelled\n * and the close goes through the Root (`openChangeAction(false)` awaited, `hidePopover()` in the\n * commit). With `action` the action runs first in this part's own transition (`data-pending` on\n * the button, with `aria-disabled`; a second click meanwhile is ignored); a rejection leaves the\n * popover open.\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>` only), `disabled`, `commandfor`,\n * `command`, `onClick` (library mode, or with `action`), `aria-disabled`, `data-pending`,\n * `data-disabled`.\n */\nexport function PopoverClose({\n action,\n disabled = false,\n className,\n style,\n children,\n render,\n ...rest\n}: PopoverCloseProps) {\n const ctx = usePopoverContext(\"Popover.Close\");\n const { popupRef, recordCloseIntent } = ctx;\n const isLibrary = ctx.mode === \"library\";\n return useOverlayClose({\n part: \"Popover.Close\",\n noun: \"popover\",\n isLibrary,\n popupId: ctx.ids.popup,\n command: \"hide-popover\",\n openGeneration: ctx.openGeneration,\n action,\n details: (event) => createActionDetails(event, {}),\n close: (event) => {\n if (isLibrary) {\n // A library-owned close (design 2.3): awaited, then hidden in the commit.\n ctx.requestClose(event, \"activate\");\n return;\n }\n // JS-free mode with `action`: a browser-owned close; there is no Root state to notify.\n const popup = popupRef.current;\n if (popup === null || !popup.isConnected || !isPopoverOpen(popup)) return;\n recordCloseIntent({ reason: \"activate\", event });\n popup.hidePopover();\n },\n disabled,\n className,\n style,\n children,\n render,\n rest,\n });\n}\n\nPopoverClose.displayName = \"PopoverClose\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmDA,SAAgB,aAAa,EAC3B,QACA,WAAW,OACX,WACA,OACA,UACA,QACA,GAAG,QACiB;CACpB,MAAM,MAAM,kBAAkB,eAAe;CAC7C,MAAM,EAAE,UAAU,sBAAsB;CACxC,MAAM,YAAY,IAAI,SAAS;CAC/B,OAAO,gBAAgB;EACrB,MAAM;EACN,MAAM;EACN;EACA,SAAS,IAAI,IAAI;EACjB,SAAS;EACT,gBAAgB,IAAI;EACpB;EACA,UAAU,UAAU,oBAAoB,OAAO,CAAC,CAAC;EACjD,QAAQ,UAAU;GAChB,IAAI,WAAW;IAEb,IAAI,aAAa,OAAO,UAAU;IAClC;GACF;GAEA,MAAM,QAAQ,SAAS;GACvB,IAAI,UAAU,QAAQ,CAAC,MAAM,eAAe,CAAC,cAAc,KAAK,GAAG;GACnE,kBAAkB;IAAE,QAAQ;IAAY;GAAM,CAAC;GAC/C,MAAM,YAAY;EACpB;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;AACH;AAEA,aAAa,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"popover-context.mjs","names":[],"sources":["../../src/popover/popover-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { PopoverRootValue } from \"../internal/use-popover-root.js\";\nimport type { PopoverPopupState } from \"./popover-popup.js\";\n\nexport type PopoverContextValue = PopoverRootValue;\n\nexport const PopoverContext = createContext<PopoverContextValue | null>(null);\n\nexport function usePopoverContext(part: string): PopoverContextValue {\n const context = use(PopoverContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a Popover.Root.`);\n }\n return context;\n}\n\n/** The Popup's state, for Title and Description rendered inside it. */\nexport const PopoverPopupContext = createContext<PopoverPopupState | null>(null);\n\n/**\n * The state Title and Description receive: the enclosing Popup's, or (outside a Popup, which\n * `aria-labelledby` allows) the Root's committed open state with the default placement.\n */\nexport function usePopoverPopupState(ctx: PopoverContextValue): PopoverPopupState {\n return use(PopoverPopupContext) ?? { open: ctx.committed, side: \"bottom\", align: \"center\" };\n}\n"],"mappings":";;;AAOA,MAAa,iBAAiB,cAA0C,IAAI;AAE5E,SAAgB,kBAAkB,MAAmC;CACnE,MAAM,UAAU,IAAI,cAAc;CAClC,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,GAAG,KAAK,yCAAyC;CAEnE,OAAO;AACT;;AAGA,MAAa,sBAAsB,cAAwC,IAAI;;;;;AAM/E,SAAgB,qBAAqB,KAA6C;CAChF,OAAO,IAAI,mBAAmB,KAAK;EAAE,MAAM,IAAI;EAAW,MAAM;EAAU,OAAO;CAAS;AAC5F"}
1
+ {"version":3,"file":"popover-context.mjs","names":[],"sources":["../../src/popover/popover-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { PopoverRootValue } from \"../internal/use-overlay-root.js\";\nimport type { PopoverPopupState } from \"./popover-popup.js\";\n\nexport const PopoverContext = createContext<PopoverRootValue | null>(null);\n\nexport function usePopoverContext(part: string): PopoverRootValue {\n const context = use(PopoverContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a Popover.Root.`);\n }\n return context;\n}\n\n/** The Popup's state, for Title and Description rendered inside it. */\nexport const PopoverPopupContext = createContext<PopoverPopupState | null>(null);\n\n/**\n * The state Title and Description receive: the enclosing Popup's, or (outside a Popup, which\n * `aria-labelledby` allows) the Root's committed open state with the default placement.\n */\nexport function usePopoverPopupState(ctx: PopoverRootValue): PopoverPopupState {\n return use(PopoverPopupContext) ?? { open: ctx.committed, side: \"bottom\", align: \"center\" };\n}\n"],"mappings":";;;AAKA,MAAa,iBAAiB,cAAuC,IAAI;AAEzE,SAAgB,kBAAkB,MAAgC;CAChE,MAAM,UAAU,IAAI,cAAc;CAClC,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,GAAG,KAAK,yCAAyC;CAEnE,OAAO;AACT;;AAGA,MAAa,sBAAsB,cAAwC,IAAI;;;;;AAM/E,SAAgB,qBAAqB,KAA0C;CAC7E,OAAO,IAAI,mBAAmB,KAAK;EAAE,MAAM,IAAI;EAAW,MAAM;EAAU,OAAO;CAAS;AAC5F"}
@@ -2,11 +2,14 @@ import { RenderProp, StateValue } from "../internal/types.mjs";
2
2
  import { AnchorAlign, AnchorSide } from "../internal/anchor-position.mjs";
3
3
  import { CSSProperties, ComponentPropsWithRef, ReactNode, RefObject, ViewTransitionClass } from "react";
4
4
  //#region src/popover/popover-popup.d.ts
5
- /** `inline-start` / `inline-end` follow the popup's `direction` (wave 11; conventions 13.1). */
5
+ /** `inline-start` / `inline-end` follow the popup's `direction` (conventions 13.1). */
6
6
  export type PopoverSide = AnchorSide;
7
7
  export type PopoverAlign = AnchorAlign;
8
8
  export interface PopoverPopupState {
9
- /** Committed open state (library mode); `false` in JS-free mode. Read `:popover-open` for the DOM truth. */
9
+ /**
10
+ * Committed open state (library mode); `false` in JS-free mode. Read `:popover-open` for the
11
+ * DOM truth.
12
+ */
10
13
  readonly open: boolean;
11
14
  /**
12
15
  * While shown: the physical side the browser placed the popup on (after any fallback flip;
@@ -58,10 +61,10 @@ export interface PopoverPopupProps extends Omit<ComponentPropsWithRef<"dialog">,
58
61
  * click outside) are the browser's and animate with CSS only. Ignored (dev warning) in JS-free
59
62
  * mode.
60
63
  *
61
- * Static: without `transition` the part renders no `<ViewTransition>`; changing it between
62
- * `undefined` and a value remounts the element. A Root inserted by a transition with
63
- * `transition` set on its Popup pays the page cross-fade (issue #35); a plain open does not,
64
- * because the children mount under the already-mounted popover element.
64
+ * Static: setting or unsetting it remounts the element. Any value, `"none"` included, makes a
65
+ * mount or `<Activity>` reveal inside a transition start a document view transition (a ~250 ms
66
+ * page cross-fade that the next transition waits for).
67
+ * A plain open starts none: the children mount under the already-mounted popover element.
65
68
  */
66
69
  transition?: ViewTransitionClass;
67
70
  className?: StateValue<string | undefined, PopoverPopupState>;
@@ -1 +1 @@
1
- {"version":3,"file":"popover-popup.d.mts","names":[],"sources":["../../src/popover/popover-popup.tsx"],"mappings":";;;;;YAuBY,cAAc;YACd,eAAe;iBAEV;;WAEN;;;;;WAKA,MAAM;;WAEN,OAAO;;iBAGD,0BAA0B,KACzC;;;;;;;EAiBA,OAAO;;;;;;EAMP,QAAQ;;;;;;;;;;;EAWR;;;;;;;;;;EAUA,eAAe,UAAU;;;;;;;;;;;;;EAazB,aAAa;EACb,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;;;;;;wBAqBvC,eACd,MAAM,UACN,OAAO,WACP,aACA,cACA,YACA,WACA,OACA,UACA,WACG,QACF,oBAAiB;yBAXJ"}
1
+ {"version":3,"file":"popover-popup.d.mts","names":[],"sources":["../../src/popover/popover-popup.tsx"],"mappings":";;;;;YAoBY,cAAc;YACd,eAAe;iBAEV;;;;;WAKN;;;;;WAKA,MAAM;;WAEN,OAAO;;iBAGD,0BAA0B,KACzC;;;;;;;EAiBA,OAAO;;;;;;EAMP,QAAQ;;;;;;;;;;;EAWR;;;;;;;;;;EAUA,eAAe,UAAU;;;;;;;;;;;;;EAazB,aAAa;EACb,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;;;;;;wBAqBvC,eACd,MAAM,UACN,OAAO,WACP,aACA,cACA,YACA,WACA,OACA,UACA,WACG,QACF,oBAAiB;yBAXJ"}