@fragiola/primitives-react 0.1.0 → 0.2.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @fragiola/primitives-react
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#123](https://github.com/fragiola/primitives/pull/123) [`18fd0ff`](https://github.com/fragiola/primitives/commit/18fd0ff180f8b7af9586db77b67b105281b89242) Thanks [@maurodesouza](https://github.com/maurodesouza)! - NumberField reports the committed value: `onValueCommitted` (Vue `@value-committed`, Angular `(valueCommitted)`) is called once a change is complete, on blur after typing, at a key or wheel step, at the release of a button press or a scrub. The toolkit's `watchAutoRepeat` takes an `onEnd` callback.
8
+
9
+ Combobox takes `autoHighlight`: typing highlights the first item the text keeps, so Enter chooses it, as Autocomplete's.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [[`18fd0ff`](https://github.com/fragiola/primitives/commit/18fd0ff180f8b7af9586db77b67b105281b89242)]:
14
+ - @fragiola/primitives@0.2.0
15
+
3
16
  ## 0.1.0
4
17
 
5
18
  ### Minor Changes
@@ -1,4 +1,4 @@
1
- import { n as ComboboxList, r as ComboboxContext } from "./parts-VT0Ohb06.js";
1
+ import { n as ComboboxList, r as ComboboxContext } from "./parts-Dpfqew1M.js";
2
2
  import { t as useElement } from "./use-element-tpFZ-kuA.js";
3
3
  import { t as useRequiredContext } from "./use-required-context-Cjd_CYnv.js";
4
4
  import { n as useVirtualRows, t as reachableRows } from "./use-virtual-rows-B5N0qgmT.js";
