@funstack/ui 0.1.0-alpha.19 → 0.1.0-alpha.20

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 (276) hide show
  1. package/dist/accordion/accordion-item.mjs +2 -2
  2. package/dist/accordion/accordion-item.mjs.map +1 -1
  3. package/dist/accordion/accordion-trigger.d.mts.map +1 -1
  4. package/dist/accordion/accordion-trigger.mjs +3 -20
  5. package/dist/accordion/accordion-trigger.mjs.map +1 -1
  6. package/dist/alert-dialog/alert-dialog-action.d.mts +73 -0
  7. package/dist/alert-dialog/alert-dialog-action.d.mts.map +1 -0
  8. package/dist/alert-dialog/alert-dialog-action.mjs +23 -0
  9. package/dist/alert-dialog/alert-dialog-action.mjs.map +1 -0
  10. package/dist/alert-dialog/alert-dialog-cancel.d.mts +31 -0
  11. package/dist/alert-dialog/alert-dialog-cancel.d.mts.map +1 -0
  12. package/dist/alert-dialog/alert-dialog-cancel.mjs +50 -0
  13. package/dist/alert-dialog/alert-dialog-cancel.mjs.map +1 -0
  14. package/dist/alert-dialog/alert-dialog-context.mjs +24 -0
  15. package/dist/alert-dialog/alert-dialog-context.mjs.map +1 -0
  16. package/dist/alert-dialog/alert-dialog-description.d.mts +25 -0
  17. package/dist/alert-dialog/alert-dialog-description.d.mts.map +1 -0
  18. package/dist/alert-dialog/alert-dialog-description.mjs +20 -0
  19. package/dist/alert-dialog/alert-dialog-description.mjs.map +1 -0
  20. package/dist/alert-dialog/alert-dialog-form.d.mts +27 -0
  21. package/dist/alert-dialog/alert-dialog-form.d.mts.map +1 -0
  22. package/dist/alert-dialog/alert-dialog-form.mjs +22 -0
  23. package/dist/alert-dialog/alert-dialog-form.mjs.map +1 -0
  24. package/dist/alert-dialog/alert-dialog-popup.d.mts +42 -0
  25. package/dist/alert-dialog/alert-dialog-popup.d.mts.map +1 -0
  26. package/dist/alert-dialog/alert-dialog-popup.mjs +53 -0
  27. package/dist/alert-dialog/alert-dialog-popup.mjs.map +1 -0
  28. package/dist/alert-dialog/alert-dialog-root.d.mts +31 -0
  29. package/dist/alert-dialog/alert-dialog-root.d.mts.map +1 -0
  30. package/dist/alert-dialog/alert-dialog-root.mjs +22 -0
  31. package/dist/alert-dialog/alert-dialog-root.mjs.map +1 -0
  32. package/dist/alert-dialog/alert-dialog-title.d.mts +23 -0
  33. package/dist/alert-dialog/alert-dialog-title.d.mts.map +1 -0
  34. package/dist/alert-dialog/alert-dialog-title.mjs +18 -0
  35. package/dist/alert-dialog/alert-dialog-title.mjs.map +1 -0
  36. package/dist/alert-dialog/alert-dialog-trigger.d.mts +23 -0
  37. package/dist/alert-dialog/alert-dialog-trigger.d.mts.map +1 -0
  38. package/dist/alert-dialog/alert-dialog-trigger.mjs +18 -0
  39. package/dist/alert-dialog/alert-dialog-trigger.mjs.map +1 -0
  40. package/dist/alert-dialog/index.d.mts +33 -0
  41. package/dist/alert-dialog/index.d.mts.map +1 -0
  42. package/dist/alert-dialog/index.mjs +33 -0
  43. package/dist/alert-dialog/index.mjs.map +1 -0
  44. package/dist/checkbox-group/checkbox-group-parent.mjs +1 -1
  45. package/dist/collapsible/collapsible-context.mjs +8 -0
  46. package/dist/collapsible/collapsible-context.mjs.map +1 -0
  47. package/dist/collapsible/collapsible-panel.d.mts +53 -0
  48. package/dist/collapsible/collapsible-panel.d.mts.map +1 -0
  49. package/dist/collapsible/collapsible-panel.mjs +41 -0
  50. package/dist/collapsible/collapsible-panel.mjs.map +1 -0
  51. package/dist/collapsible/collapsible-root.d.mts +108 -0
  52. package/dist/collapsible/collapsible-root.d.mts.map +1 -0
  53. package/dist/collapsible/collapsible-root.mjs +147 -0
  54. package/dist/collapsible/collapsible-root.mjs.map +1 -0
  55. package/dist/collapsible/collapsible-trigger.d.mts +45 -0
  56. package/dist/collapsible/collapsible-trigger.d.mts.map +1 -0
  57. package/dist/collapsible/collapsible-trigger.mjs +62 -0
  58. package/dist/collapsible/collapsible-trigger.mjs.map +1 -0
  59. package/dist/collapsible/index.d.mts +21 -0
  60. package/dist/collapsible/index.d.mts.map +1 -0
  61. package/dist/collapsible/index.mjs +21 -0
  62. package/dist/collapsible/index.mjs.map +1 -0
  63. package/dist/combobox/chip-text.mjs +24 -0
  64. package/dist/combobox/chip-text.mjs.map +1 -0
  65. package/dist/combobox/combobox-chips.d.mts +159 -0
  66. package/dist/combobox/combobox-chips.d.mts.map +1 -0
  67. package/dist/combobox/combobox-chips.mjs +198 -0
  68. package/dist/combobox/combobox-chips.mjs.map +1 -0
  69. package/dist/combobox/combobox-clear.d.mts +5 -2
  70. package/dist/combobox/combobox-clear.d.mts.map +1 -1
  71. package/dist/combobox/combobox-clear.mjs +3 -1
  72. package/dist/combobox/combobox-clear.mjs.map +1 -1
  73. package/dist/combobox/combobox-context.mjs +4 -5
  74. package/dist/combobox/combobox-context.mjs.map +1 -1
  75. package/dist/combobox/combobox-input.d.mts +10 -3
  76. package/dist/combobox/combobox-input.d.mts.map +1 -1
  77. package/dist/combobox/combobox-input.mjs +13 -5
  78. package/dist/combobox/combobox-input.mjs.map +1 -1
  79. package/dist/combobox/combobox-keyboard.mjs +50 -4
  80. package/dist/combobox/combobox-keyboard.mjs.map +1 -1
  81. package/dist/combobox/combobox-list.d.mts +1 -1
  82. package/dist/combobox/combobox-list.mjs +2 -1
  83. package/dist/combobox/combobox-list.mjs.map +1 -1
  84. package/dist/combobox/combobox-option.d.mts +5 -2
  85. package/dist/combobox/combobox-option.d.mts.map +1 -1
  86. package/dist/combobox/combobox-option.mjs +4 -3
  87. package/dist/combobox/combobox-option.mjs.map +1 -1
  88. package/dist/combobox/combobox-root.d.mts +127 -35
  89. package/dist/combobox/combobox-root.d.mts.map +1 -1
  90. package/dist/combobox/combobox-root.mjs +396 -44
  91. package/dist/combobox/combobox-root.mjs.map +1 -1
  92. package/dist/combobox/index.d.mts +8 -2
  93. package/dist/combobox/index.d.mts.map +1 -1
  94. package/dist/combobox/index.mjs +7 -1
  95. package/dist/combobox/index.mjs.map +1 -1
  96. package/dist/combobox/use-combobox-form.mjs +2 -3
  97. package/dist/combobox/use-combobox-form.mjs.map +1 -1
  98. package/dist/dialog/dialog-close.d.mts +9 -5
  99. package/dist/dialog/dialog-close.d.mts.map +1 -1
  100. package/dist/dialog/dialog-close.mjs +19 -8
  101. package/dist/dialog/dialog-close.mjs.map +1 -1
  102. package/dist/dialog/dialog-context.d.mts +2 -0
  103. package/dist/dialog/dialog-context.mjs +14 -2
  104. package/dist/dialog/dialog-context.mjs.map +1 -1
  105. package/dist/dialog/dialog-description.d.mts +2 -1
  106. package/dist/dialog/dialog-description.d.mts.map +1 -1
  107. package/dist/dialog/dialog-description.mjs +8 -4
  108. package/dist/dialog/dialog-description.mjs.map +1 -1
  109. package/dist/dialog/dialog-form.d.mts +2 -1
  110. package/dist/dialog/dialog-form.d.mts.map +1 -1
  111. package/dist/dialog/dialog-form.mjs +11 -6
  112. package/dist/dialog/dialog-form.mjs.map +1 -1
  113. package/dist/dialog/dialog-popup.d.mts +2 -1
  114. package/dist/dialog/dialog-popup.d.mts.map +1 -1
  115. package/dist/dialog/dialog-popup.mjs +23 -14
  116. package/dist/dialog/dialog-popup.mjs.map +1 -1
  117. package/dist/dialog/dialog-root.d.mts +2 -1
  118. package/dist/dialog/dialog-root.d.mts.map +1 -1
  119. package/dist/dialog/dialog-root.mjs +15 -5
  120. package/dist/dialog/dialog-root.mjs.map +1 -1
  121. package/dist/dialog/dialog-title.d.mts +2 -1
  122. package/dist/dialog/dialog-title.d.mts.map +1 -1
  123. package/dist/dialog/dialog-title.mjs +8 -4
  124. package/dist/dialog/dialog-title.mjs.map +1 -1
  125. package/dist/dialog/dialog-trigger.d.mts +2 -1
  126. package/dist/dialog/dialog-trigger.d.mts.map +1 -1
  127. package/dist/dialog/dialog-trigger.mjs +14 -9
  128. package/dist/dialog/dialog-trigger.mjs.map +1 -1
  129. package/dist/docs/components/accordion.md +2 -0
  130. package/dist/docs/components/alert-dialog.md +546 -0
  131. package/dist/docs/components/collapsible.md +408 -0
  132. package/dist/docs/components/combobox.md +288 -26
  133. package/dist/docs/components/dialog.md +7 -5
  134. package/dist/docs/components/field.md +180 -3
  135. package/dist/docs/components/hover-card.md +494 -0
  136. package/dist/docs/components/multi-select.md +622 -0
  137. package/dist/docs/components/number-field.md +1 -1
  138. package/dist/docs/components/popover.md +4 -4
  139. package/dist/docs/components/select.md +9 -1
  140. package/dist/docs/components/separator.md +182 -0
  141. package/dist/docs/components/slider.md +1 -1
  142. package/dist/docs/components/tooltip.md +1 -1
  143. package/dist/docs/concepts/experimental.md +3 -3
  144. package/dist/docs/concepts/server-components.md +1 -1
  145. package/dist/docs/index.md +7 -2
  146. package/dist/docs/roadmap.md +8 -0
  147. package/dist/field/field-control.d.mts +13 -4
  148. package/dist/field/field-control.d.mts.map +1 -1
  149. package/dist/field/field-control.mjs +39 -10
  150. package/dist/field/field-control.mjs.map +1 -1
  151. package/dist/field/field-label.d.mts +6 -2
  152. package/dist/field/field-label.d.mts.map +1 -1
  153. package/dist/field/field-label.mjs +12 -2
  154. package/dist/field/field-label.mjs.map +1 -1
  155. package/dist/field/field-root.mjs +9 -1
  156. package/dist/field/field-root.mjs.map +1 -1
  157. package/dist/hover-card/hover-card-context.mjs +13 -0
  158. package/dist/hover-card/hover-card-context.mjs.map +1 -0
  159. package/dist/hover-card/hover-card-popup.d.mts +102 -0
  160. package/dist/hover-card/hover-card-popup.d.mts.map +1 -0
  161. package/dist/hover-card/hover-card-popup.mjs +80 -0
  162. package/dist/hover-card/hover-card-popup.mjs.map +1 -0
  163. package/dist/hover-card/hover-card-root.d.mts +94 -0
  164. package/dist/hover-card/hover-card-root.d.mts.map +1 -0
  165. package/dist/hover-card/hover-card-root.mjs +74 -0
  166. package/dist/hover-card/hover-card-root.mjs.map +1 -0
  167. package/dist/hover-card/hover-card-trigger.d.mts +65 -0
  168. package/dist/hover-card/hover-card-trigger.d.mts.map +1 -0
  169. package/dist/hover-card/hover-card-trigger.mjs +109 -0
  170. package/dist/hover-card/hover-card-trigger.mjs.map +1 -0
  171. package/dist/hover-card/index.d.mts +24 -0
  172. package/dist/hover-card/index.d.mts.map +1 -0
  173. package/dist/hover-card/index.mjs +24 -0
  174. package/dist/hover-card/index.mjs.map +1 -0
  175. package/dist/hover-card/use-hover-card-interest.mjs +242 -0
  176. package/dist/hover-card/use-hover-card-interest.mjs.map +1 -0
  177. package/dist/index.d.mts +38 -9
  178. package/dist/index.mjs +6 -1
  179. package/dist/internal/action/use-multiple-selection.mjs +83 -0
  180. package/dist/internal/action/use-multiple-selection.mjs.map +1 -0
  181. package/dist/internal/details-summary.mjs +56 -0
  182. package/dist/internal/details-summary.mjs.map +1 -0
  183. package/dist/internal/form/field-context.mjs.map +1 -1
  184. package/dist/internal/form/hidden-values.mjs +29 -0
  185. package/dist/internal/form/hidden-values.mjs.map +1 -0
  186. package/dist/internal/form/validity.mjs +3 -1
  187. package/dist/internal/form/validity.mjs.map +1 -1
  188. package/dist/internal/overlay/use-interest-dismiss.mjs +2 -1
  189. package/dist/internal/overlay/use-interest-dismiss.mjs.map +1 -1
  190. package/dist/internal/overlay/use-overlay-close.mjs +5 -3
  191. package/dist/internal/overlay/use-overlay-close.mjs.map +1 -1
  192. package/dist/internal/overlay/use-overlay-root.mjs +4 -1
  193. package/dist/internal/overlay/use-overlay-root.mjs.map +1 -1
  194. package/dist/internal/overlay/use-popover-popup.mjs +20 -7
  195. package/dist/internal/overlay/use-popover-popup.mjs.map +1 -1
  196. package/dist/internal/overlay/use-popover-trigger.d.mts +1 -1
  197. package/dist/internal/typeahead.mjs +52 -0
  198. package/dist/internal/typeahead.mjs.map +1 -0
  199. package/dist/{combobox → internal}/use-active-option.mjs +8 -6
  200. package/dist/internal/use-active-option.mjs.map +1 -0
  201. package/dist/{combobox → internal}/use-deferred-leave.mjs +20 -12
  202. package/dist/internal/use-deferred-leave.mjs.map +1 -0
  203. package/dist/internal/use-name-warning.mjs +57 -1
  204. package/dist/internal/use-name-warning.mjs.map +1 -1
  205. package/dist/internal/use-option-registry.mjs +70 -0
  206. package/dist/internal/use-option-registry.mjs.map +1 -0
  207. package/dist/menu/use-menu-keyboard.mjs +7 -27
  208. package/dist/menu/use-menu-keyboard.mjs.map +1 -1
  209. package/dist/multi-select/index.d.mts +37 -0
  210. package/dist/multi-select/index.d.mts.map +1 -0
  211. package/dist/multi-select/index.mjs +37 -0
  212. package/dist/multi-select/index.mjs.map +1 -0
  213. package/dist/multi-select/multi-select-context.mjs +19 -0
  214. package/dist/multi-select/multi-select-context.mjs.map +1 -0
  215. package/dist/multi-select/multi-select-group.d.mts +120 -0
  216. package/dist/multi-select/multi-select-group.d.mts.map +1 -0
  217. package/dist/multi-select/multi-select-group.mjs +111 -0
  218. package/dist/multi-select/multi-select-group.mjs.map +1 -0
  219. package/dist/multi-select/multi-select-keyboard.mjs +145 -0
  220. package/dist/multi-select/multi-select-keyboard.mjs.map +1 -0
  221. package/dist/multi-select/multi-select-label.d.mts +42 -0
  222. package/dist/multi-select/multi-select-label.d.mts.map +1 -0
  223. package/dist/multi-select/multi-select-label.mjs +41 -0
  224. package/dist/multi-select/multi-select-label.mjs.map +1 -0
  225. package/dist/multi-select/multi-select-list.d.mts +47 -0
  226. package/dist/multi-select/multi-select-list.d.mts.map +1 -0
  227. package/dist/multi-select/multi-select-list.mjs +65 -0
  228. package/dist/multi-select/multi-select-list.mjs.map +1 -0
  229. package/dist/multi-select/multi-select-option.d.mts +68 -0
  230. package/dist/multi-select/multi-select-option.d.mts.map +1 -0
  231. package/dist/multi-select/multi-select-option.mjs +93 -0
  232. package/dist/multi-select/multi-select-option.mjs.map +1 -0
  233. package/dist/multi-select/multi-select-popup.d.mts +58 -0
  234. package/dist/multi-select/multi-select-popup.d.mts.map +1 -0
  235. package/dist/multi-select/multi-select-popup.mjs +71 -0
  236. package/dist/multi-select/multi-select-popup.mjs.map +1 -0
  237. package/dist/multi-select/multi-select-root.d.mts +125 -0
  238. package/dist/multi-select/multi-select-root.d.mts.map +1 -0
  239. package/dist/multi-select/multi-select-root.mjs +257 -0
  240. package/dist/multi-select/multi-select-root.mjs.map +1 -0
  241. package/dist/multi-select/multi-select-trigger.d.mts +66 -0
  242. package/dist/multi-select/multi-select-trigger.d.mts.map +1 -0
  243. package/dist/multi-select/multi-select-trigger.mjs +169 -0
  244. package/dist/multi-select/multi-select-trigger.mjs.map +1 -0
  245. package/dist/multi-select/multi-select-value.d.mts +57 -0
  246. package/dist/multi-select/multi-select-value.d.mts.map +1 -0
  247. package/dist/multi-select/multi-select-value.mjs +41 -0
  248. package/dist/multi-select/multi-select-value.mjs.map +1 -0
  249. package/dist/number-field/number-field-root.mjs +1 -1
  250. package/dist/number-field/use-step-button.d.mts.map +1 -1
  251. package/dist/number-field/use-step-button.mjs +11 -2
  252. package/dist/number-field/use-step-button.mjs.map +1 -1
  253. package/dist/popover/popover-close.d.mts +6 -3
  254. package/dist/popover/popover-close.d.mts.map +1 -1
  255. package/dist/popover/popover-close.mjs +3 -2
  256. package/dist/popover/popover-close.mjs.map +1 -1
  257. package/dist/popover/popover-popup.mjs +1 -1
  258. package/dist/select/select-root.d.mts +1 -1
  259. package/dist/select/select-root.d.mts.map +1 -1
  260. package/dist/select/select-root.mjs +5 -1
  261. package/dist/select/select-root.mjs.map +1 -1
  262. package/dist/separator/index.d.mts +3 -0
  263. package/dist/separator/index.mjs +1 -0
  264. package/dist/separator/separator.d.mts +58 -0
  265. package/dist/separator/separator.d.mts.map +1 -0
  266. package/dist/separator/separator.mjs +41 -0
  267. package/dist/separator/separator.mjs.map +1 -0
  268. package/dist/slider/slider-root.mjs +1 -0
  269. package/dist/slider/slider-root.mjs.map +1 -1
  270. package/dist/toast/toast-viewport.mjs +1 -1
  271. package/package.json +6 -1
  272. package/skills/funstack-ui-knowledge/SKILL.md +14 -9
  273. package/dist/combobox/use-active-option.mjs.map +0 -1
  274. package/dist/combobox/use-deferred-leave.mjs.map +0 -1
  275. package/dist/combobox/use-option-registry.mjs +0 -52
  276. package/dist/combobox/use-option-registry.mjs.map +0 -1
