@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
@@ -1 +1 @@
1
- {"version":3,"file":"combobox-keyboard.mjs","names":[],"sources":["../../src/combobox/combobox-keyboard.ts"],"sourcesContent":["\"use client\";\nimport { flushSync } from \"react-dom\";\nimport { isPopoverOpen } from \"../internal/overlay/popover-open.js\";\nimport type { PopoverRootValue } from \"../internal/overlay/use-overlay-root.js\";\nimport type { ActiveOption } from \"./use-active-option.js\";\nimport type { OptionRegistry } from \"./use-option-registry.js\";\n\nexport interface ComboboxKeyboardOptions {\n /** The Root's `disabled`, `loop` and `allowCustomValue`. */\n readonly disabled: boolean;\n readonly loop: boolean;\n readonly allowCustomValue: boolean;\n readonly popover: Pick<PopoverRootValue, \"popupRef\" | \"requestOpen\" | \"requestClose\">;\n readonly options: Pick<OptionRegistry, \"registry\" | \"orderedOptions\">;\n readonly active: Pick<ActiveOption, \"activeRef\" | \"setActive\" | \"pendingEdgeRef\">;\n /** Accepts an option (design 5.2). */\n readonly accept: (optionValue: string, event: Event) => void;\n /** Free text as the value (design 5.3). Returns whether it dispatched. */\n readonly commitText: (event: Event, close: boolean) => boolean;\n}\n\n/**\n * The keyboard model of the Combobox Input (design/components/combobox.md 8), the counterpart of\n * `menu/use-menu-keyboard.ts`. A plain factory, not a hook (it calls none): the Root calls it on\n * every render. Returns the Input's `keydown` handler, which tells whether it handled the key.\n */\nexport function createComboboxKeyDown({\n disabled,\n loop,\n allowCustomValue,\n popover,\n options,\n active,\n accept,\n commitText,\n}: ComboboxKeyboardOptions): (event: KeyboardEvent) => boolean {\n const { registry, orderedOptions } = options;\n const { activeRef, setActive, pendingEdgeRef } = active;\n\n const move = (direction: 1 | -1): void => {\n const enabled = orderedOptions().filter((option) => !option.disabled);\n if (enabled.length === 0) return;\n const last = enabled.length - 1;\n const index = enabled.findIndex((option) => option.value === activeRef.current);\n let next: number;\n if (direction === 1) next = index < 0 ? 0 : index >= last ? (loop ? 0 : last) : index + 1;\n else next = index < 0 ? last : index <= 0 ? (loop ? last : 0) : index - 1;\n const target = enabled[next]!;\n setActive(target.value);\n if (typeof target.element.scrollIntoView === \"function\") {\n target.element.scrollIntoView({ block: \"nearest\" });\n }\n };\n\n const activeEnabled = (): string | null => {\n const current = activeRef.current;\n if (current === null) return null;\n const entry = registry.get(current);\n return entry !== undefined && !entry.disabled ? current : null;\n };\n\n return (event: KeyboardEvent): boolean => {\n if (disabled || event.ctrlKey || event.metaKey) return false;\n // IME: the key belongs to the composition (Enter commits it, arrows pick a candidate).\n if (event.isComposing || event.keyCode === 229) return false;\n // What the user sees, not what is intended: right after Escape the platform has hidden the\n // popup but its `toggle` (and the fact it reports) is still queued, and an open that\n // is still committing shows nothing yet. Enter must submit and arrows must open in both.\n const isOpen = isPopoverOpen(popover.popupRef.current);\n switch (event.key) {\n case \"ArrowDown\":\n event.preventDefault();\n if (event.altKey) {\n if (!isOpen) popover.requestOpen(event, \"activate\");\n } else if (!isOpen) {\n pendingEdgeRef.current = \"first\";\n popover.requestOpen(event, \"activate\");\n } else {\n move(1);\n }\n return true;\n case \"ArrowUp\":\n event.preventDefault();\n if (event.altKey) {\n if (isOpen) {\n const current = activeEnabled();\n if (current !== null) accept(current, event);\n else popover.requestClose(event, \"activate\");\n }\n } else if (!isOpen) {\n pendingEdgeRef.current = \"last\";\n popover.requestOpen(event, \"activate\");\n } else {\n move(-1);\n }\n return true;\n case \"Enter\": {\n if (isOpen) {\n // An open listbox means the user is choosing: never submit from here.\n event.preventDefault();\n const current = activeEnabled();\n if (current !== null) accept(current, event);\n else if (allowCustomValue && !commitText(event, true)) {\n popover.requestClose(event, \"activate\");\n }\n return true;\n }\n // Closed: not prevented, so a form still submits. The key's default action (implicit\n // submission) must see the optimistic hidden value: Firefox submits before React's\n // scheduled flush of the optimistic render, so it is flushed here (design 5.3).\n if (allowCustomValue) flushSync(() => commitText(event, false));\n return false;\n }\n case \"Home\":\n case \"End\":\n case \"ArrowLeft\":\n case \"ArrowRight\":\n // APG: the caret keys move visual focus to the input (not prevented: the caret moves).\n if (activeRef.current !== null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;KAClB,eAAe,UAAU;KACzB,QAAQ,YAAY,OAAO,UAAU;IACvC,OACE,KAAK,CAAC;IAER,OAAO;GACT,KAAK;IACH,MAAM,eAAe;IACrB,IAAI,MAAM,QACJ;SAAA,QAAQ;MACV,MAAM,UAAU,cAAc;MAC9B,IAAI,YAAY,MAAM,OAAO,SAAS,KAAK;WACtC,QAAQ,aAAa,OAAO,UAAU;KAC7C;WACK,IAAI,CAAC,QAAQ;KAClB,eAAe,UAAU;KACzB,QAAQ,YAAY,OAAO,UAAU;IACvC,OACE,KAAK,EAAE;IAET,OAAO;GACT,KAAK;IACH,IAAI,QAAQ;KAEV,MAAM,eAAe;KACrB,MAAM,UAAU,cAAc;KAC9B,IAAI,YAAY,MAAM,OAAO,SAAS,KAAK;UACtC,IAAI,oBAAoB,CAAC,WAAW,OAAO,IAAI,GAClD,QAAQ,aAAa,OAAO,UAAU;KAExC,OAAO;IACT;IAIA,IAAI,kBAAkB,gBAAgB,WAAW,OAAO,KAAK,CAAC;IAC9D,OAAO;GAET,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;IAEH,IAAI,UAAU,YAAY,MAAM,UAAU,IAAI;IAC9C,OAAO;GACT,SACE,OAAO;EACX;CACF;AACF"}
1
+ {"version":3,"file":"combobox-keyboard.mjs","names":[],"sources":["../../src/combobox/combobox-keyboard.ts"],"sourcesContent":["\"use client\";\nimport { flushSync } from \"react-dom\";\nimport { isPopoverOpen } from \"../internal/overlay/popover-open.js\";\nimport type { RefObject } from \"react\";\nimport type { PopoverRootValue } from \"../internal/overlay/use-overlay-root.js\";\nimport type { ActiveOption } from \"../internal/use-active-option.js\";\nimport type { OptionRegistry } from \"../internal/use-option-registry.js\";\n\nexport interface ComboboxKeyboardOptions {\n /** The Root's `disabled`, `loop` and `allowCustomValue`. */\n readonly disabled: boolean;\n readonly loop: boolean;\n readonly allowCustomValue: boolean;\n readonly popover: Pick<\n PopoverRootValue,\n \"popupRef\" | \"requestOpen\" | \"requestClose\" | \"intended\" | \"committed\"\n >;\n readonly options: Pick<OptionRegistry, \"registry\" | \"orderedOptions\">;\n readonly active: Pick<ActiveOption, \"activeRef\" | \"setActive\" | \"pendingEdgeRef\">;\n /** Accepts an option (design 5.2). */\n readonly accept: (optionValue: string, event: Event) => void;\n /** Free text as the value (design 5.3). Returns whether it dispatched. */\n readonly commitText: (event: Event, close: boolean) => boolean;\n /** With `multiple` (design 15.6): the keys that differ, and the chips. */\n readonly multiple: ComboboxMultipleKeys | undefined;\n}\n\n/** What the Input's keys need from a `multiple` Root (design 15.6, 15.9). */\nexport interface ComboboxMultipleKeys {\n /** The text (urgent). */\n readonly textRef: RefObject<string>;\n /** At least one value is selected (optimistic): there is a chip. */\n readonly hasChips: () => boolean;\n /** Backspace in the empty input: remove the last chip and announce it. */\n readonly removeLast: (event: Event) => void;\n /** The inline-start arrow at the caret's start: focus the last chip. `false`: none mounted. */\n readonly focusLastChip: () => boolean;\n /** `allowCustomValue`: add the text as a value (or nothing if it is one) and clear it. */\n readonly addText: (event: Event) => void;\n /** Clear unmatched text (`\"dismiss\"`). */\n readonly clearText: (event: Event) => void;\n}\n\n/** The caret is at the start of the input with nothing selected. */\nfunction caretAtStart(target: EventTarget | null): boolean {\n if (!(target instanceof HTMLInputElement)) return false;\n return target.selectionStart === 0 && target.selectionEnd === 0;\n}\n\n/** ArrowLeft, or ArrowRight when the input's computed direction is `rtl` (design 15.6). */\nfunction isInlineStartArrow(event: KeyboardEvent): boolean {\n const target = event.target;\n const rtl =\n target instanceof Element &&\n target.ownerDocument.defaultView?.getComputedStyle(target).direction === \"rtl\";\n return event.key === (rtl ? \"ArrowRight\" : \"ArrowLeft\");\n}\n\n/**\n * The keyboard model of the Combobox Input (design/components/combobox.md 8), the counterpart of\n * `menu/use-menu-keyboard.ts`. A plain factory, not a hook (it calls none): the Root calls it on\n * every render. Returns the Input's `keydown` handler, which tells whether it handled the key.\n */\nexport function createComboboxKeyDown({\n disabled,\n loop,\n allowCustomValue,\n popover,\n options,\n active,\n accept,\n commitText,\n multiple,\n}: ComboboxKeyboardOptions): (event: KeyboardEvent) => boolean {\n const { registry, orderedOptions } = options;\n const { activeRef, setActive, pendingEdgeRef } = active;\n\n const move = (direction: 1 | -1): void => {\n const enabled = orderedOptions().filter((option) => !option.disabled);\n if (enabled.length === 0) return;\n const last = enabled.length - 1;\n const index = enabled.findIndex((option) => option.value === activeRef.current);\n let next: number;\n if (direction === 1) next = index < 0 ? 0 : index >= last ? (loop ? 0 : last) : index + 1;\n else next = index < 0 ? last : index <= 0 ? (loop ? last : 0) : index - 1;\n const target = enabled[next]!;\n setActive(target.value);\n if (typeof target.element.scrollIntoView === \"function\") {\n target.element.scrollIntoView({ block: \"nearest\" });\n }\n };\n\n const activeEnabled = (): string | null => {\n const current = activeRef.current;\n if (current === null) return null;\n const entry = registry.get(current);\n return entry !== undefined && !entry.disabled ? current : null;\n };\n\n return (event: KeyboardEvent): boolean => {\n if (disabled || event.ctrlKey || event.metaKey) return false;\n // IME: the key belongs to the composition (Enter commits it, arrows pick a candidate).\n if (event.isComposing || event.keyCode === 229) return false;\n // What the user sees, not what is intended: right after Escape the platform has hidden the\n // popup but its `toggle` (and the fact it reports) is still queued, and an open that\n // is still committing shows nothing yet. Enter must submit and arrows must open in both.\n const isOpen = isPopoverOpen(popover.popupRef.current);\n switch (event.key) {\n case \"ArrowDown\":\n event.preventDefault();\n if (event.altKey) {\n if (!isOpen) popover.requestOpen(event, \"activate\");\n } else if (!isOpen) {\n pendingEdgeRef.current = \"first\";\n popover.requestOpen(event, \"activate\");\n } else {\n move(1);\n }\n return true;\n case \"ArrowUp\":\n event.preventDefault();\n if (event.altKey) {\n if (isOpen && multiple !== undefined) {\n // A pick toggles and does not close: Alt+ArrowUp only closes (design 15.6).\n popover.requestClose(event, \"activate\");\n } else if (isOpen) {\n const current = activeEnabled();\n if (current !== null) accept(current, event);\n else popover.requestClose(event, \"activate\");\n }\n } else if (!isOpen) {\n pendingEdgeRef.current = \"last\";\n popover.requestOpen(event, \"activate\");\n } else {\n move(-1);\n }\n return true;\n case \"Enter\": {\n if (multiple !== undefined) {\n if (isOpen) {\n event.preventDefault();\n const current = activeEnabled();\n if (current !== null) accept(current, event);\n else if (allowCustomValue && multiple.textRef.current !== \"\") multiple.addText(event);\n return true;\n }\n if (multiple.textRef.current === \"\") return false;\n // An open on its way (requested, not committed yet: a slow `openChangeAction`, or the\n // keystroke's own open still rendering): the user typed a search and is about to\n // pick, so Enter is prevented and the text is kept (design 15.6). Not after Escape:\n // there the committed state is still open until the `toggle` fact runs, and Enter\n // keeps the closed rules below (design 8).\n if (popover.intended() && !popover.committed) {\n event.preventDefault();\n return true;\n }\n if (allowCustomValue) {\n // The user is adding an item, not submitting the form (design 15.9).\n event.preventDefault();\n multiple.addText(event);\n return true;\n }\n // Unmatched text must not reach the submission (`required`, design 15.8): cleared in\n // one flush, then the key's default runs.\n flushSync(() => multiple.clearText(event));\n return false;\n }\n if (isOpen) {\n // An open listbox means the user is choosing: never submit from here.\n event.preventDefault();\n const current = activeEnabled();\n if (current !== null) accept(current, event);\n else if (allowCustomValue && !commitText(event, true)) {\n popover.requestClose(event, \"activate\");\n }\n return true;\n }\n // Closed: not prevented, so a form still submits. The key's default action (implicit\n // submission) must see the optimistic hidden value: Firefox submits before React's\n // scheduled flush of the optimistic render, so it is flushed here (design 5.3).\n if (allowCustomValue) flushSync(() => commitText(event, false));\n return false;\n }\n case \"Backspace\":\n // A held Backspace that emptied the text does not go on to eat chips (design 15.6).\n if (\n multiple !== undefined &&\n !event.repeat &&\n !event.altKey &&\n multiple.textRef.current === \"\" &&\n multiple.hasChips()\n ) {\n multiple.removeLast(event);\n return true;\n }\n return false;\n case \"ArrowLeft\":\n case \"ArrowRight\":\n if (\n multiple !== undefined &&\n !event.altKey &&\n !event.shiftKey &&\n isInlineStartArrow(event) &&\n caretAtStart(event.target) &&\n multiple.hasChips() &&\n multiple.focusLastChip()\n ) {\n event.preventDefault();\n if (activeRef.current !== null) setActive(null);\n return true;\n }\n if (activeRef.current !== null) setActive(null);\n return false;\n case \"Home\":\n case \"End\":\n // APG: the caret keys move visual focus to the input (not prevented: the caret moves).\n if (activeRef.current !== null) setActive(null);\n return false;\n default:\n return false;\n }\n };\n}\n"],"mappings":";;;;;AA4CA,SAAS,aAAa,QAAqC;CACzD,IAAI,EAAE,kBAAkB,mBAAmB,OAAO;CAClD,OAAO,OAAO,mBAAmB,KAAK,OAAO,iBAAiB;AAChE;;AAGA,SAAS,mBAAmB,OAA+B;CACzD,MAAM,SAAS,MAAM;CACrB,MAAM,MACJ,kBAAkB,WAClB,OAAO,cAAc,aAAa,iBAAiB,MAAM,CAAC,CAAC,cAAc;CAC3E,OAAO,MAAM,SAAS,MAAM,eAAe;AAC7C;;;;;;AAOA,SAAgB,sBAAsB,EACpC,UACA,MACA,kBACA,SACA,SACA,QACA,QACA,YACA,YAC6D;CAC7D,MAAM,EAAE,UAAU,mBAAmB;CACrC,MAAM,EAAE,WAAW,WAAW,mBAAmB;CAEjD,MAAM,QAAQ,cAA4B;EACxC,MAAM,UAAU,eAAe,CAAC,CAAC,QAAQ,WAAW,CAAC,OAAO,QAAQ;EACpE,IAAI,QAAQ,WAAW,GAAG;EAC1B,MAAM,OAAO,QAAQ,SAAS;EAC9B,MAAM,QAAQ,QAAQ,WAAW,WAAW,OAAO,UAAU,UAAU,OAAO;EAC9E,IAAI;EACJ,IAAI,cAAc,GAAG,OAAO,QAAQ,IAAI,IAAI,SAAS,OAAQ,OAAO,IAAI,OAAQ,QAAQ;OACnF,OAAO,QAAQ,IAAI,OAAO,SAAS,IAAK,OAAO,OAAO,IAAK,QAAQ;EACxE,MAAM,SAAS,QAAQ;EACvB,UAAU,OAAO,KAAK;EACtB,IAAI,OAAO,OAAO,QAAQ,mBAAmB,YAC3C,OAAO,QAAQ,eAAe,EAAE,OAAO,UAAU,CAAC;CAEtD;CAEA,MAAM,sBAAqC;EACzC,MAAM,UAAU,UAAU;EAC1B,IAAI,YAAY,MAAM,OAA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AEpB,MAAM,eAAe;MACrB,SAAS,QAAQ,KAAK;MACtB,OAAO;KACT;KAGA,gBAAgB,SAAS,UAAU,KAAK,CAAC;KACzC,OAAO;IACT;IACA,IAAI,QAAQ;KAEV,MAAM,eAAe;KACrB,MAAM,UAAU,cAAc;KAC9B,IAAI,YAAY,MAAM,OAAO,SAAS,KAAK;UACtC,IAAI,oBAAoB,CAAC,WAAW,OAAO,IAAI,GAClD,QAAQ,aAAa,OAAO,UAAU;KAExC,OAAO;IACT;IAIA,IAAI,kBAAkB,gBAAgB,WAAW,OAAO,KAAK,CAAC;IAC9D,OAAO;GAET,KAAK;IAEH,IACE,aAAa,KAAA,KACb,CAAC,MAAM,UACP,CAAC,MAAM,UACP,SAAS,QAAQ,YAAY,MAC7B,SAAS,SAAS,GAClB;KACA,SAAS,WAAW,KAAK;KACzB,OAAO;IACT;IACA,OAAO;GACT,KAAK;GACL,KAAK;IACH,IACE,aAAa,KAAA,KACb,CAAC,MAAM,UACP,CAAC,MAAM,YACP,mBAAmB,KAAK,KACxB,aAAa,MAAM,MAAM,KACzB,SAAS,SAAS,KAClB,SAAS,cAAc,GACvB;KACA,MAAM,eAAe;KACrB,IAAI,UAAU,YAAY,MAAM,UAAU,IAAI;KAC9C,OAAO;IACT;IACA,IAAI,UAAU,YAAY,MAAM,UAAU,IAAI;IAC9C,OAAO;GACT,KAAK;GACL,KAAK;IAEH,IAAI,UAAU,YAAY,MAAM,UAAU,IAAI;IAC9C,OAAO;GACT,SACE,OAAO;EACX;CACF;AACF"}
@@ -39,7 +39,7 @@ export interface ComboboxListProps extends Omit<ComponentPropsWithRef<"div">, "i
39
39
  * rendered as a Suspense fallback inside it marks the results as loading (`aria-busy="true"`).
40
40
  *
41
41
  * Owned keys (conventions 1.2): `id`, `role`, `aria-labelledby` (token-merged), `aria-busy`,
42
- * `data-stale`, `data-empty`.
42
+ * `aria-multiselectable` (with `multiple` only: `"true"`), `data-stale`, `data-empty`.
43
43
  *
44
44
  * @see https://ui.funstack.work/components/combobox
45
45
  */
@@ -17,7 +17,7 @@ const isDev = process.env.NODE_ENV !== "production";
17
17
  * rendered as a Suspense fallback inside it marks the results as loading (`aria-busy="true"`).
18
18
  *
19
19
  * Owned keys (conventions 1.2): `id`, `role`, `aria-labelledby` (token-merged), `aria-busy`,
20
- * `data-stale`, `data-empty`.
20
+ * `aria-multiselectable` (with `multiple` only: `"true"`), `data-stale`, `data-empty`.
21
21
  *
22
22
  * @see https://ui.funstack.work/components/combobox
23
23
  */
@@ -44,6 +44,7 @@ function ComboboxList({ className, style, children, render, ...rest }) {
44
44
  role: "listbox",
45
45
  ...ctx.hasLabel ? { "aria-labelledby": ctx.ids.label } : ctx.fieldLabelId !== void 0 && { "aria-labelledby": ctx.fieldLabelId },
46
46
  "aria-busy": ctx.stale || ctx.loading ? true : void 0,
47
+ ...ctx.multiple && { "aria-multiselectable": true },
47
48
  "data-stale": dataAttr(ctx.stale),
48
49
  "data-empty": dataAttr(ctx.empty)
49
50
  };
@@ -1 +1 @@
1
- {"version":3,"file":"combobox-list.mjs","names":[],"sources":["../../src/combobox/combobox-list.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useNameWarning } from \"../internal/use-name-warning.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport {\n ComboboxListContext,\n ComboboxPopupContext,\n useComboboxContext,\n} from \"./combobox-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `Combobox.List`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface ComboboxListState {\n /** The deferred text the results are for: render the Options for it. */\n readonly query: string;\n /** The results shown are for an older text (`aria-busy`). */\n readonly stale: boolean;\n /** No option is mounted and the results are settled. */\n readonly empty: boolean;\n}\n\n/**\n * Props of `Combobox.List`.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport interface ComboboxListProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"id\" | \"role\" | \"aria-busy\" | \"className\" | \"style\" | \"children\"\n> {\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ComboboxListState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ComboboxListState>;\n /**\n * Usually a function of `{ query }` rendering the Options for it, under your own `<Suspense>`\n * for an async search. The previous results stay visible while the next ones load.\n */\n children?: StateValue<ReactNode, ComboboxListState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, ComboboxListState>;\n}\n\n/**\n * The listbox: `<div role=\"listbox\" aria-labelledby={label}>` (only while a `Combobox.Label` is\n * mounted), the element the input's `aria-controls` names. Its children are the results for the\n * deferred `query` (the library filters nothing, design 6.1); while they are for an older text it\n * carries `aria-busy=\"true\"` and `data-stale`. Contains only Options and Groups; a `Status`\n * rendered as a Suspense fallback inside it marks the results as loading (`aria-busy=\"true\"`).\n *\n * Owned keys (conventions 1.2): `id`, `role`, `aria-labelledby` (token-merged), `aria-busy`,\n * `data-stale`, `data-empty`.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport function ComboboxList({ className, style, children, render, ...rest }: ComboboxListProps) {\n const ctx = useComboboxContext(\"Combobox.List\");\n const inPopup = use(ComboboxPopupContext);\n useDevWarning(\n !inPopup,\n isDev &&\n \"Combobox.List: rendered outside a Combobox.Popup. The listbox must be inside the Popup, \" +\n \"which is the element the library shows and hides.\",\n );\n const { listRef } = ctx;\n // A mounted Label registers in a layout effect whose re-render is flushed before the check's\n // microtask, so `aria-labelledby` is in the DOM by then if it ever will be.\n const checkName = useNameWarning(\n isDev &&\n \"Combobox.List: the listbox has no accessible name. Render a Combobox.Label, or give \" +\n \"the List an `aria-label` / `aria-labelledby`.\",\n );\n\n const ref = useCallback(\n (element: HTMLElement) => {\n listRef.current = element;\n checkName?.(element);\n return () => {\n if (listRef.current === element) listRef.current = null;\n };\n },\n [listRef, checkName],\n );\n\n const state: ComboboxListState = { query: ctx.query, stale: ctx.stale, empty: ctx.empty };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: ctx.ids.list,\n role: \"listbox\",\n ...(ctx.hasLabel\n ? { \"aria-labelledby\": ctx.ids.label }\n : ctx.fieldLabelId !== undefined && { \"aria-labelledby\": ctx.fieldLabelId }),\n \"aria-busy\": ctx.stale || ctx.loading ? true : undefined,\n \"data-stale\": dataAttr(ctx.stale),\n \"data-empty\": dataAttr(ctx.empty),\n };\n\n return useRender<ComponentPropsWithRef<\"div\">, ComboboxListState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n style,\n children: (s) => (\n <ComboboxListContext value={true}>{resolveStateValue(children, s)}</ComboboxListContext>\n ),\n props: rest,\n libraryProps,\n ref,\n });\n}\n\nComboboxList.displayName = \"ComboboxList\";\n"],"mappings":";;;;;;;;;;AAeA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;AAiDvC,SAAgB,aAAa,EAAE,WAAW,OAAO,UAAU,QAAQ,GAAG,QAA2B;CAC/F,MAAM,MAAM,mBAAmB,eAAe;CAC9C,MAAM,UAAU,IAAI,oBAAoB;CACxC,cACE,CAAC,SACD,SACE,2IAEJ;CACA,MAAM,EAAE,YAAY;CAGpB,MAAM,YAAY,eAChB,SACE,mIAEJ;CAEA,MAAM,MAAM,aACT,YAAyB;EACxB,QAAQ,UAAU;EAClB,YAAY,OAAO;EACnB,aAAa;GACX,IAAI,QAAQ,YAAY,SAAS,QAAQ,UAAU;EACrD;CACF,GACA,CAAC,SAAS,SAAS,CACrB;CAEA,MAAM,QAA2B;EAAE,OAAO,IAAI;EAAO,OAAO,IAAI;EAAO,OAAO,IAAI;CAAM;CAExF,MAAM,eAA8D;EAClE,IAAI,IAAI,IAAI;EACZ,MAAM;EACN,GAAI,IAAI,WACJ,EAAE,mBAAmB,IAAI,IAAI,MAAM,IACnC,IAAI,iBAAiB,KAAA,KAAa,EAAE,mBAAmB,IAAI,aAAa;EAC5E,aAAa,IAAI,SAAS,IAAI,UAAU,OAAO,KAAA;EAC/C,cAAc,SAAS,IAAI,KAAK;EAChC,cAAc,SAAS,IAAI,KAAK;CAClC;CAEA,OAAO,UAA2D;EAChE,gBAAgB;EAChB;EACA;EACA;EACA;EACA,WAAW,MACT,oBAAC,qBAAD;GAAqB,OAAO;GAAO,UAAA,kBAAkB,UAAU,CAAC;EAAuB,CAAA;EAEzF,OAAO;EACP;EACA;CACF,CAAC;AACH;AAEA,aAAa,cAAc"}
1
+ {"version":3,"file":"combobox-list.mjs","names":[],"sources":["../../src/combobox/combobox-list.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useNameWarning } from \"../internal/use-name-warning.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport {\n ComboboxListContext,\n ComboboxPopupContext,\n useComboboxContext,\n} from \"./combobox-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `Combobox.List`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface ComboboxListState {\n /** The deferred text the results are for: render the Options for it. */\n readonly query: string;\n /** The results shown are for an older text (`aria-busy`). */\n readonly stale: boolean;\n /** No option is mounted and the results are settled. */\n readonly empty: boolean;\n}\n\n/**\n * Props of `Combobox.List`.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport interface ComboboxListProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"id\" | \"role\" | \"aria-busy\" | \"className\" | \"style\" | \"children\"\n> {\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ComboboxListState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ComboboxListState>;\n /**\n * Usually a function of `{ query }` rendering the Options for it, under your own `<Suspense>`\n * for an async search. The previous results stay visible while the next ones load.\n */\n children?: StateValue<ReactNode, ComboboxListState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, ComboboxListState>;\n}\n\n/**\n * The listbox: `<div role=\"listbox\" aria-labelledby={label}>` (only while a `Combobox.Label` is\n * mounted), the element the input's `aria-controls` names. Its children are the results for the\n * deferred `query` (the library filters nothing, design 6.1); while they are for an older text it\n * carries `aria-busy=\"true\"` and `data-stale`. Contains only Options and Groups; a `Status`\n * rendered as a Suspense fallback inside it marks the results as loading (`aria-busy=\"true\"`).\n *\n * Owned keys (conventions 1.2): `id`, `role`, `aria-labelledby` (token-merged), `aria-busy`,\n * `aria-multiselectable` (with `multiple` only: `\"true\"`), `data-stale`, `data-empty`.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport function ComboboxList({ className, style, children, render, ...rest }: ComboboxListProps) {\n const ctx = useComboboxContext(\"Combobox.List\");\n const inPopup = use(ComboboxPopupContext);\n useDevWarning(\n !inPopup,\n isDev &&\n \"Combobox.List: rendered outside a Combobox.Popup. The listbox must be inside the Popup, \" +\n \"which is the element the library shows and hides.\",\n );\n const { listRef } = ctx;\n // A mounted Label registers in a layout effect whose re-render is flushed before the check's\n // microtask, so `aria-labelledby` is in the DOM by then if it ever will be.\n const checkName = useNameWarning(\n isDev &&\n \"Combobox.List: the listbox has no accessible name. Render a Combobox.Label, or give \" +\n \"the List an `aria-label` / `aria-labelledby`.\",\n );\n\n const ref = useCallback(\n (element: HTMLElement) => {\n listRef.current = element;\n checkName?.(element);\n return () => {\n if (listRef.current === element) listRef.current = null;\n };\n },\n [listRef, checkName],\n );\n\n const state: ComboboxListState = { query: ctx.query, stale: ctx.stale, empty: ctx.empty };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: ctx.ids.list,\n role: \"listbox\",\n ...(ctx.hasLabel\n ? { \"aria-labelledby\": ctx.ids.label }\n : ctx.fieldLabelId !== undefined && { \"aria-labelledby\": ctx.fieldLabelId }),\n \"aria-busy\": ctx.stale || ctx.loading ? true : undefined,\n // `multiple` (design 15.7): every option toggles.\n ...(ctx.multiple && { \"aria-multiselectable\": true }),\n \"data-stale\": dataAttr(ctx.stale),\n \"data-empty\": dataAttr(ctx.empty),\n };\n\n return useRender<ComponentPropsWithRef<\"div\">, ComboboxListState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n style,\n children: (s) => (\n <ComboboxListContext value={true}>{resolveStateValue(children, s)}</ComboboxListContext>\n ),\n props: rest,\n libraryProps,\n ref,\n });\n}\n\nComboboxList.displayName = \"ComboboxList\";\n"],"mappings":";;;;;;;;;;AAeA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;AAiDvC,SAAgB,aAAa,EAAE,WAAW,OAAO,UAAU,QAAQ,GAAG,QAA2B;CAC/F,MAAM,MAAM,mBAAmB,eAAe;CAC9C,MAAM,UAAU,IAAI,oBAAoB;CACxC,cACE,CAAC,SACD,SACE,2IAEJ;CACA,MAAM,EAAE,YAAY;CAGpB,MAAM,YAAY,eAChB,SACE,mIAEJ;CAEA,MAAM,MAAM,aACT,YAAyB;EACxB,QAAQ,UAAU;EAClB,YAAY,OAAO;EACnB,aAAa;GACX,IAAI,QAAQ,YAAY,SAAS,QAAQ,UAAU;EACrD;CACF,GACA,CAAC,SAAS,SAAS,CACrB;CAEA,MAAM,QAA2B;EAAE,OAAO,IAAI;EAAO,OAAO,IAAI;EAAO,OAAO,IAAI;CAAM;CAExF,MAAM,eAA8D;EAClE,IAAI,IAAI,IAAI;EACZ,MAAM;EACN,GAAI,IAAI,WACJ,EAAE,mBAAmB,IAAI,IAAI,MAAM,IACnC,IAAI,iBAAiB,KAAA,KAAa,EAAE,mBAAmB,IAAI,aAAa;EAC5E,aAAa,IAAI,SAAS,IAAI,UAAU,OAAO,KAAA;EAE/C,GAAI,IAAI,YAAY,EAAE,wBAAwB,KAAK;EACnD,cAAc,SAAS,IAAI,KAAK;EAChC,cAAc,SAAS,IAAI,KAAK;CAClC;CAEA,OAAO,UAA2D;EAChE,gBAAgB;EAChB;EACA;EACA;EACA;EACA,WAAW,MACT,oBAAC,qBAAD;GAAqB,OAAO;GAAO,UAAA,kBAAkB,UAAU,CAAC;EAAuB,CAAA;EAEzF,OAAO;EACP;EACA;CACF,CAAC;AACH;AAEA,aAAa,cAAc"}
@@ -8,11 +8,14 @@ import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
8
8
  export interface ComboboxOptionState {
9
9
  /** The Option's `value` prop. */
10
10
  readonly value: string;
11
- /** Optimistic: this option's value is the (optimistic) selection. */
11
+ /** Optimistic: this option's value is (in) the optimistic selection. */
12
12
  readonly selected: boolean;
13
13
  /** `aria-activedescendant` points here (urgent). */
14
14
  readonly active: boolean;
15
- /** The selection is pending and this option is its optimistic target. */
15
+ /**
16
+ * The selection is pending and this option is its optimistic target; with `multiple`, the
17
+ * option is being added or removed (its optimistic and committed selection differ).
18
+ */
16
19
  readonly pending: boolean;
17
20
  /** The Option's `disabled` prop. */
18
21
  readonly disabled: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"combobox-option.d.mts","names":[],"sources":["../../src/combobox/combobox-option.tsx"],"mappings":";;;;;;;iBAsBiB;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;;iBAQM,4BAA4B,KAC3C;;EAcA;;;;;;;EAOA;;;;;;EAMA;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;wBAiBpC,iBACd,OACA,OACA,UACA,WACA,OACA,UACA,WACG,QACF,sBAAmB;yBATN"}
1
+ {"version":3,"file":"combobox-option.d.mts","names":[],"sources":["../../src/combobox/combobox-option.tsx"],"mappings":";;;;;;;iBAsBiB;;WAEN;;WAEA;;WAEA;;;;;WAKA;;WAEA;;;;;;;iBAQM,4BAA4B,KAC3C;;EAcA;;;;;;;EAOA;;;;;;EAMA;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;wBAiBpC,iBACd,OACA,OACA,UACA,WACA,OACA,UACA,WACG,QACF,sBAAmB;yBATN"}
@@ -2,7 +2,8 @@
2
2
  import { dataAttr } from "../internal/data-attr.mjs";
3
3
  import { useDevWarning } from "../internal/use-dev-warning.mjs";
4
4
  import { useRender } from "../internal/use-render.mjs";
5
- import { ComboboxListContext, optionId, useComboboxContext } from "./combobox-context.mjs";
5
+ import { optionId } from "../internal/use-option-registry.mjs";
6
+ import { ComboboxListContext, useComboboxContext } from "./combobox-context.mjs";
6
7
  import { use, useCallback, useLayoutEffect, useRef } from "react";
7
8
  //#region src/combobox/combobox-option.tsx
8
9
  const isDev = process.env.NODE_ENV !== "production";
@@ -45,12 +46,12 @@ function ComboboxOption({ value, label, disabled = false, className, style, chil
45
46
  label,
46
47
  disabled
47
48
  ]);
48
- const selected = ctx.value === value;
49
+ const selected = ctx.isSelected(value);
49
50
  const state = {
50
51
  value,
51
52
  selected,
52
53
  active: ctx.activeValue === value,
53
- pending: ctx.valuePending && selected,
54
+ pending: ctx.isPending(value),
54
55
  disabled
55
56
  };
56
57
  const libraryProps = {
@@ -1 +1 @@
1
- {"version":3,"file":"combobox-option.mjs","names":[],"sources":["../../src/combobox/combobox-option.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useLayoutEffect, useRef } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent,\n PointerEvent,\n ReactNode,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { ComboboxListContext, optionId, useComboboxContext } from \"./combobox-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `Combobox.Option`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface ComboboxOptionState {\n /** The Option's `value` prop. */\n readonly value: string;\n /** Optimistic: this option's value is the (optimistic) selection. */\n readonly selected: boolean;\n /** `aria-activedescendant` points here (urgent). */\n readonly active: boolean;\n /** The selection is pending and this option is its optimistic target. */\n readonly pending: boolean;\n /** The Option's `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Combobox.Option`.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport interface ComboboxOptionProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"id\"\n | \"role\"\n | \"aria-selected\"\n | \"aria-disabled\"\n | \"onClick\"\n | \"onPointerDown\"\n | \"onMouseDown\"\n | \"onPointerMove\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** The selection this option stands for. Unique within the Combobox; also its id fragment. */\n value: string;\n /**\n * The text written into the input when this option is accepted. Not used for matching: the\n * library filters nothing.\n *\n * @defaultValue the element's trimmed `textContent` at that moment\n */\n label?: string;\n /**\n * `aria-disabled`: shown, skipped by the arrow keys, never accepted.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ComboboxOptionState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ComboboxOptionState>;\n /** Rendered from optimistic state; must not suspend. */\n children?: StateValue<ReactNode, ComboboxOptionState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, ComboboxOptionState>;\n}\n\nconst preventDefault = (event: { preventDefault(): void }) => event.preventDefault();\n\n/**\n * One result: `<div role=\"option\" id aria-selected>`, never focused (virtual focus through the\n * input's `aria-activedescendant`). A click (or Enter while it is active) accepts it: the input\n * text becomes its label at once, it shows `data-selected` and `data-pending`, and the listbox\n * closes when `valueChangeAction` settles. Hovering makes it active.\n *\n * Owned keys (conventions 1.2): `id` (derived from `value`), `role`, `aria-selected`,\n * `aria-disabled`, `onClick`, `onPointerDown`, `onMouseDown`, `onPointerMove`, `data-selected`,\n * `data-active`, `data-pending`, `data-disabled`.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport function ComboboxOption({\n value,\n label,\n disabled = false,\n className,\n style,\n children,\n render,\n ...rest\n}: ComboboxOptionProps) {\n const ctx = useComboboxContext(\"Combobox.Option\");\n const inList = use(ComboboxListContext);\n useDevWarning(\n !inList,\n isDev && \"Combobox.Option: rendered outside a Combobox.List. Options belong in the listbox.\",\n );\n const { registerOption } = ctx;\n\n const elementRef = useRef<HTMLElement | null>(null);\n const ref = useCallback((element: HTMLElement) => {\n elementRef.current = element;\n return () => {\n if (elementRef.current === element) elementRef.current = null;\n };\n }, []);\n\n // Registration (design 14): the Root's registry drives the arrow keys, `Empty`, the active\n // option's revalidation, the announcements and the label cache.\n useLayoutEffect(() => {\n const element = elementRef.current;\n if (element === null) return;\n return registerOption(value, { element, label, disabled });\n }, [registerOption, value, label, disabled]);\n\n const selected = ctx.value === value;\n const state: ComboboxOptionState = {\n value,\n selected,\n active: ctx.activeValue === value,\n pending: ctx.valuePending && selected,\n disabled,\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: optionId(ctx.ids.optionPrefix, value),\n role: \"option\",\n \"aria-selected\": selected,\n \"aria-disabled\": disabled ? true : undefined,\n onClick: (event: MouseEvent<HTMLDivElement>) => {\n if (disabled) return;\n ctx.accept(value, event.nativeEvent);\n },\n // The input keeps focus (design 7.1), also for an Option rendered outside a Popup.\n onPointerDown: (event: PointerEvent<HTMLDivElement>) => preventDefault(event),\n onMouseDown: (event: MouseEvent<HTMLDivElement>) => preventDefault(event),\n onPointerMove: () => {\n if (!disabled && ctx.activeValue !== value) ctx.setActive(value);\n },\n \"data-selected\": dataAttr(selected),\n \"data-active\": dataAttr(state.active),\n \"data-pending\": dataAttr(state.pending),\n \"data-disabled\": dataAttr(disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"div\">, ComboboxOptionState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps,\n ref,\n });\n}\n\nComboboxOption.displayName = \"ComboboxOption\";\n"],"mappings":";;;;;;;AAgBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AA+DvC,MAAM,kBAAkB,UAAsC,MAAM,eAAe;;;;;;;;;;;;;AAcnF,SAAgB,eAAe,EAC7B,OACA,OACA,WAAW,OACX,WACA,OACA,UACA,QACA,GAAG,QACmB;CACtB,MAAM,MAAM,mBAAmB,iBAAiB;CAChD,MAAM,SAAS,IAAI,mBAAmB;CACtC,cACE,CAAC,QACD,SAAS,mFACX;CACA,MAAM,EAAE,mBAAmB;CAE3B,MAAM,aAAa,OAA2B,IAAI;CAClD,MAAM,MAAM,aAAa,YAAyB;EAChD,WAAW,UAAU;EACrB,aAAa;GACX,IAAI,WAAW,YAAY,SAAS,WAAW,UAAU;EAC3D;CACF,GAAG,CAAC,CAAC;CAIL,sBAAsB;EACpB,MAAM,UAAU,WAAW;EAC3B,IAAI,YAAY,MAAM;EACtB,OAAO,eAAe,OAAO;GAAE;GAAS;GAAO;EAAS,CAAC;CAC3D,GAAG;EAAC;EAAgB;EAAO;EAAO;CAAQ,CAAC;CAE3C,MAAM,WAAW,IAAI,UAAU;CAC/B,MAAM,QAA6B;EACjC;EACA;EACA,QAAQ,IAAI,gBAAgB;EAC5B,SAAS,IAAI,gBAAgB;EAC7B;CACF;CAEA,MAAM,eAA8D;EAClE,IAAI,SAAS,IAAI,IAAI,cAAc,KAAK;EACxC,MAAM;EACN,iBAAiB;EACjB,iBAAiB,WAAW,OAAO,KAAA;EACnC,UAAU,UAAsC;GAC9C,IAAI,UAAU;GACd,IAAI,OAAO,OAAO,MAAM,WAAW;EACrC;EAEA,gBAAgB,UAAwC,eAAe,KAAK;EAC5E,cAAc,UAAsC,eAAe,KAAK;EACxE,qBAAqB;GACnB,IAAI,CAAC,YAAY,IAAI,gBAAgB,OAAO,IAAI,UAAU,KAAK;EACjE;EACA,iBAAiB,SAAS,QAAQ;EAClC,eAAe,SAAS,MAAM,MAAM;EACpC,gBAAgB,SAAS,MAAM,OAAO;EACtC,iBAAiB,SAAS,QAAQ;CACpC;CAEA,OAAO,UAA6D;EAClE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;EACA;CACF,CAAC;AACH;AAEA,eAAe,cAAc"}
1
+ {"version":3,"file":"combobox-option.mjs","names":[],"sources":["../../src/combobox/combobox-option.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useLayoutEffect, useRef } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent,\n PointerEvent,\n ReactNode,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { ComboboxListContext, optionId, useComboboxContext } from \"./combobox-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `Combobox.Option`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface ComboboxOptionState {\n /** The Option's `value` prop. */\n readonly value: string;\n /** Optimistic: this option's value is (in) the optimistic selection. */\n readonly selected: boolean;\n /** `aria-activedescendant` points here (urgent). */\n readonly active: boolean;\n /**\n * The selection is pending and this option is its optimistic target; with `multiple`, the\n * option is being added or removed (its optimistic and committed selection differ).\n */\n readonly pending: boolean;\n /** The Option's `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Combobox.Option`.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport interface ComboboxOptionProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"id\"\n | \"role\"\n | \"aria-selected\"\n | \"aria-disabled\"\n | \"onClick\"\n | \"onPointerDown\"\n | \"onMouseDown\"\n | \"onPointerMove\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** The selection this option stands for. Unique within the Combobox; also its id fragment. */\n value: string;\n /**\n * The text written into the input when this option is accepted. Not used for matching: the\n * library filters nothing.\n *\n * @defaultValue the element's trimmed `textContent` at that moment\n */\n label?: string;\n /**\n * `aria-disabled`: shown, skipped by the arrow keys, never accepted.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ComboboxOptionState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ComboboxOptionState>;\n /** Rendered from optimistic state; must not suspend. */\n children?: StateValue<ReactNode, ComboboxOptionState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, ComboboxOptionState>;\n}\n\nconst preventDefault = (event: { preventDefault(): void }) => event.preventDefault();\n\n/**\n * One result: `<div role=\"option\" id aria-selected>`, never focused (virtual focus through the\n * input's `aria-activedescendant`). A click (or Enter while it is active) accepts it: the input\n * text becomes its label at once, it shows `data-selected` and `data-pending`, and the listbox\n * closes when `valueChangeAction` settles. Hovering makes it active.\n *\n * Owned keys (conventions 1.2): `id` (derived from `value`), `role`, `aria-selected`,\n * `aria-disabled`, `onClick`, `onPointerDown`, `onMouseDown`, `onPointerMove`, `data-selected`,\n * `data-active`, `data-pending`, `data-disabled`.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport function ComboboxOption({\n value,\n label,\n disabled = false,\n className,\n style,\n children,\n render,\n ...rest\n}: ComboboxOptionProps) {\n const ctx = useComboboxContext(\"Combobox.Option\");\n const inList = use(ComboboxListContext);\n useDevWarning(\n !inList,\n isDev && \"Combobox.Option: rendered outside a Combobox.List. Options belong in the listbox.\",\n );\n const { registerOption } = ctx;\n\n const elementRef = useRef<HTMLElement | null>(null);\n const ref = useCallback((element: HTMLElement) => {\n elementRef.current = element;\n return () => {\n if (elementRef.current === element) elementRef.current = null;\n };\n }, []);\n\n // Registration (design 14): the Root's registry drives the arrow keys, `Empty`, the active\n // option's revalidation, the announcements and the label cache.\n useLayoutEffect(() => {\n const element = elementRef.current;\n if (element === null) return;\n return registerOption(value, { element, label, disabled });\n }, [registerOption, value, label, disabled]);\n\n const selected = ctx.isSelected(value);\n const state: ComboboxOptionState = {\n value,\n selected,\n active: ctx.activeValue === value,\n pending: ctx.isPending(value),\n disabled,\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: optionId(ctx.ids.optionPrefix, value),\n role: \"option\",\n \"aria-selected\": selected,\n \"aria-disabled\": disabled ? true : undefined,\n onClick: (event: MouseEvent<HTMLDivElement>) => {\n if (disabled) return;\n ctx.accept(value, event.nativeEvent);\n },\n // The input keeps focus (design 7.1), also for an Option rendered outside a Popup.\n onPointerDown: (event: PointerEvent<HTMLDivElement>) => preventDefault(event),\n onMouseDown: (event: MouseEvent<HTMLDivElement>) => preventDefault(event),\n onPointerMove: () => {\n if (!disabled && ctx.activeValue !== value) ctx.setActive(value);\n },\n \"data-selected\": dataAttr(selected),\n \"data-active\": dataAttr(state.active),\n \"data-pending\": dataAttr(state.pending),\n \"data-disabled\": dataAttr(disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"div\">, ComboboxOptionState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps,\n ref,\n });\n}\n\nComboboxOption.displayName = \"ComboboxOption\";\n"],"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BAAiB,SAAS,QAAQ;CACpC;CAEA,OAAO,UAA6D;EAClE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;EACA;CACF,CAAC;AACH;AAEA,eAAe,cAAc"}
@@ -27,7 +27,8 @@ export interface ComboboxInputValueChangeDetails extends ActionDetails {
27
27
  export interface ComboboxOpenChangeDetails extends ActionDetails {
28
28
  /**
29
29
  * `"activate"`: typing, ArrowDown / ArrowUp / Alt+ArrowDown, the Trigger, a click on the input
30
- * with `openOnClick`, an accepted option (the close after it), a foreign `showPopover()`.
30
+ * with `openOnClick`, an accepted option (the close after it), Alt+ArrowUp, a foreign
31
+ * `showPopover()`; with `multiple`, a chip taking focus while an open is on its way (the cancel).
31
32
  * `"dismiss"`: Escape, light dismiss, focus leaving the combobox, another top-layer element.
32
33
  * `"platform"`: the popup was found open on mount (only script can cause it).
33
34
  */
@@ -52,33 +53,35 @@ export interface ComboboxRootState {
52
53
  /** The `disabled` prop, or the enclosing Field's. */
53
54
  readonly disabled: boolean;
54
55
  }
55
- /**
56
- * Props of `Combobox.Root`.
57
- *
58
- * @see https://ui.funstack.work/components/combobox
59
- */
60
- export interface ComboboxRootProps {
61
- /** Controlled selection. `null`: nothing selected. `undefined`: uncontrolled. */
62
- value?: string | null;
56
+ /** Details passed as the second argument of `valueChangeAction` with `multiple` (design 15.2). */
57
+ export interface ComboboxMultipleValueChangeDetails extends ActionDetails {
63
58
  /**
64
- * Initial selection in uncontrolled mode.
65
- *
66
- * @defaultValue `null`
67
- */
68
- defaultValue?: string | null;
69
- /**
70
- * Runs inside the Root's transition when the user accepts an option, commits free text
71
- * (`allowCustomValue`), presses Clear, or the form resets. Awaited; the listbox closes in the
72
- * commit that ends it; a rejection rolls the input text and `data-selected` back and leaves
73
- * the listbox open. May be a Server Function. A `setState` after your own `await` needs
74
- * `startTransition`.
59
+ * `"activate"`: the user toggled an option (Enter, click), added free text
60
+ * (`allowCustomValue`), removed a chip (Backspace or Delete: the `keydown`; `ChipRemove`: the
61
+ * `click`) or pressed Clear.
62
+ * `"platform"`: a form reset (`details.event` is the `reset` event).
75
63
  */
76
- valueChangeAction?: ChangeAction<string | null, ComboboxValueChangeDetails>;
64
+ readonly reason: ChangeReason;
65
+ /** Values this dispatch added, in the order they join the value. */
66
+ readonly added: readonly string[];
67
+ /** Values this dispatch removed, in value order. */
68
+ readonly removed: readonly string[];
69
+ /** `true` when `added` is free text committed under `allowCustomValue`. */
70
+ readonly custom: boolean;
71
+ }
72
+ /** State of `Combobox.Root multiple`: as `ComboboxRootState`, with the selection as a list. */
73
+ export interface ComboboxMultipleRootState extends Omit<ComboboxRootState, "value"> {
74
+ /** Optimistic selection, in pick order. Content rendered from it must not suspend. */
75
+ readonly value: readonly string[];
76
+ }
77
+ /** The props `Combobox.Root` has in both modes (design 15.2). */
78
+ export interface ComboboxRootBaseProps {
77
79
  /** Controlled input text. `undefined`: uncontrolled. */
78
80
  inputValue?: string;
79
81
  /**
80
- * Initial input text. Pass the selected value's label when `defaultValue` is
81
- * set: the library never derives the text from the value.
82
+ * Initial input text. Single selection: pass the selected value's label when `defaultValue`
83
+ * is set (the library never derives the text from the value). With `multiple` the text is only
84
+ * a search and usually starts empty; the chips show the selection.
82
85
  *
83
86
  * @defaultValue `""`
84
87
  */
@@ -103,7 +106,8 @@ export interface ComboboxRootProps {
103
106
  defaultOpen?: boolean;
104
107
  /**
105
108
  * Requests only: awaited for opens and for the close after an accepted option (or the
106
- * Trigger, or Alt+ArrowUp). Never called for a dismissal: that goes to `onOpenChange`.
109
+ * Trigger, or Alt+ArrowUp; with `multiple`, the cancel of an open still on its way when a
110
+ * chip takes focus). Never called for a dismissal: that goes to `onOpenChange`.
107
111
  */
108
112
  openChangeAction?: ChangeAction<boolean, ComboboxOpenChangeDetails>;
109
113
  /**
@@ -119,7 +123,9 @@ export interface ComboboxRootProps {
119
123
  * Free text is a value: Enter with no active option, or focus leaving with text that is not
120
124
  * the selected option's label, dispatches the text with `details.custom: true` (empty text
121
125
  * dispatches `null`). When `false`, unmatched text reverts to the selection's label when focus
122
- * leaves.
126
+ * leaves. With `multiple`: Enter with no active option (the key prevented, listbox open or
127
+ * closed) or focus leaving **adds** the text as a value (`added: [text]`, `custom: true`) and
128
+ * clears it; text already selected adds nothing. When `false`, unmatched text is cleared.
123
129
  *
124
130
  * @defaultValue `false`
125
131
  */
@@ -143,6 +149,49 @@ export interface ComboboxRootProps {
143
149
  * @defaultValue `false`
144
150
  */
145
151
  loop?: boolean;
152
+ /**
153
+ * Form participation through a hidden input with this name (value `""` for `null`); with
154
+ * `multiple`, one hidden input per value (nothing posted for an empty selection).
155
+ */
156
+ name?: string;
157
+ /** The `form` attribute of the hidden input(s). */
158
+ form?: string;
159
+ /**
160
+ * Disables the Input, Trigger and Clear (and, with `multiple`, every `ChipRemove`); nothing
161
+ * dispatches for user interaction.
162
+ *
163
+ * @defaultValue `false`
164
+ */
165
+ disabled?: boolean;
166
+ }
167
+ /**
168
+ * Props of `Combobox.Root` with a single selection (the default): `value` is `string | null`.
169
+ *
170
+ * @see https://ui.funstack.work/components/combobox
171
+ */
172
+ export interface ComboboxSingleProps extends ComboboxRootBaseProps {
173
+ /**
174
+ * `true` switches to multiple selection (see `ComboboxMultipleProps`). Fixed at mount.
175
+ *
176
+ * @defaultValue `false`
177
+ */
178
+ multiple?: false;
179
+ /** Controlled selection. `null`: nothing selected. `undefined`: uncontrolled. */
180
+ value?: string | null;
181
+ /**
182
+ * Initial selection in uncontrolled mode.
183
+ *
184
+ * @defaultValue `null`
185
+ */
186
+ defaultValue?: string | null;
187
+ /**
188
+ * Runs inside the Root's transition when the user accepts an option, commits free text
189
+ * (`allowCustomValue`), presses Clear, or the form resets. Awaited; the listbox closes in the
190
+ * commit that ends it; a rejection rolls the input text and `data-selected` back and leaves
191
+ * the listbox open. May be a Server Function. A `setState` after your own `await` needs
192
+ * `startTransition`.
193
+ */
194
+ valueChangeAction?: ChangeAction<string | null, ComboboxValueChangeDetails>;
146
195
  /**
147
196
  * The message `ariaNotify()` announces on the List when the results settle, from the number
148
197
  * of mounted options. Override for localisation or a richer message; return `null` to announce
@@ -151,19 +200,58 @@ export interface ComboboxRootProps {
151
200
  * @defaultValue English: `"No results"`, `"1 result"`, `"N results"`
152
201
  */
153
202
  announce?: (count: number, state: ComboboxRootState) => string | null;
154
- /** Form participation through a hidden input with this name (value `""` for `null`). */
155
- name?: string;
156
- /** The `form` attribute of the hidden input. */
157
- form?: string;
203
+ /** `multiple` only: a type error here (the union's excess-property check would let it through). */
204
+ announceRemoved?: never;
205
+ /** The parts, or a function of the Root's state. */
206
+ children?: StateValue<ReactNode, ComboboxRootState>;
207
+ }
208
+ /**
209
+ * Props of `Combobox.Root multiple`: the selection is a list of values shown as chips
210
+ * (`Combobox.Chips`). A pick toggles the option, clears the text and leaves the listbox open.
211
+ *
212
+ * @see https://ui.funstack.work/components/combobox
213
+ */
214
+ export interface ComboboxMultipleProps extends ComboboxRootBaseProps {
215
+ /** The selection is a list of values, shown as chips. Fixed at mount. */
216
+ multiple: true;
158
217
  /**
159
- * Disables the Input, Trigger and Clear; nothing dispatches for user interaction.
218
+ * Controlled selection. `[]`: nothing selected. `undefined`: uncontrolled. The order is the
219
+ * chip order; duplicates are ignored.
220
+ */
221
+ value?: string[];
222
+ /**
223
+ * Initial selection in uncontrolled mode; also the form-reset target (the latest value).
160
224
  *
161
- * @defaultValue `false`
225
+ * @defaultValue `[]`
162
226
  */
163
- disabled?: boolean;
227
+ defaultValue?: string[];
228
+ /**
229
+ * Runs inside the Root's transition for every change of the selection. `next` is the whole
230
+ * intended selection as a fresh array; `details.added` / `details.removed` say what this
231
+ * dispatch changed. Awaited; a rejection rolls this change back (the chip, `data-selected`)
232
+ * and nothing else. May be a Server Function. Persist the diff, not `next`: `next` can contain
233
+ * an earlier change that fails later.
234
+ */
235
+ valueChangeAction?: ChangeAction<string[], ComboboxMultipleValueChangeDetails>;
236
+ /**
237
+ * The message `ariaNotify()` announces on the Input when chips are removed outside the
238
+ * listbox (Backspace, Delete, `ChipRemove`, Clear), from the removed chips' labels. Return
239
+ * `null` to announce nothing. Ignored where `ariaNotify` is missing.
240
+ *
241
+ * @defaultValue English: the labels joined with `", "`, then `" removed"`
242
+ */
243
+ announceRemoved?: (labels: readonly string[], state: ComboboxMultipleRootState) => string | null;
244
+ /** See {@link ComboboxSingleProps.announce}. */
245
+ announce?: (count: number, state: ComboboxMultipleRootState) => string | null;
164
246
  /** The parts, or a function of the Root's state. */
165
- children?: StateValue<ReactNode, ComboboxRootState>;
247
+ children?: StateValue<ReactNode, ComboboxMultipleRootState>;
166
248
  }
249
+ /**
250
+ * Props of `Combobox.Root`, discriminated on `multiple`.
251
+ *
252
+ * @see https://ui.funstack.work/components/combobox
253
+ */
254
+ export type ComboboxRootProps = ComboboxSingleProps | ComboboxMultipleProps;
167
255
  /**
168
256
  * Owns the two states of a combobox (design/components/combobox.md 2): the selection (`value`,
169
257
  * a transition with `useOptimistic`, like every other value) and the text (`inputValue`, the
@@ -171,11 +259,15 @@ export interface ComboboxRootProps {
171
259
  * any transition). The results render from `useDeferredValue(inputValue)`; the active option is
172
260
  * urgent virtual focus (`aria-activedescendant`); the listbox is a `popover="auto"` opened by the
173
261
  * library with the input as `source`. Renders no DOM, except one `<input type="hidden">` when
174
- * `name` is given.
262
+ * `name` is given (with `multiple`, one per value: design 15.8).
263
+ *
264
+ * With `multiple` (fixed at mount, design 15) the selection is a set under the shared set-valued
265
+ * rules (`useMultipleSelection`), a pick toggles the option, clears the text and leaves the
266
+ * listbox open, and the chips (`Combobox.Chips`) render from the optimistic value.
175
267
  *
176
268
  * @see https://ui.funstack.work/components/combobox
177
269
  */
178
- export declare function ComboboxRoot(props: ComboboxRootProps): import("react").JSX.Element;
270
+ export declare function ComboboxRoot(publicProps: ComboboxRootProps): import("react").JSX.Element;
179
271
  export declare namespace ComboboxRoot {
180
272
  var displayName: string;
181
273
  }
@@ -1 +1 @@
1
- {"version":3,"file":"combobox-root.d.mts","names":[],"sources":["../../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