@serendie/ui 2.0.0 → 2.1.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.
Files changed (118) hide show
  1. package/dist/components/CheckBox/CheckBox.js +36 -35
  2. package/dist/components/ChoiceBox/ChoiceBox.js +41 -41
  3. package/dist/components/DataTable/DataTableComponent.d.ts +3 -20
  4. package/dist/components/DataTable/DataTableComponent.js +38 -36
  5. package/dist/components/DataTable/table/HeaderCheckbox.js +29 -19
  6. package/dist/components/Search/Search.d.ts +3 -1
  7. package/dist/components/Search/Search.js +34 -33
  8. package/dist/components/Select/Select.d.ts +2 -1
  9. package/dist/components/Select/Select.js +47 -41
  10. package/dist/components/Tooltip/Tooltip.d.ts +14 -0
  11. package/dist/components/Tooltip/Tooltip.js +70 -0
  12. package/dist/components/Tooltip/index.d.ts +1 -0
  13. package/dist/components/Tooltip/index.js +4 -0
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.js +12 -10
  16. package/dist/node_modules/@ark-ui/react/dist/components/accordion/accordion-item-content.js +4 -6
  17. package/dist/node_modules/@ark-ui/react/dist/components/accordion/accordion-item-indicator.js +4 -6
  18. package/dist/node_modules/@ark-ui/react/dist/components/accordion/accordion-item-trigger.js +10 -12
  19. package/dist/node_modules/@ark-ui/react/dist/components/accordion/accordion-item.js +16 -16
  20. package/dist/node_modules/@ark-ui/react/dist/components/accordion/use-accordion.js +13 -20
  21. package/dist/node_modules/@ark-ui/react/dist/components/avatar/avatar-root.js +1 -5
  22. package/dist/node_modules/@ark-ui/react/dist/components/avatar/use-avatar.js +14 -18
  23. package/dist/node_modules/@ark-ui/react/dist/components/checkbox/checkbox-hidden-input.js +4 -6
  24. package/dist/node_modules/@ark-ui/react/dist/components/checkbox/use-checkbox.js +22 -28
  25. package/dist/node_modules/@ark-ui/react/dist/components/collapsible/collapsible-content.js +7 -9
  26. package/dist/node_modules/@ark-ui/react/dist/components/collapsible/use-collapsible.js +14 -21
  27. package/dist/node_modules/@ark-ui/react/dist/components/collection/list-collection.js +5 -0
  28. package/dist/node_modules/@ark-ui/react/dist/components/combobox/combobox-content.js +9 -8
  29. package/dist/node_modules/@ark-ui/react/dist/components/combobox/combobox-item-group.js +4 -6
  30. package/dist/node_modules/@ark-ui/react/dist/components/combobox/combobox-positioner.js +4 -6
  31. package/dist/node_modules/@ark-ui/react/dist/components/combobox/combobox-root.js +17 -18
  32. package/dist/node_modules/@ark-ui/react/dist/components/combobox/combobox-trigger.js +10 -9
  33. package/dist/node_modules/@ark-ui/react/dist/components/combobox/use-combobox-item-context.js +5 -7
  34. package/dist/node_modules/@ark-ui/react/dist/components/combobox/use-combobox.js +21 -45
  35. package/dist/node_modules/@ark-ui/react/dist/components/dialog/dialog-backdrop.js +10 -9
  36. package/dist/node_modules/@ark-ui/react/dist/components/dialog/dialog-close-trigger.js +4 -6
  37. package/dist/node_modules/@ark-ui/react/dist/components/dialog/dialog-content.js +6 -5
  38. package/dist/node_modules/@ark-ui/react/dist/components/dialog/dialog-description.js +4 -6
  39. package/dist/node_modules/@ark-ui/react/dist/components/dialog/use-dialog.js +13 -22
  40. package/dist/node_modules/@ark-ui/react/dist/components/factory.js +26 -24
  41. package/dist/node_modules/@ark-ui/react/dist/components/menu/menu-content.js +9 -8
  42. package/dist/node_modules/@ark-ui/react/dist/components/menu/menu-item-group.js +1 -3
  43. package/dist/node_modules/@ark-ui/react/dist/components/menu/menu-item.js +15 -13
  44. package/dist/node_modules/@ark-ui/react/dist/components/menu/menu-root.js +13 -14
  45. package/dist/node_modules/@ark-ui/react/dist/components/menu/use-menu-option-item-props-context.js +10 -0
  46. package/dist/node_modules/@ark-ui/react/dist/components/menu/use-menu.js +14 -21
  47. package/dist/node_modules/@ark-ui/react/dist/components/pagination/pagination-ellipsis.js +4 -6
  48. package/dist/node_modules/@ark-ui/react/dist/components/pagination/pagination-next-trigger.js +4 -6
  49. package/dist/node_modules/@ark-ui/react/dist/components/pagination/pagination-prev-trigger.js +4 -6
  50. package/dist/node_modules/@ark-ui/react/dist/components/pagination/pagination-root.js +5 -4
  51. package/dist/node_modules/@ark-ui/react/dist/components/pagination/use-pagination.js +13 -19
  52. package/dist/node_modules/@ark-ui/react/dist/components/portal/portal.js +25 -16
  53. package/dist/node_modules/@ark-ui/react/dist/components/presence/split-presence-props.js +3 -2
  54. package/dist/node_modules/@ark-ui/react/dist/components/presence/use-presence.js +18 -18
  55. package/dist/node_modules/@ark-ui/react/dist/components/radio-group/radio-group-item-control.js +4 -6
  56. package/dist/node_modules/@ark-ui/react/dist/components/radio-group/radio-group-item-text.js +4 -6
  57. package/dist/node_modules/@ark-ui/react/dist/components/radio-group/radio-group-item.js +1 -5
  58. package/dist/node_modules/@ark-ui/react/dist/components/radio-group/use-radio-group.js +14 -22
  59. package/dist/node_modules/@ark-ui/react/dist/components/select/select-content.js +9 -8
  60. package/dist/node_modules/@ark-ui/react/dist/components/select/select-root.js +11 -12
  61. package/dist/node_modules/@ark-ui/react/dist/components/select/use-select.js +20 -47
  62. package/dist/node_modules/@ark-ui/react/dist/components/switch/switch-hidden-input.js +4 -6
  63. package/dist/node_modules/@ark-ui/react/dist/components/switch/use-switch.js +20 -26
  64. package/dist/node_modules/@ark-ui/react/dist/components/tabs/tabs-root.js +9 -8
  65. package/dist/node_modules/@ark-ui/react/dist/components/tabs/use-tabs.js +14 -21
  66. package/dist/node_modules/@ark-ui/react/dist/components/toast/create-toaster.js +3 -7
  67. package/dist/node_modules/@ark-ui/react/dist/components/toast/toaster.js +28 -15
  68. package/dist/node_modules/@ark-ui/react/dist/components/tooltip/tooltip-arrow-tip.js +13 -0
  69. package/dist/node_modules/@ark-ui/react/dist/components/tooltip/tooltip-arrow.js +13 -0
  70. package/dist/node_modules/@ark-ui/react/dist/components/tooltip/tooltip-content.js +15 -0
  71. package/dist/node_modules/@ark-ui/react/dist/components/tooltip/tooltip-positioner.js +14 -0
  72. package/dist/node_modules/@ark-ui/react/dist/components/tooltip/tooltip-root.js +14 -0
  73. package/dist/node_modules/@ark-ui/react/dist/components/tooltip/tooltip-trigger.js +13 -0
  74. package/dist/node_modules/@ark-ui/react/dist/components/tooltip/use-tooltip-context.js +10 -0
  75. package/dist/node_modules/@ark-ui/react/dist/components/tooltip/use-tooltip.js +17 -0
  76. package/dist/node_modules/@ark-ui/react/dist/utils/compose-refs.js +13 -7
  77. package/dist/node_modules/@floating-ui/core/dist/floating-ui.core.js +92 -90
  78. package/dist/node_modules/@floating-ui/dom/dist/floating-ui.dom.js +230 -216
  79. package/dist/node_modules/@zag-js/accordion/dist/index.js +210 -227
  80. package/dist/node_modules/@zag-js/aria-hidden/dist/index.js +49 -12
  81. package/dist/node_modules/@zag-js/avatar/dist/index.js +119 -134
  82. package/dist/node_modules/@zag-js/checkbox/dist/index.js +196 -197
  83. package/dist/node_modules/@zag-js/collapsible/dist/index.js +250 -198
  84. package/dist/node_modules/@zag-js/collection/dist/index.js +172 -179
  85. package/dist/node_modules/@zag-js/combobox/dist/index.js +1176 -1082
  86. package/dist/node_modules/@zag-js/core/dist/index.js +77 -496
  87. package/dist/node_modules/@zag-js/dialog/dist/index.js +243 -270
  88. package/dist/node_modules/@zag-js/dismissable/dist/index.js +62 -60
  89. package/dist/node_modules/@zag-js/dom-query/dist/index.js +465 -253
  90. package/dist/node_modules/@zag-js/focus-trap/dist/index.js +307 -0
  91. package/dist/node_modules/@zag-js/focus-visible/dist/index.js +48 -47
  92. package/dist/node_modules/@zag-js/interact-outside/dist/index.js +112 -80
  93. package/dist/node_modules/@zag-js/menu/dist/index.js +998 -884
  94. package/dist/node_modules/@zag-js/pagination/dist/index.js +207 -213
  95. package/dist/node_modules/@zag-js/popper/dist/index.js +130 -129
  96. package/dist/node_modules/@zag-js/presence/dist/index.js +139 -122
  97. package/dist/node_modules/@zag-js/radio-group/dist/index.js +297 -302
  98. package/dist/node_modules/@zag-js/react/dist/index.js +255 -103
  99. package/dist/node_modules/@zag-js/remove-scroll/dist/index.js +18 -31
  100. package/dist/node_modules/@zag-js/select/dist/index.js +889 -885
  101. package/dist/node_modules/@zag-js/store/dist/index.js +98 -137
  102. package/dist/node_modules/@zag-js/switch/dist/index.js +199 -191
  103. package/dist/node_modules/@zag-js/tabs/dist/index.js +383 -386
  104. package/dist/node_modules/@zag-js/toast/dist/index.js +646 -633
  105. package/dist/node_modules/@zag-js/tooltip/dist/index.js +459 -0
  106. package/dist/node_modules/@zag-js/types/dist/index.js +6 -6
  107. package/dist/node_modules/@zag-js/utils/dist/index.js +112 -99
  108. package/dist/node_modules/proxy-compare/dist/index.js +4 -106
  109. package/dist/styles.css +1 -1
  110. package/package.json +5 -5
  111. package/dist/node_modules/@ark-ui/react/dist/utils/use-is-server.js +0 -10
  112. package/dist/node_modules/@zag-js/dom-event/dist/index.js +0 -130
  113. package/dist/node_modules/@zag-js/element-rect/dist/index.js +0 -32
  114. package/dist/node_modules/@zag-js/form-utils/dist/index.js +0 -51
  115. package/dist/node_modules/aria-hidden/dist/es2015/index.js +0 -52
  116. package/dist/node_modules/focus-trap/dist/focus-trap.esm.js +0 -431
  117. package/dist/node_modules/klona/full/index.js +0 -21
  118. package/dist/node_modules/tabbable/dist/index.esm.js +0 -202
