@choc-ui/chakra-autocomplete 5.8.2 → 5.8.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"empty-state.d.ts","sourceRoot":"","sources":["../../src/components/empty-state.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAO,QAAQ,EAAmB,MAAM,kBAAkB,CAAC;AAIlE,eAAO,MAAM,UAAU,UAAW,QAAQ,4CAQzC,CAAC"}
1
+ {"version":3,"file":"empty-state.d.ts","sourceRoot":"","sources":["../../src/components/empty-state.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAO,QAAQ,EAAmB,MAAM,kBAAkB,CAAC;AAIlE,eAAO,MAAM,UAAU,GAAI,OAAO,QAAQ,4CAQzC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../src/helpers/group.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGlC,eAAO,MAAM,YAAY,aAAc,SAAS,aAAa,GAAG,QAS/D,CAAC;AACF,eAAO,MAAM,WAAW,aAAc,SAAS,YAAY,GAAG,QAQ7D,CAAC;AAEF,eAAO,MAAM,WAAW,aAAc,GAAG,gBAAgB,GAAG,EAAE,YAU7D,CAAC"}
1
+ {"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../src/helpers/group.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGlC,eAAO,MAAM,YAAY,GAAI,UAAU,SAAS,EAAE,WAAW,GAAG,QAS/D,CAAC;AACF,eAAO,MAAM,WAAW,GAAI,UAAU,SAAS,EAAE,UAAU,GAAG,QAQ7D,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,UAAU,GAAG,EAAE,cAAc,GAAG,EAAE,YAU7D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/helpers/input.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,eAAgB,GAAG,aAAa,OAAO,QAyCxE,CAAC"}
1
+ {"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/helpers/input.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,GAAI,YAAY,GAAG,EAAE,WAAW,OAAO,QAyCxE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"items.d.ts","sourceRoot":"","sources":["../../src/helpers/items.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,eAAO,MAAM,eAAe,SAAU,qBAAqB,CAAC,OAAO,CAAC,QAIrD,CAAC;AAEhB,eAAO,MAAM,WAAW,aAAc,GAAG,SAAS,MAAM,QAWvD,CAAC;AAEF,eAAO,MAAM,WAAW,aAAc,SAAS,KAAG,IAAI,EAerD,CAAC;AAEF,eAAO,MAAM,gBAAgB,QAAO,SAOnC,CAAC;AAEF,eAAO,MAAM,mBAAmB,UACvB,MAAM,aACF,IAAI,CAAC,OAAO,CAAC,aACb,IAAI,CAAC,OAAO,CAAC,YAQzB,CAAC"}
1
+ {"version":3,"file":"items.d.ts","sourceRoot":"","sources":["../../src/helpers/items.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,eAAO,MAAM,eAAe,GAAI,MAAM,qBAAqB,CAAC,OAAO,CAAC,QAIrD,CAAC;AAEhB,eAAO,MAAM,WAAW,GAAI,UAAU,GAAG,EAAE,OAAO,MAAM,QAWvD,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,UAAU,SAAS,KAAG,IAAI,EAerD,CAAC;AAEF,eAAO,MAAM,gBAAgB,QAAO,SAOnC,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,OAAO,MAAM,EACb,WAAW,IAAI,CAAC,OAAO,CAAC,EACxB,WAAW,IAAI,CAAC,OAAO,CAAC,YAQzB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/helpers/list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,eAAO,MAAM,WAAW,aAAc,KAAK,CAAC,SAAS,kSA8BpD,CAAC"}
1
+ {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/helpers/list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,eAAO,MAAM,WAAW,GAAI,UAAU,KAAK,CAAC,SAAS,kSA8BpD,CAAC"}
package/dist/index.es.js CHANGED
@@ -1,14 +1,14 @@
1
- import { jsx as p, jsxs as V, Fragment as it } from "react/jsx-runtime";
2
- import * as fe from "react";
3
- import ee, { useMemo as ue, useRef as te, useState as Le, useEffect as D, useImperativeHandle as ut, memo as at } from "react";
4
- import { useDisclosure as ct, useControllableState as ft, useUpdateEffect as pt, forwardRef as H, Popover as dt, chakra as gt, useMergeRefs as Pe, Flex as pe, Box as Xe, Divider as $e, InputGroup as mt, Input as vt, InputRightElement as ht, Spinner as Ze, useMultiStyleConfig as yt, Wrap as bt, WrapItem as qe, PopoverAnchor as Ct, PopoverContent as St, Center as xt, Tag as At, TagLabel as It, TagCloseButton as wt } from "@chakra-ui/react";
5
- const [Ot, j] = Et();
6
- function Et() {
7
- const e = fe.createContext(void 0);
1
+ import { jsx as p, jsxs as V, Fragment as ut } from "react/jsx-runtime";
2
+ import * as pe from "react";
3
+ import ee, { useMemo as te, useRef as ne, useState as Ne, useEffect as D, useImperativeHandle as at, memo as ct } from "react";
4
+ import { useDisclosure as ft, useControllableState as pt, useUpdateEffect as dt, forwardRef as H, Popover as gt, chakra as mt, useMergeRefs as De, Flex as de, Box as Xe, Divider as $e, InputGroup as vt, Input as ht, InputRightElement as yt, Spinner as Ze, useMultiStyleConfig as bt, Wrap as Ct, WrapItem as qe, PopoverAnchor as St, PopoverContent as xt, Center as At, Tag as It, TagLabel as wt, TagCloseButton as Ot } from "@chakra-ui/react";
5
+ const [Et, j] = Ft();
6
+ function Ft() {
7
+ const e = pe.createContext(void 0);
8
8
  e.displayName = "AutoCompleteContext";
9
9
  function t() {
10
10
  var o;
11
- const n = fe.useContext(e), r = "useAutoCompleteContext: `context` is undefined. Seems you forgot to wrap all autoomplete components within `<AutoComplete />`";
11
+ const n = pe.useContext(e), r = "useAutoCompleteContext: `context` is undefined. Seems you forgot to wrap all autoomplete components within `<AutoComplete />`";
12
12
  if (!n) {
13
13
  const l = new Error(r);
14
14
  throw l.name = "ContextError", (o = Error.captureStackTrace) == null || o.call(Error, l, t), l;
@@ -17,10 +17,10 @@ function Et() {
17
17
  }
18
18
  return [e.Provider, t, e];
19
19
  }
20
- function Ft(e) {
20
+ function Lt(e) {
21
21
  return e == null ? void 0 : e[0];
22
22
  }
23
- function Ne(e) {
23
+ function Pe(e) {
24
24
  return e != null && e.length ? e[e.length - 1] : void 0;
25
25
  }
26
26
  function et(e, t, n = 1, r = !0) {
@@ -28,139 +28,139 @@ function et(e, t, n = 1, r = !0) {
28
28
  let o = e + n;
29
29
  return e === -1 && (o = n > 0 ? 0 : t - 1), r ? o = (o % t + t) % t : o = Math.max(0, Math.min(o, t - 1)), o;
30
30
  }
31
- function Lt(e, t, n = !0) {
31
+ function Nt(e, t, n = !0) {
32
32
  return et(e, t, -1, n);
33
33
  }
34
- function Nt(e, t, n = !0) {
34
+ function Pt(e, t, n = !0) {
35
35
  const r = et(e, t.length, 1, n);
36
36
  return t[r];
37
37
  }
38
- function Pt(e, t, n = !0) {
39
- const r = Lt(e, t.length, n);
38
+ function Dt(e, t, n = !0) {
39
+ const r = Nt(e, t.length, n);
40
40
  return t[r];
41
41
  }
42
- function De(e) {
43
- return Array.isArray(e);
44
- }
45
- function Dt(e) {
46
- return De(e) && e.length === 0;
47
- }
48
42
  function Re(e) {
49
- return e !== null && typeof e == "object" && !De(e);
43
+ return Array.isArray(e);
50
44
  }
51
45
  function Rt(e) {
52
- return Re(e) && Object.keys(e).length === 0;
46
+ return Re(e) && e.length === 0;
53
47
  }
54
48
  function Te(e) {
55
- return De(e) ? Dt(e) : Re(e) ? Rt(e) : e == null || e === "";
49
+ return e !== null && typeof e == "object" && !Re(e);
50
+ }
51
+ function Tt(e) {
52
+ return Te(e) && Object.keys(e).length === 0;
56
53
  }
57
- function ce(e) {
54
+ function Me(e) {
55
+ return Re(e) ? Rt(e) : Te(e) ? Tt(e) : e == null || e === "";
56
+ }
57
+ function fe(e) {
58
58
  return typeof e > "u";
59
59
  }
60
60
  function tt(e) {
61
61
  return typeof e < "u";
62
62
  }
63
- function Tt(e, t) {
63
+ function Mt(e, t) {
64
64
  const n = {};
65
65
  return t.forEach((r) => {
66
66
  r in e && (n[r] = e[r]);
67
67
  }), n;
68
68
  }
69
- function Me(e, t) {
69
+ function _e(e, t) {
70
70
  const n = { ...e };
71
71
  return t.forEach((r) => {
72
72
  delete n[r];
73
73
  }), n;
74
74
  }
75
- function Mt(e) {
75
+ function _t(e) {
76
76
  return typeof e == "function";
77
77
  }
78
78
  function m(e, ...t) {
79
- return Mt(e) ? e(...t) : e;
79
+ return _t(e) ? e(...t) : e;
80
80
  }
81
- var de = function(e, t) {
82
- for (var n, r = fe.Children.toArray(e), o = 0, l = r; o < l.length; o++) {
81
+ var ge = function(e, t) {
82
+ for (var n, r = pe.Children.toArray(e), o = 0, l = r; o < l.length; o++) {
83
83
  var i = l[o];
84
84
  if (t(i))
85
85
  return i;
86
86
  if (!((n = i.props) === null || n === void 0) && n.children) {
87
- var u = de(i.props.children, t);
87
+ var u = ge(i.props.children, t);
88
88
  if (u)
89
89
  return u;
90
90
  }
91
91
  }
92
- }, ae = function(e, t) {
92
+ }, ce = function(e, t) {
93
93
  for (var n = 0, r = t.length, o = e.length; n < r; n++, o++)
94
94
  e[o] = t[n];
95
95
  return e;
96
96
  }, nt = function(e, t) {
97
- for (var n, r = fe.Children.toArray(e), o = [], l = 0, i = r; l < i.length; l++) {
97
+ for (var n, r = pe.Children.toArray(e), o = [], l = 0, i = r; l < i.length; l++) {
98
98
  var u = i[l];
99
- t(u) && (o = ae(ae([], o), [u])), !((n = u.props) === null || n === void 0) && n.children && (o = ae(ae([], o), nt(u.props.children, t)));
99
+ t(u) && (o = ce(ce([], o), [u])), !((n = u.props) === null || n === void 0) && n.children && (o = ce(ce([], o), nt(u.props.children, t)));
100
100
  }
101
101
  return o;
102
102
  };
103
103
  function Ke(e, t, n = 2) {
104
- function r(c, O) {
105
- c = " ".repeat(O - 1) + c.toLowerCase() + " ".repeat(O - 1);
106
- let C = new Array(c.length - O + 1);
107
- for (let I = 0; I < C.length; I++)
108
- C[I] = c.slice(I, I + O);
109
- return C;
104
+ function r(c, E) {
105
+ c = " ".repeat(E - 1) + c.toLowerCase() + " ".repeat(E - 1);
106
+ let b = new Array(c.length - E + 1);
107
+ for (let w = 0; w < b.length; w++)
108
+ b[w] = c.slice(w, w + E);
109
+ return b;
110
110
  }
111
111
  if (!(e != null && e.length) || !(t != null && t.length))
112
112
  return 0;
113
- let o = e.length < t.length ? e : t, l = e.length < t.length ? t : e, i = r(o, n), u = r(l, n), v = new Set(i), h = u.length, b = 0;
113
+ let o = e.length < t.length ? e : t, l = e.length < t.length ? t : e, i = r(o, n), u = r(l, n), v = new Set(i), h = u.length, y = 0;
114
114
  for (let c of u)
115
- v.delete(c) && b++;
116
- return b / h;
115
+ v.delete(c) && y++;
116
+ return y / h;
117
117
  }
118
- const _e = (e) => {
118
+ const Ge = (e) => {
119
119
  var t;
120
120
  return (t = typeof e == "string" || typeof e == "number" ? e : e[Object.keys(e)[0]]) == null ? void 0 : t.toString();
121
- }, _t = (e, t) => typeof e != "string" || Te(t) ? e : e.toString().replace(
122
- new RegExp(kt(t), "gi"),
121
+ }, Gt = (e, t) => typeof e != "string" || Me(t) ? e : e.toString().replace(
122
+ new RegExp(zt(t), "gi"),
123
123
  (r) => `<mark>${r}</mark>`
124
- ), Gt = (e) => nt(
124
+ ), Wt = (e) => nt(
125
125
  e,
126
126
  (n) => {
127
127
  var r;
128
128
  return ((r = n == null ? void 0 : n.type) == null ? void 0 : r.displayName) === "AutoCompleteItem";
129
129
  }
130
130
  ).map((n) => {
131
- const r = Tt(n.props, ["value", "label", "fixed", "disabled"]), { getValue: o = _e } = n.props, l = o(r.value);
131
+ const r = Mt(n.props, ["value", "label", "fixed", "disabled"]), { getValue: o = Ge } = n.props, l = o(r.value);
132
132
  return { ...tt(r.label) ? r : { ...r, label: l }, value: l, originalValue: r.value };
133
- }), Wt = () => ({
133
+ }), jt = () => ({
134
134
  bg: "whiteAlpha.100",
135
135
  _light: {
136
136
  bg: "gray.200"
137
137
  }
138
- }), jt = (e, t, n) => (t == null ? void 0 : t.toLowerCase().indexOf(e == null ? void 0 : e.toLowerCase())) >= 0 || (n == null ? void 0 : n.toLowerCase().indexOf(e == null ? void 0 : e.toLowerCase())) >= 0 || Ke(e, t) >= 0.5 || Ke(e, n) >= 0.5;
139
- function kt(e) {
138
+ }), kt = (e, t, n) => (t == null ? void 0 : t.toLowerCase().indexOf(e == null ? void 0 : e.toLowerCase())) >= 0 || (n == null ? void 0 : n.toLowerCase().indexOf(e == null ? void 0 : e.toLowerCase())) >= 0 || Ke(e, t) >= 0.5 || Ke(e, n) >= 0.5;
139
+ function zt(e) {
140
140
  return e.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
141
141
  }
142
- const zt = (e, t) => de(
142
+ const Bt = (e, t) => ge(
143
143
  e,
144
144
  (r) => {
145
145
  var o;
146
146
  return ((o = r == null ? void 0 : r.type) == null ? void 0 : o.displayName) === "AutoCompleteItem" && r.props.value === (t == null ? void 0 : t.value);
147
147
  }
148
- ), Bt = (e, t) => de(
148
+ ), Ht = (e, t) => ge(
149
149
  e,
150
150
  (r) => {
151
151
  var o;
152
152
  return ((o = r == null ? void 0 : r.type) == null ? void 0 : o.displayName) === "AutoCompleteItem" && r.props.value === (t == null ? void 0 : t.value);
153
153
  }
154
- ), Ht = (e, t) => tt(
155
- de(e, (n) => {
154
+ ), Ut = (e, t) => tt(
155
+ ge(e, (n) => {
156
156
  var o, l;
157
157
  const r = m(
158
- ((o = n.props) == null ? void 0 : o.getValue) || _e,
158
+ ((o = n.props) == null ? void 0 : o.getValue) || Ge,
159
159
  ((l = n.props) == null ? void 0 : l.value) || {}
160
160
  );
161
161
  return t.some((i) => i.value === r);
162
162
  })
163
- ), Ut = (e, t) => {
163
+ ), Qt = (e, t) => {
164
164
  const n = {}, r = {}, { field: o } = e;
165
165
  return o && Object.keys(o).forEach((l) => {
166
166
  if (l.startsWith("--input") === !1)
@@ -188,7 +188,7 @@ const zt = (e, t) => de(
188
188
  // w: "full",
189
189
  };
190
190
  };
191
- function Qt(e) {
191
+ function $t(e) {
192
192
  var He;
193
193
  let {
194
194
  prefocusFirstItem: t = !0,
@@ -200,54 +200,54 @@ function Qt(e) {
200
200
  freeSolo: u,
201
201
  isReadOnly: v,
202
202
  listAllValuesOnFocus: h,
203
- maxSuggestions: b,
203
+ maxSuggestions: y,
204
204
  multiple: c,
205
- closeOnSelect: O = !c,
206
- defaultValue: C,
207
- defaultValues: I = C ? [C] : [],
205
+ closeOnSelect: E = !c,
206
+ defaultValue: b,
207
+ defaultValues: w = b ? [b] : [],
208
208
  onReady: U,
209
209
  defaultIsOpen: k,
210
- disableFilter: ne,
211
- isLoading: ge = !1,
212
- placement: oe = "bottom",
210
+ disableFilter: oe,
211
+ isLoading: me = !1,
212
+ placement: re = "bottom",
213
213
  restoreOnBlurIfEmpty: Y = !u,
214
- shouldRenderSuggestions: me = () => !0,
215
- submitKeys: ve = [],
216
- suggestWhenEmpty: re,
214
+ shouldRenderSuggestions: ve = () => !0,
215
+ submitKeys: he = [],
216
+ suggestWhenEmpty: se,
217
217
  value: z,
218
218
  values: J = z ? typeof z == "string" ? [z] : [...z] : void 0
219
219
  } = e;
220
220
  u = u || (c ? !0 : e.freeSolo);
221
- const { isOpen: w, onClose: _, onOpen: Q } = ct({ defaultIsOpen: k }), he = ue(
221
+ const { isOpen: O, onClose: _, onOpen: Q } = ft({ defaultIsOpen: k }), ye = te(
222
222
  () => m(e.children, {
223
- isOpen: w,
223
+ isOpen: O,
224
224
  onClose: _,
225
225
  onOpen: Q
226
226
  }),
227
- [e.children, w]
228
- ), E = ue(() => Gt(he), [he]), N = te(null), Ge = te(null), X = te(null), $ = te(null), [We, se] = Le(!1);
229
- let le = "";
230
- c ? le = "" : ce(I) ? ce(J) || (le = J[0]) : le = I[0];
231
- const [R, Z] = Le(le ?? ""), ye = ue(
232
- () => ne ? E : E.filter(
227
+ [e.children, O]
228
+ ), x = te(() => Wt(ye), [ye]), N = ne(null), We = ne(null), X = ne(null), $ = ne(null), [je, le] = Ne(!1);
229
+ let ie = "";
230
+ c ? ie = "" : fe(w) ? fe(J) || (ie = J[0]) : ie = w[0];
231
+ const [R, Z] = Ne(ie ?? ""), be = te(
232
+ () => oe ? x : x.filter(
233
233
  (s) => s.fixed || m(
234
- e.filter || jt,
234
+ e.filter || kt,
235
235
  R,
236
236
  s.value,
237
237
  s.label
238
- ) || We
238
+ ) || je
239
239
  ).filter(
240
- (s, a) => b ? s.fixed || a < b : !0
240
+ (s, a) => y ? s.fixed || a < y : !0
241
241
  ),
242
- [R, E, We, b, ne]
243
- ), je = r ? [{ value: R, noFilter: !0, creatable: !0 }] : [], y = ue(() => [...ye, ...je], [ye, je]), [T, be] = ft({
244
- defaultValue: I.map((s) => s == null ? void 0 : s.toString()),
242
+ [R, x, je, y, oe]
243
+ ), ue = r ? [{ value: R, noFilter: !0, creatable: !0 }] : [], C = te(() => [...be, ...ue], [be, ue]), st = te(() => [...x, ...ue], [x, ue]), [T, Ce] = pt({
244
+ defaultValue: w.map((s) => s == null ? void 0 : s.toString()),
245
245
  value: J,
246
246
  onChange: (s) => {
247
- const a = y.find((F) => F.value === s[0]);
247
+ const a = C.find((F) => F.value === s.at(-1));
248
248
  if (!a) return;
249
249
  const d = s.map(
250
- (F) => y.find((L) => L.value === F)
250
+ (F) => st.find((L) => L.value === F)
251
251
  );
252
252
  m(
253
253
  e.onChange,
@@ -257,65 +257,65 @@ function Qt(e) {
257
257
  }
258
258
  });
259
259
  D(() => {
260
- y.length === 0 && !l && w && _();
261
- }, [y.length, l, w]);
262
- const [K, G] = Le(
263
- t ? (He = E[0]) == null ? void 0 : He.value : null
264
- ), st = e.maxSelections || T.length + 1, Ce = y.findIndex((s) => s.value === K), Se = Nt(
265
- Ce,
266
- y,
260
+ C.length === 0 && !l && O && _();
261
+ }, [C.length, l, O]);
262
+ const [K, G] = Ne(
263
+ t ? (He = x[0]) == null ? void 0 : He.value : null
264
+ ), lt = e.maxSelections || T.length + 1, Se = C.findIndex((s) => s.value === K), xe = Pt(
265
+ Se,
266
+ C,
267
267
  !!e.rollNavigation
268
- ), xe = Pt(
269
- Ce,
270
- y,
268
+ ), Ae = Dt(
269
+ Se,
270
+ C,
271
271
  !!e.rollNavigation
272
- ), P = Ft(y), Ae = Ne(y), ke = !y.some(
272
+ ), P = Lt(C), Ie = Pe(C), ke = !C.some(
273
273
  (s) => s.value === K
274
274
  );
275
275
  D(() => {
276
276
  var s;
277
- ke && G(t ? (s = E[0]) == null ? void 0 : s.value : null);
278
- }, [ke]), pt(() => {
277
+ ke && G(t ? (s = x[0]) == null ? void 0 : s.value : null);
278
+ }, [ke]), dt(() => {
279
279
  t && G(P == null ? void 0 : P.value);
280
280
  }, [R, P == null ? void 0 : P.value]), D(() => {
281
281
  var s;
282
- !w && t && G((s = E[0]) == null ? void 0 : s.value);
283
- }, [w]), D(() => {
284
- w && h && se(!0);
285
- }, [w, h, se]), D(() => {
286
- const s = E.find((a) => a.value === K);
282
+ !O && t && G((s = x[0]) == null ? void 0 : s.value);
283
+ }, [O]), D(() => {
284
+ O && h && le(!0);
285
+ }, [O, h, le]), D(() => {
286
+ const s = x.find((a) => a.value === K);
287
287
  m(e.onOptionFocus, {
288
288
  item: s,
289
289
  focusMethod: $.current,
290
290
  isNewInput: s == null ? void 0 : s.creatable
291
291
  });
292
292
  }, [K, e.onOptionFocus]);
293
- const Ie = (s) => {
293
+ const we = (s) => {
294
294
  var F, L;
295
- const a = y.find((x) => x.value === s), d = (a == null ? void 0 : a.label) || (a == null ? void 0 : a.value);
296
- Z(() => c ? "" : d ?? ""), !T.includes(s) && T.length < st && be((x) => c ? [...x, s] : [s]), c && ((F = N.current) == null || F.focus()), e.focusInputOnSelect && ((L = N.current) == null || L.focus()), m(e.onSelectOption, {
295
+ const a = C.find((A) => A.value === s), d = (a == null ? void 0 : a.label) || (a == null ? void 0 : a.value);
296
+ Z(() => c ? "" : d ?? ""), !T.includes(s) && T.length < lt && Ce((A) => c ? [...A, s] : [s]), c && ((F = N.current) == null || F.focus()), e.focusInputOnSelect && ((L = N.current) == null || L.focus()), m(e.onSelectOption, {
297
297
  item: a,
298
298
  selectMethod: $.current,
299
299
  isNewInput: a == null ? void 0 : a.creatable
300
300
  }), a != null && a.creatable && m(e.onCreateOption, {
301
- item: Me(a, ["noFilter"]),
301
+ item: _e(a, ["noFilter"]),
302
302
  selectMethod: $.current
303
- }), O && _();
303
+ }), E && _();
304
304
  }, ze = (s, a) => {
305
305
  var L;
306
- be((x) => {
307
- let W = E.find((M) => M.value === s);
308
- return !W && r === !0 && (W = { label: s, value: s }), W ? (m(e.onTagRemoved, s, W, x), x.filter((M) => M !== s)) : x;
306
+ Ce((A) => {
307
+ let W = x.find((M) => M.value === s);
308
+ return !W && r === !0 && (W = { label: s, value: s }), W ? (m(e.onTagRemoved, s, W, A), A.filter((M) => M !== s)) : A;
309
309
  });
310
- const d = E.find((x) => x.value === s), F = (d == null ? void 0 : d.label) || (d == null ? void 0 : d.value);
310
+ const d = x.find((A) => A.value === s), F = (d == null ? void 0 : d.label) || (d == null ? void 0 : d.value);
311
311
  R === F && Z(""), a && ((L = N.current) == null || L.focus());
312
- }, lt = (s) => {
312
+ }, it = (s) => {
313
313
  var a;
314
- be([]), s && ((a = N.current) == null || a.focus());
314
+ Ce([]), s && ((a = N.current) == null || a.focus());
315
315
  }, Be = c ? T.map((s) => {
316
316
  var a;
317
317
  return {
318
- label: ((a = E.find((d) => d.value === (s == null ? void 0 : s.toString()))) == null ? void 0 : a.label) || s,
318
+ label: ((a = x.find((d) => d.value === (s == null ? void 0 : s.toString()))) == null ? void 0 : a.label) || s,
319
319
  onRemove: () => ze(s)
320
320
  };
321
321
  }) : [];
@@ -323,23 +323,23 @@ function Qt(e) {
323
323
  m(U, { tags: Be });
324
324
  }, [T]), {
325
325
  autoCompleteProps: e,
326
- children: he,
327
- filteredList: y,
328
- filteredResults: ye,
326
+ children: ye,
327
+ filteredList: C,
328
+ filteredResults: be,
329
329
  focusedValue: K,
330
330
  defaultEmptyStateProps: i,
331
331
  getEmptyStateProps: (s) => {
332
- if (y.every((d) => d.noFilter) && l && !r)
332
+ if (C.every((d) => d.noFilter) && l && !r)
333
333
  return typeof l == "boolean" ? s : m(l, { query: R });
334
334
  },
335
335
  getGroupProps: (s) => {
336
- const a = Ht(s.children, y);
336
+ const a = Ut(s.children, C);
337
337
  return {
338
338
  divider: {
339
- hasFirstChild: zt(s.children, P),
340
- hasLastChild: Bt(
339
+ hasFirstChild: Bt(s.children, P),
340
+ hasLastChild: Ht(
341
341
  s.children,
342
- Ne(y.filter((d) => ce(d == null ? void 0 : d.noFilter)))
342
+ Pe(C.filter((d) => fe(d == null ? void 0 : d.noFilter)))
343
343
  )
344
344
  },
345
345
  group: {
@@ -348,59 +348,59 @@ function Qt(e) {
348
348
  };
349
349
  },
350
350
  getInputProps: (s, a) => {
351
- const { onBlur: d, onChange: F, onFocus: L, onKeyDown: x, variant: W, ...M } = s;
351
+ const { onBlur: d, onChange: F, onFocus: L, onKeyDown: A, variant: W, ...M } = s;
352
352
  return {
353
353
  wrapper: {
354
- ref: Ge,
354
+ ref: We,
355
355
  onClick: () => {
356
356
  var f;
357
357
  (f = N == null ? void 0 : N.current) == null || f.focus();
358
358
  },
359
- ...Ut(a, c),
359
+ ...Qt(a, c),
360
360
  ...M
361
361
  },
362
362
  input: {
363
363
  isReadOnly: v,
364
364
  onFocus: (f) => {
365
- m(L, f), e.openOnFocus && !v && Q(), e.selectOnFocus && f.target.select(), h && se(!0);
365
+ m(L, f), e.openOnFocus && !v && Q(), e.selectOnFocus && f.target.select(), h && le(!0);
366
366
  },
367
367
  onBlur: (f) => {
368
- var B, ie;
368
+ var B, ae;
369
369
  m(d, f);
370
- const S = f.relatedTarget === (X == null ? void 0 : X.current) || ((B = X.current) == null ? void 0 : B.contains(f.relatedTarget)), g = (ie = Ge.current) == null ? void 0 : ie.contains(
370
+ const S = f.relatedTarget === (X == null ? void 0 : X.current) || ((B = X.current) == null ? void 0 : B.contains(f.relatedTarget)), g = (ae = We.current) == null ? void 0 : ae.contains(
371
371
  f.relatedTarget
372
372
  );
373
373
  if (!S && !g && (n && _(), !T.includes(f.target.value) && Y)) {
374
- const we = Ne(T), A = E.find(
375
- (Ee) => Ee.value === we
376
- ), Oe = (A == null ? void 0 : A.label) || (A == null ? void 0 : A.value) || "";
377
- Z(Oe);
374
+ const Oe = Pe(T), I = x.find(
375
+ (Fe) => Fe.value === Oe
376
+ ), Ee = (I == null ? void 0 : I.label) || (I == null ? void 0 : I.value) || "";
377
+ Z(Ee);
378
378
  }
379
379
  },
380
380
  onChange: (f) => {
381
381
  const S = f.target.value;
382
382
  m(F, f), Z(S);
383
- const g = Te(S);
384
- m(me, S) && (!g || re) ? Q() : _(), se(!1);
383
+ const g = Me(S);
384
+ m(ve, S) && (!g || se) ? Q() : _(), le(!1);
385
385
  },
386
386
  onKeyDown: (f) => {
387
387
  var B;
388
- m(x, f), $.current = "keyboard";
389
- const { key: S } = f, g = y[Ce];
390
- if (["Enter", ...ve].includes(S)) {
391
- g && !(g != null && g.disabled) && w ? Ie(g == null ? void 0 : g.value) : (B = N.current) == null || B.focus(), f.preventDefault();
388
+ m(A, f), $.current = "keyboard";
389
+ const { key: S } = f, g = C[Se];
390
+ if (["Enter", ...he].includes(S)) {
391
+ g && !(g != null && g.disabled) && O ? we(g == null ? void 0 : g.value) : (B = N.current) == null || B.focus(), f.preventDefault();
392
392
  return;
393
393
  }
394
394
  if (S === "ArrowDown") {
395
- w ? G(Se == null ? void 0 : Se.value) : Q(), f.preventDefault();
395
+ O ? G(xe == null ? void 0 : xe.value) : Q(), f.preventDefault();
396
396
  return;
397
397
  }
398
398
  if (S === "ArrowUp") {
399
- w ? G(xe == null ? void 0 : xe.value) : Q(), f.preventDefault();
399
+ O ? G(Ae == null ? void 0 : Ae.value) : Q(), f.preventDefault();
400
400
  return;
401
401
  }
402
402
  if (S === "Tab") {
403
- w && g && !(g != null && g.disabled) ? Ie(g == null ? void 0 : g.value) : _();
403
+ O && g && !(g != null && g.disabled) ? we(g == null ? void 0 : g.value) : _();
404
404
  return;
405
405
  }
406
406
  if (S === "Home") {
@@ -408,7 +408,7 @@ function Qt(e) {
408
408
  return;
409
409
  }
410
410
  if (S === "End") {
411
- G(Ae == null ? void 0 : Ae.value), f.preventDefault();
411
+ G(Ie == null ? void 0 : Ie.value), f.preventDefault();
412
412
  return;
413
413
  }
414
414
  S === "Escape" && (_(), f.preventDefault());
@@ -425,74 +425,74 @@ function Qt(e) {
425
425
  _fixed: d,
426
426
  _focus: F,
427
427
  children: L,
428
- disabled: x,
428
+ disabled: A,
429
429
  label: W,
430
430
  value: M,
431
431
  fixed: f,
432
- getValue: S = _e,
432
+ getValue: S = Ge,
433
433
  onClick: g,
434
434
  onMouseOver: B,
435
- sx: ie,
436
- ...we
437
- } = s, A = a ? M : (Ue = S(M)) == null ? void 0 : Ue.toString(), Oe = A === K, Ee = y.findIndex((q) => q.value === A) >= 0, Fe = L || W || A;
435
+ sx: ae,
436
+ ...Oe
437
+ } = s, I = a ? M : (Ue = S(M)) == null ? void 0 : Ue.toString(), Ee = I === K, Fe = C.findIndex((q) => q.value === I) >= 0, Le = L || W || I;
438
438
  return {
439
439
  item: {
440
- ...typeof Fe != "string" || !o ? { children: Fe } : {
440
+ ...typeof Le != "string" || !o ? { children: Le } : {
441
441
  dangerouslySetInnerHTML: {
442
- __html: _t(Fe, R)
442
+ __html: Gt(Le, R)
443
443
  }
444
444
  },
445
- "aria-selected": T.includes(A),
446
- "aria-disabled": x,
445
+ "aria-selected": T.includes(I),
446
+ "aria-disabled": A,
447
447
  _disabled: { opacity: 0.4, cursor: "not-allowed", userSelect: "none" },
448
448
  onClick: (q) => {
449
449
  var Qe;
450
- m(g, q), x ? (Qe = N.current) == null || Qe.focus() : Ie(A);
450
+ m(g, q), A ? (Qe = N.current) == null || Qe.focus() : we(I);
451
451
  },
452
452
  onMouseOver: (q) => {
453
- m(B, q), G(A), $.current = "mouse";
453
+ m(B, q), G(I), $.current = "mouse";
454
454
  },
455
455
  sx: {
456
- ...ie,
456
+ ...ae,
457
457
  mark: {
458
458
  color: "inherit",
459
459
  bg: "transparent",
460
- ...Re(o) ? o : {
460
+ ...Te(o) ? o : {
461
461
  fontWeight: o ? "extrabold" : "inherit"
462
462
  }
463
463
  }
464
464
  },
465
- ...Oe && (F || Wt()),
465
+ ...Ee && (F || jt()),
466
466
  ...f && d,
467
- ...we
467
+ ...Oe
468
468
  },
469
469
  root: {
470
- isValidSuggestion: Ee,
471
- value: A
470
+ isValidSuggestion: Fe,
471
+ value: I
472
472
  }
473
473
  };
474
474
  },
475
475
  inputRef: N,
476
476
  interactionRef: $,
477
- isLoading: ge,
478
- isOpen: w,
479
- itemList: E,
477
+ isLoading: me,
478
+ isOpen: O,
479
+ itemList: x,
480
480
  listRef: X,
481
481
  onClose: _,
482
482
  onOpen: Q,
483
- placement: oe,
483
+ placement: re,
484
484
  query: R,
485
485
  removeItem: ze,
486
- resetItems: lt,
486
+ resetItems: it,
487
487
  setQuery: Z,
488
488
  tags: Be,
489
489
  value: z,
490
490
  values: T
491
491
  };
492
492
  }
493
- const $t = H(
493
+ const Kt = H(
494
494
  (e, t) => {
495
- const n = Qt(e), {
495
+ const n = $t(e), {
496
496
  children: r,
497
497
  isOpen: o,
498
498
  onClose: l,
@@ -501,49 +501,49 @@ const $t = H(
501
501
  resetItems: v,
502
502
  removeItem: h
503
503
  } = n;
504
- ut(t, () => ({
504
+ at(t, () => ({
505
505
  resetItems: v,
506
506
  removeItem: h
507
507
  }));
508
- const { matchWidth: b = !0 } = n.autoCompleteProps;
509
- return /* @__PURE__ */ p(Ot, { value: n, children: /* @__PURE__ */ p(
510
- dt,
508
+ const { matchWidth: y = !0 } = n.autoCompleteProps;
509
+ return /* @__PURE__ */ p(Et, { value: n, children: /* @__PURE__ */ p(
510
+ gt,
511
511
  {
512
512
  isLazy: !0,
513
513
  isOpen: o,
514
514
  autoFocus: !1,
515
515
  placement: u,
516
516
  closeOnBlur: !0,
517
- matchWidth: b,
518
- children: /* @__PURE__ */ p(gt.div, { w: "full", ref: t, children: r })
517
+ matchWidth: y,
518
+ children: /* @__PURE__ */ p(mt.div, { w: "full", ref: t, children: r })
519
519
  }
520
520
  ) });
521
521
  }
522
522
  );
523
- $t.displayName = "AutoComplete";
524
- const Kt = H(
523
+ Kt.displayName = "AutoComplete";
524
+ const Vt = H(
525
525
  (e, t) => {
526
526
  const {
527
527
  focusedValue: n,
528
528
  getItemProps: r,
529
529
  interactionRef: o
530
- } = j(), l = te(), i = Pe(t, l), u = r(e), { isValidSuggestion: v, value: h } = u.root, b = n === h;
530
+ } = j(), l = ne(), i = De(t, l), u = r(e), { isValidSuggestion: v, value: h } = u.root, y = n === h;
531
531
  D(() => {
532
532
  var U;
533
- b && o.current === "keyboard" && ((U = l == null ? void 0 : l.current) == null || U.scrollIntoView({
533
+ y && o.current === "keyboard" && ((U = l == null ? void 0 : l.current) == null || U.scrollIntoView({
534
534
  behavior: "smooth",
535
535
  block: "nearest"
536
536
  }));
537
- }, [b, o]), D(() => {
538
- typeof h != "string" && console.warn("wow"), typeof h != "string" && ce(e.getValue) && console.error(
537
+ }, [y, o]), D(() => {
538
+ typeof h != "string" && console.warn("wow"), typeof h != "string" && fe(e.getValue) && console.error(
539
539
  "You must define the `getValue` prop, when an Item's value is not a string"
540
540
  );
541
541
  }, []);
542
- const { children: c, dangerouslySetInnerHTML: O, ...C } = u.item, I = Me(C, ["groupId"]);
543
- return v ? /* @__PURE__ */ p(pe, { ref: i, ...ot, ...I, children: c || /* @__PURE__ */ p("span", { dangerouslySetInnerHTML: O }) }) : null;
542
+ const { children: c, dangerouslySetInnerHTML: E, ...b } = u.item, w = _e(b, ["groupId"]);
543
+ return v ? /* @__PURE__ */ p(de, { ref: i, ...ot, ...w, children: c || /* @__PURE__ */ p("span", { dangerouslySetInnerHTML: E }) }) : null;
544
544
  }
545
545
  );
546
- Kt.displayName = "AutoCompleteItem";
546
+ Vt.displayName = "AutoCompleteItem";
547
547
  const ot = {
548
548
  mx: "2",
549
549
  px: "2",
@@ -551,7 +551,7 @@ const ot = {
551
551
  rounded: "md",
552
552
  cursor: "pointer"
553
553
  };
554
- function Vt(e) {
554
+ function Yt(e) {
555
555
  const { alwaysDisplay: t, children: n, ...r } = e, {
556
556
  autoCompleteProps: o,
557
557
  getItemProps: l,
@@ -566,32 +566,32 @@ function Vt(e) {
566
566
  })
567
567
  },
568
568
  !0
569
- ).item, b = u.some((C) => C.value === i), c = Te(i) ? t : !0;
570
- return o.creatable && c && !b ? /* @__PURE__ */ p(pe, { ...ot, ...h, ...r, children: v || `Add ${i}` }) : null;
569
+ ).item, y = u.some((b) => b.value === i), c = Me(i) ? t : !0;
570
+ return o.creatable && c && !y ? /* @__PURE__ */ p(de, { ...ot, ...h, ...r, children: v || `Add ${i}` }) : null;
571
571
  }
572
- Vt.displayName = "AutoCompleteCreatable";
573
- const Yt = H(
572
+ Yt.displayName = "AutoCompleteCreatable";
573
+ const Jt = H(
574
574
  (e, t) => {
575
- const { children: n, showDivider: r, ...o } = e, l = Me(o, ["groupSibling"]), { getGroupProps: i } = j(), { group: u } = i(e), v = Zt(e);
575
+ const { children: n, showDivider: r, ...o } = e, l = _e(o, ["groupSibling"]), { getGroupProps: i } = j(), { group: u } = i(e), v = qt(e);
576
576
  return /* @__PURE__ */ V(Xe, { ref: t, ...u, ...l, children: [
577
577
  /* @__PURE__ */ p($e, { ...v.top }),
578
578
  n,
579
579
  /* @__PURE__ */ p($e, { ...v.bottom })
580
580
  ] });
581
581
  }
582
- ), Jt = H(
583
- (e, t) => /* @__PURE__ */ p(pe, { ...Xt, ...e, ref: t })
582
+ ), Xt = H(
583
+ (e, t) => /* @__PURE__ */ p(de, { ...Zt, ...e, ref: t })
584
584
  );
585
- Yt.displayName = "AutoCompleteGroup";
586
- Jt.displayName = "AutoCompleteGroupTitle";
587
- const Xt = {
585
+ Jt.displayName = "AutoCompleteGroup";
586
+ Xt.displayName = "AutoCompleteGroupTitle";
587
+ const Zt = {
588
588
  ml: 5,
589
589
  my: 1,
590
590
  fontSize: "xs",
591
591
  letterSpacing: "wider",
592
592
  fontWeight: "extrabold",
593
593
  textTransform: "uppercase"
594
- }, Zt = (e) => {
594
+ }, qt = (e) => {
595
595
  const { getGroupProps: t } = j(), n = e.groupSibling, {
596
596
  divider: { hasFirstChild: r, hasLastChild: o }
597
597
  } = t(e), l = {
@@ -608,9 +608,9 @@ const Xt = {
608
608
  return { top: i, bottom: u };
609
609
  }, Ve = H((e, t) => {
610
610
  const { isLoading: n } = j(), { loadingIcon: r, ...o } = e;
611
- return /* @__PURE__ */ V(mt, { children: [
612
- /* @__PURE__ */ p(vt, { ...o, ref: t }),
613
- n && /* @__PURE__ */ p(ht, { children: r || /* @__PURE__ */ p(Ze, {}) })
611
+ return /* @__PURE__ */ V(vt, { children: [
612
+ /* @__PURE__ */ p(ht, { ...o, ref: t }),
613
+ n && /* @__PURE__ */ p(yt, { children: r || /* @__PURE__ */ p(Ze, {}) })
614
614
  ] });
615
615
  }), rt = H(
616
616
  (e, t) => {
@@ -624,54 +624,54 @@ const Xt = {
624
624
  itemList: v
625
625
  } = j(), {
626
626
  children: h,
627
- isInvalid: b,
627
+ isInvalid: y,
628
628
  hidePlaceholder: c,
629
- ...O
630
- } = e, { value: C } = O;
629
+ ...E
630
+ } = e, { value: b } = E;
631
631
  D(() => {
632
632
  if (u !== void 0 && (typeof u == "string" || u instanceof String)) {
633
- const re = v.find((J) => J.value === u), z = re === void 0 ? u : re.label;
633
+ const se = v.find((J) => J.value === u), z = se === void 0 ? u : se.label;
634
634
  i(z);
635
635
  }
636
636
  }, [u]), D(() => {
637
- C !== void 0 && (typeof C == "string" || C instanceof String) && i(C);
638
- }, [C]);
639
- const I = yt("Input", e);
640
- let { wrapper: U, input: k } = o(O, I);
641
- const { ref: ne, ...ge } = U, oe = Pe(t, r), Y = m(h, { tags: l });
637
+ b !== void 0 && (typeof b == "string" || b instanceof String) && i(b);
638
+ }, [b]);
639
+ const w = bt("Input", e);
640
+ let { wrapper: U, input: k } = o(E, w);
641
+ const { ref: oe, ...me } = U, re = De(t, r), Y = m(h, { tags: l });
642
642
  c && (k = {
643
643
  ...k,
644
644
  placeholder: Array.isArray(Y) && Y.length ? void 0 : k.placeholder
645
645
  });
646
- const me = /* @__PURE__ */ p(
646
+ const ve = /* @__PURE__ */ p(
647
647
  Ve,
648
648
  {
649
- isInvalid: b,
649
+ isInvalid: y,
650
650
  ...k,
651
- ref: oe
651
+ ref: re
652
652
  }
653
- ), ve = /* @__PURE__ */ V(bt, { "aria-invalid": b, ...ge, ref: ne, children: [
653
+ ), he = /* @__PURE__ */ V(Ct, { "aria-invalid": y, ...me, ref: oe, children: [
654
654
  Y,
655
655
  /* @__PURE__ */ p(
656
656
  qe,
657
657
  {
658
658
  as: Ve,
659
659
  ...k,
660
- ref: oe
660
+ ref: re
661
661
  }
662
662
  )
663
663
  ] });
664
- return /* @__PURE__ */ p(Ct, { children: n.multiple ? ve : me });
664
+ return /* @__PURE__ */ p(St, { children: n.multiple ? he : ve });
665
665
  }
666
666
  );
667
667
  rt.displayName = "Input";
668
668
  rt.id = "Input";
669
- const qt = (e) => {
669
+ const en = (e) => {
670
670
  const { getEmptyStateProps: t, defaultEmptyStateProps: n } = j(), r = t(
671
- /* @__PURE__ */ p(pe, { ...en, ...n, children: "No options found!" })
671
+ /* @__PURE__ */ p(de, { ...tn, ...n, children: "No options found!" })
672
672
  );
673
673
  return /* @__PURE__ */ p(Xe, { ...e, children: r });
674
- }, en = {
674
+ }, tn = {
675
675
  fontSize: "sm",
676
676
  align: "center",
677
677
  justify: "center",
@@ -681,7 +681,7 @@ const qt = (e) => {
681
681
  "AutoCompleteGroup",
682
682
  "AutoCompleteItem",
683
683
  "AutoCompleteCreatable"
684
- ], tn = (e) => {
684
+ ], nn = (e) => {
685
685
  const t = ee.Children.map(e, (o, l) => {
686
686
  var i;
687
687
  if (((i = o == null ? void 0 : o.type) == null ? void 0 : i.displayName) === "AutoCompleteGroup") {
@@ -707,21 +707,21 @@ const qt = (e) => {
707
707
  );
708
708
  }
709
709
  ), n];
710
- }, nn = H(
710
+ }, on = H(
711
711
  (e, t) => {
712
- const { children: n, loadingState: r, ...o } = e, { listRef: l, isLoading: i } = j(), u = Pe(t, l), [v, h] = tn(n);
713
- return /* @__PURE__ */ V(St, { ref: u, w: "inherit", ...on, ...o, children: [
714
- i && /* @__PURE__ */ p(xt, { children: r || /* @__PURE__ */ p(Ze, { size: "md" }) }),
715
- !i && /* @__PURE__ */ V(it, { children: [
712
+ const { children: n, loadingState: r, ...o } = e, { listRef: l, isLoading: i } = j(), u = De(t, l), [v, h] = nn(n);
713
+ return /* @__PURE__ */ V(xt, { ref: u, w: "inherit", ...rn, ...o, children: [
714
+ i && /* @__PURE__ */ p(At, { children: r || /* @__PURE__ */ p(Ze, { size: "md" }) }),
715
+ !i && /* @__PURE__ */ V(ut, { children: [
716
716
  v,
717
- /* @__PURE__ */ p(qt, {}),
717
+ /* @__PURE__ */ p(en, {}),
718
718
  h
719
719
  ] })
720
720
  ] });
721
721
  }
722
722
  );
723
- nn.displayName = "AutoCompleteList";
724
- const on = {
723
+ on.displayName = "AutoCompleteList";
724
+ const rn = {
725
725
  py: "4",
726
726
  opacity: "0",
727
727
  bg: "#232934",
@@ -737,19 +737,19 @@ const on = {
737
737
  _focus: {
738
738
  boxShadow: "none"
739
739
  }
740
- }, pn = at((e) => {
740
+ }, dn = ct((e) => {
741
741
  const { label: t, onRemove: n, disabled: r, ...o } = e;
742
742
  return /* @__PURE__ */ p(qe, { children: /* @__PURE__ */ V(
743
- At,
743
+ It,
744
744
  {
745
745
  borderRadius: "md",
746
746
  fontWeight: "normal",
747
747
  ...r && Je,
748
748
  ...o,
749
749
  children: [
750
- /* @__PURE__ */ p(It, { children: t }),
750
+ /* @__PURE__ */ p(wt, { children: t }),
751
751
  /* @__PURE__ */ p(
752
- wt,
752
+ Ot,
753
753
  {
754
754
  onClick: () => !r && m(n),
755
755
  cursor: "pointer",
@@ -766,17 +766,17 @@ const on = {
766
766
  _focus: { boxShadow: "none" }
767
767
  };
768
768
  export {
769
- $t as AutoComplete,
770
- Vt as AutoCompleteCreatable,
771
- Yt as AutoCompleteGroup,
772
- Jt as AutoCompleteGroupTitle,
769
+ Kt as AutoComplete,
770
+ Yt as AutoCompleteCreatable,
771
+ Jt as AutoCompleteGroup,
772
+ Xt as AutoCompleteGroupTitle,
773
773
  rt as AutoCompleteInput,
774
- Kt as AutoCompleteItem,
775
- nn as AutoCompleteList,
776
- Ot as AutoCompleteProvider,
777
- pn as AutoCompleteTag,
774
+ Vt as AutoCompleteItem,
775
+ on as AutoCompleteList,
776
+ Et as AutoCompleteProvider,
777
+ dn as AutoCompleteTag,
778
778
  ot as baseItemStyles,
779
- Et as createContext,
780
- Qt as useAutoComplete,
779
+ Ft as createContext,
780
+ $t as useAutoComplete,
781
781
  j as useAutoCompleteContext
782
782
  };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react/jsx-runtime"),f=require("react"),a=require("@chakra-ui/react");function st(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const ue=st(f),[Qe,_]=$e();function $e(){const e=ue.createContext(void 0);e.displayName="AutoCompleteContext";function t(){var o;const n=ue.useContext(e),r="useAutoCompleteContext: `context` is undefined. Seems you forgot to wrap all autoomplete components within `<AutoComplete />`";if(!n){const l=new Error(r);throw l.name="ContextError",(o=Error.captureStackTrace)==null||o.call(Error,l,t),l}return n}return[e.Provider,t,e]}function lt(e){return e==null?void 0:e[0]}function we(e){return e!=null&&e.length?e[e.length-1]:void 0}function Ke(e,t,n=1,r=!0){if(t===0)return-1;let o=e+n;return e===-1&&(o=n>0?0:t-1),r?o=(o%t+t)%t:o=Math.max(0,Math.min(o,t-1)),o}function ut(e,t,n=!0){return Ke(e,t,-1,n)}function it(e,t,n=!0){const r=Ke(e,t.length,1,n);return t[r]}function at(e,t,n=!0){const r=ut(e,t.length,n);return t[r]}function Ie(e){return Array.isArray(e)}function ct(e){return Ie(e)&&e.length===0}function je(e){return e!==null&&typeof e=="object"&&!Ie(e)}function ft(e){return je(e)&&Object.keys(e).length===0}function Ee(e){return Ie(e)?ct(e):je(e)?ft(e):e==null||e===""}function le(e){return typeof e>"u"}function Ve(e){return typeof e<"u"}function pt(e,t){const n={};return t.forEach(r=>{r in e&&(n[r]=e[r])}),n}function Oe(e,t){const n={...e};return t.forEach(r=>{delete n[r]}),n}function dt(e){return typeof e=="function"}function h(e,...t){return dt(e)?e(...t):e}var ie=function(e,t){for(var n,r=ue.Children.toArray(e),o=0,l=r;o<l.length;o++){var u=l[o];if(t(u))return u;if(!((n=u.props)===null||n===void 0)&&n.children){var i=ie(u.props.children,t);if(i)return i}}},se=function(e,t){for(var n=0,r=t.length,o=e.length;n<r;n++,o++)e[o]=t[n];return e},Ye=function(e,t){for(var n,r=ue.Children.toArray(e),o=[],l=0,u=r;l<u.length;l++){var i=u[l];t(i)&&(o=se(se([],o),[i])),!((n=i.props)===null||n===void 0)&&n.children&&(o=se(se([],o),Ye(i.props.children,t)))}return o};function ze(e,t,n=2){function r(d,O){d=" ".repeat(O-1)+d.toLowerCase()+" ".repeat(O-1);let S=new Array(d.length-O+1);for(let j=0;j<S.length;j++)S[j]=d.slice(j,j+O);return S}if(!(e!=null&&e.length)||!(t!=null&&t.length))return 0;let o=e.length<t.length?e:t,l=e.length<t.length?t:e,u=r(o,n),i=r(l,n),y=new Set(u),C=i.length,b=0;for(let d of i)y.delete(d)&&b++;return b/C}const Re=e=>{var t;return(t=typeof e=="string"||typeof e=="number"?e:e[Object.keys(e)[0]])==null?void 0:t.toString()},gt=(e,t)=>typeof e!="string"||Ee(t)?e:e.toString().replace(new RegExp(yt(t),"gi"),r=>`<mark>${r}</mark>`),mt=e=>Ye(e,n=>{var r;return((r=n==null?void 0:n.type)==null?void 0:r.displayName)==="AutoCompleteItem"}).map(n=>{const r=pt(n.props,["value","label","fixed","disabled"]),{getValue:o=Re}=n.props,l=o(r.value);return{...Ve(r.label)?r:{...r,label:l},value:l,originalValue:r.value}}),vt=()=>({bg:"whiteAlpha.100",_light:{bg:"gray.200"}}),ht=(e,t,n)=>(t==null?void 0:t.toLowerCase().indexOf(e==null?void 0:e.toLowerCase()))>=0||(n==null?void 0:n.toLowerCase().indexOf(e==null?void 0:e.toLowerCase()))>=0||ze(e,t)>=.5||ze(e,n)>=.5;function yt(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}const Ct=(e,t)=>ie(e,r=>{var o;return((o=r==null?void 0:r.type)==null?void 0:o.displayName)==="AutoCompleteItem"&&r.props.value===(t==null?void 0:t.value)}),xt=(e,t)=>ie(e,r=>{var o;return((o=r==null?void 0:r.type)==null?void 0:o.displayName)==="AutoCompleteItem"&&r.props.value===(t==null?void 0:t.value)}),bt=(e,t)=>Ve(ie(e,n=>{var o,l;const r=h(((o=n.props)==null?void 0:o.getValue)||Re,((l=n.props)==null?void 0:l.value)||{});return t.some(u=>u.value===r)})),St=(e,t)=>{const n={},r={},{field:o}=e;return o&&Object.keys(o).forEach(l=>{if(l.startsWith("--input")===!1)n[l]=o[l];else{let u=o[l];const y=l.replace("--input-","").replace(/-([a-z])/g,function(C){return C[1].toUpperCase()});u.indexOf(".")!==-1&&(u=u.substring(u.indexOf(".")+1)),r[y]=u}}),{...t&&{...n,...r,_focusWithin:e.field._focus,pos:"relative",minH:9,py:1.5,spacing:3},cursor:"text",h:"fit-content"}};function Je(e){var Ge;let{prefocusFirstItem:t=!0,closeOnBlur:n=!0,creatable:r,emphasize:o,emptyState:l=!0,defaultEmptyStateProps:u={},freeSolo:i,isReadOnly:y,listAllValuesOnFocus:C,maxSuggestions:b,multiple:d,closeOnSelect:O=!d,defaultValue:S,defaultValues:j=S?[S]:[],onReady:U,defaultIsOpen:z,disableFilter:q,isLoading:ae=!1,placement:ee="bottom",restoreOnBlurIfEmpty:V=!i,shouldRenderSuggestions:ce=()=>!0,submitKeys:fe=[],suggestWhenEmpty:te,value:B,values:Y=B?typeof B=="string"?[B]:[...B]:void 0}=e;i=i||(d?!0:e.freeSolo);const{isOpen:E,onClose:G,onOpen:Q}=a.useDisclosure({defaultIsOpen:z}),pe=f.useMemo(()=>h(e.children,{isOpen:E,onClose:G,onOpen:Q}),[e.children,E]),R=f.useMemo(()=>mt(pe),[pe]),N=f.useRef(null),Ne=f.useRef(null),J=f.useRef(null),$=f.useRef(null),[Pe,ne]=f.useState(!1);let oe="";d?oe="":le(j)?le(Y)||(oe=Y[0]):oe=j[0];const[D,X]=f.useState(oe??""),de=f.useMemo(()=>q?R:R.filter(s=>s.fixed||h(e.filter||ht,D,s.value,s.label)||Pe).filter((s,c)=>b?s.fixed||c<b:!0),[D,R,Pe,b,q]),De=r?[{value:D,noFilter:!0,creatable:!0}]:[],x=f.useMemo(()=>[...de,...De],[de,De]),[M,ge]=a.useControllableState({defaultValue:j.map(s=>s==null?void 0:s.toString()),value:Y,onChange:s=>{const c=x.find(F=>F.value===s[0]);if(!c)return;const m=s.map(F=>x.find(L=>L.value===F));h(e.onChange,d?s:s[0],d?m:c)}});f.useEffect(()=>{x.length===0&&!l&&E&&G()},[x.length,l,E]);const[K,W]=f.useState(t?(Ge=R[0])==null?void 0:Ge.value:null),ot=e.maxSelections||M.length+1,me=x.findIndex(s=>s.value===K),ve=it(me,x,!!e.rollNavigation),he=at(me,x,!!e.rollNavigation),P=lt(x),ye=we(x),Me=!x.some(s=>s.value===K);f.useEffect(()=>{var s;Me&&W(t?(s=R[0])==null?void 0:s.value:null)},[Me]),a.useUpdateEffect(()=>{t&&W(P==null?void 0:P.value)},[D,P==null?void 0:P.value]),f.useEffect(()=>{var s;!E&&t&&W((s=R[0])==null?void 0:s.value)},[E]),f.useEffect(()=>{E&&C&&ne(!0)},[E,C,ne]),f.useEffect(()=>{const s=R.find(c=>c.value===K);h(e.onOptionFocus,{item:s,focusMethod:$.current,isNewInput:s==null?void 0:s.creatable})},[K,e.onOptionFocus]);const Ce=s=>{var F,L;const c=x.find(w=>w.value===s),m=(c==null?void 0:c.label)||(c==null?void 0:c.value);X(()=>d?"":m??""),!M.includes(s)&&M.length<ot&&ge(w=>d?[...w,s]:[s]),d&&((F=N.current)==null||F.focus()),e.focusInputOnSelect&&((L=N.current)==null||L.focus()),h(e.onSelectOption,{item:c,selectMethod:$.current,isNewInput:c==null?void 0:c.creatable}),c!=null&&c.creatable&&h(e.onCreateOption,{item:Oe(c,["noFilter"]),selectMethod:$.current}),O&&G()},Te=(s,c)=>{var L;ge(w=>{let k=R.find(T=>T.value===s);return!k&&r===!0&&(k={label:s,value:s}),k?(h(e.onTagRemoved,s,k,w),w.filter(T=>T!==s)):w});const m=R.find(w=>w.value===s),F=(m==null?void 0:m.label)||(m==null?void 0:m.value);D===F&&X(""),c&&((L=N.current)==null||L.focus())},rt=s=>{var c;ge([]),s&&((c=N.current)==null||c.focus())},_e=d?M.map(s=>{var c;return{label:((c=R.find(m=>m.value===(s==null?void 0:s.toString())))==null?void 0:c.label)||s,onRemove:()=>Te(s)}}):[];return f.useEffect(()=>{h(U,{tags:_e})},[M]),{autoCompleteProps:e,children:pe,filteredList:x,filteredResults:de,focusedValue:K,defaultEmptyStateProps:u,getEmptyStateProps:s=>{if(x.every(m=>m.noFilter)&&l&&!r)return typeof l=="boolean"?s:h(l,{query:D})},getGroupProps:s=>{const c=bt(s.children,x);return{divider:{hasFirstChild:Ct(s.children,P),hasLastChild:xt(s.children,we(x.filter(m=>le(m==null?void 0:m.noFilter))))},group:{display:c?"initial":"none"}}},getInputProps:(s,c)=>{const{onBlur:m,onChange:F,onFocus:L,onKeyDown:w,variant:k,...T}=s;return{wrapper:{ref:Ne,onClick:()=>{var g;(g=N==null?void 0:N.current)==null||g.focus()},...St(c,d),...T},input:{isReadOnly:y,onFocus:g=>{h(L,g),e.openOnFocus&&!y&&Q(),e.selectOnFocus&&g.target.select(),C&&ne(!0)},onBlur:g=>{var H,re;h(m,g);const A=g.relatedTarget===(J==null?void 0:J.current)||((H=J.current)==null?void 0:H.contains(g.relatedTarget)),v=(re=Ne.current)==null?void 0:re.contains(g.relatedTarget);if(!A&&!v&&(n&&G(),!M.includes(g.target.value)&&V)){const xe=we(M),I=R.find(Se=>Se.value===xe),be=(I==null?void 0:I.label)||(I==null?void 0:I.value)||"";X(be)}},onChange:g=>{const A=g.target.value;h(F,g),X(A);const v=Ee(A);h(ce,A)&&(!v||te)?Q():G(),ne(!1)},onKeyDown:g=>{var H;h(w,g),$.current="keyboard";const{key:A}=g,v=x[me];if(["Enter",...fe].includes(A)){v&&!(v!=null&&v.disabled)&&E?Ce(v==null?void 0:v.value):(H=N.current)==null||H.focus(),g.preventDefault();return}if(A==="ArrowDown"){E?W(ve==null?void 0:ve.value):Q(),g.preventDefault();return}if(A==="ArrowUp"){E?W(he==null?void 0:he.value):Q(),g.preventDefault();return}if(A==="Tab"){E&&v&&!(v!=null&&v.disabled)?Ce(v==null?void 0:v.value):G();return}if(A==="Home"){W(P==null?void 0:P.value),g.preventDefault();return}if(A==="End"){W(ye==null?void 0:ye.value),g.preventDefault();return}A==="Escape"&&(G(),g.preventDefault())},value:D,variant:d?"unstyled":k,...T}}},getItemProps:(s,c)=>{var We;const{_fixed:m,_focus:F,children:L,disabled:w,label:k,value:T,fixed:g,getValue:A=Re,onClick:v,onMouseOver:H,sx:re,...xe}=s,I=c?T:(We=A(T))==null?void 0:We.toString(),be=I===K,Se=x.findIndex(Z=>Z.value===I)>=0,Ae=L||k||I;return{item:{...typeof Ae!="string"||!o?{children:Ae}:{dangerouslySetInnerHTML:{__html:gt(Ae,D)}},"aria-selected":M.includes(I),"aria-disabled":w,_disabled:{opacity:.4,cursor:"not-allowed",userSelect:"none"},onClick:Z=>{var ke;h(v,Z),w?(ke=N.current)==null||ke.focus():Ce(I)},onMouseOver:Z=>{h(H,Z),W(I),$.current="mouse"},sx:{...re,mark:{color:"inherit",bg:"transparent",...je(o)?o:{fontWeight:o?"extrabold":"inherit"}}},...be&&(F||vt()),...g&&m,...xe},root:{isValidSuggestion:Se,value:I}}},inputRef:N,interactionRef:$,isLoading:ae,isOpen:E,itemList:R,listRef:J,onClose:G,onOpen:Q,placement:ee,query:D,removeItem:Te,resetItems:rt,setQuery:X,tags:_e,value:B,values:M}}const Xe=a.forwardRef((e,t)=>{const n=Je(e),{children:r,isOpen:o,onClose:l,onOpen:u,placement:i,resetItems:y,removeItem:C}=n;f.useImperativeHandle(t,()=>({resetItems:y,removeItem:C}));const{matchWidth:b=!0}=n.autoCompleteProps;return p.jsx(Qe,{value:n,children:p.jsx(a.Popover,{isLazy:!0,isOpen:o,autoFocus:!1,placement:i,closeOnBlur:!0,matchWidth:b,children:p.jsx(a.chakra.div,{w:"full",ref:t,children:r})})})});Xe.displayName="AutoComplete";const Ze=a.forwardRef((e,t)=>{const{focusedValue:n,getItemProps:r,interactionRef:o}=_(),l=f.useRef(),u=a.useMergeRefs(t,l),i=r(e),{isValidSuggestion:y,value:C}=i.root,b=n===C;f.useEffect(()=>{var U;b&&o.current==="keyboard"&&((U=l==null?void 0:l.current)==null||U.scrollIntoView({behavior:"smooth",block:"nearest"}))},[b,o]),f.useEffect(()=>{typeof C!="string"&&console.warn("wow"),typeof C!="string"&&le(e.getValue)&&console.error("You must define the `getValue` prop, when an Item's value is not a string")},[]);const{children:d,dangerouslySetInnerHTML:O,...S}=i.item,j=Oe(S,["groupId"]);return y?p.jsx(a.Flex,{ref:u,...Fe,...j,children:d||p.jsx("span",{dangerouslySetInnerHTML:O})}):null});Ze.displayName="AutoCompleteItem";const Fe={mx:"2",px:"2",py:"2",rounded:"md",cursor:"pointer"};function qe(e){const{alwaysDisplay:t,children:n,...r}=e,{autoCompleteProps:o,getItemProps:l,query:u,filteredResults:i}=_(),{children:y,...C}=l({...e,value:u,children:h(n,{value:u})},!0).item,b=i.some(S=>S.value===u),d=Ee(u)?t:!0;return o.creatable&&d&&!b?p.jsx(a.Flex,{...Fe,...C,...r,children:y||`Add ${u}`}):null}qe.displayName="AutoCompleteCreatable";const et=a.forwardRef((e,t)=>{const{children:n,showDivider:r,...o}=e,l=Oe(o,["groupSibling"]),{getGroupProps:u}=_(),{group:i}=u(e),y=wt(e);return p.jsxs(a.Box,{ref:t,...i,...l,children:[p.jsx(a.Divider,{...y.top}),n,p.jsx(a.Divider,{...y.bottom})]})}),tt=a.forwardRef((e,t)=>p.jsx(a.Flex,{...At,...e,ref:t}));et.displayName="AutoCompleteGroup";tt.displayName="AutoCompleteGroupTitle";const At={ml:5,my:1,fontSize:"xs",letterSpacing:"wider",fontWeight:"extrabold",textTransform:"uppercase"},wt=e=>{const{getGroupProps:t}=_(),n=e.groupSibling,{divider:{hasFirstChild:r,hasLastChild:o}}=t(e),l={my:2,borderColor:e.dividerColor},u={...l,mb:4,display:!e.showDivider||r?"none":""},i={...l,display:!e.showDivider||o||n?"none":""};return{top:u,bottom:i}},Be=a.forwardRef((e,t)=>{const{isLoading:n}=_(),{loadingIcon:r,...o}=e;return p.jsxs(a.InputGroup,{children:[p.jsx(a.Input,{...o,ref:t}),n&&p.jsx(a.InputRightElement,{children:r||p.jsx(a.Spinner,{})})]})}),Le=a.forwardRef((e,t)=>{const{autoCompleteProps:n,inputRef:r,getInputProps:o,tags:l,setQuery:u,value:i,itemList:y}=_(),{children:C,isInvalid:b,hidePlaceholder:d,...O}=e,{value:S}=O;f.useEffect(()=>{if(i!==void 0&&(typeof i=="string"||i instanceof String)){const te=y.find(Y=>Y.value===i),B=te===void 0?i:te.label;u(B)}},[i]),f.useEffect(()=>{S!==void 0&&(typeof S=="string"||S instanceof String)&&u(S)},[S]);const j=a.useMultiStyleConfig("Input",e);let{wrapper:U,input:z}=o(O,j);const{ref:q,...ae}=U,ee=a.useMergeRefs(t,r),V=h(C,{tags:l});d&&(z={...z,placeholder:Array.isArray(V)&&V.length?void 0:z.placeholder});const ce=p.jsx(Be,{isInvalid:b,...z,ref:ee}),fe=p.jsxs(a.Wrap,{"aria-invalid":b,...ae,ref:q,children:[V,p.jsx(a.WrapItem,{as:Be,...z,ref:ee})]});return p.jsx(a.PopoverAnchor,{children:n.multiple?fe:ce})});Le.displayName="Input";Le.id="Input";const It=e=>{const{getEmptyStateProps:t,defaultEmptyStateProps:n}=_(),r=t(p.jsx(a.Flex,{...jt,...n,children:"No options found!"}));return p.jsx(a.Box,{...e,children:r})},jt={fontSize:"sm",align:"center",justify:"center",fontWeight:"bold",fontStyle:"italic"},He=["AutoCompleteGroup","AutoCompleteItem","AutoCompleteCreatable"],Et=e=>{const t=f.Children.map(e,(o,l)=>{var u;if(((u=o==null?void 0:o.type)==null?void 0:u.displayName)==="AutoCompleteGroup"){const i=f.Children.toArray(e)[l+1];return f.cloneElement(o,{groupSibling:i?i.type.displayName==="AutoCompleteGroup":!1})}return o}),n=f.Children.toArray(t).filter(o=>{var l;return!He.includes((l=o==null?void 0:o.type)==null?void 0:l.displayName)});return[f.Children.toArray(t).filter(o=>{var l;return He.includes((l=o==null?void 0:o.type)==null?void 0:l.displayName)}),n]},nt=a.forwardRef((e,t)=>{const{children:n,loadingState:r,...o}=e,{listRef:l,isLoading:u}=_(),i=a.useMergeRefs(t,l),[y,C]=Et(n);return p.jsxs(a.PopoverContent,{ref:i,w:"inherit",...Ot,...o,children:[u&&p.jsx(a.Center,{children:r||p.jsx(a.Spinner,{size:"md"})}),!u&&p.jsxs(p.Fragment,{children:[y,p.jsx(It,{}),C]})]})});nt.displayName="AutoCompleteList";const Ot={py:"4",opacity:"0",bg:"#232934",rounded:"md",maxH:"350px",border:"none",shadow:"base",zIndex:"popover",overflowY:"auto",_light:{bg:"#ffffff"},_focus:{boxShadow:"none"}},Rt=f.memo(e=>{const{label:t,onRemove:n,disabled:r,...o}=e;return p.jsx(a.WrapItem,{children:p.jsxs(a.Tag,{borderRadius:"md",fontWeight:"normal",...r&&Ue,...o,children:[p.jsx(a.TagLabel,{children:t}),p.jsx(a.TagCloseButton,{onClick:()=>!r&&h(n),cursor:"pointer",...r&&Ue})]})})}),Ue={cursor:"text",userSelect:"none",opacity:.4,_focus:{boxShadow:"none"}};exports.AutoComplete=Xe;exports.AutoCompleteCreatable=qe;exports.AutoCompleteGroup=et;exports.AutoCompleteGroupTitle=tt;exports.AutoCompleteInput=Le;exports.AutoCompleteItem=Ze;exports.AutoCompleteList=nt;exports.AutoCompleteProvider=Qe;exports.AutoCompleteTag=Rt;exports.baseItemStyles=Fe;exports.createContext=$e;exports.useAutoComplete=Je;exports.useAutoCompleteContext=_;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react/jsx-runtime"),f=require("react"),a=require("@chakra-ui/react");function lt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const ie=lt(f),[Qe,_]=$e();function $e(){const e=ie.createContext(void 0);e.displayName="AutoCompleteContext";function t(){var o;const n=ie.useContext(e),r="useAutoCompleteContext: `context` is undefined. Seems you forgot to wrap all autoomplete components within `<AutoComplete />`";if(!n){const l=new Error(r);throw l.name="ContextError",(o=Error.captureStackTrace)==null||o.call(Error,l,t),l}return n}return[e.Provider,t,e]}function ut(e){return e==null?void 0:e[0]}function we(e){return e!=null&&e.length?e[e.length-1]:void 0}function Ke(e,t,n=1,r=!0){if(t===0)return-1;let o=e+n;return e===-1&&(o=n>0?0:t-1),r?o=(o%t+t)%t:o=Math.max(0,Math.min(o,t-1)),o}function it(e,t,n=!0){return Ke(e,t,-1,n)}function at(e,t,n=!0){const r=Ke(e,t.length,1,n);return t[r]}function ct(e,t,n=!0){const r=it(e,t.length,n);return t[r]}function je(e){return Array.isArray(e)}function ft(e){return je(e)&&e.length===0}function Ee(e){return e!==null&&typeof e=="object"&&!je(e)}function pt(e){return Ee(e)&&Object.keys(e).length===0}function Oe(e){return je(e)?ft(e):Ee(e)?pt(e):e==null||e===""}function ue(e){return typeof e>"u"}function Ve(e){return typeof e<"u"}function dt(e,t){const n={};return t.forEach(r=>{r in e&&(n[r]=e[r])}),n}function Re(e,t){const n={...e};return t.forEach(r=>{delete n[r]}),n}function gt(e){return typeof e=="function"}function h(e,...t){return gt(e)?e(...t):e}var ae=function(e,t){for(var n,r=ie.Children.toArray(e),o=0,l=r;o<l.length;o++){var u=l[o];if(t(u))return u;if(!((n=u.props)===null||n===void 0)&&n.children){var i=ae(u.props.children,t);if(i)return i}}},le=function(e,t){for(var n=0,r=t.length,o=e.length;n<r;n++,o++)e[o]=t[n];return e},Ye=function(e,t){for(var n,r=ie.Children.toArray(e),o=[],l=0,u=r;l<u.length;l++){var i=u[l];t(i)&&(o=le(le([],o),[i])),!((n=i.props)===null||n===void 0)&&n.children&&(o=le(le([],o),Ye(i.props.children,t)))}return o};function ze(e,t,n=2){function r(d,R){d=" ".repeat(R-1)+d.toLowerCase()+" ".repeat(R-1);let x=new Array(d.length-R+1);for(let E=0;E<x.length;E++)x[E]=d.slice(E,E+R);return x}if(!(e!=null&&e.length)||!(t!=null&&t.length))return 0;let o=e.length<t.length?e:t,l=e.length<t.length?t:e,u=r(o,n),i=r(l,n),y=new Set(u),C=i.length,b=0;for(let d of i)y.delete(d)&&b++;return b/C}const Fe=e=>{var t;return(t=typeof e=="string"||typeof e=="number"?e:e[Object.keys(e)[0]])==null?void 0:t.toString()},mt=(e,t)=>typeof e!="string"||Oe(t)?e:e.toString().replace(new RegExp(Ct(t),"gi"),r=>`<mark>${r}</mark>`),vt=e=>Ye(e,n=>{var r;return((r=n==null?void 0:n.type)==null?void 0:r.displayName)==="AutoCompleteItem"}).map(n=>{const r=dt(n.props,["value","label","fixed","disabled"]),{getValue:o=Fe}=n.props,l=o(r.value);return{...Ve(r.label)?r:{...r,label:l},value:l,originalValue:r.value}}),ht=()=>({bg:"whiteAlpha.100",_light:{bg:"gray.200"}}),yt=(e,t,n)=>(t==null?void 0:t.toLowerCase().indexOf(e==null?void 0:e.toLowerCase()))>=0||(n==null?void 0:n.toLowerCase().indexOf(e==null?void 0:e.toLowerCase()))>=0||ze(e,t)>=.5||ze(e,n)>=.5;function Ct(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}const bt=(e,t)=>ae(e,r=>{var o;return((o=r==null?void 0:r.type)==null?void 0:o.displayName)==="AutoCompleteItem"&&r.props.value===(t==null?void 0:t.value)}),xt=(e,t)=>ae(e,r=>{var o;return((o=r==null?void 0:r.type)==null?void 0:o.displayName)==="AutoCompleteItem"&&r.props.value===(t==null?void 0:t.value)}),St=(e,t)=>Ve(ae(e,n=>{var o,l;const r=h(((o=n.props)==null?void 0:o.getValue)||Fe,((l=n.props)==null?void 0:l.value)||{});return t.some(u=>u.value===r)})),At=(e,t)=>{const n={},r={},{field:o}=e;return o&&Object.keys(o).forEach(l=>{if(l.startsWith("--input")===!1)n[l]=o[l];else{let u=o[l];const y=l.replace("--input-","").replace(/-([a-z])/g,function(C){return C[1].toUpperCase()});u.indexOf(".")!==-1&&(u=u.substring(u.indexOf(".")+1)),r[y]=u}}),{...t&&{...n,...r,_focusWithin:e.field._focus,pos:"relative",minH:9,py:1.5,spacing:3},cursor:"text",h:"fit-content"}};function Je(e){var Ge;let{prefocusFirstItem:t=!0,closeOnBlur:n=!0,creatable:r,emphasize:o,emptyState:l=!0,defaultEmptyStateProps:u={},freeSolo:i,isReadOnly:y,listAllValuesOnFocus:C,maxSuggestions:b,multiple:d,closeOnSelect:R=!d,defaultValue:x,defaultValues:E=x?[x]:[],onReady:U,defaultIsOpen:z,disableFilter:q,isLoading:ce=!1,placement:ee="bottom",restoreOnBlurIfEmpty:V=!i,shouldRenderSuggestions:fe=()=>!0,submitKeys:pe=[],suggestWhenEmpty:te,value:B,values:Y=B?typeof B=="string"?[B]:[...B]:void 0}=e;i=i||(d?!0:e.freeSolo);const{isOpen:O,onClose:G,onOpen:Q}=a.useDisclosure({defaultIsOpen:z}),de=f.useMemo(()=>h(e.children,{isOpen:O,onClose:G,onOpen:Q}),[e.children,O]),I=f.useMemo(()=>vt(de),[de]),N=f.useRef(null),Pe=f.useRef(null),J=f.useRef(null),$=f.useRef(null),[De,ne]=f.useState(!1);let oe="";d?oe="":ue(E)?ue(Y)||(oe=Y[0]):oe=E[0];const[D,X]=f.useState(oe??""),ge=f.useMemo(()=>q?I:I.filter(s=>s.fixed||h(e.filter||yt,D,s.value,s.label)||De).filter((s,c)=>b?s.fixed||c<b:!0),[D,I,De,b,q]),re=r?[{value:D,noFilter:!0,creatable:!0}]:[],S=f.useMemo(()=>[...ge,...re],[ge,re]),ot=f.useMemo(()=>[...I,...re],[I,re]),[M,me]=a.useControllableState({defaultValue:E.map(s=>s==null?void 0:s.toString()),value:Y,onChange:s=>{const c=S.find(F=>F.value===s.at(-1));if(!c)return;const m=s.map(F=>ot.find(L=>L.value===F));h(e.onChange,d?s:s[0],d?m:c)}});f.useEffect(()=>{S.length===0&&!l&&O&&G()},[S.length,l,O]);const[K,W]=f.useState(t?(Ge=I[0])==null?void 0:Ge.value:null),rt=e.maxSelections||M.length+1,ve=S.findIndex(s=>s.value===K),he=at(ve,S,!!e.rollNavigation),ye=ct(ve,S,!!e.rollNavigation),P=ut(S),Ce=we(S),Me=!S.some(s=>s.value===K);f.useEffect(()=>{var s;Me&&W(t?(s=I[0])==null?void 0:s.value:null)},[Me]),a.useUpdateEffect(()=>{t&&W(P==null?void 0:P.value)},[D,P==null?void 0:P.value]),f.useEffect(()=>{var s;!O&&t&&W((s=I[0])==null?void 0:s.value)},[O]),f.useEffect(()=>{O&&C&&ne(!0)},[O,C,ne]),f.useEffect(()=>{const s=I.find(c=>c.value===K);h(e.onOptionFocus,{item:s,focusMethod:$.current,isNewInput:s==null?void 0:s.creatable})},[K,e.onOptionFocus]);const be=s=>{var F,L;const c=S.find(w=>w.value===s),m=(c==null?void 0:c.label)||(c==null?void 0:c.value);X(()=>d?"":m??""),!M.includes(s)&&M.length<rt&&me(w=>d?[...w,s]:[s]),d&&((F=N.current)==null||F.focus()),e.focusInputOnSelect&&((L=N.current)==null||L.focus()),h(e.onSelectOption,{item:c,selectMethod:$.current,isNewInput:c==null?void 0:c.creatable}),c!=null&&c.creatable&&h(e.onCreateOption,{item:Re(c,["noFilter"]),selectMethod:$.current}),R&&G()},Te=(s,c)=>{var L;me(w=>{let k=I.find(T=>T.value===s);return!k&&r===!0&&(k={label:s,value:s}),k?(h(e.onTagRemoved,s,k,w),w.filter(T=>T!==s)):w});const m=I.find(w=>w.value===s),F=(m==null?void 0:m.label)||(m==null?void 0:m.value);D===F&&X(""),c&&((L=N.current)==null||L.focus())},st=s=>{var c;me([]),s&&((c=N.current)==null||c.focus())},_e=d?M.map(s=>{var c;return{label:((c=I.find(m=>m.value===(s==null?void 0:s.toString())))==null?void 0:c.label)||s,onRemove:()=>Te(s)}}):[];return f.useEffect(()=>{h(U,{tags:_e})},[M]),{autoCompleteProps:e,children:de,filteredList:S,filteredResults:ge,focusedValue:K,defaultEmptyStateProps:u,getEmptyStateProps:s=>{if(S.every(m=>m.noFilter)&&l&&!r)return typeof l=="boolean"?s:h(l,{query:D})},getGroupProps:s=>{const c=St(s.children,S);return{divider:{hasFirstChild:bt(s.children,P),hasLastChild:xt(s.children,we(S.filter(m=>ue(m==null?void 0:m.noFilter))))},group:{display:c?"initial":"none"}}},getInputProps:(s,c)=>{const{onBlur:m,onChange:F,onFocus:L,onKeyDown:w,variant:k,...T}=s;return{wrapper:{ref:Pe,onClick:()=>{var g;(g=N==null?void 0:N.current)==null||g.focus()},...At(c,d),...T},input:{isReadOnly:y,onFocus:g=>{h(L,g),e.openOnFocus&&!y&&Q(),e.selectOnFocus&&g.target.select(),C&&ne(!0)},onBlur:g=>{var H,se;h(m,g);const A=g.relatedTarget===(J==null?void 0:J.current)||((H=J.current)==null?void 0:H.contains(g.relatedTarget)),v=(se=Pe.current)==null?void 0:se.contains(g.relatedTarget);if(!A&&!v&&(n&&G(),!M.includes(g.target.value)&&V)){const xe=we(M),j=I.find(Ae=>Ae.value===xe),Se=(j==null?void 0:j.label)||(j==null?void 0:j.value)||"";X(Se)}},onChange:g=>{const A=g.target.value;h(F,g),X(A);const v=Oe(A);h(fe,A)&&(!v||te)?Q():G(),ne(!1)},onKeyDown:g=>{var H;h(w,g),$.current="keyboard";const{key:A}=g,v=S[ve];if(["Enter",...pe].includes(A)){v&&!(v!=null&&v.disabled)&&O?be(v==null?void 0:v.value):(H=N.current)==null||H.focus(),g.preventDefault();return}if(A==="ArrowDown"){O?W(he==null?void 0:he.value):Q(),g.preventDefault();return}if(A==="ArrowUp"){O?W(ye==null?void 0:ye.value):Q(),g.preventDefault();return}if(A==="Tab"){O&&v&&!(v!=null&&v.disabled)?be(v==null?void 0:v.value):G();return}if(A==="Home"){W(P==null?void 0:P.value),g.preventDefault();return}if(A==="End"){W(Ce==null?void 0:Ce.value),g.preventDefault();return}A==="Escape"&&(G(),g.preventDefault())},value:D,variant:d?"unstyled":k,...T}}},getItemProps:(s,c)=>{var We;const{_fixed:m,_focus:F,children:L,disabled:w,label:k,value:T,fixed:g,getValue:A=Fe,onClick:v,onMouseOver:H,sx:se,...xe}=s,j=c?T:(We=A(T))==null?void 0:We.toString(),Se=j===K,Ae=S.findIndex(Z=>Z.value===j)>=0,Ie=L||k||j;return{item:{...typeof Ie!="string"||!o?{children:Ie}:{dangerouslySetInnerHTML:{__html:mt(Ie,D)}},"aria-selected":M.includes(j),"aria-disabled":w,_disabled:{opacity:.4,cursor:"not-allowed",userSelect:"none"},onClick:Z=>{var ke;h(v,Z),w?(ke=N.current)==null||ke.focus():be(j)},onMouseOver:Z=>{h(H,Z),W(j),$.current="mouse"},sx:{...se,mark:{color:"inherit",bg:"transparent",...Ee(o)?o:{fontWeight:o?"extrabold":"inherit"}}},...Se&&(F||ht()),...g&&m,...xe},root:{isValidSuggestion:Ae,value:j}}},inputRef:N,interactionRef:$,isLoading:ce,isOpen:O,itemList:I,listRef:J,onClose:G,onOpen:Q,placement:ee,query:D,removeItem:Te,resetItems:st,setQuery:X,tags:_e,value:B,values:M}}const Xe=a.forwardRef((e,t)=>{const n=Je(e),{children:r,isOpen:o,onClose:l,onOpen:u,placement:i,resetItems:y,removeItem:C}=n;f.useImperativeHandle(t,()=>({resetItems:y,removeItem:C}));const{matchWidth:b=!0}=n.autoCompleteProps;return p.jsx(Qe,{value:n,children:p.jsx(a.Popover,{isLazy:!0,isOpen:o,autoFocus:!1,placement:i,closeOnBlur:!0,matchWidth:b,children:p.jsx(a.chakra.div,{w:"full",ref:t,children:r})})})});Xe.displayName="AutoComplete";const Ze=a.forwardRef((e,t)=>{const{focusedValue:n,getItemProps:r,interactionRef:o}=_(),l=f.useRef(),u=a.useMergeRefs(t,l),i=r(e),{isValidSuggestion:y,value:C}=i.root,b=n===C;f.useEffect(()=>{var U;b&&o.current==="keyboard"&&((U=l==null?void 0:l.current)==null||U.scrollIntoView({behavior:"smooth",block:"nearest"}))},[b,o]),f.useEffect(()=>{typeof C!="string"&&console.warn("wow"),typeof C!="string"&&ue(e.getValue)&&console.error("You must define the `getValue` prop, when an Item's value is not a string")},[]);const{children:d,dangerouslySetInnerHTML:R,...x}=i.item,E=Re(x,["groupId"]);return y?p.jsx(a.Flex,{ref:u,...Le,...E,children:d||p.jsx("span",{dangerouslySetInnerHTML:R})}):null});Ze.displayName="AutoCompleteItem";const Le={mx:"2",px:"2",py:"2",rounded:"md",cursor:"pointer"};function qe(e){const{alwaysDisplay:t,children:n,...r}=e,{autoCompleteProps:o,getItemProps:l,query:u,filteredResults:i}=_(),{children:y,...C}=l({...e,value:u,children:h(n,{value:u})},!0).item,b=i.some(x=>x.value===u),d=Oe(u)?t:!0;return o.creatable&&d&&!b?p.jsx(a.Flex,{...Le,...C,...r,children:y||`Add ${u}`}):null}qe.displayName="AutoCompleteCreatable";const et=a.forwardRef((e,t)=>{const{children:n,showDivider:r,...o}=e,l=Re(o,["groupSibling"]),{getGroupProps:u}=_(),{group:i}=u(e),y=wt(e);return p.jsxs(a.Box,{ref:t,...i,...l,children:[p.jsx(a.Divider,{...y.top}),n,p.jsx(a.Divider,{...y.bottom})]})}),tt=a.forwardRef((e,t)=>p.jsx(a.Flex,{...It,...e,ref:t}));et.displayName="AutoCompleteGroup";tt.displayName="AutoCompleteGroupTitle";const It={ml:5,my:1,fontSize:"xs",letterSpacing:"wider",fontWeight:"extrabold",textTransform:"uppercase"},wt=e=>{const{getGroupProps:t}=_(),n=e.groupSibling,{divider:{hasFirstChild:r,hasLastChild:o}}=t(e),l={my:2,borderColor:e.dividerColor},u={...l,mb:4,display:!e.showDivider||r?"none":""},i={...l,display:!e.showDivider||o||n?"none":""};return{top:u,bottom:i}},Be=a.forwardRef((e,t)=>{const{isLoading:n}=_(),{loadingIcon:r,...o}=e;return p.jsxs(a.InputGroup,{children:[p.jsx(a.Input,{...o,ref:t}),n&&p.jsx(a.InputRightElement,{children:r||p.jsx(a.Spinner,{})})]})}),Ne=a.forwardRef((e,t)=>{const{autoCompleteProps:n,inputRef:r,getInputProps:o,tags:l,setQuery:u,value:i,itemList:y}=_(),{children:C,isInvalid:b,hidePlaceholder:d,...R}=e,{value:x}=R;f.useEffect(()=>{if(i!==void 0&&(typeof i=="string"||i instanceof String)){const te=y.find(Y=>Y.value===i),B=te===void 0?i:te.label;u(B)}},[i]),f.useEffect(()=>{x!==void 0&&(typeof x=="string"||x instanceof String)&&u(x)},[x]);const E=a.useMultiStyleConfig("Input",e);let{wrapper:U,input:z}=o(R,E);const{ref:q,...ce}=U,ee=a.useMergeRefs(t,r),V=h(C,{tags:l});d&&(z={...z,placeholder:Array.isArray(V)&&V.length?void 0:z.placeholder});const fe=p.jsx(Be,{isInvalid:b,...z,ref:ee}),pe=p.jsxs(a.Wrap,{"aria-invalid":b,...ce,ref:q,children:[V,p.jsx(a.WrapItem,{as:Be,...z,ref:ee})]});return p.jsx(a.PopoverAnchor,{children:n.multiple?pe:fe})});Ne.displayName="Input";Ne.id="Input";const jt=e=>{const{getEmptyStateProps:t,defaultEmptyStateProps:n}=_(),r=t(p.jsx(a.Flex,{...Et,...n,children:"No options found!"}));return p.jsx(a.Box,{...e,children:r})},Et={fontSize:"sm",align:"center",justify:"center",fontWeight:"bold",fontStyle:"italic"},He=["AutoCompleteGroup","AutoCompleteItem","AutoCompleteCreatable"],Ot=e=>{const t=f.Children.map(e,(o,l)=>{var u;if(((u=o==null?void 0:o.type)==null?void 0:u.displayName)==="AutoCompleteGroup"){const i=f.Children.toArray(e)[l+1];return f.cloneElement(o,{groupSibling:i?i.type.displayName==="AutoCompleteGroup":!1})}return o}),n=f.Children.toArray(t).filter(o=>{var l;return!He.includes((l=o==null?void 0:o.type)==null?void 0:l.displayName)});return[f.Children.toArray(t).filter(o=>{var l;return He.includes((l=o==null?void 0:o.type)==null?void 0:l.displayName)}),n]},nt=a.forwardRef((e,t)=>{const{children:n,loadingState:r,...o}=e,{listRef:l,isLoading:u}=_(),i=a.useMergeRefs(t,l),[y,C]=Ot(n);return p.jsxs(a.PopoverContent,{ref:i,w:"inherit",...Rt,...o,children:[u&&p.jsx(a.Center,{children:r||p.jsx(a.Spinner,{size:"md"})}),!u&&p.jsxs(p.Fragment,{children:[y,p.jsx(jt,{}),C]})]})});nt.displayName="AutoCompleteList";const Rt={py:"4",opacity:"0",bg:"#232934",rounded:"md",maxH:"350px",border:"none",shadow:"base",zIndex:"popover",overflowY:"auto",_light:{bg:"#ffffff"},_focus:{boxShadow:"none"}},Ft=f.memo(e=>{const{label:t,onRemove:n,disabled:r,...o}=e;return p.jsx(a.WrapItem,{children:p.jsxs(a.Tag,{borderRadius:"md",fontWeight:"normal",...r&&Ue,...o,children:[p.jsx(a.TagLabel,{children:t}),p.jsx(a.TagCloseButton,{onClick:()=>!r&&h(n),cursor:"pointer",...r&&Ue})]})})}),Ue={cursor:"text",userSelect:"none",opacity:.4,_focus:{boxShadow:"none"}};exports.AutoComplete=Xe;exports.AutoCompleteCreatable=qe;exports.AutoCompleteGroup=et;exports.AutoCompleteGroupTitle=tt;exports.AutoCompleteInput=Ne;exports.AutoCompleteItem=Ze;exports.AutoCompleteList=nt;exports.AutoCompleteProvider=Qe;exports.AutoCompleteTag=Ft;exports.baseItemStyles=Le;exports.createContext=$e;exports.useAutoComplete=Je;exports.useAutoCompleteContext=_;
@@ -1 +1 @@
1
- {"version":3,"file":"use-autocomplete.d.ts","sourceRoot":"","sources":["../src/use-autocomplete.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAUnD,OAAO,EAAQ,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEtD;;;;GAIG;AAEH,wBAAgB,eAAe,CAC7B,iBAAiB,EAAE,iBAAiB,GACnC,qBAAqB,CA+dvB"}
1
+ {"version":3,"file":"use-autocomplete.d.ts","sourceRoot":"","sources":["../src/use-autocomplete.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAUnD,OAAO,EAAQ,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEtD;;;;GAIG;AAEH,wBAAgB,eAAe,CAC7B,iBAAiB,EAAE,iBAAiB,GACnC,qBAAqB,CAoevB"}
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.8.2",
2
+ "version": "5.8.4",
3
3
  "license": "MIT",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",