@kumix/ui 0.3.6 → 0.3.8

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 (305) hide show
  1. package/README.md +25 -24
  2. package/dist/cascader-types-BnH6wYD-.d.ts +183 -0
  3. package/dist/cascader-types-BnH6wYD-.d.ts.map +1 -0
  4. package/dist/components/agents/ai-sidebar.d.ts +17 -1
  5. package/dist/components/agents/ai-sidebar.d.ts.map +1 -1
  6. package/dist/components/agents/ai-sidebar.js +90 -14
  7. package/dist/components/agents/ai-sidebar.js.map +1 -1
  8. package/dist/components/agents/chat-app.d.ts +10 -5
  9. package/dist/components/agents/chat-app.d.ts.map +1 -1
  10. package/dist/components/agents/chat-app.js +54 -5
  11. package/dist/components/agents/chat-app.js.map +1 -1
  12. package/dist/components/agents/citations.d.ts.map +1 -1
  13. package/dist/components/agents/citations.js +5 -6
  14. package/dist/components/agents/citations.js.map +1 -1
  15. package/dist/components/agents/tool-approval.d.ts.map +1 -1
  16. package/dist/components/agents/tool-approval.js +1 -1
  17. package/dist/components/agents/tool-approval.js.map +1 -1
  18. package/dist/components/motion/action-swap.d.ts.map +1 -1
  19. package/dist/components/motion/action-swap.js +2 -2
  20. package/dist/components/motion/action-swap.js.map +1 -1
  21. package/dist/components/motion/animated-sidebar.d.ts.map +1 -1
  22. package/dist/components/motion/animated-sidebar.js +13 -3
  23. package/dist/components/motion/animated-sidebar.js.map +1 -1
  24. package/dist/components/motion/attachment-upload.d.ts.map +1 -1
  25. package/dist/components/motion/attachment-upload.js +9 -5
  26. package/dist/components/motion/attachment-upload.js.map +1 -1
  27. package/dist/components/motion/availability-scheduler/copy-menu.js +1 -1
  28. package/dist/components/motion/availability-scheduler/day-row.d.ts +5 -2
  29. package/dist/components/motion/availability-scheduler/day-row.d.ts.map +1 -1
  30. package/dist/components/motion/availability-scheduler/day-row.js +18 -8
  31. package/dist/components/motion/availability-scheduler/day-row.js.map +1 -1
  32. package/dist/components/motion/availability-scheduler/index.d.ts.map +1 -1
  33. package/dist/components/motion/availability-scheduler/index.js +27 -5
  34. package/dist/components/motion/availability-scheduler/index.js.map +1 -1
  35. package/dist/components/motion/availability-scheduler/time-select.d.ts +3 -1
  36. package/dist/components/motion/availability-scheduler/time-select.d.ts.map +1 -1
  37. package/dist/components/motion/availability-scheduler/time-select.js +3 -1
  38. package/dist/components/motion/availability-scheduler/time-select.js.map +1 -1
  39. package/dist/components/motion/bottom-sheet.d.ts.map +1 -1
  40. package/dist/components/motion/bottom-sheet.js +78 -74
  41. package/dist/components/motion/bottom-sheet.js.map +1 -1
  42. package/dist/components/motion/center-morph-modal.d.ts.map +1 -1
  43. package/dist/components/motion/center-morph-modal.js +82 -88
  44. package/dist/components/motion/center-morph-modal.js.map +1 -1
  45. package/dist/components/motion/command-palette.d.ts.map +1 -1
  46. package/dist/components/motion/command-palette.js +51 -27
  47. package/dist/components/motion/command-palette.js.map +1 -1
  48. package/dist/components/motion/context-menu.d.ts.map +1 -1
  49. package/dist/components/motion/context-menu.js +16 -6
  50. package/dist/components/motion/context-menu.js.map +1 -1
  51. package/dist/components/motion/cylinder-carousel.d.ts.map +1 -1
  52. package/dist/components/motion/cylinder-carousel.js +4 -3
  53. package/dist/components/motion/cylinder-carousel.js.map +1 -1
  54. package/dist/components/motion/drawer.d.ts.map +1 -1
  55. package/dist/components/motion/drawer.js +30 -30
  56. package/dist/components/motion/drawer.js.map +1 -1
  57. package/dist/components/motion/expandable-action-bar.d.ts +6 -0
  58. package/dist/components/motion/expandable-action-bar.d.ts.map +1 -1
  59. package/dist/components/motion/expandable-action-bar.js +38 -9
  60. package/dist/components/motion/expandable-action-bar.js.map +1 -1
  61. package/dist/components/motion/hold-action-button.d.ts +1 -1
  62. package/dist/components/motion/hold-action-button.d.ts.map +1 -1
  63. package/dist/components/motion/hold-action-button.js +64 -50
  64. package/dist/components/motion/hold-action-button.js.map +1 -1
  65. package/dist/components/motion/loader.js +20 -22
  66. package/dist/components/motion/loader.js.map +1 -1
  67. package/dist/components/motion/morphing-modal.d.ts.map +1 -1
  68. package/dist/components/motion/morphing-modal.js +83 -83
  69. package/dist/components/motion/morphing-modal.js.map +1 -1
  70. package/dist/components/motion/morphing-search.d.ts +28 -0
  71. package/dist/components/motion/morphing-search.d.ts.map +1 -0
  72. package/dist/components/motion/morphing-search.js +418 -0
  73. package/dist/components/motion/morphing-search.js.map +1 -0
  74. package/dist/components/motion/morphing-tabs.d.ts.map +1 -1
  75. package/dist/components/motion/morphing-tabs.js +59 -18
  76. package/dist/components/motion/morphing-tabs.js.map +1 -1
  77. package/dist/components/motion/notification-stack.d.ts.map +1 -1
  78. package/dist/components/motion/notification-stack.js +28 -11
  79. package/dist/components/motion/notification-stack.js.map +1 -1
  80. package/dist/components/motion/popover-morph.d.ts.map +1 -1
  81. package/dist/components/motion/popover-morph.js +26 -11
  82. package/dist/components/motion/popover-morph.js.map +1 -1
  83. package/dist/components/motion/popover.d.ts.map +1 -1
  84. package/dist/components/motion/popover.js +39 -28
  85. package/dist/components/motion/popover.js.map +1 -1
  86. package/dist/components/motion/preview-rail.d.ts.map +1 -1
  87. package/dist/components/motion/preview-rail.js +42 -13
  88. package/dist/components/motion/preview-rail.js.map +1 -1
  89. package/dist/components/motion/project-folder.js +20 -20
  90. package/dist/components/motion/project-folder.js.map +1 -1
  91. package/dist/components/motion/pull-to-refresh.d.ts.map +1 -1
  92. package/dist/components/motion/pull-to-refresh.js +8 -7
  93. package/dist/components/motion/pull-to-refresh.js.map +1 -1
  94. package/dist/components/motion/range-slider-bubble.d.ts.map +1 -1
  95. package/dist/components/motion/range-slider-bubble.js +2 -1
  96. package/dist/components/motion/range-slider-bubble.js.map +1 -1
  97. package/dist/components/motion/range-slider-fluid.d.ts.map +1 -1
  98. package/dist/components/motion/range-slider-fluid.js +2 -1
  99. package/dist/components/motion/range-slider-fluid.js.map +1 -1
  100. package/dist/components/motion/range-slider-ruler.d.ts.map +1 -1
  101. package/dist/components/motion/range-slider-ruler.js +2 -1
  102. package/dist/components/motion/range-slider-ruler.js.map +1 -1
  103. package/dist/components/motion/range-slider-wave.d.ts.map +1 -1
  104. package/dist/components/motion/range-slider-wave.js +2 -1
  105. package/dist/components/motion/range-slider-wave.js.map +1 -1
  106. package/dist/components/motion/range-slider.d.ts.map +1 -1
  107. package/dist/components/motion/range-slider.js +2 -1
  108. package/dist/components/motion/range-slider.js.map +1 -1
  109. package/dist/components/motion/select.d.ts +15 -1
  110. package/dist/components/motion/select.d.ts.map +1 -1
  111. package/dist/components/motion/select.js +15 -4
  112. package/dist/components/motion/select.js.map +1 -1
  113. package/dist/components/motion/slide-action-button.d.ts.map +1 -1
  114. package/dist/components/motion/slide-action-button.js +3 -2
  115. package/dist/components/motion/slide-action-button.js.map +1 -1
  116. package/dist/components/motion/swipeable-list.d.ts.map +1 -1
  117. package/dist/components/motion/swipeable-list.js +2 -1
  118. package/dist/components/motion/swipeable-list.js.map +1 -1
  119. package/dist/components/motion/table/index.d.ts.map +1 -1
  120. package/dist/components/motion/table/index.js +64 -6
  121. package/dist/components/motion/table/index.js.map +1 -1
  122. package/dist/components/motion/table/table-header.d.ts.map +1 -1
  123. package/dist/components/motion/table/table-header.js +3 -2
  124. package/dist/components/motion/table/table-header.js.map +1 -1
  125. package/dist/components/motion/text-reveal.d.ts.map +1 -1
  126. package/dist/components/motion/text-reveal.js +72 -48
  127. package/dist/components/motion/text-reveal.js.map +1 -1
  128. package/dist/components/motion/tooltip.d.ts.map +1 -1
  129. package/dist/components/motion/tooltip.js +35 -15
  130. package/dist/components/motion/tooltip.js.map +1 -1
  131. package/dist/components/motion/wheel-picker.d.ts.map +1 -1
  132. package/dist/components/motion/wheel-picker.js +4 -3
  133. package/dist/components/motion/wheel-picker.js.map +1 -1
  134. package/dist/components/reui/badge.d.ts +1 -1
  135. package/dist/components/reui/cascader/cascader-async.d.ts +90 -0
  136. package/dist/components/reui/cascader/cascader-async.d.ts.map +1 -0
  137. package/dist/components/reui/cascader/cascader-async.js +549 -0
  138. package/dist/components/reui/cascader/cascader-async.js.map +1 -0
  139. package/dist/components/reui/cascader/cascader-columns.d.ts +29 -0
  140. package/dist/components/reui/cascader/cascader-columns.d.ts.map +1 -0
  141. package/dist/components/reui/cascader/cascader-columns.js +135 -0
  142. package/dist/components/reui/cascader/cascader-columns.js.map +1 -0
  143. package/dist/components/reui/cascader/cascader-context.d.ts +193 -0
  144. package/dist/components/reui/cascader/cascader-context.d.ts.map +1 -0
  145. package/dist/components/reui/cascader/cascader-context.js +59 -0
  146. package/dist/components/reui/cascader/cascader-context.js.map +1 -0
  147. package/dist/components/reui/cascader/cascader-footer.d.ts +85 -0
  148. package/dist/components/reui/cascader/cascader-footer.d.ts.map +1 -0
  149. package/dist/components/reui/cascader/cascader-footer.js +456 -0
  150. package/dist/components/reui/cascader/cascader-footer.js.map +1 -0
  151. package/dist/components/reui/cascader/cascader-i18n.d.ts +17 -0
  152. package/dist/components/reui/cascader/cascader-i18n.d.ts.map +1 -0
  153. package/dist/components/reui/cascader/cascader-i18n.js +68 -0
  154. package/dist/components/reui/cascader/cascader-i18n.js.map +1 -0
  155. package/dist/components/reui/cascader/cascader-item.d.ts +115 -0
  156. package/dist/components/reui/cascader/cascader-item.d.ts.map +1 -0
  157. package/dist/components/reui/cascader/cascader-item.js +530 -0
  158. package/dist/components/reui/cascader/cascader-item.js.map +1 -0
  159. package/dist/components/reui/cascader/cascader-lib.d.ts +141 -0
  160. package/dist/components/reui/cascader/cascader-lib.d.ts.map +1 -0
  161. package/dist/components/reui/cascader/cascader-lib.js +576 -0
  162. package/dist/components/reui/cascader/cascader-lib.js.map +1 -0
  163. package/dist/components/reui/cascader/cascader-nav.d.ts +59 -0
  164. package/dist/components/reui/cascader/cascader-nav.d.ts.map +1 -0
  165. package/dist/components/reui/cascader/cascader-nav.js +312 -0
  166. package/dist/components/reui/cascader/cascader-nav.js.map +1 -0
  167. package/dist/components/reui/cascader/cascader-types.d.ts +2 -0
  168. package/dist/components/reui/cascader/cascader-types.js +2 -0
  169. package/dist/components/reui/cascader/cascader-virtual.d.ts +65 -0
  170. package/dist/components/reui/cascader/cascader-virtual.d.ts.map +1 -0
  171. package/dist/components/reui/cascader/cascader-virtual.js +240 -0
  172. package/dist/components/reui/cascader/cascader-virtual.js.map +1 -0
  173. package/dist/components/reui/cascader/cascader.d.ts +322 -0
  174. package/dist/components/reui/cascader/cascader.d.ts.map +1 -0
  175. package/dist/components/reui/cascader/cascader.js +1459 -0
  176. package/dist/components/reui/cascader/cascader.js.map +1 -0
  177. package/dist/components/reui/event-calendar/event-calendar-event.d.ts +28 -47
  178. package/dist/components/reui/event-calendar/event-calendar-event.d.ts.map +1 -1
  179. package/dist/components/reui/event-calendar/event-calendar-event.js +26 -44
  180. package/dist/components/reui/event-calendar/event-calendar-event.js.map +1 -1
  181. package/dist/components/reui/event-calendar/event-calendar-nav.js +1 -1
  182. package/dist/components/reui/event-calendar/event-calendar-types.d.ts +19 -57
  183. package/dist/components/reui/event-calendar/event-calendar-types.d.ts.map +1 -1
  184. package/dist/components/reui/filters/filters-advanced.d.ts +52 -0
  185. package/dist/components/reui/filters/filters-advanced.d.ts.map +1 -0
  186. package/dist/components/reui/filters/filters-advanced.js +1191 -0
  187. package/dist/components/reui/filters/filters-advanced.js.map +1 -0
  188. package/dist/components/reui/filters/filters-builder.d.ts +43 -0
  189. package/dist/components/reui/filters/filters-builder.d.ts.map +1 -0
  190. package/dist/components/reui/filters/filters-builder.js +152 -0
  191. package/dist/components/reui/filters/filters-builder.js.map +1 -0
  192. package/dist/components/reui/filters/filters-chip.d.ts +79 -0
  193. package/dist/components/reui/filters/filters-chip.d.ts.map +1 -0
  194. package/dist/components/reui/filters/filters-chip.js +553 -0
  195. package/dist/components/reui/filters/filters-chip.js.map +1 -0
  196. package/dist/components/reui/filters/filters-context.d.ts +290 -0
  197. package/dist/components/reui/filters/filters-context.d.ts.map +1 -0
  198. package/dist/components/reui/filters/filters-context.js +277 -0
  199. package/dist/components/reui/filters/filters-context.js.map +1 -0
  200. package/dist/components/reui/filters/filters-date.d.ts +43 -0
  201. package/dist/components/reui/filters/filters-date.d.ts.map +1 -0
  202. package/dist/components/reui/filters/filters-date.js +143 -0
  203. package/dist/components/reui/filters/filters-date.js.map +1 -0
  204. package/dist/components/reui/filters/filters-dnd.d.ts +101 -0
  205. package/dist/components/reui/filters/filters-dnd.d.ts.map +1 -0
  206. package/dist/components/reui/filters/filters-dnd.js +454 -0
  207. package/dist/components/reui/filters/filters-dnd.js.map +1 -0
  208. package/dist/components/reui/filters/filters-draft.d.ts +2 -0
  209. package/dist/components/reui/filters/filters-draft.js +128 -0
  210. package/dist/components/reui/filters/filters-draft.js.map +1 -0
  211. package/dist/components/reui/filters/filters-editors.d.ts +91 -0
  212. package/dist/components/reui/filters/filters-editors.d.ts.map +1 -0
  213. package/dist/components/reui/filters/filters-editors.js +773 -0
  214. package/dist/components/reui/filters/filters-editors.js.map +1 -0
  215. package/dist/components/reui/filters/filters-i18n.d.ts +24 -0
  216. package/dist/components/reui/filters/filters-i18n.d.ts.map +1 -0
  217. package/dist/components/reui/filters/filters-i18n.js +127 -0
  218. package/dist/components/reui/filters/filters-i18n.js.map +1 -0
  219. package/dist/components/reui/filters/filters-lib.d.ts +171 -0
  220. package/dist/components/reui/filters/filters-lib.d.ts.map +1 -0
  221. package/dist/components/reui/filters/filters-lib.js +336 -0
  222. package/dist/components/reui/filters/filters-lib.js.map +1 -0
  223. package/dist/components/reui/filters/filters-operators.d.ts +49 -0
  224. package/dist/components/reui/filters/filters-operators.d.ts.map +1 -0
  225. package/dist/components/reui/filters/filters-operators.js +300 -0
  226. package/dist/components/reui/filters/filters-operators.js.map +1 -0
  227. package/dist/components/reui/filters/filters-query.d.ts +132 -0
  228. package/dist/components/reui/filters/filters-query.d.ts.map +1 -0
  229. package/dist/components/reui/filters/filters-query.js +476 -0
  230. package/dist/components/reui/filters/filters-query.js.map +1 -0
  231. package/dist/components/reui/filters/filters-types.d.ts +452 -0
  232. package/dist/components/reui/filters/filters-types.d.ts.map +1 -0
  233. package/dist/components/reui/filters/filters-types.js +2 -0
  234. package/dist/components/reui/filters/filters.d.ts +114 -0
  235. package/dist/components/reui/filters/filters.d.ts.map +1 -0
  236. package/dist/components/reui/filters/filters.js +638 -0
  237. package/dist/components/reui/filters/filters.js.map +1 -0
  238. package/dist/components/reui/frame.d.ts +1 -1
  239. package/dist/components/reui/gantt/gantt-bar.js +1 -1
  240. package/dist/components/reui/gantt/gantt-nav.js +1 -1
  241. package/dist/components/reui/gantt/gantt-types.d.ts +25 -71
  242. package/dist/components/reui/gantt/gantt-types.d.ts.map +1 -1
  243. package/dist/components/reui/gantt/gantt-view.js +1 -1
  244. package/dist/components/reui/icon-tile.d.ts +1 -1
  245. package/dist/components/ui/badge.d.ts +1 -1
  246. package/dist/components/ui/bubble.d.ts +1 -1
  247. package/dist/components/ui/button.d.ts +2 -2
  248. package/dist/components/ui/checkbox.js +1 -1
  249. package/dist/components/ui/checkbox.js.map +1 -1
  250. package/dist/components/ui/field.js +2 -2
  251. package/dist/components/ui/field.js.map +1 -1
  252. package/dist/components/ui/item.d.ts +2 -2
  253. package/dist/components/ui/marker.d.ts +1 -1
  254. package/dist/components/ui/radio-group.js +1 -1
  255. package/dist/components/ui/radio-group.js.map +1 -1
  256. package/dist/components/ui/sidebar.d.ts +1 -1
  257. package/dist/components/ui/sidebar.js +1 -1
  258. package/dist/components/ui/switch.js +1 -1
  259. package/dist/components/ui/switch.js.map +1 -1
  260. package/dist/components/ui/tabs.d.ts +1 -1
  261. package/dist/components/ui/toggle.d.ts +1 -1
  262. package/dist/{copy-menu-Bk5GP9Gp.js → copy-menu-1FKoMc9o.js} +9 -2
  263. package/dist/copy-menu-1FKoMc9o.js.map +1 -0
  264. package/dist/filters-draft-DEAl3TO-.d.ts +70 -0
  265. package/dist/filters-draft-DEAl3TO-.d.ts.map +1 -0
  266. package/dist/hooks/use-dismiss.d.ts +34 -0
  267. package/dist/hooks/use-dismiss.d.ts.map +1 -0
  268. package/dist/hooks/use-dismiss.js +78 -0
  269. package/dist/hooks/use-dismiss.js.map +1 -0
  270. package/dist/hooks/use-favicon.d.ts +17 -0
  271. package/dist/hooks/use-favicon.d.ts.map +1 -0
  272. package/dist/hooks/use-favicon.js +35 -0
  273. package/dist/hooks/use-favicon.js.map +1 -0
  274. package/dist/hooks/use-hover-gesture.d.ts +38 -0
  275. package/dist/hooks/use-hover-gesture.d.ts.map +1 -0
  276. package/dist/hooks/use-hover-gesture.js +46 -0
  277. package/dist/hooks/use-hover-gesture.js.map +1 -0
  278. package/dist/hooks/use-slider.d.ts.map +1 -1
  279. package/dist/hooks/use-slider.js +3 -2
  280. package/dist/hooks/use-slider.js.map +1 -1
  281. package/dist/hooks/use-tap-gesture.d.ts +47 -0
  282. package/dist/hooks/use-tap-gesture.d.ts.map +1 -0
  283. package/dist/hooks/use-tap-gesture.js +51 -0
  284. package/dist/hooks/use-tap-gesture.js.map +1 -0
  285. package/dist/hooks/use-touch-capable.d.ts +15 -0
  286. package/dist/hooks/use-touch-capable.d.ts.map +1 -0
  287. package/dist/hooks/use-touch-capable.js +29 -0
  288. package/dist/hooks/use-touch-capable.js.map +1 -0
  289. package/dist/lib/text-shimmer.d.ts +2 -2
  290. package/dist/lib/text-shimmer.d.ts.map +1 -1
  291. package/dist/lib/text-shimmer.js +2 -2
  292. package/dist/lib/text-shimmer.js.map +1 -1
  293. package/dist/lib/touch.d.ts +66 -0
  294. package/dist/lib/touch.d.ts.map +1 -0
  295. package/dist/lib/touch.js +79 -0
  296. package/dist/lib/touch.js.map +1 -0
  297. package/dist/presence-gate-BekdC4Bo.js +24 -0
  298. package/dist/presence-gate-BekdC4Bo.js.map +1 -0
  299. package/dist/types-smkWN_7x.d.ts.map +1 -1
  300. package/package.json +9 -9
  301. package/dist/components/reui/filters.d.ts +0 -176
  302. package/dist/components/reui/filters.d.ts.map +0 -1
  303. package/dist/components/reui/filters.js +0 -1223
  304. package/dist/components/reui/filters.js.map +0 -1
  305. package/dist/copy-menu-Bk5GP9Gp.js.map +0 -1