@@ -78,7 +78,63 @@ function useShownNameWarningDev(element, shown, message, applies) {
78
78
  applies
79
79
  ]);
80
80
  }
81
+ /**
82
+ * Development check that a dialog has a description (AlertDialog,
83
+ * design/components/alert-dialog.md 2.2): an id of its `aria-describedby` that names an element
84
+ * in the document. Judged over the dialog's first showing rather than its first frame, so a
85
+ * description behind a Suspense boundary still pending when the dialog opens counts once it
86
+ * arrives: checked when the dialog opens (`toggle`), then on every change inside it, and
87
+ * `message` is logged at its first `close` if none was found by then. Once per instance. Pass
88
+ * `message` as `isDev && "..."`; a no-op in production.
89
+ */
90
+ const useShownDescriptionWarning = isDev ? useShownDescriptionWarningDev : noop;
91
+ function hasDescription(element) {
92
+ const doc = element.ownerDocument;
93
+ return (element.getAttribute("aria-describedby") ?? "").split(/\s+/).some((id) => id !== "" && doc.getElementById(id) !== null);
94
+ }
95
+ function useShownDescriptionWarningDev(element, message) {
96
+ const done = useRef(false);
97
+ useEffect(() => {
98
+ const target = element.current;
99
+ if (message === false || target === null || done.current) return;
100
+ let observer = null;
101
+ const stop = () => {
102
+ observer?.disconnect();
103
+ observer = null;
104
+ };
105
+ const found = () => {
106
+ if (!hasDescription(target)) return false;
107
+ done.current = true;
108
+ stop();
109
+ return true;
110
+ };
111
+ const onToggle = (event) => {
112
+ if (event.target !== target || done.current || observer !== null) return;
113
+ if (event.newState !== "open" || found()) return;
114
+ observer = new MutationObserver(() => {
115
+ found();
116
+ });
117
+ observer.observe(target, {
118
+ childList: true,
119
+ subtree: true
120
+ });
121
+ };
122
+ const onClose = (event) => {
123
+ if (event.target !== target || done.current || found()) return;
124
+ done.current = true;
125
+ stop();
126
+ console.error(message);
127
+ };
128
+ target.addEventListener("toggle", onToggle);
129
+ target.addEventListener("close", onClose);
130
+ return () => {
131
+ stop();
132
+ target.removeEventListener("toggle", onToggle);
133
+ target.removeEventListener("close", onClose);
134
+ };
135
+ }, [element, message]);
136
+ }
81
137
  //#endregion
82
- export { BUTTON_NAME, TEXT_NAME, useNameWarning, useShownNameWarning };
138
+ export { BUTTON_NAME, TEXT_NAME, useNameWarning, useShownDescriptionWarning, useShownNameWarning };
83
139
 
