@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
@@ -0,0 +1,58 @@
1
+ import { RenderProp, StateValue } from "../internal/types.mjs";
2
+ import { CSSProperties, ComponentPropsWithRef, ReactNode, ViewTransitionClass } from "react";
3
+ //#region src/multi-select/multi-select-popup.d.ts
4
+ /**
5
+ * State of `MultiSelect.Popup`, passed to the function forms of `className`, `style`, `children`
6
+ * and `render`.
7
+ */
8
+ export interface MultiSelectPopupState {
9
+ /** Committed open state. Read `:popover-open` for the DOM truth. */
10
+ readonly open: boolean;
11
+ }
12
+ /**
13
+ * Props of `MultiSelect.Popup`.
14
+ *
15
+ * @see https://ui.funstack.work/components/multi-select
16
+ */
17
+ export interface MultiSelectPopupProps extends Omit<ComponentPropsWithRef<"div">, "id" | "popover" | "onToggle" | "onBeforeToggle" | "onPointerDown" | "onMouseDown" | "className" | "style" | "children"> {
18
+ /**
19
+ * `false` (default): the children are not rendered while the listbox is closed. `true`: they
20
+ * stay mounted inside `<Activity mode="hidden">`.
21
+ *
22
+ * @defaultValue `false`
23
+ */
24
+ keepMounted?: boolean;
25
+ /**
26
+ * Forwarded to the `<ViewTransition default>` around the popover element itself. Animates the
27
+ * library's opens and closes (the Trigger, the keys); dismissals are the browser's (CSS only).
28
+ * Static.
29
+ */
30
+ transition?: ViewTransitionClass;
31
+ /** Class name, or a function of the part's state that returns one. */
32
+ className?: StateValue<string | undefined, MultiSelectPopupState>;
33
+ /** Inline style, or a function of the part's state that returns one. */
34
+ style?: StateValue<CSSProperties | undefined, MultiSelectPopupState>;
35
+ /** Content, or a function of the part's state. */
36
+ children?: StateValue<ReactNode, MultiSelectPopupState>;
37
+ /** Must render a `<div>`: a `<dialog>` would pull focus out of the Trigger. */
38
+ render?: RenderProp<ComponentPropsWithRef<"div">, MultiSelectPopupState>;
39
+ }
40
+ /**
41
+ * The listbox's container: `<div popover="auto">`, opened by the library with
42
+ * `showPopover({ source: trigger })` and placed below (or, flipped, above) the Trigger with CSS
43
+ * Anchor Positioning, at least as wide as the Trigger (design/components/multi-select.md B.12).
44
+ * Focus never enters it: a press anywhere in it is `preventDefault()`ed so the Trigger keeps
45
+ * focus (B.4). Holds the `List` and, outside it, `Empty` and `Status`. Style it with
46
+ * `:popover-open`; it emits no `data-open`.
47
+ *
48
+ * Owned keys (conventions 1.2): `id`, `popover`, `onPointerDown`, `onMouseDown`. Inline
49
+ * `position-area`, `position-try-fallbacks` and `min-width` sit under the consumer's `style`.
50
+ *
51
+ * @see https://ui.funstack.work/components/multi-select
52
+ */
53
+ export declare function MultiSelectPopup({ keepMounted, transition, className, style, children, render, ...rest }: MultiSelectPopupProps): ReactNode;
54
+ export declare namespace MultiSelectPopup {
55
+ var displayName: string;
56
+ }
57
+ //#endregion
58
+ //# sourceMappingURL=multi-select-popup.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi-select-popup.d.mts","names":[],"sources":["../../src/multi-select/multi-select-popup.tsx"],"mappings":";;;;;;;iBAyBiB;;WAEN;;;;;;;iBAQM,8BAA8B,KAC7C;;;;;;;EAiBA;;;;;;EAMA,aAAa;;EAEb,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;;wBAkBpC,mBACd,aACA,YACA,WACA,OACA,UACA,WACG,QACF,wBAAqB;yBARR"}
@@ -0,0 +1,71 @@
1
+ "use client";
2
+ import { useTransitionBoundary } from "../internal/transition-boundary.mjs";
3
+ import { resolveStateValue } from "../internal/render-element.mjs";
4
+ import { useRender } from "../internal/use-render.mjs";
5
+ import { useElementCheck } from "../internal/use-element-check.mjs";
6
+ import { useMergedRefs } from "../internal/use-merged-refs.mjs";
7
+ import { listenInvokerPresses } from "../internal/overlay/invokers.mjs";
8
+ import { usePopoverPopup } from "../internal/overlay/use-popover-popup.mjs";
9
+ import { MultiSelectPopupContext, useMultiSelectContext } from "./multi-select-context.mjs";
10
+ import { jsx } from "react/jsx-runtime";
11
+ //#region src/multi-select/multi-select-popup.tsx
12
+ const isDev = process.env.NODE_ENV !== "production";
13
+ const preventDefault = (event) => event.preventDefault();
14
+ /**
15
+ * The listbox's container: `<div popover="auto">`, opened by the library with
16
+ * `showPopover({ source: trigger })` and placed below (or, flipped, above) the Trigger with CSS
17
+ * Anchor Positioning, at least as wide as the Trigger (design/components/multi-select.md B.12).
18
+ * Focus never enters it: a press anywhere in it is `preventDefault()`ed so the Trigger keeps
19
+ * focus (B.4). Holds the `List` and, outside it, `Empty` and `Status`. Style it with
20
+ * `:popover-open`; it emits no `data-open`.
21
+ *
22
+ * Owned keys (conventions 1.2): `id`, `popover`, `onPointerDown`, `onMouseDown`. Inline
23
+ * `position-area`, `position-try-fallbacks` and `min-width` sit under the consumer's `style`.
24
+ *
25
+ * @see https://ui.funstack.work/components/multi-select
26
+ */
27
+ function MultiSelectPopup({ keepMounted, transition, className, style, children, render, ...rest }) {
28
+ const { popover } = useMultiSelectContext("MultiSelect.Popup");
29
+ const { setElement, renderContent } = usePopoverPopup(popover, {
30
+ part: "MultiSelect.Popup",
31
+ initialFocus: () => null,
32
+ keepMounted,
33
+ transition,
34
+ whileShown: listenInvokerPresses
35
+ });
36
+ const devRef = useElementCheck(isDev && ((element) => element.tagName !== "DIV" ? `MultiSelect.Popup: rendered a <${element.tagName.toLowerCase()}>. Render a <div>: a <dialog popover> runs the dialog focusing steps and takes focus out of the Trigger.` : null));
37
+ const ref = useMergedRefs(setElement, devRef);
38
+ const state = { open: popover.committed };
39
+ const libraryProps = {
40
+ id: popover.ids.popup,
41
+ popover: "auto",
42
+ onPointerDown: (event) => preventDefault(event),
43
+ onMouseDown: (event) => preventDefault(event)
44
+ };
45
+ const content = (s) => /* @__PURE__ */ jsx(MultiSelectPopupContext, {
46
+ value: true,
47
+ children: renderContent(() => resolveStateValue(children, s))
48
+ });
49
+ const element = useRender({
50
+ defaultElement: "div",
51
+ render,
52
+ state,
53
+ className,
54
+ style: (s) => ({
55
+ positionArea: "self-block-end span-self-inline-end",
56
+ positionTryFallbacks: "flip-block",
57
+ minWidth: "anchor-size(width)",
58
+ ...resolveStateValue(style, s)
59
+ }),
60
+ children: content,
61
+ props: rest,
62
+ libraryProps,
63
+ ref
64
+ });
65
+ return useTransitionBoundary("MultiSelect.Popup", transition, element);
66
+ }
67
+ MultiSelectPopup.displayName = "MultiSelectPopup";
68
+ //#endregion
69
+ export { MultiSelectPopup };
70
+
71
+ //# sourceMappingURL=multi-select-popup.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi-select-popup.mjs","names":[],"sources":["../../src/multi-select/multi-select-popup.tsx"],"sourcesContent":["\"use client\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent,\n PointerEvent,\n ReactNode,\n ViewTransitionClass,\n} from \"react\";\nimport { listenInvokerPresses } from \"../internal/overlay/invokers.js\";\nimport { usePopoverPopup } from \"../internal/overlay/use-popover-popup.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { MultiSelectPopupContext, useMultiSelectContext } from \"./multi-select-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `MultiSelect.Popup`, passed to the function forms of `className`, `style`, `children`\n * and `render`.\n */\nexport interface MultiSelectPopupState {\n /** Committed open state. Read `:popover-open` for the DOM truth. */\n readonly open: boolean;\n}\n\n/**\n * Props of `MultiSelect.Popup`.\n *\n * @see https://ui.funstack.work/components/multi-select\n */\nexport interface MultiSelectPopupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"id\"\n | \"popover\"\n | \"onToggle\"\n | \"onBeforeToggle\"\n | \"onPointerDown\"\n | \"onMouseDown\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * `false` (default): the children are not rendered while the listbox is closed. `true`: they\n * stay mounted inside `<Activity mode=\"hidden\">`.\n *\n * @defaultValue `false`\n */\n keepMounted?: boolean;\n /**\n * Forwarded to the `<ViewTransition default>` around the popover element itself. Animates the\n * library's opens and closes (the Trigger, the keys); dismissals are the browser's (CSS only).\n * Static.\n */\n transition?: ViewTransitionClass;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, MultiSelectPopupState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, MultiSelectPopupState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, MultiSelectPopupState>;\n /** Must render a `<div>`: a `<dialog>` would pull focus out of the Trigger. */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MultiSelectPopupState>;\n}\n\nconst preventDefault = (event: { preventDefault(): void }) => event.preventDefault();\n\n/**\n * The listbox's container: `<div popover=\"auto\">`, opened by the library with\n * `showPopover({ source: trigger })` and placed below (or, flipped, above) the Trigger with CSS\n * Anchor Positioning, at least as wide as the Trigger (design/components/multi-select.md B.12).\n * Focus never enters it: a press anywhere in it is `preventDefault()`ed so the Trigger keeps\n * focus (B.4). Holds the `List` and, outside it, `Empty` and `Status`. Style it with\n * `:popover-open`; it emits no `data-open`.\n *\n * Owned keys (conventions 1.2): `id`, `popover`, `onPointerDown`, `onMouseDown`. Inline\n * `position-area`, `position-try-fallbacks` and `min-width` sit under the consumer's `style`.\n *\n * @see https://ui.funstack.work/components/multi-select\n */\nexport function MultiSelectPopup({\n keepMounted,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: MultiSelectPopupProps) {\n const ctx = useMultiSelectContext(\"MultiSelect.Popup\");\n const { popover } = ctx;\n\n const { setElement, renderContent } = usePopoverPopup(popover, {\n part: \"MultiSelect.Popup\",\n // Focus stays on the Trigger: nothing inside the popup is ever focused.\n initialFocus: () => null,\n keepMounted,\n transition,\n // While shown, a press on an invoker of the popup (the Trigger included) moves no focus.\n whileShown: listenInvokerPresses,\n });\n\n const devRef = useElementCheck(\n isDev &&\n ((element) =>\n element.tagName !== \"DIV\"\n ? `MultiSelect.Popup: rendered a <${element.tagName.toLowerCase()}>. Render a <div>: ` +\n \"a <dialog popover> runs the dialog focusing steps and takes focus out of the Trigger.\"\n : null),\n );\n const ref = useMergedRefs(setElement, devRef);\n\n const state: MultiSelectPopupState = { open: popover.committed };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: popover.ids.popup,\n popover: \"auto\",\n onPointerDown: (event: PointerEvent<HTMLDivElement>) => preventDefault(event),\n onMouseDown: (event: MouseEvent<HTMLDivElement>) => preventDefault(event),\n };\n\n const content = (s: MultiSelectPopupState): ReactNode => (\n <MultiSelectPopupContext value={true}>\n {renderContent(() => resolveStateValue(children, s))}\n </MultiSelectPopupContext>\n );\n\n const element = useRender<ComponentPropsWithRef<\"div\">, MultiSelectPopupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // `self-*` keywords resolve against the popup's own inherited direction (conventions 13.1;\n // combobox.md 7.2). The consumer wins.\n style: (s) => ({\n positionArea: \"self-block-end span-self-inline-end\",\n positionTryFallbacks: \"flip-block\",\n minWidth: \"anchor-size(width)\",\n ...resolveStateValue(style, s),\n }),\n children: content,\n props: rest,\n libraryProps,\n ref,\n });\n\n return useTransitionBoundary(\"MultiSelect.Popup\", transition, element);\n}\n\nMultiSelectPopup.displayName = \"MultiSelectPopup\";\n"],"mappings":";;;;;;;;;;;AAmBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAmDvC,MAAM,kBAAkB,UAAsC,MAAM,eAAe;;;;;;;;;;;;;;AAenF,SAAgB,iBAAiB,EAC/B,aACA,YACA,WACA,OACA,UACA,QACA,GAAG,QACqB;CAExB,MAAM,EAAE,YADI,sBAAsB,mBACZ;CAEtB,MAAM,EAAE,YAAY,kBAAkB,gBAAgB,SAAS;EAC7D,MAAM;EAEN,oBAAoB;EACpB;EACA;EAEA,YAAY;CACd,CAAC;CAED,MAAM,SAAS,gBACb,WACI,YACA,QAAQ,YAAY,QAChB,kCAAkC,QAAQ,QAAQ,YAAY,EAAE,4GAEhE,KACV;CACA,MAAM,MAAM,cAAc,YAAY,MAAM;CAE5C,MAAM,QAA+B,EAAE,MAAM,QAAQ,UAAU;CAE/D,MAAM,eAA8D;EAClE,IAAI,QAAQ,IAAI;EAChB,SAAS;EACT,gBAAgB,UAAwC,eAAe,KAAK;EAC5E,cAAc,UAAsC,eAAe,KAAK;CAC1E;CAEA,MAAM,WAAW,MACf,oBAAC,yBAAD;EAAyB,OAAO;EAC7B,UAAA,oBAAoB,kBAAkB,UAAU,CAAC,CAAC;CAC5B,CAAA;CAG3B,MAAM,UAAU,UAA+D;EAC7E,gBAAgB;EAChB;EACA;EACA;EAGA,QAAQ,OAAO;GACb,cAAc;GACd,sBAAsB;GACtB,UAAU;GACV,GAAG,kBAAkB,OAAO,CAAC;EAC/B;EACA,UAAU;EACV,OAAO;EACP;EACA;CACF,CAAC;CAED,OAAO,sBAAsB,qBAAqB,YAAY,OAAO;AACvE;AAEA,iBAAiB,cAAc"}
@@ -0,0 +1,125 @@
1
+ import { ActionDetails, ChangeAction, ChangeReason, StateValue, UrgentChangeHandler } from "../internal/types.mjs";
2
+ import { ReactNode } from "react";
3
+ //#region src/multi-select/multi-select-root.d.ts
4
+ /** Details passed as the second argument of `MultiSelect.Root`'s `valueChangeAction`. */
5
+ export interface MultiSelectValueChangeDetails extends ActionDetails {
6
+ /**
7
+ * `"activate"`: the user toggled an option (Enter, Space, click; `details.event` is the
8
+ * `keydown` or `click`).
9
+ * `"platform"`: a form reset (`details.event` is the `reset` event).
10
+ */
11
+ readonly reason: ChangeReason;
12
+ /** Values this dispatch added, in the order they join the value. */
13
+ readonly added: readonly string[];
14
+ /** Values this dispatch removed, in value order. */
15
+ readonly removed: readonly string[];
16
+ }
17
+ /** Details passed as the second argument of `MultiSelect.Root`'s `openChangeAction` and `onOpenChange`. */
18
+ export interface MultiSelectOpenChangeDetails extends ActionDetails {
19
+ /**
20
+ * `"activate"`: the Trigger (click, Enter, Space, arrows, Home, End, a typed character),
21
+ * Alt+ArrowUp, a foreign invoker or `showPopover()`.
22
+ * `"dismiss"`: Escape, light dismiss, focus leaving, another top-layer element.
23
+ * `"platform"`: the popup was found open at mount.
24
+ */
25
+ readonly reason: ChangeReason;
26
+ }
27
+ /** State of `MultiSelect.Root`, passed to the function form of `children`. */
28
+ export interface MultiSelectRootState {
29
+ /** Optimistic selection, in pick order. Content rendered from it must not suspend. */
30
+ readonly value: readonly string[];
31
+ /** The value of the option `aria-activedescendant` points at, or `null`. */
32
+ readonly activeValue: string | null;
33
+ /** Optimistic open state. */
34
+ readonly open: boolean;
35
+ /** A `valueChangeAction` or `openChangeAction` dispatched through this Root is in flight. */
36
+ readonly pending: boolean;
37
+ /** The `disabled` prop, or the enclosing Field's. */
38
+ readonly disabled: boolean;
39
+ }
40
+ /**
41
+ * Props of `MultiSelect.Root`.
42
+ *
43
+ * @see https://ui.funstack.work/components/multi-select
44
+ */
45
+ export interface MultiSelectRootProps {
46
+ /** Controlled selection. `[]`: nothing selected. `undefined`: uncontrolled. Duplicates are ignored. */
47
+ value?: string[];
48
+ /**
49
+ * Initial selection in uncontrolled mode; also the form-reset target (the latest value).
50
+ *
51
+ * @defaultValue `[]`
52
+ */
53
+ defaultValue?: string[];
54
+ /**
55
+ * Runs inside the Root's transition for every change of the selection. `next` is the whole
56
+ * intended selection as a fresh array; `details.added` / `details.removed` say what this
57
+ * dispatch changed. Awaited; a rejection rolls this change back and nothing else. May be a
58
+ * Server Function. Persist the diff, not `next`: `next` can contain an earlier change that
59
+ * fails later.
60
+ */
61
+ valueChangeAction?: ChangeAction<string[], MultiSelectValueChangeDetails>;
62
+ /** Controlled open state. `undefined`: uncontrolled. */
63
+ open?: boolean;
64
+ /**
65
+ * Initial open state when uncontrolled. Opens after hydration.
66
+ *
67
+ * @defaultValue `false`
68
+ */
69
+ defaultOpen?: boolean;
70
+ /**
71
+ * Requests only: awaited for opens and for the closes the parts ask for (the Trigger,
72
+ * Alt+ArrowUp). Never called for a dismissal: that goes to `onOpenChange`.
73
+ */
74
+ openChangeAction?: ChangeAction<boolean, MultiSelectOpenChangeDetails>;
75
+ /**
76
+ * Facts only: the listbox was closed without the library closing it on request (Escape, light
77
+ * dismiss, focus leaving the Trigger, another top-layer element, script). Always `false`.
78
+ * Called synchronously, outside any Transition, and not awaited: nothing is pending.
79
+ * Controlled: set your state **directly** here (`onOpenChange={setOpen}`). May return a
80
+ * promise; a rejection or a throw goes to `reportError`.
81
+ */
82
+ onOpenChange?: UrgentChangeHandler<boolean, MultiSelectOpenChangeDetails>;
83
+ /**
84
+ * Wrap from the last option to the first and back with the arrow keys.
85
+ *
86
+ * @defaultValue `false`
87
+ */
88
+ loop?: boolean;
89
+ /** Form participation: one hidden input with this name per value (nothing posted for `[]`). */
90
+ name?: string;
91
+ /** The `form` attribute of the hidden inputs and of the validity element. */
92
+ form?: string;
93
+ /**
94
+ * At least one value must be selected for the form to submit: a visually hidden validity
95
+ * element after the Trigger is `required` while the optimistic selection is empty, and the
96
+ * Trigger carries `aria-required`.
97
+ *
98
+ * @defaultValue `false`
99
+ */
100
+ required?: boolean;
101
+ /**
102
+ * Disables the Trigger natively; nothing opens or dispatches. The hidden inputs still post.
103
+ *
104
+ * @defaultValue `false`
105
+ */
106
+ disabled?: boolean;
107
+ /** The parts, or a function of the Root's state. */
108
+ children?: StateValue<ReactNode, MultiSelectRootState>;
109
+ }
110
+ /**
111
+ * Owns a multi-select listbox (design/components/multi-select.md): the selection (`value`, a set
112
+ * in pick order under the shared set-valued rules, a transition with `useOptimistic`), the open
113
+ * state (`usePopoverRoot`, library mode), the active option (urgent virtual focus through the
114
+ * Trigger's `aria-activedescendant`), the Option and Status registries, the label cache and the
115
+ * form-reset listener. Renders no DOM, except one `<input type="hidden">` per value when `name`
116
+ * is given.
117
+ *
118
+ * @see https://ui.funstack.work/components/multi-select
119
+ */
120
+ export declare function MultiSelectRoot(props: MultiSelectRootProps): import("react").JSX.Element;
121
+ export declare namespace MultiSelectRoot {
122
+ var displayName: string;
123
+ }
124
+ //#endregion
125
+ //# sourceMappingURL=multi-select-root.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi-select-root.d.mts","names":[],"sources":["../../src/multi-select/multi-select-root.tsx"],"mappings":";;;;iBAkCiB,sCAAsC;;;;;;WAM5C,QAAQ;;WAER;;WAEA;;;iBAIM,qCAAqC;;;;;;;WAO3C,QAAQ;;;iBAIF;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;;iBAQM;;EAEf;;;;;;EAMA;;;;;;;;EAQA,oBAAoB,uBAAuB;;EAG3C;;;;;;EAMA;;;;;EAKA,mBAAmB,sBAAsB;;;;;;;;EAQzC,eAAe,6BAA6B;;;;;;EAO5C;;EAEA;;EAEA;;;;;;;;EAQA;;;;;;EAMA;;EAEA,WAAW,WAAW,WAAW;;;;;;;;;;;;wBAanB,gBAAgB,OAAO,uCAAoB,IAAA;yBAA3C"}
@@ -0,0 +1,257 @@
1
+ "use client";
2
+ import { resolveStateValue } from "../internal/render-element.mjs";
3
+ import { useLatest } from "../internal/use-latest.mjs";
4
+ import { toSet } from "../internal/value-set.mjs";
5
+ import { isPopoverOpen } from "../internal/overlay/popover-open.mjs";
6
+ import { popoverDetails, usePopoverRoot } from "../internal/overlay/use-overlay-root.mjs";
7
+ import { FieldContext } from "../internal/form/field-context.mjs";
8
+ import { resolveFieldDefaults, useFieldValueChange } from "../internal/form/use-field-control.mjs";
9
+ import { useFormReset, useResetTarget } from "../internal/form/use-form-reset.mjs";
10
+ import { toggleFromTrigger } from "../internal/overlay/use-popover-trigger.mjs";
11
+ import { createTypeaheadBuffer } from "../internal/typeahead.mjs";
12
+ import { optionLabel, useOptionRegistry } from "../internal/use-option-registry.mjs";
13
+ import { HiddenValues } from "../internal/form/hidden-values.mjs";
14
+ import { useActiveOption } from "../internal/use-active-option.mjs";
15
+ import { useDeferredLeave } from "../internal/use-deferred-leave.mjs";
16
+ import { useMultipleSelection } from "../internal/action/use-multiple-selection.mjs";
17
+ import { MultiSelectContext } from "./multi-select-context.mjs";
18
+ import { createMultiSelectKeyDown } from "./multi-select-keyboard.mjs";
19
+ import { use, useCallback, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
20
+ import { jsx, jsxs } from "react/jsx-runtime";
21
+ //#region src/multi-select/multi-select-root.tsx
22
+ const NO_LABELS = /* @__PURE__ */ new Map();
23
+ /**
24
+ * Owns a multi-select listbox (design/components/multi-select.md): the selection (`value`, a set
25
+ * in pick order under the shared set-valued rules, a transition with `useOptimistic`), the open
26
+ * state (`usePopoverRoot`, library mode), the active option (urgent virtual focus through the
27
+ * Trigger's `aria-activedescendant`), the Option and Status registries, the label cache and the
28
+ * form-reset listener. Renders no DOM, except one `<input type="hidden">` per value when `name`
29
+ * is given.
30
+ *
31
+ * @see https://ui.funstack.work/components/multi-select
32
+ */
33
+ function MultiSelectRoot(props) {
34
+ const { value, defaultValue, valueChangeAction, open, defaultOpen, openChangeAction, onOpenChange, loop = false, form, children } = props;
35
+ const field = use(FieldContext);
36
+ const { name, disabled, required } = resolveFieldDefaults(field, {
37
+ name: props.name,
38
+ disabled: props.disabled ?? false,
39
+ required: props.required ?? false
40
+ });
41
+ const fieldControlId = field?.ids.control;
42
+ const id = useId();
43
+ const ids = useMemo(() => ({
44
+ trigger: fieldControlId ?? `${id}-trigger`,
45
+ label: `${id}-label`,
46
+ list: `${id}-list`,
47
+ optionPrefix: `${id}-option-`
48
+ }), [id, fieldControlId]);
49
+ const popover = usePopoverRoot({
50
+ component: "multi-select",
51
+ part: "MultiSelect.Root",
52
+ mode: "library",
53
+ open,
54
+ defaultOpen,
55
+ openChangeAction,
56
+ onOpenChange,
57
+ details: popoverDetails
58
+ });
59
+ const triggerRef = useRef(null);
60
+ const listRef = useRef(null);
61
+ const hiddenRef = useRef(null);
62
+ const validityRef = useRef(null);
63
+ const multi = useMultipleSelection({
64
+ component: "multi-select",
65
+ part: "MultiSelect.Root",
66
+ enabled: true,
67
+ value,
68
+ defaultValue,
69
+ valueChangeAction,
70
+ resetFields: {}
71
+ });
72
+ const selectedRef = useLatest(multi.optimistic);
73
+ /** The next change of the optimistic selection comes from the user (a dispatch). */
74
+ const userEdit = useRef(false);
75
+ useFieldValueChange(multi.values, () => {
76
+ const edit = userEdit.current;
77
+ userEdit.current = false;
78
+ return edit;
79
+ });
80
+ const [labels] = useState(() => /* @__PURE__ */ new Map());
81
+ const [valueLabels, setValueLabels] = useState(NO_LABELS);
82
+ const learnLabels = useCallback((entries) => {
83
+ if (entries.length === 0) return;
84
+ setValueLabels((prev) => {
85
+ let next = null;
86
+ for (const [v, label] of entries) {
87
+ if (prev.get(v) === label) continue;
88
+ next ??= new Map(prev);
89
+ next.set(v, label);
90
+ }
91
+ return next ?? prev;
92
+ });
93
+ }, []);
94
+ const { registry, optionCount, statusCount, statusCountRef, labelCount, registerOption, registerStatus, registerLabel, orderedOptions } = useOptionRegistry("MultiSelect", labels, (optionValue, label) => {
95
+ if (selectedRef.current.has(optionValue)) learnLabels([[optionValue, label]]);
96
+ });
97
+ useLayoutEffect(() => {
98
+ const entries = [];
99
+ for (const v of multi.values) {
100
+ const label = labels.get(v);
101
+ if (label !== void 0) entries.push([v, label]);
102
+ }
103
+ learnLabels(entries);
104
+ }, [
105
+ multi.values,
106
+ labels,
107
+ learnLabels
108
+ ]);
109
+ const loading = statusCount > 0;
110
+ const empty = optionCount === 0 && !loading;
111
+ const active = useActiveOption({
112
+ popover,
113
+ orderedOptions,
114
+ autoHighlight: false,
115
+ stale: false,
116
+ loading: () => statusCountRef.current > 0
117
+ });
118
+ const { activeValue, activeRef, setActive, pendingEdgeRef } = active;
119
+ /** The initial active option (B.8): the first selected option, else the first or last one. */
120
+ const selectedEdge = (fallback) => {
121
+ return (enabled) => {
122
+ const selected = selectedRef.current;
123
+ const first = enabled.find((option) => selected.has(option.value));
124
+ if (first !== void 0) return first.value;
125
+ return (fallback === "first" ? enabled[0] : enabled.at(-1))?.value ?? null;
126
+ };
127
+ };
128
+ const resetTarget = useResetTarget(value, defaultValue);
129
+ const formElement = useMemo(() => ({
130
+ get current() {
131
+ return hiddenRef.current ?? validityRef.current ?? triggerRef.current;
132
+ },
133
+ set current(_ignored) {}
134
+ }), []);
135
+ useFormReset(formElement, (event) => {
136
+ multi.reset(toSet(resetTarget ?? []), event);
137
+ });
138
+ const toggle = (optionValue, event) => {
139
+ if (disabled) return;
140
+ const entry = registry.get(optionValue);
141
+ if (entry === void 0 || entry.disabled) return;
142
+ const label = optionLabel(entry);
143
+ labels.set(optionValue, label);
144
+ learnLabels([[optionValue, label]]);
145
+ pendingEdgeRef.current = null;
146
+ if (activeRef.current !== optionValue) setActive(optionValue);
147
+ const patch = multi.optimistic.has(optionValue) ? {
148
+ added: [],
149
+ removed: [optionValue]
150
+ } : {
151
+ added: [optionValue],
152
+ removed: []
153
+ };
154
+ if (multi.change(patch, { reason: "activate" }, event)) userEdit.current = true;
155
+ };
156
+ const typeahead = useRef(createTypeaheadBuffer());
157
+ const keyDown = createMultiSelectKeyDown({
158
+ disabled,
159
+ loop,
160
+ popover,
161
+ options: {
162
+ registry,
163
+ orderedOptions
164
+ },
165
+ active,
166
+ typeahead,
167
+ selectedEdge,
168
+ toggle
169
+ });
170
+ const triggerClick = (event) => {
171
+ event.preventDefault();
172
+ if (disabled) return;
173
+ const trigger = triggerRef.current;
174
+ if (trigger !== null && trigger.ownerDocument.activeElement !== trigger) trigger.focus();
175
+ toggleFromTrigger(popover, event, () => {
176
+ pendingEdgeRef.current = selectedEdge("first");
177
+ });
178
+ };
179
+ /** Focus has left the Trigger and the Popup (B.4): a shown listbox closes as a dismissal. */
180
+ const leave = (event) => {
181
+ pendingEdgeRef.current = null;
182
+ if (disabled) return;
183
+ const popup = popover.popupRef.current;
184
+ if (popup !== null && isPopoverOpen(popup)) {
185
+ popover.recordCloseIntent({
186
+ reason: "dismiss",
187
+ event
188
+ });
189
+ popup.hidePopover();
190
+ }
191
+ };
192
+ const { focusIn, focusOut } = useDeferredLeave({
193
+ surfaceRef: triggerRef,
194
+ popupRef: popover.popupRef,
195
+ leave
196
+ });
197
+ const labelClick = (event) => {
198
+ event.preventDefault();
199
+ if (!disabled) triggerRef.current?.focus();
200
+ };
201
+ const valueLabelsList = useMemo(() => multi.values.map((v) => valueLabels.get(v)), [multi.values, valueLabels]);
202
+ const pending = multi.pending || popover.pending;
203
+ const context = {
204
+ popover,
205
+ ids,
206
+ values: multi.values,
207
+ labels: valueLabelsList,
208
+ isSelected: (v) => multi.optimistic.has(v),
209
+ isPending: (v) => multi.pending && multi.optimistic.has(v) !== multi.committed.has(v),
210
+ pending,
211
+ activeValue,
212
+ empty,
213
+ loading,
214
+ hasLabel: labelCount > 0,
215
+ fieldLabelId: field?.ids.label,
216
+ disabled,
217
+ required,
218
+ form,
219
+ triggerRef,
220
+ listRef,
221
+ validityRef,
222
+ registerOption,
223
+ registerStatus,
224
+ registerLabel,
225
+ setActive: (v) => {
226
+ pendingEdgeRef.current = null;
227
+ setActive(v);
228
+ },
229
+ toggle,
230
+ triggerClick,
231
+ keyDown,
232
+ focusIn,
233
+ focusOut,
234
+ labelClick
235
+ };
236
+ const state = {
237
+ value: multi.values,
238
+ activeValue,
239
+ open: popover.optimistic,
240
+ pending,
241
+ disabled
242
+ };
243
+ return /* @__PURE__ */ jsxs(MultiSelectContext, {
244
+ value: context,
245
+ children: [/* @__PURE__ */ jsx(HiddenValues, {
246
+ name,
247
+ form,
248
+ values: multi.values,
249
+ inputRef: hiddenRef
250
+ }), resolveStateValue(children, state)]
251
+ });
252
+ }
253
+ MultiSelectRoot.displayName = "MultiSelectRoot";
254
+ //#endregion
255
+ export { MultiSelectRoot };
256
+
257
+ //# sourceMappingURL=multi-select-root.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi-select-root.mjs","names":[],"sources":["../../src/multi-select/multi-select-root.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useId, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport type { ReactNode, RefObject } from \"react\";\nimport { useMultipleSelection } from \"../internal/action/use-multiple-selection.js\";\nimport { FieldContext } from \"../internal/form/field-context.js\";\nimport { HiddenValues } from \"../internal/form/hidden-values.js\";\nimport type { FormAssociatedElement } from \"../internal/form/use-form-owner-event.js\";\nimport { useFormReset, useResetTarget } from \"../internal/form/use-form-reset.js\";\nimport { resolveFieldDefaults, useFieldValueChange } from \"../internal/form/use-field-control.js\";\nimport { isPopoverOpen } from \"../internal/overlay/popover-open.js\";\nimport { toggleFromTrigger } from \"../internal/overlay/use-popover-trigger.js\";\nimport { popoverDetails, usePopoverRoot } from \"../internal/overlay/use-overlay-root.js\";\nimport { createTypeaheadBuffer } from \"../internal/typeahead.js\";\nimport type {\n ActionDetails,\n ChangeAction,\n ChangeReason,\n StateValue,\n UrgentChangeHandler,\n} from \"../internal/types.js\";\nimport { useActiveOption } from \"../internal/use-active-option.js\";\nimport type { PendingEdge } from \"../internal/use-active-option.js\";\nimport { useDeferredLeave } from \"../internal/use-deferred-leave.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { optionLabel, useOptionRegistry } from \"../internal/use-option-registry.js\";\nimport { resolveStateValue } from \"../internal/use-render.js\";\nimport { toSet } from \"../internal/value-set.js\";\nimport { MultiSelectContext } from \"./multi-select-context.js\";\nimport type { MultiSelectContextValue } from \"./multi-select-context.js\";\nimport { createMultiSelectKeyDown } from \"./multi-select-keyboard.js\";\n\nconst NO_LABELS: ReadonlyMap<string, string> = new Map();\n\n/** Details passed as the second argument of `MultiSelect.Root`'s `valueChangeAction`. */\nexport interface MultiSelectValueChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user toggled an option (Enter, Space, click; `details.event` is the\n * `keydown` or `click`).\n * `\"platform\"`: a form reset (`details.event` is the `reset` event).\n */\n readonly reason: ChangeReason;\n /** Values this dispatch added, in the order they join the value. */\n readonly added: readonly string[];\n /** Values this dispatch removed, in value order. */\n readonly removed: readonly string[];\n}\n\n/** Details passed as the second argument of `MultiSelect.Root`'s `openChangeAction` and `onOpenChange`. */\nexport interface MultiSelectOpenChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the Trigger (click, Enter, Space, arrows, Home, End, a typed character),\n * Alt+ArrowUp, a foreign invoker or `showPopover()`.\n * `\"dismiss\"`: Escape, light dismiss, focus leaving, another top-layer element.\n * `\"platform\"`: the popup was found open at mount.\n */\n readonly reason: ChangeReason;\n}\n\n/** State of `MultiSelect.Root`, passed to the function form of `children`. */\nexport interface MultiSelectRootState {\n /** Optimistic selection, in pick order. Content rendered from it must not suspend. */\n readonly value: readonly string[];\n /** The value of the option `aria-activedescendant` points at, or `null`. */\n readonly activeValue: string | null;\n /** Optimistic open state. */\n readonly open: boolean;\n /** A `valueChangeAction` or `openChangeAction` dispatched through this Root is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop, or the enclosing Field's. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `MultiSelect.Root`.\n *\n * @see https://ui.funstack.work/components/multi-select\n */\nexport interface MultiSelectRootProps {\n /** Controlled selection. `[]`: nothing selected. `undefined`: uncontrolled. Duplicates are ignored. */\n value?: string[];\n /**\n * Initial selection in uncontrolled mode; also the form-reset target (the latest value).\n *\n * @defaultValue `[]`\n */\n defaultValue?: string[];\n /**\n * Runs inside the Root's transition for every change of the selection. `next` is the whole\n * intended selection as a fresh array; `details.added` / `details.removed` say what this\n * dispatch changed. Awaited; a rejection rolls this change back and nothing else. May be a\n * Server Function. Persist the diff, not `next`: `next` can contain an earlier change that\n * fails later.\n */\n valueChangeAction?: ChangeAction<string[], MultiSelectValueChangeDetails>;\n\n /** Controlled open state. `undefined`: uncontrolled. */\n open?: boolean;\n /**\n * Initial open state when uncontrolled. Opens after hydration.\n *\n * @defaultValue `false`\n */\n defaultOpen?: boolean;\n /**\n * Requests only: awaited for opens and for the closes the parts ask for (the Trigger,\n * Alt+ArrowUp). Never called for a dismissal: that goes to `onOpenChange`.\n */\n openChangeAction?: ChangeAction<boolean, MultiSelectOpenChangeDetails>;\n /**\n * Facts only: the listbox was closed without the library closing it on request (Escape, light\n * dismiss, focus leaving the Trigger, another top-layer element, script). Always `false`.\n * Called synchronously, outside any Transition, and not awaited: nothing is pending.\n * Controlled: set your state **directly** here (`onOpenChange={setOpen}`). May return a\n * promise; a rejection or a throw goes to `reportError`.\n */\n onOpenChange?: UrgentChangeHandler<boolean, MultiSelectOpenChangeDetails>;\n\n /**\n * Wrap from the last option to the first and back with the arrow keys.\n *\n * @defaultValue `false`\n */\n loop?: boolean;\n /** Form participation: one hidden input with this name per value (nothing posted for `[]`). */\n name?: string;\n /** The `form` attribute of the hidden inputs and of the validity element. */\n form?: string;\n /**\n * At least one value must be selected for the form to submit: a visually hidden validity\n * element after the Trigger is `required` while the optimistic selection is empty, and the\n * Trigger carries `aria-required`.\n *\n * @defaultValue `false`\n */\n required?: boolean;\n /**\n * Disables the Trigger natively; nothing opens or dispatches. The hidden inputs still post.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** The parts, or a function of the Root's state. */\n children?: StateValue<ReactNode, MultiSelectRootState>;\n}\n\n/**\n * Owns a multi-select listbox (design/components/multi-select.md): the selection (`value`, a set\n * in pick order under the shared set-valued rules, a transition with `useOptimistic`), the open\n * state (`usePopoverRoot`, library mode), the active option (urgent virtual focus through the\n * Trigger's `aria-activedescendant`), the Option and Status registries, the label cache and the\n * form-reset listener. Renders no DOM, except one `<input type=\"hidden\">` per value when `name`\n * is given.\n *\n * @see https://ui.funstack.work/components/multi-select\n */\nexport function MultiSelectRoot(props: MultiSelectRootProps) {\n const {\n value,\n defaultValue,\n valueChangeAction,\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n loop = false,\n form,\n children,\n } = props;\n\n // Inside a Field.Root (design/components/field-form.md 7.2): the Trigger is the Field's control\n // (its id is the Field's, so `Field.Label` points at it); `name`, `disabled` and `required`\n // default from the Field, and the List is named by `Field.Label` when no Label is mounted.\n const field = use(FieldContext);\n const { name, disabled, required } = resolveFieldDefaults(field, {\n name: props.name,\n disabled: props.disabled ?? false,\n required: props.required ?? false,\n });\n const fieldControlId = field?.ids.control;\n\n const id = useId();\n const ids = useMemo(\n () => ({\n trigger: fieldControlId ?? `${id}-trigger`,\n label: `${id}-label`,\n list: `${id}-list`,\n optionPrefix: `${id}-option-`,\n }),\n [id, fieldControlId],\n );\n\n const popover = usePopoverRoot<MultiSelectOpenChangeDetails>({\n component: \"multi-select\",\n part: \"MultiSelect.Root\",\n mode: \"library\",\n open,\n defaultOpen,\n openChangeAction,\n onOpenChange,\n details: popoverDetails,\n });\n\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const listRef = useRef<HTMLElement | null>(null);\n const hiddenRef = useRef<HTMLInputElement | null>(null);\n const validityRef = useRef<HTMLSelectElement | null>(null);\n\n // --- Selection: a set, pick order (B.6) ---------------------------------------------------\n\n const multi = useMultipleSelection<Record<never, never>>({\n component: \"multi-select\",\n part: \"MultiSelect.Root\",\n enabled: true,\n value,\n defaultValue,\n valueChangeAction,\n resetFields: {},\n });\n const selectedRef = useLatest(multi.optimistic);\n\n /** The next change of the optimistic selection comes from the user (a dispatch). */\n const userEdit = useRef(false);\n // Inside a Field: React writes the hidden inputs with no `input` / `change` event, so the\n // Field is told after the commit (a user's pick dismisses a shown server error like typing).\n useFieldValueChange(multi.values, () => {\n const edit = userEdit.current;\n userEdit.current = false;\n return edit;\n });\n\n // --- Labels (B.7; the label cache of combobox.md 2.3) --------------------------------------\n\n const [labels] = useState(() => new Map<string, string>());\n // The cache is a mutable map read by handlers; `Value` renders from this snapshot of its\n // entries for the selected values, written in the pick's event and when an Option for a\n // selected value registers.\n const [valueLabels, setValueLabels] = useState<ReadonlyMap<string, string>>(NO_LABELS);\n const learnLabels = useCallback((entries: readonly (readonly [string, string])[]) => {\n if (entries.length === 0) return;\n setValueLabels((prev) => {\n let next: Map<string, string> | null = null;\n for (const [v, label] of entries) {\n if (prev.get(v) === label) continue;\n next ??= new Map(prev);\n next.set(v, label);\n }\n return next ?? prev;\n });\n }, []);\n\n const {\n registry,\n optionCount,\n statusCount,\n statusCountRef,\n labelCount,\n registerOption,\n registerStatus,\n registerLabel,\n orderedOptions,\n } = useOptionRegistry(\"MultiSelect\", labels, (optionValue, label) => {\n if (selectedRef.current.has(optionValue)) learnLabels([[optionValue, label]]);\n });\n // A value that joined the selection from outside (a controlled parent, a reset) takes the\n // cache's entry, if an Option for it was ever mounted.\n useLayoutEffect(() => {\n const entries: [string, string][] = [];\n for (const v of multi.values) {\n const label = labels.get(v);\n if (label !== undefined) entries.push([v, label]);\n }\n // oxlint-disable-next-line react/set-state-in-effect -- the cache is a ref map render cannot read\n learnLabels(entries);\n }, [multi.values, labels, learnLabels]);\n\n // A Status inside the List is a Suspense fallback: the options are loading (combobox.md 6.3).\n const loading = statusCount > 0;\n const empty = optionCount === 0 && !loading;\n\n const active = useActiveOption({\n popover,\n orderedOptions,\n autoHighlight: false,\n stale: false,\n loading: () => statusCountRef.current > 0,\n });\n const { activeValue, activeRef, setActive, pendingEdgeRef } = active;\n\n /** The initial active option (B.8): the first selected option, else the first or last one. */\n const selectedEdge = (fallback: \"first\" | \"last\"): PendingEdge => {\n return (enabled) => {\n const selected = selectedRef.current;\n const first = enabled.find((option) => selected.has(option.value));\n if (first !== undefined) return first.value;\n return (fallback === \"first\" ? enabled[0] : enabled.at(-1))?.value ?? null;\n };\n };\n\n // --- Form: hidden inputs, reset (B.10) -----------------------------------------------------\n\n // Reset targets (conventions 3.8 rule 6): uncontrolled, the latest `defaultValue`; controlled,\n // the mount-time `value`.\n const resetTarget = useResetTarget(value, defaultValue);\n const formElement = useMemo<RefObject<FormAssociatedElement | null>>(\n () => ({\n get current() {\n // A button has a form owner too: the reset listener works without `name` and `required`.\n return (hiddenRef.current ??\n validityRef.current ??\n triggerRef.current) as FormAssociatedElement | null;\n },\n set current(_ignored) {},\n }),\n [],\n );\n useFormReset(formElement, (event) => {\n multi.reset(toSet(resetTarget ?? []), event);\n });\n\n // --- Interaction (B.4, B.5, B.8) -----------------------------------------------------------\n\n const toggle = (optionValue: string, event: Event): void => {\n if (disabled) return;\n const entry = registry.get(optionValue);\n if (entry === undefined || entry.disabled) return;\n const label = optionLabel(entry);\n labels.set(optionValue, label);\n // Before the dispatch: the Value's first render with the value already has its label.\n learnLabels([[optionValue, label]]);\n pendingEdgeRef.current = null;\n if (activeRef.current !== optionValue) setActive(optionValue);\n const patch = multi.optimistic.has(optionValue)\n ? { added: [], removed: [optionValue] }\n : { added: [optionValue], removed: [] };\n if (multi.change(patch, { reason: \"activate\" }, event)) userEdit.current = true;\n // No close, no focus move: the listbox stays open (B.5).\n };\n\n const typeahead = useRef(createTypeaheadBuffer());\n // The factory only builds the `keydown` handler: the refs it reads are read when a key is\n // pressed, never during render.\n // oxlint-disable-next-line react/refs\n const keyDown = createMultiSelectKeyDown({\n disabled,\n loop,\n popover,\n options: { registry, orderedOptions },\n active,\n typeahead,\n selectedEdge,\n toggle,\n });\n\n const triggerClick = (event: MouseEvent): void => {\n // Cancelled first, whatever follows: the popover toggle of `popovertarget` never runs (the\n // library opens the listbox), so the click toggles against the state the user saw (B.4).\n event.preventDefault();\n if (disabled) return;\n // WebKit does not focus a button on a mouse press; the keys and the leave rule need focus.\n const trigger = triggerRef.current;\n if (trigger !== null && trigger.ownerDocument.activeElement !== trigger) trigger.focus();\n toggleFromTrigger(popover, event, () => {\n pendingEdgeRef.current = selectedEdge(\"first\");\n });\n };\n\n /** Focus has left the Trigger and the Popup (B.4): a shown listbox closes as a dismissal. */\n const leave = (event: Event): void => {\n pendingEdgeRef.current = null;\n if (disabled) return;\n const popup = popover.popupRef.current;\n if (popup !== null && isPopoverOpen(popup)) {\n popover.recordCloseIntent({ reason: \"dismiss\", event });\n popup.hidePopover();\n }\n };\n const { focusIn, focusOut } = useDeferredLeave({\n surfaceRef: triggerRef,\n popupRef: popover.popupRef,\n leave,\n });\n\n const labelClick = (event: MouseEvent): void => {\n // A `<label for>` on a button forwards the click, which would open the listbox; a label on\n // a native `<select>` only focuses it (B.8).\n event.preventDefault();\n if (!disabled) triggerRef.current?.focus();\n };\n\n const valueLabelsList = useMemo(\n () => multi.values.map((v) => valueLabels.get(v)),\n [multi.values, valueLabels],\n );\n\n const pending = multi.pending || popover.pending;\n const context: MultiSelectContextValue = {\n popover,\n ids,\n values: multi.values,\n labels: valueLabelsList,\n isSelected: (v) => multi.optimistic.has(v),\n isPending: (v) => multi.pending && multi.optimistic.has(v) !== multi.committed.has(v),\n pending,\n activeValue,\n empty,\n loading,\n hasLabel: labelCount > 0,\n fieldLabelId: field?.ids.label,\n disabled,\n required,\n form,\n triggerRef,\n listRef,\n validityRef,\n registerOption,\n registerStatus,\n registerLabel,\n // Hover on an option: as the keys, it disarms an edge waiting for the options to load.\n setActive: (v) => {\n pendingEdgeRef.current = null;\n setActive(v);\n },\n toggle,\n triggerClick,\n keyDown,\n focusIn,\n focusOut,\n labelClick,\n };\n\n const state: MultiSelectRootState = {\n value: multi.values,\n activeValue,\n open: popover.optimistic,\n pending,\n disabled,\n };\n\n return (\n <MultiSelectContext value={context}>\n <HiddenValues name={name} form={form} values={multi.values} inputRef={hiddenRef} />\n {resolveStateValue(children, state)}\n </MultiSelectContext>\n );\n}\n\nMultiSelectRoot.displayName = \"MultiSelectRoot\";\n"],"mappings":"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"}
@@ -0,0 +1,66 @@
1
+ import { RenderProp, StateValue } from "../internal/types.mjs";
2
+ import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
3
+ //#region src/multi-select/multi-select-trigger.d.ts
4
+ /**
5
+ * State of `MultiSelect.Trigger`, passed to the function forms of `className`, `style`,
6
+ * `children` and `render`.
7
+ */
8
+ export interface MultiSelectTriggerState {
9
+ /** Optimistic selection, in pick order. */
10
+ readonly value: readonly string[];
11
+ /** Optimistic open state. */
12
+ readonly open: boolean;
13
+ /** The Root's `pending`: a value or open transition is in flight. */
14
+ readonly pending: boolean;
15
+ /** Disabled by its own prop or by the Root. */
16
+ readonly disabled: boolean;
17
+ }
18
+ /**
19
+ * Props of `MultiSelect.Trigger`.
20
+ *
21
+ * @see https://ui.funstack.work/components/multi-select
22
+ */
23
+ export interface MultiSelectTriggerProps extends Omit<ComponentPropsWithRef<"button">, "type" | "role" | "onClick" | "onKeyDown" | "onFocus" | "onBlur" | "popoverTarget" | "popoverTargetAction" | "commandfor" | "command" | "aria-expanded" | "aria-controls" | "aria-activedescendant" | "aria-required" | "form" | "disabled" | "className" | "style" | "children"> {
24
+ /**
25
+ * Disables this button; the Root's `disabled` does too. Native `disabled`.
26
+ *
27
+ * @defaultValue `false`
28
+ */
29
+ disabled?: boolean;
30
+ /** Class name, or a function of the part's state that returns one. */
31
+ className?: StateValue<string | undefined, MultiSelectTriggerState>;
32
+ /** Inline style, or a function of the part's state that returns one. */
33
+ style?: StateValue<CSSProperties | undefined, MultiSelectTriggerState>;
34
+ /** Non-interactive content only (a `<button>` may not contain interactive content). Must not suspend. */
35
+ children?: StateValue<ReactNode, MultiSelectTriggerState>;
36
+ /** Must render a `<button>`: the `popovertarget` light-dismiss exemption is defined for buttons. */
37
+ render?: RenderProp<ComponentPropsWithRef<"button">, MultiSelectTriggerState>;
38
+ }
39
+ /**
40
+ * The combobox itself: `<button type="button" role="combobox">`, the one Tab stop of the
41
+ * MultiSelect (design/components/multi-select.md B.1, B.4). DOM focus stays here while the listbox
42
+ * is open; the options are virtual focus through `aria-activedescendant`. After hydration it names
43
+ * the Popup as its invoker (`popovertarget`, written through the ref, never server-rendered), so
44
+ * a press on it while the listbox is shown is not a light dismiss; every click is cancelled and
45
+ * toggles the listbox against the state the user saw. It renders `aria-expanded` from the shown
46
+ * listbox (the role requires the state, and before hydration there is no invoker). With
47
+ * `required` it renders the **validity element** right after itself: a visually hidden one-option
48
+ * `<select tabindex="-1" aria-hidden="true">`, `required` while the optimistic selection is empty
49
+ * (B.10). It blocks a submission natively; its
50
+ * `invalid` is cancelled (no browser bubble) and the attempt focuses the button, so the message is
51
+ * `Field.Error`'s. Focus it receives passes to the button.
52
+ *
53
+ * Owned keys (conventions 1.2): `id`, `type`, `role`, `disabled`, `aria-expanded`,
54
+ * `aria-controls` (token-merged), `aria-activedescendant`, `aria-required`, `popovertarget`
55
+ * (written after hydration), `form`, `onClick`, `onKeyDown`, `onFocus`, `onBlur`,
56
+ * `data-open`, `data-pending`, `data-disabled`; inside a `Field.Root` also `aria-describedby`
57
+ * (token-merged), `aria-invalid` and `data-invalid`.
58
+ *
59
+ * @see https://ui.funstack.work/components/multi-select
60
+ */
61
+ export declare function MultiSelectTrigger({ disabled: ownDisabled, className, style, children, render, ...rest }: MultiSelectTriggerProps): string | number | bigint | boolean | import("react").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | Iterable<ReactNode> | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | import("react").ReactPortal | null | undefined> | null | undefined;
62
+ export declare namespace MultiSelectTrigger {
63
+ var displayName: string;
64
+ }
65
+ //#endregion
66
+ //# sourceMappingURL=multi-select-trigger.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi-select-trigger.d.mts","names":[],"sources":["../../src/multi-select/multi-select-trigger.tsx"],"mappings":";;;;;;;iBA8BiB;;WAEN;;WAEA;;WAEA;;WAEA;;;;;;;iBAQM,gCAAgC,KAC/C;;;;;;EA0BA;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;wBAyCvC,qBACd,UAAU,aACV,WACA,OACA,UACA,WACG,QACF,+EAAuB,IAAA,UAAA,SAAA,aAAA,6CAAA,SAAA,6BAAA,+CAAA,8CAAA;yBAPV"}