@@ -58,4 +58,4 @@ function ComboboxVirtualList({ children, itemSize, measure, overscan, loading =
58
58
  const ComboboxVirtual = { List: ComboboxVirtualList };
59
59
  export { ComboboxVirtual as t };
60
60
 
61
- //# sourceMappingURL=combobox-virtual-BI-l10BE.js.map
61
+ //# sourceMappingURL=combobox-virtual-DCbsgcWu.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"combobox-virtual-BI-l10BE.js","names":[],"sources":["../src/components/combobox-virtual/combobox-virtual-list.tsx","../src/components/combobox-virtual/parts.ts"],"sourcesContent":["import {\n type ReactNode,\n type Ref,\n useLayoutEffect,\n useMemo,\n useRef,\n} from \"react\";\nimport { useElement } from \"../../hooks/use-element.ts\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport {\n reachableRows,\n useVirtualRows,\n type VirtualListProps,\n} from \"../../hooks/use-virtual-rows.ts\";\nimport { mergeRefs } from \"../../utils/merge-refs.ts\";\nimport type { PartProps } from \"../../utils/render-element.tsx\";\nimport { ComboboxContext } from \"../combobox/combobox-context.ts\";\nimport { ComboboxList } from \"../combobox/combobox-list.tsx\";\n\nexport interface ComboboxVirtualListProps<Entry = unknown>\n extends Omit<PartProps<{ empty: boolean }>, \"children\">,\n VirtualListProps {\n /** A `Combobox.Item` for each matching item in view (the Root's `items`, flat). */\n children: (entry: Entry, index: number) => ReactNode;\n}\n\n/**\n * Combobox's List rendering only the matching items in view (spec/virtual-lists.md): the ends, the\n * highlighted item with its neighbours and the selected item stay rendered, so the Input's keys\n * and `aria-activedescendant` behave as with every item rendered.\n */\nexport function ComboboxVirtualList<Entry = unknown>({\n children,\n itemSize,\n measure,\n overscan,\n loading = false,\n onLoadMore,\n ref,\n ...props\n}: ComboboxVirtualListProps<Entry>) {\n const context = useRequiredContext(ComboboxContext, \"ComboboxVirtual.List\");\n const [list, setList] = useElement<HTMLElement>();\n const entries = context.entries as readonly Entry[];\n const { multiple, isSelected, highlighted } = context;\n const selected = useMemo(\n () => (multiple ? -1 : entries.findIndex((entry) => isSelected(entry))),\n [entries, multiple, isSelected],\n );\n // the highlighted option is rendered: its index is the one its element was rendered at\n const elements = useRef<ReadonlyMap<number, HTMLElement>>(new Map());\n let current: number | undefined;\n for (const [index, element] of elements.current) {\n if (highlighted !== null && element.id === highlighted) {\n current = index;\n }\n }\n const virtual = useVirtualRows({\n items: entries,\n render: children,\n pinned: reachableRows(entries.length, current, selected),\n list,\n itemSize,\n measure,\n overscan,\n loading,\n onLoadMore,\n });\n elements.current = virtual.elements;\n // the highlighted row in view, by its offset: after the Item's own scroll (its effect runs\n // first, again once the popup is placed), which reads boxes a popup's opening scale transforms\n const { virtualizer } = virtual;\n const { positioner } = context;\n // biome-ignore lint/correctness/useExhaustiveDependencies: runs again once the popup is placed, after the Item's own scroll\n useLayoutEffect(() => {\n if (current !== undefined) {\n virtualizer.scrollToIndex(current);\n }\n }, [current, virtualizer, positioner]);\n return (\n <ComboboxList\n {...props}\n ref={mergeRefs(setList, ref as Ref<HTMLElement> | undefined)}\n aria-busy={loading ? \"true\" : undefined}\n data-loading={loading ? \"\" : undefined}\n >\n {virtual.rows}\n </ComboboxList>\n );\n}\n","import { ComboboxVirtualList } from \"./combobox-virtual-list.tsx\";\n\n/** spec/virtual-lists.md */\nexport const ComboboxVirtual = {\n List: ComboboxVirtualList,\n};\n"],"mappings":";;;;;;;;;;;;;AA+BA,SAAgB,oBAAqC,EACjD,UACA,UACA,SACA,UACA,UAAU,OACV,YACA,KACA,GAAG,SAC6B;CAChC,MAAM,UAAU,mBAAmB,iBAAiB,sBAAsB;CAC1E,MAAM,CAAC,MAAM,WAAW,WAAwB;CAChD,MAAM,UAAU,QAAQ;CACxB,MAAM,EAAE,UAAU,YAAY,gBAAgB;CAC9C,MAAM,WAAW,cACN,WAAW,KAAK,QAAQ,WAAW,UAAU,WAAW,KAAK,CAAC,GACrE;EAAC;EAAS;EAAU;CAAU,CAClC;CAEA,MAAM,WAAW,uBAAyC,IAAI,IAAI,CAAC;CACnE,IAAI;CACJ,KAAK,MAAM,CAAC,OAAO,YAAY,SAAS,SACpC,IAAI,gBAAgB,QAAQ,QAAQ,OAAO,aACvC,UAAU;CAGlB,MAAM,UAAU,eAAe;EAC3B,OAAO;EACP,QAAQ;EACR,QAAQ,cAAc,QAAQ,QAAQ,SAAS,QAAQ;EACvD;EACA;EACA;EACA;EACA;EACA;CACJ,CAAC;CACD,SAAS,UAAU,QAAQ;CAG3B,MAAM,EAAE,gBAAgB;CACxB,MAAM,EAAE,eAAe;CAEvB,sBAAsB;EAClB,IAAI,YAAY,KAAA,GACZ,YAAY,cAAc,OAAO;CAEzC,GAAG;EAAC;EAAS;EAAa;CAAU,CAAC;CACrC,OACI,oBAAC,cAAD;EACI,GAAI;EACJ,KAAK,UAAU,SAAS,GAAmC;EAC3D,aAAW,UAAU,SAAS,KAAA;EAC9B,gBAAc,UAAU,KAAK,KAAA;EAE5B,UAAA,QAAQ;CACC,CAAA;AAEtB;;;ACtFA,MAAa,kBAAkB,EAC3B,MAAM,oBACV"}
1
+ {"version":3,"file":"combobox-virtual-DCbsgcWu.js","names":[],"sources":["../src/components/combobox-virtual/combobox-virtual-list.tsx","../src/components/combobox-virtual/parts.ts"],"sourcesContent":["import {\n type ReactNode,\n type Ref,\n useLayoutEffect,\n useMemo,\n useRef,\n} from \"react\";\nimport { useElement } from \"../../hooks/use-element.ts\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport {\n reachableRows,\n useVirtualRows,\n type VirtualListProps,\n} from \"../../hooks/use-virtual-rows.ts\";\nimport { mergeRefs } from \"../../utils/merge-refs.ts\";\nimport type { PartProps } from \"../../utils/render-element.tsx\";\nimport { ComboboxContext } from \"../combobox/combobox-context.ts\";\nimport { ComboboxList } from \"../combobox/combobox-list.tsx\";\n\nexport interface ComboboxVirtualListProps<Entry = unknown>\n extends Omit<PartProps<{ empty: boolean }>, \"children\">,\n VirtualListProps {\n /** A `Combobox.Item` for each matching item in view (the Root's `items`, flat). */\n children: (entry: Entry, index: number) => ReactNode;\n}\n\n/**\n * Combobox's List rendering only the matching items in view (spec/virtual-lists.md): the ends, the\n * highlighted item with its neighbours and the selected item stay rendered, so the Input's keys\n * and `aria-activedescendant` behave as with every item rendered.\n */\nexport function ComboboxVirtualList<Entry = unknown>({\n children,\n itemSize,\n measure,\n overscan,\n loading = false,\n onLoadMore,\n ref,\n ...props\n}: ComboboxVirtualListProps<Entry>) {\n const context = useRequiredContext(ComboboxContext, \"ComboboxVirtual.List\");\n const [list, setList] = useElement<HTMLElement>();\n const entries = context.entries as readonly Entry[];\n const { multiple, isSelected, highlighted } = context;\n const selected = useMemo(\n () => (multiple ? -1 : entries.findIndex((entry) => isSelected(entry))),\n [entries, multiple, isSelected],\n );\n // the highlighted option is rendered: its index is the one its element was rendered at\n const elements = useRef<ReadonlyMap<number, HTMLElement>>(new Map());\n let current: number | undefined;\n for (const [index, element] of elements.current) {\n if (highlighted !== null && element.id === highlighted) {\n current = index;\n }\n }\n const virtual = useVirtualRows({\n items: entries,\n render: children,\n pinned: reachableRows(entries.length, current, selected),\n list,\n itemSize,\n measure,\n overscan,\n loading,\n onLoadMore,\n });\n elements.current = virtual.elements;\n // the highlighted row in view, by its offset: after the Item's own scroll (its effect runs\n // first, again once the popup is placed), which reads boxes a popup's opening scale transforms\n const { virtualizer } = virtual;\n const { positioner } = context;\n // biome-ignore lint/correctness/useExhaustiveDependencies: runs again once the popup is placed, after the Item's own scroll\n useLayoutEffect(() => {\n if (current !== undefined) {\n virtualizer.scrollToIndex(current);\n }\n }, [current, virtualizer, positioner]);\n return (\n <ComboboxList\n {...props}\n ref={mergeRefs(setList, ref as Ref<HTMLElement> | undefined)}\n aria-busy={loading ? \"true\" : undefined}\n data-loading={loading ? \"\" : undefined}\n >\n {virtual.rows}\n </ComboboxList>\n );\n}\n","import { ComboboxVirtualList } from \"./combobox-virtual-list.tsx\";\n\n/** spec/virtual-lists.md */\nexport const ComboboxVirtual = {\n List: ComboboxVirtualList,\n};\n"],"mappings":";;;;;;;;;;;;;AA+BA,SAAgB,oBAAqC,EACjD,UACA,UACA,SACA,UACA,UAAU,OACV,YACA,KACA,GAAG,SAC6B;CAChC,MAAM,UAAU,mBAAmB,iBAAiB,sBAAsB;CAC1E,MAAM,CAAC,MAAM,WAAW,WAAwB;CAChD,MAAM,UAAU,QAAQ;CACxB,MAAM,EAAE,UAAU,YAAY,gBAAgB;CAC9C,MAAM,WAAW,cACN,WAAW,KAAK,QAAQ,WAAW,UAAU,WAAW,KAAK,CAAC,GACrE;EAAC;EAAS;EAAU;CAAU,CAClC;CAEA,MAAM,WAAW,uBAAyC,IAAI,IAAI,CAAC;CACnE,IAAI;CACJ,KAAK,MAAM,CAAC,OAAO,YAAY,SAAS,SACpC,IAAI,gBAAgB,QAAQ,QAAQ,OAAO,aACvC,UAAU;CAGlB,MAAM,UAAU,eAAe;EAC3B,OAAO;EACP,QAAQ;EACR,QAAQ,cAAc,QAAQ,QAAQ,SAAS,QAAQ;EACvD;EACA;EACA;EACA;EACA;EACA;CACJ,CAAC;CACD,SAAS,UAAU,QAAQ;CAG3B,MAAM,EAAE,gBAAgB;CACxB,MAAM,EAAE,eAAe;CAEvB,sBAAsB;EAClB,IAAI,YAAY,KAAA,GACZ,YAAY,cAAc,OAAO;CAEzC,GAAG;EAAC;EAAS;EAAa;CAAU,CAAC;CACrC,OACI,oBAAC,cAAD;EACI,GAAI;EACJ,KAAK,UAAU,SAAS,GAAmC;EAC3D,aAAW,UAAU,SAAS,KAAA;EAC9B,gBAAc,UAAU,KAAK,KAAA;EAE5B,UAAA,QAAQ;CACC,CAAA;AAEtB;;;ACtFA,MAAa,kBAAkB,EAC3B,MAAM,oBACV"}
@@ -1,4 +1,4 @@
1
1
  import { t as VirtualListProps } from "./use-virtual-rows-BQFqR0_e.js";
2
- import { t as Combobox } from "./parts-B2E7RN77.js";
3
- import { n as ComboboxVirtualListProps, t as ComboboxVirtual } from "./index-DQ68aV2P.js";
2
+ import { t as Combobox } from "./parts-osxHWzAd.js";
3
+ import { n as ComboboxVirtualListProps, t as ComboboxVirtual } from "./index-BiEoqfAh.js";
4
4
  export { Combobox, ComboboxVirtual, type ComboboxVirtualListProps, type VirtualListProps };
@@ -1,3 +1,3 @@
1
- import { t as Combobox } from "./parts-VT0Ohb06.js";
2
- import { t as ComboboxVirtual } from "./combobox-virtual-BI-l10BE.js";
1
+ import { t as Combobox } from "./parts-Dpfqew1M.js";
2
+ import { t as ComboboxVirtual } from "./combobox-virtual-DCbsgcWu.js";
3
3
  export { Combobox, ComboboxVirtual };
@@ -3,7 +3,7 @@ import { t as OverlayRootProps } from "./use-overlay-root-BDO5E_0S.js";
3
3
  import { t as PositionerProps } from "./use-positioner-BpxM4U5Y.js";
4
4
  import { a as OverlayActions, i as OpenChangeDetails, n as ChangeReason, t as ChangeDetails } from "./change-details-CPSkPCNw.js";
5
5
  import { n as RenderProp } from "./render-element-Pwuv2wsL.js";
6
- import { a as ComboboxRootSingleProps, c as ComboboxPortalProps, d as ComboboxItemProps, f as ComboboxItemState, i as ComboboxRootProps, l as ComboboxListProps, n as ComboboxValueProps, o as ComboboxPositionerProps, r as ComboboxRootMultipleProps, s as ComboboxPositionerState, t as Combobox, u as ComboboxItemIndicatorProps } from "./parts-B2E7RN77.js";
6
+ import { a as ComboboxRootSingleProps, c as ComboboxPortalProps, d as ComboboxItemProps, f as ComboboxItemState, i as ComboboxRootProps, l as ComboboxListProps, n as ComboboxValueProps, o as ComboboxPositionerProps, r as ComboboxRootMultipleProps, s as ComboboxPositionerState, t as Combobox, u as ComboboxItemIndicatorProps } from "./parts-osxHWzAd.js";
7
7
  import { ItemEquality, ItemFilter, ItemGroup } from "@fragiola/primitives/collection";
8
8
  import { Align, Side } from "@fragiola/primitives/positioning";
9
9
  export { type Align, type ChangeDetails, type ChangeReason, Combobox, type ComboboxItemIndicatorProps, type ComboboxItemProps, type ComboboxItemState, type ComboboxListProps, type ComboboxPortalProps, type ComboboxPositionerProps, type ComboboxPositionerState, type ComboboxRootMultipleProps, type ComboboxRootProps, type ComboboxRootSingleProps, type ComboboxValueProps, type ItemEquality, type ItemFilter, type ItemGroup, type OpenChangeDetails, type OverlayActions, type OverlayPortalProps, type OverlayRootProps, type PositionerProps, type RenderProp, type Side };
package/dist/combobox.js CHANGED
@@ -1 +1 @@
1
- export { t as Combobox } from "./parts-VT0Ohb06.js";
1
+ export { t as Combobox } from "./parts-Dpfqew1M.js";
@@ -1,5 +1,5 @@
1
1
  import { t as VirtualListProps } from "./use-virtual-rows-BQFqR0_e.js";
2
- import "./parts-B2E7RN77.js";
2
+ import "./parts-osxHWzAd.js";
3
3
  import { t as PartProps } from "./render-element-Pwuv2wsL.js";
4
4
  import { ReactNode } from "react";
5
5
  interface ComboboxVirtualListProps<Entry = unknown> extends Omit<PartProps<{
@@ -35,6 +35,11 @@ interface NumberFieldRootProps extends PartProps<NumberFieldState> {
35
35
  value?: number | null;
36
36
  defaultValue?: number | null;
37
37
  onValueChange?: (value: number | null, details: ChangeDetails) => void;
38
+ /**
39
+ * The value once a change is complete: on blur after typing, at a key or wheel step, at the
40
+ * release of a button press or a scrub (spec/number-field.md, "Committing").
41
+ */
42
+ onValueCommitted?: (value: number | null, details: ChangeDetails) => void;
38
43
  min?: number;
39
44
  max?: number;
40
45
  /** The amount of a step (default `1`). */
@@ -64,7 +69,7 @@ interface NumberFieldRootProps extends PartProps<NumberFieldState> {
64
69
  * Holds a NumberField's value, its text and its hidden form input (spec/number-field.md, the APG
65
70
  * spinbutton).
66
71
  */
67
- declare function NumberFieldRoot({ value: valueProp, defaultValue, onValueChange, min, max, step, smallStep, largeStep, snapOnStep, clampOnBlur, format, locale, allowWheelScrub, required, readOnly, disabled: disabledProp, name, id: idProp, children, ...props }: NumberFieldRootProps): import("react").JSX.Element;
72
+ declare function NumberFieldRoot({ value: valueProp, defaultValue, onValueChange, onValueCommitted, min, max, step, smallStep, largeStep, snapOnStep, clampOnBlur, format, locale, allowWheelScrub, required, readOnly, disabled: disabledProp, name, id: idProp, children, ...props }: NumberFieldRootProps): import("react").JSX.Element;
68
73
  interface NumberFieldScrubAreaProps extends PartProps<NumberFieldState> {
69
74
  /** The axis the pointer scrubs along (default `"horizontal"`). */
70
75
  direction?: "horizontal" | "vertical";
package/dist/index.d.ts CHANGED
@@ -39,9 +39,9 @@ import { c as ColorSliderThumbProps, d as ColorSliderLabelProps, f as ColorSlide
39
39
  import { c as ColorSwatchState, o as ColorSwatch, s as ColorSwatchProps } from "./index-Cjl7RT2o.js";
40
40
  import { c as ColorSwatchPickerRootState, l as ColorSwatchPickerItemProps, o as ColorSwatchPicker, s as ColorSwatchPickerRootProps, u as ColorSwatchPickerItemState } from "./index-CsXJJ0G8.js";
41
41
  import { c as ColorWheelState, o as ColorWheel, s as ColorWheelRootProps } from "./index-D1-zqp2Q.js";
42
- import { a as ComboboxRootSingleProps, c as ComboboxPortalProps, d as ComboboxItemProps, f as ComboboxItemState, i as ComboboxRootProps, l as ComboboxListProps, n as ComboboxValueProps, o as ComboboxPositionerProps, r as ComboboxRootMultipleProps, s as ComboboxPositionerState, t as Combobox, u as ComboboxItemIndicatorProps } from "./parts-B2E7RN77.js";
42
+ import { a as ComboboxRootSingleProps, c as ComboboxPortalProps, d as ComboboxItemProps, f as ComboboxItemState, i as ComboboxRootProps, l as ComboboxListProps, n as ComboboxValueProps, o as ComboboxPositionerProps, r as ComboboxRootMultipleProps, s as ComboboxPositionerState, t as Combobox, u as ComboboxItemIndicatorProps } from "./parts-osxHWzAd.js";
43
43
  import { ItemEquality } from "./combobox.js";
44
- import { n as ComboboxVirtualListProps, t as ComboboxVirtual } from "./index-DQ68aV2P.js";
44
+ import { n as ComboboxVirtualListProps, t as ComboboxVirtual } from "./index-BiEoqfAh.js";
45
45
  import { a as CommandListState, i as CommandRootState, n as CommandSeparatorProps, o as CommandItemProps, r as CommandRootProps, s as CommandItemState, t as Command } from "./parts-DoQQN1Io.js";
46
46
  import { CommandEntry, CommandFilter } from "./command.js";
47
47
  import { n as CommandVirtual, r as CommandVirtualListProps } from "./index-CzB9dDcM.js";
@@ -86,7 +86,7 @@ import { a as MonthRangeCalendar, o as MonthRangeCalendarRootProps } from "./ind
86
86
  import { a as MonthRangePicker, o as MonthRangePickerRootProps } from "./index-DRow1231.js";
87
87
  import { a as MultipleCalendarRootProps, i as MultipleCalendar } from "./index-OmXQjsNi.js";
88
88
  import { a as NavigationMenuTriggerProps, c as NavigationMenuRootState, d as NavigationMenuPortalProps, f as NavigationMenuPopupState, g as NavigationMenuContentState, h as NavigationMenuOrientation, i as NavigationMenu, l as NavigationMenuPositionerProps, m as NavigationMenuItemProps, o as NavigationMenuTriggerState, p as NavigationMenuLinkProps, s as NavigationMenuRootProps, t as ActivationDirection, u as NavigationMenuPositionerState } from "./index-DHwyHITu.js";
89
- import { a as NumberFieldInputProps, c as NumberFieldDecrementProps, i as NumberFieldRootProps, l as NumberFieldState, n as NumberFieldScrubAreaCursorProps, o as NumberFieldIncrementProps, r as NumberFieldScrubAreaProps, s as NumberFieldGroupProps, t as NumberField } from "./index-CcwKZWPY.js";
89
+ import { a as NumberFieldInputProps, c as NumberFieldDecrementProps, i as NumberFieldRootProps, l as NumberFieldState, n as NumberFieldScrubAreaCursorProps, o as NumberFieldIncrementProps, r as NumberFieldScrubAreaProps, s as NumberFieldGroupProps, t as NumberField } from "./index-Dy7NUYXe.js";
90
90
  import { a as OTPFieldInputState, i as OTPFieldInputProps, n as OTPField, o as OTPFieldState, r as OTPFieldRootProps, t as OtpValidationType } from "./index-t4CBZJDG.js";
91
91
  import { a as PaginationPreviousProps, c as PaginationItemProps, d as PaginationEllipsisProps, f as PaginationControlProps, i as PaginationRootProps, l as PaginationItemState, m as PaginationState, n as Pagination, o as PaginationNextProps, p as PaginationControlState, r as PaginationRenderProps, s as PaginationLastProps, t as PaginationRangeItem, u as PaginationFirstProps } from "./index-BdxleDV0.js";
92
92
  import { a as PasswordInputState, i as PasswordInputInputProps, n as PasswordInputVisibilityTriggerProps, r as PasswordInputRootProps, t as PasswordInput } from "./index-wv0Lafz4.js";
package/dist/index.js CHANGED
@@ -27,9 +27,9 @@ import { t as ColorSlider } from "./color-slider-Bw940FJr.js";
27
27
  import { t as ColorSwatch } from "./color-swatch-C9ws0xF4.js";
28
28
  import { t as ColorSwatchPicker } from "./color-swatch-picker-CnmTr1SY.js";
29
29
  import { t as ColorWheel } from "./color-wheel--n8w5fIJ.js";
30
- import { t as Combobox } from "./parts-VT0Ohb06.js";
30
+ import { t as Combobox } from "./parts-Dpfqew1M.js";
31
31
  import "./combobox.js";
32
- import { t as ComboboxVirtual } from "./combobox-virtual-BI-l10BE.js";
32
+ import { t as ComboboxVirtual } from "./combobox-virtual-DCbsgcWu.js";
33
33
  import { t as Command } from "./parts-XRa0gd47.js";
34
34
  import "./command.js";
35
35
  import { t as CommandVirtual } from "./command-virtual-CxNLxsih.js";
@@ -65,7 +65,7 @@ import { t as MonthRangeCalendar } from "./month-range-calendar-BmnWB6OD.js";
65
65
  import { t as MonthRangePicker } from "./month-range-picker-TfMtxi2X.js";
66
66
  import { t as MultipleCalendar } from "./multiple-calendar-EBsuTzYQ.js";
67
67
  import { t as NavigationMenu } from "./navigation-menu-82shSjXS.js";
68
- import { t as NumberField } from "./number-field-BUNkL15K.js";
68
+ import { t as NumberField } from "./number-field-ChJoV38v.js";
69
69
  import { t as OTPField } from "./otp-field-BMKBhv0O.js";
70
70
  import { t as Pagination } from "./pagination-CMWaQSpr.js";
71
71
  import { t as PasswordInput } from "./password-input-BQAySlmc.js";
@@ -32,11 +32,14 @@ function useStepperButton(context, direction) {
32
32
  latest.current = context;
33
33
  useEffect(() => {
34
34
  if (element === null) return;
35
- return watchAutoRepeat(element, { onStep: (event) => {
36
- const current = latest.current;
37
- const amount = current.amount(event);
38
- return current.stepBy(direction * amount, direction > 0 ? "increment-press" : "decrement-press", event);
39
- } });
35
+ return watchAutoRepeat(element, {
36
+ onStep: (event) => {
37
+ const current = latest.current;
38
+ const amount = current.amount(event);
39
+ return current.stepBy(direction * amount, direction > 0 ? "increment-press" : "decrement-press", event);
40
+ },
41
+ onEnd: (event) => latest.current.commit(event)
42
+ });
40
43
  }, [element, direction]);
41
44
  const { value, min, max } = context;
42
45
  const atBound = value !== null && (direction > 0 ? max !== void 0 && value >= max : min !== void 0 && value <= min);
@@ -183,7 +186,7 @@ const NOOP = () => {};
183
186
  * Holds a NumberField's value, its text and its hidden form input (spec/number-field.md, the APG
184
187
  * spinbutton).
185
188
  */
186
- function NumberFieldRoot({ value: valueProp, defaultValue = null, onValueChange, min, max, step = 1, smallStep = .1, largeStep = 10, snapOnStep = false, clampOnBlur = true, format, locale, allowWheelScrub = false, required = false, readOnly = false, disabled: disabledProp = false, name, id: idProp, children, ...props }) {
189
+ function NumberFieldRoot({ value: valueProp, defaultValue = null, onValueChange, onValueCommitted, min, max, step = 1, smallStep = .1, largeStep = 10, snapOnStep = false, clampOnBlur = true, format, locale, allowWheelScrub = false, required = false, readOnly = false, disabled: disabledProp = false, name, id: idProp, children, ...props }) {
187
190
  const generatedId = useId();
188
191
  const inputId = idProp ?? generatedId;
189
192
  const [value, setOwnValue] = useControllableState(valueProp, defaultValue, onValueChange);
@@ -208,6 +211,7 @@ function NumberFieldRoot({ value: valueProp, defaultValue = null, onValueChange,
208
211
  const inputValue = typed ?? formattedValue;
209
212
  const current = useRef(value);
210
213
  current.current = value;
214
+ const pending = useRef(null);
211
215
  const latest = useRef({
212
216
  value,
213
217
  typed,
@@ -224,6 +228,7 @@ function NumberFieldRoot({ value: valueProp, defaultValue = null, onValueChange,
224
228
  readOnly,
225
229
  defaultValue,
226
230
  setOwnValue,
231
+ onValueCommitted,
227
232
  reset: field.reset
228
233
  });
229
234
  latest.current = {
@@ -242,16 +247,31 @@ function NumberFieldRoot({ value: valueProp, defaultValue = null, onValueChange,
242
247
  readOnly,
243
248
  defaultValue,
244
249
  setOwnValue,
250
+ onValueCommitted,
245
251
  reset: field.reset
246
252
  };
247
253
  const actions = useMemo(() => {
248
254
  const setValue = (next, details) => {
255
+ if (details.reason === "none") pending.current = null;
256
+ else if (!Object.is(next, current.current)) pending.current = details.reason;
249
257
  current.current = next;
250
258
  latest.current.setOwnValue(next, details);
251
259
  setTimeout(() => {
252
260
  current.current = latest.current.value;
253
261
  });
254
262
  };
263
+ /** Reports the value when a change is pending (spec/number-field.md, "Committing"). */
264
+ const commit = (event) => {
265
+ const reason = pending.current;
266
+ if (reason === null) return;
267
+ pending.current = null;
268
+ latest.current.onValueCommitted?.(current.current, {
269
+ reason,
270
+ event
271
+ });
272
+ };
273
+ /** A key or the wheel commits its step at once. */
274
+ const commitsAtOnce = (reason) => reason === "keyboard" || reason === "wheel";
255
275
  /** The value a step starts from: the typed text when it reads as a number. */
256
276
  const base = () => {
257
277
  const { typed: text, locale: lang, format: options } = latest.current;
@@ -264,6 +284,7 @@ function NumberFieldRoot({ value: valueProp, defaultValue = null, onValueChange,
264
284
  };
265
285
  return {
266
286
  setValue,
287
+ commit,
267
288
  amount: (event) => {
268
289
  const { step: one, smallStep: small, largeStep: large } = latest.current;
269
290
  return event?.altKey ? small : event?.shiftKey ? large : one;
@@ -282,6 +303,7 @@ function NumberFieldRoot({ value: valueProp, defaultValue = null, onValueChange,
282
303
  reason,
283
304
  event
284
305
  });
306
+ if (commitsAtOnce(reason)) commit(event);
285
307
  const bound = amount > 0 ? state.max : state.min;
286
308
  return bound === void 0 || next !== bound;
287
309
  },
@@ -293,6 +315,7 @@ function NumberFieldRoot({ value: valueProp, defaultValue = null, onValueChange,
293
315
  reason,
294
316
  event
295
317
  });
318
+ if (commitsAtOnce(reason)) commit(event);
296
319
  },
297
320
  onInputText: (text, event) => {
298
321
  const state = latest.current;
@@ -327,6 +350,7 @@ function NumberFieldRoot({ value: valueProp, defaultValue = null, onValueChange,
327
350
  reason: "input-blur",
328
351
  event
329
352
  });
353
+ commit(event);
330
354
  }
331
355
  };
332
356
  }, []);
@@ -375,6 +399,7 @@ function NumberFieldRoot({ value: valueProp, defaultValue = null, onValueChange,
375
399
  amount: actions.amount,
376
400
  stepBy: actions.stepBy,
377
401
  stepTo: actions.stepTo,
402
+ commit: actions.commit,
378
403
  onInputText: actions.onInputText,
379
404
  onInputBlur: actions.onInputBlur,
380
405
  setInputElement,
@@ -437,7 +462,10 @@ function NumberFieldScrubArea({ direction = "horizontal", pixelSensitivity = 2,
437
462
  const amount = current.amount(event);
438
463
  current.stepBy(steps > 0 ? amount : -amount, "scrub", event, Math.abs(steps));
439
464
  },
440
- onEnd: () => latest.current.setScrubbing(false),
465
+ onEnd: (event) => {
466
+ latest.current.setScrubbing(false);
467
+ latest.current.commit(event);
468
+ },
441
469
  onCursor: (point) => latest.current.setCursor(point)
442
470
  });
443
471
  }, [
@@ -488,4 +516,4 @@ const NumberField = {
488
516
  };
489
517
  export { NumberField as t };
490
518
 
491
- //# sourceMappingURL=number-field-BUNkL15K.js.map
519
+ //# sourceMappingURL=number-field-ChJoV38v.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number-field-ChJoV38v.js","names":[],"sources":["../src/components/number-field/number-field-context.ts","../src/components/number-field/use-stepper-button.ts","../src/components/number-field/number-field-decrement.tsx","../src/components/number-field/number-field-group.tsx","../src/components/number-field/number-field-increment.tsx","../src/components/number-field/number-field-input.tsx","../src/components/number-field/number-field-root.tsx","../src/components/number-field/number-field-scrub-area.tsx","../src/components/number-field/number-field-scrub-area-cursor.tsx","../src/components/number-field/parts.ts"],"sourcesContent":["import type { ScrubPoint } from \"@fragiola/primitives/number\";\nimport { createContext } from \"react\";\nimport type { FieldControlBinding } from \"../../hooks/use-field-control.ts\";\nimport type { ChangeReason } from \"../../utils/change-details.ts\";\n\n/** The state every part renders with (spec/number-field.md, \"State attributes and ARIA\"). */\nexport interface NumberFieldState {\n /** The value: a number, or `null` while empty. */\n value: number | null;\n /** The Input's text. */\n inputValue: string;\n disabled: boolean;\n readOnly: boolean;\n required: boolean;\n scrubbing: boolean;\n}\n\nexport interface NumberFieldContextValue extends NumberFieldState {\n inputId: string;\n min: number | undefined;\n max: number | undefined;\n locale: string | undefined;\n format: Intl.NumberFormatOptions | undefined;\n /** The value as `format` writes it (`aria-valuetext`), `\"\"` while empty. */\n formattedValue: string;\n allowWheelScrub: boolean;\n field: FieldControlBinding;\n /** The state attributes and the field's, for every part. */\n attributes: Record<`data-${string}`, string>;\n /** The amount of one step for an event's modifier keys (Alt: small, Shift: large). */\n amount: (\n event: { altKey?: boolean; shiftKey?: boolean } | undefined,\n ) => number;\n /**\n * Steps `times` times by `amount` (negative: down) from the value (or the typed text): returns\n * whether another step that way could still change it (a bound not reached).\n */\n stepBy: (\n amount: number,\n reason: ChangeReason,\n event: Event | undefined,\n times?: number,\n ) => boolean;\n /** Sets the value, as a step does (Home and End set a bound). */\n stepTo: (\n value: number,\n reason: ChangeReason,\n event: Event | undefined,\n ) => void;\n /** A button press or a scrub ended: reports a pending change (onValueCommitted). */\n commit: (event: Event | undefined) => void;\n /** The Input's text changed. */\n onInputText: (text: string, event: Event) => boolean;\n /** The Input lost focus. */\n onInputBlur: (event: Event) => void;\n setInputElement: (element: HTMLInputElement | null) => void;\n setScrubbing: (scrubbing: boolean) => void;\n cursor: ScrubPoint | null;\n setCursor: (point: ScrubPoint | null) => void;\n}\n\nexport const NumberFieldContext = createContext<NumberFieldContextValue | null>(\n null,\n);\n\n/** The state the parts render with. */\nexport function numberFieldState(\n context: NumberFieldContextValue,\n): NumberFieldState {\n return {\n value: context.value,\n inputValue: context.inputValue,\n disabled: context.disabled,\n readOnly: context.readOnly,\n required: context.required,\n scrubbing: context.scrubbing,\n };\n}\n","import { watchAutoRepeat } from \"@fragiola/primitives/number\";\nimport { useEffect, useRef, useState } from \"react\";\nimport type { NumberFieldContextValue } from \"./number-field-context.ts\";\n\n/**\n * An Increment's or a Decrement's press and hold (spec/number-field.md, \"Pointer\"), and whether\n * it is disabled: the field disabled or read-only, or its step would change nothing.\n */\nexport function useStepperButton(\n context: NumberFieldContextValue,\n direction: 1 | -1,\n) {\n const [element, setElement] = useState<HTMLElement | null>(null);\n const latest = useRef(context);\n latest.current = context;\n useEffect(() => {\n if (element === null) {\n return undefined;\n }\n return watchAutoRepeat(element, {\n onStep: (event) => {\n const current = latest.current;\n const amount = current.amount(event as MouseEvent);\n return current.stepBy(\n direction * amount,\n direction > 0 ? \"increment-press\" : \"decrement-press\",\n event,\n );\n },\n onEnd: (event) => latest.current.commit(event),\n });\n }, [element, direction]);\n const { value, min, max } = context;\n const atBound =\n value !== null &&\n (direction > 0\n ? max !== undefined && value >= max\n : min !== undefined && value <= min);\n return {\n ref: setElement,\n disabled: context.disabled || context.readOnly || atBound,\n };\n}\n","import { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport {\n NumberFieldContext,\n type NumberFieldState,\n numberFieldState,\n} from \"./number-field-context.ts\";\nimport { useStepperButton } from \"./use-stepper-button.ts\";\n\nexport type NumberFieldDecrementProps = PartProps<NumberFieldState>;\n\n/**\n * Steps the value down, once or held (spec/number-field.md, \"Pointer\"); out of the tab order, its\n * name the consumer's.\n */\nexport function NumberFieldDecrement(props: NumberFieldDecrementProps) {\n const context = useRequiredContext(\n NumberFieldContext,\n \"NumberField.Decrement\",\n );\n const button = useStepperButton(context, -1);\n return renderElement(\n \"button\",\n props,\n numberFieldState(context),\n {\n type: \"button\",\n tabIndex: -1,\n disabled: button.disabled,\n \"aria-controls\": context.inputId,\n \"data-primitives-part\": \"number-field-decrement\",\n ...context.attributes,\n },\n button.ref,\n );\n}\n","import { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport {\n NumberFieldContext,\n type NumberFieldState,\n numberFieldState,\n} from \"./number-field-context.ts\";\n\nexport type NumberFieldGroupProps = PartProps<NumberFieldState>;\n\n/** Groups the Input with its buttons (`role=\"group\"`, spec/number-field.md). */\nexport function NumberFieldGroup(props: NumberFieldGroupProps) {\n const context = useRequiredContext(NumberFieldContext, \"NumberField.Group\");\n return renderElement(\"div\", props, numberFieldState(context), {\n role: \"group\",\n \"data-primitives-part\": \"number-field-group\",\n ...context.attributes,\n });\n}\n","import { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport {\n NumberFieldContext,\n type NumberFieldState,\n numberFieldState,\n} from \"./number-field-context.ts\";\nimport { useStepperButton } from \"./use-stepper-button.ts\";\n\nexport type NumberFieldIncrementProps = PartProps<NumberFieldState>;\n\n/**\n * Steps the value up, once or held (spec/number-field.md, \"Pointer\"); out of the tab order, its\n * name the consumer's.\n */\nexport function NumberFieldIncrement(props: NumberFieldIncrementProps) {\n const context = useRequiredContext(\n NumberFieldContext,\n \"NumberField.Increment\",\n );\n const button = useStepperButton(context, 1);\n return renderElement(\n \"button\",\n props,\n numberFieldState(context),\n {\n type: \"button\",\n tabIndex: -1,\n disabled: button.disabled,\n \"aria-controls\": context.inputId,\n \"data-primitives-part\": \"number-field-increment\",\n ...context.attributes,\n },\n button.ref,\n );\n}\n","import {\n type ChangeEvent,\n type FocusEvent,\n type KeyboardEvent,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport {\n NumberFieldContext,\n type NumberFieldState,\n numberFieldState,\n} from \"./number-field-context.ts\";\n\nexport type NumberFieldInputProps = PartProps<NumberFieldState>;\n\n/** The `spinbutton`: a text input with the formatted value (spec/number-field.md, the APG). */\nexport function NumberFieldInput(props: NumberFieldInputProps) {\n const context = useRequiredContext(NumberFieldContext, \"NumberField.Input\");\n const {\n value,\n min,\n max,\n disabled,\n readOnly,\n required,\n field,\n setInputElement,\n allowWheelScrub,\n } = context;\n const latest = useRef(context);\n latest.current = context;\n const element = useRef<HTMLInputElement | null>(null);\n const ref = useCallback(\n (node: HTMLElement | null) => {\n element.current = node as HTMLInputElement | null;\n setInputElement(node as HTMLInputElement | null);\n },\n [setInputElement],\n );\n\n // the wheel over the focused Input steps it, and the page does not scroll (a non-passive\n // listener, which React's `onWheel` cannot be)\n useEffect(() => {\n const input = element.current;\n if (input === null || !allowWheelScrub) {\n return undefined;\n }\n const onWheel = (event: WheelEvent) => {\n if (\n input.ownerDocument.activeElement !== input ||\n event.deltaY === 0\n ) {\n return;\n }\n const current = latest.current;\n if (current.disabled || current.readOnly) {\n return;\n }\n event.preventDefault();\n const amount = current.amount(event);\n current.stepBy(event.deltaY < 0 ? amount : -amount, \"wheel\", event);\n };\n input.addEventListener(\"wheel\", onWheel, { passive: false });\n return () => input.removeEventListener(\"wheel\", onWheel);\n }, [allowWheelScrub]);\n\n const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n const current = latest.current;\n if (current.disabled || current.readOnly) {\n return;\n }\n const native = event.nativeEvent;\n const amount = current.amount(native);\n switch (event.key) {\n case \"ArrowUp\":\n current.stepBy(amount, \"keyboard\", native);\n break;\n case \"ArrowDown\":\n current.stepBy(-amount, \"keyboard\", native);\n break;\n case \"PageUp\":\n current.stepBy(\n current.amount({ shiftKey: true }),\n \"keyboard\",\n native,\n );\n break;\n case \"PageDown\":\n current.stepBy(\n -current.amount({ shiftKey: true }),\n \"keyboard\",\n native,\n );\n break;\n case \"Home\":\n if (current.min === undefined) {\n return;\n }\n current.stepTo(current.min, \"keyboard\", native);\n break;\n case \"End\":\n if (current.max === undefined) {\n return;\n }\n current.stepTo(current.max, \"keyboard\", native);\n break;\n default:\n return;\n }\n event.preventDefault();\n };\n\n const integer =\n context.format?.maximumFractionDigits === 0 &&\n min !== undefined &&\n min >= 0;\n return renderElement(\n \"input\",\n props,\n numberFieldState(context),\n {\n id: context.inputId,\n type: \"text\",\n role: \"spinbutton\",\n inputMode: integer ? \"numeric\" : \"decimal\",\n autoComplete: \"off\",\n autoCorrect: \"off\",\n spellCheck: \"false\",\n value: context.inputValue,\n disabled,\n readOnly,\n \"aria-valuenow\": value ?? undefined,\n \"aria-valuemin\": min,\n \"aria-valuemax\": max,\n \"aria-valuetext\":\n value === null ? undefined : context.formattedValue,\n \"aria-required\": required ? \"true\" : undefined,\n \"aria-readonly\": readOnly ? \"true\" : undefined,\n ...field.aria,\n \"data-primitives-part\": \"number-field-input\",\n ...context.attributes,\n onChange: (event: ChangeEvent<HTMLInputElement>) => {\n latest.current.onInputText(\n event.currentTarget.value,\n event.nativeEvent,\n );\n },\n onKeyDown,\n onFocus: field.onFocus,\n onBlur: (event: FocusEvent<HTMLInputElement>) => {\n latest.current.onInputBlur(event.nativeEvent);\n field.onBlur();\n },\n },\n ref,\n );\n}\n","import {\n bridgeForm,\n VISUALLY_HIDDEN_INPUT_STYLE,\n} from \"@fragiola/primitives/form\";\nimport {\n clampNumber,\n formatNumber,\n isNumberText,\n parseNumber,\n type ScrubPoint,\n stepNumber,\n} from \"@fragiola/primitives/number\";\nimport { useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { useControllableState } from \"../../hooks/use-controllable-state.ts\";\nimport { useFieldControl } from \"../../hooks/use-field-control.ts\";\nimport type {\n ChangeDetails,\n ChangeReason,\n} from \"../../utils/change-details.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport {\n NumberFieldContext,\n type NumberFieldContextValue,\n type NumberFieldState,\n} from \"./number-field-context.ts\";\n\nexport interface NumberFieldRootProps extends PartProps<NumberFieldState> {\n /** A number, or `null` while empty. */\n value?: number | null;\n defaultValue?: number | null;\n onValueChange?: (value: number | null, details: ChangeDetails) => void;\n /**\n * The value once a change is complete: on blur after typing, at a key or wheel step, at the\n * release of a button press or a scrub (spec/number-field.md, \"Committing\").\n */\n onValueCommitted?: (value: number | null, details: ChangeDetails) => void;\n min?: number;\n max?: number;\n /** The amount of a step (default `1`). */\n step?: number;\n /** The amount of a step with Alt (default `0.1`). */\n smallStep?: number;\n /** The amount of a step with Shift, Page Up and Page Down (default `10`). */\n largeStep?: number;\n /** A step from a value off the grid goes to the grid's next point. */\n snapOnStep?: boolean;\n /** A typed value outside `[min, max]` is clamped on blur (default `true`). */\n clampOnBlur?: boolean;\n /** How the Input writes the value; default: the plain number in the locale. */\n format?: Intl.NumberFormatOptions;\n /** The locale of the format and the parsing (BCP 47; default: the runtime's). */\n locale?: string;\n /** The mouse wheel steps the value over the focused Input. */\n allowWheelScrub?: boolean;\n required?: boolean;\n readOnly?: boolean;\n disabled?: boolean;\n name?: string;\n /** The Input's `id`. */\n id?: string;\n}\n\nconst NOOP = () => {};\n\n/**\n * Holds a NumberField's value, its text and its hidden form input (spec/number-field.md, the APG\n * spinbutton).\n */\nexport function NumberFieldRoot({\n value: valueProp,\n defaultValue = null,\n onValueChange,\n onValueCommitted,\n min,\n max,\n step = 1,\n smallStep = 0.1,\n largeStep = 10,\n snapOnStep = false,\n clampOnBlur = true,\n format,\n locale,\n allowWheelScrub = false,\n required = false,\n readOnly = false,\n disabled: disabledProp = false,\n name,\n id: idProp,\n children,\n ...props\n}: NumberFieldRootProps) {\n const generatedId = useId();\n const inputId = idProp ?? generatedId;\n const [value, setOwnValue] = useControllableState(\n valueProp,\n defaultValue,\n onValueChange,\n );\n // the text the user typed, until the blur formats it (`null`: the formatted value)\n const [typed, setTyped] = useState<string | null>(null);\n const [scrubbing, setScrubbing] = useState(false);\n const [cursor, setCursor] = useState<ScrubPoint | null>(null);\n const [input, setInputElement] = useState<HTMLInputElement | null>(null);\n const hidden = useRef<HTMLInputElement>(null);\n const field = useFieldControl({\n id: inputId,\n labelable: true,\n value,\n filled: value !== null,\n input: () => hidden.current,\n focusTarget: () => input,\n });\n const disabled = disabledProp || field.disabled;\n const formattedValue = formatNumber(value, { locale, format });\n const inputValue = typed ?? formattedValue;\n\n // the value as of the last change, so a held button's steps never read a stale render\n const current = useRef(value);\n current.current = value;\n // the reason of the last change not committed yet\n const pending = useRef<ChangeReason | null>(null);\n const latest = useRef({\n value,\n typed,\n min,\n max,\n step,\n smallStep,\n largeStep,\n snapOnStep,\n clampOnBlur,\n format,\n locale,\n disabled,\n readOnly,\n defaultValue,\n setOwnValue,\n onValueCommitted,\n reset: field.reset,\n });\n latest.current = {\n value,\n typed,\n min,\n max,\n step,\n smallStep,\n largeStep,\n snapOnStep,\n clampOnBlur,\n format,\n locale,\n disabled,\n readOnly,\n defaultValue,\n setOwnValue,\n onValueCommitted,\n reset: field.reset,\n };\n\n const actions = useMemo(() => {\n const setValue = (next: number | null, details: ChangeDetails) => {\n if (details.reason === \"none\") {\n pending.current = null;\n } else if (!Object.is(next, current.current)) {\n pending.current = details.reason;\n }\n current.current = next;\n latest.current.setOwnValue(next, details);\n // an override for the steps of this task only: a consumer that refused the value\n // renders nothing, and the next task steps from the value it kept\n setTimeout(() => {\n current.current = latest.current.value;\n });\n };\n /** Reports the value when a change is pending (spec/number-field.md, \"Committing\"). */\n const commit = (event: Event | undefined) => {\n const reason = pending.current;\n if (reason === null) {\n return;\n }\n pending.current = null;\n latest.current.onValueCommitted?.(current.current, {\n reason,\n event,\n });\n };\n /** A key or the wheel commits its step at once. */\n const commitsAtOnce = (reason: ChangeReason) =>\n reason === \"keyboard\" || reason === \"wheel\";\n /** The value a step starts from: the typed text when it reads as a number. */\n const base = (): number | null => {\n const {\n typed: text,\n locale: lang,\n format: options,\n } = latest.current;\n if (text === null) {\n return current.current;\n }\n const parsed = parseNumber(text, { locale: lang, format: options });\n return parsed === null || Number.isNaN(parsed)\n ? current.current\n : parsed;\n };\n return {\n setValue,\n commit,\n amount: (\n event: { altKey?: boolean; shiftKey?: boolean } | undefined,\n ) => {\n const {\n step: one,\n smallStep: small,\n largeStep: large,\n } = latest.current;\n return event?.altKey ? small : event?.shiftKey ? large : one;\n },\n stepBy: (\n amount: number,\n reason: ChangeReason,\n event: Event | undefined,\n times = 1,\n ) => {\n const state = latest.current;\n if (state.disabled || state.readOnly) {\n return false;\n }\n let next = base();\n for (let index = 0; index < times; index += 1) {\n next = stepNumber(next, amount, {\n min: state.min,\n max: state.max,\n snapOnStep: state.snapOnStep,\n });\n }\n setTyped(null);\n if (!Object.is(next, current.current)) {\n setValue(next, { reason, event });\n }\n if (commitsAtOnce(reason)) {\n commit(event);\n }\n const bound = amount > 0 ? state.max : state.min;\n return bound === undefined || next !== bound;\n },\n stepTo: (\n next: number,\n reason: ChangeReason,\n event: Event | undefined,\n ) => {\n const state = latest.current;\n if (state.disabled || state.readOnly) {\n return;\n }\n setTyped(null);\n if (!Object.is(next, current.current)) {\n setValue(next, { reason, event });\n }\n if (commitsAtOnce(reason)) {\n commit(event);\n }\n },\n onInputText: (text: string, event: Event) => {\n const state = latest.current;\n if (state.disabled || state.readOnly) {\n return false;\n }\n const options = { locale: state.locale, format: state.format };\n if (!isNumberText(text, options)) {\n // refused: the text stays as it was (spec/number-field.md, \"Typing\")\n return false;\n }\n setTyped(text);\n if (text.trim() === \"\") {\n setValue(null, { reason: \"input-clear\", event });\n return true;\n }\n const parsed = parseNumber(text, options);\n if (parsed !== null && !Number.isNaN(parsed)) {\n setValue(parsed, { reason: \"input-change\", event });\n }\n return true;\n },\n onInputBlur: (event: Event) => {\n const state = latest.current;\n if (state.typed === null) {\n return;\n }\n let next = base();\n if (state.clampOnBlur && next !== null) {\n next = clampNumber(next, state.min, state.max);\n }\n setTyped(null);\n if (!Object.is(next, current.current)) {\n setValue(next, { reason: \"input-blur\", event });\n }\n commit(event);\n },\n };\n }, []);\n\n // a form reset returns it to its default, and writes the rendered value back (Switch's way)\n useEffect(() => {\n const element = hidden.current;\n if (element === null) {\n return undefined;\n }\n return bridgeForm(element, {\n reset: () => {\n const state = latest.current;\n state.reset();\n setTyped(null);\n actions.setValue(state.defaultValue, { reason: \"none\" });\n // the rendered value, which a render that changes it patches again (a controlled\n // field that refuses the reset keeps its input)\n element.value = state.value === null ? \"\" : String(state.value);\n },\n invalid: () => input,\n });\n }, [input, actions]);\n\n const state: NumberFieldState = {\n value,\n inputValue,\n disabled,\n readOnly,\n required,\n scrubbing,\n };\n const attributes = {\n ...stateAttributes({\n disabled,\n readonly: readOnly,\n required,\n scrubbing,\n }),\n ...field.attributes,\n };\n const context: NumberFieldContextValue = {\n ...state,\n inputId,\n min,\n max,\n locale,\n format,\n formattedValue,\n allowWheelScrub,\n field,\n attributes,\n amount: actions.amount,\n stepBy: actions.stepBy,\n stepTo: actions.stepTo,\n commit: actions.commit,\n onInputText: actions.onInputText,\n onInputBlur: actions.onInputBlur,\n setInputElement,\n setScrubbing,\n cursor,\n setCursor,\n };\n const formName = field.name ?? name;\n return (\n <NumberFieldContext.Provider value={context}>\n {renderElement(\"div\", { ...props, children }, state, {\n \"data-primitives-part\": \"number-field-root\",\n ...attributes,\n })}\n <input\n ref={hidden}\n type=\"number\"\n aria-hidden=\"true\"\n tabIndex={-1}\n name={formName}\n value={value === null ? \"\" : String(value)}\n min={min}\n max={max}\n step=\"any\"\n required={required}\n disabled={disabled}\n onChange={NOOP}\n onFocus={() => input?.focus()}\n style={VISUALLY_HIDDEN_INPUT_STYLE}\n data-primitives-part=\"number-field-hidden-input\"\n />\n </NumberFieldContext.Provider>\n );\n}\n","import { watchScrub } from \"@fragiola/primitives/number\";\nimport { type MouseEvent, useEffect, useRef, useState } from \"react\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport {\n NumberFieldContext,\n type NumberFieldState,\n numberFieldState,\n} from \"./number-field-context.ts\";\n\nexport interface NumberFieldScrubAreaProps extends PartProps<NumberFieldState> {\n /** The axis the pointer scrubs along (default `\"horizontal\"`). */\n direction?: \"horizontal\" | \"vertical\";\n /** The pixels one step takes (default `2`). */\n pixelSensitivity?: number;\n}\n\nconst STYLE = { touchAction: \"none\", userSelect: \"none\" } as const;\n\n/** A press dragged along it steps the value (spec/number-field.md, \"Pointer\": scrub). */\nexport function NumberFieldScrubArea({\n direction = \"horizontal\",\n pixelSensitivity = 2,\n ...props\n}: NumberFieldScrubAreaProps) {\n const context = useRequiredContext(\n NumberFieldContext,\n \"NumberField.ScrubArea\",\n );\n const [element, setElement] = useState<HTMLElement | null>(null);\n const latest = useRef(context);\n latest.current = context;\n useEffect(() => {\n if (element === null) {\n return undefined;\n }\n return watchScrub(element, {\n direction,\n pixelSensitivity,\n onStart: () => {\n const current = latest.current;\n if (current.disabled || current.readOnly) {\n return false;\n }\n current.setScrubbing(true);\n return true;\n },\n onScrub: (steps, event) => {\n const current = latest.current;\n const amount = current.amount(event);\n current.stepBy(\n steps > 0 ? amount : -amount,\n \"scrub\",\n event,\n Math.abs(steps),\n );\n },\n onEnd: (event) => {\n latest.current.setScrubbing(false);\n latest.current.commit(event);\n },\n onCursor: (point) => latest.current.setCursor(point),\n });\n }, [element, direction, pixelSensitivity]);\n return renderElement(\n \"span\",\n props,\n numberFieldState(context),\n {\n style: STYLE,\n // a press keeps the focus where it is\n onMouseDown: (event: MouseEvent<HTMLElement>) => {\n if (event.button === 0) {\n event.preventDefault();\n }\n },\n \"data-primitives-part\": \"number-field-scrub-area\",\n ...context.attributes,\n },\n setElement,\n );\n}\n","import { createPortal } from \"react-dom\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport {\n NumberFieldContext,\n type NumberFieldState,\n numberFieldState,\n} from \"./number-field-context.ts\";\n\nexport type NumberFieldScrubAreaCursorProps = PartProps<NumberFieldState>;\n\n/**\n * The virtual cursor of a locked scrub (spec/number-field.md, \"Pointer\"), in a portal into `body`:\n * rendered only while a mouse scrubs with the pointer locked.\n */\nexport function NumberFieldScrubAreaCursor(\n props: NumberFieldScrubAreaCursorProps,\n) {\n const context = useRequiredContext(\n NumberFieldContext,\n \"NumberField.ScrubAreaCursor\",\n );\n const { cursor } = context;\n if (cursor === null || typeof document === \"undefined\") {\n return null;\n }\n return createPortal(\n renderElement(\"span\", props, numberFieldState(context), {\n style: {\n position: \"fixed\",\n top: 0,\n left: 0,\n pointerEvents: \"none\",\n transform: `translate3d(${cursor.x}px, ${cursor.y}px, 0)`,\n },\n \"data-primitives-part\": \"number-field-scrub-area-cursor\",\n ...context.attributes,\n }),\n document.body,\n );\n}\n","import { NumberFieldDecrement } from \"./number-field-decrement.tsx\";\nimport { NumberFieldGroup } from \"./number-field-group.tsx\";\nimport { NumberFieldIncrement } from \"./number-field-increment.tsx\";\nimport { NumberFieldInput } from \"./number-field-input.tsx\";\nimport { NumberFieldRoot } from \"./number-field-root.tsx\";\nimport { NumberFieldScrubArea } from \"./number-field-scrub-area.tsx\";\nimport { NumberFieldScrubAreaCursor } from \"./number-field-scrub-area-cursor.tsx\";\n\n/** spec/number-field.md */\nexport const NumberField = {\n Root: NumberFieldRoot,\n Group: NumberFieldGroup,\n Input: NumberFieldInput,\n Increment: NumberFieldIncrement,\n Decrement: NumberFieldDecrement,\n ScrubArea: NumberFieldScrubArea,\n ScrubAreaCursor: NumberFieldScrubAreaCursor,\n};\n"],"mappings":";;;;;;;;;;;AA6DA,MAAa,qBAAqB,cAC9B,IACJ;;AAGA,SAAgB,iBACZ,SACgB;CAChB,OAAO;EACH,OAAO,QAAQ;EACf,YAAY,QAAQ;EACpB,UAAU,QAAQ;EAClB,UAAU,QAAQ;EAClB,UAAU,QAAQ;EAClB,WAAW,QAAQ;CACvB;AACJ;;;;;;ACrEA,SAAgB,iBACZ,SACA,WACF;CACE,MAAM,CAAC,SAAS,cAAc,SAA6B,IAAI;CAC/D,MAAM,SAAS,OAAO,OAAO;CAC7B,OAAO,UAAU;CACjB,gBAAgB;EACZ,IAAI,YAAY,MACZ;EAEJ,OAAO,gBAAgB,SAAS;GAC5B,SAAS,UAAU;IACf,MAAM,UAAU,OAAO;IACvB,MAAM,SAAS,QAAQ,OAAO,KAAmB;IACjD,OAAO,QAAQ,OACX,YAAY,QACZ,YAAY,IAAI,oBAAoB,mBACpC,KACJ;GACJ;GACA,QAAQ,UAAU,OAAO,QAAQ,OAAO,KAAK;EACjD,CAAC;CACL,GAAG,CAAC,SAAS,SAAS,CAAC;CACvB,MAAM,EAAE,OAAO,KAAK,QAAQ;CAC5B,MAAM,UACF,UAAU,SACT,YAAY,IACP,QAAQ,KAAA,KAAa,SAAS,MAC9B,QAAQ,KAAA,KAAa,SAAS;CACxC,OAAO;EACH,KAAK;EACL,UAAU,QAAQ,YAAY,QAAQ,YAAY;CACtD;AACJ;;;;;;AC3BA,SAAgB,qBAAqB,OAAkC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GAAG,QAAQ;CACf,GACA,UACJ;AACJ;;;;;;AClEA,SAAgB,2BACZ,OACF;CACE,MAAM,UAAU,mBACZ,oBACA,6BACJ;CACA,MAAM,EAAE,WAAW;CACnB,IAAI,WAAW,QAAQ,OAAO,aAAa,aACvC,OAAO;CAEX,OAAO,aACH,cAAc,QAAQ,OAAO,iBAAiB,OAAO,GAAG;EACpD,OAAO;GACH,UAAU;GACV,KAAK;GACL,MAAM;GACN,eAAe;GACf,WAAW,eAAe,OAAO,EAAE,MAAM,OAAO,EAAE;EACtD;EACA,wBAAwB;EACxB,GAAG,QAAQ;CACf,CAAC,GACD,SAAS,IACb;AACJ;;;AC/BA,MAAa,cAAc;CACvB,MAAM;CACN,OAAO;CACP,OAAO;CACP,WAAW;CACX,WAAW;CACX,WAAW;CACX,iBAAiB;AACrB"}
@@ -1,4 +1,4 @@
1
1
  import { n as ChangeReason, t as ChangeDetails } from "./change-details-CPSkPCNw.js";
2
2
  import { n as RenderProp } from "./render-element-Pwuv2wsL.js";
3
- import { a as NumberFieldInputProps, c as NumberFieldDecrementProps, i as NumberFieldRootProps, l as NumberFieldState, n as NumberFieldScrubAreaCursorProps, o as NumberFieldIncrementProps, r as NumberFieldScrubAreaProps, s as NumberFieldGroupProps, t as NumberField } from "./index-CcwKZWPY.js";
3
+ import { a as NumberFieldInputProps, c as NumberFieldDecrementProps, i as NumberFieldRootProps, l as NumberFieldState, n as NumberFieldScrubAreaCursorProps, o as NumberFieldIncrementProps, r as NumberFieldScrubAreaProps, s as NumberFieldGroupProps, t as NumberField } from "./index-Dy7NUYXe.js";
4
4
  export { type ChangeDetails, type ChangeReason, NumberField, type NumberFieldDecrementProps, type NumberFieldGroupProps, type NumberFieldIncrementProps, type NumberFieldInputProps, type NumberFieldRootProps, type NumberFieldScrubAreaCursorProps, type NumberFieldScrubAreaProps, type NumberFieldState, type RenderProp };
@@ -1 +1 @@
1
- export { t as NumberField } from "./number-field-BUNkL15K.js";
1
+ export { t as NumberField } from "./number-field-ChJoV38v.js";
@@ -257,7 +257,7 @@ function ComboboxInput(props) {
257
257
  context.setInputValue(event.target.value, "input-change");
258
258
  context.setHighlighted(null);
259
259
  context.markTyped();
260
- context.pendingHighlight.current = null;
260
+ context.pendingHighlight.current = context.autoHighlight && event.target.value !== "" ? "typed" : null;
261
261
  if (!open) context.setOpen(true, "input-change", event.nativeEvent);
262
262
  },
263
263
  onClick: () => openOnPress(context),
@@ -363,19 +363,26 @@ function ComboboxItemIndicator({ keepMounted = false, ...props }) {
363
363
  /** The `listbox`. Applies the highlight the keyboard asked for once its items render. */
364
364
  function ComboboxList({ children, ...props }) {
365
365
  const context = useRequiredContext(ComboboxContext, "Combobox.List");
366
- const { list, pendingHighlight, setHighlighted, itemCount, open } = context;
366
+ const { list, pendingHighlight, setHighlighted, itemCount, open, inputValue } = context;
367
367
  useLayoutEffect(() => {
368
368
  const pending = pendingHighlight.current;
369
369
  if (list === null || pending === null) return;
370
- pendingHighlight.current = null;
370
+ const rendered = list.querySelectorAll("[role=\"option\"]").length;
371
371
  const items = orderedItems(context);
372
+ if (items.length < rendered) return;
373
+ pendingHighlight.current = null;
374
+ if (pending === "typed") {
375
+ setHighlighted(items[0]?.id ?? null);
376
+ return;
377
+ }
372
378
  const selected = context.multiple ? void 0 : items.find((item) => context.isSelected(item.value));
373
379
  const edge = pending === "first" ? items[0] : items.at(-1);
374
380
  setHighlighted((selected ?? (pending === "selected" ? void 0 : edge))?.id ?? null);
375
381
  }, [
376
382
  list,
377
383
  itemCount,
378
- open
384
+ open,
385
+ inputValue
379
386
  ]);
380
387
  const empty = context.hasItems ? context.entries.length === 0 : itemCount === 0;
381
388
  const content = typeof children === "function" ? context.entries.map((entry, index) => children(entry, index)) : children;
@@ -478,7 +485,7 @@ const NOOP = () => {};
478
485
  const NONE = [];
479
486
  /** Holds the combobox's state; renders its hidden form inputs (spec/combobox.md). */
480
487
  function ComboboxRoot(props) {
481
- const { items, filter: filterProp, limit = -1, locale, multiple = false, inputValue: inputValueProp, defaultInputValue, onInputValueChange, isItemEqualToValue, itemToStringLabel, itemToStringValue, name, required = false, disabled: disabledProp = false, children, open: openProp, defaultOpen, onOpenChange, onOpenChangeComplete, actionsRef } = props;
488
+ const { items, filter: filterProp, limit = -1, locale, multiple = false, autoHighlight = false, inputValue: inputValueProp, defaultInputValue, onInputValueChange, isItemEqualToValue, itemToStringLabel, itemToStringValue, name, required = false, disabled: disabledProp = false, children, open: openProp, defaultOpen, onOpenChange, onOpenChangeComplete, actionsRef } = props;
482
489
  const defaultValue = props.defaultValue ?? (multiple ? NONE : null);
483
490
  const root = useOverlayRoot({
484
491
  open: openProp,
@@ -635,6 +642,7 @@ function ComboboxRoot(props) {
635
642
  setOpen,
636
643
  field,
637
644
  multiple,
645
+ autoHighlight,
638
646
  value,
639
647
  values,
640
648
  inputValue,
@@ -672,6 +680,7 @@ function ComboboxRoot(props) {
672
680
  setOpen,
673
681
  field,
674
682
  multiple,
683
+ autoHighlight,
675
684
  value,
676
685
  values,
677
686
  inputValue,
@@ -803,4 +812,4 @@ const Combobox = {
803
812
  };
804
813
  export { ComboboxList as n, ComboboxContext as r, Combobox as t };
805
814
 
806
- //# sourceMappingURL=parts-VT0Ohb06.js.map
815
+ //# sourceMappingURL=parts-Dpfqew1M.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parts-Dpfqew1M.js","names":[],"sources":["../src/components/combobox/combobox-context.ts","../src/components/combobox/combobox-chip.tsx","../src/components/combobox/combobox-chip-remove.tsx","../src/components/combobox/combobox-chips.tsx","../src/components/combobox/combobox-clear.tsx","../src/components/combobox/combobox-empty.tsx","../src/components/combobox/combobox-group.tsx","../src/components/combobox/combobox-group-label.tsx","../src/components/combobox/combobox-input.tsx","../src/components/combobox/combobox-input-group.tsx","../src/components/combobox/combobox-item.tsx","../src/components/combobox/combobox-item-indicator.tsx","../src/components/combobox/combobox-list.tsx","../src/components/combobox/combobox-popup.tsx","../src/components/combobox/combobox-portal.tsx","../src/components/combobox/combobox-positioner.tsx","../src/components/combobox/combobox-root.tsx","../src/components/combobox/combobox-separator.tsx","../src/components/combobox/combobox-status.tsx","../src/components/combobox/combobox-trigger.tsx","../src/components/combobox/combobox-value.tsx","../src/components/combobox/parts.ts"],"sourcesContent":["import type { Align, Side } from \"@fragiola/primitives/positioning\";\nimport { createContext, type MutableRefObject } from \"react\";\nimport type { FieldControlBinding } from \"../../hooks/use-field-control.ts\";\nimport type { OverlayRoot } from \"../../hooks/use-overlay-root.ts\";\nimport type { ChangeReason } from \"../../utils/change-details.ts\";\n\n/** A rendered Item, as the Root knows it. */\nexport interface ComboboxItemInfo {\n value: unknown;\n disabled: boolean;\n id: string;\n}\n\n/**\n * What is highlighted once the list renders: the first, the last or the selected item, or the\n * first item the typed text kept (`autoHighlight`).\n */\nexport type PendingHighlight = \"first\" | \"last\" | \"selected\" | \"typed\" | null;\n\nexport interface ComboboxContextValue extends OverlayRoot {\n /** The enclosing field's binding, for the input (spec/field.md). */\n field: FieldControlBinding;\n multiple: boolean;\n /** Typing highlights the first item the filter keeps. */\n autoHighlight: boolean;\n /** The selected item (or `null`), or the selected items with `multiple`. */\n value: unknown;\n /** The selected items, as a list in both modes. */\n values: readonly unknown[];\n inputValue: string;\n setInputValue: (value: string, reason: ChangeReason) => void;\n disabled: boolean;\n /** The highlighted item's id. */\n highlighted: string | null;\n setHighlighted: (id: string | null) => void;\n isSelected: (item: unknown) => boolean;\n /** Chooses an item (spec/combobox.md, \"Choosing an item\"). */\n choose: (item: unknown) => void;\n /** Clears the text and the value. */\n clear: (reason: ChangeReason) => void;\n /** Removes the value at `index` (`multiple`). */\n removeAt: (index: number, reason: ChangeReason) => void;\n /** An item's text (`itemToStringLabel`). */\n label: (item: unknown) => string;\n /** Whether the Root has `items` (it filters them). */\n hasItems: boolean;\n /** The matching entries: items, or groups with their matching items. */\n entries: readonly unknown[];\n /** The input's text changed by typing since the list opened. */\n markTyped: () => void;\n items: Map<HTMLElement, ComboboxItemInfo>;\n list: HTMLElement | null;\n setList: (element: HTMLElement | null) => void;\n /** The Trigger button (the overlay root's `trigger` is the input). */\n button: HTMLElement | null;\n setButton: (element: HTMLElement | null) => void;\n inputGroup: HTMLElement | null;\n setInputGroup: (element: HTMLElement | null) => void;\n chips: HTMLElement | null;\n setChips: (element: HTMLElement | null) => void;\n clearButton: HTMLElement | null;\n setClearButton: (element: HTMLElement | null) => void;\n listId: string;\n pendingHighlight: MutableRefObject<PendingHighlight>;\n placed: { side: Side; align: Align };\n setPlaced: (placed: { side: Side; align: Align }) => void;\n /** Bumped when items register, so `data-empty` and the pending highlight follow. */\n itemCount: number;\n setItemCount: (count: number) => void;\n}\n\nexport const ComboboxContext = createContext<ComboboxContextValue | null>(null);\n\nexport interface ComboboxItemContextValue {\n selected: boolean;\n}\n\nexport const ComboboxItemContext =\n createContext<ComboboxItemContextValue | null>(null);\n\nexport interface ComboboxGroupContextValue {\n labelId: string;\n}\n\nexport const ComboboxGroupContext =\n createContext<ComboboxGroupContextValue | null>(null);\n\nexport interface ComboboxChipContextValue {\n /** The chip's element, read when a key or a press removes it. */\n element: () => HTMLElement | null;\n}\n\nexport const ComboboxChipContext =\n createContext<ComboboxChipContextValue | null>(null);\n\n/** The rendered items of the list, in order. */\nexport function orderedItems(\n context: ComboboxContextValue,\n): ComboboxItemInfo[] {\n if (context.list === null) {\n return [];\n }\n return [...context.list.querySelectorAll<HTMLElement>('[role=\"option\"]')]\n .map((element) => context.items.get(element))\n .filter((item): item is ComboboxItemInfo => item !== undefined);\n}\n\n/** The rendered chips, in value order. */\nexport function chipElements(context: ComboboxContextValue): HTMLElement[] {\n if (context.chips === null) {\n return [];\n }\n return [\n ...context.chips.querySelectorAll<HTMLElement>(\n '[data-primitives-part=\"combobox-chip\"]',\n ),\n ];\n}\n\n/**\n * A press on the InputGroup or the Chips, outside their buttons, chips and input: focuses the\n * input and opens the list (spec/combobox.md, \"Pointer\").\n */\nexport function pressToOpen(\n context: ComboboxContextValue,\n event: { target: EventTarget | null; preventDefault: () => void },\n): void {\n const target = event.target as Element | null;\n if (\n target === null ||\n target === context.trigger ||\n target.closest('button, [data-primitives-part=\"combobox-chip\"]') !==\n null\n ) {\n return;\n }\n event.preventDefault();\n if (context.disabled) {\n return;\n }\n context.trigger?.focus();\n openOnPress(context);\n}\n\n/** A press on the input opens the list, on the selected item in single mode. */\nexport function openOnPress(context: ComboboxContextValue): void {\n if (context.open || context.disabled) {\n return;\n }\n context.pendingHighlight.current = context.multiple ? null : \"selected\";\n context.setOpen(true, \"input-press\");\n}\n","import { chipKeyTarget } from \"@fragiola/primitives/collection\";\nimport { getDirection } from \"@fragiola/primitives/direction\";\nimport { type KeyboardEvent, useContext, useRef } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { DirectionContext } from \"../../direction/direction-context.ts\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport {\n ComboboxChipContext,\n ComboboxContext,\n chipElements,\n} from \"./combobox-context.ts\";\n\n/** One value of a `multiple` combobox; the arrows move between chips (spec/combobox.md). */\nexport function ComboboxChip(props: PartProps<{ disabled: boolean }>) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Chip\");\n const direction = useContext(DirectionContext);\n const element = useRef<HTMLElement | null>(null);\n const { disabled } = context;\n\n const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {\n if (disabled || event.ctrlKey || event.metaKey || event.altKey) {\n return;\n }\n const chips = chipElements(context);\n const index = chips.indexOf(event.currentTarget);\n const action = chipKeyTarget(\n event.key,\n index,\n chips.length,\n getDirection(event.currentTarget, direction) === \"rtl\",\n );\n if (action === null) {\n return;\n }\n // a printable character goes on to the input, focused below\n if (event.key.length !== 1 || event.key === \" \") {\n event.preventDefault();\n }\n if (action.remove) {\n flushSync(() => context.removeAt(index, \"none\"));\n }\n if (action.open) {\n context.setOpen(true, \"list-navigation\");\n }\n const target =\n action.focus === \"input\"\n ? context.trigger\n : chipElements(context)[action.focus];\n target?.focus();\n };\n\n return (\n <ComboboxChipContext.Provider\n value={{ element: () => element.current }}\n >\n {renderElement(\n \"div\",\n props,\n { disabled },\n {\n tabIndex: -1,\n \"aria-disabled\": disabled ? \"true\" : undefined,\n \"data-primitives-part\": \"combobox-chip\",\n ...stateAttributes({ disabled }),\n onKeyDown,\n },\n (node: HTMLElement | null) => {\n element.current = node;\n },\n )}\n </ComboboxChipContext.Provider>\n );\n}\n","import { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport {\n ComboboxChipContext,\n ComboboxContext,\n chipElements,\n} from \"./combobox-context.ts\";\n\n/** Removes its chip's value and returns focus to the input. */\nexport function ComboboxChipRemove(props: PartProps<{ disabled: boolean }>) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.ChipRemove\");\n const chip = useRequiredContext(ComboboxChipContext, \"Combobox.ChipRemove\");\n const { disabled } = context;\n return renderElement(\n \"button\",\n props,\n { disabled },\n {\n type: \"button\",\n tabIndex: -1,\n disabled,\n \"data-primitives-part\": \"combobox-chip-remove\",\n ...stateAttributes({ disabled }),\n onPointerDown: (event: PointerEvent) => event.preventDefault(),\n onClick: () => {\n const element = chip.element();\n const index =\n element === null\n ? -1\n : chipElements(context).indexOf(element);\n if (index >= 0) {\n context.removeAt(index, \"chip-remove-press\");\n }\n context.trigger?.focus();\n },\n },\n );\n}\n","import type { MouseEvent } from \"react\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { ComboboxContext, pressToOpen } from \"./combobox-context.ts\";\n\n/** `multiple`: holds the chips and the Input; a `toolbar` while it holds a chip. */\nexport function ComboboxChips(props: PartProps<Record<string, never>>) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Chips\");\n return renderElement(\n \"div\",\n props,\n {},\n {\n role: context.values.length > 0 ? \"toolbar\" : undefined,\n \"data-primitives-part\": \"combobox-chips\",\n onMouseDown: (event: MouseEvent) => pressToOpen(context, event),\n },\n context.setChips,\n );\n}\n","import { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport { ComboboxContext } from \"./combobox-context.ts\";\n\n/** Clears the text and the value; rendered only while there is a value (spec/combobox.md). */\nexport function ComboboxClear(props: PartProps<{ disabled: boolean }>) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Clear\");\n const { disabled } = context;\n if (context.values.length === 0) {\n return null;\n }\n return renderElement(\n \"button\",\n props,\n { disabled },\n {\n type: \"button\",\n tabIndex: -1,\n disabled,\n \"data-primitives-part\": \"combobox-clear\",\n ...stateAttributes({ disabled }),\n onPointerDown: (event: PointerEvent) => event.preventDefault(),\n onClick: () => {\n context.clear(\"clear-press\");\n context.trigger?.focus();\n },\n },\n context.setClearButton,\n );\n}\n","import { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { ComboboxContext } from \"./combobox-context.ts\";\n\n/**\n * A polite live region, always rendered; its children are shown only while the list is empty\n * (spec/combobox.md).\n */\nexport function ComboboxEmpty({\n children,\n ...props\n}: PartProps<Record<string, never>>) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Empty\");\n const empty = context.hasItems\n ? context.entries.length === 0\n : context.itemCount === 0;\n return renderElement(\n \"div\",\n { ...props, children: empty ? children : null },\n {},\n {\n role: \"status\",\n \"aria-live\": \"polite\",\n \"aria-atomic\": \"true\",\n \"data-primitives-part\": \"combobox-empty\",\n },\n );\n}\n","import { useId } from \"react\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { ComboboxGroupContext } from \"./combobox-context.ts\";\n\n/** A `group` of items, named by its GroupLabel (spec/combobox.md). */\nexport function ComboboxGroup(props: PartProps<Record<string, never>>) {\n const labelId = `${useId()}-label`;\n return (\n <ComboboxGroupContext.Provider value={{ labelId }}>\n {renderElement(\n \"div\",\n props,\n {},\n {\n role: \"group\",\n \"aria-labelledby\": labelId,\n \"data-primitives-part\": \"combobox-group\",\n },\n )}\n </ComboboxGroupContext.Provider>\n );\n}\n","import { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { ComboboxGroupContext } from \"./combobox-context.ts\";\n\n/** Names its Group. */\nexport function ComboboxGroupLabel(props: PartProps<Record<string, never>>) {\n const group = useRequiredContext(\n ComboboxGroupContext,\n \"Combobox.GroupLabel\",\n );\n return renderElement(\n \"div\",\n props,\n {},\n { id: group.labelId, \"data-primitives-part\": \"combobox-group-label\" },\n );\n}\n","import { chipArrows, stepThroughNone } from \"@fragiola/primitives/collection\";\nimport { getDirection } from \"@fragiola/primitives/direction\";\nimport { type ChangeEvent, type KeyboardEvent, useContext } from \"react\";\nimport { DirectionContext } from \"../../direction/direction-context.ts\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport {\n ComboboxContext,\n chipElements,\n openOnPress,\n orderedItems,\n type PendingHighlight,\n} from \"./combobox-context.ts\";\n\n/**\n * The `combobox`: keeps DOM focus while the list is open; the highlighted item is announced with\n * `aria-activedescendant` (spec/combobox.md, \"Keyboard\").\n */\nexport function ComboboxInput(\n props: PartProps<{ open: boolean; disabled: boolean }>,\n) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Input\");\n const direction = useContext(DirectionContext);\n const { open, disabled, highlighted, field } = context;\n const items = orderedItems(context);\n const active = items.find((item) => item.id === highlighted);\n\n const openWith = (highlight: PendingHighlight, event?: Event) => {\n context.pendingHighlight.current = highlight;\n context.setOpen(true, \"list-navigation\", event);\n };\n const move = (delta: 1 | -1) => {\n // past an end, the visual focus goes back to the input; from the input, to the near end\n const index = items.findIndex((item) => item.id === highlighted);\n context.setHighlighted(\n items[stepThroughNone(items.length, index, delta)]?.id ?? null,\n );\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n const input = event.currentTarget;\n switch (event.key) {\n case \"ArrowDown\":\n case \"ArrowUp\": {\n event.preventDefault();\n if (event.altKey) {\n if (event.key === \"ArrowDown\" && !open) {\n openWith(null, event.nativeEvent);\n } else if (event.key === \"ArrowUp\" && open) {\n context.setOpen(\n false,\n \"list-navigation\",\n event.nativeEvent,\n );\n }\n return;\n }\n if (!open) {\n openWith(\n event.key === \"ArrowDown\" ? \"first\" : \"last\",\n event.nativeEvent,\n );\n return;\n }\n move(event.key === \"ArrowDown\" ? 1 : -1);\n return;\n }\n case \"Enter\":\n if (open) {\n event.preventDefault();\n if (active !== undefined && !active.disabled) {\n context.choose(active.value);\n }\n }\n return;\n case \"Escape\":\n // the open list's layer takes Escape first; here the list is closed\n if (\n !open &&\n (context.inputValue !== \"\" || context.values.length > 0)\n ) {\n event.preventDefault();\n context.clear(\"escape-key\");\n }\n return;\n case \"Tab\":\n if (open) {\n context.setOpen(false, \"focus-out\", event.nativeEvent);\n }\n return;\n case \"Backspace\":\n if (\n context.multiple &&\n input.value === \"\" &&\n context.values.length > 0\n ) {\n context.removeAt(context.values.length - 1, \"none\");\n }\n return;\n default: {\n const chips = chipElements(context);\n if (\n context.multiple &&\n event.key ===\n chipArrows(getDirection(input, direction) === \"rtl\")\n .previous &&\n input.selectionStart === 0 &&\n input.selectionEnd === 0 &&\n chips.length > 0\n ) {\n event.preventDefault();\n chips.at(-1)?.focus();\n }\n }\n }\n };\n\n const state = { open, disabled };\n return renderElement(\n \"input\",\n props,\n state,\n {\n type: \"text\",\n id: context.triggerId,\n role: \"combobox\",\n autoComplete: \"off\",\n disabled,\n value: context.inputValue,\n \"aria-autocomplete\": \"list\",\n \"aria-expanded\": open,\n \"aria-controls\": context.listId,\n \"aria-activedescendant\": open && active ? active.id : undefined,\n ...field.aria,\n \"data-primitives-part\": \"combobox-input\",\n ...field.attributes,\n ...stateAttributes({ \"popup-open\": open, disabled }),\n onChange: (event: ChangeEvent<HTMLInputElement>) => {\n context.setInputValue(event.target.value, \"input-change\");\n context.setHighlighted(null);\n context.markTyped();\n // autoHighlight: the first item the text keeps, once the list renders\n context.pendingHighlight.current =\n context.autoHighlight && event.target.value !== \"\"\n ? \"typed\"\n : null;\n if (!open) {\n context.setOpen(true, \"input-change\", event.nativeEvent);\n }\n },\n onClick: () => openOnPress(context),\n onKeyDown,\n onFocus: field.onFocus,\n onBlur: field.onBlur,\n },\n context.setTrigger,\n );\n}\n","import type { MouseEvent } from \"react\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport { ComboboxContext, pressToOpen } from \"./combobox-context.ts\";\n\n/** Holds the Input and its buttons; anchors the list (spec/combobox.md). */\nexport function ComboboxInputGroup(\n props: PartProps<{ open: boolean; disabled: boolean }>,\n) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.InputGroup\");\n const { open, disabled } = context;\n return renderElement(\n \"div\",\n props,\n { open, disabled },\n {\n role: \"group\",\n \"data-primitives-part\": \"combobox-input-group\",\n ...stateAttributes({ \"popup-open\": open, disabled }),\n onMouseDown: (event: MouseEvent) => pressToOpen(context, event),\n },\n context.setInputGroup,\n );\n}\n","import { scrollIntoViewWithin } from \"@fragiola/primitives/collection\";\nimport { useId, useLayoutEffect } from \"react\";\nimport { useElement } from \"../../hooks/use-element.ts\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport { ComboboxContext, ComboboxItemContext } from \"./combobox-context.ts\";\n\nexport interface ComboboxItemState {\n highlighted: boolean;\n selected: boolean;\n disabled: boolean;\n}\n\nexport interface ComboboxItemProps extends PartProps<ComboboxItemState> {\n /** The item: written into the input as `itemToStringLabel(value)` when chosen. */\n value: unknown;\n /** Can be highlighted, never chosen. */\n disabled?: boolean;\n}\n\n/** An `option` (spec/combobox.md). */\nexport function ComboboxItem({\n value,\n disabled = false,\n ...props\n}: ComboboxItemProps) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Item\");\n const [element, ref] = useElement<HTMLElement>();\n const id = useId();\n const { items, setItemCount } = context;\n useLayoutEffect(() => {\n if (element === null) {\n return undefined;\n }\n items.set(element, { value, disabled, id });\n setItemCount(items.size);\n return () => {\n items.delete(element);\n setItemCount(items.size);\n };\n }, [element, value, disabled, id, items, setItemCount]);\n\n const highlighted = context.highlighted === id;\n const selected = context.isSelected(value);\n const { positioner } = context;\n // within the popup only: a list that mounts before it is placed never scrolls the page\n useLayoutEffect(() => {\n if (highlighted && element !== null) {\n scrollIntoViewWithin(element, positioner);\n }\n }, [highlighted, element, positioner]);\n\n const state = { highlighted, selected, disabled };\n return (\n <ComboboxItemContext.Provider value={{ selected }}>\n {renderElement(\n \"div\",\n props,\n state,\n {\n role: \"option\",\n id,\n \"aria-selected\": selected ? \"true\" : undefined,\n \"aria-disabled\": disabled ? \"true\" : undefined,\n \"data-primitives-part\": \"combobox-item\",\n ...stateAttributes({ highlighted, selected, disabled }),\n onPointerMove: () => {\n if (!highlighted) {\n context.setHighlighted(id);\n }\n },\n onPointerDown: (event: PointerEvent) =>\n event.preventDefault(),\n onClick: () => {\n if (!disabled) {\n context.choose(value);\n }\n },\n },\n ref,\n )}\n </ComboboxItemContext.Provider>\n );\n}\n","import { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { ComboboxItemContext } from \"./combobox-context.ts\";\n\nexport interface ComboboxItemIndicatorProps\n extends PartProps<{ selected: boolean }> {\n /** Rendered while the item is not selected too. */\n keepMounted?: boolean;\n}\n\n/** Marks a selected item; hidden from assistive technologies (spec/combobox.md). */\nexport function ComboboxItemIndicator({\n keepMounted = false,\n ...props\n}: ComboboxItemIndicatorProps) {\n const item = useRequiredContext(\n ComboboxItemContext,\n \"Combobox.ItemIndicator\",\n );\n if (!item.selected && !keepMounted) {\n return null;\n }\n return renderElement(\n \"span\",\n props,\n { selected: item.selected },\n {\n \"aria-hidden\": \"true\",\n \"data-primitives-part\": \"combobox-item-indicator\",\n },\n );\n}\n","import { type ReactNode, useLayoutEffect } from \"react\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport { ComboboxContext, orderedItems } from \"./combobox-context.ts\";\n\nexport interface ComboboxListProps<Entry = unknown>\n extends Omit<PartProps<{ empty: boolean }>, \"children\"> {\n /**\n * Nodes, or a render function of each matching entry (an item, or a group). `Entry` is the\n * consumer's own type, inferred from the function's parameter.\n */\n children?: ReactNode | ((entry: Entry, index: number) => ReactNode);\n}\n\n/** The `listbox`. Applies the highlight the keyboard asked for once its items render. */\nexport function ComboboxList<Entry = unknown>({\n children,\n ...props\n}: ComboboxListProps<Entry>) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.List\");\n const {\n list,\n pendingHighlight,\n setHighlighted,\n itemCount,\n open,\n inputValue,\n } = context;\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: runs when the list opens, its items or its text change\n useLayoutEffect(() => {\n const pending = pendingHighlight.current;\n if (list === null || pending === null) {\n return;\n }\n // an Item registers once its element is set, a commit after it mounts: an item the new\n // text brought back is not registered yet, and the highlight waits for it (`itemCount`)\n const rendered = list.querySelectorAll('[role=\"option\"]').length;\n const items = orderedItems(context);\n if (items.length < rendered) {\n return;\n }\n pendingHighlight.current = null;\n if (pending === \"typed\") {\n setHighlighted(items[0]?.id ?? null);\n return;\n }\n const selected = context.multiple\n ? undefined\n : items.find((item) => context.isSelected(item.value));\n const edge = pending === \"first\" ? items[0] : items.at(-1);\n const target = selected ?? (pending === \"selected\" ? undefined : edge);\n setHighlighted(target?.id ?? null);\n }, [list, itemCount, open, inputValue]);\n\n const empty = context.hasItems\n ? context.entries.length === 0\n : itemCount === 0;\n const content =\n typeof children === \"function\"\n ? context.entries.map((entry, index) =>\n // the Root holds the consumer's items: the render function names their type\n children(entry as Entry, index),\n )\n : children;\n return renderElement(\n \"div\",\n { ...props, children: content },\n { empty },\n {\n role: \"listbox\",\n id: context.listId,\n \"aria-multiselectable\": context.multiple ? \"true\" : undefined,\n \"data-primitives-part\": \"combobox-list\",\n ...stateAttributes({ empty }),\n },\n context.setList,\n );\n}\n","import { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport { ComboboxContext } from \"./combobox-context.ts\";\n\n/** The floating container of the list (no role of its own). */\nexport function ComboboxPopup(\n props: PartProps<{ open: boolean; side: string; align: string }>,\n) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Popup\");\n const status = context.presence.status;\n return renderElement(\n \"div\",\n props,\n { open: context.open, ...context.placed },\n {\n \"data-primitives-part\": \"combobox-popup\",\n ...stateAttributes({\n open: context.open,\n closed: !context.open,\n side: context.placed.side,\n align: context.placed.align,\n \"starting-style\": status === \"starting\",\n \"ending-style\": status === \"ending\",\n }),\n },\n context.setPopup,\n );\n}\n","import {\n type OverlayPortalProps,\n useOverlayPortal,\n} from \"../../hooks/use-overlay-portal.ts\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { ComboboxContext } from \"./combobox-context.ts\";\n\nexport interface ComboboxPortalProps extends OverlayPortalProps {}\n\nexport function ComboboxPortal(props: ComboboxPortalProps) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Portal\");\n return useOverlayPortal(context.presence.mounted, props);\n}\n","import { openOverlaySession } from \"@fragiola/primitives/overlay\";\nimport { useEffect, useLayoutEffect } from \"react\";\nimport {\n type PositionerProps,\n usePositioner,\n} from \"../../hooks/use-positioner.ts\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport { ComboboxContext } from \"./combobox-context.ts\";\n\nexport interface ComboboxPositionerState {\n open: boolean;\n side: string;\n align: string;\n}\n\nexport interface ComboboxPositionerProps\n extends PartProps<ComboboxPositionerState>,\n PositionerProps {}\n\n/**\n * Places the list under the InputGroup (else the Chips, else the Input); the open list is a layer\n * (Escape, outside press).\n */\nexport function ComboboxPositioner({\n side,\n align,\n sideOffset,\n alignOffset,\n collisionPadding,\n anchor,\n ...props\n}: ComboboxPositionerProps) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Positioner\");\n const {\n open,\n positioner,\n trigger,\n button,\n inputGroup,\n chips,\n clearButton,\n setOpen,\n setPlaced,\n } = context;\n const placed = usePositioner(\n { side, align, sideOffset, alignOffset, collisionPadding, anchor },\n { side: \"bottom\", align: \"start\" },\n inputGroup ?? chips ?? trigger,\n positioner,\n null,\n context.presence.mounted,\n );\n useLayoutEffect(() => setPlaced(placed), [placed, setPlaced]);\n useEffect(() => {\n if (!open || positioner === null) {\n return undefined;\n }\n const session = openOverlaySession(positioner.ownerDocument, {\n elements: () => [positioner],\n ignore: () => [trigger, button, inputGroup, chips, clearButton],\n dismiss: (reason, event) => setOpen(false, reason, event),\n });\n return session.end;\n }, [\n open,\n positioner,\n trigger,\n button,\n inputGroup,\n chips,\n clearButton,\n setOpen,\n ]);\n return renderElement(\n \"div\",\n props,\n { open, ...placed },\n {\n role: \"presentation\",\n hidden: context.presence.mounted ? undefined : true,\n \"data-primitives-part\": \"combobox-positioner\",\n ...stateAttributes({\n open,\n closed: !open,\n side: placed.side,\n align: placed.align,\n }),\n },\n context.setPositioner,\n );\n}\n","import {\n containsFilter,\n filterItems,\n type ItemEquality,\n type ItemFilter,\n type ItemGroup,\n includesItem,\n itemFormValue,\n itemLabel,\n queryIsLabel,\n toggleItem,\n} from \"@fragiola/primitives/collection\";\nimport {\n bridgeForm,\n VISUALLY_HIDDEN_INPUT_STYLE,\n} from \"@fragiola/primitives/form\";\nimport type { Align, Side } from \"@fragiola/primitives/positioning\";\nimport {\n type ReactNode,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { useControllableState } from \"../../hooks/use-controllable-state.ts\";\nimport { useFieldControl } from \"../../hooks/use-field-control.ts\";\nimport {\n type OverlayRootProps,\n useOverlayRoot,\n} from \"../../hooks/use-overlay-root.ts\";\nimport type {\n ChangeDetails,\n ChangeReason,\n} from \"../../utils/change-details.ts\";\nimport {\n ComboboxContext,\n type ComboboxItemInfo,\n type PendingHighlight,\n} from \"./combobox-context.ts\";\n\ninterface ComboboxRootCommonProps<Item> extends OverlayRootProps {\n /** The items, or groups of items: the combobox filters them (spec/combobox.md). */\n items?: readonly (Item | ItemGroup<Item>)[];\n /** Whether an item matches the query; `null` turns filtering off. */\n filter?: ItemFilter<Item> | null;\n /** The most items the list renders; `-1` for no limit. */\n limit?: number;\n locale?: string;\n /** Typing highlights the first item the filter keeps, so Enter chooses it (default `false`). */\n autoHighlight?: boolean;\n inputValue?: string;\n defaultInputValue?: string;\n onInputValueChange?: (inputValue: string, details: ChangeDetails) => void;\n isItemEqualToValue?: ItemEquality<Item>;\n itemToStringLabel?: (item: Item) => string;\n itemToStringValue?: (item: Item) => string;\n name?: string;\n required?: boolean;\n disabled?: boolean;\n children?: ReactNode;\n}\n\nexport interface ComboboxRootSingleProps<Item>\n extends ComboboxRootCommonProps<Item> {\n multiple?: false;\n value?: Item | null;\n defaultValue?: Item | null;\n onValueChange?: (value: Item | null, details: ChangeDetails) => void;\n}\n\nexport interface ComboboxRootMultipleProps<Item>\n extends ComboboxRootCommonProps<Item> {\n multiple: true;\n value?: readonly Item[];\n defaultValue?: readonly Item[];\n onValueChange?: (value: Item[], details: ChangeDetails) => void;\n}\n\nexport type ComboboxRootProps<Item> =\n | ComboboxRootSingleProps<Item>\n | ComboboxRootMultipleProps<Item>;\n\nconst NOOP = () => {};\nconst NONE: readonly unknown[] = [];\n\n/** Holds the combobox's state; renders its hidden form inputs (spec/combobox.md). */\nexport function ComboboxRoot<Item>(props: ComboboxRootProps<Item>) {\n const {\n items,\n filter: filterProp,\n limit = -1,\n locale,\n multiple = false,\n autoHighlight = false,\n inputValue: inputValueProp,\n defaultInputValue,\n onInputValueChange,\n isItemEqualToValue,\n itemToStringLabel,\n itemToStringValue,\n name,\n required = false,\n disabled: disabledProp = false,\n children,\n open: openProp,\n defaultOpen,\n onOpenChange,\n onOpenChangeComplete,\n actionsRef,\n } = props;\n const defaultValue: unknown =\n props.defaultValue ?? (multiple ? NONE : null);\n const root = useOverlayRoot({\n open: openProp,\n defaultOpen,\n onOpenChange,\n onOpenChangeComplete,\n actionsRef,\n });\n const [value, setValue] = useControllableState<unknown, ChangeDetails>(\n props.value,\n defaultValue,\n props.onValueChange as\n | ((value: unknown, details: ChangeDetails) => void)\n | undefined,\n );\n const label = useCallback(\n (item: unknown) =>\n itemLabel(\n item,\n itemToStringLabel as ((item: unknown) => string) | undefined,\n ),\n [itemToStringLabel],\n );\n const formValue = (item: unknown) =>\n itemFormValue(\n item,\n itemToStringValue as ((item: unknown) => string) | undefined,\n );\n const isEqual = isItemEqualToValue as ItemEquality<unknown> | undefined;\n const values = useMemo<readonly unknown[]>(() => {\n if (multiple) {\n return (value as readonly unknown[] | null) ?? NONE;\n }\n return value === null || value === undefined ? NONE : [value];\n }, [multiple, value]);\n\n const [inputValue, setInputValueState] = useControllableState(\n inputValueProp,\n defaultInputValue ??\n (multiple ? \"\" : label(props.value ?? defaultValue)),\n onInputValueChange,\n );\n const hidden = useRef<HTMLInputElement>(null);\n const field = useFieldControl({\n id: root.trigger?.id || root.triggerId,\n labelable: true,\n value,\n filled: values.length > 0,\n input: () => hidden.current,\n // the Input\n focusTarget: () => root.trigger,\n });\n const disabled = disabledProp || field.disabled;\n const [highlighted, setHighlighted] = useState<string | null>(null);\n const registered = useMemo(\n () => new Map<HTMLElement, ComboboxItemInfo>(),\n [],\n );\n const [list, setList] = useState<HTMLElement | null>(null);\n const [button, setButton] = useState<HTMLElement | null>(null);\n const [inputGroup, setInputGroup] = useState<HTMLElement | null>(null);\n const [chips, setChips] = useState<HTMLElement | null>(null);\n const [clearButton, setClearButton] = useState<HTMLElement | null>(null);\n const [itemCount, setItemCount] = useState(0);\n const [typed, setTyped] = useState(false);\n const pendingHighlight = useRef<PendingHighlight>(null);\n const [placed, setPlaced] = useState<{ side: Side; align: Align }>({\n side: \"bottom\",\n align: \"start\",\n });\n const listId = `${useId()}-list`;\n\n const setInputValue = useCallback(\n (next: string, reason: ChangeReason) =>\n setInputValueState(next, { reason }),\n [setInputValueState],\n );\n const latest = useRef({ value, values, inputValue, multiple, label });\n latest.current = { value, values, inputValue, multiple, label };\n\n const { setOpen: setOpenState } = root;\n const setOpen = useCallback(\n (next: boolean, reason: ChangeReason, event?: Event): boolean => {\n // a close the consumer cancels leaves the list, its text and highlight as they are\n const changed = setOpenState(next, reason, event);\n if (!next || reason !== \"input-change\") {\n if (changed || next) {\n setTyped(false);\n }\n }\n if (next || !changed) {\n return changed;\n }\n // a list reopened during its exit animation starts with no highlight\n setHighlighted(null);\n pendingHighlight.current = null;\n if (reason === \"item-press\") {\n return changed;\n }\n // closing without a choice resets the text (spec/combobox.md, \"Choosing an item\")\n const current = latest.current;\n const text = current.multiple ? \"\" : current.label(current.value);\n if (current.inputValue !== text) {\n setInputValueState(text, {\n reason: text === \"\" ? \"input-clear\" : \"none\",\n });\n }\n return changed;\n },\n [setOpenState, setInputValueState],\n );\n\n const choose = useCallback(\n (item: unknown) => {\n const current = latest.current;\n setHighlighted(null);\n if (!current.multiple) {\n setValue(item, { reason: \"item-press\" });\n setInputValueState(current.label(item), {\n reason: \"item-press\",\n });\n setOpen(false, \"item-press\");\n return;\n }\n setValue(toggleItem(current.values, item, isEqual), {\n reason: \"item-press\",\n });\n if (current.inputValue.trim() !== \"\") {\n setInputValueState(\"\", { reason: \"input-clear\" });\n setOpen(false, \"item-press\");\n }\n },\n [setValue, setInputValueState, setOpen, isEqual],\n );\n const clear = useCallback(\n (reason: ChangeReason) => {\n setInputValueState(\"\", { reason });\n setValue(latest.current.multiple ? [] : null, { reason });\n setHighlighted(null);\n },\n [setInputValueState, setValue],\n );\n const removeAt = useCallback(\n (index: number, reason: ChangeReason) => {\n setValue(\n latest.current.values.filter((_, at) => at !== index),\n { reason },\n );\n },\n [setValue],\n );\n const isSelected = useCallback(\n (item: unknown) => includesItem(values, item, isEqual),\n [values, isEqual],\n );\n const markTyped = useCallback(() => setTyped(true), []);\n\n const filter = useMemo(\n () =>\n filterProp === undefined\n ? containsFilter<unknown>(locale)\n : (filterProp as ItemFilter<unknown> | null),\n [filterProp, locale],\n );\n const entries = useMemo(() => {\n if (items === undefined) {\n return NONE;\n }\n const query = inputValue.trim();\n // a single combobox that opened on its selected item's label shows every item\n const whole =\n !multiple &&\n !typed &&\n values.length > 0 &&\n queryIsLabel(label(values[0]), query, locale);\n return filterItems(items as readonly unknown[], whole ? \"\" : query, {\n filter,\n limit,\n itemToString: label,\n });\n }, [\n items,\n inputValue,\n multiple,\n typed,\n values,\n label,\n locale,\n filter,\n limit,\n ]);\n\n const reset = useRef({\n defaultValue,\n setValue,\n setInputValueState,\n label,\n markReset: field.reset,\n });\n reset.current = {\n defaultValue,\n setValue,\n setInputValueState,\n label,\n markReset: field.reset,\n };\n const triggerElement = root.trigger;\n useEffect(() => {\n const element = hidden.current;\n if (element === null) {\n return undefined;\n }\n return bridgeForm(element, {\n reset: () => {\n const current = reset.current;\n current.markReset();\n current.setValue(current.defaultValue, { reason: \"none\" });\n current.setInputValueState(\n latest.current.multiple\n ? \"\"\n : current.label(current.defaultValue),\n { reason: \"none\" },\n );\n },\n invalid: () => triggerElement,\n });\n }, [triggerElement]);\n\n const context = useMemo(\n () => ({\n ...root,\n setOpen,\n field,\n multiple,\n autoHighlight,\n value,\n values,\n inputValue,\n setInputValue,\n disabled,\n highlighted,\n setHighlighted,\n isSelected,\n choose,\n clear,\n removeAt,\n label,\n hasItems: items !== undefined,\n entries,\n markTyped,\n items: registered,\n list,\n setList,\n button,\n setButton,\n inputGroup,\n setInputGroup,\n chips,\n setChips,\n clearButton,\n setClearButton,\n listId,\n pendingHighlight,\n placed,\n setPlaced,\n itemCount,\n setItemCount,\n }),\n [\n root,\n setOpen,\n field,\n multiple,\n autoHighlight,\n value,\n values,\n inputValue,\n setInputValue,\n disabled,\n highlighted,\n isSelected,\n choose,\n clear,\n removeAt,\n label,\n items,\n entries,\n markTyped,\n registered,\n list,\n button,\n inputGroup,\n chips,\n clearButton,\n listId,\n placed,\n itemCount,\n ],\n );\n const fieldName = field.name ?? name;\n return (\n <ComboboxContext.Provider value={context}>\n {children}\n <input\n ref={hidden}\n aria-hidden=\"true\"\n tabIndex={-1}\n name={multiple ? undefined : fieldName}\n value={multiple ? \"\" : formValue(value)}\n required={multiple ? required && values.length === 0 : required}\n disabled={disabled}\n onChange={NOOP}\n style={VISUALLY_HIDDEN_INPUT_STYLE}\n data-primitives-part=\"combobox-hidden-input\"\n />\n {multiple && fieldName !== undefined\n ? values.map((item, index) => (\n <input\n // biome-ignore lint/suspicious/noArrayIndexKey: two values may share a form value\n key={index}\n type=\"hidden\"\n name={fieldName}\n value={formValue(item)}\n disabled={disabled}\n data-primitives-part=\"combobox-hidden-input\"\n />\n ))\n : null}\n </ComboboxContext.Provider>\n );\n}\n","import { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\n\n/** Between groups; no role of its own (a `listbox` owns only groups and options). */\nexport function ComboboxSeparator(props: PartProps<Record<string, never>>) {\n return renderElement(\n \"div\",\n props,\n {},\n {\n role: \"presentation\",\n \"data-orientation\": \"horizontal\",\n \"data-primitives-part\": \"combobox-separator\",\n },\n );\n}\n","import { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\n\n/** A polite live region for the consumer's text (spec/combobox.md). */\nexport function ComboboxStatus(props: PartProps<Record<string, never>>) {\n return renderElement(\n \"div\",\n props,\n {},\n {\n role: \"status\",\n \"aria-live\": \"polite\",\n \"aria-atomic\": \"true\",\n \"data-primitives-part\": \"combobox-status\",\n },\n );\n}\n","import type { MouseEvent as ReactMouseEvent } from \"react\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport { ComboboxContext } from \"./combobox-context.ts\";\n\n/** Toggles the list; not in the tab order, keeps focus in the input. */\nexport function ComboboxTrigger(\n props: PartProps<{ open: boolean; disabled: boolean }>,\n) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Trigger\");\n const { open, disabled } = context;\n return renderElement(\n \"button\",\n props,\n { open, disabled },\n {\n type: \"button\",\n tabIndex: -1,\n disabled,\n \"aria-expanded\": open,\n \"aria-controls\": context.listId,\n \"data-primitives-part\": \"combobox-trigger\",\n ...stateAttributes({ \"popup-open\": open, disabled }),\n onPointerDown: (event: PointerEvent) => event.preventDefault(),\n onClick: (event: ReactMouseEvent) => {\n context.pendingHighlight.current = null;\n context.setOpen(!open, \"trigger-press\", event.nativeEvent);\n context.trigger?.focus();\n },\n },\n context.setButton,\n );\n}\n","import type { ReactNode } from \"react\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { ComboboxContext } from \"./combobox-context.ts\";\n\nexport interface ComboboxValueProps<Value = unknown> {\n /**\n * A node, or a render function of the value (an item or `null`, or the list of items). `Value`\n * is the consumer's own type, inferred from the function's parameter.\n */\n children?: ReactNode | ((value: Value) => ReactNode);\n}\n\n/** Renders the value: its label (labels joined with \", \"), or the consumer's render function. */\nexport function ComboboxValue<Value = unknown>({\n children,\n}: ComboboxValueProps<Value>) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Value\");\n if (typeof children === \"function\") {\n // the Root holds the consumer's items: the render function names their type\n return <>{children(context.value as Value)}</>;\n }\n if (children !== undefined) {\n return <>{children}</>;\n }\n return <>{context.values.map(context.label).join(\", \")}</>;\n}\n","import { ComboboxChip } from \"./combobox-chip.tsx\";\nimport { ComboboxChipRemove } from \"./combobox-chip-remove.tsx\";\nimport { ComboboxChips } from \"./combobox-chips.tsx\";\nimport { ComboboxClear } from \"./combobox-clear.tsx\";\nimport { ComboboxEmpty } from \"./combobox-empty.tsx\";\nimport { ComboboxGroup } from \"./combobox-group.tsx\";\nimport { ComboboxGroupLabel } from \"./combobox-group-label.tsx\";\nimport { ComboboxInput } from \"./combobox-input.tsx\";\nimport { ComboboxInputGroup } from \"./combobox-input-group.tsx\";\nimport { ComboboxItem } from \"./combobox-item.tsx\";\nimport { ComboboxItemIndicator } from \"./combobox-item-indicator.tsx\";\nimport { ComboboxList } from \"./combobox-list.tsx\";\nimport { ComboboxPopup } from \"./combobox-popup.tsx\";\nimport { ComboboxPortal } from \"./combobox-portal.tsx\";\nimport { ComboboxPositioner } from \"./combobox-positioner.tsx\";\nimport { ComboboxRoot } from \"./combobox-root.tsx\";\nimport { ComboboxSeparator } from \"./combobox-separator.tsx\";\nimport { ComboboxStatus } from \"./combobox-status.tsx\";\nimport { ComboboxTrigger } from \"./combobox-trigger.tsx\";\nimport { ComboboxValue } from \"./combobox-value.tsx\";\n\n/** spec/combobox.md */\nexport const Combobox = {\n Root: ComboboxRoot,\n InputGroup: ComboboxInputGroup,\n Input: ComboboxInput,\n Trigger: ComboboxTrigger,\n Clear: ComboboxClear,\n Chips: ComboboxChips,\n Chip: ComboboxChip,\n ChipRemove: ComboboxChipRemove,\n Value: ComboboxValue,\n Status: ComboboxStatus,\n Portal: ComboboxPortal,\n Positioner: ComboboxPositioner,\n Popup: ComboboxPopup,\n Empty: ComboboxEmpty,\n List: ComboboxList,\n Group: ComboboxGroup,\n GroupLabel: ComboboxGroupLabel,\n Separator: ComboboxSeparator,\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AG,gBAAgB;GAAE,cAAc;GAAM;EAAS,CAAC;EACnD,gBAAgB,UAAwB,MAAM,eAAe;EAC7D,UAAU,UAA2B;GACjC,QAAQ,iBAAiB,UAAU;GACnC,QAAQ,QAAQ,CAAC,MAAM,iBAAiB,MAAM,WAAW;GACzD,QAAQ,SAAS,MAAM;EAC3B;CACJ,GACA,QAAQ,SACZ;AACJ;;;ACpBA,SAAgB,cAA+B,EAC3C,YAC0B;CAC1B,MAAM,UAAU,mBAAmB,iBAAiB,gBAAgB;CACpE,IAAI,OAAO,aAAa,YAEpB,OAAO,oBAAA,UAAA,EAAA,UAAG,SAAS,QAAQ,KAAc,EAAI,CAAA;CAEjD,IAAI,aAAa,KAAA,GACb,OAAO,oBAAA,UAAA,EAAG,SAAW,CAAA;CAEzB,OAAO,oBAAA,UAAA,EAAA,UAAG,QAAQ,OAAO,IAAI,QAAQ,KAAK,CAAC,CAAC,KAAK,IAAI,EAAI,CAAA;AAC7D;;;ACHA,MAAa,WAAW;CACpB,MAAM;CACN,YAAY;CACZ,OAAO;CACP,SAAS;CACT,OAAO;CACP,OAAO;CACP,MAAM;CACN,YAAY;CACZ,OAAO;CACP,QAAQ;CACR,QAAQ;CACR,YAAY;CACZ,OAAO;CACP,OAAO;CACP,MAAM;CACN,OAAO;CACP,YAAY;CACZ,WAAW;CACX,MAAM;CACN,eAAe;AACnB"}
@@ -100,6 +100,8 @@ interface ComboboxRootCommonProps<Item> extends OverlayRootProps {
100
100
  /** The most items the list renders; `-1` for no limit. */
101
101
  limit?: number;
102
102
  locale?: string;
103
+ /** Typing highlights the first item the filter keeps, so Enter chooses it (default `false`). */
104
+ autoHighlight?: boolean;
103
105
  inputValue?: string;
104
106
  defaultInputValue?: string;
105
107
  onInputValueChange?: (inputValue: string, details: ChangeDetails) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fragiola/primitives-react",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Headless, accessible React primitives (Dialog, Tabs, ...) of Fragiola Primitives: behaviour and ARIA, one entry per component, styled by you.",
5
5
  "keywords": [
6
6
  "react",
@@ -529,7 +529,7 @@
529
529
  "LICENSE"
530
530
  ],
531
531
  "dependencies": {
532
- "@fragiola/primitives": "0.1.0"
532
+ "@fragiola/primitives": "0.2.0"
533
533
  },
534
534
  "peerDependencies": {
535
535
  "react": "^19.0.0",
@@ -1 +0,0 @@
1
- {"version":3,"file":"number-field-BUNkL15K.js","names":[],"sources":["../src/components/number-field/number-field-context.ts","../src/components/number-field/use-stepper-button.ts","../src/components/number-field/number-field-decrement.tsx","../src/components/number-field/number-field-group.tsx","../src/components/number-field/number-field-increment.tsx","../src/components/number-field/number-field-input.tsx","../src/components/number-field/number-field-root.tsx","../src/components/number-field/number-field-scrub-area.tsx","../src/components/number-field/number-field-scrub-area-cursor.tsx","../src/components/number-field/parts.ts"],"sourcesContent":["import type { ScrubPoint } from \"@fragiola/primitives/number\";\nimport { createContext } from \"react\";\nimport type { FieldControlBinding } from \"../../hooks/use-field-control.ts\";\nimport type { ChangeReason } from \"../../utils/change-details.ts\";\n\n/** The state every part renders with (spec/number-field.md, \"State attributes and ARIA\"). */\nexport interface NumberFieldState {\n /** The value: a number, or `null` while empty. */\n value: number | null;\n /** The Input's text. */\n inputValue: string;\n disabled: boolean;\n readOnly: boolean;\n required: boolean;\n scrubbing: boolean;\n}\n\nexport interface NumberFieldContextValue extends NumberFieldState {\n inputId: string;\n min: number | undefined;\n max: number | undefined;\n locale: string | undefined;\n format: Intl.NumberFormatOptions | undefined;\n /** The value as `format` writes it (`aria-valuetext`), `\"\"` while empty. */\n formattedValue: string;\n allowWheelScrub: boolean;\n field: FieldControlBinding;\n /** The state attributes and the field's, for every part. */\n attributes: Record<`data-${string}`, string>;\n /** The amount of one step for an event's modifier keys (Alt: small, Shift: large). */\n amount: (\n event: { altKey?: boolean; shiftKey?: boolean } | undefined,\n ) => number;\n /**\n * Steps `times` times by `amount` (negative: down) from the value (or the typed text): returns\n * whether another step that way could still change it (a bound not reached).\n */\n stepBy: (\n amount: number,\n reason: ChangeReason,\n event: Event | undefined,\n times?: number,\n ) => boolean;\n /** Sets the value, as a step does (Home and End set a bound). */\n stepTo: (\n value: number,\n reason: ChangeReason,\n event: Event | undefined,\n ) => void;\n /** The Input's text changed. */\n onInputText: (text: string, event: Event) => boolean;\n /** The Input lost focus. */\n onInputBlur: (event: Event) => void;\n setInputElement: (element: HTMLInputElement | null) => void;\n setScrubbing: (scrubbing: boolean) => void;\n cursor: ScrubPoint | null;\n setCursor: (point: ScrubPoint | null) => void;\n}\n\nexport const NumberFieldContext = createContext<NumberFieldContextValue | null>(\n null,\n);\n\n/** The state the parts render with. */\nexport function numberFieldState(\n context: NumberFieldContextValue,\n): NumberFieldState {\n return {\n value: context.value,\n inputValue: context.inputValue,\n disabled: context.disabled,\n readOnly: context.readOnly,\n required: context.required,\n scrubbing: context.scrubbing,\n };\n}\n","import { watchAutoRepeat } from \"@fragiola/primitives/number\";\nimport { useEffect, useRef, useState } from \"react\";\nimport type { NumberFieldContextValue } from \"./number-field-context.ts\";\n\n/**\n * An Increment's or a Decrement's press and hold (spec/number-field.md, \"Pointer\"), and whether\n * it is disabled: the field disabled or read-only, or its step would change nothing.\n */\nexport function useStepperButton(\n context: NumberFieldContextValue,\n direction: 1 | -1,\n) {\n const [element, setElement] = useState<HTMLElement | null>(null);\n const latest = useRef(context);\n latest.current = context;\n useEffect(() => {\n if (element === null) {\n return undefined;\n }\n return watchAutoRepeat(element, {\n onStep: (event) => {\n const current = latest.current;\n const amount = current.amount(event as MouseEvent);\n return current.stepBy(\n direction * amount,\n direction > 0 ? \"increment-press\" : \"decrement-press\",\n event,\n );\n },\n });\n }, [element, direction]);\n const { value, min, max } = context;\n const atBound =\n value !== null &&\n (direction > 0\n ? max !== undefined && value >= max\n : min !== undefined && value <= min);\n return {\n ref: setElement,\n disabled: context.disabled || context.readOnly || atBound,\n };\n}\n","import { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport {\n NumberFieldContext,\n type NumberFieldState,\n numberFieldState,\n} from \"./number-field-context.ts\";\nimport { useStepperButton } from \"./use-stepper-button.ts\";\n\nexport type NumberFieldDecrementProps = PartProps<NumberFieldState>;\n\n/**\n * Steps the value down, once or held (spec/number-field.md, \"Pointer\"); out of the tab order, its\n * name the consumer's.\n */\nexport function NumberFieldDecrement(props: NumberFieldDecrementProps) {\n const context = useRequiredContext(\n NumberFieldContext,\n \"NumberField.Decrement\",\n );\n const button = useStepperButton(context, -1);\n return renderElement(\n \"button\",\n props,\n numberFieldState(context),\n {\n type: \"button\",\n tabIndex: -1,\n disabled: button.disabled,\n \"aria-controls\": context.inputId,\n \"data-primitives-part\": \"number-field-decrement\",\n ...context.attributes,\n },\n button.ref,\n );\n}\n","import { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport {\n NumberFieldContext,\n type NumberFieldState,\n numberFieldState,\n} from \"./number-field-context.ts\";\n\nexport type NumberFieldGroupProps = PartProps<NumberFieldState>;\n\n/** Groups the Input with its buttons (`role=\"group\"`, spec/number-field.md). */\nexport function NumberFieldGroup(props: NumberFieldGroupProps) {\n const context = useRequiredContext(NumberFieldContext, \"NumberField.Group\");\n return renderElement(\"div\", props, numberFieldState(context), {\n role: \"group\",\n \"data-primitives-part\": \"number-field-group\",\n ...context.attributes,\n });\n}\n","import { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport {\n NumberFieldContext,\n type NumberFieldState,\n numberFieldState,\n} from \"./number-field-context.ts\";\nimport { useStepperButton } from \"./use-stepper-button.ts\";\n\nexport type NumberFieldIncrementProps = PartProps<NumberFieldState>;\n\n/**\n * Steps the value up, once or held (spec/number-field.md, \"Pointer\"); out of the tab order, its\n * name the consumer's.\n */\nexport function NumberFieldIncrement(props: NumberFieldIncrementProps) {\n const context = useRequiredContext(\n NumberFieldContext,\n \"NumberField.Increment\",\n );\n const button = useStepperButton(context, 1);\n return renderElement(\n \"button\",\n props,\n numberFieldState(context),\n {\n type: \"button\",\n tabIndex: -1,\n disabled: button.disabled,\n \"aria-controls\": context.inputId,\n \"data-primitives-part\": \"number-field-increment\",\n ...context.attributes,\n },\n button.ref,\n );\n}\n","import {\n type ChangeEvent,\n type FocusEvent,\n type KeyboardEvent,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport {\n NumberFieldContext,\n type NumberFieldState,\n numberFieldState,\n} from \"./number-field-context.ts\";\n\nexport type NumberFieldInputProps = PartProps<NumberFieldState>;\n\n/** The `spinbutton`: a text input with the formatted value (spec/number-field.md, the APG). */\nexport function NumberFieldInput(props: NumberFieldInputProps) {\n const context = useRequiredContext(NumberFieldContext, \"NumberField.Input\");\n const {\n value,\n min,\n max,\n disabled,\n readOnly,\n required,\n field,\n setInputElement,\n allowWheelScrub,\n } = context;\n const latest = useRef(context);\n latest.current = context;\n const element = useRef<HTMLInputElement | null>(null);\n const ref = useCallback(\n (node: HTMLElement | null) => {\n element.current = node as HTMLInputElement | null;\n setInputElement(node as HTMLInputElement | null);\n },\n [setInputElement],\n );\n\n // the wheel over the focused Input steps it, and the page does not scroll (a non-passive\n // listener, which React's `onWheel` cannot be)\n useEffect(() => {\n const input = element.current;\n if (input === null || !allowWheelScrub) {\n return undefined;\n }\n const onWheel = (event: WheelEvent) => {\n if (\n input.ownerDocument.activeElement !== input ||\n event.deltaY === 0\n ) {\n return;\n }\n const current = latest.current;\n if (current.disabled || current.readOnly) {\n return;\n }\n event.preventDefault();\n const amount = current.amount(event);\n current.stepBy(event.deltaY < 0 ? amount : -amount, \"wheel\", event);\n };\n input.addEventListener(\"wheel\", onWheel, { passive: false });\n return () => input.removeEventListener(\"wheel\", onWheel);\n }, [allowWheelScrub]);\n\n const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n const current = latest.current;\n if (current.disabled || current.readOnly) {\n return;\n }\n const native = event.nativeEvent;\n const amount = current.amount(native);\n switch (event.key) {\n case \"ArrowUp\":\n current.stepBy(amount, \"keyboard\", native);\n break;\n case \"ArrowDown\":\n current.stepBy(-amount, \"keyboard\", native);\n break;\n case \"PageUp\":\n current.stepBy(\n current.amount({ shiftKey: true }),\n \"keyboard\",\n native,\n );\n break;\n case \"PageDown\":\n current.stepBy(\n -current.amount({ shiftKey: true }),\n \"keyboard\",\n native,\n );\n break;\n case \"Home\":\n if (current.min === undefined) {\n return;\n }\n current.stepTo(current.min, \"keyboard\", native);\n break;\n case \"End\":\n if (current.max === undefined) {\n return;\n }\n current.stepTo(current.max, \"keyboard\", native);\n break;\n default:\n return;\n }\n event.preventDefault();\n };\n\n const integer =\n context.format?.maximumFractionDigits === 0 &&\n min !== undefined &&\n min >= 0;\n return renderElement(\n \"input\",\n props,\n numberFieldState(context),\n {\n id: context.inputId,\n type: \"text\",\n role: \"spinbutton\",\n inputMode: integer ? \"numeric\" : \"decimal\",\n autoComplete: \"off\",\n autoCorrect: \"off\",\n spellCheck: \"false\",\n value: context.inputValue,\n disabled,\n readOnly,\n \"aria-valuenow\": value ?? undefined,\n \"aria-valuemin\": min,\n \"aria-valuemax\": max,\n \"aria-valuetext\":\n value === null ? undefined : context.formattedValue,\n \"aria-required\": required ? \"true\" : undefined,\n \"aria-readonly\": readOnly ? \"true\" : undefined,\n ...field.aria,\n \"data-primitives-part\": \"number-field-input\",\n ...context.attributes,\n onChange: (event: ChangeEvent<HTMLInputElement>) => {\n latest.current.onInputText(\n event.currentTarget.value,\n event.nativeEvent,\n );\n },\n onKeyDown,\n onFocus: field.onFocus,\n onBlur: (event: FocusEvent<HTMLInputElement>) => {\n latest.current.onInputBlur(event.nativeEvent);\n field.onBlur();\n },\n },\n ref,\n );\n}\n","import {\n bridgeForm,\n VISUALLY_HIDDEN_INPUT_STYLE,\n} from \"@fragiola/primitives/form\";\nimport {\n clampNumber,\n formatNumber,\n isNumberText,\n parseNumber,\n type ScrubPoint,\n stepNumber,\n} from \"@fragiola/primitives/number\";\nimport { useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { useControllableState } from \"../../hooks/use-controllable-state.ts\";\nimport { useFieldControl } from \"../../hooks/use-field-control.ts\";\nimport type {\n ChangeDetails,\n ChangeReason,\n} from \"../../utils/change-details.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport {\n NumberFieldContext,\n type NumberFieldContextValue,\n type NumberFieldState,\n} from \"./number-field-context.ts\";\n\nexport interface NumberFieldRootProps extends PartProps<NumberFieldState> {\n /** A number, or `null` while empty. */\n value?: number | null;\n defaultValue?: number | null;\n onValueChange?: (value: number | null, details: ChangeDetails) => void;\n min?: number;\n max?: number;\n /** The amount of a step (default `1`). */\n step?: number;\n /** The amount of a step with Alt (default `0.1`). */\n smallStep?: number;\n /** The amount of a step with Shift, Page Up and Page Down (default `10`). */\n largeStep?: number;\n /** A step from a value off the grid goes to the grid's next point. */\n snapOnStep?: boolean;\n /** A typed value outside `[min, max]` is clamped on blur (default `true`). */\n clampOnBlur?: boolean;\n /** How the Input writes the value; default: the plain number in the locale. */\n format?: Intl.NumberFormatOptions;\n /** The locale of the format and the parsing (BCP 47; default: the runtime's). */\n locale?: string;\n /** The mouse wheel steps the value over the focused Input. */\n allowWheelScrub?: boolean;\n required?: boolean;\n readOnly?: boolean;\n disabled?: boolean;\n name?: string;\n /** The Input's `id`. */\n id?: string;\n}\n\nconst NOOP = () => {};\n\n/**\n * Holds a NumberField's value, its text and its hidden form input (spec/number-field.md, the APG\n * spinbutton).\n */\nexport function NumberFieldRoot({\n value: valueProp,\n defaultValue = null,\n onValueChange,\n min,\n max,\n step = 1,\n smallStep = 0.1,\n largeStep = 10,\n snapOnStep = false,\n clampOnBlur = true,\n format,\n locale,\n allowWheelScrub = false,\n required = false,\n readOnly = false,\n disabled: disabledProp = false,\n name,\n id: idProp,\n children,\n ...props\n}: NumberFieldRootProps) {\n const generatedId = useId();\n const inputId = idProp ?? generatedId;\n const [value, setOwnValue] = useControllableState(\n valueProp,\n defaultValue,\n onValueChange,\n );\n // the text the user typed, until the blur formats it (`null`: the formatted value)\n const [typed, setTyped] = useState<string | null>(null);\n const [scrubbing, setScrubbing] = useState(false);\n const [cursor, setCursor] = useState<ScrubPoint | null>(null);\n const [input, setInputElement] = useState<HTMLInputElement | null>(null);\n const hidden = useRef<HTMLInputElement>(null);\n const field = useFieldControl({\n id: inputId,\n labelable: true,\n value,\n filled: value !== null,\n input: () => hidden.current,\n focusTarget: () => input,\n });\n const disabled = disabledProp || field.disabled;\n const formattedValue = formatNumber(value, { locale, format });\n const inputValue = typed ?? formattedValue;\n\n // the value as of the last change, so a held button's steps never read a stale render\n const current = useRef(value);\n current.current = value;\n const latest = useRef({\n value,\n typed,\n min,\n max,\n step,\n smallStep,\n largeStep,\n snapOnStep,\n clampOnBlur,\n format,\n locale,\n disabled,\n readOnly,\n defaultValue,\n setOwnValue,\n reset: field.reset,\n });\n latest.current = {\n value,\n typed,\n min,\n max,\n step,\n smallStep,\n largeStep,\n snapOnStep,\n clampOnBlur,\n format,\n locale,\n disabled,\n readOnly,\n defaultValue,\n setOwnValue,\n reset: field.reset,\n };\n\n const actions = useMemo(() => {\n const setValue = (next: number | null, details: ChangeDetails) => {\n current.current = next;\n latest.current.setOwnValue(next, details);\n // an override for the steps of this task only: a consumer that refused the value\n // renders nothing, and the next task steps from the value it kept\n setTimeout(() => {\n current.current = latest.current.value;\n });\n };\n /** The value a step starts from: the typed text when it reads as a number. */\n const base = (): number | null => {\n const {\n typed: text,\n locale: lang,\n format: options,\n } = latest.current;\n if (text === null) {\n return current.current;\n }\n const parsed = parseNumber(text, { locale: lang, format: options });\n return parsed === null || Number.isNaN(parsed)\n ? current.current\n : parsed;\n };\n return {\n setValue,\n amount: (\n event: { altKey?: boolean; shiftKey?: boolean } | undefined,\n ) => {\n const {\n step: one,\n smallStep: small,\n largeStep: large,\n } = latest.current;\n return event?.altKey ? small : event?.shiftKey ? large : one;\n },\n stepBy: (\n amount: number,\n reason: ChangeReason,\n event: Event | undefined,\n times = 1,\n ) => {\n const state = latest.current;\n if (state.disabled || state.readOnly) {\n return false;\n }\n let next = base();\n for (let index = 0; index < times; index += 1) {\n next = stepNumber(next, amount, {\n min: state.min,\n max: state.max,\n snapOnStep: state.snapOnStep,\n });\n }\n setTyped(null);\n if (!Object.is(next, current.current)) {\n setValue(next, { reason, event });\n }\n const bound = amount > 0 ? state.max : state.min;\n return bound === undefined || next !== bound;\n },\n stepTo: (\n next: number,\n reason: ChangeReason,\n event: Event | undefined,\n ) => {\n const state = latest.current;\n if (state.disabled || state.readOnly) {\n return;\n }\n setTyped(null);\n if (!Object.is(next, current.current)) {\n setValue(next, { reason, event });\n }\n },\n onInputText: (text: string, event: Event) => {\n const state = latest.current;\n if (state.disabled || state.readOnly) {\n return false;\n }\n const options = { locale: state.locale, format: state.format };\n if (!isNumberText(text, options)) {\n // refused: the text stays as it was (spec/number-field.md, \"Typing\")\n return false;\n }\n setTyped(text);\n if (text.trim() === \"\") {\n setValue(null, { reason: \"input-clear\", event });\n return true;\n }\n const parsed = parseNumber(text, options);\n if (parsed !== null && !Number.isNaN(parsed)) {\n setValue(parsed, { reason: \"input-change\", event });\n }\n return true;\n },\n onInputBlur: (event: Event) => {\n const state = latest.current;\n if (state.typed === null) {\n return;\n }\n let next = base();\n if (state.clampOnBlur && next !== null) {\n next = clampNumber(next, state.min, state.max);\n }\n setTyped(null);\n if (!Object.is(next, current.current)) {\n setValue(next, { reason: \"input-blur\", event });\n }\n },\n };\n }, []);\n\n // a form reset returns it to its default, and writes the rendered value back (Switch's way)\n useEffect(() => {\n const element = hidden.current;\n if (element === null) {\n return undefined;\n }\n return bridgeForm(element, {\n reset: () => {\n const state = latest.current;\n state.reset();\n setTyped(null);\n actions.setValue(state.defaultValue, { reason: \"none\" });\n // the rendered value, which a render that changes it patches again (a controlled\n // field that refuses the reset keeps its input)\n element.value = state.value === null ? \"\" : String(state.value);\n },\n invalid: () => input,\n });\n }, [input, actions]);\n\n const state: NumberFieldState = {\n value,\n inputValue,\n disabled,\n readOnly,\n required,\n scrubbing,\n };\n const attributes = {\n ...stateAttributes({\n disabled,\n readonly: readOnly,\n required,\n scrubbing,\n }),\n ...field.attributes,\n };\n const context: NumberFieldContextValue = {\n ...state,\n inputId,\n min,\n max,\n locale,\n format,\n formattedValue,\n allowWheelScrub,\n field,\n attributes,\n amount: actions.amount,\n stepBy: actions.stepBy,\n stepTo: actions.stepTo,\n onInputText: actions.onInputText,\n onInputBlur: actions.onInputBlur,\n setInputElement,\n setScrubbing,\n cursor,\n setCursor,\n };\n const formName = field.name ?? name;\n return (\n <NumberFieldContext.Provider value={context}>\n {renderElement(\"div\", { ...props, children }, state, {\n \"data-primitives-part\": \"number-field-root\",\n ...attributes,\n })}\n <input\n ref={hidden}\n type=\"number\"\n aria-hidden=\"true\"\n tabIndex={-1}\n name={formName}\n value={value === null ? \"\" : String(value)}\n min={min}\n max={max}\n step=\"any\"\n required={required}\n disabled={disabled}\n onChange={NOOP}\n onFocus={() => input?.focus()}\n style={VISUALLY_HIDDEN_INPUT_STYLE}\n data-primitives-part=\"number-field-hidden-input\"\n />\n </NumberFieldContext.Provider>\n );\n}\n","import { watchScrub } from \"@fragiola/primitives/number\";\nimport { type MouseEvent, useEffect, useRef, useState } from \"react\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport {\n NumberFieldContext,\n type NumberFieldState,\n numberFieldState,\n} from \"./number-field-context.ts\";\n\nexport interface NumberFieldScrubAreaProps extends PartProps<NumberFieldState> {\n /** The axis the pointer scrubs along (default `\"horizontal\"`). */\n direction?: \"horizontal\" | \"vertical\";\n /** The pixels one step takes (default `2`). */\n pixelSensitivity?: number;\n}\n\nconst STYLE = { touchAction: \"none\", userSelect: \"none\" } as const;\n\n/** A press dragged along it steps the value (spec/number-field.md, \"Pointer\": scrub). */\nexport function NumberFieldScrubArea({\n direction = \"horizontal\",\n pixelSensitivity = 2,\n ...props\n}: NumberFieldScrubAreaProps) {\n const context = useRequiredContext(\n NumberFieldContext,\n \"NumberField.ScrubArea\",\n );\n const [element, setElement] = useState<HTMLElement | null>(null);\n const latest = useRef(context);\n latest.current = context;\n useEffect(() => {\n if (element === null) {\n return undefined;\n }\n return watchScrub(element, {\n direction,\n pixelSensitivity,\n onStart: () => {\n const current = latest.current;\n if (current.disabled || current.readOnly) {\n return false;\n }\n current.setScrubbing(true);\n return true;\n },\n onScrub: (steps, event) => {\n const current = latest.current;\n const amount = current.amount(event);\n current.stepBy(\n steps > 0 ? amount : -amount,\n \"scrub\",\n event,\n Math.abs(steps),\n );\n },\n onEnd: () => latest.current.setScrubbing(false),\n onCursor: (point) => latest.current.setCursor(point),\n });\n }, [element, direction, pixelSensitivity]);\n return renderElement(\n \"span\",\n props,\n numberFieldState(context),\n {\n style: STYLE,\n // a press keeps the focus where it is\n onMouseDown: (event: MouseEvent<HTMLElement>) => {\n if (event.button === 0) {\n event.preventDefault();\n }\n },\n \"data-primitives-part\": \"number-field-scrub-area\",\n ...context.attributes,\n },\n setElement,\n );\n}\n","import { createPortal } from \"react-dom\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport {\n NumberFieldContext,\n type NumberFieldState,\n numberFieldState,\n} from \"./number-field-context.ts\";\n\nexport type NumberFieldScrubAreaCursorProps = PartProps<NumberFieldState>;\n\n/**\n * The virtual cursor of a locked scrub (spec/number-field.md, \"Pointer\"), in a portal into `body`:\n * rendered only while a mouse scrubs with the pointer locked.\n */\nexport function NumberFieldScrubAreaCursor(\n props: NumberFieldScrubAreaCursorProps,\n) {\n const context = useRequiredContext(\n NumberFieldContext,\n \"NumberField.ScrubAreaCursor\",\n );\n const { cursor } = context;\n if (cursor === null || typeof document === \"undefined\") {\n return null;\n }\n return createPortal(\n renderElement(\"span\", props, numberFieldState(context), {\n style: {\n position: \"fixed\",\n top: 0,\n left: 0,\n pointerEvents: \"none\",\n transform: `translate3d(${cursor.x}px, ${cursor.y}px, 0)`,\n },\n \"data-primitives-part\": \"number-field-scrub-area-cursor\",\n ...context.attributes,\n }),\n document.body,\n );\n}\n","import { NumberFieldDecrement } from \"./number-field-decrement.tsx\";\nimport { NumberFieldGroup } from \"./number-field-group.tsx\";\nimport { NumberFieldIncrement } from \"./number-field-increment.tsx\";\nimport { NumberFieldInput } from \"./number-field-input.tsx\";\nimport { NumberFieldRoot } from \"./number-field-root.tsx\";\nimport { NumberFieldScrubArea } from \"./number-field-scrub-area.tsx\";\nimport { NumberFieldScrubAreaCursor } from \"./number-field-scrub-area-cursor.tsx\";\n\n/** spec/number-field.md */\nexport const NumberField = {\n Root: NumberFieldRoot,\n Group: NumberFieldGroup,\n Input: NumberFieldInput,\n Increment: NumberFieldIncrement,\n Decrement: NumberFieldDecrement,\n ScrubArea: NumberFieldScrubArea,\n ScrubAreaCursor: NumberFieldScrubAreaCursor,\n};\n"],"mappings":";;;;;;;;;;;AA2DA,MAAa,qBAAqB,cAC9B,IACJ;;AAGA,SAAgB,iBACZ,SACgB;CAChB,OAAO;EACH,OAAO,QAAQ;EACf,YAAY,QAAQ;EACpB,UAAU,QAAQ;EAClB,UAAU,QAAQ;EAClB,UAAU,QAAQ;EAClB,WAAW,QAAQ;CACvB;AACJ;;;;;;ACnEA,SAAgB,iBACZ,SACA,WACF;CACE,MAAM,CAAC,SAAS,cAAc,SAA6B,IAAI;CAC/D,MAAM,SAAS,OAAO,OAAO;CAC7B,OAAO,UAAU;CACjB,gBAAgB;EACZ,IAAI,YAAY,MACZ;EAEJ,OAAO,gBAAgB,SAAS,EAC5B,SAAS,UAAU;GACf,MAAM,UAAU,OAAO;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,OAAO,aAAa,aACvC,OAAO;CAEX,OAAO,aACH,cAAc,QAAQ,OAAO,iBAAiB,OAAO,GAAG;EACpD,OAAO;GACH,UAAU;GACV,KAAK;GACL,MAAM;GACN,eAAe;GACf,WAAW,eAAe,OAAO,EAAE,MAAM,OAAO,EAAE;EACtD;EACA,wBAAwB;EACxB,GAAG,QAAQ;CACf,CAAC,GACD,SAAS,IACb;AACJ;;;AC/BA,MAAa,cAAc;CACvB,MAAM;CACN,OAAO;CACP,OAAO;CACP,WAAW;CACX,WAAW;CACX,WAAW;CACX,iBAAiB;AACrB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"parts-VT0Ohb06.js","names":[],"sources":["../src/components/combobox/combobox-context.ts","../src/components/combobox/combobox-chip.tsx","../src/components/combobox/combobox-chip-remove.tsx","../src/components/combobox/combobox-chips.tsx","../src/components/combobox/combobox-clear.tsx","../src/components/combobox/combobox-empty.tsx","../src/components/combobox/combobox-group.tsx","../src/components/combobox/combobox-group-label.tsx","../src/components/combobox/combobox-input.tsx","../src/components/combobox/combobox-input-group.tsx","../src/components/combobox/combobox-item.tsx","../src/components/combobox/combobox-item-indicator.tsx","../src/components/combobox/combobox-list.tsx","../src/components/combobox/combobox-popup.tsx","../src/components/combobox/combobox-portal.tsx","../src/components/combobox/combobox-positioner.tsx","../src/components/combobox/combobox-root.tsx","../src/components/combobox/combobox-separator.tsx","../src/components/combobox/combobox-status.tsx","../src/components/combobox/combobox-trigger.tsx","../src/components/combobox/combobox-value.tsx","../src/components/combobox/parts.ts"],"sourcesContent":["import type { Align, Side } from \"@fragiola/primitives/positioning\";\nimport { createContext, type MutableRefObject } from \"react\";\nimport type { FieldControlBinding } from \"../../hooks/use-field-control.ts\";\nimport type { OverlayRoot } from \"../../hooks/use-overlay-root.ts\";\nimport type { ChangeReason } from \"../../utils/change-details.ts\";\n\n/** A rendered Item, as the Root knows it. */\nexport interface ComboboxItemInfo {\n value: unknown;\n disabled: boolean;\n id: string;\n}\n\n/** What the keyboard highlights once the list renders: the first, the last or the selected item. */\nexport type PendingHighlight = \"first\" | \"last\" | \"selected\" | null;\n\nexport interface ComboboxContextValue extends OverlayRoot {\n /** The enclosing field's binding, for the input (spec/field.md). */\n field: FieldControlBinding;\n multiple: boolean;\n /** The selected item (or `null`), or the selected items with `multiple`. */\n value: unknown;\n /** The selected items, as a list in both modes. */\n values: readonly unknown[];\n inputValue: string;\n setInputValue: (value: string, reason: ChangeReason) => void;\n disabled: boolean;\n /** The highlighted item's id. */\n highlighted: string | null;\n setHighlighted: (id: string | null) => void;\n isSelected: (item: unknown) => boolean;\n /** Chooses an item (spec/combobox.md, \"Choosing an item\"). */\n choose: (item: unknown) => void;\n /** Clears the text and the value. */\n clear: (reason: ChangeReason) => void;\n /** Removes the value at `index` (`multiple`). */\n removeAt: (index: number, reason: ChangeReason) => void;\n /** An item's text (`itemToStringLabel`). */\n label: (item: unknown) => string;\n /** Whether the Root has `items` (it filters them). */\n hasItems: boolean;\n /** The matching entries: items, or groups with their matching items. */\n entries: readonly unknown[];\n /** The input's text changed by typing since the list opened. */\n markTyped: () => void;\n items: Map<HTMLElement, ComboboxItemInfo>;\n list: HTMLElement | null;\n setList: (element: HTMLElement | null) => void;\n /** The Trigger button (the overlay root's `trigger` is the input). */\n button: HTMLElement | null;\n setButton: (element: HTMLElement | null) => void;\n inputGroup: HTMLElement | null;\n setInputGroup: (element: HTMLElement | null) => void;\n chips: HTMLElement | null;\n setChips: (element: HTMLElement | null) => void;\n clearButton: HTMLElement | null;\n setClearButton: (element: HTMLElement | null) => void;\n listId: string;\n pendingHighlight: MutableRefObject<PendingHighlight>;\n placed: { side: Side; align: Align };\n setPlaced: (placed: { side: Side; align: Align }) => void;\n /** Bumped when items register, so `data-empty` and the pending highlight follow. */\n itemCount: number;\n setItemCount: (count: number) => void;\n}\n\nexport const ComboboxContext = createContext<ComboboxContextValue | null>(null);\n\nexport interface ComboboxItemContextValue {\n selected: boolean;\n}\n\nexport const ComboboxItemContext =\n createContext<ComboboxItemContextValue | null>(null);\n\nexport interface ComboboxGroupContextValue {\n labelId: string;\n}\n\nexport const ComboboxGroupContext =\n createContext<ComboboxGroupContextValue | null>(null);\n\nexport interface ComboboxChipContextValue {\n /** The chip's element, read when a key or a press removes it. */\n element: () => HTMLElement | null;\n}\n\nexport const ComboboxChipContext =\n createContext<ComboboxChipContextValue | null>(null);\n\n/** The rendered items of the list, in order. */\nexport function orderedItems(\n context: ComboboxContextValue,\n): ComboboxItemInfo[] {\n if (context.list === null) {\n return [];\n }\n return [...context.list.querySelectorAll<HTMLElement>('[role=\"option\"]')]\n .map((element) => context.items.get(element))\n .filter((item): item is ComboboxItemInfo => item !== undefined);\n}\n\n/** The rendered chips, in value order. */\nexport function chipElements(context: ComboboxContextValue): HTMLElement[] {\n if (context.chips === null) {\n return [];\n }\n return [\n ...context.chips.querySelectorAll<HTMLElement>(\n '[data-primitives-part=\"combobox-chip\"]',\n ),\n ];\n}\n\n/**\n * A press on the InputGroup or the Chips, outside their buttons, chips and input: focuses the\n * input and opens the list (spec/combobox.md, \"Pointer\").\n */\nexport function pressToOpen(\n context: ComboboxContextValue,\n event: { target: EventTarget | null; preventDefault: () => void },\n): void {\n const target = event.target as Element | null;\n if (\n target === null ||\n target === context.trigger ||\n target.closest('button, [data-primitives-part=\"combobox-chip\"]') !==\n null\n ) {\n return;\n }\n event.preventDefault();\n if (context.disabled) {\n return;\n }\n context.trigger?.focus();\n openOnPress(context);\n}\n\n/** A press on the input opens the list, on the selected item in single mode. */\nexport function openOnPress(context: ComboboxContextValue): void {\n if (context.open || context.disabled) {\n return;\n }\n context.pendingHighlight.current = context.multiple ? null : \"selected\";\n context.setOpen(true, \"input-press\");\n}\n","import { chipKeyTarget } from \"@fragiola/primitives/collection\";\nimport { getDirection } from \"@fragiola/primitives/direction\";\nimport { type KeyboardEvent, useContext, useRef } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { DirectionContext } from \"../../direction/direction-context.ts\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport {\n ComboboxChipContext,\n ComboboxContext,\n chipElements,\n} from \"./combobox-context.ts\";\n\n/** One value of a `multiple` combobox; the arrows move between chips (spec/combobox.md). */\nexport function ComboboxChip(props: PartProps<{ disabled: boolean }>) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Chip\");\n const direction = useContext(DirectionContext);\n const element = useRef<HTMLElement | null>(null);\n const { disabled } = context;\n\n const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {\n if (disabled || event.ctrlKey || event.metaKey || event.altKey) {\n return;\n }\n const chips = chipElements(context);\n const index = chips.indexOf(event.currentTarget);\n const action = chipKeyTarget(\n event.key,\n index,\n chips.length,\n getDirection(event.currentTarget, direction) === \"rtl\",\n );\n if (action === null) {\n return;\n }\n // a printable character goes on to the input, focused below\n if (event.key.length !== 1 || event.key === \" \") {\n event.preventDefault();\n }\n if (action.remove) {\n flushSync(() => context.removeAt(index, \"none\"));\n }\n if (action.open) {\n context.setOpen(true, \"list-navigation\");\n }\n const target =\n action.focus === \"input\"\n ? context.trigger\n : chipElements(context)[action.focus];\n target?.focus();\n };\n\n return (\n <ComboboxChipContext.Provider\n value={{ element: () => element.current }}\n >\n {renderElement(\n \"div\",\n props,\n { disabled },\n {\n tabIndex: -1,\n \"aria-disabled\": disabled ? \"true\" : undefined,\n \"data-primitives-part\": \"combobox-chip\",\n ...stateAttributes({ disabled }),\n onKeyDown,\n },\n (node: HTMLElement | null) => {\n element.current = node;\n },\n )}\n </ComboboxChipContext.Provider>\n );\n}\n","import { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport {\n ComboboxChipContext,\n ComboboxContext,\n chipElements,\n} from \"./combobox-context.ts\";\n\n/** Removes its chip's value and returns focus to the input. */\nexport function ComboboxChipRemove(props: PartProps<{ disabled: boolean }>) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.ChipRemove\");\n const chip = useRequiredContext(ComboboxChipContext, \"Combobox.ChipRemove\");\n const { disabled } = context;\n return renderElement(\n \"button\",\n props,\n { disabled },\n {\n type: \"button\",\n tabIndex: -1,\n disabled,\n \"data-primitives-part\": \"combobox-chip-remove\",\n ...stateAttributes({ disabled }),\n onPointerDown: (event: PointerEvent) => event.preventDefault(),\n onClick: () => {\n const element = chip.element();\n const index =\n element === null\n ? -1\n : chipElements(context).indexOf(element);\n if (index >= 0) {\n context.removeAt(index, \"chip-remove-press\");\n }\n context.trigger?.focus();\n },\n },\n );\n}\n","import type { MouseEvent } from \"react\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { ComboboxContext, pressToOpen } from \"./combobox-context.ts\";\n\n/** `multiple`: holds the chips and the Input; a `toolbar` while it holds a chip. */\nexport function ComboboxChips(props: PartProps<Record<string, never>>) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Chips\");\n return renderElement(\n \"div\",\n props,\n {},\n {\n role: context.values.length > 0 ? \"toolbar\" : undefined,\n \"data-primitives-part\": \"combobox-chips\",\n onMouseDown: (event: MouseEvent) => pressToOpen(context, event),\n },\n context.setChips,\n );\n}\n","import { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport { ComboboxContext } from \"./combobox-context.ts\";\n\n/** Clears the text and the value; rendered only while there is a value (spec/combobox.md). */\nexport function ComboboxClear(props: PartProps<{ disabled: boolean }>) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Clear\");\n const { disabled } = context;\n if (context.values.length === 0) {\n return null;\n }\n return renderElement(\n \"button\",\n props,\n { disabled },\n {\n type: \"button\",\n tabIndex: -1,\n disabled,\n \"data-primitives-part\": \"combobox-clear\",\n ...stateAttributes({ disabled }),\n onPointerDown: (event: PointerEvent) => event.preventDefault(),\n onClick: () => {\n context.clear(\"clear-press\");\n context.trigger?.focus();\n },\n },\n context.setClearButton,\n );\n}\n","import { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { ComboboxContext } from \"./combobox-context.ts\";\n\n/**\n * A polite live region, always rendered; its children are shown only while the list is empty\n * (spec/combobox.md).\n */\nexport function ComboboxEmpty({\n children,\n ...props\n}: PartProps<Record<string, never>>) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Empty\");\n const empty = context.hasItems\n ? context.entries.length === 0\n : context.itemCount === 0;\n return renderElement(\n \"div\",\n { ...props, children: empty ? children : null },\n {},\n {\n role: \"status\",\n \"aria-live\": \"polite\",\n \"aria-atomic\": \"true\",\n \"data-primitives-part\": \"combobox-empty\",\n },\n );\n}\n","import { useId } from \"react\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { ComboboxGroupContext } from \"./combobox-context.ts\";\n\n/** A `group` of items, named by its GroupLabel (spec/combobox.md). */\nexport function ComboboxGroup(props: PartProps<Record<string, never>>) {\n const labelId = `${useId()}-label`;\n return (\n <ComboboxGroupContext.Provider value={{ labelId }}>\n {renderElement(\n \"div\",\n props,\n {},\n {\n role: \"group\",\n \"aria-labelledby\": labelId,\n \"data-primitives-part\": \"combobox-group\",\n },\n )}\n </ComboboxGroupContext.Provider>\n );\n}\n","import { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { ComboboxGroupContext } from \"./combobox-context.ts\";\n\n/** Names its Group. */\nexport function ComboboxGroupLabel(props: PartProps<Record<string, never>>) {\n const group = useRequiredContext(\n ComboboxGroupContext,\n \"Combobox.GroupLabel\",\n );\n return renderElement(\n \"div\",\n props,\n {},\n { id: group.labelId, \"data-primitives-part\": \"combobox-group-label\" },\n );\n}\n","import { chipArrows, stepThroughNone } from \"@fragiola/primitives/collection\";\nimport { getDirection } from \"@fragiola/primitives/direction\";\nimport { type ChangeEvent, type KeyboardEvent, useContext } from \"react\";\nimport { DirectionContext } from \"../../direction/direction-context.ts\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport {\n ComboboxContext,\n chipElements,\n openOnPress,\n orderedItems,\n type PendingHighlight,\n} from \"./combobox-context.ts\";\n\n/**\n * The `combobox`: keeps DOM focus while the list is open; the highlighted item is announced with\n * `aria-activedescendant` (spec/combobox.md, \"Keyboard\").\n */\nexport function ComboboxInput(\n props: PartProps<{ open: boolean; disabled: boolean }>,\n) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Input\");\n const direction = useContext(DirectionContext);\n const { open, disabled, highlighted, field } = context;\n const items = orderedItems(context);\n const active = items.find((item) => item.id === highlighted);\n\n const openWith = (highlight: PendingHighlight, event?: Event) => {\n context.pendingHighlight.current = highlight;\n context.setOpen(true, \"list-navigation\", event);\n };\n const move = (delta: 1 | -1) => {\n // past an end, the visual focus goes back to the input; from the input, to the near end\n const index = items.findIndex((item) => item.id === highlighted);\n context.setHighlighted(\n items[stepThroughNone(items.length, index, delta)]?.id ?? null,\n );\n };\n\n const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n const input = event.currentTarget;\n switch (event.key) {\n case \"ArrowDown\":\n case \"ArrowUp\": {\n event.preventDefault();\n if (event.altKey) {\n if (event.key === \"ArrowDown\" && !open) {\n openWith(null, event.nativeEvent);\n } else if (event.key === \"ArrowUp\" && open) {\n context.setOpen(\n false,\n \"list-navigation\",\n event.nativeEvent,\n );\n }\n return;\n }\n if (!open) {\n openWith(\n event.key === \"ArrowDown\" ? \"first\" : \"last\",\n event.nativeEvent,\n );\n return;\n }\n move(event.key === \"ArrowDown\" ? 1 : -1);\n return;\n }\n case \"Enter\":\n if (open) {\n event.preventDefault();\n if (active !== undefined && !active.disabled) {\n context.choose(active.value);\n }\n }\n return;\n case \"Escape\":\n // the open list's layer takes Escape first; here the list is closed\n if (\n !open &&\n (context.inputValue !== \"\" || context.values.length > 0)\n ) {\n event.preventDefault();\n context.clear(\"escape-key\");\n }\n return;\n case \"Tab\":\n if (open) {\n context.setOpen(false, \"focus-out\", event.nativeEvent);\n }\n return;\n case \"Backspace\":\n if (\n context.multiple &&\n input.value === \"\" &&\n context.values.length > 0\n ) {\n context.removeAt(context.values.length - 1, \"none\");\n }\n return;\n default: {\n const chips = chipElements(context);\n if (\n context.multiple &&\n event.key ===\n chipArrows(getDirection(input, direction) === \"rtl\")\n .previous &&\n input.selectionStart === 0 &&\n input.selectionEnd === 0 &&\n chips.length > 0\n ) {\n event.preventDefault();\n chips.at(-1)?.focus();\n }\n }\n }\n };\n\n const state = { open, disabled };\n return renderElement(\n \"input\",\n props,\n state,\n {\n type: \"text\",\n id: context.triggerId,\n role: \"combobox\",\n autoComplete: \"off\",\n disabled,\n value: context.inputValue,\n \"aria-autocomplete\": \"list\",\n \"aria-expanded\": open,\n \"aria-controls\": context.listId,\n \"aria-activedescendant\": open && active ? active.id : undefined,\n ...field.aria,\n \"data-primitives-part\": \"combobox-input\",\n ...field.attributes,\n ...stateAttributes({ \"popup-open\": open, disabled }),\n onChange: (event: ChangeEvent<HTMLInputElement>) => {\n context.setInputValue(event.target.value, \"input-change\");\n context.setHighlighted(null);\n context.markTyped();\n context.pendingHighlight.current = null;\n if (!open) {\n context.setOpen(true, \"input-change\", event.nativeEvent);\n }\n },\n onClick: () => openOnPress(context),\n onKeyDown,\n onFocus: field.onFocus,\n onBlur: field.onBlur,\n },\n context.setTrigger,\n );\n}\n","import type { MouseEvent } from \"react\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport { ComboboxContext, pressToOpen } from \"./combobox-context.ts\";\n\n/** Holds the Input and its buttons; anchors the list (spec/combobox.md). */\nexport function ComboboxInputGroup(\n props: PartProps<{ open: boolean; disabled: boolean }>,\n) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.InputGroup\");\n const { open, disabled } = context;\n return renderElement(\n \"div\",\n props,\n { open, disabled },\n {\n role: \"group\",\n \"data-primitives-part\": \"combobox-input-group\",\n ...stateAttributes({ \"popup-open\": open, disabled }),\n onMouseDown: (event: MouseEvent) => pressToOpen(context, event),\n },\n context.setInputGroup,\n );\n}\n","import { scrollIntoViewWithin } from \"@fragiola/primitives/collection\";\nimport { useId, useLayoutEffect } from \"react\";\nimport { useElement } from \"../../hooks/use-element.ts\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport { ComboboxContext, ComboboxItemContext } from \"./combobox-context.ts\";\n\nexport interface ComboboxItemState {\n highlighted: boolean;\n selected: boolean;\n disabled: boolean;\n}\n\nexport interface ComboboxItemProps extends PartProps<ComboboxItemState> {\n /** The item: written into the input as `itemToStringLabel(value)` when chosen. */\n value: unknown;\n /** Can be highlighted, never chosen. */\n disabled?: boolean;\n}\n\n/** An `option` (spec/combobox.md). */\nexport function ComboboxItem({\n value,\n disabled = false,\n ...props\n}: ComboboxItemProps) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Item\");\n const [element, ref] = useElement<HTMLElement>();\n const id = useId();\n const { items, setItemCount } = context;\n useLayoutEffect(() => {\n if (element === null) {\n return undefined;\n }\n items.set(element, { value, disabled, id });\n setItemCount(items.size);\n return () => {\n items.delete(element);\n setItemCount(items.size);\n };\n }, [element, value, disabled, id, items, setItemCount]);\n\n const highlighted = context.highlighted === id;\n const selected = context.isSelected(value);\n const { positioner } = context;\n // within the popup only: a list that mounts before it is placed never scrolls the page\n useLayoutEffect(() => {\n if (highlighted && element !== null) {\n scrollIntoViewWithin(element, positioner);\n }\n }, [highlighted, element, positioner]);\n\n const state = { highlighted, selected, disabled };\n return (\n <ComboboxItemContext.Provider value={{ selected }}>\n {renderElement(\n \"div\",\n props,\n state,\n {\n role: \"option\",\n id,\n \"aria-selected\": selected ? \"true\" : undefined,\n \"aria-disabled\": disabled ? \"true\" : undefined,\n \"data-primitives-part\": \"combobox-item\",\n ...stateAttributes({ highlighted, selected, disabled }),\n onPointerMove: () => {\n if (!highlighted) {\n context.setHighlighted(id);\n }\n },\n onPointerDown: (event: PointerEvent) =>\n event.preventDefault(),\n onClick: () => {\n if (!disabled) {\n context.choose(value);\n }\n },\n },\n ref,\n )}\n </ComboboxItemContext.Provider>\n );\n}\n","import { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { ComboboxItemContext } from \"./combobox-context.ts\";\n\nexport interface ComboboxItemIndicatorProps\n extends PartProps<{ selected: boolean }> {\n /** Rendered while the item is not selected too. */\n keepMounted?: boolean;\n}\n\n/** Marks a selected item; hidden from assistive technologies (spec/combobox.md). */\nexport function ComboboxItemIndicator({\n keepMounted = false,\n ...props\n}: ComboboxItemIndicatorProps) {\n const item = useRequiredContext(\n ComboboxItemContext,\n \"Combobox.ItemIndicator\",\n );\n if (!item.selected && !keepMounted) {\n return null;\n }\n return renderElement(\n \"span\",\n props,\n { selected: item.selected },\n {\n \"aria-hidden\": \"true\",\n \"data-primitives-part\": \"combobox-item-indicator\",\n },\n );\n}\n","import { type ReactNode, useLayoutEffect } from \"react\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport { ComboboxContext, orderedItems } from \"./combobox-context.ts\";\n\nexport interface ComboboxListProps<Entry = unknown>\n extends Omit<PartProps<{ empty: boolean }>, \"children\"> {\n /**\n * Nodes, or a render function of each matching entry (an item, or a group). `Entry` is the\n * consumer's own type, inferred from the function's parameter.\n */\n children?: ReactNode | ((entry: Entry, index: number) => ReactNode);\n}\n\n/** The `listbox`. Applies the highlight the keyboard asked for once its items render. */\nexport function ComboboxList<Entry = unknown>({\n children,\n ...props\n}: ComboboxListProps<Entry>) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.List\");\n const { list, pendingHighlight, setHighlighted, itemCount, open } = context;\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: runs when the list opens, or its items change\n useLayoutEffect(() => {\n const pending = pendingHighlight.current;\n if (list === null || pending === null) {\n return;\n }\n pendingHighlight.current = null;\n const items = orderedItems(context);\n const selected = context.multiple\n ? undefined\n : items.find((item) => context.isSelected(item.value));\n const edge = pending === \"first\" ? items[0] : items.at(-1);\n const target = selected ?? (pending === \"selected\" ? undefined : edge);\n setHighlighted(target?.id ?? null);\n }, [list, itemCount, open]);\n\n const empty = context.hasItems\n ? context.entries.length === 0\n : itemCount === 0;\n const content =\n typeof children === \"function\"\n ? context.entries.map((entry, index) =>\n // the Root holds the consumer's items: the render function names their type\n children(entry as Entry, index),\n )\n : children;\n return renderElement(\n \"div\",\n { ...props, children: content },\n { empty },\n {\n role: \"listbox\",\n id: context.listId,\n \"aria-multiselectable\": context.multiple ? \"true\" : undefined,\n \"data-primitives-part\": \"combobox-list\",\n ...stateAttributes({ empty }),\n },\n context.setList,\n );\n}\n","import { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport { ComboboxContext } from \"./combobox-context.ts\";\n\n/** The floating container of the list (no role of its own). */\nexport function ComboboxPopup(\n props: PartProps<{ open: boolean; side: string; align: string }>,\n) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Popup\");\n const status = context.presence.status;\n return renderElement(\n \"div\",\n props,\n { open: context.open, ...context.placed },\n {\n \"data-primitives-part\": \"combobox-popup\",\n ...stateAttributes({\n open: context.open,\n closed: !context.open,\n side: context.placed.side,\n align: context.placed.align,\n \"starting-style\": status === \"starting\",\n \"ending-style\": status === \"ending\",\n }),\n },\n context.setPopup,\n );\n}\n","import {\n type OverlayPortalProps,\n useOverlayPortal,\n} from \"../../hooks/use-overlay-portal.ts\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { ComboboxContext } from \"./combobox-context.ts\";\n\nexport interface ComboboxPortalProps extends OverlayPortalProps {}\n\nexport function ComboboxPortal(props: ComboboxPortalProps) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Portal\");\n return useOverlayPortal(context.presence.mounted, props);\n}\n","import { openOverlaySession } from \"@fragiola/primitives/overlay\";\nimport { useEffect, useLayoutEffect } from \"react\";\nimport {\n type PositionerProps,\n usePositioner,\n} from \"../../hooks/use-positioner.ts\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport { ComboboxContext } from \"./combobox-context.ts\";\n\nexport interface ComboboxPositionerState {\n open: boolean;\n side: string;\n align: string;\n}\n\nexport interface ComboboxPositionerProps\n extends PartProps<ComboboxPositionerState>,\n PositionerProps {}\n\n/**\n * Places the list under the InputGroup (else the Chips, else the Input); the open list is a layer\n * (Escape, outside press).\n */\nexport function ComboboxPositioner({\n side,\n align,\n sideOffset,\n alignOffset,\n collisionPadding,\n anchor,\n ...props\n}: ComboboxPositionerProps) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Positioner\");\n const {\n open,\n positioner,\n trigger,\n button,\n inputGroup,\n chips,\n clearButton,\n setOpen,\n setPlaced,\n } = context;\n const placed = usePositioner(\n { side, align, sideOffset, alignOffset, collisionPadding, anchor },\n { side: \"bottom\", align: \"start\" },\n inputGroup ?? chips ?? trigger,\n positioner,\n null,\n context.presence.mounted,\n );\n useLayoutEffect(() => setPlaced(placed), [placed, setPlaced]);\n useEffect(() => {\n if (!open || positioner === null) {\n return undefined;\n }\n const session = openOverlaySession(positioner.ownerDocument, {\n elements: () => [positioner],\n ignore: () => [trigger, button, inputGroup, chips, clearButton],\n dismiss: (reason, event) => setOpen(false, reason, event),\n });\n return session.end;\n }, [\n open,\n positioner,\n trigger,\n button,\n inputGroup,\n chips,\n clearButton,\n setOpen,\n ]);\n return renderElement(\n \"div\",\n props,\n { open, ...placed },\n {\n role: \"presentation\",\n hidden: context.presence.mounted ? undefined : true,\n \"data-primitives-part\": \"combobox-positioner\",\n ...stateAttributes({\n open,\n closed: !open,\n side: placed.side,\n align: placed.align,\n }),\n },\n context.setPositioner,\n );\n}\n","import {\n containsFilter,\n filterItems,\n type ItemEquality,\n type ItemFilter,\n type ItemGroup,\n includesItem,\n itemFormValue,\n itemLabel,\n queryIsLabel,\n toggleItem,\n} from \"@fragiola/primitives/collection\";\nimport {\n bridgeForm,\n VISUALLY_HIDDEN_INPUT_STYLE,\n} from \"@fragiola/primitives/form\";\nimport type { Align, Side } from \"@fragiola/primitives/positioning\";\nimport {\n type ReactNode,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { useControllableState } from \"../../hooks/use-controllable-state.ts\";\nimport { useFieldControl } from \"../../hooks/use-field-control.ts\";\nimport {\n type OverlayRootProps,\n useOverlayRoot,\n} from \"../../hooks/use-overlay-root.ts\";\nimport type {\n ChangeDetails,\n ChangeReason,\n} from \"../../utils/change-details.ts\";\nimport {\n ComboboxContext,\n type ComboboxItemInfo,\n type PendingHighlight,\n} from \"./combobox-context.ts\";\n\ninterface ComboboxRootCommonProps<Item> extends OverlayRootProps {\n /** The items, or groups of items: the combobox filters them (spec/combobox.md). */\n items?: readonly (Item | ItemGroup<Item>)[];\n /** Whether an item matches the query; `null` turns filtering off. */\n filter?: ItemFilter<Item> | null;\n /** The most items the list renders; `-1` for no limit. */\n limit?: number;\n locale?: string;\n inputValue?: string;\n defaultInputValue?: string;\n onInputValueChange?: (inputValue: string, details: ChangeDetails) => void;\n isItemEqualToValue?: ItemEquality<Item>;\n itemToStringLabel?: (item: Item) => string;\n itemToStringValue?: (item: Item) => string;\n name?: string;\n required?: boolean;\n disabled?: boolean;\n children?: ReactNode;\n}\n\nexport interface ComboboxRootSingleProps<Item>\n extends ComboboxRootCommonProps<Item> {\n multiple?: false;\n value?: Item | null;\n defaultValue?: Item | null;\n onValueChange?: (value: Item | null, details: ChangeDetails) => void;\n}\n\nexport interface ComboboxRootMultipleProps<Item>\n extends ComboboxRootCommonProps<Item> {\n multiple: true;\n value?: readonly Item[];\n defaultValue?: readonly Item[];\n onValueChange?: (value: Item[], details: ChangeDetails) => void;\n}\n\nexport type ComboboxRootProps<Item> =\n | ComboboxRootSingleProps<Item>\n | ComboboxRootMultipleProps<Item>;\n\nconst NOOP = () => {};\nconst NONE: readonly unknown[] = [];\n\n/** Holds the combobox's state; renders its hidden form inputs (spec/combobox.md). */\nexport function ComboboxRoot<Item>(props: ComboboxRootProps<Item>) {\n const {\n items,\n filter: filterProp,\n limit = -1,\n locale,\n multiple = false,\n inputValue: inputValueProp,\n defaultInputValue,\n onInputValueChange,\n isItemEqualToValue,\n itemToStringLabel,\n itemToStringValue,\n name,\n required = false,\n disabled: disabledProp = false,\n children,\n open: openProp,\n defaultOpen,\n onOpenChange,\n onOpenChangeComplete,\n actionsRef,\n } = props;\n const defaultValue: unknown =\n props.defaultValue ?? (multiple ? NONE : null);\n const root = useOverlayRoot({\n open: openProp,\n defaultOpen,\n onOpenChange,\n onOpenChangeComplete,\n actionsRef,\n });\n const [value, setValue] = useControllableState<unknown, ChangeDetails>(\n props.value,\n defaultValue,\n props.onValueChange as\n | ((value: unknown, details: ChangeDetails) => void)\n | undefined,\n );\n const label = useCallback(\n (item: unknown) =>\n itemLabel(\n item,\n itemToStringLabel as ((item: unknown) => string) | undefined,\n ),\n [itemToStringLabel],\n );\n const formValue = (item: unknown) =>\n itemFormValue(\n item,\n itemToStringValue as ((item: unknown) => string) | undefined,\n );\n const isEqual = isItemEqualToValue as ItemEquality<unknown> | undefined;\n const values = useMemo<readonly unknown[]>(() => {\n if (multiple) {\n return (value as readonly unknown[] | null) ?? NONE;\n }\n return value === null || value === undefined ? NONE : [value];\n }, [multiple, value]);\n\n const [inputValue, setInputValueState] = useControllableState(\n inputValueProp,\n defaultInputValue ??\n (multiple ? \"\" : label(props.value ?? defaultValue)),\n onInputValueChange,\n );\n const hidden = useRef<HTMLInputElement>(null);\n const field = useFieldControl({\n id: root.trigger?.id || root.triggerId,\n labelable: true,\n value,\n filled: values.length > 0,\n input: () => hidden.current,\n // the Input\n focusTarget: () => root.trigger,\n });\n const disabled = disabledProp || field.disabled;\n const [highlighted, setHighlighted] = useState<string | null>(null);\n const registered = useMemo(\n () => new Map<HTMLElement, ComboboxItemInfo>(),\n [],\n );\n const [list, setList] = useState<HTMLElement | null>(null);\n const [button, setButton] = useState<HTMLElement | null>(null);\n const [inputGroup, setInputGroup] = useState<HTMLElement | null>(null);\n const [chips, setChips] = useState<HTMLElement | null>(null);\n const [clearButton, setClearButton] = useState<HTMLElement | null>(null);\n const [itemCount, setItemCount] = useState(0);\n const [typed, setTyped] = useState(false);\n const pendingHighlight = useRef<PendingHighlight>(null);\n const [placed, setPlaced] = useState<{ side: Side; align: Align }>({\n side: \"bottom\",\n align: \"start\",\n });\n const listId = `${useId()}-list`;\n\n const setInputValue = useCallback(\n (next: string, reason: ChangeReason) =>\n setInputValueState(next, { reason }),\n [setInputValueState],\n );\n const latest = useRef({ value, values, inputValue, multiple, label });\n latest.current = { value, values, inputValue, multiple, label };\n\n const { setOpen: setOpenState } = root;\n const setOpen = useCallback(\n (next: boolean, reason: ChangeReason, event?: Event): boolean => {\n // a close the consumer cancels leaves the list, its text and highlight as they are\n const changed = setOpenState(next, reason, event);\n if (!next || reason !== \"input-change\") {\n if (changed || next) {\n setTyped(false);\n }\n }\n if (next || !changed) {\n return changed;\n }\n // a list reopened during its exit animation starts with no highlight\n setHighlighted(null);\n pendingHighlight.current = null;\n if (reason === \"item-press\") {\n return changed;\n }\n // closing without a choice resets the text (spec/combobox.md, \"Choosing an item\")\n const current = latest.current;\n const text = current.multiple ? \"\" : current.label(current.value);\n if (current.inputValue !== text) {\n setInputValueState(text, {\n reason: text === \"\" ? \"input-clear\" : \"none\",\n });\n }\n return changed;\n },\n [setOpenState, setInputValueState],\n );\n\n const choose = useCallback(\n (item: unknown) => {\n const current = latest.current;\n setHighlighted(null);\n if (!current.multiple) {\n setValue(item, { reason: \"item-press\" });\n setInputValueState(current.label(item), {\n reason: \"item-press\",\n });\n setOpen(false, \"item-press\");\n return;\n }\n setValue(toggleItem(current.values, item, isEqual), {\n reason: \"item-press\",\n });\n if (current.inputValue.trim() !== \"\") {\n setInputValueState(\"\", { reason: \"input-clear\" });\n setOpen(false, \"item-press\");\n }\n },\n [setValue, setInputValueState, setOpen, isEqual],\n );\n const clear = useCallback(\n (reason: ChangeReason) => {\n setInputValueState(\"\", { reason });\n setValue(latest.current.multiple ? [] : null, { reason });\n setHighlighted(null);\n },\n [setInputValueState, setValue],\n );\n const removeAt = useCallback(\n (index: number, reason: ChangeReason) => {\n setValue(\n latest.current.values.filter((_, at) => at !== index),\n { reason },\n );\n },\n [setValue],\n );\n const isSelected = useCallback(\n (item: unknown) => includesItem(values, item, isEqual),\n [values, isEqual],\n );\n const markTyped = useCallback(() => setTyped(true), []);\n\n const filter = useMemo(\n () =>\n filterProp === undefined\n ? containsFilter<unknown>(locale)\n : (filterProp as ItemFilter<unknown> | null),\n [filterProp, locale],\n );\n const entries = useMemo(() => {\n if (items === undefined) {\n return NONE;\n }\n const query = inputValue.trim();\n // a single combobox that opened on its selected item's label shows every item\n const whole =\n !multiple &&\n !typed &&\n values.length > 0 &&\n queryIsLabel(label(values[0]), query, locale);\n return filterItems(items as readonly unknown[], whole ? \"\" : query, {\n filter,\n limit,\n itemToString: label,\n });\n }, [\n items,\n inputValue,\n multiple,\n typed,\n values,\n label,\n locale,\n filter,\n limit,\n ]);\n\n const reset = useRef({\n defaultValue,\n setValue,\n setInputValueState,\n label,\n markReset: field.reset,\n });\n reset.current = {\n defaultValue,\n setValue,\n setInputValueState,\n label,\n markReset: field.reset,\n };\n const triggerElement = root.trigger;\n useEffect(() => {\n const element = hidden.current;\n if (element === null) {\n return undefined;\n }\n return bridgeForm(element, {\n reset: () => {\n const current = reset.current;\n current.markReset();\n current.setValue(current.defaultValue, { reason: \"none\" });\n current.setInputValueState(\n latest.current.multiple\n ? \"\"\n : current.label(current.defaultValue),\n { reason: \"none\" },\n );\n },\n invalid: () => triggerElement,\n });\n }, [triggerElement]);\n\n const context = useMemo(\n () => ({\n ...root,\n setOpen,\n field,\n multiple,\n value,\n values,\n inputValue,\n setInputValue,\n disabled,\n highlighted,\n setHighlighted,\n isSelected,\n choose,\n clear,\n removeAt,\n label,\n hasItems: items !== undefined,\n entries,\n markTyped,\n items: registered,\n list,\n setList,\n button,\n setButton,\n inputGroup,\n setInputGroup,\n chips,\n setChips,\n clearButton,\n setClearButton,\n listId,\n pendingHighlight,\n placed,\n setPlaced,\n itemCount,\n setItemCount,\n }),\n [\n root,\n setOpen,\n field,\n multiple,\n value,\n values,\n inputValue,\n setInputValue,\n disabled,\n highlighted,\n isSelected,\n choose,\n clear,\n removeAt,\n label,\n items,\n entries,\n markTyped,\n registered,\n list,\n button,\n inputGroup,\n chips,\n clearButton,\n listId,\n placed,\n itemCount,\n ],\n );\n const fieldName = field.name ?? name;\n return (\n <ComboboxContext.Provider value={context}>\n {children}\n <input\n ref={hidden}\n aria-hidden=\"true\"\n tabIndex={-1}\n name={multiple ? undefined : fieldName}\n value={multiple ? \"\" : formValue(value)}\n required={multiple ? required && values.length === 0 : required}\n disabled={disabled}\n onChange={NOOP}\n style={VISUALLY_HIDDEN_INPUT_STYLE}\n data-primitives-part=\"combobox-hidden-input\"\n />\n {multiple && fieldName !== undefined\n ? values.map((item, index) => (\n <input\n // biome-ignore lint/suspicious/noArrayIndexKey: two values may share a form value\n key={index}\n type=\"hidden\"\n name={fieldName}\n value={formValue(item)}\n disabled={disabled}\n data-primitives-part=\"combobox-hidden-input\"\n />\n ))\n : null}\n </ComboboxContext.Provider>\n );\n}\n","import { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\n\n/** Between groups; no role of its own (a `listbox` owns only groups and options). */\nexport function ComboboxSeparator(props: PartProps<Record<string, never>>) {\n return renderElement(\n \"div\",\n props,\n {},\n {\n role: \"presentation\",\n \"data-orientation\": \"horizontal\",\n \"data-primitives-part\": \"combobox-separator\",\n },\n );\n}\n","import { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\n\n/** A polite live region for the consumer's text (spec/combobox.md). */\nexport function ComboboxStatus(props: PartProps<Record<string, never>>) {\n return renderElement(\n \"div\",\n props,\n {},\n {\n role: \"status\",\n \"aria-live\": \"polite\",\n \"aria-atomic\": \"true\",\n \"data-primitives-part\": \"combobox-status\",\n },\n );\n}\n","import type { MouseEvent as ReactMouseEvent } from \"react\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { type PartProps, renderElement } from \"../../utils/render-element.tsx\";\nimport { stateAttributes } from \"../../utils/state-attributes.ts\";\nimport { ComboboxContext } from \"./combobox-context.ts\";\n\n/** Toggles the list; not in the tab order, keeps focus in the input. */\nexport function ComboboxTrigger(\n props: PartProps<{ open: boolean; disabled: boolean }>,\n) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Trigger\");\n const { open, disabled } = context;\n return renderElement(\n \"button\",\n props,\n { open, disabled },\n {\n type: \"button\",\n tabIndex: -1,\n disabled,\n \"aria-expanded\": open,\n \"aria-controls\": context.listId,\n \"data-primitives-part\": \"combobox-trigger\",\n ...stateAttributes({ \"popup-open\": open, disabled }),\n onPointerDown: (event: PointerEvent) => event.preventDefault(),\n onClick: (event: ReactMouseEvent) => {\n context.pendingHighlight.current = null;\n context.setOpen(!open, \"trigger-press\", event.nativeEvent);\n context.trigger?.focus();\n },\n },\n context.setButton,\n );\n}\n","import type { ReactNode } from \"react\";\nimport { useRequiredContext } from \"../../hooks/use-required-context.ts\";\nimport { ComboboxContext } from \"./combobox-context.ts\";\n\nexport interface ComboboxValueProps<Value = unknown> {\n /**\n * A node, or a render function of the value (an item or `null`, or the list of items). `Value`\n * is the consumer's own type, inferred from the function's parameter.\n */\n children?: ReactNode | ((value: Value) => ReactNode);\n}\n\n/** Renders the value: its label (labels joined with \", \"), or the consumer's render function. */\nexport function ComboboxValue<Value = unknown>({\n children,\n}: ComboboxValueProps<Value>) {\n const context = useRequiredContext(ComboboxContext, \"Combobox.Value\");\n if (typeof children === \"function\") {\n // the Root holds the consumer's items: the render function names their type\n return <>{children(context.value as Value)}</>;\n }\n if (children !== undefined) {\n return <>{children}</>;\n }\n return <>{context.values.map(context.label).join(\", \")}</>;\n}\n","import { ComboboxChip } from \"./combobox-chip.tsx\";\nimport { ComboboxChipRemove } from \"./combobox-chip-remove.tsx\";\nimport { ComboboxChips } from \"./combobox-chips.tsx\";\nimport { ComboboxClear } from \"./combobox-clear.tsx\";\nimport { ComboboxEmpty } from \"./combobox-empty.tsx\";\nimport { ComboboxGroup } from \"./combobox-group.tsx\";\nimport { ComboboxGroupLabel } from \"./combobox-group-label.tsx\";\nimport { ComboboxInput } from \"./combobox-input.tsx\";\nimport { ComboboxInputGroup } from \"./combobox-input-group.tsx\";\nimport { ComboboxItem } from \"./combobox-item.tsx\";\nimport { ComboboxItemIndicator } from \"./combobox-item-indicator.tsx\";\nimport { ComboboxList } from \"./combobox-list.tsx\";\nimport { ComboboxPopup } from \"./combobox-popup.tsx\";\nimport { ComboboxPortal } from \"./combobox-portal.tsx\";\nimport { ComboboxPositioner } from \"./combobox-positioner.tsx\";\nimport { ComboboxRoot } from \"./combobox-root.tsx\";\nimport { ComboboxSeparator } from \"./combobox-separator.tsx\";\nimport { ComboboxStatus } from \"./combobox-status.tsx\";\nimport { ComboboxTrigger } from \"./combobox-trigger.tsx\";\nimport { ComboboxValue } from \"./combobox-value.tsx\";\n\n/** spec/combobox.md */\nexport const Combobox = {\n Root: ComboboxRoot,\n InputGroup: ComboboxInputGroup,\n Input: ComboboxInput,\n Trigger: ComboboxTrigger,\n Clear: ComboboxClear,\n Chips: ComboboxChips,\n Chip: ComboboxChip,\n ChipRemove: ComboboxChipRemove,\n Value: ComboboxValue,\n Status: ComboboxStatus,\n Portal: ComboboxPortal,\n Positioner: ComboboxPositioner,\n Popup: ComboboxPopup,\n Empty: ComboboxEmpty,\n List: ComboboxList,\n Group: ComboboxGroup,\n GroupLabel: ComboboxGroupLabel,\n Separator: ComboboxSeparator,\n Item: ComboboxItem,\n ItemIndicator: ComboboxItemIndicator,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkEA,MAAa,kBAAkB,cAA2C,IAAI;AAM9E,MAAa,sBACT,cAA+C,IAAI;AAMvD,MAAa,uBACT,cAAgD,IAAI;AAOxD,MAAa,sBACT,cAA+C,IAAI;;AAGvD,SAAgB,aACZ,SACkB;CAClB,IAAI,QAAQ,SAAS,MACjB,OAAO,CAAC;CAEZ,OAAO,CAAC,GAAG,QAAQ,KAAK,iBAA8B,mBAAiB,CAAC,CAAC,CACpE,KAAK,YAAY,QAAQ,MAAM,IAAI,OAAO,CAAC,CAAC,CAC5C,QAAQ,SAAmC,SAAS,KAAA,CAAS;AACtE;;AAGA,SAAgB,aAAa,SAA8C;CACvE,IAAI,QAAQ,UAAU,MAClB,OAAO,CAAC;CAEZ,OAAO,CACH,GAAG,QAAQ,MAAM,iBACb,0CACJ,CACJ;AACJ;;;;;AAMA,SAAgB,YACZ,SACA,OACI;CACJ,MAAM,SAAS,MAAM;CACrB,IACI,WAAW,QACX,WAAW,QAAQ,WACnB,OAAO,QAAQ,kDAAgD,MAC3D,MAEJ;CAEJ,MAAM,eAAe;CACrB,IAAI,QAAQ,UACR;CAEJ,QAAQ,SAAS,MAAM;CACvB,YAAY,OAAO;AACvB;;AAGA,SAAgB,YAAY,SAAqC;CAC7D,IAAI,QAAQ,QAAQ,QAAQ,UACxB;CAEJ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MAAM,UAAU,eACL;EACH,GAAG;EACH;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,UAAU,UAAU,KAAA;EACpB;EACA;EACA,OAAO;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACJ,IACA;EACI;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACJ,CACJ;CACA,MAAM,YAAY,MAAM,QAAQ;CAChC,OACI,qBAAC,gBAAgB,UAAjB;EAA0B,OAAO;EAAjC,UAAA;GACK;GACD,oBAAC,SAAD;IACI,KAAK;IACL,eAAY;IACZ,UAAU;IACV,MAAM,WAAW,KAAA,IAAY;IAC7B,OAAO,WAAW,KAAK,UAAU,KAAK;IACtC,UAAU,WAAW,YAAY,OAAO,WAAW,IAAI;IAC7C;IACV,UAAU;IACV,OAAO;IACP,wBAAqB;GACxB,CAAA;GACA,YAAY,cAAc,KAAA,IACrB,OAAO,KAAK,MAAM,UACd,oBAAC,SAAD;IAGI,MAAK;IACL,MAAM;IACN,OAAO,UAAU,IAAI;IACX;IACV,wBAAqB;GACxB,GANQ,KAMR,CACJ,IACD;EACgB;;AAElC;;;ACnbA,SAAgB,kBAAkB,OAAyC;CACvE,OAAO,cACH,OACA,OACA,CAAC,GACD;EACI,MAAM;EACN,oBAAoB;EACpB,wBAAwB;CAC5B,CACJ;AACJ;;;ACXA,SAAgB,eAAe,OAAyC;CACpE,OAAO,cACH,OACA,OACA,CAAC,GACD;EACI,MAAM;EACN,aAAa;EACb,eAAe;EACf,wBAAwB;CAC5B,CACJ;AACJ;;;ACRA,SAAgB,gBACZ,OACF;CACE,MAAM,UAAU,mBAAmB,iBAAiB,kBAAkB;CACtE,MAAM,EAAE,MAAM,aAAa;CAC3B,OAAO,cACH,U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