84
140
  //# sourceMappingURL=use-name-warning.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-name-warning.mjs","names":[],"sources":["../../src/internal/use-name-warning.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport type { RefObject } from \"react\";\nimport type { ElementCheck } from \"./use-element-check.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** What counts as a name besides `aria-label` and `aria-labelledby`. */\nexport interface NameRules {\n /** `aria-labelledby` counts only when one of its ids is in the document (a mounted Title). */\n readonly resolveIds?: boolean;\n /** Text content counts (a button with a visible label). */\n readonly text?: boolean;\n /** `title` counts. */\n readonly title?: boolean;\n}\n\n/** A button is also named by its text or `title`. */\nexport const BUTTON_NAME: NameRules = { text: true, title: true };\n\n/** Text content names it too (`title` does not). */\nexport const TEXT_NAME: NameRules = { text: true };\n\n/** Whether `element` has an accessible name by `rules` (development checks only). */\nfunction hasName(element: Element, rules: NameRules): boolean {\n if (element.hasAttribute(\"aria-label\")) return true;\n const labelledBy = element.getAttribute(\"aria-labelledby\");\n if (labelledBy !== null) {\n if (!rules.resolveIds) return true;\n const doc = element.ownerDocument;\n if (labelledBy.split(/\\s+/).some((id) => id !== \"\" && doc.getElementById(id) !== null)) {\n return true;\n }\n }\n if (rules.text && (element.textContent ?? \"\").trim() !== \"\") return true;\n return rules.title === true && element.hasAttribute(\"title\");\n}\n\n/**\n * Development check that a part the consumer must name (an icon-only button, a listbox) has an\n * accessible name: a microtask after the element attaches (the text may come from children\n * rendered in the same commit, and a Label's registration re-render is flushed by then), once\n * per instance. The result is a callback ref, or a function to call from the part's own ref.\n *\n * Pass `message` as `isDev && \"...\"` with the calling module's own `isDev` constant, so the text\n * folds away in a production build; there the hook is a no-op that returns `undefined`.\n */\nexport const useNameWarning: (\n message: string | false,\n rules?: NameRules,\n) => ElementCheck<HTMLElement> | undefined = isDev ? useNameWarningDev : noop;\n\nfunction noop(): undefined {\n return undefined;\n}\n\nfunction useNameWarningDev(\n message: string | false,\n rules: NameRules = {},\n): ElementCheck<HTMLElement> | undefined {\n const warned = useRef(false);\n const { resolveIds, text, title } = rules;\n const check = useCallback(\n (element: HTMLElement) => {\n if (warned.current) return () => {};\n queueMicrotask(() => {\n if (warned.current || !element.isConnected) return;\n if (hasName(element, { resolveIds, text, title })) return;\n warned.current = true;\n console.error(message);\n });\n return () => {};\n },\n [message, resolveIds, text, title],\n );\n return message === false ? undefined : check;\n}\n\n/**\n * Development check that a popup has an accessible name once it is (or can be) shown: in an\n * effect while `shown`, once per instance. `applies` limits it to the elements that need a name\n * (a role). Pass `message` as `isDev && \"...\"`, as for `useNameWarning`; a no-op in production.\n */\nexport const useShownNameWarning: (\n element: RefObject<Element | null> | Element | null,\n shown: boolean,\n message: string | false,\n applies?: (element: Element) => boolean,\n) => void = isDev ? useShownNameWarningDev : noop;\n\nfunction useShownNameWarningDev(\n element: RefObject<Element | null> | Element | null,\n shown: boolean,\n message: string | false,\n applies?: (element: Element) => boolean,\n): void {\n const warned = useRef(false);\n useEffect(() => {\n if (message === false || !shown || warned.current) return;\n const target = element !== null && \"current\" in element ? element.current : element;\n if (target === null || hasName(target, { resolveIds: true })) return;\n if (applies !== undefined && !applies(target)) return;\n warned.current = true;\n console.error(message);\n }, [element, shown, message, applies]);\n}\n"],"mappings":";;;AAKA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAavC,MAAa,cAAyB;CAAE,MAAM;CAAM,OAAO;AAAK;;AAGhE,MAAa,YAAuB,EAAE,MAAM,KAAK;;AAGjD,SAAS,QAAQ,SAAkB,OAA2B;CAC5D,IAAI,QAAQ,aAAa,YAAY,GAAG,OAAO;CAC/C,MAAM,aAAa,QAAQ,aAAa,iBAAiB;CACzD,IAAI,eAAe,MAAM;EACvB,IAAI,CAAC,MAAM,YAAY,OAAO;EAC9B,MAAM,MAAM,QAAQ;EACpB,IAAI,WAAW,MAAM,KAAK,CAAC,CAAC,MAAM,OAAO,OAAO,MAAM,IAAI,eAAe,EAAE,MAAM,IAAI,GACnF,OAAO;CAEX;CACA,IAAI,MAAM,SAAS,QAAQ,eAAe,GAAA,CAAI,KAAK,MAAM,IAAI,OAAO;CACpE,OAAO,MAAM,UAAU,QAAQ,QAAQ,aAAa,OAAO;AAC7D;;;;;;;;;;AAWA,MAAa,iBAGgC,QAAQ,oBAAoB;AAEzE,SAAS,OAAkB,CAE3B;AAEA,SAAS,kBACP,SACA,QAAmB,CAAC,GACmB;CACvC,MAAM,SAAS,OAAO,KAAK;CAC3B,MAAM,EAAE,YAAY,MAAM,UAAU;CACpC,MAAM,QAAQ,aACX,YAAyB;EACxB,IAAI,OAAO,SAAS,aAAa,CAAC;EAClC,qBAAqB;GACnB,IAAI,OAAO,WAAW,CAAC,QAAQ,aAAa;GAC5C,IAAI,QAAQ,SAAS;IAAE;IAAY;IAAM;GAAM,CAAC,GAAG;GACnD,OAAO,UAAU;GACjB,QAAQ,MAAM,OAAO;EACvB,CAAC;EACD,aAAa,CAAC;CAChB,GACA;EAAC;EAAS;EAAY;EAAM;CAAK,CACnC;CACA,OAAO,YAAY,QAAQ,KAAA,IAAY;AACzC;;;;;;AAOA,MAAa,sBAKD,QAAQ,yBAAyB;AAE7C,SAAS,uBACP,SACA,OACA,SACA,SACM;CACN,MAAM,SAAS,OAAO,KAAK;CAC3B,gBAAgB;EACd,IAAI,YAAY,SAAS,CAAC,SAAS,OAAO,SAAS;EACnD,MAAM,SAAS,YAAY,QAAQ,aAAa,UAAU,QAAQ,UAAU;EAC5E,IAAI,WAAW,QAAQ,QAAQ,QAAQ,EAAE,YAAY,KAAK,CAAC,GAAG;EAC9D,IAAI,YAAY,KAAA,KAAa,CAAC,QAAQ,MAAM,GAAG;EAC/C,OAAO,UAAU;EACjB,QAAQ,MAAM,OAAO;CACvB,GAAG;EAAC;EAAS;EAAO;EAAS;CAAO,CAAC;AACvC"}
