@choc-ui/chakra-autocomplete 5.8.1 → 5.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,8 +1,8 @@
1
- import { jsx as p, jsxs as K, Fragment as it } from "react/jsx-runtime";
1
+ import { jsx as p, jsxs as V, Fragment as it } from "react/jsx-runtime";
2
2
  import * as fe from "react";
3
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 B, Popover as dt, chakra as gt, useMergeRefs as Pe, Flex as pe, Box as Xe, Divider as Qe, 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, W] = Et();
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
6
  function Et() {
7
7
  const e = fe.createContext(void 0);
8
8
  e.displayName = "AutoCompleteContext";
@@ -100,7 +100,7 @@ var de = function(e, t) {
100
100
  }
101
101
  return o;
102
102
  };
103
- function $e(e, t, n = 2) {
103
+ function Ke(e, t, n = 2) {
104
104
  function r(c, O) {
105
105
  c = " ".repeat(O - 1) + c.toLowerCase() + " ".repeat(O - 1);
106
106
  let C = new Array(c.length - O + 1);
@@ -135,7 +135,7 @@ const _e = (e) => {
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 || $e(e, t) >= 0.5 || $e(e, n) >= 0.5;
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
139
  function kt(e) {
140
140
  return e.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
141
141
  }
@@ -188,7 +188,7 @@ const zt = (e, t) => de(
188
188
  // w: "full",
189
189
  };
190
190
  };
191
- function Vt(e) {
191
+ function Qt(e) {
192
192
  var He;
193
193
  let {
194
194
  prefocusFirstItem: t = !0,
@@ -205,8 +205,8 @@ function Vt(e) {
205
205
  closeOnSelect: O = !c,
206
206
  defaultValue: C,
207
207
  defaultValues: I = C ? [C] : [],
208
- onReady: H,
209
- defaultIsOpen: j,
208
+ onReady: U,
209
+ defaultIsOpen: k,
210
210
  disableFilter: ne,
211
211
  isLoading: ge = !1,
212
212
  placement: oe = "bottom",
@@ -214,18 +214,18 @@ function Vt(e) {
214
214
  shouldRenderSuggestions: me = () => !0,
215
215
  submitKeys: ve = [],
216
216
  suggestWhenEmpty: re,
217
- value: k,
218
- values: J = k ? typeof k == "string" ? [k] : [...k] : void 0
217
+ value: z,
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: U } = ct({ defaultIsOpen: j }), he = ue(
221
+ const { isOpen: w, onClose: _, onOpen: Q } = ct({ defaultIsOpen: k }), he = ue(
222
222
  () => m(e.children, {
223
223
  isOpen: w,
224
224
  onClose: _,
225
- onOpen: U
225
+ onOpen: Q
226
226
  }),
227
227
  [e.children, w]
228
- ), E = ue(() => Gt(he), [he]), N = te(null), Ge = te(null), X = te(null), V = te(null), [We, se] = Le(!1);
228
+ ), E = ue(() => Gt(he), [he]), N = te(null), Ge = te(null), X = te(null), $ = te(null), [We, se] = Le(!1);
229
229
  let le = "";
230
230
  c ? le = "" : ce(I) ? ce(J) || (le = J[0]) : le = I[0];
231
231
  const [R, Z] = Le(le ?? ""), ye = ue(
@@ -259,9 +259,9 @@ function Vt(e) {
259
259
  D(() => {
260
260
  y.length === 0 && !l && w && _();
261
261
  }, [y.length, l, w]);
262
- const [Q, G] = Le(
262
+ const [K, G] = Le(
263
263
  t ? (He = E[0]) == null ? void 0 : He.value : null
264
- ), st = e.maxSelections || T.length + 1, Ce = y.findIndex((s) => s.value === Q), Se = Nt(
264
+ ), st = e.maxSelections || T.length + 1, Ce = y.findIndex((s) => s.value === K), Se = Nt(
265
265
  Ce,
266
266
  y,
267
267
  !!e.rollNavigation
@@ -270,7 +270,7 @@ function Vt(e) {
270
270
  y,
271
271
  !!e.rollNavigation
272
272
  ), P = Ft(y), Ae = Ne(y), ke = !y.some(
273
- (s) => s.value === Q
273
+ (s) => s.value === K
274
274
  );
275
275
  D(() => {
276
276
  var s;
@@ -283,29 +283,29 @@ function Vt(e) {
283
283
  }, [w]), D(() => {
284
284
  w && h && se(!0);
285
285
  }, [w, h, se]), D(() => {
286
- const s = E.find((a) => a.value === Q);
286
+ const s = E.find((a) => a.value === K);
287
287
  m(e.onOptionFocus, {
288
288
  item: s,
289
- focusMethod: V.current,
289
+ focusMethod: $.current,
290
290
  isNewInput: s == null ? void 0 : s.creatable
291
291
  });
292
- }, [Q, e.onOptionFocus]);
292
+ }, [K, e.onOptionFocus]);
293
293
  const Ie = (s) => {
294
294
  var F, L;
295
295
  const a = y.find((x) => x.value === s), d = (a == null ? void 0 : a.label) || (a == null ? void 0 : a.value);
296
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, {
297
297
  item: a,
298
- selectMethod: V.current,
298
+ selectMethod: $.current,
299
299
  isNewInput: a == null ? void 0 : a.creatable
300
300
  }), a != null && a.creatable && m(e.onCreateOption, {
301
301
  item: Me(a, ["noFilter"]),
302
- selectMethod: V.current
302
+ selectMethod: $.current
303
303
  }), O && _();
304
304
  }, ze = (s, a) => {
305
305
  var L;
306
306
  be((x) => {
307
- const $ = E.find((M) => M.value === s);
308
- return $ ? (m(e.onTagRemoved, s, $, x), x.filter((M) => M !== s)) : 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;
309
309
  });
310
310
  const d = E.find((x) => x.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());
@@ -320,13 +320,13 @@ function Vt(e) {
320
320
  };
321
321
  }) : [];
322
322
  return D(() => {
323
- m(H, { tags: Be });
323
+ m(U, { tags: Be });
324
324
  }, [T]), {
325
325
  autoCompleteProps: e,
326
326
  children: he,
327
327
  filteredList: y,
328
328
  filteredResults: ye,
329
- focusedValue: Q,
329
+ focusedValue: K,
330
330
  defaultEmptyStateProps: i,
331
331
  getEmptyStateProps: (s) => {
332
332
  if (y.every((d) => d.noFilter) && l && !r)
@@ -348,7 +348,7 @@ function Vt(e) {
348
348
  };
349
349
  },
350
350
  getInputProps: (s, a) => {
351
- const { onBlur: d, onChange: F, onFocus: L, onKeyDown: x, variant: $, ...M } = s;
351
+ const { onBlur: d, onChange: F, onFocus: L, onKeyDown: x, variant: W, ...M } = s;
352
352
  return {
353
353
  wrapper: {
354
354
  ref: Ge,
@@ -362,12 +362,12 @@ function Vt(e) {
362
362
  input: {
363
363
  isReadOnly: v,
364
364
  onFocus: (f) => {
365
- m(L, f), e.openOnFocus && !v && U(), e.selectOnFocus && f.target.select(), h && se(!0);
365
+ m(L, f), e.openOnFocus && !v && Q(), e.selectOnFocus && f.target.select(), h && se(!0);
366
366
  },
367
367
  onBlur: (f) => {
368
- var z, ie;
368
+ var B, ie;
369
369
  m(d, f);
370
- const S = f.relatedTarget === (X == null ? void 0 : X.current) || ((z = X.current) == null ? void 0 : z.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 = (ie = Ge.current) == null ? void 0 : ie.contains(
371
371
  f.relatedTarget
372
372
  );
373
373
  if (!S && !g && (n && _(), !T.includes(f.target.value) && Y)) {
@@ -381,22 +381,22 @@ function Vt(e) {
381
381
  const S = f.target.value;
382
382
  m(F, f), Z(S);
383
383
  const g = Te(S);
384
- m(me, S) && (!g || re) ? U() : _(), se(!1);
384
+ m(me, S) && (!g || re) ? Q() : _(), se(!1);
385
385
  },
386
386
  onKeyDown: (f) => {
387
- var z;
388
- m(x, f), V.current = "keyboard";
387
+ var B;
388
+ m(x, f), $.current = "keyboard";
389
389
  const { key: S } = f, g = y[Ce];
390
390
  if (["Enter", ...ve].includes(S)) {
391
- g && !(g != null && g.disabled) && w ? Ie(g == null ? void 0 : g.value) : (z = N.current) == null || z.focus(), f.preventDefault();
391
+ g && !(g != null && g.disabled) && w ? Ie(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) : U(), f.preventDefault();
395
+ w ? G(Se == null ? void 0 : Se.value) : Q(), f.preventDefault();
396
396
  return;
397
397
  }
398
398
  if (S === "ArrowUp") {
399
- w ? G(xe == null ? void 0 : xe.value) : U(), f.preventDefault();
399
+ w ? G(xe == null ? void 0 : xe.value) : Q(), f.preventDefault();
400
400
  return;
401
401
  }
402
402
  if (S === "Tab") {
@@ -414,7 +414,7 @@ function Vt(e) {
414
414
  S === "Escape" && (_(), f.preventDefault());
415
415
  },
416
416
  value: R,
417
- variant: c ? "unstyled" : $,
417
+ variant: c ? "unstyled" : W,
418
418
  ...M
419
419
  }
420
420
  };
@@ -426,15 +426,15 @@ function Vt(e) {
426
426
  _focus: F,
427
427
  children: L,
428
428
  disabled: x,
429
- label: $,
429
+ label: W,
430
430
  value: M,
431
431
  fixed: f,
432
432
  getValue: S = _e,
433
433
  onClick: g,
434
- onMouseOver: z,
434
+ onMouseOver: B,
435
435
  sx: ie,
436
436
  ...we
437
- } = s, A = a ? M : (Ue = S(M)) == null ? void 0 : Ue.toString(), Oe = A === Q, Ee = y.findIndex((q) => q.value === A) >= 0, Fe = L || $ || A;
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;
438
438
  return {
439
439
  item: {
440
440
  ...typeof Fe != "string" || !o ? { children: Fe } : {
@@ -446,11 +446,11 @@ function Vt(e) {
446
446
  "aria-disabled": x,
447
447
  _disabled: { opacity: 0.4, cursor: "not-allowed", userSelect: "none" },
448
448
  onClick: (q) => {
449
- var Ve;
450
- m(g, q), x ? (Ve = N.current) == null || Ve.focus() : Ie(A);
449
+ var Qe;
450
+ m(g, q), x ? (Qe = N.current) == null || Qe.focus() : Ie(A);
451
451
  },
452
452
  onMouseOver: (q) => {
453
- m(z, q), G(A), V.current = "mouse";
453
+ m(B, q), G(A), $.current = "mouse";
454
454
  },
455
455
  sx: {
456
456
  ...ie,
@@ -473,26 +473,26 @@ function Vt(e) {
473
473
  };
474
474
  },
475
475
  inputRef: N,
476
- interactionRef: V,
476
+ interactionRef: $,
477
477
  isLoading: ge,
478
478
  isOpen: w,
479
479
  itemList: E,
480
480
  listRef: X,
481
481
  onClose: _,
482
- onOpen: U,
482
+ onOpen: Q,
483
483
  placement: oe,
484
484
  query: R,
485
485
  removeItem: ze,
486
486
  resetItems: lt,
487
487
  setQuery: Z,
488
488
  tags: Be,
489
- value: k,
489
+ value: z,
490
490
  values: T
491
491
  };
492
492
  }
493
- const Qt = B(
493
+ const $t = H(
494
494
  (e, t) => {
495
- const n = Vt(e), {
495
+ const n = Qt(e), {
496
496
  children: r,
497
497
  isOpen: o,
498
498
  onClose: l,
@@ -520,17 +520,17 @@ const Qt = B(
520
520
  ) });
521
521
  }
522
522
  );
523
- Qt.displayName = "AutoComplete";
524
- const $t = B(
523
+ $t.displayName = "AutoComplete";
524
+ const Kt = H(
525
525
  (e, t) => {
526
526
  const {
527
527
  focusedValue: n,
528
528
  getItemProps: r,
529
529
  interactionRef: o
530
- } = W(), l = te(), i = Pe(t, l), u = r(e), { isValidSuggestion: v, value: h } = u.root, b = n === h;
530
+ } = j(), l = te(), i = Pe(t, l), u = r(e), { isValidSuggestion: v, value: h } = u.root, b = n === h;
531
531
  D(() => {
532
- var H;
533
- b && o.current === "keyboard" && ((H = l == null ? void 0 : l.current) == null || H.scrollIntoView({
532
+ var U;
533
+ b && o.current === "keyboard" && ((U = l == null ? void 0 : l.current) == null || U.scrollIntoView({
534
534
  behavior: "smooth",
535
535
  block: "nearest"
536
536
  }));
@@ -543,7 +543,7 @@ const $t = B(
543
543
  return v ? /* @__PURE__ */ p(pe, { ref: i, ...ot, ...I, children: c || /* @__PURE__ */ p("span", { dangerouslySetInnerHTML: O }) }) : null;
544
544
  }
545
545
  );
546
- $t.displayName = "AutoCompleteItem";
546
+ Kt.displayName = "AutoCompleteItem";
547
547
  const ot = {
548
548
  mx: "2",
549
549
  px: "2",
@@ -551,13 +551,13 @@ const ot = {
551
551
  rounded: "md",
552
552
  cursor: "pointer"
553
553
  };
554
- function Kt(e) {
554
+ function Vt(e) {
555
555
  const { alwaysDisplay: t, children: n, ...r } = e, {
556
556
  autoCompleteProps: o,
557
557
  getItemProps: l,
558
558
  query: i,
559
559
  filteredResults: u
560
- } = W(), { children: v, ...h } = l(
560
+ } = j(), { children: v, ...h } = l(
561
561
  {
562
562
  ...e,
563
563
  value: i,
@@ -569,17 +569,17 @@ function Kt(e) {
569
569
  ).item, b = u.some((C) => C.value === i), c = Te(i) ? t : !0;
570
570
  return o.creatable && c && !b ? /* @__PURE__ */ p(pe, { ...ot, ...h, ...r, children: v || `Add ${i}` }) : null;
571
571
  }
572
- Kt.displayName = "AutoCompleteCreatable";
573
- const Yt = B(
572
+ Vt.displayName = "AutoCompleteCreatable";
573
+ const Yt = H(
574
574
  (e, t) => {
575
- const { children: n, showDivider: r, ...o } = e, l = Me(o, ["groupSibling"]), { getGroupProps: i } = W(), { group: u } = i(e), v = Zt(e);
576
- return /* @__PURE__ */ K(Xe, { ref: t, ...u, ...l, children: [
577
- /* @__PURE__ */ p(Qe, { ...v.top }),
575
+ const { children: n, showDivider: r, ...o } = e, l = Me(o, ["groupSibling"]), { getGroupProps: i } = j(), { group: u } = i(e), v = Zt(e);
576
+ return /* @__PURE__ */ V(Xe, { ref: t, ...u, ...l, children: [
577
+ /* @__PURE__ */ p($e, { ...v.top }),
578
578
  n,
579
- /* @__PURE__ */ p(Qe, { ...v.bottom })
579
+ /* @__PURE__ */ p($e, { ...v.bottom })
580
580
  ] });
581
581
  }
582
- ), Jt = B(
582
+ ), Jt = H(
583
583
  (e, t) => /* @__PURE__ */ p(pe, { ...Xt, ...e, ref: t })
584
584
  );
585
585
  Yt.displayName = "AutoCompleteGroup";
@@ -592,7 +592,7 @@ const Xt = {
592
592
  fontWeight: "extrabold",
593
593
  textTransform: "uppercase"
594
594
  }, Zt = (e) => {
595
- const { getGroupProps: t } = W(), n = e.groupSibling, {
595
+ const { getGroupProps: t } = j(), n = e.groupSibling, {
596
596
  divider: { hasFirstChild: r, hasLastChild: o }
597
597
  } = t(e), l = {
598
598
  my: 2,
@@ -606,13 +606,13 @@ const Xt = {
606
606
  display: !e.showDivider || o || n ? "none" : ""
607
607
  };
608
608
  return { top: i, bottom: u };
609
- }, Ke = B((e, t) => {
610
- const { isLoading: n } = W(), { loadingIcon: r, ...o } = e;
611
- return /* @__PURE__ */ K(mt, { children: [
609
+ }, Ve = H((e, t) => {
610
+ const { isLoading: n } = j(), { loadingIcon: r, ...o } = e;
611
+ return /* @__PURE__ */ V(mt, { children: [
612
612
  /* @__PURE__ */ p(vt, { ...o, ref: t }),
613
613
  n && /* @__PURE__ */ p(ht, { children: r || /* @__PURE__ */ p(Ze, {}) })
614
614
  ] });
615
- }), rt = B(
615
+ }), rt = H(
616
616
  (e, t) => {
617
617
  const {
618
618
  autoCompleteProps: n,
@@ -622,7 +622,7 @@ const Xt = {
622
622
  setQuery: i,
623
623
  value: u,
624
624
  itemList: v
625
- } = W(), {
625
+ } = j(), {
626
626
  children: h,
627
627
  isInvalid: b,
628
628
  hidePlaceholder: c,
@@ -630,33 +630,33 @@ const Xt = {
630
630
  } = e, { value: C } = O;
631
631
  D(() => {
632
632
  if (u !== void 0 && (typeof u == "string" || u instanceof String)) {
633
- const re = v.find((J) => J.value === u), k = re === void 0 ? u : re.label;
634
- i(k);
633
+ const re = v.find((J) => J.value === u), z = re === void 0 ? u : re.label;
634
+ i(z);
635
635
  }
636
636
  }, [u]), D(() => {
637
637
  C !== void 0 && (typeof C == "string" || C instanceof String) && i(C);
638
638
  }, [C]);
639
639
  const I = yt("Input", e);
640
- let { wrapper: H, input: j } = o(O, I);
641
- const { ref: ne, ...ge } = H, oe = Pe(t, r), Y = m(h, { tags: l });
642
- c && (j = {
643
- ...j,
644
- placeholder: Array.isArray(Y) && Y.length ? void 0 : j.placeholder
640
+ let { wrapper: U, input: k } = o(O, I);
641
+ const { ref: ne, ...ge } = U, oe = Pe(t, r), Y = m(h, { tags: l });
642
+ c && (k = {
643
+ ...k,
644
+ placeholder: Array.isArray(Y) && Y.length ? void 0 : k.placeholder
645
645
  });
646
646
  const me = /* @__PURE__ */ p(
647
- Ke,
647
+ Ve,
648
648
  {
649
649
  isInvalid: b,
650
- ...j,
650
+ ...k,
651
651
  ref: oe
652
652
  }
653
- ), ve = /* @__PURE__ */ K(bt, { "aria-invalid": b, ...ge, ref: ne, children: [
653
+ ), ve = /* @__PURE__ */ V(bt, { "aria-invalid": b, ...ge, ref: ne, children: [
654
654
  Y,
655
655
  /* @__PURE__ */ p(
656
656
  qe,
657
657
  {
658
- as: Ke,
659
- ...j,
658
+ as: Ve,
659
+ ...k,
660
660
  ref: oe
661
661
  }
662
662
  )
@@ -667,7 +667,7 @@ const Xt = {
667
667
  rt.displayName = "Input";
668
668
  rt.id = "Input";
669
669
  const qt = (e) => {
670
- const { getEmptyStateProps: t, defaultEmptyStateProps: n } = W(), r = t(
670
+ const { getEmptyStateProps: t, defaultEmptyStateProps: n } = j(), r = t(
671
671
  /* @__PURE__ */ p(pe, { ...en, ...n, children: "No options found!" })
672
672
  );
673
673
  return /* @__PURE__ */ p(Xe, { ...e, children: r });
@@ -707,12 +707,12 @@ const qt = (e) => {
707
707
  );
708
708
  }
709
709
  ), n];
710
- }, nn = B(
710
+ }, nn = H(
711
711
  (e, t) => {
712
- const { children: n, loadingState: r, ...o } = e, { listRef: l, isLoading: i } = W(), u = Pe(t, l), [v, h] = tn(n);
713
- return /* @__PURE__ */ K(St, { ref: u, w: "inherit", ...on, ...o, children: [
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
714
  i && /* @__PURE__ */ p(xt, { children: r || /* @__PURE__ */ p(Ze, { size: "md" }) }),
715
- !i && /* @__PURE__ */ K(it, { children: [
715
+ !i && /* @__PURE__ */ V(it, { children: [
716
716
  v,
717
717
  /* @__PURE__ */ p(qt, {}),
718
718
  h
@@ -739,7 +739,7 @@ const on = {
739
739
  }
740
740
  }, pn = at((e) => {
741
741
  const { label: t, onRemove: n, disabled: r, ...o } = e;
742
- return /* @__PURE__ */ p(qe, { children: /* @__PURE__ */ K(
742
+ return /* @__PURE__ */ p(qe, { children: /* @__PURE__ */ V(
743
743
  At,
744
744
  {
745
745
  borderRadius: "md",
@@ -766,17 +766,17 @@ const on = {
766
766
  _focus: { boxShadow: "none" }
767
767
  };
768
768
  export {
769
- Qt as AutoComplete,
770
- Kt as AutoCompleteCreatable,
769
+ $t as AutoComplete,
770
+ Vt as AutoCompleteCreatable,
771
771
  Yt as AutoCompleteGroup,
772
772
  Jt as AutoCompleteGroupTitle,
773
773
  rt as AutoCompleteInput,
774
- $t as AutoCompleteItem,
774
+ Kt as AutoCompleteItem,
775
775
  nn as AutoCompleteList,
776
776
  Ot as AutoCompleteProvider,
777
777
  pn as AutoCompleteTag,
778
778
  ot as baseItemStyles,
779
779
  Et as createContext,
780
- Vt as useAutoComplete,
781
- W as useAutoCompleteContext
780
+ Qt as useAutoComplete,
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 le=st(f),[Ve,_]=Qe();function Qe(){const e=le.createContext(void 0);e.displayName="AutoCompleteContext";function t(){var o;const n=le.useContext(e),r="useAutoCompleteContext: `context` is undefined. Seems you forgot to wrap all autoomplete components within `<AutoComplete />`";if(!n){const u=new Error(r);throw u.name="ContextError",(o=Error.captureStackTrace)==null||o.call(Error,u,t),u}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 $e(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 lt(e,t,n=!0){return $e(e,t,-1,n)}function it(e,t,n=!0){const r=$e(e,t.length,1,n);return t[r]}function at(e,t,n=!0){const r=lt(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 ue(e){return typeof e>"u"}function Ke(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=le.Children.toArray(e),o=0,u=r;o<u.length;o++){var l=u[o];if(t(l))return l;if(!((n=l.props)===null||n===void 0)&&n.children){var i=ie(l.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=le.Children.toArray(e),o=[],u=0,l=r;u<l.length;u++){var i=l[u];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,u=e.length<t.length?t:e,l=r(o,n),i=r(u,n),y=new Set(l),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,u=o(r.value);return{...Ke(r.label)?r:{...r,label:u},value:u,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)=>Ke(ie(e,n=>{var o,u;const r=h(((o=n.props)==null?void 0:o.getValue)||Re,((u=n.props)==null?void 0:u.value)||{});return t.some(l=>l.value===r)})),St=(e,t)=>{const n={},r={},{field:o}=e;return o&&Object.keys(o).forEach(u=>{if(u.startsWith("--input")===!1)n[u]=o[u];else{let l=o[u];const y=u.replace("--input-","").replace(/-([a-z])/g,function(C){return C[1].toUpperCase()});l.indexOf(".")!==-1&&(l=l.substring(l.indexOf(".")+1)),r[y]=l}}),{...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:u=!0,defaultEmptyStateProps:l={},freeSolo:i,isReadOnly:y,listAllValuesOnFocus:C,maxSuggestions:b,multiple:d,closeOnSelect:O=!d,defaultValue:S,defaultValues:j=S?[S]:[],onReady:H,defaultIsOpen:k,disableFilter:q,isLoading:ae=!1,placement:ee="bottom",restoreOnBlurIfEmpty:K=!i,shouldRenderSuggestions:ce=()=>!0,submitKeys:fe=[],suggestWhenEmpty:te,value:z,values:Y=z?typeof z=="string"?[z]:[...z]:void 0}=e;i=i||(d?!0:e.freeSolo);const{isOpen:E,onClose:G,onOpen:U}=a.useDisclosure({defaultIsOpen:k}),pe=f.useMemo(()=>h(e.children,{isOpen:E,onClose:G,onOpen:U}),[e.children,E]),R=f.useMemo(()=>mt(pe),[pe]),N=f.useRef(null),Ne=f.useRef(null),J=f.useRef(null),V=f.useRef(null),[Pe,ne]=f.useState(!1);let oe="";d?oe="":ue(j)?ue(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&&!u&&E&&G()},[x.length,u,E]);const[Q,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===Q),ve=it(me,x,!!e.rollNavigation),he=at(me,x,!!e.rollNavigation),P=ut(x),ye=we(x),Me=!x.some(s=>s.value===Q);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===Q);h(e.onOptionFocus,{item:s,focusMethod:V.current,isNewInput:s==null?void 0:s.creatable})},[Q,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:V.current,isNewInput:c==null?void 0:c.creatable}),c!=null&&c.creatable&&h(e.onCreateOption,{item:Oe(c,["noFilter"]),selectMethod:V.current}),O&&G()},Te=(s,c)=>{var L;ge(w=>{const $=R.find(T=>T.value===s);return $?(h(e.onTagRemoved,s,$,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(H,{tags:_e})},[M]),{autoCompleteProps:e,children:pe,filteredList:x,filteredResults:de,focusedValue:Q,defaultEmptyStateProps:l,getEmptyStateProps:s=>{if(x.every(m=>m.noFilter)&&u&&!r)return typeof u=="boolean"?s:h(u,{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=>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:$,...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&&U(),e.selectOnFocus&&g.target.select(),C&&ne(!0)},onBlur:g=>{var B,re;h(m,g);const A=g.relatedTarget===(J==null?void 0:J.current)||((B=J.current)==null?void 0:B.contains(g.relatedTarget)),v=(re=Ne.current)==null?void 0:re.contains(g.relatedTarget);if(!A&&!v&&(n&&G(),!M.includes(g.target.value)&&K)){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)?U():G(),ne(!1)},onKeyDown:g=>{var B;h(w,g),V.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):(B=N.current)==null||B.focus(),g.preventDefault();return}if(A==="ArrowDown"){E?W(ve==null?void 0:ve.value):U(),g.preventDefault();return}if(A==="ArrowUp"){E?W(he==null?void 0:he.value):U(),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":$,...T}}},getItemProps:(s,c)=>{var We;const{_fixed:m,_focus:F,children:L,disabled:w,label:$,value:T,fixed:g,getValue:A=Re,onClick:v,onMouseOver:B,sx:re,...xe}=s,I=c?T:(We=A(T))==null?void 0:We.toString(),be=I===Q,Se=x.findIndex(Z=>Z.value===I)>=0,Ae=L||$||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(B,Z),W(I),V.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:V,isLoading:ae,isOpen:E,itemList:R,listRef:J,onClose:G,onOpen:U,placement:ee,query:D,removeItem:Te,resetItems:rt,setQuery:X,tags:_e,value:z,values:M}}const Xe=a.forwardRef((e,t)=>{const n=Je(e),{children:r,isOpen:o,onClose:u,onOpen:l,placement:i,resetItems:y,removeItem:C}=n;f.useImperativeHandle(t,()=>({resetItems:y,removeItem:C}));const{matchWidth:b=!0}=n.autoCompleteProps;return p.jsx(Ve,{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}=_(),u=f.useRef(),l=a.useMergeRefs(t,u),i=r(e),{isValidSuggestion:y,value:C}=i.root,b=n===C;f.useEffect(()=>{var H;b&&o.current==="keyboard"&&((H=u==null?void 0:u.current)==null||H.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:O,...S}=i.item,j=Oe(S,["groupId"]);return y?p.jsx(a.Flex,{ref:l,...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:u,query:l,filteredResults:i}=_(),{children:y,...C}=u({...e,value:l,children:h(n,{value:l})},!0).item,b=i.some(S=>S.value===l),d=Ee(l)?t:!0;return o.creatable&&d&&!b?p.jsx(a.Flex,{...Fe,...C,...r,children:y||`Add ${l}`}):null}qe.displayName="AutoCompleteCreatable";const et=a.forwardRef((e,t)=>{const{children:n,showDivider:r,...o}=e,u=Oe(o,["groupSibling"]),{getGroupProps:l}=_(),{group:i}=l(e),y=wt(e);return p.jsxs(a.Box,{ref:t,...i,...u,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),u={my:2,borderColor:e.dividerColor},l={...u,mb:4,display:!e.showDivider||r?"none":""},i={...u,display:!e.showDivider||o||n?"none":""};return{top:l,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:u,setQuery:l,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),z=te===void 0?i:te.label;l(z)}},[i]),f.useEffect(()=>{S!==void 0&&(typeof S=="string"||S instanceof String)&&l(S)},[S]);const j=a.useMultiStyleConfig("Input",e);let{wrapper:H,input:k}=o(O,j);const{ref:q,...ae}=H,ee=a.useMergeRefs(t,r),K=h(C,{tags:u});d&&(k={...k,placeholder:Array.isArray(K)&&K.length?void 0:k.placeholder});const ce=p.jsx(Be,{isInvalid:b,...k,ref:ee}),fe=p.jsxs(a.Wrap,{"aria-invalid":b,...ae,ref:q,children:[K,p.jsx(a.WrapItem,{as:Be,...k,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,u)=>{var l;if(((l=o==null?void 0:o.type)==null?void 0:l.displayName)==="AutoCompleteGroup"){const i=f.Children.toArray(e)[u+1];return f.cloneElement(o,{groupSibling:i?i.type.displayName==="AutoCompleteGroup":!1})}return o}),n=f.Children.toArray(t).filter(o=>{var u;return!He.includes((u=o==null?void 0:o.type)==null?void 0:u.displayName)});return[f.Children.toArray(t).filter(o=>{var u;return He.includes((u=o==null?void 0:o.type)==null?void 0:u.displayName)}),n]},nt=a.forwardRef((e,t)=>{const{children:n,loadingState:r,...o}=e,{listRef:u,isLoading:l}=_(),i=a.useMergeRefs(t,u),[y,C]=Et(n);return p.jsxs(a.PopoverContent,{ref:i,w:"inherit",...Ot,...o,children:[l&&p.jsx(a.Center,{children:r||p.jsx(a.Spinner,{size:"md"})}),!l&&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=Ve;exports.AutoCompleteTag=Rt;exports.baseItemStyles=Fe;exports.createContext=Qe;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 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 +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,CAwdvB"}
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"}
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.8.1",
2
+ "version": "5.8.2",
3
3
  "license": "MIT",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",