@@ -1,14 +1,13 @@
1
- import { createAnatomy as B } from "../../anatomy/dist/index.js";
2
- import { ListCollection as D } from "../../collection/dist/index.js";
3
- import { createMachine as W, guards as $ } from "../../core/dist/index.js";
4
- import { isContextMenuEvent as Y, getEventKey as U, isLeftClick as q, clickIfLink as j } from "../../dom-event/dist/index.js";
5
- import { createScope as J, raf as C, observeAttributes as Q, observeChildren as X, scrollIntoView as Z, dataAttr as u, ariaAttr as A, isDownloadingEvent as z, isOpeningInNewTab as x, isComposingEvent as ee, query as te } from "../../dom-query/dist/index.js";
6
- import { getPlacement as H, getPlacementStyles as ne } from "../../popper/dist/index.js";
7
- import { ariaHidden as ie } from "../../aria-hidden/dist/index.js";
8
- import { trackDismissableElement as le } from "../../dismissable/dist/index.js";
9
- import { compact as oe, isArray as G, match as R, isBoolean as ae, isEqual as F, addOrRemove as re } from "../../utils/dist/index.js";
10
- import { ref as M } from "../../store/dist/index.js";
11
- var se = B("combobox").parts(
1
+ import { createAnatomy as ce } from "../../anatomy/dist/index.js";
2
+ import { ListCollection as ee } from "../../collection/dist/index.js";
3
+ import { raf as f, setCaretToEnd as ge, observeAttributes as de, observeChildren as he, clickIfLink as Ie, dataAttr as u, ariaAttr as K, isDownloadingEvent as pe, isOpeningInNewTab as me, isContextMenuEvent as Ce, isLeftClick as U, getEventKey as $, isComposingEvent as fe, scrollIntoView as Oe, isAnchorElement as ve, query as Ee } from "../../dom-query/dist/index.js";
4
+ import { getPlacement as q, getPlacementStyles as Ve } from "../../popper/dist/index.js";
5
+ import { match as D, remove as Te, addOrRemove as Y, isBoolean as ye, isEqual as Pe, ensure as Se } from "../../utils/dist/index.js";
6
+ import { ariaHidden as Ne } from "../../aria-hidden/dist/index.js";
7
+ import { setup as be } from "../../core/dist/index.js";
8
+ import { trackDismissableElement as ke } from "../../dismissable/dist/index.js";
9
+ import { createProps as G } from "../../types/dist/index.js";
10
+ var Le = ce("combobox").parts(
12
11
  "root",
13
12
  "clearTrigger",
14
13
  "content",
@@ -23,1243 +22,1338 @@ var se = B("combobox").parts(
23
22
  "list",
24
23
  "positioner",
25
24
  "trigger"
26
- ), I = se.build(), _ = (t) => M(new D(t));
27
- _.empty = () => M(new D({ items: [] }));
28
- var o = J({
29
- getRootId: (t) => {
30
- var n;
31
- return ((n = t.ids) == null ? void 0 : n.root) ?? `combobox:${t.id}`;
32
- },
33
- getLabelId: (t) => {
34
- var n;
35
- return ((n = t.ids) == null ? void 0 : n.label) ?? `combobox:${t.id}:label`;
36
- },
37
- getControlId: (t) => {
38
- var n;
39
- return ((n = t.ids) == null ? void 0 : n.control) ?? `combobox:${t.id}:control`;
40
- },
41
- getInputId: (t) => {
42
- var n;
43
- return ((n = t.ids) == null ? void 0 : n.input) ?? `combobox:${t.id}:input`;
44
- },
45
- getContentId: (t) => {
46
- var n;
47
- return ((n = t.ids) == null ? void 0 : n.content) ?? `combobox:${t.id}:content`;
48
- },
49
- getPositionerId: (t) => {
50
- var n;
51
- return ((n = t.ids) == null ? void 0 : n.positioner) ?? `combobox:${t.id}:popper`;
52
- },
53
- getTriggerId: (t) => {
54
- var n;
55
- return ((n = t.ids) == null ? void 0 : n.trigger) ?? `combobox:${t.id}:toggle-btn`;
56
- },
57
- getClearTriggerId: (t) => {
58
- var n;
59
- return ((n = t.ids) == null ? void 0 : n.clearTrigger) ?? `combobox:${t.id}:clear-btn`;
60
- },
61
- getItemGroupId: (t, n) => {
62
- var e, i;
63
- return ((i = (e = t.ids) == null ? void 0 : e.itemGroup) == null ? void 0 : i.call(e, n)) ?? `combobox:${t.id}:optgroup:${n}`;
64
- },
65
- getItemGroupLabelId: (t, n) => {
66
- var e, i;
67
- return ((i = (e = t.ids) == null ? void 0 : e.itemGroupLabel) == null ? void 0 : i.call(e, n)) ?? `combobox:${t.id}:optgroup-label:${n}`;
68
- },
69
- getItemId: (t, n) => {
70
- var e, i;
71
- return ((i = (e = t.ids) == null ? void 0 : e.item) == null ? void 0 : i.call(e, n)) ?? `combobox:${t.id}:option:${n}`;
72
- },
73
- getContentEl: (t) => o.getById(t, o.getContentId(t)),
74
- getInputEl: (t) => o.getById(t, o.getInputId(t)),
75
- getPositionerEl: (t) => o.getById(t, o.getPositionerId(t)),
76
- getControlEl: (t) => o.getById(t, o.getControlId(t)),
77
- getTriggerEl: (t) => o.getById(t, o.getTriggerId(t)),
78
- getClearTriggerEl: (t) => o.getById(t, o.getClearTriggerId(t)),
79
- getHighlightedItemEl: (t) => {
80
- const n = t.highlightedValue;
81
- if (n == null) return;
82
- const e = `[role=option][data-value="${CSS.escape(n)}"`;
83
- return te(o.getContentEl(t), e);
84
- },
85
- focusInputEl: (t) => {
86
- const n = o.getInputEl(t);
87
- o.isActiveElement(t, n) || n == null || n.focus({ preventScroll: !0 });
88
- },
89
- focusTriggerEl: (t) => {
90
- const n = o.getTriggerEl(t);
91
- o.isActiveElement(t, n) || n == null || n.focus({ preventScroll: !0 });
92
- }
93
- });
94
- function Ee(t, n, e) {
95
- const i = t.context.translations, r = t.context.collection, s = t.context.disabled, c = t.context.isInteractive, O = t.context.invalid, V = t.context.readOnly, d = t.hasTag("open"), f = t.hasTag("focused"), E = t.context.composite, b = t.context.highlightedValue, N = ne({
96
- ...t.context.positioning,
97
- placement: t.context.currentPlacement
25
+ ), p = Le.build(), te = (e) => new ee(e);
26
+ te.empty = () => new ee({ items: [] });
27
+ var Fe = (e) => {
28
+ var t;
29
+ return ((t = e.ids) == null ? void 0 : t.root) ?? `combobox:${e.id}`;
30
+ }, B = (e) => {
31
+ var t;
32
+ return ((t = e.ids) == null ? void 0 : t.label) ?? `combobox:${e.id}:label`;
33
+ }, ie = (e) => {
34
+ var t;
35
+ return ((t = e.ids) == null ? void 0 : t.control) ?? `combobox:${e.id}:control`;
36
+ }, M = (e) => {
37
+ var t;
38
+ return ((t = e.ids) == null ? void 0 : t.input) ?? `combobox:${e.id}:input`;
39
+ }, w = (e) => {
40
+ var t;
41
+ return ((t = e.ids) == null ? void 0 : t.content) ?? `combobox:${e.id}:content`;
42
+ }, ne = (e) => {
43
+ var t;
44
+ return ((t = e.ids) == null ? void 0 : t.positioner) ?? `combobox:${e.id}:popper`;
45
+ }, le = (e) => {
46
+ var t;
47
+ return ((t = e.ids) == null ? void 0 : t.trigger) ?? `combobox:${e.id}:toggle-btn`;
48
+ }, oe = (e) => {
49
+ var t;
50
+ return ((t = e.ids) == null ? void 0 : t.clearTrigger) ?? `combobox:${e.id}:clear-btn`;
51
+ }, Ae = (e, t) => {
52
+ var i, n;
53
+ return ((n = (i = e.ids) == null ? void 0 : i.itemGroup) == null ? void 0 : n.call(i, t)) ?? `combobox:${e.id}:optgroup:${t}`;
54
+ }, j = (e, t) => {
55
+ var i, n;
56
+ return ((n = (i = e.ids) == null ? void 0 : i.itemGroupLabel) == null ? void 0 : n.call(i, t)) ?? `combobox:${e.id}:optgroup-label:${t}`;
57
+ }, J = (e, t) => {
58
+ var i, n;
59
+ return ((n = (i = e.ids) == null ? void 0 : i.item) == null ? void 0 : n.call(i, t)) ?? `combobox:${e.id}:option:${t}`;
60
+ }, T = (e) => e.getById(w(e)), y = (e) => e.getById(M(e)), Q = (e) => e.getById(ne(e)), X = (e) => e.getById(ie(e)), L = (e) => e.getById(le(e)), Z = (e) => e.getById(oe(e)), ae = (e, t) => {
61
+ if (t == null) return;
62
+ const i = `[role=option][data-value="${CSS.escape(t)}"]`;
63
+ return Ee(T(e), i);
64
+ }, z = (e) => {
65
+ const t = y(e);
66
+ e.isActiveElement(t) || t == null || t.focus({ preventScroll: !0 });
67
+ }, Re = (e) => {
68
+ const t = L(e);
69
+ e.isActiveElement(t) || t == null || t.focus({ preventScroll: !0 });
70
+ };
71
+ function Ye(e, t) {
72
+ const { context: i, prop: n, state: o, send: a, scope: r, computed: C, event: k } = e, O = n("translations"), E = n("collection"), I = n("disabled"), P = C("isInteractive"), v = n("invalid"), S = n("readOnly"), d = o.hasTag("open"), F = o.hasTag("focused"), N = n("composite"), b = i.get("highlightedValue"), se = Ve({
73
+ ...n("positioning"),
74
+ placement: i.get("currentPlacement")
98
75
  });
99
- function T(l) {
100
- const { item: a } = l, p = r.getItemDisabled(a), h = r.getItemValue(a);
101
- return {
102
- value: h,
103
- disabled: !!(p || p),
104
- highlighted: b === h,
105
- selected: t.context.value.includes(h)
76
+ function H(l) {
77
+ const s = E.getItemDisabled(l.item), g = E.getItemValue(l.item);
78
+ return Se(g, () => `[zag-js] No value found for item ${JSON.stringify(l.item)}`), {
79
+ value: g,
80
+ disabled: !!(s || s),
81
+ highlighted: b === g,
82
+ selected: i.get("value").includes(g)
106
83
  };
107
84
  }
108
85
  return {
109
- focused: f,
86
+ focused: F,
110
87
  open: d,
111
- inputValue: t.context.inputValue,
88
+ inputValue: i.get("inputValue"),
112
89
  highlightedValue: b,
113
- highlightedItem: t.context.highlightedItem,
114
- value: t.context.value,
115
- valueAsString: t.context.valueAsString,
116
- hasSelectedItems: t.context.hasSelectedItems,
117
- selectedItems: t.context.selectedItems,
118
- collection: t.context.collection,
119
- reposition(l = {}) {
120
- n({ type: "POSITIONING.SET", options: l });
90
+ highlightedItem: i.get("highlightedItem"),
91
+ value: i.get("value"),
92
+ valueAsString: i.get("valueAsString"),
93
+ hasSelectedItems: C("hasSelectedItems"),
94
+ selectedItems: i.get("selectedItems"),
95
+ collection: n("collection"),
96
+ multiple: !!n("multiple"),
97
+ disabled: !!I,
98
+ syncSelectedItems() {
99
+ a({ type: "SELECTED_ITEMS.SYNC" });
121
100
  },
122
- setCollection(l) {
123
- n({ type: "COLLECTION.SET", value: l });
101
+ reposition(l = {}) {
102
+ a({ type: "POSITIONING.SET", options: l });
124
103
  },
125
104
  setHighlightValue(l) {
126
- n({ type: "HIGHLIGHTED_VALUE.SET", value: l });
105
+ a({ type: "HIGHLIGHTED_VALUE.SET", value: l });
127
106
  },
128
107
  selectValue(l) {
129
- n({ type: "ITEM.SELECT", value: l });
108
+ a({ type: "ITEM.SELECT", value: l });
130
109
  },
131
110
  setValue(l) {
132
- n({ type: "VALUE.SET", value: l });
111
+ a({ type: "VALUE.SET", value: l });
133
112
  },
134
113
  setInputValue(l) {
135
- n({ type: "INPUT_VALUE.SET", value: l });
114
+ a({ type: "INPUT_VALUE.SET", value: l });
136
115
  },
137
116
  clearValue(l) {
138
- l != null ? n({ type: "ITEM.CLEAR", value: l }) : n("VALUE.CLEAR");
117
+ l != null ? a({ type: "ITEM.CLEAR", value: l }) : a({ type: "VALUE.CLEAR" });
139
118
  },
140
119
  focus() {
141
120
  var l;
142
- (l = o.getInputEl(t.context)) == null || l.focus();
121
+ (l = y(r)) == null || l.focus();
143
122
  },
144
123
  setOpen(l) {
145
- l !== d && n(l ? "OPEN" : "CLOSE");
124
+ o.hasTag("open") !== l && a({ type: l ? "OPEN" : "CLOSE" });
146
125
  },
147
126
  getRootProps() {
148
- return e.element({
149
- ...I.root.attrs,
150
- dir: t.context.dir,
151
- id: o.getRootId(t.context),
152
- "data-invalid": u(O),
153
- "data-readonly": u(V)
127
+ return t.element({
128
+ ...p.root.attrs,
129
+ dir: n("dir"),
130
+ id: Fe(r),
131
+ "data-invalid": u(v),
132
+ "data-readonly": u(S)
154
133
  });
155
134
  },
156
135
  getLabelProps() {
157
- return e.label({
158
- ...I.label.attrs,
159
- dir: t.context.dir,
160
- htmlFor: o.getInputId(t.context),
161
- id: o.getLabelId(t.context),
162
- "data-readonly": u(V),
163
- "data-disabled": u(s),
164
- "data-invalid": u(O),
165
- "data-focus": u(f),
136
+ return t.label({
137
+ ...p.label.attrs,
138
+ dir: n("dir"),
139
+ htmlFor: M(r),
140
+ id: B(r),
141
+ "data-readonly": u(S),
142
+ "data-disabled": u(I),
143
+ "data-invalid": u(v),
144
+ "data-focus": u(F),
166
145
  onClick(l) {
167
- var a;
168
- E || (l.preventDefault(), (a = o.getTriggerEl(t.context)) == null || a.focus({ preventScroll: !0 }));
146
+ var s;
147
+ N || (l.preventDefault(), (s = L(r)) == null || s.focus({ preventScroll: !0 }));
169
148
  }
170
149
  });
171
150
  },
172
151
  getControlProps() {
173
- return e.element({
174
- ...I.control.attrs,
175
- dir: t.context.dir,
176
- id: o.getControlId(t.context),
152
+ return t.element({
153
+ ...p.control.attrs,
154
+ dir: n("dir"),
155
+ id: ie(r),
177
156
  "data-state": d ? "open" : "closed",
178
- "data-focus": u(f),
179
- "data-disabled": u(s),
180
- "data-invalid": u(O)
157
+ "data-focus": u(F),
158
+ "data-disabled": u(I),
159
+ "data-invalid": u(v)
181
160
  });
182
161
  },
183
162
  getPositionerProps() {
184
- return e.element({
185
- ...I.positioner.attrs,
186
- dir: t.context.dir,
187
- id: o.getPositionerId(t.context),
188
- style: N.floating
163
+ return t.element({
164
+ ...p.positioner.attrs,
165
+ dir: n("dir"),
166
+ id: ne(r),
167
+ style: se.floating
189
168
  });
190
169
  },
191
170
  getInputProps() {
192
- return e.input({
193
- ...I.input.attrs,
194
- dir: t.context.dir,
195
- "aria-invalid": A(O),
196
- "data-invalid": u(O),
197
- name: t.context.name,
198
- form: t.context.form,
199
- disabled: s,
200
- autoFocus: t.context.autoFocus,
201
- required: t.context.required,
171
+ return t.input({
172
+ ...p.input.attrs,
173
+ dir: n("dir"),
174
+ "aria-invalid": K(v),
175
+ "data-invalid": u(v),
176
+ "data-autofocus": u(n("autoFocus")),
177
+ name: n("name"),
178
+ form: n("form"),
179
+ disabled: I,
180
+ required: n("required"),
202
181
  autoComplete: "off",
203
182
  autoCorrect: "off",
204
183
  autoCapitalize: "none",
205
184
  spellCheck: "false",
206
- readOnly: V,
207
- placeholder: t.context.placeholder,
208
- id: o.getInputId(t.context),
185
+ readOnly: S,
186
+ placeholder: n("placeholder"),
187
+ id: M(r),
209
188
  type: "text",
210
189
  role: "combobox",
211
- defaultValue: t.context.inputValue,
212
- "aria-autocomplete": t.context.autoComplete ? "both" : "list",
213
- "aria-controls": o.getContentId(t.context),
190
+ defaultValue: i.get("inputValue"),
191
+ "aria-autocomplete": C("autoComplete") ? "both" : "list",
192
+ "aria-controls": w(r),
214
193
  "aria-expanded": d,
215
194
  "data-state": d ? "open" : "closed",
216
- "aria-activedescendant": b ? o.getItemId(t.context, b) : void 0,
195
+ "aria-activedescendant": b ? J(r, b) : void 0,
217
196
  onClick(l) {
218
- l.defaultPrevented || t.context.openOnClick && c && n("INPUT.CLICK");
197
+ l.defaultPrevented || n("openOnClick") && P && a({ type: "INPUT.CLICK" });
219
198
  },
220
199
  onFocus() {
221
- s || n("INPUT.FOCUS");
200
+ I || a({ type: "INPUT.FOCUS" });
222
201
  },
223
202
  onBlur() {
224
- s || n("INPUT.BLUR");
203
+ I || a({ type: "INPUT.BLUR" });
225
204
  },
226
205
  onChange(l) {
227
- n({ type: "INPUT.CHANGE", value: l.currentTarget.value });
206
+ a({ type: "INPUT.CHANGE", value: l.currentTarget.value });
228
207
  },
229
208
  onKeyDown(l) {
230
- if (l.defaultPrevented || !c || l.ctrlKey || l.shiftKey || ee(l)) return;
231
- const a = t.context.openOnKeyPress, p = l.ctrlKey || l.metaKey || l.shiftKey, h = !0, y = {
232
- ArrowDown(v) {
233
- !a && !d || (n({ type: v.altKey ? "OPEN" : "INPUT.ARROW_DOWN", keypress: h }), v.preventDefault());
209
+ if (l.defaultPrevented || !P || l.ctrlKey || l.shiftKey || fe(l)) return;
210
+ const s = n("openOnKeyPress"), g = l.ctrlKey || l.metaKey || l.shiftKey, h = !0, A = {
211
+ ArrowDown(V) {
212
+ !s && !d || (a({ type: V.altKey ? "OPEN" : "INPUT.ARROW_DOWN", keypress: h }), V.preventDefault());
234
213
  },
235
214
  ArrowUp() {
236
- !a && !d || (n({ type: l.altKey ? "CLOSE" : "INPUT.ARROW_UP", keypress: h }), l.preventDefault());
215
+ !s && !d || (a({ type: l.altKey ? "CLOSE" : "INPUT.ARROW_UP", keypress: h }), l.preventDefault());
237
216
  },
238
- Home(v) {
239
- p || (n({ type: "INPUT.HOME", keypress: h }), d && v.preventDefault());
217
+ Home(V) {
218
+ g || (a({ type: "INPUT.HOME", keypress: h }), d && V.preventDefault());
240
219
  },
241
- End(v) {
242
- p || (n({ type: "INPUT.END", keypress: h }), d && v.preventDefault());
220
+ End(V) {
221
+ g || (a({ type: "INPUT.END", keypress: h }), d && V.preventDefault());
243
222
  },
244
- Enter(v) {
245
- n({ type: "INPUT.ENTER", keypress: h }), d && v.preventDefault();
246
- const K = o.getHighlightedItemEl(t.context);
247
- j(K);
223
+ Enter(V) {
224
+ var W;
225
+ a({ type: "INPUT.ENTER", keypress: h });
226
+ const ue = C("isCustomValue") && n("allowCustomValue");
227
+ if (d && !ue && V.preventDefault(), b == null) return;
228
+ const _ = ae(r, b);
229
+ ve(_) && ((W = n("navigate")) == null || W({ value: b, node: _, href: _.href }));
248
230
  },
249
231
  Escape() {
250
- n({ type: "INPUT.ESCAPE", keypress: h }), l.preventDefault();
232
+ a({ type: "INPUT.ESCAPE", keypress: h }), l.preventDefault();
251
233
  }
252
- }, w = U(l, t.context), k = y[w];
253
- k == null || k(l);
234
+ }, re = $(l, { dir: n("dir") }), x = A[re];
235
+ x == null || x(l);
254
236
  }
255
237
  });
256
238
  },
257
239
  getTriggerProps(l = {}) {
258
- return e.button({
259
- ...I.trigger.attrs,
260
- dir: t.context.dir,
261
- id: o.getTriggerId(t.context),
262
- "aria-haspopup": E ? "listbox" : "dialog",
240
+ return t.button({
241
+ ...p.trigger.attrs,
242
+ dir: n("dir"),
243
+ id: le(r),
244
+ "aria-haspopup": N ? "listbox" : "dialog",
263
245
  type: "button",
264
246
  tabIndex: l.focusable ? void 0 : -1,
265
- "aria-label": i.triggerLabel,
247
+ "aria-label": O.triggerLabel,
266
248
  "aria-expanded": d,
267
249
  "data-state": d ? "open" : "closed",
268
- "aria-controls": d ? o.getContentId(t.context) : void 0,
269
- disabled: s,
270
- "data-invalid": u(O),
250
+ "aria-controls": d ? w(r) : void 0,
251
+ disabled: I,
252
+ "data-invalid": u(v),
271
253
  "data-focusable": u(l.focusable),
272
- "data-readonly": u(V),
273
- "data-disabled": u(s),
254
+ "data-readonly": u(S),
255
+ "data-disabled": u(I),
274
256
  onFocus() {
275
- l.focusable && n({ type: "INPUT.FOCUS", src: "trigger" });
257
+ l.focusable && a({ type: "INPUT.FOCUS", src: "trigger" });
276
258
  },
277
- onClick(a) {
278
- a.defaultPrevented || c && q(a) && n("TRIGGER.CLICK");
259
+ onClick(s) {
260
+ s.defaultPrevented || P && U(s) && a({ type: "TRIGGER.CLICK" });
279
261
  },
280
- onPointerDown(a) {
281
- c && a.pointerType !== "touch" && (a.preventDefault(), queueMicrotask(() => {
282
- var p;
283
- (p = o.getInputEl(t.context)) == null || p.focus({ preventScroll: !0 });
262
+ onPointerDown(s) {
263
+ P && s.pointerType !== "touch" && U(s) && (s.preventDefault(), queueMicrotask(() => {
264
+ var g;
265
+ (g = y(r)) == null || g.focus({ preventScroll: !0 });
284
266
  }));
285
267
  },
286
- onKeyDown(a) {
287
- if (a.defaultPrevented || E) return;
288
- const p = {
268
+ onKeyDown(s) {
269
+ if (s.defaultPrevented || N) return;
270
+ const g = {
289
271
  ArrowDown() {
290
- n({ type: "INPUT.ARROW_DOWN", src: "trigger" });
272
+ a({ type: "INPUT.ARROW_DOWN", src: "trigger" });
291
273
  },
292
274
  ArrowUp() {
293
- n({ type: "INPUT.ARROW_UP", src: "trigger" });
275
+ a({ type: "INPUT.ARROW_UP", src: "trigger" });
294
276
  }
295
- }, h = U(a, t.context), y = p[h];
296
- y && (y(a), a.preventDefault());
277
+ }, h = $(s, { dir: n("dir") }), A = g[h];
278
+ A && (A(s), s.preventDefault());
297
279
  }
298
280
  });
299
281
  },
300
282
  getContentProps() {
301
- return e.element({
302
- ...I.content.attrs,
303
- dir: t.context.dir,
304
- id: o.getContentId(t.context),
305
- role: E ? "listbox" : "dialog",
283
+ return t.element({
284
+ ...p.content.attrs,
285
+ dir: n("dir"),
286
+ id: w(r),
287
+ role: N ? "listbox" : "dialog",
306
288
  tabIndex: -1,
307
289
  hidden: !d,
308
290
  "data-state": d ? "open" : "closed",
309
- "data-placement": t.context.currentPlacement,
310
- "aria-labelledby": o.getLabelId(t.context),
311
- "aria-multiselectable": t.context.multiple && E ? !0 : void 0,
291
+ "data-placement": i.get("currentPlacement"),
292
+ "aria-labelledby": B(r),
293
+ "aria-multiselectable": n("multiple") && N ? !0 : void 0,
294
+ "data-empty": u(E.size === 0),
312
295
  onPointerDown(l) {
313
- l.preventDefault();
296
+ U(l) && l.preventDefault();
314
297
  }
315
298
  });
316
299
  },
317
300
  getListProps() {
318
- return e.element({
319
- ...I.list.attrs,
320
- role: E ? void 0 : "listbox",
321
- "aria-labelledby": o.getLabelId(t.context),
322
- "aria-multiselectable": t.context.multiple && !E ? !0 : void 0
301
+ return t.element({
302
+ ...p.list.attrs,
303
+ role: N ? void 0 : "listbox",
304
+ "data-empty": u(E.size === 0),
305
+ "aria-labelledby": B(r),
306
+ "aria-multiselectable": n("multiple") && !N ? !0 : void 0
323
307
  });
324
308
  },
325
309
  getClearTriggerProps() {
326
- return e.button({
327
- ...I.clearTrigger.attrs,
328
- dir: t.context.dir,
329
- id: o.getClearTriggerId(t.context),
310
+ return t.button({
311
+ ...p.clearTrigger.attrs,
312
+ dir: n("dir"),
313
+ id: oe(r),
330
314
  type: "button",
331
315
  tabIndex: -1,
332
- disabled: s,
333
- "data-invalid": u(O),
334
- "aria-label": i.clearTriggerLabel,
335
- "aria-controls": o.getInputId(t.context),
336
- hidden: !t.context.value.length,
316
+ disabled: I,
317
+ "data-invalid": u(v),
318
+ "aria-label": O.clearTriggerLabel,
319
+ "aria-controls": M(r),
320
+ hidden: !i.get("value").length,
337
321
  onPointerDown(l) {
338
- l.preventDefault();
322
+ U(l) && l.preventDefault();
339
323
  },
340
324
  onClick(l) {
341
- l.defaultPrevented || c && n({ type: "VALUE.CLEAR", src: "clear-trigger" });
325
+ l.defaultPrevented || P && a({ type: "VALUE.CLEAR", src: "clear-trigger" });
342
326
  }
343
327
  });
344
328
  },
345
- getItemState: T,
329
+ getItemState: H,
346
330
  getItemProps(l) {
347
- const a = T(l), p = a.value;
348
- return e.element({
349
- ...I.item.attrs,
350
- dir: t.context.dir,
351
- id: o.getItemId(t.context, p),
331
+ const s = H(l), g = s.value;
332
+ return t.element({
333
+ ...p.item.attrs,
334
+ dir: n("dir"),
335
+ id: J(r, g),
352
336
  role: "option",
353
337
  tabIndex: -1,
354
- "data-highlighted": u(a.highlighted),
355
- "data-state": a.selected ? "checked" : "unchecked",
356
- "aria-selected": A(a.highlighted),
357
- "aria-disabled": A(a.disabled),
358
- "data-disabled": u(a.disabled),
359
- "data-value": a.value,
338
+ "data-highlighted": u(s.highlighted),
339
+ "data-state": s.selected ? "checked" : "unchecked",
340
+ "aria-selected": K(s.highlighted),
341
+ "aria-disabled": K(s.disabled),
342
+ "data-disabled": u(s.disabled),
343
+ "data-value": s.value,
360
344
  onPointerMove() {
361
- a.disabled || a.highlighted || n({ type: "ITEM.POINTER_MOVE", value: p });
345
+ s.disabled || s.highlighted || a({ type: "ITEM.POINTER_MOVE", value: g });
362
346
  },
363
347
  onPointerLeave() {
364
- l.persistFocus || a.disabled || !t.previousEvent.type.includes("POINTER") || n({ type: "ITEM.POINTER_LEAVE", value: p });
348
+ if (l.persistFocus || s.disabled) return;
349
+ const h = k.previous();
350
+ h != null && h.type.includes("POINTER") && a({ type: "ITEM.POINTER_LEAVE", value: g });
365
351
  },
366
352
  onClick(h) {
367
- z(h) || x(h) || Y(h) || a.disabled || n({ type: "ITEM.CLICK", src: "click", value: p });
353
+ pe(h) || me(h) || Ce(h) || s.disabled || a({ type: "ITEM.CLICK", src: "click", value: g });
368
354
  }
369
355
  });
370
356
  },
371
357
  getItemTextProps(l) {
372
- const a = T(l);
373
- return e.element({
374
- ...I.itemText.attrs,
375
- dir: t.context.dir,
376
- "data-state": a.selected ? "checked" : "unchecked",
377
- "data-disabled": u(a.disabled),
378
- "data-highlighted": u(a.highlighted)
358
+ const s = H(l);
359
+ return t.element({
360
+ ...p.itemText.attrs,
361
+ dir: n("dir"),
362
+ "data-state": s.selected ? "checked" : "unchecked",
363
+ "data-disabled": u(s.disabled),
364
+ "data-highlighted": u(s.highlighted)
379
365
  });
380
366
  },
381
367
  getItemIndicatorProps(l) {
382
- const a = T(l);
383
- return e.element({
368
+ const s = H(l);
369
+ return t.element({
384
370
  "aria-hidden": !0,
385
- ...I.itemIndicator.attrs,
386
- dir: t.context.dir,
387
- "data-state": a.selected ? "checked" : "unchecked",
388
- hidden: !a.selected
371
+ ...p.itemIndicator.attrs,
372
+ dir: n("dir"),
373
+ "data-state": s.selected ? "checked" : "unchecked",
374
+ hidden: !s.selected
389
375
  });
390
376
  },
391
377
  getItemGroupProps(l) {
392
- const { id: a } = l;
393
- return e.element({
394
- ...I.itemGroup.attrs,
395
- dir: t.context.dir,
396
- id: o.getItemGroupId(t.context, a),
397
- "aria-labelledby": o.getItemGroupLabelId(t.context, a)
378
+ const { id: s } = l;
379
+ return t.element({
380
+ ...p.itemGroup.attrs,
381
+ dir: n("dir"),
382
+ id: Ae(r, s),
383
+ "aria-labelledby": j(r, s),
384
+ "data-empty": u(E.size === 0),
385
+ role: "group"
398
386
  });
399
387
  },
400
388
  getItemGroupLabelProps(l) {
401
- const { htmlFor: a } = l;
402
- return e.element({
403
- ...I.itemGroupLabel.attrs,
404
- dir: t.context.dir,
405
- id: o.getItemGroupLabelId(t.context, a),
406
- role: "group"
389
+ const { htmlFor: s } = l;
390
+ return t.element({
391
+ ...p.itemGroupLabel.attrs,
392
+ dir: n("dir"),
393
+ id: j(r, s),
394
+ role: "presentation"
407
395
  });
408
396
  }
409
397
  };
410
398
  }
411
- var { and: m, not: P } = $;
412
- function ve(t) {
413
- const n = oe(t);
414
- return W(
415
- {
416
- id: "combobox",
417
- initial: n.open ? "suggesting" : "idle",
418
- context: {
419
- loopFocus: !0,
420
- openOnClick: !1,
421
- value: [],
422
- highlightedValue: null,
423
- inputValue: "",
424
- allowCustomValue: !1,
425
- closeOnSelect: !n.multiple,
426
- inputBehavior: "none",
427
- selectionBehavior: "replace",
428
- openOnKeyPress: !0,
429
- openOnChange: !0,
430
- composite: !0,
431
- readOnly: !1,
432
- disabled: !1,
433
- ...n,
434
- highlightedItem: null,
435
- selectedItems: [],
436
- valueAsString: "",
437
- collection: n.collection ?? _.empty(),
438
- positioning: {
439
- placement: "bottom",
440
- sameWidth: !0,
441
- ...n.positioning
442
- },
443
- translations: {
444
- triggerLabel: "Toggle suggestions",
445
- clearTriggerLabel: "Clear value",
446
- ...n.translations
447
- }
448
- },
449
- created: ["syncInitialValues", "syncSelectionBehavior"],
450
- computed: {
451
- isInputValueEmpty: (e) => e.inputValue.length === 0,
452
- isInteractive: (e) => !(e.readOnly || e.disabled),
453
- autoComplete: (e) => e.inputBehavior === "autocomplete",
454
- autoHighlight: (e) => e.inputBehavior === "autohighlight",
455
- hasSelectedItems: (e) => e.value.length > 0
399
+ var { guards: He, createMachine: Ue, choose: De } = be(), { and: c, not: m } = He, je = Ue({
400
+ props({ props: e }) {
401
+ return {
402
+ loopFocus: !0,
403
+ openOnClick: !1,
404
+ defaultValue: [],
405
+ closeOnSelect: !e.multiple,
406
+ allowCustomValue: !1,
407
+ inputBehavior: "none",
408
+ selectionBehavior: e.multiple ? "clear" : "replace",
409
+ openOnKeyPress: !0,
410
+ openOnChange: !0,
411
+ composite: !0,
412
+ navigate({ node: t }) {
413
+ Ie(t);
456
414
  },
457
- watch: {
458
- value: ["syncSelectedItems"],
459
- inputValue: ["syncInputValue"],
460
- highlightedValue: ["syncHighlightedItem", "autofillInputValue"],
461
- multiple: ["syncSelectionBehavior"],
462
- open: ["toggleVisibility"]
415
+ collection: te.empty(),
416
+ ...e,
417
+ positioning: {
418
+ placement: "bottom",
419
+ sameWidth: !0,
420
+ ...e.positioning
463
421
  },
464
- on: {
465
- "HIGHLIGHTED_VALUE.SET": {
466
- actions: ["setHighlightedItem"]
467
- },
468
- "ITEM.SELECT": {
469
- actions: ["selectItem"]
470
- },
471
- "ITEM.CLEAR": {
472
- actions: ["clearItem"]
473
- },
474
- "VALUE.SET": {
475
- actions: ["setSelectedItems"]
476
- },
477
- "INPUT_VALUE.SET": {
478
- actions: "setInputValue"
479
- },
480
- "COLLECTION.SET": {
481
- actions: ["setCollection"]
422
+ translations: {
423
+ triggerLabel: "Toggle suggestions",
424
+ clearTriggerLabel: "Clear value",
425
+ ...e.translations
426
+ }
427
+ };
428
+ },
429
+ initialState({ prop: e }) {
430
+ return e("open") || e("defaultOpen") ? "suggesting" : "idle";
431
+ },
432
+ context({ prop: e, bindable: t, getContext: i }) {
433
+ return {
434
+ currentPlacement: t(() => ({
435
+ defaultValue: void 0
436
+ })),
437
+ value: t(() => ({
438
+ defaultValue: e("defaultValue"),
439
+ value: e("value"),
440
+ isEqual: Pe,
441
+ hash(n) {
442
+ return n.join(",");
482
443
  },
483
- "POSITIONING.SET": {
484
- actions: ["reposition"]
444
+ onChange(n) {
445
+ var k;
446
+ const o = i(), a = o.get("selectedItems"), r = e("collection"), C = n.map((O) => a.find((I) => r.getItemValue(I) === O) || r.find(O));
447
+ o.set("selectedItems", C), o.set("valueAsString", r.stringifyItems(C)), (k = e("onValueChange")) == null || k({ value: n, items: C });
485
448
  }
486
- },
487
- states: {
488
- idle: {
489
- tags: ["idle", "closed"],
490
- entry: ["scrollContentToTop", "clearHighlightedItem"],
491
- on: {
492
- "CONTROLLED.OPEN": {
493
- target: "interacting"
494
- },
495
- "TRIGGER.CLICK": [
496
- {
497
- guard: "isOpenControlled",
498
- actions: ["setInitialFocus", "highlightFirstSelectedItem", "invokeOnOpen"]
499
- },
500
- {
501
- target: "interacting",
502
- actions: ["setInitialFocus", "highlightFirstSelectedItem", "invokeOnOpen"]
503
- }
504
- ],
505
- "INPUT.CLICK": [
506
- {
507
- guard: "isOpenControlled",
508
- actions: ["highlightFirstSelectedItem", "invokeOnOpen"]
509
- },
510
- {
511
- target: "interacting",
512
- actions: ["highlightFirstSelectedItem", "invokeOnOpen"]
513
- }
514
- ],
515
- "INPUT.FOCUS": {
516
- target: "focused"
517
- },
518
- OPEN: [
519
- {
520
- guard: "isOpenControlled",
521
- actions: ["invokeOnOpen"]
522
- },
523
- {
524
- target: "interacting",
525
- actions: ["invokeOnOpen"]
526
- }
527
- ],
528
- "VALUE.CLEAR": {
529
- target: "focused",
530
- actions: ["clearInputValue", "clearSelectedItems", "setInitialFocus"]
531
- }
449
+ })),
450
+ highlightedValue: t(() => ({
451
+ defaultValue: e("defaultHighlightedValue") || null,
452
+ value: e("highlightedValue"),
453
+ onChange(n) {
454
+ var a;
455
+ const o = e("collection").find(n);
456
+ (a = e("onHighlightChange")) == null || a({ highlightedValue: n, highlightedItem: o });
457
+ }
458
+ })),
459
+ inputValue: t(() => {
460
+ let n = e("inputValue") || e("defaultInputValue") || "";
461
+ const o = e("defaultValue") || e("value") || [];
462
+ if (!n.trim() && !e("multiple")) {
463
+ const a = e("collection").stringifyMany(o);
464
+ n = D(e("selectionBehavior"), {
465
+ preserve: n || a,
466
+ replace: a,
467
+ clear: ""
468
+ });
469
+ }
470
+ return {
471
+ defaultValue: n,
472
+ value: e("inputValue"),
473
+ onChange(a) {
474
+ var r;
475
+ (r = e("onInputValueChange")) == null || r({ inputValue: a });
532
476
  }
477
+ };
478
+ }),
479
+ highlightedItem: t(() => {
480
+ const n = e("highlightedValue");
481
+ return { defaultValue: e("collection").find(n) };
482
+ }),
483
+ selectedItems: t(() => {
484
+ const n = e("value") || e("defaultValue") || [];
485
+ return { defaultValue: e("collection").findMany(n) };
486
+ }),
487
+ valueAsString: t(() => {
488
+ const n = e("value") || e("defaultValue") || [];
489
+ return { sync: !0, defaultValue: e("collection").stringifyMany(n) };
490
+ })
491
+ };
492
+ },
493
+ computed: {
494
+ isInputValueEmpty: ({ context: e }) => e.get("inputValue").length === 0,
495
+ isInteractive: ({ prop: e }) => !(e("readOnly") || e("disabled")),
496
+ autoComplete: ({ prop: e }) => e("inputBehavior") === "autocomplete",
497
+ autoHighlight: ({ prop: e }) => e("inputBehavior") === "autohighlight",
498
+ hasSelectedItems: ({ context: e }) => e.get("value").length > 0,
499
+ isCustomValue: ({ context: e }) => e.get("inputValue") !== e.get("valueAsString")
500
+ },
501
+ watch({ context: e, prop: t, track: i, action: n }) {
502
+ i([() => e.hash("value")], () => {
503
+ n(["syncSelectedItems"]);
504
+ }), i([() => e.get("inputValue")], () => {
505
+ n(["syncInputValue"]);
506
+ }), i([() => e.get("highlightedValue")], () => {
507
+ n(["syncHighlightedItem", "autofillInputValue"]);
508
+ }), i([() => t("open")], () => {
509
+ n(["toggleVisibility"]);
510
+ });
511
+ },
512
+ on: {
513
+ "SELECTED_ITEMS.SYNC": {
514
+ actions: ["syncSelectedItems"]
515
+ },
516
+ "HIGHLIGHTED_VALUE.SET": {
517
+ actions: ["setHighlightedItem"]
518
+ },
519
+ "ITEM.SELECT": {
520
+ actions: ["selectItem"]
521
+ },
522
+ "ITEM.CLEAR": {
523
+ actions: ["clearItem"]
524
+ },
525
+ "VALUE.SET": {
526
+ actions: ["setValue"]
527
+ },
528
+ "INPUT_VALUE.SET": {
529
+ actions: ["setInputValue"]
530
+ },
531
+ "POSITIONING.SET": {
532
+ actions: ["reposition"]
533
+ }
534
+ },
535
+ entry: De([
536
+ {
537
+ guard: "autoFocus",
538
+ actions: ["setInitialFocus"]
539
+ }
540
+ ]),
541
+ states: {
542
+ idle: {
543
+ tags: ["idle", "closed"],
544
+ entry: ["scrollContentToTop", "clearHighlightedItem"],
545
+ on: {
546
+ "CONTROLLED.OPEN": {
547
+ target: "interacting"
533
548
  },
534
- focused: {
535
- tags: ["focused", "closed"],
536
- entry: ["scrollContentToTop", "clearHighlightedItem"],
537
- on: {
538
- "CONTROLLED.OPEN": [
539
- {
540
- guard: "isChangeEvent",
541
- target: "suggesting"
542
- },
543
- {
544
- target: "interacting"
545
- }
546
- ],
547
- "INPUT.CHANGE": [
548
- {
549
- guard: m("isOpenControlled", "openOnChange"),
550
- actions: ["setInputValue", "invokeOnOpen", "highlightFirstItemIfNeeded"]
551
- },
552
- {
553
- guard: "openOnChange",
554
- target: "suggesting",
555
- actions: ["setInputValue", "invokeOnOpen", "highlightFirstItemIfNeeded"]
556
- },
557
- {
558
- actions: "setInputValue"
559
- }
560
- ],
561
- "LAYER.INTERACT_OUTSIDE": {
562
- target: "idle"
563
- },
564
- "INPUT.ESCAPE": {
565
- guard: m("isCustomValue", P("allowCustomValue")),
566
- actions: "revertInputValue"
567
- },
568
- "INPUT.BLUR": {
569
- target: "idle"
570
- },
571
- "INPUT.CLICK": [
572
- {
573
- guard: "isOpenControlled",
574
- actions: ["highlightFirstSelectedItem", "invokeOnOpen"]
575
- },
576
- {
577
- target: "interacting",
578
- actions: ["highlightFirstSelectedItem", "invokeOnOpen"]
579
- }
580
- ],
581
- "TRIGGER.CLICK": [
582
- {
583
- guard: "isOpenControlled",
584
- actions: ["setInitialFocus", "highlightFirstSelectedItem", "invokeOnOpen"]
585
- },
586
- {
587
- target: "interacting",
588
- actions: ["setInitialFocus", "highlightFirstSelectedItem", "invokeOnOpen"]
589
- }
590
- ],
591
- "INPUT.ARROW_DOWN": [
592
- // == group 1 ==
593
- {
594
- guard: m("isOpenControlled", "autoComplete"),
595
- actions: ["invokeOnOpen"]
596
- },
597
- {
598
- guard: "autoComplete",
599
- target: "interacting",
600
- actions: ["invokeOnOpen"]
601
- },
602
- // == group 2 ==
603
- {
604
- guard: "isOpenControlled",
605
- actions: ["highlightFirstOrSelectedItem", "invokeOnOpen"]
606
- },
607
- {
608
- target: "interacting",
609
- actions: ["highlightFirstOrSelectedItem", "invokeOnOpen"]
610
- }
611
- ],
612
- "INPUT.ARROW_UP": [
613
- // == group 1 ==
614
- {
615
- guard: "autoComplete",
616
- target: "interacting",
617
- actions: "invokeOnOpen"
618
- },
619
- {
620
- guard: "autoComplete",
621
- target: "interacting",
622
- actions: "invokeOnOpen"
623
- },
624
- // == group 2 ==
625
- {
626
- target: "interacting",
627
- actions: ["highlightLastOrSelectedItem", "invokeOnOpen"]
628
- },
629
- {
630
- target: "interacting",
631
- actions: ["highlightLastOrSelectedItem", "invokeOnOpen"]
632
- }
633
- ],
634
- OPEN: [
635
- {
636
- guard: "isOpenControlled",
637
- actions: ["invokeOnOpen"]
638
- },
639
- {
640
- target: "interacting",
641
- actions: ["invokeOnOpen"]
642
- }
643
- ],
644
- "VALUE.CLEAR": {
645
- actions: ["clearInputValue", "clearSelectedItems"]
646
- }
549
+ "TRIGGER.CLICK": [
550
+ {
551
+ guard: "isOpenControlled",
552
+ actions: ["setInitialFocus", "highlightFirstSelectedItem", "invokeOnOpen"]
553
+ },
554
+ {
555
+ target: "interacting",
556
+ actions: ["setInitialFocus", "highlightFirstSelectedItem", "invokeOnOpen"]
647
557
  }
648
- },
649
- interacting: {
650
- tags: ["open", "focused"],
651
- entry: ["setInitialFocus"],
652
- activities: ["scrollToHighlightedItem", "trackDismissableLayer", "computePlacement", "hideOtherElements"],
653
- on: {
654
- "CONTROLLED.CLOSE": [
655
- {
656
- guard: "restoreFocus",
657
- target: "focused",
658
- actions: ["setFinalFocus"]
659
- },
660
- {
661
- target: "idle"
662
- }
663
- ],
664
- "INPUT.HOME": {
665
- actions: ["highlightFirstItem"]
666
- },
667
- "INPUT.END": {
668
- actions: ["highlightLastItem"]
669
- },
670
- "INPUT.ARROW_DOWN": [
671
- {
672
- guard: m("autoComplete", "isLastItemHighlighted"),
673
- actions: ["clearHighlightedItem", "scrollContentToTop"]
674
- },
675
- {
676
- actions: ["highlightNextItem"]
677
- }
678
- ],
679
- "INPUT.ARROW_UP": [
680
- {
681
- guard: m("autoComplete", "isFirstItemHighlighted"),
682
- actions: "clearHighlightedItem"
683
- },
684
- {
685
- actions: "highlightPrevItem"
686
- }
687
- ],
688
- "INPUT.ENTER": [
689
- {
690
- guard: m("isOpenControlled", "closeOnSelect"),
691
- actions: ["selectHighlightedItem", "invokeOnClose"]
692
- },
693
- {
694
- guard: "closeOnSelect",
695
- target: "focused",
696
- actions: ["selectHighlightedItem", "invokeOnClose", "setFinalFocus"]
697
- },
698
- {
699
- actions: ["selectHighlightedItem"]
700
- }
701
- ],
702
- "INPUT.CHANGE": [
703
- {
704
- guard: "autoComplete",
705
- target: "suggesting",
706
- actions: ["setInputValue", "invokeOnOpen"]
707
- },
708
- {
709
- target: "suggesting",
710
- actions: ["clearHighlightedItem", "setInputValue", "invokeOnOpen"]
711
- }
712
- ],
713
- "ITEM.POINTER_MOVE": {
714
- actions: ["setHighlightedItem"]
715
- },
716
- "ITEM.POINTER_LEAVE": {
717
- actions: ["clearHighlightedItem"]
718
- },
719
- "ITEM.CLICK": [
720
- {
721
- guard: m("isOpenControlled", "closeOnSelect"),
722
- actions: ["selectItem", "invokeOnClose"]
723
- },
724
- {
725
- guard: "closeOnSelect",
726
- target: "focused",
727
- actions: ["selectItem", "invokeOnClose", "setFinalFocus"]
728
- },
729
- {
730
- actions: ["selectItem"]
731
- }
732
- ],
733
- "LAYER.ESCAPE": [
734
- {
735
- guard: m("isOpenControlled", "autoComplete"),
736
- actions: ["syncInputValue", "invokeOnClose"]
737
- },
738
- {
739
- guard: "autoComplete",
740
- target: "focused",
741
- actions: ["syncInputValue", "invokeOnClose"]
742
- },
743
- {
744
- guard: "isOpenControlled",
745
- actions: "invokeOnClose"
746
- },
747
- {
748
- target: "focused",
749
- actions: ["invokeOnClose", "setFinalFocus"]
750
- }
751
- ],
752
- "TRIGGER.CLICK": [
753
- {
754
- guard: "isOpenControlled",
755
- actions: "invokeOnClose"
756
- },
757
- {
758
- target: "focused",
759
- actions: "invokeOnClose"
760
- }
761
- ],
762
- "LAYER.INTERACT_OUTSIDE": [
763
- // == group 1 ==
764
- {
765
- guard: m("isOpenControlled", "isCustomValue", P("allowCustomValue")),
766
- actions: ["revertInputValue", "invokeOnClose"]
767
- },
768
- {
769
- guard: m("isCustomValue", P("allowCustomValue")),
770
- target: "idle",
771
- actions: ["revertInputValue", "invokeOnClose"]
772
- },
773
- // == group 2 ==
774
- {
775
- guard: "isOpenControlled",
776
- actions: "invokeOnClose"
777
- },
778
- {
779
- target: "idle",
780
- actions: "invokeOnClose"
781
- }
782
- ],
783
- CLOSE: [
784
- {
785
- guard: "isOpenControlled",
786
- actions: ["invokeOnClose"]
787
- },
788
- {
789
- target: "focused",
790
- actions: ["invokeOnClose", "setFinalFocus"]
791
- }
792
- ],
793
- "VALUE.CLEAR": [
794
- {
795
- guard: "isOpenControlled",
796
- actions: ["clearInputValue", "clearSelectedItems", "invokeOnClose"]
797
- },
798
- {
799
- target: "focused",
800
- actions: ["clearInputValue", "clearSelectedItems", "invokeOnClose", "setFinalFocus"]
801
- }
802
- ]
558
+ ],
559
+ "INPUT.CLICK": [
560
+ {
561
+ guard: "isOpenControlled",
562
+ actions: ["highlightFirstSelectedItem", "invokeOnOpen"]
563
+ },
564
+ {
565
+ target: "interacting",
566
+ actions: ["highlightFirstSelectedItem", "invokeOnOpen"]
803
567
  }
568
+ ],
569
+ "INPUT.FOCUS": {
570
+ target: "focused"
804
571
  },
805
- suggesting: {
806
- tags: ["open", "focused"],
807
- activities: [
808
- "trackDismissableLayer",
809
- "scrollToHighlightedItem",
810
- "computePlacement",
811
- "trackChildNodes",
812
- "hideOtherElements"
813
- ],
814
- entry: ["setInitialFocus"],
815
- on: {
816
- "CONTROLLED.CLOSE": [
817
- {
818
- guard: "restoreFocus",
819
- target: "focused",
820
- actions: ["setFinalFocus"]
821
- },
822
- {
823
- target: "idle"
824
- }
825
- ],
826
- CHILDREN_CHANGE: {
827
- actions: ["highlightFirstItem"]
828
- },
829
- "INPUT.ARROW_DOWN": {
830
- target: "interacting",
831
- actions: ["highlightNextItem"]
832
- },
833
- "INPUT.ARROW_UP": {
834
- target: "interacting",
835
- actions: ["highlightPrevItem"]
836
- },
837
- "INPUT.HOME": {
838
- target: "interacting",
839
- actions: ["highlightFirstItem"]
840
- },
841
- "INPUT.END": {
842
- target: "interacting",
843
- actions: ["highlightLastItem"]
844
- },
845
- "INPUT.ENTER": [
846
- {
847
- guard: m("isOpenControlled", "closeOnSelect"),
848
- actions: ["selectHighlightedItem", "invokeOnClose"]
849
- },
850
- {
851
- guard: "closeOnSelect",
852
- target: "focused",
853
- actions: ["selectHighlightedItem", "invokeOnClose", "setFinalFocus"]
854
- },
855
- {
856
- actions: ["selectHighlightedItem"]
857
- }
858
- ],
859
- "INPUT.CHANGE": [
860
- {
861
- guard: "autoHighlight",
862
- actions: ["setInputValue"]
863
- },
864
- {
865
- actions: ["setInputValue"]
866
- }
867
- ],
868
- "LAYER.ESCAPE": [
869
- {
870
- guard: "isOpenControlled",
871
- actions: ["invokeOnClose"]
872
- },
873
- {
874
- target: "focused",
875
- actions: ["invokeOnClose"]
876
- }
877
- ],
878
- "ITEM.POINTER_MOVE": {
879
- target: "interacting",
880
- actions: ["setHighlightedItem"]
881
- },
882
- "ITEM.POINTER_LEAVE": {
883
- actions: ["clearHighlightedItem"]
884
- },
885
- "LAYER.INTERACT_OUTSIDE": [
886
- // == group 1 ==
887
- {
888
- guard: m("isOpenControlled", "isCustomValue", P("allowCustomValue")),
889
- actions: ["revertInputValue", "invokeOnClose"]
890
- },
891
- {
892
- guard: m("isCustomValue", P("allowCustomValue")),
893
- target: "idle",
894
- actions: ["revertInputValue", "invokeOnClose"]
895
- },
896
- // == group 2 ==
897
- {
898
- guard: "isOpenControlled",
899
- actions: ["invokeOnClose"]
900
- },
901
- {
902
- target: "idle",
903
- actions: ["invokeOnClose"]
904
- }
905
- ],
906
- "TRIGGER.CLICK": [
907
- {
908
- guard: "isOpenControlled",
909
- actions: ["invokeOnClose"]
910
- },
911
- {
912
- target: "focused",
913
- actions: ["invokeOnClose"]
914
- }
915
- ],
916
- "ITEM.CLICK": [
917
- {
918
- guard: m("isOpenControlled", "closeOnSelect"),
919
- actions: ["selectItem", "invokeOnClose"]
920
- },
921
- {
922
- guard: "closeOnSelect",
923
- target: "focused",
924
- actions: ["selectItem", "invokeOnClose", "setFinalFocus"]
925
- },
926
- {
927
- actions: ["selectItem"]
928
- }
929
- ],
930
- CLOSE: [
931
- {
932
- guard: "isOpenControlled",
933
- actions: ["invokeOnClose"]
934
- },
935
- {
936
- target: "focused",
937
- actions: ["invokeOnClose", "setFinalFocus"]
938
- }
939
- ],
940
- "VALUE.CLEAR": [
941
- {
942
- guard: "isOpenControlled",
943
- actions: ["clearInputValue", "clearSelectedItems", "invokeOnClose"]
944
- },
945
- {
946
- target: "focused",
947
- actions: ["clearInputValue", "clearSelectedItems", "invokeOnClose", "setFinalFocus"]
948
- }
949
- ]
572
+ OPEN: [
573
+ {
574
+ guard: "isOpenControlled",
575
+ actions: ["invokeOnOpen"]
576
+ },
577
+ {
578
+ target: "interacting",
579
+ actions: ["invokeOnOpen"]
950
580
  }
581
+ ],
582
+ "VALUE.CLEAR": {
583
+ target: "focused",
584
+ actions: ["clearInputValue", "clearSelectedItems", "setInitialFocus"]
951
585
  }
952
586
  }
953
587
  },
954
- {
955
- guards: {
956
- isInputValueEmpty: (e) => e.isInputValueEmpty,
957
- autoComplete: (e) => e.autoComplete && !e.multiple,
958
- autoHighlight: (e) => e.autoHighlight,
959
- isFirstItemHighlighted: (e) => e.collection.firstValue === e.highlightedValue,
960
- isLastItemHighlighted: (e) => e.collection.lastValue === e.highlightedValue,
961
- isCustomValue: (e) => e.inputValue !== e.valueAsString,
962
- allowCustomValue: (e) => !!e.allowCustomValue,
963
- hasHighlightedItem: (e) => e.highlightedValue != null,
964
- closeOnSelect: (e) => !!e.closeOnSelect,
965
- isOpenControlled: (e) => !!e["open.controlled"],
966
- openOnChange: (e, i) => {
967
- var r;
968
- return ae(e.openOnChange) ? e.openOnChange : !!((r = e.openOnChange) != null && r.call(e, { inputValue: i.value }));
969
- },
970
- restoreFocus: (e, i) => i.restoreFocus == null ? !0 : !!i.restoreFocus,
971
- isChangeEvent: (e, i) => {
972
- var r;
973
- return ((r = i.previousEvent) == null ? void 0 : r.type) === "INPUT.CHANGE";
974
- }
975
- },
976
- activities: {
977
- trackDismissableLayer(e, i, { send: r }) {
978
- return e.disableLayer ? void 0 : le(() => o.getContentEl(e), {
979
- defer: !0,
980
- exclude: () => [o.getInputEl(e), o.getTriggerEl(e), o.getClearTriggerEl(e)],
981
- onFocusOutside: e.onFocusOutside,
982
- onPointerDownOutside: e.onPointerDownOutside,
983
- onInteractOutside: e.onInteractOutside,
984
- onEscapeKeyDown(c) {
985
- c.preventDefault(), c.stopPropagation(), r("LAYER.ESCAPE");
986
- },
987
- onDismiss() {
988
- r({ type: "LAYER.INTERACT_OUTSIDE", restoreFocus: !1 });
989
- }
990
- });
991
- },
992
- hideOtherElements(e) {
993
- return ie([o.getInputEl(e), o.getContentEl(e), o.getTriggerEl(e)]);
588
+ focused: {
589
+ tags: ["focused", "closed"],
590
+ entry: ["scrollContentToTop", "clearHighlightedItem"],
591
+ on: {
592
+ "CONTROLLED.OPEN": [
593
+ {
594
+ guard: "isChangeEvent",
595
+ target: "suggesting"
596
+ },
597
+ {
598
+ target: "interacting"
599
+ }
600
+ ],
601
+ "INPUT.CHANGE": [
602
+ {
603
+ guard: c("isOpenControlled", "openOnChange"),
604
+ actions: ["setInputValue", "invokeOnOpen", "highlightFirstItemIfNeeded"]
605
+ },
606
+ {
607
+ guard: "openOnChange",
608
+ target: "suggesting",
609
+ actions: ["setInputValue", "invokeOnOpen", "highlightFirstItemIfNeeded"]
610
+ },
611
+ {
612
+ actions: ["setInputValue"]
613
+ }
614
+ ],
615
+ "LAYER.INTERACT_OUTSIDE": {
616
+ target: "idle"
994
617
  },
995
- computePlacement(e) {
996
- const i = () => o.getControlEl(e), r = () => o.getPositionerEl(e);
997
- return e.currentPlacement = e.positioning.placement, H(i, r, {
998
- ...e.positioning,
999
- defer: !0,
1000
- onComplete(s) {
1001
- e.currentPlacement = s.placement;
1002
- }
1003
- });
618
+ "INPUT.ESCAPE": {
619
+ guard: c("isCustomValue", m("allowCustomValue")),
620
+ actions: ["revertInputValue"]
1004
621
  },
1005
- // in event the options are fetched (async), we still want to auto-highlight the first option
1006
- trackChildNodes(e, i, { send: r }) {
1007
- return e.autoHighlight ? X(() => o.getContentEl(e), {
1008
- callback: () => r("CHILDREN_CHANGE"),
1009
- defer: !0
1010
- }) : void 0;
622
+ "INPUT.BLUR": {
623
+ target: "idle"
1011
624
  },
1012
- scrollToHighlightedItem(e, i, { getState: r }) {
1013
- const s = o.getInputEl(e);
1014
- let c = [];
1015
- const O = (f) => {
1016
- if (r().event.type.includes("POINTER") || !e.highlightedValue) return;
1017
- const N = o.getHighlightedItemEl(e), T = o.getContentEl(e);
1018
- if (e.scrollToIndexFn) {
1019
- const a = e.collection.indexOf(e.highlightedValue);
1020
- e.scrollToIndexFn({ index: a, immediate: f });
1021
- return;
1022
- }
1023
- const l = C(() => {
1024
- Z(N, { rootEl: T, block: "nearest" });
1025
- });
1026
- c.push(l);
1027
- }, V = C(() => O(!0));
1028
- c.push(V);
1029
- const d = Q(s, {
1030
- attributes: ["aria-activedescendant"],
1031
- callback: () => O(!1)
1032
- });
1033
- return c.push(d), () => {
1034
- c.forEach((f) => f());
1035
- };
625
+ "INPUT.CLICK": [
626
+ {
627
+ guard: "isOpenControlled",
628
+ actions: ["highlightFirstSelectedItem", "invokeOnOpen"]
629
+ },
630
+ {
631
+ target: "interacting",
632
+ actions: ["highlightFirstSelectedItem", "invokeOnOpen"]
633
+ }
634
+ ],
635
+ "TRIGGER.CLICK": [
636
+ {
637
+ guard: "isOpenControlled",
638
+ actions: ["setInitialFocus", "highlightFirstSelectedItem", "invokeOnOpen"]
639
+ },
640
+ {
641
+ target: "interacting",
642
+ actions: ["setInitialFocus", "highlightFirstSelectedItem", "invokeOnOpen"]
643
+ }
644
+ ],
645
+ "INPUT.ARROW_DOWN": [
646
+ // == group 1 ==
647
+ {
648
+ guard: c("isOpenControlled", "autoComplete"),
649
+ actions: ["invokeOnOpen"]
650
+ },
651
+ {
652
+ guard: "autoComplete",
653
+ target: "interacting",
654
+ actions: ["invokeOnOpen"]
655
+ },
656
+ // == group 2 ==
657
+ {
658
+ guard: "isOpenControlled",
659
+ actions: ["highlightFirstOrSelectedItem", "invokeOnOpen"]
660
+ },
661
+ {
662
+ target: "interacting",
663
+ actions: ["highlightFirstOrSelectedItem", "invokeOnOpen"]
664
+ }
665
+ ],
666
+ "INPUT.ARROW_UP": [
667
+ // == group 1 ==
668
+ {
669
+ guard: "autoComplete",
670
+ target: "interacting",
671
+ actions: ["invokeOnOpen"]
672
+ },
673
+ {
674
+ guard: "autoComplete",
675
+ target: "interacting",
676
+ actions: ["invokeOnOpen"]
677
+ },
678
+ // == group 2 ==
679
+ {
680
+ target: "interacting",
681
+ actions: ["highlightLastOrSelectedItem", "invokeOnOpen"]
682
+ },
683
+ {
684
+ target: "interacting",
685
+ actions: ["highlightLastOrSelectedItem", "invokeOnOpen"]
686
+ }
687
+ ],
688
+ OPEN: [
689
+ {
690
+ guard: "isOpenControlled",
691
+ actions: ["invokeOnOpen"]
692
+ },
693
+ {
694
+ target: "interacting",
695
+ actions: ["invokeOnOpen"]
696
+ }
697
+ ],
698
+ "VALUE.CLEAR": {
699
+ actions: ["clearInputValue", "clearSelectedItems"]
1036
700
  }
1037
- },
1038
- actions: {
1039
- reposition(e, i) {
1040
- H(() => o.getControlEl(e), () => o.getPositionerEl(e), {
1041
- ...e.positioning,
1042
- ...i.options,
1043
- defer: !0,
1044
- listeners: !1,
1045
- onComplete(c) {
1046
- e.currentPlacement = c.placement;
1047
- }
1048
- });
1049
- },
1050
- setHighlightedItem(e, i) {
1051
- i.value != null && g.highlightedValue(e, i.value);
1052
- },
1053
- clearHighlightedItem(e) {
1054
- g.highlightedValue(e, null, !0);
1055
- },
1056
- selectHighlightedItem(e) {
1057
- g.value(e, e.highlightedValue);
1058
- },
1059
- selectItem(e, i) {
1060
- i.value != null && g.value(e, i.value);
1061
- },
1062
- clearItem(e, i) {
1063
- if (i.value == null) return;
1064
- const r = e.value.filter((s) => s !== i.value);
1065
- g.value(e, r);
1066
- },
1067
- setInitialFocus(e) {
1068
- C(() => {
1069
- o.focusInputEl(e);
1070
- });
1071
- },
1072
- setFinalFocus(e) {
1073
- C(() => {
1074
- const i = o.getTriggerEl(e);
1075
- (i == null ? void 0 : i.dataset.focusable) == null ? o.focusInputEl(e) : o.focusTriggerEl(e);
1076
- });
1077
- },
1078
- syncInputValue(e) {
1079
- const i = o.getInputEl(e);
1080
- i && (i.value = e.inputValue, queueMicrotask(() => {
1081
- const { selectionStart: r, selectionEnd: s } = i;
1082
- Math.abs((s ?? 0) - (r ?? 0)) === 0 && r === 0 && i.setSelectionRange(i.value.length, i.value.length);
1083
- }));
1084
- },
1085
- setInputValue(e, i) {
1086
- g.inputValue(e, i.value);
1087
- },
1088
- clearInputValue(e) {
1089
- g.inputValue(e, "");
1090
- },
1091
- revertInputValue(e) {
1092
- const i = R(e.selectionBehavior, {
1093
- replace: e.hasSelectedItems ? e.valueAsString : "",
1094
- preserve: e.inputValue,
1095
- clear: ""
1096
- });
1097
- g.inputValue(e, i);
1098
- },
1099
- syncInitialValues(e) {
1100
- const i = e.collection.findMany(e.value), r = e.collection.stringifyMany(e.value);
1101
- e.highlightedItem = e.collection.find(e.highlightedValue), e.selectedItems = i, e.valueAsString = r, !(e.inputValue.trim() || e.multiple) && (e.inputValue = R(e.selectionBehavior, {
1102
- preserve: e.inputValue || r,
1103
- replace: r,
1104
- clear: ""
1105
- }));
1106
- },
1107
- syncSelectionBehavior(e) {
1108
- e.multiple && (e.selectionBehavior = "clear");
1109
- },
1110
- setSelectedItems(e, i) {
1111
- G(i.value) && g.value(e, i.value);
1112
- },
1113
- clearSelectedItems(e) {
1114
- g.value(e, []);
1115
- },
1116
- scrollContentToTop(e) {
1117
- if (e.scrollToIndexFn)
1118
- e.scrollToIndexFn({ index: 0, immediate: !0 });
1119
- else {
1120
- const i = o.getContentEl(e);
1121
- if (!i) return;
1122
- i.scrollTop = 0;
701
+ }
702
+ },
703
+ interacting: {
704
+ tags: ["open", "focused"],
705
+ entry: ["setInitialFocus"],
706
+ effects: ["scrollToHighlightedItem", "trackDismissableLayer", "trackPlacement", "hideOtherElements"],
707
+ on: {
708
+ "CONTROLLED.CLOSE": [
709
+ {
710
+ guard: "restoreFocus",
711
+ target: "focused",
712
+ actions: ["setFinalFocus"]
713
+ },
714
+ {
715
+ target: "idle"
1123
716
  }
717
+ ],
718
+ "INPUT.HOME": {
719
+ actions: ["highlightFirstItem"]
1124
720
  },
1125
- invokeOnOpen(e) {
1126
- var i;
1127
- (i = e.onOpenChange) == null || i.call(e, { open: !0 });
1128
- },
1129
- invokeOnClose(e) {
1130
- var i;
1131
- (i = e.onOpenChange) == null || i.call(e, { open: !1 });
1132
- },
1133
- highlightFirstItem(e) {
1134
- C(() => {
1135
- const i = e.collection.firstValue;
1136
- g.highlightedValue(e, i, !0);
1137
- });
1138
- },
1139
- highlightFirstItemIfNeeded(e) {
1140
- e.autoHighlight && C(() => {
1141
- const i = e.collection.firstValue;
1142
- g.highlightedValue(e, i);
1143
- });
721
+ "INPUT.END": {
722
+ actions: ["highlightLastItem"]
1144
723
  },
1145
- highlightLastItem(e) {
1146
- C(() => {
1147
- const i = e.collection.lastValue;
1148
- g.highlightedValue(e, i);
1149
- });
724
+ "INPUT.ARROW_DOWN": [
725
+ {
726
+ guard: c("autoComplete", "isLastItemHighlighted"),
727
+ actions: ["clearHighlightedItem", "scrollContentToTop"]
728
+ },
729
+ {
730
+ actions: ["highlightNextItem"]
731
+ }
732
+ ],
733
+ "INPUT.ARROW_UP": [
734
+ {
735
+ guard: c("autoComplete", "isFirstItemHighlighted"),
736
+ actions: ["clearHighlightedItem"]
737
+ },
738
+ {
739
+ actions: ["highlightPrevItem"]
740
+ }
741
+ ],
742
+ "INPUT.ENTER": [
743
+ // == group 1 ==
744
+ {
745
+ guard: c("isOpenControlled", "isCustomValue", m("hasHighlightedItem"), m("allowCustomValue")),
746
+ actions: ["revertInputValue", "invokeOnClose"]
747
+ },
748
+ {
749
+ guard: c("isCustomValue", m("hasHighlightedItem"), m("allowCustomValue")),
750
+ target: "focused",
751
+ actions: ["revertInputValue", "invokeOnClose"]
752
+ },
753
+ // == group 2 ==
754
+ {
755
+ guard: c("isOpenControlled", "closeOnSelect"),
756
+ actions: ["selectHighlightedItem", "invokeOnClose"]
757
+ },
758
+ {
759
+ guard: "closeOnSelect",
760
+ target: "focused",
761
+ actions: ["selectHighlightedItem", "invokeOnClose", "setFinalFocus"]
762
+ },
763
+ {
764
+ actions: ["selectHighlightedItem"]
765
+ }
766
+ ],
767
+ "INPUT.CHANGE": [
768
+ {
769
+ guard: "autoComplete",
770
+ target: "suggesting",
771
+ actions: ["setInputValue"]
772
+ },
773
+ {
774
+ target: "suggesting",
775
+ actions: ["clearHighlightedItem", "setInputValue"]
776
+ }
777
+ ],
778
+ "ITEM.POINTER_MOVE": {
779
+ actions: ["setHighlightedItem"]
1150
780
  },
1151
- highlightNextItem(e) {
1152
- let i = null;
1153
- e.highlightedValue ? (i = e.collection.getNextValue(e.highlightedValue), !i && e.loopFocus && (i = e.collection.firstValue)) : i = e.collection.firstValue, g.highlightedValue(e, i);
781
+ "ITEM.POINTER_LEAVE": {
782
+ actions: ["clearHighlightedItem"]
1154
783
  },
1155
- highlightPrevItem(e) {
1156
- let i = null;
1157
- e.highlightedValue ? (i = e.collection.getPreviousValue(e.highlightedValue), !i && e.loopFocus && (i = e.collection.lastValue)) : i = e.collection.lastValue, g.highlightedValue(e, i);
784
+ "ITEM.CLICK": [
785
+ {
786
+ guard: c("isOpenControlled", "closeOnSelect"),
787
+ actions: ["selectItem", "invokeOnClose"]
788
+ },
789
+ {
790
+ guard: "closeOnSelect",
791
+ target: "focused",
792
+ actions: ["selectItem", "invokeOnClose", "setFinalFocus"]
793
+ },
794
+ {
795
+ actions: ["selectItem"]
796
+ }
797
+ ],
798
+ "LAYER.ESCAPE": [
799
+ {
800
+ guard: c("isOpenControlled", "autoComplete"),
801
+ actions: ["syncInputValue", "invokeOnClose"]
802
+ },
803
+ {
804
+ guard: "autoComplete",
805
+ target: "focused",
806
+ actions: ["syncInputValue", "invokeOnClose"]
807
+ },
808
+ {
809
+ guard: "isOpenControlled",
810
+ actions: ["invokeOnClose"]
811
+ },
812
+ {
813
+ target: "focused",
814
+ actions: ["invokeOnClose", "setFinalFocus"]
815
+ }
816
+ ],
817
+ "TRIGGER.CLICK": [
818
+ {
819
+ guard: "isOpenControlled",
820
+ actions: ["invokeOnClose"]
821
+ },
822
+ {
823
+ target: "focused",
824
+ actions: ["invokeOnClose"]
825
+ }
826
+ ],
827
+ "LAYER.INTERACT_OUTSIDE": [
828
+ // == group 1 ==
829
+ {
830
+ guard: c("isOpenControlled", "isCustomValue", m("allowCustomValue")),
831
+ actions: ["revertInputValue", "invokeOnClose"]
832
+ },
833
+ {
834
+ guard: c("isCustomValue", m("allowCustomValue")),
835
+ target: "idle",
836
+ actions: ["revertInputValue", "invokeOnClose"]
837
+ },
838
+ // == group 2 ==
839
+ {
840
+ guard: "isOpenControlled",
841
+ actions: ["invokeOnClose"]
842
+ },
843
+ {
844
+ target: "idle",
845
+ actions: ["invokeOnClose"]
846
+ }
847
+ ],
848
+ CLOSE: [
849
+ {
850
+ guard: "isOpenControlled",
851
+ actions: ["invokeOnClose"]
852
+ },
853
+ {
854
+ target: "focused",
855
+ actions: ["invokeOnClose", "setFinalFocus"]
856
+ }
857
+ ],
858
+ "VALUE.CLEAR": [
859
+ {
860
+ guard: "isOpenControlled",
861
+ actions: ["clearInputValue", "clearSelectedItems", "invokeOnClose"]
862
+ },
863
+ {
864
+ target: "focused",
865
+ actions: ["clearInputValue", "clearSelectedItems", "invokeOnClose", "setFinalFocus"]
866
+ }
867
+ ]
868
+ }
869
+ },
870
+ suggesting: {
871
+ tags: ["open", "focused"],
872
+ effects: [
873
+ "trackDismissableLayer",
874
+ "scrollToHighlightedItem",
875
+ "trackPlacement",
876
+ "trackChildNodes",
877
+ "hideOtherElements"
878
+ ],
879
+ entry: ["setInitialFocus"],
880
+ on: {
881
+ "CONTROLLED.CLOSE": [
882
+ {
883
+ guard: "restoreFocus",
884
+ target: "focused",
885
+ actions: ["setFinalFocus"]
886
+ },
887
+ {
888
+ target: "idle"
889
+ }
890
+ ],
891
+ CHILDREN_CHANGE: {
892
+ guard: "autoHighlight",
893
+ actions: ["highlightFirstItem"]
1158
894
  },
1159
- highlightFirstSelectedItem(e) {
1160
- C(() => {
1161
- const [i] = e.collection.sort(e.value);
1162
- g.highlightedValue(e, i);
1163
- });
895
+ "INPUT.ARROW_DOWN": {
896
+ target: "interacting",
897
+ actions: ["highlightNextItem"]
1164
898
  },
1165
- highlightFirstOrSelectedItem(e) {
1166
- C(() => {
1167
- let i = null;
1168
- e.hasSelectedItems ? i = e.collection.sort(e.value)[0] : i = e.collection.firstValue, g.highlightedValue(e, i);
1169
- });
899
+ "INPUT.ARROW_UP": {
900
+ target: "interacting",
901
+ actions: ["highlightPrevItem"]
1170
902
  },
1171
- highlightLastOrSelectedItem(e) {
1172
- C(() => {
1173
- let i = null;
1174
- e.hasSelectedItems ? i = e.collection.sort(e.value)[0] : i = e.collection.lastValue, g.highlightedValue(e, i);
1175
- });
903
+ "INPUT.HOME": {
904
+ target: "interacting",
905
+ actions: ["highlightFirstItem"]
1176
906
  },
1177
- autofillInputValue(e, i) {
1178
- const r = o.getInputEl(e);
1179
- if (!e.autoComplete || !r || !i.keypress) return;
1180
- const s = e.collection.stringify(e.highlightedValue);
1181
- C(() => {
1182
- r.value = s || e.inputValue;
1183
- });
907
+ "INPUT.END": {
908
+ target: "interacting",
909
+ actions: ["highlightLastItem"]
1184
910
  },
1185
- setCollection(e, i) {
1186
- e.collection = i.value;
911
+ "INPUT.ENTER": [
912
+ // == group 1 ==
913
+ {
914
+ guard: c("isOpenControlled", "isCustomValue", m("hasHighlightedItem"), m("allowCustomValue")),
915
+ actions: ["revertInputValue", "invokeOnClose"]
916
+ },
917
+ {
918
+ guard: c("isCustomValue", m("hasHighlightedItem"), m("allowCustomValue")),
919
+ target: "focused",
920
+ actions: ["revertInputValue", "invokeOnClose"]
921
+ },
922
+ // == group 2 ==
923
+ {
924
+ guard: c("isOpenControlled", "closeOnSelect"),
925
+ actions: ["selectHighlightedItem", "invokeOnClose"]
926
+ },
927
+ {
928
+ guard: "closeOnSelect",
929
+ target: "focused",
930
+ actions: ["selectHighlightedItem", "invokeOnClose", "setFinalFocus"]
931
+ },
932
+ {
933
+ actions: ["selectHighlightedItem"]
934
+ }
935
+ ],
936
+ "INPUT.CHANGE": {
937
+ actions: ["setInputValue"]
1187
938
  },
1188
- syncSelectedItems(e) {
1189
- L.valueChange(e);
939
+ "LAYER.ESCAPE": [
940
+ {
941
+ guard: "isOpenControlled",
942
+ actions: ["invokeOnClose"]
943
+ },
944
+ {
945
+ target: "focused",
946
+ actions: ["invokeOnClose"]
947
+ }
948
+ ],
949
+ "ITEM.POINTER_MOVE": {
950
+ target: "interacting",
951
+ actions: ["setHighlightedItem"]
1190
952
  },
1191
- syncHighlightedItem(e) {
1192
- L.highlightChange(e);
953
+ "ITEM.POINTER_LEAVE": {
954
+ actions: ["clearHighlightedItem"]
1193
955
  },
1194
- toggleVisibility(e, i, { send: r }) {
1195
- r({ type: e.open ? "CONTROLLED.OPEN" : "CONTROLLED.CLOSE", previousEvent: i });
1196
- }
956
+ "LAYER.INTERACT_OUTSIDE": [
957
+ // == group 1 ==
958
+ {
959
+ guard: c("isOpenControlled", "isCustomValue", m("allowCustomValue")),
960
+ actions: ["revertInputValue", "invokeOnClose"]
961
+ },
962
+ {
963
+ guard: c("isCustomValue", m("allowCustomValue")),
964
+ target: "idle",
965
+ actions: ["revertInputValue", "invokeOnClose"]
966
+ },
967
+ // == group 2 ==
968
+ {
969
+ guard: "isOpenControlled",
970
+ actions: ["invokeOnClose"]
971
+ },
972
+ {
973
+ target: "idle",
974
+ actions: ["invokeOnClose"]
975
+ }
976
+ ],
977
+ "TRIGGER.CLICK": [
978
+ {
979
+ guard: "isOpenControlled",
980
+ actions: ["invokeOnClose"]
981
+ },
982
+ {
983
+ target: "focused",
984
+ actions: ["invokeOnClose"]
985
+ }
986
+ ],
987
+ "ITEM.CLICK": [
988
+ {
989
+ guard: c("isOpenControlled", "closeOnSelect"),
990
+ actions: ["selectItem", "invokeOnClose"]
991
+ },
992
+ {
993
+ guard: "closeOnSelect",
994
+ target: "focused",
995
+ actions: ["selectItem", "invokeOnClose", "setFinalFocus"]
996
+ },
997
+ {
998
+ actions: ["selectItem"]
999
+ }
1000
+ ],
1001
+ CLOSE: [
1002
+ {
1003
+ guard: "isOpenControlled",
1004
+ actions: ["invokeOnClose"]
1005
+ },
1006
+ {
1007
+ target: "focused",
1008
+ actions: ["invokeOnClose", "setFinalFocus"]
1009
+ }
1010
+ ],
1011
+ "VALUE.CLEAR": [
1012
+ {
1013
+ guard: "isOpenControlled",
1014
+ actions: ["clearInputValue", "clearSelectedItems", "invokeOnClose"]
1015
+ },
1016
+ {
1017
+ target: "focused",
1018
+ actions: ["clearInputValue", "clearSelectedItems", "invokeOnClose", "setFinalFocus"]
1019
+ }
1020
+ ]
1197
1021
  }
1198
1022
  }
1199
- );
1200
- }
1201
- var L = {
1202
- valueChange: (t) => {
1203
- const n = t.selectedItems;
1204
- t.selectedItems = t.value.map((r) => {
1205
- const s = n.find((c) => t.collection.getItemValue(c) === r);
1206
- return s || t.collection.find(r);
1207
- });
1208
- const e = t.collection.stringifyItems(t.selectedItems);
1209
- t.valueAsString = e;
1210
- let i;
1211
- t.getSelectionValue ? i = t.getSelectionValue({
1212
- inputValue: t.inputValue,
1213
- selectedItems: Array.from(t.selectedItems),
1214
- valueAsString: e
1215
- }) : i = R(t.selectionBehavior, {
1216
- replace: t.valueAsString,
1217
- preserve: t.inputValue,
1218
- clear: ""
1219
- }), g.inputValue(t, i);
1220
1023
  },
1221
- highlightChange: (t) => {
1222
- t.highlightedItem = t.collection.find(t.highlightedValue);
1223
- }
1224
- }, S = {
1225
- valueChange: (t) => {
1226
- var n;
1227
- L.valueChange(t), (n = t.onValueChange) == null || n.call(t, {
1228
- value: Array.from(t.value),
1229
- items: Array.from(t.selectedItems)
1230
- });
1231
- },
1232
- highlightChange: (t) => {
1233
- var n;
1234
- L.highlightChange(t), (n = t.onHighlightChange) == null || n.call(t, {
1235
- highlightedValue: t.highlightedValue,
1236
- highlightedItem: t.highlightedItem
1237
- });
1238
- },
1239
- inputChange: (t) => {
1240
- var n;
1241
- (n = t.onInputValueChange) == null || n.call(t, { inputValue: t.inputValue });
1242
- }
1243
- }, g = {
1244
- value: (t, n, e = !1) => {
1245
- if (!F(t.value, n) && !(n == null && !e)) {
1246
- if (n == null && e) {
1247
- t.value = [], S.valueChange(t);
1248
- return;
1024
+ implementations: {
1025
+ guards: {
1026
+ isInputValueEmpty: ({ computed: e }) => e("isInputValueEmpty"),
1027
+ autoComplete: ({ computed: e, prop: t }) => e("autoComplete") && !t("multiple"),
1028
+ autoHighlight: ({ computed: e }) => e("autoHighlight"),
1029
+ isFirstItemHighlighted: ({ prop: e, context: t }) => e("collection").firstValue === t.get("highlightedValue"),
1030
+ isLastItemHighlighted: ({ prop: e, context: t }) => e("collection").lastValue === t.get("highlightedValue"),
1031
+ isCustomValue: ({ computed: e }) => e("isCustomValue"),
1032
+ allowCustomValue: ({ prop: e }) => !!e("allowCustomValue"),
1033
+ hasHighlightedItem: ({ context: e }) => e.get("highlightedValue") != null,
1034
+ closeOnSelect: ({ prop: e }) => !!e("closeOnSelect"),
1035
+ isOpenControlled: ({ prop: e }) => e("open") != null,
1036
+ openOnChange: ({ prop: e, context: t }) => {
1037
+ const i = e("openOnChange");
1038
+ return ye(i) ? i : !!(i != null && i({ inputValue: t.get("inputValue") }));
1039
+ },
1040
+ restoreFocus: ({ event: e }) => e.restoreFocus == null ? !0 : !!e.restoreFocus,
1041
+ isChangeEvent: ({ event: e }) => {
1042
+ var t;
1043
+ return ((t = e.previousEvent) == null ? void 0 : t.type) === "INPUT.CHANGE";
1044
+ },
1045
+ autoFocus: ({ prop: e }) => !!e("autoFocus")
1046
+ },
1047
+ effects: {
1048
+ trackDismissableLayer({ send: e, prop: t, scope: i }) {
1049
+ return t("disableLayer") ? void 0 : ke(() => T(i), {
1050
+ defer: !0,
1051
+ exclude: () => [y(i), L(i), Z(i)],
1052
+ onFocusOutside: t("onFocusOutside"),
1053
+ onPointerDownOutside: t("onPointerDownOutside"),
1054
+ onInteractOutside: t("onInteractOutside"),
1055
+ onEscapeKeyDown(o) {
1056
+ o.preventDefault(), o.stopPropagation(), e({ type: "LAYER.ESCAPE" });
1057
+ },
1058
+ onDismiss() {
1059
+ e({ type: "LAYER.INTERACT_OUTSIDE", restoreFocus: !1 });
1060
+ }
1061
+ });
1062
+ },
1063
+ hideOtherElements({ scope: e }) {
1064
+ return Ne([
1065
+ y(e),
1066
+ T(e),
1067
+ L(e),
1068
+ Z(e)
1069
+ ]);
1070
+ },
1071
+ trackPlacement({ context: e, prop: t, scope: i }) {
1072
+ const n = () => X(i) || L(i), o = () => Q(i);
1073
+ return e.set("currentPlacement", t("positioning").placement), q(n, o, {
1074
+ ...t("positioning"),
1075
+ defer: !0,
1076
+ onComplete(a) {
1077
+ e.set("currentPlacement", a.placement);
1078
+ }
1079
+ });
1080
+ },
1081
+ // in event the options are fetched (async), we still want to auto-highlight the first option
1082
+ trackChildNodes({ scope: e, computed: t, send: i }) {
1083
+ return t("autoHighlight") ? he(() => T(e), {
1084
+ callback: () => i({ type: "CHILDREN_CHANGE" }),
1085
+ defer: !0
1086
+ }) : void 0;
1087
+ },
1088
+ scrollToHighlightedItem({ context: e, prop: t, scope: i, event: n }) {
1089
+ const o = y(i);
1090
+ let a = [];
1091
+ const r = (O) => {
1092
+ const E = n.current().type.includes("POINTER"), I = e.get("highlightedValue");
1093
+ if (E || !I) return;
1094
+ const P = ae(i, I), v = T(i), S = t("scrollToIndexFn");
1095
+ if (S) {
1096
+ const F = t("collection").indexOf(I);
1097
+ S({ index: F, immediate: O });
1098
+ return;
1099
+ }
1100
+ const d = f(() => {
1101
+ Oe(P, { rootEl: v, block: "nearest" });
1102
+ });
1103
+ a.push(d);
1104
+ }, C = f(() => r(!0));
1105
+ a.push(C);
1106
+ const k = de(o, {
1107
+ attributes: ["aria-activedescendant"],
1108
+ callback: () => r(!1)
1109
+ });
1110
+ return a.push(k), () => {
1111
+ a.forEach((O) => O());
1112
+ };
1113
+ }
1114
+ },
1115
+ actions: {
1116
+ reposition({ context: e, prop: t, scope: i, event: n }) {
1117
+ q(() => X(i), () => Q(i), {
1118
+ ...t("positioning"),
1119
+ ...n.options,
1120
+ defer: !0,
1121
+ listeners: !1,
1122
+ onComplete(r) {
1123
+ e.set("currentPlacement", r.placement);
1124
+ }
1125
+ });
1126
+ },
1127
+ setHighlightedItem(e) {
1128
+ const { context: t, event: i } = e;
1129
+ i.value != null && t.set("highlightedValue", i.value);
1130
+ },
1131
+ clearHighlightedItem(e) {
1132
+ const { context: t } = e;
1133
+ t.set("highlightedValue", null);
1134
+ },
1135
+ selectHighlightedItem(e) {
1136
+ var a;
1137
+ const { context: t, prop: i } = e, n = t.get("highlightedValue");
1138
+ if (!n) return;
1139
+ const o = i("multiple") ? Y(t.get("value"), n) : [n];
1140
+ (a = i("onSelect")) == null || a({ value: o, itemValue: n }), t.set("value", o), t.set("inputValue", R(e));
1141
+ },
1142
+ selectItem(e) {
1143
+ const { context: t, event: i, flush: n, prop: o } = e;
1144
+ i.value != null && n(() => {
1145
+ var r;
1146
+ const a = o("multiple") ? Y(t.get("value"), i.value) : [i.value];
1147
+ (r = o("onSelect")) == null || r({ value: a, itemValue: i.value }), t.set("value", a), t.set("inputValue", R(e));
1148
+ });
1149
+ },
1150
+ clearItem(e) {
1151
+ const { context: t, event: i, flush: n } = e;
1152
+ i.value != null && n(() => {
1153
+ const o = Te(t.get("value"), i.value);
1154
+ t.set("value", o), t.set("inputValue", R(e));
1155
+ });
1156
+ },
1157
+ setInitialFocus({ scope: e }) {
1158
+ f(() => {
1159
+ z(e);
1160
+ });
1161
+ },
1162
+ setFinalFocus({ scope: e }) {
1163
+ f(() => {
1164
+ const t = L(e);
1165
+ (t == null ? void 0 : t.dataset.focusable) == null ? z(e) : Re(e);
1166
+ });
1167
+ },
1168
+ syncInputValue({ context: e, scope: t, event: i }) {
1169
+ const n = y(t);
1170
+ n && (n.value = e.get("inputValue"), queueMicrotask(() => {
1171
+ i.current().type !== "INPUT.CHANGE" && ge(n);
1172
+ }));
1173
+ },
1174
+ setInputValue({ context: e, event: t }) {
1175
+ e.set("inputValue", t.value);
1176
+ },
1177
+ clearInputValue({ context: e }) {
1178
+ e.set("inputValue", "");
1179
+ },
1180
+ revertInputValue({ context: e, prop: t, computed: i }) {
1181
+ const n = t("selectionBehavior"), o = D(n, {
1182
+ replace: i("hasSelectedItems") ? e.get("valueAsString") : "",
1183
+ preserve: e.get("inputValue"),
1184
+ clear: ""
1185
+ });
1186
+ e.set("inputValue", o);
1187
+ },
1188
+ setValue(e) {
1189
+ const { context: t, flush: i, event: n } = e;
1190
+ i(() => {
1191
+ t.set("value", n.value), t.set("inputValue", R(e));
1192
+ });
1193
+ },
1194
+ clearSelectedItems(e) {
1195
+ const { context: t, flush: i } = e;
1196
+ i(() => {
1197
+ t.set("value", []), t.set("inputValue", R(e));
1198
+ });
1199
+ },
1200
+ scrollContentToTop({ prop: e, scope: t }) {
1201
+ const i = e("scrollToIndexFn");
1202
+ if (i)
1203
+ i({ index: 0, immediate: !0 });
1204
+ else {
1205
+ const n = T(t);
1206
+ if (!n) return;
1207
+ n.scrollTop = 0;
1208
+ }
1209
+ },
1210
+ invokeOnOpen({ prop: e }) {
1211
+ var t;
1212
+ (t = e("onOpenChange")) == null || t({ open: !0 });
1213
+ },
1214
+ invokeOnClose({ prop: e }) {
1215
+ var t;
1216
+ (t = e("onOpenChange")) == null || t({ open: !1 });
1217
+ },
1218
+ highlightFirstItem({ context: e, prop: t, scope: i }) {
1219
+ (T(i) ? queueMicrotask : f)(() => {
1220
+ const o = t("collection").firstValue;
1221
+ o && e.set("highlightedValue", o);
1222
+ });
1223
+ },
1224
+ highlightFirstItemIfNeeded({ computed: e, action: t }) {
1225
+ e("autoHighlight") && t(["highlightFirstItem"]);
1226
+ },
1227
+ highlightLastItem({ context: e, prop: t, scope: i }) {
1228
+ (T(i) ? queueMicrotask : f)(() => {
1229
+ const o = t("collection").lastValue;
1230
+ o && e.set("highlightedValue", o);
1231
+ });
1232
+ },
1233
+ highlightNextItem({ context: e, prop: t }) {
1234
+ let i = null;
1235
+ const n = e.get("highlightedValue"), o = t("collection");
1236
+ n ? (i = o.getNextValue(n), !i && t("loopFocus") && (i = o.firstValue)) : i = o.firstValue, i && e.set("highlightedValue", i);
1237
+ },
1238
+ highlightPrevItem({ context: e, prop: t }) {
1239
+ let i = null;
1240
+ const n = e.get("highlightedValue"), o = t("collection");
1241
+ n ? (i = o.getPreviousValue(n), !i && t("loopFocus") && (i = o.lastValue)) : i = o.lastValue, i && e.set("highlightedValue", i);
1242
+ },
1243
+ highlightFirstSelectedItem({ context: e, prop: t }) {
1244
+ f(() => {
1245
+ const [i] = t("collection").sort(e.get("value"));
1246
+ i && e.set("highlightedValue", i);
1247
+ });
1248
+ },
1249
+ highlightFirstOrSelectedItem({ context: e, prop: t, computed: i }) {
1250
+ f(() => {
1251
+ let n = null;
1252
+ i("hasSelectedItems") ? n = t("collection").sort(e.get("value"))[0] : n = t("collection").firstValue, n && e.set("highlightedValue", n);
1253
+ });
1254
+ },
1255
+ highlightLastOrSelectedItem({ context: e, prop: t, computed: i }) {
1256
+ f(() => {
1257
+ const n = t("collection");
1258
+ let o = null;
1259
+ i("hasSelectedItems") ? o = n.sort(e.get("value"))[0] : o = n.lastValue, o && e.set("highlightedValue", o);
1260
+ });
1261
+ },
1262
+ autofillInputValue({ context: e, computed: t, prop: i, event: n, scope: o }) {
1263
+ const a = y(o), r = i("collection");
1264
+ if (!t("autoComplete") || !a || !n.keypress) return;
1265
+ const C = r.stringify(e.get("highlightedValue"));
1266
+ f(() => {
1267
+ a.value = C || e.get("inputValue");
1268
+ });
1269
+ },
1270
+ syncSelectedItems(e) {
1271
+ queueMicrotask(() => {
1272
+ const { context: t, prop: i } = e, n = D(i("selectionBehavior"), {
1273
+ preserve: t.get("inputValue"),
1274
+ replace: i("collection").stringifyMany(t.get("value")),
1275
+ clear: ""
1276
+ });
1277
+ t.set("selectedItems", Me(e)), t.set("inputValue", n);
1278
+ });
1279
+ },
1280
+ syncHighlightedItem({ context: e, prop: t }) {
1281
+ const i = t("collection").find(e.get("highlightedValue"));
1282
+ e.set("highlightedItem", i);
1283
+ },
1284
+ toggleVisibility({ event: e, send: t, prop: i }) {
1285
+ t({ type: i("open") ? "CONTROLLED.OPEN" : "CONTROLLED.CLOSE", previousEvent: e });
1249
1286
  }
1250
- G(n) ? t.value = n : n != null && (t.value = t.multiple ? re(t.value, n) : [n]), S.valueChange(t);
1251
1287
  }
1252
- },
1253
- highlightedValue: (t, n, e = !1) => {
1254
- F(t.highlightedValue, n) || !n && !e || (t.highlightedValue = n || null, S.highlightChange(t));
1255
- },
1256
- inputValue: (t, n) => {
1257
- F(t.inputValue, n) || (t.inputValue = n, S.inputChange(t));
1258
1288
  }
1259
- };
1289
+ });
1290
+ function R({ context: e, prop: t }) {
1291
+ return D(t("selectionBehavior"), {
1292
+ preserve: e.get("inputValue"),
1293
+ replace: e.get("valueAsString"),
1294
+ clear: ""
1295
+ });
1296
+ }
1297
+ function Me({ context: e, prop: t }) {
1298
+ const i = t("collection");
1299
+ return e.get("value").map((n) => {
1300
+ const o = e.get("selectedItems").find((a) => i.getItemValue(a) === n);
1301
+ return o || i.find(n);
1302
+ });
1303
+ }
1304
+ G()([
1305
+ "allowCustomValue",
1306
+ "autoFocus",
1307
+ "closeOnSelect",
1308
+ "collection",
1309
+ "composite",
1310
+ "defaultHighlightedValue",
1311
+ "defaultInputValue",
1312
+ "defaultOpen",
1313
+ "defaultValue",
1314
+ "dir",
1315
+ "disabled",
1316
+ "disableLayer",
1317
+ "form",
1318
+ "getRootNode",
1319
+ "highlightedValue",
1320
+ "id",
1321
+ "ids",
1322
+ "inputBehavior",
1323
+ "inputValue",
1324
+ "invalid",
1325
+ "loopFocus",
1326
+ "multiple",
1327
+ "name",
1328
+ "navigate",
1329
+ "onFocusOutside",
1330
+ "onHighlightChange",
1331
+ "onInputValueChange",
1332
+ "onInteractOutside",
1333
+ "onOpenChange",
1334
+ "onOpenChange",
1335
+ "onPointerDownOutside",
1336
+ "onSelect",
1337
+ "onValueChange",
1338
+ "open",
1339
+ "openOnChange",
1340
+ "openOnClick",
1341
+ "openOnKeyPress",
1342
+ "placeholder",
1343
+ "positioning",
1344
+ "readOnly",
1345
+ "required",
1346
+ "scrollToIndexFn",
1347
+ "selectionBehavior",
1348
+ "translations",
1349
+ "value"
1350
+ ]);
1351
+ G()(["htmlFor"]);
1352
+ G()(["id"]);
1353
+ G()(["item", "persistFocus"]);
1260
1354
  export {
1261
- se as anatomy,
1262
- _ as collection,
1263
- Ee as connect,
1264
- ve as machine
1355
+ Le as anatomy,
1356
+ te as collection,
1357
+ Ye as connect,
1358
+ je as machine
1265
1359
  };