@@ -0,0 +1,1459 @@
1
+ "use client";
2
+ import { ScrollArea } from "../../ui/scroll-area.js";
3
+ import { CascaderActionsContext, CascaderHighlightContext, CascaderRenderContext, CascaderStateContext, createCascaderHighlightStore, useCascaderActions, useCascaderHighlight, useCascaderRender, useCascaderState } from "./cascader-context.js";
4
+ import { CASCADER_LIST_HEIGHT_CLASS, CASCADER_LIST_PAD_CLASS, CASCADER_ROOT_KEY, CASCADER_ROWS_CLASS, CASCADER_SCROLL_CLASS, applyCascadeSelection, buildCascaderIndex, collapseCascaderPath, createCascaderMoreNode, filterCascaderLevel, findAmbiguousCascaderLabels, findCascaderDataIssues, flattenCascaderTree, getCascaderCheckedValues, getCascaderChildren, getCascaderCount, getCascaderIndeterminateFrom, getCascaderPath, getCascaderSelectedDescendants, getCascaderTabTarget, isCascaderBranch, isCascaderMoreNode, isCascaderSelectable, matchesCascaderQuery, mergeCascaderIndex, normalizeCascaderQuery, searchCascaderDeep, warnCascaderOnce } from "./cascader-lib.js";
5
+ import { useCascaderLoadState, useCascaderLoader } from "./cascader-async.js";
6
+ import { resolveCascaderLabels } from "./cascader-i18n.js";
7
+ import * as React$1 from "react";
8
+ import { cn } from "@kumix/utils";
9
+ import { jsx, jsxs } from "react/jsx-runtime";
10
+ import { ChevronDownIcon, XIcon } from "lucide-react";
11
+ import { mergeProps } from "@base-ui/react/merge-props";
12
+ import { useRender } from "@base-ui/react/use-render";
13
+ import { Combobox } from "@base-ui/react";
14
+ //#region src/components/reui/cascader/cascader.tsx
15
+ /** Stable `filteredItems` for a level swap; a fixed identity cannot loop. */
16
+ const EMPTY = [];
17
+ /** Stable empty array for the `actions` prop, so a cascader with no footer
18
+ * does not republish the actions context on every render. */
19
+ const EMPTY_ACTIONS = [];
20
+ const ANNOUNCE_MARKER = "⁠";
21
+ const ANNOUNCE_DEBOUNCE = 150;
22
+ function useControllable(controlled, defaultValue, onChange, devName) {
23
+ const [uncontrolled, setUncontrolled] = React$1.useState(defaultValue);
24
+ const isControlled = controlled !== void 0;
25
+ const value = isControlled ? controlled : uncontrolled;
26
+ const wasControlled = React$1.useRef(isControlled);
27
+ React$1.useEffect(() => {
28
+ if (process.env.NODE_ENV === "production") return;
29
+ if (wasControlled.current === isControlled || !devName) return;
30
+ const from = wasControlled.current ? "controlled" : "uncontrolled";
31
+ const to = isControlled ? "controlled" : "uncontrolled";
32
+ wasControlled.current = isControlled;
33
+ warnCascaderOnce(`controlled-switch:${devName}`, `\`${devName}\` switched from ${from} to ${to}. Decide once: pass \`${devName}\` for the whole life of the component, or pass only the default and let the cascader own it.`);
34
+ }, [isControlled, devName]);
35
+ const latest = React$1.useRef({
36
+ value,
37
+ isControlled,
38
+ onChange
39
+ });
40
+ React$1.useEffect(() => {
41
+ latest.current = {
42
+ value,
43
+ isControlled,
44
+ onChange
45
+ };
46
+ });
47
+ const lastProp = React$1.useRef(controlled);
48
+ React$1.useEffect(() => {
49
+ lastProp.current = controlled;
50
+ });
51
+ return [value, React$1.useCallback((next) => {
52
+ const current = latest.current.value;
53
+ const resolved = typeof next === "function" ? next(current) : next;
54
+ if (Object.is(resolved, current)) {
55
+ if (!latest.current.isControlled || Object.is(resolved, lastProp.current)) return;
56
+ }
57
+ latest.current = {
58
+ ...latest.current,
59
+ value: resolved
60
+ };
61
+ if (!latest.current.isControlled) setUncontrolled(resolved);
62
+ latest.current.onChange?.(resolved);
63
+ }, [])];
64
+ }
65
+ function shallowEqualRecords(a, b) {
66
+ const left = a;
67
+ const right = b;
68
+ const keys = Object.keys(left);
69
+ if (keys.length !== Object.keys(right).length) return false;
70
+ for (const key of keys) if (!Object.is(left[key], right[key])) return false;
71
+ return true;
72
+ }
73
+ function shallowEqualItemLists(a, b) {
74
+ if (a.length !== b.length) return false;
75
+ for (let i = 0; i < a.length; i += 1) if (a[i] !== b[i] && !shallowEqualRecords(a[i], b[i])) return false;
76
+ return true;
77
+ }
78
+ function useShallowStable(value, equal) {
79
+ const [stable, setStable] = React$1.useState(value);
80
+ if (Object.is(value, stable)) return stable;
81
+ if (typeof value === "object" && value !== null && typeof stable === "object" && stable !== null && equal(value, stable)) return stable;
82
+ setStable(value);
83
+ return value;
84
+ }
85
+ /**
86
+ * The cascader's internals, typed for the caller's own item payload.
87
+ * @deprecated Reads BOTH halves, so a caller re-renders on every keystroke.
88
+ * Prefer `useCascaderActions()` or `useCascaderState()`. Kept for compat.
89
+ */
90
+ function useCascader() {
91
+ const actions = useCascaderActions();
92
+ const state = useCascaderState();
93
+ return React$1.useMemo(() => ({
94
+ ...actions,
95
+ ...state
96
+ }), [actions, state]);
97
+ }
98
+ /** Headless access to the selection, for a trigger that is not
99
+ * `CascaderValue`. Pass the payload explicitly to get `node.data` typed. */
100
+ function useCascaderSelection() {
101
+ const { multiple, setSelection } = useCascaderActions();
102
+ const { index, selectedValues } = useCascaderState();
103
+ return React$1.useMemo(() => {
104
+ const selected = selectedValues.map((value) => index.byValue.get(value)).filter(Boolean);
105
+ const paths = selectedValues.map((value) => getCascaderPath(index, value));
106
+ return {
107
+ selected,
108
+ paths,
109
+ first: selected[0] ?? null,
110
+ firstPath: paths[0] ?? [],
111
+ count: selectedValues.length,
112
+ isEmpty: selectedValues.length === 0,
113
+ multiple,
114
+ remove: (value) => setSelection(selectedValues.filter((entry) => entry !== value)),
115
+ clear: () => setSelection([], "clear")
116
+ };
117
+ }, [
118
+ index,
119
+ selectedValues,
120
+ multiple,
121
+ setSelection
122
+ ]);
123
+ }
124
+ /** Normalizes to an array. `""` is "no selection", not a node: it is the
125
+ * uncontrolled default, and resolving it would render a blank chip. */
126
+ function toArray(value) {
127
+ if (value == null) return [];
128
+ if (Array.isArray(value)) return value.filter((entry) => entry !== "");
129
+ return value === "" ? [] : [value];
130
+ }
131
+ /** Misconfigurations that are SILENT by design. Once each, never in prod. */
132
+ function useCascaderDevWarnings(options) {
133
+ const { items, getParent, mode, multiple, cascade, indicator, selectable, searchScope, max, value, defaultValue, hasExpanded, hasPath, hasOnSearch } = options;
134
+ const issues = React$1.useMemo(() => process.env.NODE_ENV === "production" ? null : findCascaderDataIssues(items, getParent), [items, getParent]);
135
+ React$1.useEffect(() => {
136
+ if (process.env.NODE_ENV === "production") return;
137
+ for (const duplicate of issues?.duplicates ?? []) warnCascaderOnce(`duplicate-value:${duplicate}`, `Duplicate node value ${JSON.stringify(duplicate)}. \`value\` is the selection key, so only the first occurrence is indexed and the rest never render.`);
138
+ for (const cycle of issues?.cycles ?? []) warnCascaderOnce(`cycle:${cycle}`, `\`getParent\` puts ${JSON.stringify(cycle)} on a cycle. The depth walk is cycle-guarded so nothing hangs, but every depth on that chain is clamped rather than derived.`);
139
+ }, [issues]);
140
+ React$1.useEffect(() => {
141
+ if (process.env.NODE_ENV === "production") return;
142
+ for (const [prop, current] of [["value", value], ["defaultValue", defaultValue]]) {
143
+ if (current == null) continue;
144
+ if (multiple && !Array.isArray(current)) warnCascaderOnce(`value-shape:multiple:${prop}`, `\`multiple\` is set but \`${prop}\` is a string. Multi-select reads and writes a \`string[]\`; a string is treated as no selection at all.`);
145
+ else if (!multiple && Array.isArray(current)) warnCascaderOnce(`value-shape:single:${prop}`, `\`${prop}\` is an array but \`multiple\` is not set. Single-select reads and writes a \`string\`; only the first entry would survive a commit.`);
146
+ }
147
+ if (cascade && !multiple) warnCascaderOnce("cascade-without-multiple", "`cascade` does nothing without `multiple`: a single selection has no subtree to propagate over.");
148
+ if (cascade && selectable === "leaf") warnCascaderOnce("cascade-with-leaf-selectable", "`cascade` does nothing while `selectable=\"leaf\"`: no branch can be committed, so no commit ever has a subtree under it. Pass `selectable=\"any\"` or a predicate that accepts branches.");
149
+ if (!indicator && multiple) warnCascaderOnce("indicator-false-with-multiple", "`indicator={false}` does nothing with `multiple`: the checkbox is the selection control rather than a decoration, so it and its gutter stay. Mark selection your own way from `data-selected` on the row, and drop the prop.");
150
+ if (max != null && !multiple) warnCascaderOnce("max-without-multiple", "`max` does nothing without `multiple`: there is only ever one selection to cap.");
151
+ if (hasExpanded && mode !== "tree") warnCascaderOnce(`expanded-outside-tree:${mode}`, `\`expanded\` only does something in \`mode="tree"\`, and this cascader is in \`mode="${mode}"\`. Drill and columns navigate with \`path\`.`);
152
+ if (hasPath && mode === "tree") warnCascaderOnce("path-in-tree", "`path` does nothing in `mode=\"tree\"`: branches expand in place rather than replacing the level. Use `expanded`.");
153
+ if (searchScope === "deep" && mode === "tree") warnCascaderOnce("deep-search-in-tree", "`searchScope=\"deep\"` does nothing in `mode=\"tree\"`: a tree query already matches at any depth and auto-expands the ancestors of every hit.");
154
+ if (hasOnSearch && mode === "tree") warnCascaderOnce("onsearch-in-tree", "`onSearch` does nothing in `mode=\"tree\"`: a tree query filters the loaded tree in place, and a server hit belongs to no visible branch, so its results would never render. The request is not fired. Filter the tree locally, or use drill or columns for server search.");
155
+ }, [
156
+ mode,
157
+ multiple,
158
+ cascade,
159
+ indicator,
160
+ selectable,
161
+ searchScope,
162
+ max,
163
+ value,
164
+ defaultValue,
165
+ hasExpanded,
166
+ hasPath,
167
+ hasOnSearch
168
+ ]);
169
+ }
170
+ /** No default on `T`: inferred from `items`, so `node.data` arrives typed. */
171
+ function Cascader({ items, getParent, getChildren, onSearch, searchDebounce, resolveValue, loadKey, prefetch, onLoadError, value: valueProp, defaultValue, onValueChange: onValueChangeProp, multiple = false, selectable = "leaf", indicator = true, actions, cascade = false, max, mode = "drill", expandTrigger, path: pathProp, defaultPath, onPathChange, expanded: expandedProp, defaultExpanded, onExpandedChange, open: openProp, defaultOpen = false, onOpenChange, closeOnSelect = true, inputValue: inputValueProp, defaultInputValue = "", onInputValueChange, searchScope = "level", filter, revealSelected = true, maxHeight, virtualize, virtualizeThreshold = 100, estimateRowSize = 32, overscan = 8, labels: labelsProp, renderItem, renderLabel, disabled, name, form, id, required, readOnly, invalid, inputRef, inline, children }) {
172
+ const baseIndex = React$1.useMemo(() => buildCascaderIndex(items, getParent), [items, getParent]);
173
+ const baseId = React$1.useId();
174
+ const stableLabelsProp = useShallowStable(labelsProp, shallowEqualRecords);
175
+ const labels = React$1.useMemo(() => resolveCascaderLabels(stableLabelsProp), [stableLabelsProp]);
176
+ useCascaderDevWarnings({
177
+ items,
178
+ getParent,
179
+ mode,
180
+ multiple,
181
+ cascade,
182
+ indicator,
183
+ selectable,
184
+ searchScope,
185
+ max,
186
+ value: valueProp,
187
+ defaultValue,
188
+ hasExpanded: expandedProp !== void 0 || defaultExpanded !== void 0 || onExpandedChange !== void 0,
189
+ hasPath: pathProp !== void 0 || defaultPath !== void 0 || onPathChange !== void 0,
190
+ hasOnSearch: onSearch !== void 0
191
+ });
192
+ const onValueChange = onValueChangeProp;
193
+ const [value, setValue] = useControllable(valueProp, defaultValue ?? (multiple ? [] : ""), void 0, "value");
194
+ const pathReasonRef = React$1.useRef("external");
195
+ const openReasonRef = React$1.useRef("none");
196
+ const [path, setPath] = useControllable(pathProp, defaultPath ?? [], (next) => onPathChange?.(next, { reason: pathReasonRef.current }), "path");
197
+ const [expandedList, setExpandedList] = useControllable(expandedProp, defaultExpanded ?? [], onExpandedChange, "expanded");
198
+ const [open, setOpen] = useControllable(openProp, defaultOpen, (next) => onOpenChange?.(next, { reason: openReasonRef.current }), "open");
199
+ /** The internal `setPath`: names its reason, then hands back to "external". */
200
+ const setPathWithReason = React$1.useCallback((next, reason) => {
201
+ pathReasonRef.current = reason;
202
+ try {
203
+ setPath(next);
204
+ } finally {
205
+ pathReasonRef.current = "external";
206
+ }
207
+ }, [setPath]);
208
+ const [query, setQuery] = useControllable(inputValueProp, defaultInputValue, onInputValueChange, "inputValue");
209
+ const expanded = React$1.useMemo(() => new Set(expandedList), [expandedList]);
210
+ const selectedValues = React$1.useMemo(() => toArray(value), [value]);
211
+ const levels = React$1.useMemo(() => {
212
+ if (mode === "tree") return [CASCADER_ROOT_KEY, ...expandedList];
213
+ if (mode === "columns") return [CASCADER_ROOT_KEY, ...path];
214
+ return [path.length ? path[path.length - 1] : CASCADER_ROOT_KEY];
215
+ }, [
216
+ mode,
217
+ path,
218
+ expandedList
219
+ ]);
220
+ const loader = useCascaderLoader({
221
+ base: baseIndex,
222
+ getChildren,
223
+ onSearch: mode === "tree" ? void 0 : onSearch,
224
+ resolveValue,
225
+ searchDebounce,
226
+ loadKey,
227
+ prefetch,
228
+ onLoadError,
229
+ enabled: open || !!inline,
230
+ query,
231
+ levels,
232
+ path,
233
+ values: selectedValues
234
+ });
235
+ const loadStates = loader.states;
236
+ const { ensureLevel, retryLevel: retryLoaderLevel, invalidateLevel } = loader;
237
+ /**
238
+ * Whether pressing this branch has to FETCH first: in flight, failed, or
239
+ * never asked. `baseIndex`, NOT the merged `index`: `resolveValue` writes an
240
+ * ancestor chain into `pages` without touching `states`, so the merged index
241
+ * shows children for levels never requested. Must agree with `ensureLevel`'s
242
+ * own guards or a press parks a navigation nothing will ever settle.
243
+ */
244
+ const needsChildren = React$1.useCallback((node) => {
245
+ if (!loader.active) return false;
246
+ const state = loadStates.get(node.value);
247
+ if (state) return state.loading || state.error;
248
+ return !baseIndex.childrenOf.has(node.value);
249
+ }, [
250
+ loader.active,
251
+ loadStates,
252
+ baseIndex
253
+ ]);
254
+ const index = React$1.useMemo(() => mergeCascaderIndex(baseIndex, loader.store.pages, loader.store.detached), [
255
+ baseIndex,
256
+ loader.store.pages,
257
+ loader.store.detached
258
+ ]);
259
+ /** Whether a level needs the paging pseudo-row. A never-fetched level gets
260
+ * nothing; that is the empty state's job. Tree has no per-level empty state,
261
+ * so there the row is also the branch's loading and error surface. */
262
+ const needsMoreRow = React$1.useCallback((key, childCount) => {
263
+ const state = loadStates.get(key);
264
+ if (!state) return false;
265
+ if (childCount > 0) return state.hasMore || state.loading || state.error;
266
+ return mode === "tree" && (state.loading || state.error);
267
+ }, [loadStates, mode]);
268
+ const labelCacheRef = React$1.useRef(/* @__PURE__ */ new Map());
269
+ for (const selected of selectedValues) {
270
+ const node = index.byValue.get(selected);
271
+ if (node) labelCacheRef.current.set(selected, node);
272
+ }
273
+ const resolveNode = React$1.useCallback((nodeValue) => index.byValue.get(nodeValue) ?? labelCacheRef.current.get(nodeValue) ?? {
274
+ value: nodeValue,
275
+ label: nodeValue
276
+ }, [index]);
277
+ const currentParentValue = path.length ? path[path.length - 1] : null;
278
+ const currentParent = currentParentValue ? index.byValue.get(currentParentValue) ?? null : null;
279
+ const currentLevelKey = currentParentValue ?? "\0root";
280
+ const isDeepSearching = searchScope === "deep" && query.trim().length > 0 && mode !== "tree";
281
+ const localDeepResults = React$1.useMemo(() => {
282
+ if (!isDeepSearching) return null;
283
+ return searchCascaderDeep(index, query, {
284
+ within: currentParentValue,
285
+ matches: filter
286
+ });
287
+ }, [
288
+ isDeepSearching,
289
+ index,
290
+ query,
291
+ currentParentValue,
292
+ filter
293
+ ]);
294
+ const deepResults = loader.searchResults ?? localDeepResults;
295
+ const levelItems = React$1.useMemo(() => {
296
+ const level = getCascaderChildren(index, currentParentValue);
297
+ return filterCascaderLevel(level, query, filter);
298
+ }, [
299
+ index,
300
+ currentParentValue,
301
+ query,
302
+ filter
303
+ ]);
304
+ /** The active level's rows plus the paging pseudo-row, appended HERE because
305
+ * every index Base UI hands out indexes this array: a DOM row missing from
306
+ * it shifts the highlight and every windowed row by one. */
307
+ const levelRendered = React$1.useMemo(() => {
308
+ if (deepResults) return deepResults;
309
+ if (!needsMoreRow(currentLevelKey, levelItems.length)) return levelItems;
310
+ return [...levelItems, createCascaderMoreNode(currentLevelKey, levelItems.length)];
311
+ }, [
312
+ deepResults,
313
+ levelItems,
314
+ currentLevelKey,
315
+ needsMoreRow
316
+ ]);
317
+ const columns = React$1.useMemo(() => {
318
+ if (mode !== "columns") return [];
319
+ const trail = [];
320
+ for (let depth = 0; depth <= path.length; depth += 1) {
321
+ const parentValue = depth === 0 ? null : path[depth - 1];
322
+ const parent = parentValue ? index.byValue.get(parentValue) ?? null : null;
323
+ const isActive = depth === path.length;
324
+ let columnItems;
325
+ if (isActive) columnItems = levelRendered;
326
+ else {
327
+ const key = parentValue ?? "\0root";
328
+ const children = getCascaderChildren(index, parentValue);
329
+ columnItems = needsMoreRow(key, children.length) ? [...children, createCascaderMoreNode(key, children.length)] : children;
330
+ }
331
+ trail.push({
332
+ parent,
333
+ depth,
334
+ activeValue: path[depth] ?? null,
335
+ active: isActive,
336
+ items: columnItems
337
+ });
338
+ }
339
+ return trail;
340
+ }, [
341
+ mode,
342
+ path,
343
+ index,
344
+ levelRendered,
345
+ needsMoreRow
346
+ ]);
347
+ const treeSentinels = React$1.useMemo(() => {
348
+ if (mode !== "tree") return void 0;
349
+ const keys = /* @__PURE__ */ new Set();
350
+ const consider = (key) => {
351
+ if (needsMoreRow(key, index.childrenOf.get(key)?.length ?? 0)) keys.add(key);
352
+ };
353
+ consider(CASCADER_ROOT_KEY);
354
+ for (const value of expanded) consider(value);
355
+ return keys.size ? keys : void 0;
356
+ }, [
357
+ mode,
358
+ index,
359
+ expanded,
360
+ needsMoreRow
361
+ ]);
362
+ const treeRows = React$1.useMemo(() => {
363
+ if (mode !== "tree") return [];
364
+ const rows = flattenCascaderTree(index, expanded, treeSentinels);
365
+ const normalized = normalizeCascaderQuery(query);
366
+ if (!normalized) return rows;
367
+ const keep = /* @__PURE__ */ new Set();
368
+ for (const node of index.all) {
369
+ if (!(filter ? filter(node, normalized) : matchesCascaderQuery(node, normalized))) continue;
370
+ for (const ancestor of getCascaderPath(index, node.value)) keep.add(ancestor.value);
371
+ }
372
+ return flattenCascaderTree(index, /* @__PURE__ */ new Set([...expanded, ...keep])).filter((row) => keep.has(row.node.value));
373
+ }, [
374
+ mode,
375
+ index,
376
+ expanded,
377
+ treeSentinels,
378
+ query,
379
+ filter
380
+ ]);
381
+ const renderedItems = React$1.useMemo(() => mode === "tree" ? treeRows.map((row) => row.node) : levelRendered, [
382
+ mode,
383
+ treeRows,
384
+ levelRendered
385
+ ]);
386
+ /** Base UI never resets the highlighted index on an `items` change and has
387
+ * no imperative setter; its one automatic reset is an out-of-range clamp, so
388
+ * a single empty frame trips it. The frame rides `filteredItems`, so the
389
+ * `items` identity stays put. */
390
+ const levelKey = currentParentValue ?? "";
391
+ const [swap, setSwap] = React$1.useState({
392
+ key: levelKey,
393
+ active: false
394
+ });
395
+ if (swap.key !== levelKey) setSwap({
396
+ key: levelKey,
397
+ active: true
398
+ });
399
+ const swapping = swap.active && swap.key === levelKey;
400
+ React$1.useLayoutEffect(() => {
401
+ if (swap.active) setSwap((prev) => ({
402
+ ...prev,
403
+ active: false
404
+ }));
405
+ }, [swap.active]);
406
+ const [virtualRenderers, setVirtualRenderers] = React$1.useState(0);
407
+ const registerVirtualRenderer = React$1.useCallback(() => {
408
+ setVirtualRenderers((count) => count + 1);
409
+ return () => setVirtualRenderers((count) => Math.max(0, count - 1));
410
+ }, []);
411
+ const hasVirtualRenderer = virtualRenderers > 0;
412
+ const wantsVirtual = virtualize ?? renderedItems.length >= virtualizeThreshold;
413
+ const [virtualLatch, setVirtualLatch] = React$1.useState({
414
+ key: levelKey,
415
+ on: false
416
+ });
417
+ const virtualized = hasVirtualRenderer && (virtualLatch.key === levelKey ? virtualLatch.on || wantsVirtual : wantsVirtual);
418
+ if (!hasVirtualRenderer) {
419
+ if (virtualLatch.on || virtualLatch.key !== levelKey) setVirtualLatch({
420
+ key: levelKey,
421
+ on: false
422
+ });
423
+ } else if (virtualLatch.key !== levelKey) setVirtualLatch({
424
+ key: levelKey,
425
+ on: virtualized
426
+ });
427
+ else if (virtualized && !virtualLatch.on) setVirtualLatch({
428
+ key: levelKey,
429
+ on: true
430
+ });
431
+ /**
432
+ * One forced re-render, one commit AFTER windowing turns on. Base UI sizes
433
+ * `listRef` from `filteredItems` in a layout effect keyed on that array's
434
+ * identity, but `virtualized` reaches the list a commit later and the
435
+ * `CompositeList` teardown REPLACES `listRef` with an empty array nothing
436
+ * re-sizes, so ArrowDown stops at the last WINDOWED row. A passive effect is
437
+ * late enough: the teardown is scheduled from a layout effect.
438
+ */
439
+ const [_virtualSyncs, setVirtualSyncs] = React$1.useState(0);
440
+ React$1.useEffect(() => {
441
+ if (!virtualized) return;
442
+ setVirtualSyncs((count) => count + 1);
443
+ }, [virtualized]);
444
+ React$1.useEffect(() => {
445
+ if (process.env.NODE_ENV === "production") return void 0;
446
+ if (virtualize !== true || hasVirtualRenderer) return void 0;
447
+ const timeout = setTimeout(() => {
448
+ console.error("[Cascader] `virtualize` is true but no windowing renderer is mounted. Render <CascaderVirtualItems /> inside <CascaderList>, or <CascaderVirtualColumn /> through the <CascaderColumns> slot.");
449
+ }, 0);
450
+ return () => clearTimeout(timeout);
451
+ }, [virtualize, hasVirtualRenderer]);
452
+ /** One signal per navigation, feeding the live region, bumped EXACTLY once
453
+ * per action. `seq` alternates the invisible marker so two identical
454
+ * announcements are still two mutations; `toggled` names the tree branch. */
455
+ const [announceSignal, setAnnounceSignal] = React$1.useState({
456
+ seq: 0,
457
+ toggled: null,
458
+ notice: null
459
+ });
460
+ const bumpAnnouncement = React$1.useCallback((toggled) => {
461
+ setAnnounceSignal((prev) => ({
462
+ seq: prev.seq + 1,
463
+ toggled,
464
+ notice: null
465
+ }));
466
+ }, []);
467
+ /** Speaks for interactions that change nothing on screen: a refusal returns
468
+ * before any state moves, a cascade sweep is invisible from the row pressed.
469
+ * The seq bump keeps two identical refusals two mutations. */
470
+ const announceNotice = React$1.useCallback((notice) => {
471
+ setAnnounceSignal((prev) => ({
472
+ seq: prev.seq + 1,
473
+ toggled: null,
474
+ notice
475
+ }));
476
+ }, []);
477
+ /**
478
+ * The navigation a press asked for and a fetch has not answered yet. Load
479
+ * BEFORE you move: drilling in first threw away the list the user was
480
+ * reading and, on failure, stranded them on an error screen for a level they
481
+ * had never seen. Holding here keeps the old rows and puts the progress on
482
+ * the pressed row, whose chevron `CascaderItem` swaps for a spinner.
483
+ */
484
+ const [pendingNavigation, setPendingNavigation] = React$1.useState(null);
485
+ /** Asks for a branch's children and parks the navigation until they land.
486
+ * BOTH entry points are called unconditionally: `retryLevel` no-ops unless
487
+ * the level errored, `ensureLevel` no-ops if it has state, so a repeat press
488
+ * is free and the readiness decision stays inside the loader. */
489
+ const requestChildren = React$1.useCallback((node, pending) => {
490
+ setPendingNavigation(pending);
491
+ retryLoaderLevel(node.value);
492
+ ensureLevel(node.value, "level");
493
+ bumpAnnouncement(null);
494
+ }, [
495
+ retryLoaderLevel,
496
+ ensureLevel,
497
+ bumpAnnouncement
498
+ ]);
499
+ const pushLevel = React$1.useCallback((nodeValue) => {
500
+ setPathWithReason((prev) => [...prev, nodeValue], "drill");
501
+ setQuery("");
502
+ bumpAnnouncement(null);
503
+ }, [
504
+ setPathWithReason,
505
+ setQuery,
506
+ bumpAnnouncement
507
+ ]);
508
+ const popLevel = React$1.useCallback(() => {
509
+ setPathWithReason((prev) => prev.length ? prev.slice(0, -1) : prev, "back");
510
+ setQuery("");
511
+ setPendingNavigation(null);
512
+ bumpAnnouncement(null);
513
+ }, [
514
+ setPathWithReason,
515
+ setQuery,
516
+ bumpAnnouncement
517
+ ]);
518
+ const goToDepth = React$1.useCallback((depth) => {
519
+ setPathWithReason((prev) => prev.slice(0, Math.max(0, depth)), "breadcrumb");
520
+ setQuery("");
521
+ setPendingNavigation(null);
522
+ bumpAnnouncement(null);
523
+ }, [
524
+ setPathWithReason,
525
+ setQuery,
526
+ bumpAnnouncement
527
+ ]);
528
+ const toggleExpanded = React$1.useCallback((nodeValue) => {
529
+ setExpandedList((prev) => prev.includes(nodeValue) ? prev.filter((v) => v !== nodeValue) : [...prev, nodeValue]);
530
+ bumpAnnouncement(nodeValue);
531
+ }, [setExpandedList, bumpAnnouncement]);
532
+ const isBranch = React$1.useCallback((node) => isCascaderBranch(index, node), [index]);
533
+ const isSelectable = React$1.useCallback((node) => isCascaderSelectable(index, node, selectable), [index, selectable]);
534
+ const branchesSelectable = selectable !== "leaf";
535
+ const openFlyoutsRef = React$1.useRef(/* @__PURE__ */ new Set());
536
+ const setFlyoutOpen = React$1.useCallback((key, open) => {
537
+ if (open) openFlyoutsRef.current.add(key);
538
+ else openFlyoutsRef.current.delete(key);
539
+ }, []);
540
+ const hasOpenFlyout = React$1.useCallback(() => openFlyoutsRef.current.size > 0, []);
541
+ const stableActions = useShallowStable(actions, shallowEqualItemLists);
542
+ const resolvedActions = React$1.useMemo(() => stableActions ?? EMPTY_ACTIONS, [stableActions]);
543
+ const selectedSet = React$1.useMemo(() => new Set(selectedValues), [selectedValues]);
544
+ const isSelected = React$1.useCallback((node) => selectedSet.has(node.value), [selectedSet]);
545
+ /** Selected-descendant counts, walked ONCE per selection change and never
546
+ * stored, so the flat value array stays the only source of truth. The walk
547
+ * is `selections x depth`, up from each selection rather than down from each
548
+ * row, which keeps the count and `isIndeterminate` O(1). */
549
+ const selectedDescendants = React$1.useMemo(() => getCascaderSelectedDescendants(index, selectedValues), [index, selectedValues]);
550
+ const selectedDescendantCount = React$1.useCallback((node) => selectedDescendants.get(node.value) ?? 0, [selectedDescendants]);
551
+ const indeterminateSet = React$1.useMemo(() => {
552
+ if (!cascade || !multiple) return null;
553
+ return getCascaderIndeterminateFrom(selectedDescendants, selectedValues);
554
+ }, [
555
+ cascade,
556
+ multiple,
557
+ selectedDescendants,
558
+ selectedValues
559
+ ]);
560
+ const isIndeterminate = React$1.useCallback((node) => indeterminateSet?.has(node.value) ?? false, [indeterminateSet]);
561
+ const highlightedRef = React$1.useRef(null);
562
+ const getHighlighted = React$1.useCallback(() => highlightedRef.current, []);
563
+ const [highlightStore] = React$1.useState(createCascaderHighlightStore);
564
+ const currentLoadState = React$1.useMemo(() => loadStates.get(currentLevelKey) ?? null, [loadStates, currentLevelKey]);
565
+ const searchLoadState = loader.searchState;
566
+ /** What the query announcement COUNTS: matches, not rows, since the list
567
+ * also carries a tree query's ancestor context and the Load-more row. Server
568
+ * hits count as-is; re-judging them locally would drop what it matched on
569
+ * data the client cannot see. */
570
+ const announcedMatches = React$1.useMemo(() => {
571
+ if (deepResults) return deepResults.length;
572
+ const normalized = normalizeCascaderQuery(query);
573
+ if (!normalized) return 0;
574
+ const matches = filter ?? matchesCascaderQuery;
575
+ return renderedItems.filter((node) => !isCascaderMoreNode(node) && matches(node, normalized)).length;
576
+ }, [
577
+ deepResults,
578
+ renderedItems,
579
+ query,
580
+ filter
581
+ ]);
582
+ const announcementTarget = React$1.useMemo(() => {
583
+ if (!open && !inline) return {
584
+ text: "",
585
+ defer: false
586
+ };
587
+ const total = renderedItems.length;
588
+ const marker = ANNOUNCE_MARKER.repeat(announceSignal.seq % 2);
589
+ if (announceSignal.notice) return {
590
+ text: `${announceSignal.notice}${marker}`,
591
+ defer: false
592
+ };
593
+ const toggled = mode === "tree" && announceSignal.toggled ? index.byValue.get(announceSignal.toggled) ?? null : null;
594
+ const pendingState = pendingNavigation ? loadStates.get(pendingNavigation.value) ?? null : null;
595
+ const levelState = query.trim() ? searchLoadState : currentLoadState;
596
+ let text;
597
+ let defer = false;
598
+ if (pendingState?.error) text = labels.error;
599
+ else if (pendingNavigation) text = labels.loading;
600
+ else if (levelState?.error) text = labels.error;
601
+ else if (levelState?.loading) text = query.trim() ? labels.searchingAnnouncement : total > 0 ? labels.loadingMore : labels.loading;
602
+ else if (query.trim()) {
603
+ text = announcedMatches === 0 ? labels.empty : labels.resultsAnnouncement(announcedMatches);
604
+ defer = true;
605
+ } else if (toggled) text = expanded.has(toggled.value) ? labels.expandedAnnouncement(toggled.label, getCascaderCount(index, toggled)) : labels.collapsedAnnouncement(toggled.label);
606
+ else if (currentParent) text = labels.levelAnnouncement(currentParent.label, path.length + 1, total);
607
+ else text = labels.rootAnnouncement(total);
608
+ return {
609
+ text: `${text}${marker}`,
610
+ defer
611
+ };
612
+ }, [
613
+ open,
614
+ inline,
615
+ mode,
616
+ index,
617
+ expanded,
618
+ announceSignal,
619
+ query,
620
+ labels,
621
+ renderedItems.length,
622
+ announcedMatches,
623
+ currentParent,
624
+ path.length,
625
+ currentLoadState,
626
+ searchLoadState,
627
+ pendingNavigation,
628
+ loadStates
629
+ ]);
630
+ /** The COMMITTED announcement. Immediate texts commit during render (the
631
+ * pattern `swap` uses), so an async settle announces in the very commit that
632
+ * shows the rows. Only the deferred query count uses the timer below. */
633
+ const [announced, setAnnounced] = React$1.useState(announcementTarget);
634
+ if (!announcementTarget.defer && announced.text !== announcementTarget.text) setAnnounced(announcementTarget);
635
+ React$1.useEffect(() => {
636
+ if (!announcementTarget.defer) return void 0;
637
+ const timer = setTimeout(() => setAnnounced(announcementTarget), ANNOUNCE_DEBOUNCE);
638
+ return () => clearTimeout(timer);
639
+ }, [announcementTarget]);
640
+ const announcement = announced.text;
641
+ const stateValue = React$1.useMemo(() => ({
642
+ index,
643
+ path,
644
+ expanded,
645
+ query,
646
+ currentParent,
647
+ levelItems,
648
+ deepResults,
649
+ renderedItems,
650
+ columns,
651
+ treeRows,
652
+ selectedValues,
653
+ selectedDescendants,
654
+ loadStates,
655
+ searchState: searchLoadState,
656
+ announcement
657
+ }), [
658
+ index,
659
+ path,
660
+ expanded,
661
+ query,
662
+ currentParent,
663
+ levelItems,
664
+ deepResults,
665
+ renderedItems,
666
+ columns,
667
+ treeRows,
668
+ selectedValues,
669
+ selectedDescendants,
670
+ loadStates,
671
+ searchLoadState,
672
+ announcement
673
+ ]);
674
+ /**
675
+ * Latest committed props and derived state, WRITTEN IN AN EFFECT. That is
676
+ * what keeps the callbacks below `[]`-dep and stable for the life of the
677
+ * cascader; writing during render is unsafe under concurrent rendering. The
678
+ * cost: a read sees the PREVIOUS commit until the effect runs, so ONLY event
679
+ * handlers may read it. Anything used during render is memoised instead.
680
+ */
681
+ const latest = React$1.useRef({
682
+ index,
683
+ state: stateValue,
684
+ mode,
685
+ multiple,
686
+ cascade,
687
+ max,
688
+ labels,
689
+ closeOnSelect,
690
+ selectedValues,
691
+ deepResults,
692
+ onValueChange,
693
+ resolveNode,
694
+ isSelectable,
695
+ needsChildren,
696
+ expanded
697
+ });
698
+ React$1.useEffect(() => {
699
+ latest.current = {
700
+ index,
701
+ state: stateValue,
702
+ mode,
703
+ multiple,
704
+ cascade,
705
+ max,
706
+ labels,
707
+ closeOnSelect,
708
+ selectedValues,
709
+ deepResults,
710
+ onValueChange,
711
+ resolveNode,
712
+ isSelectable,
713
+ needsChildren,
714
+ expanded
715
+ };
716
+ });
717
+ const getIndex = React$1.useCallback(() => latest.current.index, []);
718
+ const getState = React$1.useCallback(() => latest.current.state, []);
719
+ const goToLevelAt = React$1.useCallback((nodeValue, depth) => {
720
+ setPathWithReason((prev) => [...prev.slice(0, Math.max(0, depth)), nodeValue], "drill");
721
+ setQuery("");
722
+ bumpAnnouncement(null);
723
+ }, [
724
+ setPathWithReason,
725
+ setQuery,
726
+ bumpAnnouncement
727
+ ]);
728
+ const navigateAt = React$1.useCallback((node, depth) => {
729
+ if (latest.current.mode === "tree") {
730
+ toggleExpanded(node.value);
731
+ return;
732
+ }
733
+ if (latest.current.needsChildren(node)) {
734
+ requestChildren(node, {
735
+ value: node.value,
736
+ kind: "at",
737
+ depth
738
+ });
739
+ return;
740
+ }
741
+ goToLevelAt(node.value, depth);
742
+ }, [
743
+ toggleExpanded,
744
+ goToLevelAt,
745
+ requestChildren
746
+ ]);
747
+ const navigate = React$1.useCallback((node) => {
748
+ const { mode: currentMode, deepResults: currentDeepResults, index: currentIndex, expanded: currentExpanded, needsChildren: pending } = latest.current;
749
+ if (currentMode === "tree") {
750
+ if (!currentExpanded.has(node.value) && pending(node)) {
751
+ requestChildren(node, {
752
+ value: node.value,
753
+ kind: "expand",
754
+ depth: 0
755
+ });
756
+ return;
757
+ }
758
+ toggleExpanded(node.value);
759
+ return;
760
+ }
761
+ if (currentDeepResults) {
762
+ if (pending(node)) {
763
+ const ancestors = getCascaderPath(currentIndex, node.value);
764
+ requestChildren(node, {
765
+ value: node.value,
766
+ kind: "at",
767
+ depth: Math.max(0, ancestors.length - 1)
768
+ });
769
+ return;
770
+ }
771
+ const ancestors = getCascaderPath(currentIndex, node.value);
772
+ setPathWithReason(ancestors.map((entry) => entry.value), "drill");
773
+ setQuery("");
774
+ bumpAnnouncement(null);
775
+ return;
776
+ }
777
+ if (pending(node)) {
778
+ requestChildren(node, {
779
+ value: node.value,
780
+ kind: "push",
781
+ depth: 0
782
+ });
783
+ return;
784
+ }
785
+ pushLevel(node.value);
786
+ }, [
787
+ toggleExpanded,
788
+ setPathWithReason,
789
+ setQuery,
790
+ pushLevel,
791
+ bumpAnnouncement,
792
+ requestChildren
793
+ ]);
794
+ /**
795
+ * The other half of `requestChildren`: the fetch settled, so the held
796
+ * navigation happens or is dropped. Reads the load STATE, not a promise:
797
+ * only the loader knows a request was superseded, aborted or retried, and no
798
+ * entry at all means it has not reached the store yet. On failure nothing
799
+ * moves and the intent is KEPT, which is what makes the row's retry
800
+ * affordance mean something; only `popLevel`, `goToDepth` and a close drop it.
801
+ */
802
+ React$1.useEffect(() => {
803
+ if (!pendingNavigation) return;
804
+ const state = loadStates.get(pendingNavigation.value);
805
+ if (!state || state.loading || state.error) return;
806
+ setPendingNavigation(null);
807
+ if (pendingNavigation.kind === "expand") {
808
+ toggleExpanded(pendingNavigation.value);
809
+ return;
810
+ }
811
+ if (pendingNavigation.kind === "at") {
812
+ goToLevelAt(pendingNavigation.value, pendingNavigation.depth);
813
+ return;
814
+ }
815
+ pushLevel(pendingNavigation.value);
816
+ }, [
817
+ pendingNavigation,
818
+ loadStates,
819
+ toggleExpanded,
820
+ goToLevelAt,
821
+ pushLevel
822
+ ]);
823
+ React$1.useEffect(() => {
824
+ if (!open && !inline) setPendingNavigation(null);
825
+ }, [open, inline]);
826
+ const emitSelection = React$1.useCallback((nextValues, node, reason) => {
827
+ const { selectedValues: current, multiple: currentMultiple, onValueChange: emit, index: currentIndex, resolveNode: resolve } = latest.current;
828
+ if (nextValues.length === current.length && nextValues.every((entry, i) => entry === current[i])) return;
829
+ const next = currentMultiple ? nextValues : nextValues[0] ?? "";
830
+ setValue(next);
831
+ if (!emit) return;
832
+ const chain = node ? getCascaderPath(currentIndex, node.value) : [];
833
+ emit(next, {
834
+ node,
835
+ path: node ? chain.length ? chain : [node] : [],
836
+ nodes: nextValues.map(resolve),
837
+ reason
838
+ });
839
+ }, [setValue]);
840
+ const setSelection = React$1.useCallback((values, reason) => {
841
+ const { selectedValues: current, resolveNode: resolve } = latest.current;
842
+ const before = new Set(current);
843
+ const after = new Set(values);
844
+ const added = values.find((entry) => !before.has(entry));
845
+ const removed = current.find((entry) => !after.has(entry));
846
+ if (reason === "clear") {
847
+ emitSelection(values, null, "clear");
848
+ return;
849
+ }
850
+ if (added) {
851
+ emitSelection(values, resolve(added), reason ?? "select");
852
+ return;
853
+ }
854
+ if (removed) {
855
+ emitSelection(values, resolve(removed), reason ?? "deselect");
856
+ return;
857
+ }
858
+ emitSelection(values, null, reason ?? "select");
859
+ }, [emitSelection]);
860
+ const commit = React$1.useCallback((node) => {
861
+ const { multiple: currentMultiple, cascade: currentCascade, selectedValues: current, max: currentMax, index: currentIndex, isSelectable: currentIsSelectable, labels: currentLabels, closeOnSelect: currentCloseOnSelect } = latest.current;
862
+ if (!currentMultiple) {
863
+ emitSelection([node.value], node, "select");
864
+ if (currentCloseOnSelect) {
865
+ openReasonRef.current = "item-press";
866
+ setOpen(false);
867
+ } else setQuery("");
868
+ return;
869
+ }
870
+ if (currentCascade) {
871
+ const selecting = !current.includes(node.value);
872
+ const next = applyCascadeSelection(currentIndex, current, node.value, selecting, currentIsSelectable);
873
+ if (selecting && currentMax != null && next.length > currentMax && next.length > current.length) {
874
+ announceNotice(currentLabels.maxReachedAnnouncement(currentMax));
875
+ return;
876
+ }
877
+ emitSelection(next, node, selecting ? "select" : "deselect");
878
+ const before = new Set(current);
879
+ const after = new Set(next);
880
+ let swept = 0;
881
+ for (const entry of selecting ? next : current) {
882
+ if (entry === node.value) continue;
883
+ if (selecting ? !before.has(entry) : !after.has(entry)) swept += 1;
884
+ }
885
+ if (swept > 0) announceNotice(currentLabels.cascadeAnnouncement(node.label ?? node.value, swept, selecting));
886
+ setQuery("");
887
+ return;
888
+ }
889
+ if (current.includes(node.value)) emitSelection(current.filter((v) => v !== node.value), node, "deselect");
890
+ else if (currentMax == null || current.length < currentMax) emitSelection([...current, node.value], node, "select");
891
+ else announceNotice(currentLabels.maxReachedAnnouncement(currentMax));
892
+ setQuery("");
893
+ }, [
894
+ emitSelection,
895
+ setOpen,
896
+ setQuery,
897
+ announceNotice
898
+ ]);
899
+ /** Safety net for paths that bypass the row-level veto (the drag-select
900
+ * mouseup). `details.cancel()` suppresses the commit and the close together:
901
+ * Base UI shares one event-details object between them. */
902
+ const handleComboboxValueChange = React$1.useCallback((next, details) => {
903
+ if (!multiple) {
904
+ const node = Array.isArray(next) ? next[0] ?? null : next;
905
+ if (node && isCascaderMoreNode(node)) {
906
+ details.cancel();
907
+ return;
908
+ }
909
+ if (node && !isSelectable(node) && isBranch(node)) {
910
+ details.cancel();
911
+ navigate(node);
912
+ return;
913
+ }
914
+ if (node) {
915
+ if (!closeOnSelect) details.cancel();
916
+ commit(node);
917
+ }
918
+ return;
919
+ }
920
+ const nextNodes = Array.isArray(next) ? next : [];
921
+ const before = new Set(selectedValues);
922
+ const added = nextNodes.find((node) => !before.has(node.value));
923
+ if (added && isCascaderMoreNode(added)) {
924
+ details.cancel();
925
+ return;
926
+ }
927
+ if (added && !isSelectable(added) && isBranch(added)) {
928
+ details.cancel();
929
+ navigate(added);
930
+ return;
931
+ }
932
+ if (cascade) {
933
+ const nextValues = new Set(nextNodes.map((node) => node.value));
934
+ const removed = selectedValues.find((entry) => !nextValues.has(entry));
935
+ const toggled = added ?? (removed != null ? resolveNode(removed) : null);
936
+ if (toggled) commit(toggled);
937
+ return;
938
+ }
939
+ if (max != null && nextNodes.length > selectedValues.length && nextNodes.length > max) {
940
+ details.cancel();
941
+ announceNotice(labels.maxReachedAnnouncement(max));
942
+ return;
943
+ }
944
+ setSelection(nextNodes.map((node) => node.value));
945
+ setQuery("");
946
+ }, [
947
+ multiple,
948
+ selectedValues,
949
+ max,
950
+ cascade,
951
+ closeOnSelect,
952
+ labels,
953
+ announceNotice,
954
+ isSelectable,
955
+ isBranch,
956
+ navigate,
957
+ commit,
958
+ resolveNode,
959
+ setSelection,
960
+ setQuery
961
+ ]);
962
+ const handleOpenChange = React$1.useCallback((nextOpen, details) => {
963
+ if (details.isCanceled) return;
964
+ if (!nextOpen && details.reason === "escape-key" && hasOpenFlyout()) {
965
+ details.cancel();
966
+ return;
967
+ }
968
+ openReasonRef.current = details.reason ?? "none";
969
+ setOpen(nextOpen);
970
+ if (!nextOpen) {
971
+ setQuery("");
972
+ return;
973
+ }
974
+ if (revealSelected) {
975
+ setQuery("");
976
+ const first = toArray(value)[0];
977
+ setPathWithReason(first ? getCascaderPath(index, first).slice(0, -1).map((node) => node.value) : [], "reveal");
978
+ }
979
+ }, [
980
+ setOpen,
981
+ setQuery,
982
+ revealSelected,
983
+ value,
984
+ index,
985
+ setPathWithReason,
986
+ hasOpenFlyout
987
+ ]);
988
+ const renderContext = React$1.useMemo(() => ({
989
+ renderItem,
990
+ renderLabel
991
+ }), [renderItem, renderLabel]);
992
+ /** The stable half: nothing in these deps moves on a keystroke, a level
993
+ * change or a highlight, which is what makes `React.memo` on `CascaderItem`
994
+ * hold while the user types. Destructured off `loader` so the memo depends
995
+ * on its `[]`-dep callbacks, not the object it republishes per load. */
996
+ const { active: hasLoader, loadMore, retryLevel, prefetchNode } = loader;
997
+ const actionsValue = React$1.useMemo(() => ({
998
+ index,
999
+ mode,
1000
+ multiple,
1001
+ cascade,
1002
+ branchesSelectable,
1003
+ indicator,
1004
+ expandTrigger,
1005
+ actions: resolvedActions,
1006
+ searchScope,
1007
+ maxHeight,
1008
+ inline: !!inline,
1009
+ invalid: !!invalid,
1010
+ baseId,
1011
+ labels,
1012
+ virtualized,
1013
+ registerVirtualRenderer,
1014
+ virtualize,
1015
+ virtualizeThreshold,
1016
+ estimateRowSize,
1017
+ overscan,
1018
+ hasLoader,
1019
+ loadMore,
1020
+ retryLevel,
1021
+ invalidateLevel,
1022
+ getIndex,
1023
+ getState,
1024
+ getHighlighted,
1025
+ setPath,
1026
+ pushLevel,
1027
+ popLevel,
1028
+ goToDepth,
1029
+ toggleExpanded,
1030
+ setFlyoutOpen,
1031
+ hasOpenFlyout,
1032
+ setQuery,
1033
+ setSelection,
1034
+ commit,
1035
+ navigate,
1036
+ navigateAt,
1037
+ resolveNode,
1038
+ isBranch,
1039
+ isSelectable,
1040
+ isSelected,
1041
+ isIndeterminate,
1042
+ selectedDescendantCount
1043
+ }), [
1044
+ index,
1045
+ mode,
1046
+ multiple,
1047
+ cascade,
1048
+ branchesSelectable,
1049
+ indicator,
1050
+ expandTrigger,
1051
+ resolvedActions,
1052
+ searchScope,
1053
+ maxHeight,
1054
+ inline,
1055
+ invalid,
1056
+ baseId,
1057
+ labels,
1058
+ virtualized,
1059
+ registerVirtualRenderer,
1060
+ virtualize,
1061
+ virtualizeThreshold,
1062
+ estimateRowSize,
1063
+ overscan,
1064
+ hasLoader,
1065
+ loadMore,
1066
+ retryLevel,
1067
+ invalidateLevel,
1068
+ getIndex,
1069
+ getState,
1070
+ getHighlighted,
1071
+ setPath,
1072
+ pushLevel,
1073
+ popLevel,
1074
+ goToDepth,
1075
+ toggleExpanded,
1076
+ setFlyoutOpen,
1077
+ hasOpenFlyout,
1078
+ setQuery,
1079
+ setSelection,
1080
+ commit,
1081
+ navigate,
1082
+ navigateAt,
1083
+ resolveNode,
1084
+ isBranch,
1085
+ isSelectable,
1086
+ isSelected,
1087
+ isIndeterminate,
1088
+ selectedDescendantCount
1089
+ ]);
1090
+ const comboboxItems = React$1.useMemo(() => virtualized ? renderedItems.slice() : renderedItems, [renderedItems, virtualized]);
1091
+ const comboboxValue = React$1.useMemo(() => {
1092
+ if (multiple) return selectedValues.map(resolveNode);
1093
+ return selectedValues.length ? resolveNode(selectedValues[0]) : null;
1094
+ }, [
1095
+ multiple,
1096
+ selectedValues,
1097
+ resolveNode
1098
+ ]);
1099
+ return /* @__PURE__ */ jsx(CascaderActionsContext.Provider, {
1100
+ value: actionsValue,
1101
+ children: /* @__PURE__ */ jsx(CascaderStateContext.Provider, {
1102
+ value: stateValue,
1103
+ children: /* @__PURE__ */ jsx(CascaderHighlightContext.Provider, {
1104
+ value: highlightStore,
1105
+ children: /* @__PURE__ */ jsx(CascaderRenderContext.Provider, {
1106
+ value: renderContext,
1107
+ children: /* @__PURE__ */ jsx(Combobox.Root, {
1108
+ items: renderedItems,
1109
+ filteredItems: swapping ? EMPTY : comboboxItems,
1110
+ filter: null,
1111
+ value: comboboxValue,
1112
+ onValueChange: handleComboboxValueChange,
1113
+ open,
1114
+ onOpenChange: handleOpenChange,
1115
+ inputValue: query,
1116
+ onInputValueChange: (next) => setQuery(next),
1117
+ multiple,
1118
+ disabled,
1119
+ name,
1120
+ ...form != null ? { form } : null,
1121
+ ...id != null ? { id } : null,
1122
+ ...required != null ? { required } : null,
1123
+ ...readOnly != null ? { readOnly } : null,
1124
+ ...inputRef ? { inputRef } : null,
1125
+ inline,
1126
+ virtualized,
1127
+ itemToStringValue: (item) => item?.value ?? "",
1128
+ itemToStringLabel: (item) => item?.label ?? "",
1129
+ isItemEqualToValue: (a, b) => a?.value === b?.value,
1130
+ onItemHighlighted: (item, details) => {
1131
+ highlightedRef.current = item ?? null;
1132
+ highlightStore.set({
1133
+ index: details.index,
1134
+ value: item?.value ?? null
1135
+ });
1136
+ prefetchNode(item);
1137
+ },
1138
+ children
1139
+ })
1140
+ })
1141
+ })
1142
+ })
1143
+ });
1144
+ }
1145
+ function CascaderTrigger({ className, children, showIcon = true, ref, ...props }) {
1146
+ const { invalid } = useCascaderActions();
1147
+ const triggerRef = React$1.useRef(null);
1148
+ const setTrigger = React$1.useCallback((node) => {
1149
+ triggerRef.current = node;
1150
+ if (typeof ref === "function") ref(node);
1151
+ else if (ref) ref.current = node;
1152
+ }, [ref]);
1153
+ /** 18 of 19 audited examples shipped an unnamed combobox: the trigger's
1154
+ * contents are the field's VALUE, so a screen reader never hears its NAME.
1155
+ * Checked in the DOM, since the name may arrive as a `<label for>`. */
1156
+ React$1.useEffect(() => {
1157
+ if (process.env.NODE_ENV === "production") return;
1158
+ const element = triggerRef.current;
1159
+ if (!element) return;
1160
+ if (element.hasAttribute("aria-label") || element.hasAttribute("aria-labelledby") || element.closest("label") !== null || element.id !== "" && element.ownerDocument.querySelector(`label[for="${CSS.escape(element.id)}"]`) !== null) return;
1161
+ warnCascaderOnce("trigger-unnamed", "`CascaderTrigger` has no accessible name. Its contents are the field's VALUE - they change with the selection - so a screen reader hears what is picked but never what the field is for. Pass `aria-label` or `aria-labelledby`, or reference the trigger's `id` from a `<label>`.");
1162
+ });
1163
+ return /* @__PURE__ */ jsxs(Combobox.Trigger, {
1164
+ ref: setTrigger,
1165
+ "data-slot": "cascader-trigger",
1166
+ ...invalid ? {
1167
+ "aria-invalid": true,
1168
+ "data-invalid": ""
1169
+ } : null,
1170
+ className: cn(TRIGGER_ICON_FALLBACK_CLASS, className),
1171
+ ...props,
1172
+ children: [children, showIcon ? /* @__PURE__ */ jsx(ChevronDownIcon, { className: `${TRIGGER_ICON_CLASS} pointer-events-none shrink-0` }) : null]
1173
+ });
1174
+ }
1175
+ /** Icon size for a combobox surface: 14px in mira and sera, 16px elsewhere. */
1176
+ const TRIGGER_ICON_CLASS = "text-muted-foreground size-4";
1177
+ /** The same ladder, applied only to trigger children that carry no size. */
1178
+ const TRIGGER_ICON_FALLBACK_CLASS = "[&_svg:not([class*='size-'])]:size-4";
1179
+ /** The chips field: a form-control surface, so it carries the invalid states. */
1180
+ const CHIPS_CLASS = "flex flex-wrap items-center border bg-clip-padding dark:bg-input/30 border-input focus-within:border-ring focus-within:ring-ring/50 has-aria-invalid:ring-destructive/20 dark:has-aria-invalid:ring-destructive/40 has-aria-invalid:border-destructive dark:has-aria-invalid:border-destructive/50 bg-transparent px-2.5 text-sm focus-within:ring-3 has-aria-invalid:ring-3 min-h-8 gap-1 rounded-lg py-1 transition-colors has-data-[slot=combobox-chip]:px-1";
1181
+ const CHIP_CLASS = "text-foreground flex w-fit items-center justify-center gap-1 font-medium whitespace-nowrap bg-muted rounded-sm px-1.5 text-xs has-data-[slot=combobox-chip-remove]:pr-0 h-[calc(--spacing(5.25))]";
1182
+ const CHIP_REMOVE_CLASS = "opacity-50 hover:opacity-100 -ml-1";
1183
+ /** The floating panel's surface. The shared popup's `InputGroup` sizing is
1184
+ * left out (mirrored in `cascader-nav.tsx`), as are its `max-h-72` and
1185
+ * `min-w-*`: `CascaderContent` sets both from the positioner's variables. */
1186
+ const CONTENT_SURFACE_CLASS = "bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 overflow-hidden ring-1 duration-100 ring-foreground/10 shadow-md rounded-lg data-[side=inline-start]:slide-in-from-right-2 data-[side=inline-end]:slide-in-from-left-2";
1187
+ const EMPTY_CLASS = "text-muted-foreground hidden w-full justify-center py-2 text-center group-data-empty/combobox-content:flex text-sm";
1188
+ /** Ref for the chips container: they replace the trigger, so the popup has to
1189
+ * be anchored to them. Hand it to `CascaderContent`'s `anchor`. */
1190
+ function useCascaderAnchor() {
1191
+ return React$1.useRef(null);
1192
+ }
1193
+ /**
1194
+ * The multi-select trigger surface: one removable chip per selection, where
1195
+ * `CascaderValue` would collapse to "3 selected". A component rather than a
1196
+ * recipe because of three easy misses: the popup anchored to the chips, an
1197
+ * accessible name on every remove button, and labels that disambiguate when
1198
+ * two branches use the same one.
1199
+ *
1200
+ * ```tsx
1201
+ * const anchor = useCascaderAnchor()
1202
+ * <Cascader multiple items={items}>
1203
+ * <CascaderChips ref={anchor} placeholder="Select attributes" />
1204
+ * <CascaderContent anchor={anchor}>...</CascaderContent>
1205
+ * </Cascader>
1206
+ * ```
1207
+ */
1208
+ function CascaderChips({ className, children, placeholder, strategy = "all", ...props }) {
1209
+ const { labels, multiple, invalid, resolveNode, index, isSelectable, setSelection } = useCascaderActions();
1210
+ const { selectedValues } = useCascaderState();
1211
+ React$1.useEffect(() => {
1212
+ if (process.env.NODE_ENV === "production") return;
1213
+ if (multiple) return;
1214
+ warnCascaderOnce("chips-without-multiple", "`CascaderChips` renders one chip per selection and there is only ever one without `multiple`. Use `CascaderValue` for a single-select trigger.");
1215
+ }, [multiple]);
1216
+ const nodes = (strategy === "all" ? selectedValues : getCascaderCheckedValues(index, selectedValues, strategy)).map(resolveNode);
1217
+ const ambiguous = findAmbiguousCascaderLabels(nodes);
1218
+ const removeClosure = (node) => {
1219
+ setSelection(applyCascadeSelection(index, selectedValues, node.value, false, isSelectable), "deselect");
1220
+ };
1221
+ const content = typeof children === "function" ? children(nodes) : children;
1222
+ return /* @__PURE__ */ jsx(Combobox.Chips, {
1223
+ "data-slot": "cascader-chips",
1224
+ "aria-label": labels.chipsLabel,
1225
+ ...invalid ? {
1226
+ "aria-invalid": true,
1227
+ "data-invalid": ""
1228
+ } : null,
1229
+ className: cn(CHIPS_CLASS, className),
1230
+ ...props,
1231
+ children: content ?? (nodes.length === 0 ? /* @__PURE__ */ jsx("span", {
1232
+ "data-slot": "cascader-chips-placeholder",
1233
+ className: "truncate text-muted-foreground",
1234
+ children: placeholder
1235
+ }) : nodes.map((node) => /* @__PURE__ */ jsx(CascaderChip, {
1236
+ node,
1237
+ showPath: ambiguous.has(node.value),
1238
+ ...strategy !== "all" ? { onRemove: () => removeClosure(node) } : null
1239
+ }, node.value)))
1240
+ });
1241
+ }
1242
+ /** One chip. Removal goes through Base UI's `ChipRemove`, which reports the
1243
+ * shortened selection to the root, so it lands in the same `setSelection` as
1244
+ * every other deselection and `cascade` applies to it. */
1245
+ function CascaderChip({ className, node, showPath = false, maxSegments = 2, showRemove = true, onRemove, children, ...props }) {
1246
+ const { labels, index } = useCascaderActions();
1247
+ const chain = showPath ? getCascaderPath(index, node.value) : [];
1248
+ const segments = collapseCascaderPath(chain, {
1249
+ maxSegments,
1250
+ collapse: "start"
1251
+ });
1252
+ const label = segments.length ? segments.map((segment) => segment.type === "node" ? segment.node.label : "…").join(` ${labels.pathSeparator} `) : node.label;
1253
+ return /* @__PURE__ */ jsxs(Combobox.Chip, {
1254
+ "data-slot": "cascader-chip",
1255
+ ...onRemove ? { onKeyDown: (event) => {
1256
+ if (event.key !== "Backspace" && event.key !== "Delete") return;
1257
+ event.preventBaseUIHandler();
1258
+ onRemove();
1259
+ } } : null,
1260
+ className: cn(CHIP_CLASS, "has-disabled:pointer-events-none has-disabled:cursor-not-allowed has-disabled:opacity-50", className),
1261
+ ...props,
1262
+ children: [children ?? /* @__PURE__ */ jsx("span", {
1263
+ className: "truncate",
1264
+ children: label
1265
+ }), showRemove ? /* @__PURE__ */ jsx(Combobox.ChipRemove, {
1266
+ "data-slot": "cascader-chip-remove",
1267
+ "aria-label": labels.removeChip(label),
1268
+ ...onRemove ? { onClick: (event) => {
1269
+ event.preventBaseUIHandler();
1270
+ onRemove();
1271
+ } } : null,
1272
+ className: CHIP_REMOVE_CLASS,
1273
+ children: /* @__PURE__ */ jsx(XIcon, { className: "pointer-events-none" })
1274
+ }) : null]
1275
+ });
1276
+ }
1277
+ /** Portal + Positioner + floating panel. Unlike shadcn's `ComboboxContent` it
1278
+ * does NOT clamp the popup to the anchor width (a cascader panel is routinely
1279
+ * wider), but it keeps `group/combobox-content`, which `CascaderEmpty` needs. */
1280
+ function CascaderContent({ className, side = "bottom", sideOffset = 6, align = "start", alignOffset = 0, anchor, collisionBoundary, collisionPadding, sticky, positionMethod, container, ref, ...props }) {
1281
+ const { labels } = useCascaderActions();
1282
+ const popupRef = React$1.useRef(null);
1283
+ const setPopup = React$1.useCallback((node) => {
1284
+ popupRef.current = node;
1285
+ if (typeof ref === "function") ref(node);
1286
+ else if (ref) ref.current = node;
1287
+ }, [ref]);
1288
+ /**
1289
+ * Focus goes to the search field, where the level keys and
1290
+ * `aria-activedescendant` live. Base UI's own default agrees but is COMPUTED
1291
+ * FROM THE FIRST RENDER, when the field has not mounted, and collapses to
1292
+ * "do not move focus": measured, a KEYBOARD open left focus on the trigger
1293
+ * and cost two Tabs to reach the footer where a pointer open cost one.
1294
+ *
1295
+ * `initialFocus` rather than an effect, because anything scheduled alongside
1296
+ * Base UI's focus manager is a race; the field is resolved INSIDE the
1297
+ * callback, which runs after the layout effects. Touch is handed back to
1298
+ * Base UI on purpose - focusing the popup keeps the Android keyboard shut.
1299
+ */
1300
+ const initialFocus = React$1.useCallback((openType) => {
1301
+ const popup = popupRef.current;
1302
+ if (!popup) return true;
1303
+ if (openType === "touch") return popup;
1304
+ return popup.querySelector("[data-slot=\"cascader-input\"]") ?? true;
1305
+ }, []);
1306
+ return /* @__PURE__ */ jsx(Combobox.Portal, {
1307
+ ...container !== void 0 ? { container } : null,
1308
+ children: /* @__PURE__ */ jsx(Combobox.Positioner, {
1309
+ side,
1310
+ sideOffset,
1311
+ align,
1312
+ alignOffset,
1313
+ anchor,
1314
+ ...collisionBoundary !== void 0 ? { collisionBoundary } : null,
1315
+ ...collisionPadding !== void 0 ? { collisionPadding } : null,
1316
+ ...sticky !== void 0 ? { sticky } : null,
1317
+ ...positionMethod !== void 0 ? { positionMethod } : null,
1318
+ className: "isolate z-50",
1319
+ children: /* @__PURE__ */ jsx(Combobox.Popup, {
1320
+ ref: setPopup,
1321
+ "data-slot": "cascader-content",
1322
+ "data-menu-target": "",
1323
+ "aria-label": labels.panelLabel,
1324
+ initialFocus,
1325
+ className: cn(CONTENT_SURFACE_CLASS, "group/combobox-content relative flex max-h-(--available-height) min-w-(--anchor-width) max-w-(--available-width) origin-(--transform-origin) flex-col", className),
1326
+ ...props
1327
+ })
1328
+ })
1329
+ });
1330
+ }
1331
+ /**
1332
+ * The nav + list(s) + footer container, with no positioning of its own: inside
1333
+ * `CascaderContent` for the popup case, alone for the embedded one.
1334
+ *
1335
+ * `min-h-0` and `max-h-full` are load-bearing. A flex child without `min-h-0`
1336
+ * refuses to shrink below its content, which is the usual reason a scroll area
1337
+ * never scrolls - worst embedded, where no positioner publishes
1338
+ * `--available-height`. It also owns the panel's TAB ORDER: the scroll area
1339
+ * makes itself a tab stop whenever the level overflows, stranding the footer,
1340
+ * and the panel is the only ancestor of both ends of that move in BOTH shapes.
1341
+ */
1342
+ function CascaderPanel({ className, ...props }) {
1343
+ const { mode } = useCascaderActions();
1344
+ const defaultProps = {
1345
+ "data-slot": "cascader-panel",
1346
+ "data-mode": mode,
1347
+ onKeyDown: React$1.useCallback((event) => {
1348
+ if (event.key !== "Tab" || event.defaultPrevented) return;
1349
+ if (event.altKey || event.ctrlKey || event.metaKey) return;
1350
+ const panel = event.currentTarget;
1351
+ const target = event.target;
1352
+ if (!target || !panel.contains(target)) return;
1353
+ const next = getCascaderTabTarget(panel, target, event.shiftKey);
1354
+ if (!next) return;
1355
+ event.preventDefault();
1356
+ next.focus();
1357
+ }, []),
1358
+ className: cn("flex max-h-full min-h-0 w-full flex-col", className)
1359
+ };
1360
+ return useRender({
1361
+ defaultTagName: "div",
1362
+ render: props.render,
1363
+ props: mergeProps(defaultProps, props)
1364
+ });
1365
+ }
1366
+ /**
1367
+ * Scroll container for one level: pattern 3 of the house scroll reference,
1368
+ * viewport-bounded popup scroll. The height is `min()` of `--available-height`
1369
+ * (the positioner's space between anchor and viewport edge) and `maxHeight`,
1370
+ * so neither can be ignored; a fixed pixel cap alone still reserved 288px for
1371
+ * a panel opened 200px above the fold and spilled off screen, and wasted room
1372
+ * in a tall window. The four classes are shared with `CascaderColumns` and
1373
+ * live in `cascader-lib.tsx`.
1374
+ */
1375
+ function CascaderList({ className, style, maxHeight: maxHeightProp, ...props }) {
1376
+ const { maxHeight, mode, labels, baseId, virtualized } = useCascaderActions();
1377
+ const { currentParent } = useCascaderState();
1378
+ const resolved = maxHeightProp ?? maxHeight;
1379
+ return /* @__PURE__ */ jsx("div", {
1380
+ "data-slot": "cascader-list-shell",
1381
+ style: resolved != null ? {
1382
+ ...style,
1383
+ "--cascader-max-height": typeof resolved === "number" ? `${resolved}px` : resolved
1384
+ } : style,
1385
+ className: cn("relative flex max-h-full min-h-0", CASCADER_LIST_PAD_CLASS),
1386
+ children: /* @__PURE__ */ jsx("div", {
1387
+ "data-slot": "cascader-list-bounds",
1388
+ className: cn("flex w-full min-w-0 flex-col overscroll-contain", CASCADER_LIST_HEIGHT_CLASS),
1389
+ children: /* @__PURE__ */ jsx(ScrollArea, {
1390
+ className: CASCADER_SCROLL_CLASS,
1391
+ children: /* @__PURE__ */ jsx(Combobox.List, {
1392
+ "data-slot": "cascader-list",
1393
+ "aria-label": currentParent?.label ?? labels.rootLevel,
1394
+ id: `${baseId}-column-0`,
1395
+ ...mode === "tree" ? { role: "tree" } : null,
1396
+ ...virtualized ? { "data-virtualized": true } : null,
1397
+ className: cn(CASCADER_ROWS_CLASS, virtualized && "relative", className),
1398
+ ...props
1399
+ })
1400
+ })
1401
+ })
1402
+ });
1403
+ }
1404
+ /** The empty, loading and error surface, in ONE element that never unmounts.
1405
+ * `Combobox.Empty` renders whenever `filteredItems.length === 0`, as true of a
1406
+ * fetching level as of an empty one, so swapping siblings would announce "No
1407
+ * results found." over every async level. Swap the CHILDREN. */
1408
+ function CascaderEmpty({ className, children, skeletonRows, ...props }) {
1409
+ const { labels, retryLevel } = useCascaderActions();
1410
+ const { query, path, searchState } = useCascaderState();
1411
+ const levelKey = path.length ? path[path.length - 1] : CASCADER_ROOT_KEY;
1412
+ const loadState = useCascaderLoadState(levelKey);
1413
+ const state = query.trim() ? searchState ?? loadState : loadState;
1414
+ let body = children ?? labels.empty;
1415
+ if (state?.error) body = /* @__PURE__ */ jsxs("span", {
1416
+ "data-slot": "cascader-error",
1417
+ className: "flex flex-col items-center gap-1.5",
1418
+ children: [/* @__PURE__ */ jsx("span", { children: labels.error }), /* @__PURE__ */ jsx("button", {
1419
+ type: "button",
1420
+ "data-slot": "cascader-retry",
1421
+ onClick: () => retryLevel(levelKey),
1422
+ className: "rounded-md px-2 py-0.5 font-medium text-foreground outline-hidden transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring/50",
1423
+ children: labels.retry
1424
+ })]
1425
+ });
1426
+ else if (state?.loading) body = /* @__PURE__ */ jsx("span", {
1427
+ "data-slot": "cascader-loading",
1428
+ className: "flex w-full items-center justify-center",
1429
+ children: labels.loading
1430
+ });
1431
+ return /* @__PURE__ */ jsx(Combobox.Empty, {
1432
+ "data-slot": "cascader-empty",
1433
+ "data-state": state?.error ? "error" : state?.loading ? "loading" : "empty",
1434
+ className: cn(EMPTY_CLASS, className),
1435
+ "aria-live": void 0,
1436
+ "aria-atomic": void 0,
1437
+ ...props,
1438
+ children: body
1439
+ });
1440
+ }
1441
+ /**
1442
+ * Polite live region for the current level and result count, which drill-down
1443
+ * otherwise hides in a visual breadcrumb. Built on `Combobox.Status` for its
1444
+ * initial-mutation marker: Safari and VoiceOver need a text change ~200ms
1445
+ * after mount before reading a polite region at all.
1446
+ */
1447
+ function CascaderStatus({ className, children, ...props }) {
1448
+ const { announcement } = useCascaderState();
1449
+ return /* @__PURE__ */ jsx(Combobox.Status, {
1450
+ "data-slot": "cascader-status",
1451
+ className: cn("sr-only", className),
1452
+ ...props,
1453
+ children: children ?? announcement
1454
+ });
1455
+ }
1456
+ //#endregion
1457
+ export { Cascader, CascaderChip, CascaderChips, CascaderContent, CascaderEmpty, CascaderList, CascaderPanel, CascaderStatus, CascaderTrigger, createCascaderHighlightStore, useCascader, useCascaderActions, useCascaderAnchor, useCascaderHighlight, useCascaderRender, useCascaderSelection, useCascaderState };
1458
+
1459
+ //# sourceMappingURL=cascader.js.map