1
+ {"version":3,"file":"use-name-warning.mjs","names":[],"sources":["../../src/internal/use-name-warning.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport type { RefObject } from \"react\";\nimport type { ElementCheck } from \"./use-element-check.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** What counts as a name besides `aria-label` and `aria-labelledby`. */\nexport interface NameRules {\n /** `aria-labelledby` counts only when one of its ids is in the document (a mounted Title). */\n readonly resolveIds?: boolean;\n /** Text content counts (a button with a visible label). */\n readonly text?: boolean;\n /** `title` counts. */\n readonly title?: boolean;\n}\n\n/** A button is also named by its text or `title`. */\nexport const BUTTON_NAME: NameRules = { text: true, title: true };\n\n/** Text content names it too (`title` does not). */\nexport const TEXT_NAME: NameRules = { text: true };\n\n/** Whether `element` has an accessible name by `rules` (development checks only). */\nfunction hasName(element: Element, rules: NameRules): boolean {\n if (element.hasAttribute(\"aria-label\")) return true;\n const labelledBy = element.getAttribute(\"aria-labelledby\");\n if (labelledBy !== null) {\n if (!rules.resolveIds) return true;\n const doc = element.ownerDocument;\n if (labelledBy.split(/\\s+/).some((id) => id !== \"\" && doc.getElementById(id) !== null)) {\n return true;\n }\n }\n if (rules.text && (element.textContent ?? \"\").trim() !== \"\") return true;\n return rules.title === true && element.hasAttribute(\"title\");\n}\n\n/**\n * Development check that a part the consumer must name (an icon-only button, a listbox) has an\n * accessible name: a microtask after the element attaches (the text may come from children\n * rendered in the same commit, and a Label's registration re-render is flushed by then), once\n * per instance. The result is a callback ref, or a function to call from the part's own ref.\n *\n * Pass `message` as `isDev && \"...\"` with the calling module's own `isDev` constant, so the text\n * folds away in a production build; there the hook is a no-op that returns `undefined`.\n */\nexport const useNameWarning: (\n message: string | false,\n rules?: NameRules,\n) => ElementCheck<HTMLElement> | undefined = isDev ? useNameWarningDev : noop;\n\nfunction noop(): undefined {\n return undefined;\n}\n\nfunction useNameWarningDev(\n message: string | false,\n rules: NameRules = {},\n): ElementCheck<HTMLElement> | undefined {\n const warned = useRef(false);\n const { resolveIds, text, title } = rules;\n const check = useCallback(\n (element: HTMLElement) => {\n if (warned.current) return () => {};\n queueMicrotask(() => {\n if (warned.current || !element.isConnected) return;\n if (hasName(element, { resolveIds, text, title })) return;\n warned.current = true;\n console.error(message);\n });\n return () => {};\n },\n [message, resolveIds, text, title],\n );\n return message === false ? undefined : check;\n}\n\n/**\n * Development check that a popup has an accessible name once it is (or can be) shown: in an\n * effect while `shown`, once per instance. `applies` limits it to the elements that need a name\n * (a role). Pass `message` as `isDev && \"...\"`, as for `useNameWarning`; a no-op in production.\n */\nexport const useShownNameWarning: (\n element: RefObject<Element | null> | Element | null,\n shown: boolean,\n message: string | false,\n applies?: (element: Element) => boolean,\n) => void = isDev ? useShownNameWarningDev : noop;\n\nfunction useShownNameWarningDev(\n element: RefObject<Element | null> | Element | null,\n shown: boolean,\n message: string | false,\n applies?: (element: Element) => boolean,\n): void {\n const warned = useRef(false);\n useEffect(() => {\n if (message === false || !shown || warned.current) return;\n const target = element !== null && \"current\" in element ? element.current : element;\n if (target === null || hasName(target, { resolveIds: true })) return;\n if (applies !== undefined && !applies(target)) return;\n warned.current = true;\n console.error(message);\n }, [element, shown, message, applies]);\n}\n\n/**\n * Development check that a dialog has a description (AlertDialog,\n * design/components/alert-dialog.md 2.2): an id of its `aria-describedby` that names an element\n * in the document. Judged over the dialog's first showing rather than its first frame, so a\n * description behind a Suspense boundary still pending when the dialog opens counts once it\n * arrives: checked when the dialog opens (`toggle`), then on every change inside it, and\n * `message` is logged at its first `close` if none was found by then. Once per instance. Pass\n * `message` as `isDev && \"...\"`; a no-op in production.\n */\nexport const useShownDescriptionWarning: (\n element: RefObject<HTMLElement | null>,\n message: string | false,\n) => void = isDev ? useShownDescriptionWarningDev : noop;\n\nfunction hasDescription(element: Element): boolean {\n const doc = element.ownerDocument;\n return (element.getAttribute(\"aria-describedby\") ?? \"\")\n .split(/\\s+/)\n .some((id) => id !== \"\" && doc.getElementById(id) !== null);\n}\n\nfunction useShownDescriptionWarningDev(\n element: RefObject<HTMLElement | null>,\n message: string | false,\n): void {\n const done = useRef(false);\n useEffect(() => {\n const target = element.current;\n if (message === false || target === null || done.current) return;\n let observer: MutationObserver | null = null;\n const stop = () => {\n observer?.disconnect();\n observer = null;\n };\n const found = (): boolean => {\n if (!hasDescription(target)) return false;\n done.current = true;\n stop();\n return true;\n };\n const onToggle = (event: Event) => {\n if (event.target !== target || done.current || observer !== null) return;\n if ((event as ToggleEvent).newState !== \"open\" || found()) return;\n observer = new MutationObserver(() => {\n found();\n });\n observer.observe(target, { childList: true, subtree: true });\n };\n const onClose = (event: Event) => {\n if (event.target !== target || done.current || found()) return;\n done.current = true;\n stop();\n console.error(message);\n };\n target.addEventListener(\"toggle\", onToggle);\n target.addEventListener(\"close\", onClose);\n return () => {\n stop();\n target.removeEventListener(\"toggle\", onToggle);\n target.removeEventListener(\"close\", onClose);\n };\n }, [element, message]);\n}\n"],"mappings":";;;AAKA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAavC,MAAa,cAAyB;CAAE,MAAM;CAAM,OAAO;AAAK;;AAGhE,MAAa,YAAuB,EAAE,MAAM,KAAK;;AAGjD,SAAS,QAAQ,SAAkB,OAA2B;CAC5D,IAAI,QAAQ,aAAa,YAAY,GAAG,OAAO;CAC/C,MAAM,aAAa,QAAQ,aAAa,iBAAiB;CACzD,IAAI,eAAe,MAAM;EACvB,IAAI,CAAC,MAAM,YAAY,OAAO;EAC9B,MAAM,MAAM,QAAQ;EACpB,IAAI,WAAW,MAAM,KAAK,CAAC,CAAC,MAAM,OAAO,OAAO,MAAM,IAAI,eAAe,EAAE,MAAM,IAAI,GACnF,OAAO;CAEX;CACA,IAAI,MAAM,SAAS,QAAQ,eAAe,GAAA,CAAI,KAAK,MAAM,IAAI,OAAO;CACpE,OAAO,MAAM,UAAU,QAAQ,QAAQ,aAAa,OAAO;AAC7D;;;;;;;;;;AAWA,MAAa,iBAGgC,QAAQ,oBAAoB;AAEzE,SAAS,OAAkB,CAE3B;AAEA,SAAS,kBACP,SACA,QAAmB,CAAC,GACmB;CACvC,MAAM,SAAS,OAAO,KAAK;CAC3B,MAAM,EAAE,YAAY,MAAM,UAAU;CACpC,MAAM,QAAQ,aACX,YAAyB;EACxB,IAAI,OAAO,SAAS,aAAa,CAAC;EAClC,qBAAqB;GACnB,IAAI,OAAO,WAAW,CAAC,QAAQ,aAAa;GAC5C,IAAI,QAAQ,SAAS;IAAE;IAAY;IAAM;GAAM,CAAC,GAAG;GACnD,OAAO,UAAU;GACjB,QAAQ,MAAM,OAAO;EACvB,CAAC;EACD,aAAa,CAAC;CAChB,GACA;EAAC;EAAS;EAAY;EAAM;CAAK,CACnC;CACA,OAAO,YAAY,QAAQ,KAAA,IAAY;AACzC;;;;;;AAOA,MAAa,sBAKD,QAAQ,yBAAyB;AAE7C,SAAS,uBACP,SACA,OACA,SACA,SACM;CACN,MAAM,SAAS,OAAO,KAAK;CAC3B,gBAAgB;EACd,IAAI,YAAY,SAAS,CAAC,SAAS,OAAO,SAAS;EACnD,MAAM,SAAS,YAAY,QAAQ,aAAa,UAAU,QAAQ,UAAU;EAC5E,IAAI,WAAW,QAAQ,QAAQ,QAAQ,EAAE,YAAY,KAAK,CAAC,GAAG;EAC9D,IAAI,YAAY,KAAA,KAAa,CAAC,QAAQ,MAAM,GAAG;EAC/C,OAAO,UAAU;EACjB,QAAQ,MAAM,OAAO;CACvB,GAAG;EAAC;EAAS;EAAO;EAAS;CAAO,CAAC;AACvC;;;;;;;;;;AAWA,MAAa,6BAGD,QAAQ,gCAAgC;AAEpD,SAAS,eAAe,SAA2B;CACjD,MAAM,MAAM,QAAQ;CACpB,QAAQ,QAAQ,aAAa,kBAAkB,KAAK,GAAA,CACjD,MAAM,KAAK,CAAC,CACZ,MAAM,OAAO,OAAO,MAAM,IAAI,eAAe,EAAE,MAAM,IAAI;AAC9D;AAEA,SAAS,8BACP,SACA,SACM;CACN,MAAM,OAAO,OAAO,KAAK;CACzB,gBAAgB;EACd,MAAM,SAAS,QAAQ;EACvB,IAAI,YAAY,SAAS,WAAW,QAAQ,KAAK,SAAS;EAC1D,IAAI,WAAoC;EACxC,MAAM,aAAa;GACjB,UAAU,WAAW;GACrB,WAAW;EACb;EACA,MAAM,cAAuB;GAC3B,IAAI,CAAC,eAAe,MAAM,GAAG,OAAO;GACpC,KAAK,UAAU;GACf,KAAK;GACL,OAAO;EACT;EACA,MAAM,YAAY,UAAiB;GACjC,IAAI,MAAM,WAAW,UAAU,KAAK,WAAW,aAAa,MAAM;GAClE,IAAK,MAAsB,aAAa,UAAU,MAAM,GAAG;GAC3D,WAAW,IAAI,uBAAuB;IACpC,MAAM;GACR,CAAC;GACD,SAAS,QAAQ,QAAQ;IAAE,WAAW;IAAM,SAAS;GAAK,CAAC;EAC7D;EACA,MAAM,WAAW,UAAiB;GAChC,IAAI,MAAM,WAAW,UAAU,KAAK,WAAW,MAAM,GAAG;GACxD,KAAK,UAAU;GACf,KAAK;GACL,QAAQ,MAAM,OAAO;EACvB;EACA,OAAO,iBAAiB,UAAU,QAAQ;EAC1C,OAAO,iBAAiB,SAAS,OAAO;EACxC,aAAa;GACX,KAAK;GACL,OAAO,oBAAoB,UAAU,QAAQ;GAC7C,OAAO,oBAAoB,SAAS,OAAO;EAC7C;CACF,GAAG,CAAC,SAAS,OAAO,CAAC;AACvB"}
@@ -0,0 +1,70 @@
1
+ "use client";
2
+ import { useLatest } from "./use-latest.mjs";
3
+ import { sortByDocumentOrder } from "./dom-order.mjs";
4
+ import { useRegisterCount } from "./use-register-count.mjs";
5
+ import { useCallback, useRef, useState } from "react";
6
+ //#region src/internal/use-option-registry.ts
7
+ const isDev = process.env.NODE_ENV !== "production";
8
+ /** The id fragment of an option value: stable across result sets, no whitespace (combobox.md 3.5). */
9
+ function optionId(prefix, value) {
10
+ return `${prefix}${encodeURIComponent(value)}`;
11
+ }
12
+ /** The text of an option: its `label` prop, else its trimmed `textContent` now. */
13
+ function optionLabel(entry) {
14
+ return entry.label ?? (entry.element.textContent ?? "").trim();
15
+ }
16
+ /**
17
+ * The Options, Statuses and Labels mounted in a listbox component, Combobox or MultiSelect
18
+ * (design/components/combobox.md 2, 6.5; multi-select.md B.15). An Option's label is learnt into
19
+ * `labels` (the label cache, combobox.md 2.3) as it registers.
20
+ */
21
+ function useOptionRegistry(component, labels, onLabel) {
22
+ const onLabelRef = useLatest(onLabel);
23
+ const [registry] = useState(() => /* @__PURE__ */ new Map());
24
+ const [optionCount, setOptionCount] = useState(0);
25
+ const { count: statusCount, register: registerStatus, countRef: statusCountRef } = useRegisterCount();
26
+ const { count: labelCount, register: registerLabel } = useRegisterCount();
27
+ const warnedDuplicate = useRef(false);
28
+ return {
29
+ registry,
30
+ optionCount,
31
+ statusCount,
32
+ statusCountRef,
33
+ labelCount,
34
+ registerOption: useCallback((optionValue, entry) => {
35
+ const existing = registry.get(optionValue);
36
+ if (isDev && !warnedDuplicate.current && existing !== void 0 && existing.element !== entry.element && existing.element.isConnected) {
37
+ warnedDuplicate.current = true;
38
+ console.error(`${component}.Option: two options have the value ${JSON.stringify(optionValue)}. Option ids are derived from the value, so they must be unique within one ${component}.`);
39
+ }
40
+ registry.set(optionValue, entry);
41
+ const label = optionLabel(entry);
42
+ labels.set(optionValue, label);
43
+ onLabelRef.current?.(optionValue, label);
44
+ setOptionCount(registry.size);
45
+ return () => {
46
+ if (registry.get(optionValue) === entry) registry.delete(optionValue);
47
+ setOptionCount(registry.size);
48
+ };
49
+ }, [
50
+ component,
51
+ registry,
52
+ labels,
53
+ onLabelRef
54
+ ]),
55
+ registerStatus,
56
+ registerLabel,
57
+ orderedOptions: useCallback(() => {
58
+ const options = [];
59
+ for (const [optionValue, entry] of registry) options.push({
60
+ value: optionValue,
61
+ ...entry
62
+ });
63
+ return sortByDocumentOrder(options, (option) => option.element);
64
+ }, [registry])
65
+ };
66
+ }
67
+ //#endregion
68
+ export { optionId, optionLabel, useOptionRegistry };
69
+
70
+ //# sourceMappingURL=use-option-registry.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-option-registry.mjs","names":[],"sources":["../../src/internal/use-option-registry.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useRef, useState } from \"react\";\nimport type { RefObject } from \"react\";\nimport { sortByDocumentOrder } from \"./dom-order.js\";\nimport { useLatest } from \"./use-latest.js\";\nimport { useRegisterCount } from \"./use-register-count.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * What a mounted listbox option (`Combobox.Option`, `MultiSelect.Option`) tells its Root\n * (design/components/combobox.md 2, \"mounted options, labels\").\n */\nexport interface ListboxOptionEntry {\n readonly element: HTMLElement;\n /** The `label` prop; `undefined`: the element's trimmed `textContent` at the moment of use. */\n readonly label: string | undefined;\n readonly disabled: boolean;\n}\n\nexport interface OrderedOption extends ListboxOptionEntry {\n readonly value: string;\n}\n\n/** The id fragment of an option value: stable across result sets, no whitespace (combobox.md 3.5). */\nexport function optionId(prefix: string, value: string): string {\n return `${prefix}${encodeURIComponent(value)}`;\n}\n\n/** The text of an option: its `label` prop, else its trimmed `textContent` now. */\nexport function optionLabel(entry: ListboxOptionEntry): string {\n return entry.label ?? (entry.element.textContent ?? \"\").trim();\n}\n\nexport interface OptionRegistry {\n /** The mounted Options by value. */\n readonly registry: ReadonlyMap<string, ListboxOptionEntry>;\n readonly optionCount: number;\n readonly statusCount: number;\n /**\n * The same count for the announcement effect: the open commit's passive effects can run before\n * the re-render the Status's registration scheduled (the race `registry` avoids for options).\n */\n readonly statusCountRef: RefObject<number>;\n readonly labelCount: number;\n readonly registerOption: (value: string, entry: ListboxOptionEntry) => () => void;\n readonly registerStatus: () => () => void;\n readonly registerLabel: () => () => void;\n /** The registered Options in document order. */\n readonly orderedOptions: () => OrderedOption[];\n}\n\n/**\n * The Options, Statuses and Labels mounted in a listbox component, Combobox or MultiSelect\n * (design/components/combobox.md 2, 6.5; multi-select.md B.15). An Option's label is learnt into\n * `labels` (the label cache, combobox.md 2.3) as it registers.\n */\nexport function useOptionRegistry(\n /** The namespace for the duplicate-value warning (`\"Combobox\"`). */\n component: string,\n labels: Map<string, string>,\n /** Called with every label learnt from a registering Option (the chips, combobox.md 15.1). */\n onLabel?: (value: string, label: string) => void,\n): OptionRegistry {\n const onLabelRef = useLatest(onLabel);\n const [registry] = useState(() => new Map<string, ListboxOptionEntry>());\n const [optionCount, setOptionCount] = useState(0);\n const {\n count: statusCount,\n register: registerStatus,\n countRef: statusCountRef,\n } = useRegisterCount();\n const { count: labelCount, register: registerLabel } = useRegisterCount();\n const warnedDuplicate = useRef(false);\n\n const registerOption = useCallback(\n (optionValue: string, entry: ListboxOptionEntry) => {\n const existing = registry.get(optionValue);\n if (\n isDev &&\n !warnedDuplicate.current &&\n existing !== undefined &&\n existing.element !== entry.element &&\n existing.element.isConnected\n ) {\n warnedDuplicate.current = true;\n console.error(\n `${component}.Option: two options have the value ${JSON.stringify(optionValue)}. ` +\n `Option ids are derived from the value, so they must be unique within one ${component}.`,\n );\n }\n registry.set(optionValue, entry);\n const label = optionLabel(entry);\n labels.set(optionValue, label);\n onLabelRef.current?.(optionValue, label);\n setOptionCount(registry.size);\n return () => {\n if (registry.get(optionValue) === entry) registry.delete(optionValue);\n setOptionCount(registry.size);\n };\n },\n [component, registry, labels, onLabelRef],\n );\n\n const orderedOptions = useCallback((): OrderedOption[] => {\n const options: OrderedOption[] = [];\n for (const [optionValue, entry] of registry) options.push({ value: optionValue, ...entry });\n return sortByDocumentOrder(options, (option) => option.element);\n }, [registry]);\n\n return {\n registry,\n optionCount,\n statusCount,\n statusCountRef,\n labelCount,\n registerOption,\n registerStatus,\n registerLabel,\n orderedOptions,\n };\n}\n"],"mappings":";;;;;;AAOA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAkBvC,SAAgB,SAAS,QAAgB,OAAuB;CAC9D,OAAO,GAAG,SAAS,mBAAmB,KAAK;AAC7C;;AAGA,SAAgB,YAAY,OAAmC;CAC7D,OAAO,MAAM,UAAU,MAAM,QAAQ,eAAe,GAAA,CAAI,KAAK;AAC/D;;;;;;AAyBA,SAAgB,kBAEd,WACA,QAEA,SACgB;CAChB,MAAM,aAAa,UAAU,OAAO;CACpC,MAAM,CAAC,YAAY,+BAAe,IAAI,IAAgC,CAAC;CACvE,MAAM,CAAC,aAAa,kBAAkB,SAAS,CAAC;CAChD,MAAM,EACJ,OAAO,aACP,UAAU,gBACV,UAAU,mBACR,iBAAiB;CACrB,MAAM,EAAE,OAAO,YAAY,UAAU,kBAAkB,iBAAiB;CACxE,MAAM,kBAAkB,OAAO,KAAK;CAqCpC,OAAO;EACL;EACA;EACA;EACA;EACA;EACA,gBAzCqB,aACpB,aAAqB,UAA8B;GAClD,MAAM,WAAW,SAAS,IAAI,WAAW;GACzC,IACE,SACA,CAAC,gBAAgB,WACjB,aAAa,KAAA,KACb,SAAS,YAAY,MAAM,WAC3B,SAAS,QAAQ,aACjB;IACA,gBAAgB,UAAU;IAC1B,QAAQ,MACN,GAAG,UAAU,sCAAsC,KAAK,UAAU,WAAW,EAAE,6EACD,UAAU,EAC1F;GACF;GACA,SAAS,IAAI,aAAa,KAAK;GAC/B,MAAM,QAAQ,YAAY,KAAK;GAC/B,OAAO,IAAI,aAAa,KAAK;GAC7B,WAAW,UAAU,aAAa,KAAK;GACvC,eAAe,SAAS,IAAI;GAC5B,aAAa;IACX,IAAI,SAAS,IAAI,WAAW,MAAM,OAAO,SAAS,OAAO,WAAW;IACpE,eAAe,SAAS,IAAI;GAC9B;EACF,GACA;GAAC;GAAW;GAAU;GAAQ;EAAU,CAe3B;EACb;EACA;EACA,gBAfqB,kBAAmC;GACxD,MAAM,UAA2B,CAAC;GAClC,KAAK,MAAM,CAAC,aAAa,UAAU,UAAU,QAAQ,KAAK;IAAE,OAAO;IAAa,GAAG;GAAM,CAAC;GAC1F,OAAO,oBAAoB,UAAU,WAAW,OAAO,OAAO;EAChE,GAAG,CAAC,QAAQ,CAWG;CACf;AACF"}
@@ -1,9 +1,8 @@
1
1
  "use client";
