@choc-ui/chakra-autocomplete 5.8.4 → 5.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/autocomplete-list.d.ts.map +1 -1
- package/dist/index.es.js +79 -79
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocomplete-list.d.ts","sourceRoot":"","sources":["../src/autocomplete-list.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,mBAAmB,
|
|
1
|
+
{"version":3,"file":"autocomplete-list.d.ts","sourceRoot":"","sources":["../src/autocomplete-list.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,mBAAmB,EAIpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,MAAM,WAAW,qBAAsB,SAAQ,mBAAmB;IAChE,YAAY,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC/B;AAED,eAAO,MAAM,gBAAgB,0EA0B5B,CAAC"}
|
package/dist/index.es.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as p, jsxs as V, Fragment as ut } from "react/jsx-runtime";
|
|
2
2
|
import * as pe from "react";
|
|
3
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,
|
|
5
|
-
const [
|
|
6
|
-
function
|
|
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, Portal as xt, PopoverContent as At, Center as It, Tag as wt, TagLabel as Ot, TagCloseButton as Et } from "@chakra-ui/react";
|
|
5
|
+
const [Ft, j] = Lt();
|
|
6
|
+
function Lt() {
|
|
7
7
|
const e = pe.createContext(void 0);
|
|
8
8
|
e.displayName = "AutoCompleteContext";
|
|
9
9
|
function t() {
|
|
@@ -17,7 +17,7 @@ function Ft() {
|
|
|
17
17
|
}
|
|
18
18
|
return [e.Provider, t, e];
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function Nt(e) {
|
|
21
21
|
return e == null ? void 0 : e[0];
|
|
22
22
|
}
|
|
23
23
|
function Pe(e) {
|
|
@@ -28,31 +28,31 @@ 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
|
|
31
|
+
function Pt(e, t, n = !0) {
|
|
32
32
|
return et(e, t, -1, n);
|
|
33
33
|
}
|
|
34
|
-
function
|
|
34
|
+
function Dt(e, t, n = !0) {
|
|
35
35
|
const r = et(e, t.length, 1, n);
|
|
36
36
|
return t[r];
|
|
37
37
|
}
|
|
38
|
-
function
|
|
39
|
-
const r =
|
|
38
|
+
function Rt(e, t, n = !0) {
|
|
39
|
+
const r = Pt(e, t.length, n);
|
|
40
40
|
return t[r];
|
|
41
41
|
}
|
|
42
42
|
function Re(e) {
|
|
43
43
|
return Array.isArray(e);
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function Tt(e) {
|
|
46
46
|
return Re(e) && e.length === 0;
|
|
47
47
|
}
|
|
48
48
|
function Te(e) {
|
|
49
49
|
return e !== null && typeof e == "object" && !Re(e);
|
|
50
50
|
}
|
|
51
|
-
function
|
|
51
|
+
function Mt(e) {
|
|
52
52
|
return Te(e) && Object.keys(e).length === 0;
|
|
53
53
|
}
|
|
54
54
|
function Me(e) {
|
|
55
|
-
return Re(e) ?
|
|
55
|
+
return Re(e) ? Tt(e) : Te(e) ? Mt(e) : e == null || e === "";
|
|
56
56
|
}
|
|
57
57
|
function fe(e) {
|
|
58
58
|
return typeof e > "u";
|
|
@@ -60,7 +60,7 @@ function fe(e) {
|
|
|
60
60
|
function tt(e) {
|
|
61
61
|
return typeof e < "u";
|
|
62
62
|
}
|
|
63
|
-
function
|
|
63
|
+
function _t(e, t) {
|
|
64
64
|
const n = {};
|
|
65
65
|
return t.forEach((r) => {
|
|
66
66
|
r in e && (n[r] = e[r]);
|
|
@@ -72,11 +72,11 @@ function _e(e, t) {
|
|
|
72
72
|
delete n[r];
|
|
73
73
|
}), n;
|
|
74
74
|
}
|
|
75
|
-
function
|
|
75
|
+
function Gt(e) {
|
|
76
76
|
return typeof e == "function";
|
|
77
77
|
}
|
|
78
78
|
function m(e, ...t) {
|
|
79
|
-
return
|
|
79
|
+
return Gt(e) ? e(...t) : e;
|
|
80
80
|
}
|
|
81
81
|
var ge = function(e, t) {
|
|
82
82
|
for (var n, r = pe.Children.toArray(e), o = 0, l = r; o < l.length; o++) {
|
|
@@ -118,40 +118,40 @@ function Ke(e, t, n = 2) {
|
|
|
118
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
|
-
},
|
|
122
|
-
new RegExp(
|
|
121
|
+
}, Wt = (e, t) => typeof e != "string" || Me(t) ? e : e.toString().replace(
|
|
122
|
+
new RegExp(Bt(t), "gi"),
|
|
123
123
|
(r) => `<mark>${r}</mark>`
|
|
124
|
-
),
|
|
124
|
+
), jt = (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 =
|
|
131
|
+
const r = _t(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
|
-
}),
|
|
133
|
+
}), kt = () => ({
|
|
134
134
|
bg: "whiteAlpha.100",
|
|
135
135
|
_light: {
|
|
136
136
|
bg: "gray.200"
|
|
137
137
|
}
|
|
138
|
-
}),
|
|
139
|
-
function
|
|
138
|
+
}), zt = (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 Bt(e) {
|
|
140
140
|
return e.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
141
141
|
}
|
|
142
|
-
const
|
|
142
|
+
const Ht = (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
|
-
),
|
|
148
|
+
), Ut = (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
|
-
),
|
|
154
|
+
), Qt = (e, t) => tt(
|
|
155
155
|
ge(e, (n) => {
|
|
156
156
|
var o, l;
|
|
157
157
|
const r = m(
|
|
@@ -160,7 +160,7 @@ const Bt = (e, t) => ge(
|
|
|
160
160
|
);
|
|
161
161
|
return t.some((i) => i.value === r);
|
|
162
162
|
})
|
|
163
|
-
),
|
|
163
|
+
), $t = (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 Bt = (e, t) => ge(
|
|
|
188
188
|
// w: "full",
|
|
189
189
|
};
|
|
190
190
|
};
|
|
191
|
-
function
|
|
191
|
+
function Kt(e) {
|
|
192
192
|
var He;
|
|
193
193
|
let {
|
|
194
194
|
prefocusFirstItem: t = !0,
|
|
@@ -225,13 +225,13 @@ function $t(e) {
|
|
|
225
225
|
onOpen: Q
|
|
226
226
|
}),
|
|
227
227
|
[e.children, O]
|
|
228
|
-
), x = te(() =>
|
|
228
|
+
), x = te(() => jt(ye), [ye]), N = ne(null), We = ne(null), X = ne(null), $ = ne(null), [je, le] = Ne(!1);
|
|
229
229
|
let ie = "";
|
|
230
230
|
c ? ie = "" : fe(w) ? fe(J) || (ie = J[0]) : ie = w[0];
|
|
231
231
|
const [R, Z] = Ne(ie ?? ""), be = te(
|
|
232
232
|
() => oe ? x : x.filter(
|
|
233
233
|
(s) => s.fixed || m(
|
|
234
|
-
e.filter ||
|
|
234
|
+
e.filter || zt,
|
|
235
235
|
R,
|
|
236
236
|
s.value,
|
|
237
237
|
s.label
|
|
@@ -261,15 +261,15 @@ function $t(e) {
|
|
|
261
261
|
}, [C.length, l, O]);
|
|
262
262
|
const [K, G] = Ne(
|
|
263
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 =
|
|
264
|
+
), lt = e.maxSelections || T.length + 1, Se = C.findIndex((s) => s.value === K), xe = Dt(
|
|
265
265
|
Se,
|
|
266
266
|
C,
|
|
267
267
|
!!e.rollNavigation
|
|
268
|
-
), Ae =
|
|
268
|
+
), Ae = Rt(
|
|
269
269
|
Se,
|
|
270
270
|
C,
|
|
271
271
|
!!e.rollNavigation
|
|
272
|
-
), P =
|
|
272
|
+
), P = Nt(C), Ie = Pe(C), ke = !C.some(
|
|
273
273
|
(s) => s.value === K
|
|
274
274
|
);
|
|
275
275
|
D(() => {
|
|
@@ -333,11 +333,11 @@ function $t(e) {
|
|
|
333
333
|
return typeof l == "boolean" ? s : m(l, { query: R });
|
|
334
334
|
},
|
|
335
335
|
getGroupProps: (s) => {
|
|
336
|
-
const a =
|
|
336
|
+
const a = Qt(s.children, C);
|
|
337
337
|
return {
|
|
338
338
|
divider: {
|
|
339
|
-
hasFirstChild:
|
|
340
|
-
hasLastChild:
|
|
339
|
+
hasFirstChild: Ht(s.children, P),
|
|
340
|
+
hasLastChild: Ut(
|
|
341
341
|
s.children,
|
|
342
342
|
Pe(C.filter((d) => fe(d == null ? void 0 : d.noFilter)))
|
|
343
343
|
)
|
|
@@ -356,7 +356,7 @@ function $t(e) {
|
|
|
356
356
|
var f;
|
|
357
357
|
(f = N == null ? void 0 : N.current) == null || f.focus();
|
|
358
358
|
},
|
|
359
|
-
|
|
359
|
+
...$t(a, c),
|
|
360
360
|
...M
|
|
361
361
|
},
|
|
362
362
|
input: {
|
|
@@ -439,7 +439,7 @@ function $t(e) {
|
|
|
439
439
|
item: {
|
|
440
440
|
...typeof Le != "string" || !o ? { children: Le } : {
|
|
441
441
|
dangerouslySetInnerHTML: {
|
|
442
|
-
__html:
|
|
442
|
+
__html: Wt(Le, R)
|
|
443
443
|
}
|
|
444
444
|
},
|
|
445
445
|
"aria-selected": T.includes(I),
|
|
@@ -462,7 +462,7 @@ function $t(e) {
|
|
|
462
462
|
}
|
|
463
463
|
}
|
|
464
464
|
},
|
|
465
|
-
...Ee && (F ||
|
|
465
|
+
...Ee && (F || kt()),
|
|
466
466
|
...f && d,
|
|
467
467
|
...Oe
|
|
468
468
|
},
|
|
@@ -490,9 +490,9 @@ function $t(e) {
|
|
|
490
490
|
values: T
|
|
491
491
|
};
|
|
492
492
|
}
|
|
493
|
-
const
|
|
493
|
+
const Vt = H(
|
|
494
494
|
(e, t) => {
|
|
495
|
-
const n =
|
|
495
|
+
const n = Kt(e), {
|
|
496
496
|
children: r,
|
|
497
497
|
isOpen: o,
|
|
498
498
|
onClose: l,
|
|
@@ -506,7 +506,7 @@ const Kt = H(
|
|
|
506
506
|
removeItem: h
|
|
507
507
|
}));
|
|
508
508
|
const { matchWidth: y = !0 } = n.autoCompleteProps;
|
|
509
|
-
return /* @__PURE__ */ p(
|
|
509
|
+
return /* @__PURE__ */ p(Ft, { value: n, children: /* @__PURE__ */ p(
|
|
510
510
|
gt,
|
|
511
511
|
{
|
|
512
512
|
isLazy: !0,
|
|
@@ -520,8 +520,8 @@ const Kt = H(
|
|
|
520
520
|
) });
|
|
521
521
|
}
|
|
522
522
|
);
|
|
523
|
-
|
|
524
|
-
const
|
|
523
|
+
Vt.displayName = "AutoComplete";
|
|
524
|
+
const Yt = H(
|
|
525
525
|
(e, t) => {
|
|
526
526
|
const {
|
|
527
527
|
focusedValue: n,
|
|
@@ -543,7 +543,7 @@ const Vt = H(
|
|
|
543
543
|
return v ? /* @__PURE__ */ p(de, { ref: i, ...ot, ...w, children: c || /* @__PURE__ */ p("span", { dangerouslySetInnerHTML: E }) }) : null;
|
|
544
544
|
}
|
|
545
545
|
);
|
|
546
|
-
|
|
546
|
+
Yt.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
|
|
554
|
+
function Jt(e) {
|
|
555
555
|
const { alwaysDisplay: t, children: n, ...r } = e, {
|
|
556
556
|
autoCompleteProps: o,
|
|
557
557
|
getItemProps: l,
|
|
@@ -569,29 +569,29 @@ function Yt(e) {
|
|
|
569
569
|
).item, y = u.some((b) => b.value === i), c = Me(i) ? t : !0;
|
|
570
570
|
return o.creatable && c && !y ? /* @__PURE__ */ p(de, { ...ot, ...h, ...r, children: v || `Add ${i}` }) : null;
|
|
571
571
|
}
|
|
572
|
-
|
|
573
|
-
const
|
|
572
|
+
Jt.displayName = "AutoCompleteCreatable";
|
|
573
|
+
const Xt = H(
|
|
574
574
|
(e, t) => {
|
|
575
|
-
const { children: n, showDivider: r, ...o } = e, l = _e(o, ["groupSibling"]), { getGroupProps: i } = j(), { group: u } = i(e), v =
|
|
575
|
+
const { children: n, showDivider: r, ...o } = e, l = _e(o, ["groupSibling"]), { getGroupProps: i } = j(), { group: u } = i(e), v = en(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
|
-
),
|
|
583
|
-
(e, t) => /* @__PURE__ */ p(de, { ...
|
|
582
|
+
), Zt = H(
|
|
583
|
+
(e, t) => /* @__PURE__ */ p(de, { ...qt, ...e, ref: t })
|
|
584
584
|
);
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
const
|
|
585
|
+
Xt.displayName = "AutoCompleteGroup";
|
|
586
|
+
Zt.displayName = "AutoCompleteGroupTitle";
|
|
587
|
+
const qt = {
|
|
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
|
-
},
|
|
594
|
+
}, en = (e) => {
|
|
595
595
|
const { getGroupProps: t } = j(), n = e.groupSibling, {
|
|
596
596
|
divider: { hasFirstChild: r, hasLastChild: o }
|
|
597
597
|
} = t(e), l = {
|
|
@@ -666,12 +666,12 @@ const Zt = {
|
|
|
666
666
|
);
|
|
667
667
|
rt.displayName = "Input";
|
|
668
668
|
rt.id = "Input";
|
|
669
|
-
const
|
|
669
|
+
const tn = (e) => {
|
|
670
670
|
const { getEmptyStateProps: t, defaultEmptyStateProps: n } = j(), r = t(
|
|
671
|
-
/* @__PURE__ */ p(de, { ...
|
|
671
|
+
/* @__PURE__ */ p(de, { ...nn, ...n, children: "No options found!" })
|
|
672
672
|
);
|
|
673
673
|
return /* @__PURE__ */ p(Xe, { ...e, children: r });
|
|
674
|
-
},
|
|
674
|
+
}, nn = {
|
|
675
675
|
fontSize: "sm",
|
|
676
676
|
align: "center",
|
|
677
677
|
justify: "center",
|
|
@@ -681,7 +681,7 @@ const en = (e) => {
|
|
|
681
681
|
"AutoCompleteGroup",
|
|
682
682
|
"AutoCompleteItem",
|
|
683
683
|
"AutoCompleteCreatable"
|
|
684
|
-
],
|
|
684
|
+
], on = (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 en = (e) => {
|
|
|
707
707
|
);
|
|
708
708
|
}
|
|
709
709
|
), n];
|
|
710
|
-
},
|
|
710
|
+
}, rn = H(
|
|
711
711
|
(e, t) => {
|
|
712
|
-
const { children: n, loadingState: r, ...o } = e, { listRef: l, isLoading: i } = j(), u = De(t, l), [v, h] =
|
|
713
|
-
return /* @__PURE__ */
|
|
714
|
-
i && /* @__PURE__ */ p(
|
|
712
|
+
const { children: n, loadingState: r, ...o } = e, { listRef: l, isLoading: i } = j(), u = De(t, l), [v, h] = on(n);
|
|
713
|
+
return /* @__PURE__ */ p(xt, { appendToParentPortal: !1, children: /* @__PURE__ */ V(At, { ref: u, w: "inherit", ...sn, ...o, children: [
|
|
714
|
+
i && /* @__PURE__ */ p(It, { children: r || /* @__PURE__ */ p(Ze, { size: "md" }) }),
|
|
715
715
|
!i && /* @__PURE__ */ V(ut, { children: [
|
|
716
716
|
v,
|
|
717
|
-
/* @__PURE__ */ p(
|
|
717
|
+
/* @__PURE__ */ p(tn, {}),
|
|
718
718
|
h
|
|
719
719
|
] })
|
|
720
|
-
] });
|
|
720
|
+
] }) });
|
|
721
721
|
}
|
|
722
722
|
);
|
|
723
|
-
|
|
724
|
-
const
|
|
723
|
+
rn.displayName = "AutoCompleteList";
|
|
724
|
+
const sn = {
|
|
725
725
|
py: "4",
|
|
726
726
|
opacity: "0",
|
|
727
727
|
bg: "#232934",
|
|
@@ -737,19 +737,19 @@ const rn = {
|
|
|
737
737
|
_focus: {
|
|
738
738
|
boxShadow: "none"
|
|
739
739
|
}
|
|
740
|
-
},
|
|
740
|
+
}, gn = ct((e) => {
|
|
741
741
|
const { label: t, onRemove: n, disabled: r, ...o } = e;
|
|
742
742
|
return /* @__PURE__ */ p(qe, { children: /* @__PURE__ */ V(
|
|
743
|
-
|
|
743
|
+
wt,
|
|
744
744
|
{
|
|
745
745
|
borderRadius: "md",
|
|
746
746
|
fontWeight: "normal",
|
|
747
747
|
...r && Je,
|
|
748
748
|
...o,
|
|
749
749
|
children: [
|
|
750
|
-
/* @__PURE__ */ p(
|
|
750
|
+
/* @__PURE__ */ p(Ot, { children: t }),
|
|
751
751
|
/* @__PURE__ */ p(
|
|
752
|
-
|
|
752
|
+
Et,
|
|
753
753
|
{
|
|
754
754
|
onClick: () => !r && m(n),
|
|
755
755
|
cursor: "pointer",
|
|
@@ -766,17 +766,17 @@ const rn = {
|
|
|
766
766
|
_focus: { boxShadow: "none" }
|
|
767
767
|
};
|
|
768
768
|
export {
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
769
|
+
Vt as AutoComplete,
|
|
770
|
+
Jt as AutoCompleteCreatable,
|
|
771
|
+
Xt as AutoCompleteGroup,
|
|
772
|
+
Zt as AutoCompleteGroupTitle,
|
|
773
773
|
rt as AutoCompleteInput,
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
774
|
+
Yt as AutoCompleteItem,
|
|
775
|
+
rn as AutoCompleteList,
|
|
776
|
+
Ft as AutoCompleteProvider,
|
|
777
|
+
gn as AutoCompleteTag,
|
|
778
778
|
ot as baseItemStyles,
|
|
779
|
-
|
|
780
|
-
|
|
779
|
+
Lt as createContext,
|
|
780
|
+
Kt 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 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
|
+
"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 b=new Array(d.length-R+1);for(let E=0;E<b.length;E++)b[E]=d.slice(E,E+R);return b}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,x=0;for(let d of i)y.delete(d)&&x++;return x/C}const Pe=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=Pe}=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 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)}),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)}),St=(e,t)=>Ve(ae(e,n=>{var o,l;const r=h(((o=n.props)==null?void 0:o.getValue)||Pe,((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:x,multiple:d,closeOnSelect:R=!d,defaultValue:b,defaultValues:E=b?[b]:[],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]),L=f.useRef(null),Ne=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)=>x?s.fixed||c<x:!0),[D,I,De,x,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(P=>P.value===s.at(-1));if(!c)return;const m=s.map(P=>ot.find(F=>F.value===P));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),N=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(N==null?void 0:N.value)},[D,N==null?void 0:N.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 xe=s=>{var P,F;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&&((P=L.current)==null||P.focus()),e.focusInputOnSelect&&((F=L.current)==null||F.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 F;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),P=(m==null?void 0:m.label)||(m==null?void 0:m.value);D===P&&X(""),c&&((F=L.current)==null||F.focus())},st=s=>{var c;me([]),s&&((c=L.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:xt(s.children,N),hasLastChild:bt(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:P,onFocus:F,onKeyDown:w,variant:k,...T}=s;return{wrapper:{ref:Ne,onClick:()=>{var g;(g=L==null?void 0:L.current)==null||g.focus()},...At(c,d),...T},input:{isReadOnly:y,onFocus:g=>{h(F,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=Ne.current)==null?void 0:se.contains(g.relatedTarget);if(!A&&!v&&(n&&G(),!M.includes(g.target.value)&&V)){const be=we(M),j=I.find(Ae=>Ae.value===be),Se=(j==null?void 0:j.label)||(j==null?void 0:j.value)||"";X(Se)}},onChange:g=>{const A=g.target.value;h(P,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?xe(v==null?void 0:v.value):(H=L.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)?xe(v==null?void 0:v.value):G();return}if(A==="Home"){W(N==null?void 0:N.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:P,children:F,disabled:w,label:k,value:T,fixed:g,getValue:A=Pe,onClick:v,onMouseOver:H,sx:se,...be}=s,j=c?T:(We=A(T))==null?void 0:We.toString(),Se=j===K,Ae=S.findIndex(Z=>Z.value===j)>=0,Ie=F||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=L.current)==null||ke.focus():xe(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&&(P||ht()),...g&&m,...be},root:{isValidSuggestion:Ae,value:j}}},inputRef:L,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:x=!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:x,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,x=n===C;f.useEffect(()=>{var U;x&&o.current==="keyboard"&&((U=l==null?void 0:l.current)==null||U.scrollIntoView({behavior:"smooth",block:"nearest"}))},[x,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,...b}=i.item,E=Re(b,["groupId"]);return y?p.jsx(a.Flex,{ref:u,...Fe,...E,children:d||p.jsx("span",{dangerouslySetInnerHTML:R})}):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,x=i.some(b=>b.value===u),d=Oe(u)?t:!0;return o.creatable&&d&&!x?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=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,{})})]})}),Le=a.forwardRef((e,t)=>{const{autoCompleteProps:n,inputRef:r,getInputProps:o,tags:l,setQuery:u,value:i,itemList:y}=_(),{children:C,isInvalid:x,hidePlaceholder:d,...R}=e,{value:b}=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(()=>{b!==void 0&&(typeof b=="string"||b instanceof String)&&u(b)},[b]);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:x,...z,ref:ee}),pe=p.jsxs(a.Wrap,{"aria-invalid":x,...ce,ref:q,children:[V,p.jsx(a.WrapItem,{as:Be,...z,ref:ee})]});return p.jsx(a.PopoverAnchor,{children:n.multiple?pe:fe})});Le.displayName="Input";Le.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.jsx(a.Portal,{appendToParentPortal:!1,children: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"}},Pt=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=Pt;exports.baseItemStyles=Fe;exports.createContext=$e;exports.useAutoComplete=Je;exports.useAutoCompleteContext=_;
|
package/package.json
CHANGED