2
2
  import { focusItem, hasModifier, isMenuItem, isRtl, menuItems, typeaheadText } from "./menu-dom.mjs";
3
+ import { createTypeaheadBuffer, isTypingAhead, typeaheadMatch } from "../internal/typeahead.mjs";
3
4
  import { useCallback, useRef } from "react";
4
5
  //#region src/menu/use-menu-keyboard.ts
5
- /** Typeahead buffer lifetime after the last keystroke (design 5.1). */
6
- const TYPEAHEAD_RESET_MS = 500;
7
6
  /**
8
7
  * The keyboard model of a menu popup (design 5): ArrowUp / ArrowDown / Home / End move focus
9
8
  * between items (the browser does where `focusgroup` is native), printable characters run
@@ -11,34 +10,15 @@ const TYPEAHEAD_RESET_MS = 500;
11
10
  */
12
11
  function useMenuKeyboard(menu, nativeFocusgroup) {
13
12
  const { popover, submenu, loop } = menu;
14
- const typeahead = useRef({
15
- text: "",
16
- at: 0
17
- });
18
- const typingAhead = useCallback(() => {
19
- const { text, at } = typeahead.current;
20
- return text !== "" && Date.now() - at <= TYPEAHEAD_RESET_MS;
21
- }, []);
13
+ const typeahead = useRef(createTypeaheadBuffer());
14
+ const typingAhead = useCallback(() => isTypingAhead(typeahead.current), []);
22
15
  const runTypeahead = (popup, current, key) => {
23
- const now = Date.now();
24
- const buffer = typeahead.current;
25
- if (buffer.text === "" || now - buffer.at > TYPEAHEAD_RESET_MS) buffer.text = "";
26
- if (key === " " && buffer.text === "") return false;
27
- buffer.text += key.toLowerCase();
28
- buffer.at = now;
29
16
  const items = menuItems(popup);
30
- if (items.length === 0) return true;
31
- const repeated = [...buffer.text].every((c) => c === buffer.text[0]);
32
- const search = repeated ? buffer.text[0] : buffer.text;
33
17
  const index = current === null ? -1 : items.indexOf(current);
34
- const start = repeated || index < 0 ? index + 1 : index;
35
- for (let i = 0; i < items.length; i++) {
36
- const item = items[(start + i) % items.length];
37
- if (typeaheadText(item).startsWith(search)) {
38
- if (item !== current) focusItem(item);
39
- break;
40
- }
41
- }
18
+ const match = typeaheadMatch(typeahead.current, key, items.map(typeaheadText), index);
19
+ if (match === null) return false;
20
+ const item = items[match];
21
+ if (item !== void 0 && item !== current) focusItem(item);
42
22
  return true;
43
23
  };
44
24
  const onKeyDown = (event) => {
@@ -1 +1 @@
1
- {"version":3,"file":"use-menu-keyboard.mjs","names":[],"sources":["../../src/menu/use-menu-keyboard.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useRef } from \"react\";\nimport type { KeyboardEvent } from \"react\";\nimport type { MenuContextValue } from \"./menu-context.js\";\nimport { focusItem, hasModifier, isMenuItem, isRtl, menuItems, typeaheadText } from \"./menu-dom.js\";\n\n/** Typeahead buffer lifetime after the last keystroke (design 5.1). */\nconst TYPEAHEAD_RESET_MS = 500;\n\nexport interface MenuKeyboard {\n /** Menu.Popup's `onKeyDown`. */\n readonly onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;\n /** Whether a typeahead buffer is live (Space then belongs to it, not to an item). Stable. */\n readonly typingAhead: () => boolean;\n}\n\n/**\n * The keyboard model of a menu popup (design 5): ArrowUp / ArrowDown / Home / End move focus\n * between items (the browser does where `focusgroup` is native), printable characters run\n * typeahead, ArrowLeft (ArrowRight in RTL) closes a submenu.\n */\nexport function useMenuKeyboard(menu: MenuContextValue, nativeFocusgroup: boolean): MenuKeyboard {\n const { popover, submenu, loop } = menu;\n const typeahead = useRef({ text: \"\", at: 0 });\n const typingAhead = useCallback(() => {\n const { text, at } = typeahead.current;\n return text !== \"\" && Date.now() - at <= TYPEAHEAD_RESET_MS;\n }, []);\n\n const runTypeahead = (popup: HTMLElement, current: HTMLElement | null, key: string): boolean => {\n const now = Date.now();\n const buffer = typeahead.current;\n if (buffer.text === \"\" || now - buffer.at > TYPEAHEAD_RESET_MS) buffer.text = \"\";\n if (key === \" \" && buffer.text === \"\") return false;\n buffer.text += key.toLowerCase();\n buffer.at = now;\n const items = menuItems(popup);\n if (items.length === 0) return true;\n // A repeated single character cycles through the items starting with it; a longer buffer\n // keeps the current item while it still matches (design 5.1).\n const repeated = [...buffer.text].every((c) => c === buffer.text[0]);\n const search = repeated ? buffer.text[0]! : buffer.text;\n const index = current === null ? -1 : items.indexOf(current);\n const start = repeated || index < 0 ? index + 1 : index;\n for (let i = 0; i < items.length; i++) {\n const item = items[(start + i) % items.length]!;\n if (typeaheadText(item).startsWith(search)) {\n if (item !== current) focusItem(item);\n break;\n }\n }\n return true;\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {\n if (event.defaultPrevented || hasModifier(event)) return;\n const popup = event.currentTarget;\n const target = event.target as HTMLElement;\n const onItem = isMenuItem(target, popup);\n if (!onItem && target !== popup) return;\n const key = event.key;\n\n // ArrowLeft (ArrowRight in RTL) closes a submenu; focus returns to its SubmenuTrigger\n // through the popover hook's nested focus rule (design 6.3).\n if (submenu && key === (isRtl(popup) ? \"ArrowRight\" : \"ArrowLeft\")) {\n event.preventDefault();\n popover.requestClose(event.nativeEvent, \"activate\");\n return;\n }\n\n if (key === \"ArrowDown\" || key === \"ArrowUp\" || key === \"Home\" || key === \"End\") {\n if (!onItem) {\n // The popup itself has focus (no items at open, or focus landed on it some other way):\n // into the list from its edge.\n event.preventDefault();\n const items = menuItems(popup);\n const item = key === \"ArrowDown\" || key === \"Home\" ? items[0] : items.at(-1);\n if (item !== undefined) focusItem(item);\n return;\n }\n // The browser moves focus itself where `focusgroup` is implemented.\n if (nativeFocusgroup) return;\n event.preventDefault();\n const items = menuItems(popup);\n const index = items.indexOf(target);\n const last = items.length - 1;\n let next: number;\n if (key === \"Home\") next = 0;\n else if (key === \"End\") next = last;\n else if (key === \"ArrowDown\") next = index >= last ? (loop ? 0 : last) : index + 1;\n else next = index <= 0 ? (loop ? last : 0) : index - 1;\n const item = items[next];\n if (item !== undefined && item !== target) focusItem(item);\n return;\n }\n\n if (key.length === 1 && runTypeahead(popup, onItem ? target : null, key)) {\n event.preventDefault();\n }\n };\n\n return { onKeyDown, typingAhead };\n}\n"],"mappings":";;;;;AAOA,MAAM,qBAAqB;;;;;;AAc3B,SAAgB,gBAAgB,MAAwB,kBAAyC;CAC/F,MAAM,EAAE,SAAS,SAAS,SAAS;CACnC,MAAM,YAAY,OAAO;EAAE,MAAM;EAAI,IAAI;CAAE,CAAC;CAC5C,MAAM,cAAc,kBAAkB;EACpC,MAAM,EAAE,MAAM,OAAO,UAAU;EAC/B,OAAO,SAAS,MAAM,KAAK,IAAI,IAAI,MAAM;CAC3C,GAAG,CAAC,CAAC;CAEL,MAAM,gBAAgB,OAAoB,SAA6B,QAAyB;EAC9F,MAAM,MAAM,KAAK,IAAI;EACrB,MAAM,SAAS,UAAU;EACzB,IAAI,OAAO,SAAS,MAAM,MAAM,OAAO,KAAK,oBAAoB,OAAO,OAAO;EAC9E,IAAI,QAAQ,OAAO,OAAO,SAAS,IAAI,OAAO;EAC9C,OAAO,QAAQ,IAAI,YAAY;EAC/B,OAAO,KAAK;EACZ,MAAM,QAAQ,UAAU,KAAK;EAC7B,IAAI,MAAM,WAAW,GAAG,OAAO;EAG/B,MAAM,WAAW,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC,OAAO,MAAM,MAAM,OAAO,KAAK,EAAE;EACnE,MAAM,SAAS,WAAW,OAAO,KAAK,KAAM,OAAO;EACnD,MAAM,QAAQ,YAAY,OAAO,KAAK,MAAM,QAAQ,OAAO;EAC3D,MAAM,QAAQ,YAAY,QAAQ,IAAI,QAAQ,IAAI;EAClD,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;GACrC,MAAM,OAAO,OAAO,QAAQ,KAAK,MAAM;GACvC,IAAI,cAAc,IAAI,CAAC,CAAC,WAAW,MAAM,GAAG;IAC1C,IAAI,SAAS,SAAS,UAAU,IAAI;IACpC;GACF;EACF;EACA,OAAO;CACT;CAEA,MAAM,aAAa,UAAsC;EACvD,IAAI,MAAM,oBAAoB,YAAY,KAAK,GAAG;EAClD,MAAM,QAAQ,MAAM;EACpB,MAAM,SAAS,MAAM;EACrB,MAAM,SAAS,WAAW,QAAQ,KAAK;EACvC,IAAI,CAAC,UAAU,WAAW,OAAO;EACjC,MAAM,MAAM,MAAM;EAIlB,IAAI,WAAW,SAAS,MAAM,KAAK,IAAI,eAAe,cAAc;GAClE,MAAM,eAAe;GACrB,QAAQ,aAAa,MAAM,aAAa,UAAU;GAClD;EACF;EAEA,IAAI,QAAQ,eAAe,QAAQ,aAAa,QAAQ,UAAU,QAAQ,OAAO;GAC/E,IAAI,CAAC,QAAQ;IAGX,MAAM,eAAe;IACrB,MAAM,QAAQ,UAAU,KAAK;IAC7B,MAAM,OAAO,QAAQ,eAAe,QAAQ,SAAS,MAAM,KAAK,MAAM,GAAG,EAAE;IAC3E,IAAI,SAAS,KAAA,GAAW,UAAU,IAAI;IACtC;GACF;GAEA,IAAI,kBAAkB;GACtB,MAAM,eAAe;GACrB,MAAM,QAAQ,UAAU,KAAK;GAC7B,MAAM,QAAQ,MAAM,QAAQ,MAAM;GAClC,MAAM,OAAO,MAAM,SAAS;GAC5B,IAAI;GACJ,IAAI,QAAQ,QAAQ,OAAO;QACtB,IAAI,QAAQ,OAAO,OAAO;QAC1B,IAAI,QAAQ,aAAa,OAAO,SAAS,OAAQ,OAAO,IAAI,OAAQ,QAAQ;QAC5E,OAAO,SAAS,IAAK,OAAO,OAAO,IAAK,QAAQ;GACrD,MAAM,OAAO,MAAM;GACnB,IAAI,SAAS,KAAA,KAAa,SAAS,QAAQ,UAAU,IAAI;GACzD;EACF;EAEA,IAAI,IAAI,WAAW,KAAK,aAAa,OAAO,SAAS,SAAS,MAAM,GAAG,GACrE,MAAM,eAAe;CAEzB;CAEA,OAAO;EAAE;EAAW;CAAY;AAClC"}
1
+ {"version":3,"file":"use-menu-keyboard.mjs","names":[],"sources":["../../src/menu/use-menu-keyboard.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useRef } from \"react\";\nimport type { KeyboardEvent } from \"react\";\nimport type { MenuContextValue } from \"./menu-context.js\";\nimport { focusItem, hasModifier, isMenuItem, isRtl, menuItems, typeaheadText } from \"./menu-dom.js\";\nimport { createTypeaheadBuffer, isTypingAhead, typeaheadMatch } from \"../internal/typeahead.js\";\n\nexport interface MenuKeyboard {\n /** Menu.Popup's `onKeyDown`. */\n readonly onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;\n /** Whether a typeahead buffer is live (Space then belongs to it, not to an item). Stable. */\n readonly typingAhead: () => boolean;\n}\n\n/**\n * The keyboard model of a menu popup (design 5): ArrowUp / ArrowDown / Home / End move focus\n * between items (the browser does where `focusgroup` is native), printable characters run\n * typeahead, ArrowLeft (ArrowRight in RTL) closes a submenu.\n */\nexport function useMenuKeyboard(menu: MenuContextValue, nativeFocusgroup: boolean): MenuKeyboard {\n const { popover, submenu, loop } = menu;\n const typeahead = useRef(createTypeaheadBuffer());\n const typingAhead = useCallback(() => isTypingAhead(typeahead.current), []);\n\n // Typeahead (design 5.1, `internal/typeahead.ts`): a repeated single character cycles through\n // the items starting with it; a longer buffer keeps the current item while it still matches.\n const runTypeahead = (popup: HTMLElement, current: HTMLElement | null, key: string): boolean => {\n const items = menuItems(popup);\n const index = current === null ? -1 : items.indexOf(current);\n const match = typeaheadMatch(typeahead.current, key, items.map(typeaheadText), index);\n if (match === null) return false;\n const item = items[match];\n if (item !== undefined && item !== current) focusItem(item);\n return true;\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {\n if (event.defaultPrevented || hasModifier(event)) return;\n const popup = event.currentTarget;\n const target = event.target as HTMLElement;\n const onItem = isMenuItem(target, popup);\n if (!onItem && target !== popup) return;\n const key = event.key;\n\n // ArrowLeft (ArrowRight in RTL) closes a submenu; focus returns to its SubmenuTrigger\n // through the popover hook's nested focus rule (design 6.3).\n if (submenu && key === (isRtl(popup) ? \"ArrowRight\" : \"ArrowLeft\")) {\n event.preventDefault();\n popover.requestClose(event.nativeEvent, \"activate\");\n return;\n }\n\n if (key === \"ArrowDown\" || key === \"ArrowUp\" || key === \"Home\" || key === \"End\") {\n if (!onItem) {\n // The popup itself has focus (no items at open, or focus landed on it some other way):\n // into the list from its edge.\n event.preventDefault();\n const items = menuItems(popup);\n const item = key === \"ArrowDown\" || key === \"Home\" ? items[0] : items.at(-1);\n if (item !== undefined) focusItem(item);\n return;\n }\n // The browser moves focus itself where `focusgroup` is implemented.\n if (nativeFocusgroup) return;\n event.preventDefault();\n const items = menuItems(popup);\n const index = items.indexOf(target);\n const last = items.length - 1;\n let next: number;\n if (key === \"Home\") next = 0;\n else if (key === \"End\") next = last;\n else if (key === \"ArrowDown\") next = index >= last ? (loop ? 0 : last) : index + 1;\n else next = index <= 0 ? (loop ? last : 0) : index - 1;\n const item = items[next];\n if (item !== undefined && item !== target) focusItem(item);\n return;\n }\n\n if (key.length === 1 && runTypeahead(popup, onItem ? target : null, key)) {\n event.preventDefault();\n }\n };\n\n return { onKeyDown, typingAhead };\n}\n"],"mappings":";;;;;;;;;;AAmBA,SAAgB,gBAAgB,MAAwB,kBAAyC;CAC/F,MAAM,EAAE,SAAS,SAAS,SAAS;CACnC,MAAM,YAAY,OAAO,sBAAsB,CAAC;CAChD,MAAM,cAAc,kBAAkB,cAAc,UAAU,OAAO,GAAG,CAAC,CAAC;CAI1E,MAAM,gBAAgB,OAAoB,SAA6B,QAAyB;EAC9F,MAAM,QAAQ,UAAU,KAAK;EAC7B,MAAM,QAAQ,YAAY,OAAO,KAAK,MAAM,QAAQ,OAAO;EAC3D,MAAM,QAAQ,eAAe,UAAU,SAAS,KAAK,MAAM,IAAI,aAAa,GAAG,KAAK;EACpF,IAAI,UAAU,MAAM,OAAO;EAC3B,MAAM,OAAO,MAAM;EACnB,IAAI,SAAS,KAAA,KAAa,SAAS,SAAS,UAAU,IAAI;EAC1D,OAAO;CACT;CAEA,MAAM,aAAa,UAAsC;EACvD,IAAI,MAAM,oBAAoB,YAAY,KAAK,GAAG;EAClD,MAAM,QAAQ,MAAM;EACpB,MAAM,SAAS,MAAM;EACrB,MAAM,SAAS,WAAW,QAAQ,KAAK;EACvC,IAAI,CAAC,UAAU,WAAW,OAAO;EACjC,MAAM,MAAM,MAAM;EAIlB,IAAI,WAAW,SAAS,MAAM,KAAK,IAAI,eAAe,cAAc;GAClE,MAAM,eAAe;GACrB,QAAQ,aAAa,MAAM,aAAa,UAAU;GAClD;EACF;EAEA,IAAI,QAAQ,eAAe,QAAQ,aAAa,QAAQ,UAAU,QAAQ,OAAO;GAC/E,IAAI,CAAC,QAAQ;IAGX,MAAM,eAAe;IACrB,MAAM,QAAQ,UAAU,KAAK;IAC7B,MAAM,OAAO,QAAQ,eAAe,QAAQ,SAAS,MAAM,KAAK,MAAM,GAAG,EAAE;IAC3E,IAAI,SAAS,KAAA,GAAW,UAAU,IAAI;IACtC;GACF;GAEA,IAAI,kBAAkB;GACtB,MAAM,eAAe;GACrB,MAAM,QAAQ,UAAU,KAAK;GAC7B,MAAM,QAAQ,MAAM,QAAQ,MAAM;GAClC,MAAM,OAAO,MAAM,SAAS;GAC5B,IAAI;GACJ,IAAI,QAAQ,QAAQ,OAAO;QACtB,IAAI,QAAQ,OAAO,OAAO;QAC1B,IAAI,QAAQ,aAAa,OAAO,SAAS,OAAQ,OAAO,IAAI,OAAQ,QAAQ;QAC5E,OAAO,SAAS,IAAK,OAAO,OAAO,IAAK,QAAQ;GACrD,MAAM,OAAO,MAAM;GACnB,IAAI,SAAS,KAAA,KAAa,SAAS,QAAQ,UAAU,IAAI;GACzD;EACF;EAEA,IAAI,IAAI,WAAW,KAAK,aAAa,OAAO,SAAS,SAAS,MAAM,GAAG,GACrE,MAAM,eAAe;CAEzB;CAEA,OAAO;EAAE;EAAW;CAAY;AAClC"}
@@ -0,0 +1,37 @@
1
+ import "../internal/platform-attributes.mjs";
2
+ import { MultiSelectList, MultiSelectListProps, MultiSelectListState } from "./multi-select-list.mjs";
3
+ import { MultiSelectEmpty, MultiSelectEmptyProps, MultiSelectEmptyState, MultiSelectGroup, MultiSelectGroupLabel, MultiSelectGroupLabelProps, MultiSelectGroupLabelState, MultiSelectGroupProps, MultiSelectGroupState, MultiSelectStatus, MultiSelectStatusProps, MultiSelectStatusState } from "./multi-select-group.mjs";
4
+ import { MultiSelectLabel, MultiSelectLabelProps, MultiSelectLabelState } from "./multi-select-label.mjs";
5
+ import { MultiSelectOption, MultiSelectOptionProps, MultiSelectOptionState } from "./multi-select-option.mjs";
6
+ import { MultiSelectPopup, MultiSelectPopupProps, MultiSelectPopupState } from "./multi-select-popup.mjs";
7
+ import { MultiSelectOpenChangeDetails, MultiSelectRoot, MultiSelectRootProps, MultiSelectRootState, MultiSelectValueChangeDetails } from "./multi-select-root.mjs";
8
+ import { MultiSelectTrigger, MultiSelectTriggerProps, MultiSelectTriggerState } from "./multi-select-trigger.mjs";
9
+ import { MultiSelectValue, MultiSelectValueProps, MultiSelectValueState } from "./multi-select-value.mjs";
10
+ //#region src/multi-select/index.d.ts
11
+ /**
12
+ * A select-only combobox with a multi-select listbox (WAI-ARIA APG) on `popover="auto"`: `Root`
13
+ * (no DOM, or one hidden input per value with `name`) > `Label`, `Trigger`
14
+ * (`button[role=combobox]`) > `Value`, `Popup` (`div[popover=auto]`) > `List`
15
+ * (`div[role=listbox][aria-multiselectable]`) > `Option`, `Group` > `GroupLabel`; `Empty` and
16
+ * `Status` in the Popup. A pick toggles one option and the listbox stays open; each pick is a
17
+ * transition with an optimistic selection and `data-pending` on the option. Single selection is
18
+ * `Select`, the browser's own control.
19
+ *
20
+ * @see https://ui.funstack.work/components/multi-select
21
+ */
22
+ export declare const MultiSelect: {
23
+ readonly Root: typeof MultiSelectRoot;
24
+ readonly Label: typeof MultiSelectLabel;
25
+ readonly Trigger: typeof MultiSelectTrigger;
26
+ readonly Value: typeof MultiSelectValue;
27
+ readonly Popup: typeof MultiSelectPopup;
28
+ readonly List: typeof MultiSelectList;
29
+ readonly Option: typeof MultiSelectOption;
30
+ readonly Group: typeof MultiSelectGroup;
31
+ readonly GroupLabel: typeof MultiSelectGroupLabel;
32
+ readonly Empty: typeof MultiSelectEmpty;
33
+ readonly Status: typeof MultiSelectStatus;
34
+ };
35
+ //#endregion
36
+ export type { MultiSelectEmptyProps, MultiSelectEmptyState, MultiSelectGroupLabelProps, MultiSelectGroupLabelState, MultiSelectGroupProps, MultiSelectGroupState, MultiSelectLabelProps, MultiSelectLabelState, MultiSelectListProps, MultiSelectListState, MultiSelectOpenChangeDetails, MultiSelectOptionProps, MultiSelectOptionState, MultiSelectPopupProps, MultiSelectPopupState, MultiSelectRootProps, MultiSelectRootState, MultiSelectStatusProps, MultiSelectStatusState, MultiSelectTriggerProps, MultiSelectTriggerState, MultiSelectValueChangeDetails, MultiSelectValueProps, MultiSelectValueState };
37
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/multi-select/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;qBA4Ba;WACX,aAAI;WACJ,cAAK;WACL,gBAAO;WACP,cAAK;WACL,cAAK;WACL,aAAI;WACJ,eAAM;WACN,cAAK;WACL,mBAAU;WACV,cAAK;WACL,eAAM"}
@@ -0,0 +1,37 @@
1
+ import { MultiSelectEmpty, MultiSelectGroup, MultiSelectGroupLabel, MultiSelectStatus } from "./multi-select-group.mjs";
2
+ import { MultiSelectLabel } from "./multi-select-label.mjs";
3
+ import { MultiSelectList } from "./multi-select-list.mjs";
4
+ import { MultiSelectOption } from "./multi-select-option.mjs";
5
+ import { MultiSelectPopup } from "./multi-select-popup.mjs";
6
+ import { MultiSelectRoot } from "./multi-select-root.mjs";
7
+ import { MultiSelectTrigger } from "./multi-select-trigger.mjs";
8
+ import { MultiSelectValue } from "./multi-select-value.mjs";
9
+ //#region src/multi-select/index.ts
10
+ /**
11
+ * A select-only combobox with a multi-select listbox (WAI-ARIA APG) on `popover="auto"`: `Root`
12
+ * (no DOM, or one hidden input per value with `name`) > `Label`, `Trigger`
13
+ * (`button[role=combobox]`) > `Value`, `Popup` (`div[popover=auto]`) > `List`
14
+ * (`div[role=listbox][aria-multiselectable]`) > `Option`, `Group` > `GroupLabel`; `Empty` and
15
+ * `Status` in the Popup. A pick toggles one option and the listbox stays open; each pick is a
16
+ * transition with an optimistic selection and `data-pending` on the option. Single selection is
17
+ * `Select`, the browser's own control.
18
+ *
19
+ * @see https://ui.funstack.work/components/multi-select
20
+ */
21
+ const MultiSelect = {
22
+ Root: MultiSelectRoot,
23
+ Label: MultiSelectLabel,
24
+ Trigger: MultiSelectTrigger,
25
+ Value: MultiSelectValue,
26
+ Popup: MultiSelectPopup,
27
+ List: MultiSelectList,
28
+ Option: MultiSelectOption,
29
+ Group: MultiSelectGroup,
30
+ GroupLabel: MultiSelectGroupLabel,
31
+ Empty: MultiSelectEmpty,
32
+ Status: MultiSelectStatus
33
+ };
34
+ //#endregion
35
+ export { MultiSelect };
36
+
37
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/multi-select/index.ts"],"sourcesContent":["// Ships the platform attribute typings with this subpath (conventions 7.4). Type-only: the built\n// JS has no import of it.\nimport \"../internal/platform-attributes.js\";\nimport {\n MultiSelectEmpty,\n MultiSelectGroup,\n MultiSelectGroupLabel,\n MultiSelectStatus,\n} from \"./multi-select-group.js\";\nimport { MultiSelectLabel } from \"./multi-select-label.js\";\nimport { MultiSelectList } from \"./multi-select-list.js\";\nimport { MultiSelectOption } from \"./multi-select-option.js\";\nimport { MultiSelectPopup } from \"./multi-select-popup.js\";\nimport { MultiSelectRoot } from \"./multi-select-root.js\";\nimport { MultiSelectTrigger } from \"./multi-select-trigger.js\";\nimport { MultiSelectValue } from \"./multi-select-value.js\";\n\n/**\n * A select-only combobox with a multi-select listbox (WAI-ARIA APG) on `popover=\"auto\"`: `Root`\n * (no DOM, or one hidden input per value with `name`) > `Label`, `Trigger`\n * (`button[role=combobox]`) > `Value`, `Popup` (`div[popover=auto]`) > `List`\n * (`div[role=listbox][aria-multiselectable]`) > `Option`, `Group` > `GroupLabel`; `Empty` and\n * `Status` in the Popup. A pick toggles one option and the listbox stays open; each pick is a\n * transition with an optimistic selection and `data-pending` on the option. Single selection is\n * `Select`, the browser's own control.\n *\n * @see https://ui.funstack.work/components/multi-select\n */\nexport const MultiSelect = {\n Root: MultiSelectRoot,\n Label: MultiSelectLabel,\n Trigger: MultiSelectTrigger,\n Value: MultiSelectValue,\n Popup: MultiSelectPopup,\n List: MultiSelectList,\n Option: MultiSelectOption,\n Group: MultiSelectGroup,\n GroupLabel: MultiSelectGroupLabel,\n Empty: MultiSelectEmpty,\n Status: MultiSelectStatus,\n} as const;\n\nexport type {\n MultiSelectRootProps,\n MultiSelectRootState,\n MultiSelectValueChangeDetails,\n MultiSelectOpenChangeDetails,\n} from \"./multi-select-root.js\";\nexport type { MultiSelectLabelProps, MultiSelectLabelState } from \"./multi-select-label.js\";\nexport type { MultiSelectTriggerProps, MultiSelectTriggerState } from \"./multi-select-trigger.js\";\nexport type { MultiSelectValueProps, MultiSelectValueState } from \"./multi-select-value.js\";\nexport type { MultiSelectPopupProps, MultiSelectPopupState } from \"./multi-select-popup.js\";\nexport type { MultiSelectListProps, MultiSelectListState } from \"./multi-select-list.js\";\nexport type { MultiSelectOptionProps, MultiSelectOptionState } from \"./multi-select-option.js\";\nexport type {\n MultiSelectGroupProps,\n MultiSelectGroupState,\n MultiSelectGroupLabelProps,\n MultiSelectGroupLabelState,\n MultiSelectEmptyProps,\n MultiSelectEmptyState,\n MultiSelectStatusProps,\n MultiSelectStatusState,\n} from \"./multi-select-group.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA4BA,MAAa,cAAc;CACzB,MAAM;CACN,OAAO;CACP,SAAS;CACT,OAAO;CACP,OAAO;CACP,MAAM;CACN,QAAQ;CACR,OAAO;CACP,YAAY;CACZ,OAAO;CACP,QAAQ;AACV"}
@@ -0,0 +1,19 @@
1
+ "use client";
2
+ import { createContext, use } from "react";
3
+ //#region src/multi-select/multi-select-context.ts
4
+ const MultiSelectContext = createContext(null);
5
+ function useMultiSelectContext(part) {
6
+ const context = use(MultiSelectContext);
7
+ if (context === null) throw new Error(`${part} must be rendered inside a MultiSelect.Root.`);
8
+ return context;
9
+ }
10
+ /** Provided by `MultiSelect.Popup` (a List outside a Popup warns). */
11
+ const MultiSelectPopupContext = createContext(false);
12
+ /** Provided by `MultiSelect.List` (an Option outside a List warns). */
13
+ const MultiSelectListContext = createContext(false);
14
+ /** `MultiSelect.Group`: the id its `MultiSelect.GroupLabel` renders. */
15
+ const MultiSelectGroupContext = createContext(null);
16
+ //#endregion
17
+ export { MultiSelectContext, MultiSelectGroupContext, MultiSelectListContext, MultiSelectPopupContext, useMultiSelectContext };
18
+
19
+ //# sourceMappingURL=multi-select-context.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi-select-context.mjs","names":[],"sources":["../../src/multi-select/multi-select-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { RefObject } from \"react\";\nimport type { PopoverRootValue } from \"../internal/overlay/use-overlay-root.js\";\nimport type { ListboxOptionEntry } from \"../internal/use-option-registry.js\";\n\n/** One MultiSelect: what its Root provides to every part (design/components/multi-select.md B.1). */\nexport interface MultiSelectContextValue {\n /** The shared popover machinery (`usePopoverRoot`, library mode). */\n readonly popover: PopoverRootValue;\n readonly ids: {\n readonly trigger: string;\n readonly label: string;\n readonly list: string;\n /** `${root}-option-`: an Option's id is this plus `encodeURIComponent(value)`. */\n readonly optionPrefix: string;\n };\n /** Optimistic selection in pick order. */\n readonly values: readonly string[];\n /** For each value, the label cache's entry from render state (`undefined`: never seen). */\n readonly labels: readonly (string | undefined)[];\n /** `value` is in the optimistic selection (`aria-selected`, `data-selected`). */\n readonly isSelected: (value: string) => boolean;\n /** `data-pending` of an Option: its optimistic and committed membership differ (B.5). */\n readonly isPending: (value: string) => boolean;\n /** A value or open transition is in flight (the Root's `pending`). */\n readonly pending: boolean;\n /** The option `aria-activedescendant` points at (urgent virtual focus), or `null`. */\n readonly activeValue: string | null;\n /** No option is mounted and the List is not loading (`Empty`, `data-empty`). */\n readonly empty: boolean;\n /** A `MultiSelect.Status` is mounted inside the List (a Suspense fallback). */\n readonly loading: boolean;\n /** A `MultiSelect.Label` is mounted (the List's `aria-labelledby` names it only then). */\n readonly hasLabel: boolean;\n /** The enclosing `Field.Label`'s id: names the List when no `MultiSelect.Label` is mounted. */\n readonly fieldLabelId: string | undefined;\n readonly disabled: boolean;\n /** `required` (own or the Field's): the Trigger renders the validity element (B.10). */\n readonly required: boolean;\n /** The Root's `form`, for the validity element. */\n readonly form: string | undefined;\n readonly triggerRef: RefObject<HTMLButtonElement | null>;\n readonly listRef: RefObject<HTMLElement | null>;\n /** The validity element (B.10), rendered by the Trigger with `required`. */\n readonly validityRef: RefObject<HTMLSelectElement | null>;\n /** Registers a mounted Option; returns the unregistration. */\n readonly registerOption: (value: string, entry: ListboxOptionEntry) => () => void;\n /** Registers a mounted `MultiSelect.Status`; while one is mounted the List is loading. */\n readonly registerStatus: () => () => void;\n /** Registers a mounted `MultiSelect.Label`; returns the unregistration. */\n readonly registerLabel: () => () => void;\n /** Make `value` the active option (urgent; never dispatches). */\n readonly setActive: (value: string | null) => void;\n /** A pick (B.5): toggles the option; the listbox stays open. */\n readonly toggle: (value: string, event: Event) => void;\n /** The Trigger's click (B.4): toggles the listbox and focuses the Trigger. */\n readonly triggerClick: (event: MouseEvent) => void;\n /** The keyboard model of B.8, run by the Trigger's `onKeyDown`. */\n readonly keyDown: (event: KeyboardEvent) => void;\n /** Focus arrived on the Trigger: track presses until a leave is decided. */\n readonly focusIn: (event: FocusEvent) => void;\n /** Focus left the Trigger (B.4): the listbox closes when it went outside the Popup. */\n readonly focusOut: (event: FocusEvent) => void;\n /** The Label's click (B.8): focus the Trigger without opening the listbox. */\n readonly labelClick: (event: MouseEvent) => void;\n}\n\nexport const MultiSelectContext = createContext<MultiSelectContextValue | null>(null);\n\nexport function useMultiSelectContext(part: string): MultiSelectContextValue {\n const context = use(MultiSelectContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a MultiSelect.Root.`);\n }\n return context;\n}\n\n/** Provided by `MultiSelect.Popup` (a List outside a Popup warns). */\nexport const MultiSelectPopupContext = createContext<boolean>(false);\n\n/** Provided by `MultiSelect.List` (an Option outside a List warns). */\nexport const MultiSelectListContext = createContext<boolean>(false);\n\n/** `MultiSelect.Group`: the id its `MultiSelect.GroupLabel` renders. */\nexport const MultiSelectGroupContext = createContext<string | null>(null);\n"],"mappings":";;;AAoEA,MAAa,qBAAqB,cAA8C,IAAI;AAEpF,SAAgB,sBAAsB,MAAuC;CAC3E,MAAM,UAAU,IAAI,kBAAkB;CACtC,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,GAAG,KAAK,6CAA6C;CAEvE,OAAO;AACT;;AAGA,MAAa,0BAA0B,cAAuB,KAAK;;AAGnE,MAAa,yBAAyB,cAAuB,KAAK;;AAGlE,MAAa,0BAA0B,cAA6B,IAAI"}
@@ -0,0 +1,120 @@
1
+ import { RenderProp, StateValue } from "../internal/types.mjs";
2
+ import { MultiSelectListState } from "./multi-select-list.mjs";
3
+ import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
4
+ //#region src/multi-select/multi-select-group.d.ts
5
+ /** State of `MultiSelect.Group`: empty (the part has no state of its own). */
6
+ export type MultiSelectGroupState = Record<string, never>;
7
+ /** State of `MultiSelect.GroupLabel`: empty (the part has no state of its own). */
8
+ export type MultiSelectGroupLabelState = Record<string, never>;
9
+ /** State of `MultiSelect.Status`: empty (the part has no state of its own). */
10
+ export type MultiSelectStatusState = Record<string, never>;
11
+ /** `MultiSelect.Empty` renders from the List's state. */
12
+ export type MultiSelectEmptyState = MultiSelectListState;
13
+ /**
14
+ * Props of `MultiSelect.Group`.
15
+ *
16
+ * @see https://ui.funstack.work/components/multi-select
17
+ */
18
+ export interface MultiSelectGroupProps extends Omit<ComponentPropsWithRef<"div">, "role" | "className" | "style" | "children"> {
19
+ /** Class name, or a function of the part's state that returns one. */
20
+ className?: StateValue<string | undefined, MultiSelectGroupState>;
21
+ /** Inline style, or a function of the part's state that returns one. */
22
+ style?: StateValue<CSSProperties | undefined, MultiSelectGroupState>;
23
+ /** Content, or a function of the part's state. */
24
+ children?: StateValue<ReactNode, MultiSelectGroupState>;
25
+ /** Replace the default `<div>` (element form) or take over rendering (function form). */
26
+ render?: RenderProp<ComponentPropsWithRef<"div">, MultiSelectGroupState>;
27
+ }
28
+ /**
29
+ * A labelled set of options: `<div role="group" aria-labelledby>` named by the
30
+ * `MultiSelect.GroupLabel` inside it. Owned keys: `role`, `aria-labelledby` (token-merged).
31
+ *
32
+ * @see https://ui.funstack.work/components/multi-select
33
+ */
34
+ export declare function MultiSelectGroup({ className, style, children, render, ...rest }: MultiSelectGroupProps): import("react").JSX.Element;
35
+ export declare namespace MultiSelectGroup {
36
+ var displayName: string;
37
+ }
38
+ /**
39
+ * Props of `MultiSelect.GroupLabel`.
40
+ *
41
+ * @see https://ui.funstack.work/components/multi-select
42
+ */
43
+ export interface MultiSelectGroupLabelProps extends Omit<ComponentPropsWithRef<"div">, "id" | "className" | "style" | "children"> {
44
+ /** Class name, or a function of the part's state that returns one. */
45
+ className?: StateValue<string | undefined, MultiSelectGroupLabelState>;
46
+ /** Inline style, or a function of the part's state that returns one. */
47
+ style?: StateValue<CSSProperties | undefined, MultiSelectGroupLabelState>;
48
+ /** Content, or a function of the part's state. */
49
+ children?: StateValue<ReactNode, MultiSelectGroupLabelState>;
50
+ /** Replace the default `<div>` (element form) or take over rendering (function form). */
51
+ render?: RenderProp<ComponentPropsWithRef<"div">, MultiSelectGroupLabelState>;
52
+ }
53
+ /**
54
+ * The name of the enclosing `MultiSelect.Group`: a `<div>` with the referenced id. Owned key:
55
+ * `id`.
56
+ *
57
+ * @see https://ui.funstack.work/components/multi-select
58
+ */
59
+ export declare function MultiSelectGroupLabel({ className, style, children, render, ...rest }: MultiSelectGroupLabelProps): ReactNode;
60
+ export declare namespace MultiSelectGroupLabel {
61
+ var displayName: string;
62
+ }
63
+ /**
64
+ * Props of `MultiSelect.Empty`.
65
+ *
66
+ * @see https://ui.funstack.work/components/multi-select
67
+ */
68
+ export interface MultiSelectEmptyProps extends Omit<ComponentPropsWithRef<"div">, "className" | "style" | "children"> {
69
+ /** Class name, or a function of the part's state that returns one. */
70
+ className?: StateValue<string | undefined, MultiSelectEmptyState>;
71
+ /** Inline style, or a function of the part's state that returns one. */
72
+ style?: StateValue<CSSProperties | undefined, MultiSelectEmptyState>;
73
+ /** Content, or a function of the part's state. */
74
+ children?: StateValue<ReactNode, MultiSelectEmptyState>;
75
+ /** Replace the default `<div>` (element form) or take over rendering (function form). */
76
+ render?: RenderProp<ComponentPropsWithRef<"div">, MultiSelectEmptyState>;
77
+ }
78
+ /**
79
+ * "Nothing to choose from": renders a `<div>` with its children only when the List has **no
80
+ * mounted options and none are loading** (no `MultiSelect.Status` mounted inside the List);
81
+ * nothing otherwise (combobox.md 6.3). Place it in the Popup, outside the List (a listbox holds
82
+ * only options). Owns no keys.
83
+ *
84
+ * @see https://ui.funstack.work/components/multi-select
85
+ */
86
+ export declare function MultiSelectEmpty({ className, style, children, render, ...rest }: MultiSelectEmptyProps): ReactNode;
87
+ export declare namespace MultiSelectEmpty {
88
+ var displayName: string;
89
+ }
90
+ /**
91
+ * Props of `MultiSelect.Status`.
92
+ *
93
+ * @see https://ui.funstack.work/components/multi-select
94
+ */
95
+ export interface MultiSelectStatusProps extends Omit<ComponentPropsWithRef<"div">, "role" | "className" | "style" | "children"> {
96
+ /** Class name, or a function of the part's state that returns one. */
97
+ className?: StateValue<string | undefined, MultiSelectStatusState>;
98
+ /** Inline style, or a function of the part's state that returns one. */
99
+ style?: StateValue<CSSProperties | undefined, MultiSelectStatusState>;
100
+ /** Content, or a function of the part's state. */
101
+ children?: StateValue<ReactNode, MultiSelectStatusState>;
102
+ /** Replace the default `<div>` (element form) or take over rendering (function form). */
103
+ render?: RenderProp<ComponentPropsWithRef<"div">, MultiSelectStatusState>;
104
+ }
105
+ /**
106
+ * A loading row or a hint. Rendered **inside the List** (the usual Suspense fallback,
107
+ * `<Suspense fallback={<MultiSelect.Status>Loading…</MultiSelect.Status>}>`), it marks the
108
+ * List as loading: `<div role="none">` (a listbox owns only options and groups; the List is
109
+ * `aria-busy` instead), `Empty` stays hidden and the initial active option waits until the
110
+ * options are there. Rendered in the Popup outside the List it is a plain hint,
111
+ * `<div role="status">`. Owned key: `role`.
112
+ *
113
+ * @see https://ui.funstack.work/components/multi-select
114
+ */
115
+ export declare function MultiSelectStatus({ className, style, children, render, ...rest }: MultiSelectStatusProps): ReactNode;
116
+ export declare namespace MultiSelectStatus {
117
+ var displayName: string;
118
+ }
119
+ //#endregion
120
+ //# sourceMappingURL=multi-select-group.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi-select-group.d.mts","names":[],"sources":["../../src/multi-select/multi-select-group.tsx"],"mappings":";;;;;YAgBY,wBAAwB;;YAExB,6BAA6B;;YAE7B,yBAAyB;;YAEzB,wBAAwB;;;;;;iBASnB,8BAA8B,KAC7C;;EAIA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;wBASpC,mBACd,WACA,OACA,UACA,WACG,QACF,wCAAqB,IAAA;yBANR;;;;;;;;iBA6BC,mCAAmC,KAClD;;EAIA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;wBASpC,wBACd,WACA,OACA,UACA,WACG,QACF,6BAA0B;yBANb;;;;;;;;iBA+BC,8BAA8B,KAC7C;;EAIA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;wBAWpC,mBACd,WACA,OACA,UACA,WACG,QACF,wBAAqB;yBANR;;;;;;;;iBA4BC,+BAA+B,KAC9C;;EAIA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;wBAapC,oBACd,WACA,OACA,UACA,WACG,QACF,yBAAsB;yBANT"}
@@ -0,0 +1,111 @@
1
+ "use client";
2
+ import { useDevWarning } from "../internal/use-dev-warning.mjs";
3
+ import { useRender } from "../internal/use-render.mjs";
4
+ import { MultiSelectGroupContext, MultiSelectListContext, useMultiSelectContext } from "./multi-select-context.mjs";
5
+ import { use, useId, useLayoutEffect } from "react";
6
+ import { jsx } from "react/jsx-runtime";
7
+ //#region src/multi-select/multi-select-group.tsx
8
+ const isDev = process.env.NODE_ENV !== "production";
9
+ const EMPTY = {};
10
+ /**
11
+ * A labelled set of options: `<div role="group" aria-labelledby>` named by the
12
+ * `MultiSelect.GroupLabel` inside it. Owned keys: `role`, `aria-labelledby` (token-merged).
13
+ *
14
+ * @see https://ui.funstack.work/components/multi-select
15
+ */
16
+ function MultiSelectGroup({ className, style, children, render, ...rest }) {
17
+ useMultiSelectContext("MultiSelect.Group");
18
+ const labelId = `${useId()}-label`;
19
+ const element = useRender({
20
+ defaultElement: "div",
21
+ render,
22
+ state: EMPTY,
23
+ className,
24
+ style,
25
+ children,
26
+ props: rest,
27
+ libraryProps: {
28
+ role: "group",
29
+ "aria-labelledby": labelId
30
+ }
31
+ });
32
+ return /* @__PURE__ */ jsx(MultiSelectGroupContext, {
33
+ value: labelId,
34
+ children: element
35
+ });
36
+ }
37
+ MultiSelectGroup.displayName = "MultiSelectGroup";
38
+ /**
39
+ * The name of the enclosing `MultiSelect.Group`: a `<div>` with the referenced id. Owned key:
40
+ * `id`.
41
+ *
42
+ * @see https://ui.funstack.work/components/multi-select
43
+ */
44
+ function MultiSelectGroupLabel({ className, style, children, render, ...rest }) {
45
+ const labelId = use(MultiSelectGroupContext);
46
+ useDevWarning(labelId === null, isDev && "MultiSelect.GroupLabel: rendered outside a MultiSelect.Group; it names nothing.");
47
+ return useRender({
48
+ defaultElement: "div",
49
+ render,
50
+ state: EMPTY,
51
+ className,
52
+ style,
53
+ children,
54
+ props: rest,
55
+ libraryProps: labelId === null ? {} : { id: labelId }
56
+ });
57
+ }
58
+ MultiSelectGroupLabel.displayName = "MultiSelectGroupLabel";
59
+ /**
60
+ * "Nothing to choose from": renders a `<div>` with its children only when the List has **no
61
+ * mounted options and none are loading** (no `MultiSelect.Status` mounted inside the List);
62
+ * nothing otherwise (combobox.md 6.3). Place it in the Popup, outside the List (a listbox holds
63
+ * only options). Owns no keys.
64
+ *
65
+ * @see https://ui.funstack.work/components/multi-select
66
+ */
67
+ function MultiSelectEmpty({ className, style, children, render, ...rest }) {
68
+ const ctx = useMultiSelectContext("MultiSelect.Empty");
69
+ const state = { empty: ctx.empty };
70
+ const element = useRender({
71
+ defaultElement: "div",
72
+ render,
73
+ state,
74
+ className,
75
+ style,
76
+ children,
77
+ props: rest
78
+ });
79
+ return ctx.empty ? element : null;
80
+ }
81
+ MultiSelectEmpty.displayName = "MultiSelectEmpty";
82
+ /**
83
+ * A loading row or a hint. Rendered **inside the List** (the usual Suspense fallback,
84
+ * `<Suspense fallback={<MultiSelect.Status>Loading…</MultiSelect.Status>}>`), it marks the
85
+ * List as loading: `<div role="none">` (a listbox owns only options and groups; the List is
86
+ * `aria-busy` instead), `Empty` stays hidden and the initial active option waits until the
87
+ * options are there. Rendered in the Popup outside the List it is a plain hint,
88
+ * `<div role="status">`. Owned key: `role`.
89
+ *
90
+ * @see https://ui.funstack.work/components/multi-select
91
+ */
92
+ function MultiSelectStatus({ className, style, children, render, ...rest }) {
93
+ const { registerStatus } = useMultiSelectContext("MultiSelect.Status");
94
+ const inList = use(MultiSelectListContext);
95
+ useLayoutEffect(() => inList ? registerStatus() : void 0, [inList, registerStatus]);
96
+ return useRender({
97
+ defaultElement: "div",
98
+ render,
99
+ state: EMPTY,
100
+ className,
101
+ style,
102
+ children,
103
+ props: rest,
104
+ libraryProps: { role: inList ? "none" : "status" }
105
+ });
106
+ }
107
+ MultiSelectStatus.displayName = "MultiSelectStatus";
108
+ //#endregion
109
+ export { MultiSelectEmpty, MultiSelectGroup, MultiSelectGroupLabel, MultiSelectStatus };
110
+
111
+ //# sourceMappingURL=multi-select-group.mjs.map