@choc-ui/chakra-autocomplete 6.1.3 → 6.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.es.js +111 -111
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
|
|
39
39
|
## Chakra V3 and V2 Support
|
|
40
40
|
|
|
41
|
-
AutoComplete Version 6+ supports [Chakra UI V3](https://www.chakra-ui.com/). If you are using [Chakra UI V2](https://v2.chakra-ui.com/), please continue to use the current choc-autocomplete v5.X. We will continue to try and support Chakra V2 but will eventually be removed once V3 becomes more widely adopted.
|
|
41
|
+
AutoComplete Version 6+ supports [Chakra UI V3](https://www.chakra-ui.com/). If you are using [Chakra UI V2](https://v2.chakra-ui.com/), please continue to use the current choc-autocomplete v5.X [documentation here](https://github.com/anubra266/choc-autocomplete/tree/v5). We will continue to try and support Chakra V2 but will eventually be removed once V3 becomes more widely adopted.
|
|
42
42
|
|
|
43
43
|
For help migrating from Chakra UI V2 to V3, please see their [migration guide](https://chakra-ui.com/docs/get-started/migration)
|
|
44
44
|
|
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as a, jsxs as q, Fragment as pt } from "react/jsx-runtime";
|
|
2
2
|
import * as L from "react";
|
|
3
|
-
import P, { useMemo as Z, useRef as
|
|
3
|
+
import P, { useMemo as Z, useRef as le, useState as De, useEffect as j, forwardRef as U, useImperativeHandle as dt, memo as mt } from "react";
|
|
4
4
|
import { useDisclosure as gt, useControllableState as ht, IconButton as vt, Portal as yt, Popover as N, chakra as bt, Flex as ve, Box as _e, Separator as Xe, Group as Ct, InputElement as Je, Input as wt, Spinner as nt, PopoverAnchor as St, Center as xt, Tag as J } from "@chakra-ui/react";
|
|
5
5
|
const [Ot, H] = At();
|
|
6
6
|
function At() {
|
|
@@ -107,9 +107,9 @@ var be = function(e, t) {
|
|
|
107
107
|
if (t(u))
|
|
108
108
|
return u;
|
|
109
109
|
if (!((n = u.props) === null || n === void 0) && n.children) {
|
|
110
|
-
var
|
|
111
|
-
if (
|
|
112
|
-
return
|
|
110
|
+
var i = be(u.props.children, t);
|
|
111
|
+
if (i)
|
|
112
|
+
return i;
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
}, de = function(e, t) {
|
|
@@ -118,8 +118,8 @@ var be = function(e, t) {
|
|
|
118
118
|
return e;
|
|
119
119
|
}, st = function(e, t) {
|
|
120
120
|
for (var n, r = L.Children.toArray(e), o = [], s = 0, u = r; s < u.length; s++) {
|
|
121
|
-
var
|
|
122
|
-
t(
|
|
121
|
+
var i = u[s];
|
|
122
|
+
t(i) && (o = de(de([], o), [i])), !((n = i.props) === null || n === void 0) && n.children && (o = de(de([], o), st(i.props.children, t)));
|
|
123
123
|
}
|
|
124
124
|
return o;
|
|
125
125
|
};
|
|
@@ -133,8 +133,8 @@ function Ze(e, t, n = 2) {
|
|
|
133
133
|
}
|
|
134
134
|
if (!(e != null && e.length) || !(t != null && t.length))
|
|
135
135
|
return 0;
|
|
136
|
-
let o = e.length < t.length ? e : t, s = e.length < t.length ? t : e, u = r(o, n),
|
|
137
|
-
for (let d of
|
|
136
|
+
let o = e.length < t.length ? e : t, s = e.length < t.length ? t : e, u = r(o, n), i = r(s, n), f = new Set(u), v = i.length, y = 0;
|
|
137
|
+
for (let d of i)
|
|
138
138
|
f.delete(d) && y++;
|
|
139
139
|
return y / v;
|
|
140
140
|
}
|
|
@@ -193,7 +193,7 @@ function Ht(e) {
|
|
|
193
193
|
emphasize: o,
|
|
194
194
|
emptyState: s = !0,
|
|
195
195
|
defaultEmptyStateProps: u = {},
|
|
196
|
-
freeSolo:
|
|
196
|
+
freeSolo: i,
|
|
197
197
|
isReadOnly: f,
|
|
198
198
|
listAllValuesOnFocus: v,
|
|
199
199
|
maxSuggestions: y,
|
|
@@ -203,17 +203,17 @@ function Ht(e) {
|
|
|
203
203
|
defaultValues: O = E ? [E] : [],
|
|
204
204
|
onReady: T,
|
|
205
205
|
defaultIsOpen: Ce,
|
|
206
|
-
disableFilter:
|
|
206
|
+
disableFilter: ee,
|
|
207
207
|
isLoading: we = !1,
|
|
208
|
-
placement:
|
|
209
|
-
restoreOnBlurIfEmpty:
|
|
208
|
+
placement: te = "bottom",
|
|
209
|
+
restoreOnBlurIfEmpty: ie = !i,
|
|
210
210
|
shouldRenderSuggestions: Se = () => !0,
|
|
211
211
|
submitKeys: ue = [],
|
|
212
212
|
suggestWhenEmpty: xe,
|
|
213
213
|
value: K,
|
|
214
214
|
values: Oe = K ? typeof K == "string" ? [K] : [...K] : void 0
|
|
215
215
|
} = e;
|
|
216
|
-
|
|
216
|
+
i = i || (d ? !0 : e.freeSolo);
|
|
217
217
|
const { open: A, onClose: z, onOpen: V } = gt({ open: Ce }), Ae = Z(
|
|
218
218
|
() => h(e.children, {
|
|
219
219
|
isOpen: A,
|
|
@@ -221,33 +221,33 @@ function Ht(e) {
|
|
|
221
221
|
onOpen: V
|
|
222
222
|
}),
|
|
223
223
|
[e.children, A]
|
|
224
|
-
), S = Z(() => Gt(Ae), [Ae]), F =
|
|
224
|
+
), S = Z(() => Gt(Ae), [Ae]), F = le(null), Be = le(null), ne = le(null), Y = le(null), [$e, ae] = De(!1);
|
|
225
225
|
let ce = "";
|
|
226
226
|
d ? ce = "" : me(O) ? me(Oe) || (ce = Oe[0]) : ce = O[0];
|
|
227
|
-
const [_,
|
|
228
|
-
() =>
|
|
229
|
-
(
|
|
227
|
+
const [_, re] = De(ce ?? ""), Ee = Z(
|
|
228
|
+
() => ee ? S : S.filter(
|
|
229
|
+
(l) => l.fixed || h(
|
|
230
230
|
e.filter || Wt,
|
|
231
231
|
_,
|
|
232
|
-
|
|
233
|
-
|
|
232
|
+
l.value,
|
|
233
|
+
l.label
|
|
234
234
|
) || $e
|
|
235
235
|
).filter(
|
|
236
|
-
(
|
|
236
|
+
(l, c) => y ? l.fixed || c < y : !0
|
|
237
237
|
),
|
|
238
|
-
[_, S, $e, y,
|
|
238
|
+
[_, S, $e, y, ee]
|
|
239
239
|
), fe = r ? [{ value: _, noFilter: !0, creatable: !0 }] : [], b = Z(() => [...Ee, ...fe], [Ee, fe]), at = Z(() => [...S, ...fe], [S, fe]), [G, Ie] = ht({
|
|
240
|
-
defaultValue: O.map((
|
|
240
|
+
defaultValue: O.map((l) => l == null ? void 0 : l.toString()),
|
|
241
241
|
value: Oe,
|
|
242
|
-
onChange: (
|
|
243
|
-
const c = b.find((I) => I.value ===
|
|
242
|
+
onChange: (l) => {
|
|
243
|
+
const c = b.find((I) => I.value === l.at(-1));
|
|
244
244
|
if (!c) return;
|
|
245
|
-
const m =
|
|
245
|
+
const m = l.map(
|
|
246
246
|
(I) => at.find((R) => R.value === I)
|
|
247
247
|
);
|
|
248
248
|
h(
|
|
249
249
|
e.onChange,
|
|
250
|
-
d ?
|
|
250
|
+
d ? l : l[0],
|
|
251
251
|
d ? m : c
|
|
252
252
|
);
|
|
253
253
|
}
|
|
@@ -257,7 +257,7 @@ function Ht(e) {
|
|
|
257
257
|
}, [b.length, s, A]);
|
|
258
258
|
const [X, M] = De(
|
|
259
259
|
t ? (Ue = S[0]) == null ? void 0 : Ue.value : null
|
|
260
|
-
), ct = e.maxSelections || G.length + 1, Pe = b.findIndex((
|
|
260
|
+
), ct = e.maxSelections || G.length + 1, Pe = b.findIndex((l) => l.value === X), Ne = Pt(
|
|
261
261
|
Pe,
|
|
262
262
|
b,
|
|
263
263
|
!!e.rollNavigation
|
|
@@ -266,30 +266,30 @@ function Ht(e) {
|
|
|
266
266
|
b,
|
|
267
267
|
!!e.rollNavigation
|
|
268
268
|
), D = Et(b), je = Te(b), He = !b.some(
|
|
269
|
-
(
|
|
269
|
+
(l) => l.value === X
|
|
270
270
|
);
|
|
271
271
|
j(() => {
|
|
272
|
-
var
|
|
273
|
-
He && M(t ? (
|
|
272
|
+
var l;
|
|
273
|
+
He && M(t ? (l = S[0]) == null ? void 0 : l.value : null);
|
|
274
274
|
}, [He]), j(() => {
|
|
275
275
|
t && M(D == null ? void 0 : D.value);
|
|
276
276
|
}, [t, M, _, D == null ? void 0 : D.value]), j(() => {
|
|
277
|
-
var
|
|
278
|
-
!A && t && M((
|
|
277
|
+
var l;
|
|
278
|
+
!A && t && M((l = S[0]) == null ? void 0 : l.value);
|
|
279
279
|
}, [A]), j(() => {
|
|
280
280
|
A && v && ae(!0);
|
|
281
281
|
}, [A, v, ae]), j(() => {
|
|
282
|
-
const
|
|
282
|
+
const l = S.find((c) => c.value === X);
|
|
283
283
|
h(e.onOptionFocus, {
|
|
284
|
-
item:
|
|
284
|
+
item: l,
|
|
285
285
|
focusMethod: Y.current,
|
|
286
|
-
isNewInput:
|
|
286
|
+
isNewInput: l == null ? void 0 : l.creatable
|
|
287
287
|
});
|
|
288
288
|
}, [X, e.onOptionFocus]);
|
|
289
|
-
const Le = (
|
|
289
|
+
const Le = (l) => {
|
|
290
290
|
var I, R;
|
|
291
|
-
const c = b.find((x) => x.value ===
|
|
292
|
-
|
|
291
|
+
const c = b.find((x) => x.value === l), m = (c == null ? void 0 : c.label) || (c == null ? void 0 : c.value);
|
|
292
|
+
re(() => d ? "" : m ?? ""), !G.includes(l) && G.length < ct && Ie((x) => d ? [...x, l] : [l]), d && ((I = F.current) == null || I.focus()), e.focusInputOnSelect && ((R = F.current) == null || R.focus()), h(e.onSelectOption, {
|
|
293
293
|
item: c,
|
|
294
294
|
selectMethod: Y.current,
|
|
295
295
|
isNewInput: c == null ? void 0 : c.creatable
|
|
@@ -297,22 +297,22 @@ function Ht(e) {
|
|
|
297
297
|
item: ye(c, ["noFilter"]),
|
|
298
298
|
selectMethod: Y.current
|
|
299
299
|
}), C && z();
|
|
300
|
-
}, Ke = (
|
|
300
|
+
}, Ke = (l, c) => {
|
|
301
301
|
var R;
|
|
302
302
|
Ie((x) => {
|
|
303
|
-
let B = S.find((W) => W.value ===
|
|
304
|
-
return !B && r === !0 && (B = { label:
|
|
303
|
+
let B = S.find((W) => W.value === l);
|
|
304
|
+
return !B && r === !0 && (B = { label: l, value: l }), B ? (h(e.onTagRemoved, l, B, x), x.filter((W) => W !== l)) : x;
|
|
305
305
|
});
|
|
306
|
-
const m = S.find((x) => x.value ===
|
|
307
|
-
_ === I &&
|
|
308
|
-
}, ft = (
|
|
306
|
+
const m = S.find((x) => x.value === l), I = (m == null ? void 0 : m.label) || (m == null ? void 0 : m.value);
|
|
307
|
+
_ === I && re(""), c && ((R = F.current) == null || R.focus());
|
|
308
|
+
}, ft = (l) => {
|
|
309
309
|
var c;
|
|
310
|
-
Ie([]),
|
|
311
|
-
}, Qe = d ? G.map((
|
|
310
|
+
Ie([]), l && ((c = F.current) == null || c.focus());
|
|
311
|
+
}, Qe = d ? G.map((l) => {
|
|
312
312
|
var c;
|
|
313
313
|
return {
|
|
314
|
-
label: ((c = S.find((m) => m.value === (
|
|
315
|
-
onRemove: () => Ke(
|
|
314
|
+
label: ((c = S.find((m) => m.value === (l == null ? void 0 : l.toString()))) == null ? void 0 : c.label) || l,
|
|
315
|
+
onRemove: () => Ke(l)
|
|
316
316
|
};
|
|
317
317
|
}) : [];
|
|
318
318
|
return j(() => {
|
|
@@ -324,17 +324,17 @@ function Ht(e) {
|
|
|
324
324
|
filteredResults: Ee,
|
|
325
325
|
focusedValue: X,
|
|
326
326
|
defaultEmptyStateProps: u,
|
|
327
|
-
getEmptyStateProps: (
|
|
327
|
+
getEmptyStateProps: (l) => {
|
|
328
328
|
if (b.every((m) => m.noFilter) && s && !r)
|
|
329
|
-
return typeof s == "boolean" ?
|
|
329
|
+
return typeof s == "boolean" ? l : h(s, { query: _ });
|
|
330
330
|
},
|
|
331
|
-
getGroupProps: (
|
|
332
|
-
const c = $t(
|
|
331
|
+
getGroupProps: (l) => {
|
|
332
|
+
const c = $t(l.children, b);
|
|
333
333
|
return {
|
|
334
334
|
divider: {
|
|
335
|
-
hasFirstChild: zt(
|
|
335
|
+
hasFirstChild: zt(l.children, D),
|
|
336
336
|
hasLastChild: Bt(
|
|
337
|
-
|
|
337
|
+
l.children,
|
|
338
338
|
Te(b.filter((m) => me(m == null ? void 0 : m.noFilter)))
|
|
339
339
|
)
|
|
340
340
|
},
|
|
@@ -343,8 +343,8 @@ function Ht(e) {
|
|
|
343
343
|
}
|
|
344
344
|
};
|
|
345
345
|
},
|
|
346
|
-
getInputProps: (
|
|
347
|
-
const { onBlur: m, onChange: I, onFocus: R, onKeyDown: x, variant: B, ...W } =
|
|
346
|
+
getInputProps: (l, c) => {
|
|
347
|
+
const { onBlur: m, onChange: I, onFocus: R, onKeyDown: x, variant: B, ...W } = l;
|
|
348
348
|
return {
|
|
349
349
|
wrapper: {
|
|
350
350
|
ref: Be,
|
|
@@ -363,19 +363,19 @@ function Ht(e) {
|
|
|
363
363
|
onBlur: (p) => {
|
|
364
364
|
var Q, pe;
|
|
365
365
|
h(m, p);
|
|
366
|
-
const w = p.relatedTarget === (
|
|
366
|
+
const w = p.relatedTarget === (ne == null ? void 0 : ne.current) || ((Q = ne.current) == null ? void 0 : Q.contains(p.relatedTarget)), g = (pe = Be.current) == null ? void 0 : pe.contains(
|
|
367
367
|
p.relatedTarget
|
|
368
368
|
);
|
|
369
|
-
if (!w && !g && (n && z(), !G.includes(p.target.value) &&
|
|
369
|
+
if (!w && !g && (n && z(), !G.includes(p.target.value) && ie)) {
|
|
370
370
|
const k = Te(G), $ = S.find(
|
|
371
|
-
(
|
|
371
|
+
(oe) => oe.value === k
|
|
372
372
|
), Fe = ($ == null ? void 0 : $.label) || ($ == null ? void 0 : $.value) || "";
|
|
373
|
-
|
|
373
|
+
re(Fe);
|
|
374
374
|
}
|
|
375
375
|
},
|
|
376
376
|
onChange: (p) => {
|
|
377
377
|
const w = p.target.value;
|
|
378
|
-
h(I, p),
|
|
378
|
+
h(I, p), re(w);
|
|
379
379
|
const g = We(w);
|
|
380
380
|
h(Se, w) && (!g || xe) ? V() : z(), ae(!1);
|
|
381
381
|
},
|
|
@@ -416,7 +416,7 @@ function Ht(e) {
|
|
|
416
416
|
}
|
|
417
417
|
};
|
|
418
418
|
},
|
|
419
|
-
getItemProps: (
|
|
419
|
+
getItemProps: (l, c) => {
|
|
420
420
|
var Ve;
|
|
421
421
|
const {
|
|
422
422
|
_fixed: m,
|
|
@@ -431,23 +431,23 @@ function Ht(e) {
|
|
|
431
431
|
onMouseOver: Q,
|
|
432
432
|
//sx,
|
|
433
433
|
...pe
|
|
434
|
-
} =
|
|
434
|
+
} = l, k = c ? W : (Ve = w(W)) == null ? void 0 : Ve.toString(), $ = k === X, Fe = b.findIndex((se) => se.value === k) >= 0, oe = R || B || k;
|
|
435
435
|
return {
|
|
436
436
|
item: {
|
|
437
|
-
...typeof
|
|
437
|
+
...typeof oe != "string" || !o ? { children: oe } : {
|
|
438
438
|
dangerouslySetInnerHTML: {
|
|
439
|
-
__html: _t(
|
|
439
|
+
__html: _t(oe, _)
|
|
440
440
|
}
|
|
441
441
|
},
|
|
442
442
|
"aria-selected": G.includes(k),
|
|
443
443
|
"aria-disabled": x,
|
|
444
444
|
_disabled: { opacity: 0.4, cursor: "not-allowed", userSelect: "none" },
|
|
445
|
-
onMouseDown: (
|
|
445
|
+
onMouseDown: (se) => {
|
|
446
446
|
var Ye;
|
|
447
|
-
h(g,
|
|
447
|
+
h(g, se), x ? (Ye = F.current) == null || Ye.focus() : Le(k);
|
|
448
448
|
},
|
|
449
|
-
onMouseOver: (
|
|
450
|
-
h(Q,
|
|
449
|
+
onMouseOver: (se) => {
|
|
450
|
+
h(Q, se), M(k), Y.current = "mouse";
|
|
451
451
|
},
|
|
452
452
|
sx: {
|
|
453
453
|
//...sx,
|
|
@@ -474,26 +474,26 @@ function Ht(e) {
|
|
|
474
474
|
isLoading: we,
|
|
475
475
|
isOpen: A,
|
|
476
476
|
itemList: S,
|
|
477
|
-
listRef:
|
|
477
|
+
listRef: ne,
|
|
478
478
|
onClose: z,
|
|
479
479
|
onOpen: V,
|
|
480
|
-
placement:
|
|
480
|
+
placement: te,
|
|
481
481
|
query: _,
|
|
482
482
|
removeItem: Ke,
|
|
483
483
|
resetItems: ft,
|
|
484
|
-
setQuery:
|
|
484
|
+
setQuery: re,
|
|
485
485
|
tags: Qe,
|
|
486
486
|
value: K,
|
|
487
487
|
values: G
|
|
488
488
|
};
|
|
489
489
|
}
|
|
490
|
-
var
|
|
490
|
+
var lt = {
|
|
491
491
|
color: void 0,
|
|
492
492
|
size: void 0,
|
|
493
493
|
className: void 0,
|
|
494
494
|
style: void 0,
|
|
495
495
|
attr: void 0
|
|
496
|
-
}, qe = P.createContext && /* @__PURE__ */ P.createContext(
|
|
496
|
+
}, qe = P.createContext && /* @__PURE__ */ P.createContext(lt), Kt = ["attr", "size", "title"];
|
|
497
497
|
function Qt(e, t) {
|
|
498
498
|
if (e == null) return {};
|
|
499
499
|
var n = Ut(e, t), r, o;
|
|
@@ -562,15 +562,15 @@ function Xt(e, t) {
|
|
|
562
562
|
}
|
|
563
563
|
return (t === "string" ? String : Number)(e);
|
|
564
564
|
}
|
|
565
|
-
function
|
|
565
|
+
function it(e) {
|
|
566
566
|
return e && e.map((t, n) => /* @__PURE__ */ P.createElement(t.tag, he({
|
|
567
567
|
key: n
|
|
568
|
-
}, t.attr),
|
|
568
|
+
}, t.attr), it(t.child)));
|
|
569
569
|
}
|
|
570
570
|
function Jt(e) {
|
|
571
571
|
return (t) => /* @__PURE__ */ P.createElement(Zt, ge({
|
|
572
572
|
attr: he({}, e.attr)
|
|
573
|
-
}, t),
|
|
573
|
+
}, t), it(e.child));
|
|
574
574
|
}
|
|
575
575
|
function Zt(e) {
|
|
576
576
|
var t = (n) => {
|
|
@@ -578,7 +578,7 @@ function Zt(e) {
|
|
|
578
578
|
attr: r,
|
|
579
579
|
size: o,
|
|
580
580
|
title: s
|
|
581
|
-
} = e, u = Qt(e, Kt),
|
|
581
|
+
} = e, u = Qt(e, Kt), i = o || n.size || "1em", f;
|
|
582
582
|
return n.className && (f = n.className), e.className && (f = (f ? f + " " : "") + e.className), /* @__PURE__ */ P.createElement("svg", ge({
|
|
583
583
|
stroke: "currentColor",
|
|
584
584
|
fill: "currentColor",
|
|
@@ -588,12 +588,12 @@ function Zt(e) {
|
|
|
588
588
|
style: he(he({
|
|
589
589
|
color: e.color || n.color
|
|
590
590
|
}, n.style), e.style),
|
|
591
|
-
height:
|
|
592
|
-
width:
|
|
591
|
+
height: i,
|
|
592
|
+
width: i,
|
|
593
593
|
xmlns: "http://www.w3.org/2000/svg"
|
|
594
594
|
}), s && /* @__PURE__ */ P.createElement("title", null, s), e.children);
|
|
595
595
|
};
|
|
596
|
-
return qe !== void 0 ? /* @__PURE__ */ P.createElement(qe.Consumer, null, (n) => t(n)) : t(
|
|
596
|
+
return qe !== void 0 ? /* @__PURE__ */ P.createElement(qe.Consumer, null, (n) => t(n)) : t(lt);
|
|
597
597
|
}
|
|
598
598
|
function qt(e) {
|
|
599
599
|
return Jt({ attr: { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, child: [{ tag: "path", attr: { d: "M18 6 6 18" }, child: [] }, { tag: "path", attr: { d: "m6 6 12 12" }, child: [] }] })(e);
|
|
@@ -634,7 +634,7 @@ const on = U(
|
|
|
634
634
|
isOpen: o,
|
|
635
635
|
onClose: s,
|
|
636
636
|
onOpen: u,
|
|
637
|
-
placement:
|
|
637
|
+
placement: i,
|
|
638
638
|
resetItems: f,
|
|
639
639
|
removeItem: v
|
|
640
640
|
} = n;
|
|
@@ -648,7 +648,7 @@ const on = U(
|
|
|
648
648
|
{
|
|
649
649
|
open: o,
|
|
650
650
|
autoFocus: !1,
|
|
651
|
-
positioning: { placement:
|
|
651
|
+
positioning: { placement: i, sameWidth: y },
|
|
652
652
|
present: o,
|
|
653
653
|
children: /* @__PURE__ */ a(bt.div, { w: "full", ref: t, children: r })
|
|
654
654
|
}
|
|
@@ -662,7 +662,7 @@ const sn = U(
|
|
|
662
662
|
focusedValue: n,
|
|
663
663
|
getItemProps: r,
|
|
664
664
|
interactionRef: o
|
|
665
|
-
} = H(), s =
|
|
665
|
+
} = H(), s = le(), u = ke(t, s), i = r(e), { isValidSuggestion: f, value: v } = i.root, y = n === v;
|
|
666
666
|
j(() => {
|
|
667
667
|
var T;
|
|
668
668
|
y && o.current === "keyboard" && ((T = s == null ? void 0 : s.current) == null || T.scrollIntoView({
|
|
@@ -674,7 +674,7 @@ const sn = U(
|
|
|
674
674
|
"You must define the `getValue` prop, when an Item's value is not a string"
|
|
675
675
|
);
|
|
676
676
|
}, []);
|
|
677
|
-
const { children: d, dangerouslySetInnerHTML: C, ...E } =
|
|
677
|
+
const { children: d, dangerouslySetInnerHTML: C, ...E } = i.item, O = ye(E, ["groupId"]);
|
|
678
678
|
return f ? /* @__PURE__ */ a(ve, { ref: u, ...ut, ...O, children: d || /* @__PURE__ */ a("span", { dangerouslySetInnerHTML: C }) }) : null;
|
|
679
679
|
}
|
|
680
680
|
);
|
|
@@ -691,7 +691,7 @@ function ln(e) {
|
|
|
691
691
|
autoCompleteProps: o,
|
|
692
692
|
getItemProps: s,
|
|
693
693
|
query: u,
|
|
694
|
-
filteredResults:
|
|
694
|
+
filteredResults: i
|
|
695
695
|
} = H(), { children: f, ...v } = s(
|
|
696
696
|
{
|
|
697
697
|
...e,
|
|
@@ -701,14 +701,14 @@ function ln(e) {
|
|
|
701
701
|
})
|
|
702
702
|
},
|
|
703
703
|
!0
|
|
704
|
-
).item, y =
|
|
704
|
+
).item, y = i.some((E) => E.value === u), d = We(u) ? t : !0;
|
|
705
705
|
return o.creatable && d && !y ? /* @__PURE__ */ a(ve, { ...ut, ...v, ...r, children: f || `Add ${u}` }) : null;
|
|
706
706
|
}
|
|
707
707
|
ln.displayName = "AutoCompleteCreatable";
|
|
708
708
|
const un = U(
|
|
709
709
|
(e, t) => {
|
|
710
|
-
const { children: n, showDivider: r, ...o } = e, s = ye(o, ["groupSibling"]), { getGroupProps: u } = H(), { group:
|
|
711
|
-
return /* @__PURE__ */ q(_e, { ref: t, ...
|
|
710
|
+
const { children: n, showDivider: r, ...o } = e, s = ye(o, ["groupSibling"]), { getGroupProps: u } = H(), { group: i } = u(e), f = fn(e);
|
|
711
|
+
return /* @__PURE__ */ q(_e, { ref: t, ...i, ...s, children: [
|
|
712
712
|
/* @__PURE__ */ a(Xe, { ...f.top }),
|
|
713
713
|
n,
|
|
714
714
|
/* @__PURE__ */ a(Xe, { ...f.bottom })
|
|
@@ -736,11 +736,11 @@ const cn = {
|
|
|
736
736
|
...s,
|
|
737
737
|
mb: 4,
|
|
738
738
|
display: !e.showDivider || r ? "none" : ""
|
|
739
|
-
},
|
|
739
|
+
}, i = {
|
|
740
740
|
...s,
|
|
741
741
|
display: !e.showDivider || o || n ? "none" : ""
|
|
742
742
|
};
|
|
743
|
-
return { top: u, bottom:
|
|
743
|
+
return { top: u, bottom: i };
|
|
744
744
|
}, pn = L.forwardRef(
|
|
745
745
|
function(t, n) {
|
|
746
746
|
const {
|
|
@@ -748,19 +748,19 @@ const cn = {
|
|
|
748
748
|
startElementProps: o,
|
|
749
749
|
endElement: s,
|
|
750
750
|
endElementProps: u,
|
|
751
|
-
children:
|
|
751
|
+
children: i,
|
|
752
752
|
startOffset: f = "6px",
|
|
753
753
|
endOffset: v = "6px",
|
|
754
754
|
...y
|
|
755
755
|
} = t;
|
|
756
756
|
return /* @__PURE__ */ q(Ct, { ref: n, ...y, children: [
|
|
757
757
|
r && /* @__PURE__ */ a(Je, { pointerEvents: "none", ...o, children: r }),
|
|
758
|
-
L.cloneElement(
|
|
758
|
+
L.cloneElement(i, {
|
|
759
759
|
...r && {
|
|
760
760
|
ps: `calc(var(--input-height) - ${f})`
|
|
761
761
|
},
|
|
762
762
|
...s && { pe: `calc(var(--input-height) - ${v})` },
|
|
763
|
-
...
|
|
763
|
+
...i.props
|
|
764
764
|
}),
|
|
765
765
|
s && /* @__PURE__ */ a(Je, { placement: "end", ...u, children: s })
|
|
766
766
|
] });
|
|
@@ -776,7 +776,7 @@ const cn = {
|
|
|
776
776
|
getInputProps: o,
|
|
777
777
|
tags: s,
|
|
778
778
|
setQuery: u,
|
|
779
|
-
value:
|
|
779
|
+
value: i,
|
|
780
780
|
itemList: f
|
|
781
781
|
} = H(), {
|
|
782
782
|
children: v,
|
|
@@ -784,31 +784,31 @@ const cn = {
|
|
|
784
784
|
...d
|
|
785
785
|
} = e, { value: C } = d;
|
|
786
786
|
j(() => {
|
|
787
|
-
if (
|
|
788
|
-
const ue = f.find((K) => K.value ===
|
|
787
|
+
if (i !== void 0 && (typeof i == "string" || i instanceof String)) {
|
|
788
|
+
const ue = f.find((K) => K.value === i), xe = ue === void 0 ? i : ue.label;
|
|
789
789
|
u(xe);
|
|
790
790
|
}
|
|
791
|
-
}, [
|
|
791
|
+
}, [i]), j(() => {
|
|
792
792
|
C !== void 0 && (typeof C == "string" || C instanceof String) && u(C);
|
|
793
793
|
}, [C]);
|
|
794
794
|
const E = {};
|
|
795
795
|
let { wrapper: O, input: T } = o(d, E);
|
|
796
|
-
const { ref: Ce, ...
|
|
796
|
+
const { ref: Ce, ...ee } = O, we = ke(t, r), te = h(v, { tags: s });
|
|
797
797
|
y && (T = {
|
|
798
798
|
...T,
|
|
799
|
-
placeholder: Array.isArray(
|
|
799
|
+
placeholder: Array.isArray(te) && te.length ? void 0 : T.placeholder
|
|
800
800
|
});
|
|
801
|
-
const
|
|
801
|
+
const ie = /* @__PURE__ */ a(
|
|
802
802
|
dn,
|
|
803
803
|
{
|
|
804
804
|
...T,
|
|
805
805
|
ref: we
|
|
806
806
|
}
|
|
807
|
-
), Se = /* @__PURE__ */ q(_e, { ...
|
|
808
|
-
|
|
809
|
-
|
|
807
|
+
), Se = /* @__PURE__ */ q(_e, { ...ee, ref: Ce, children: [
|
|
808
|
+
te,
|
|
809
|
+
ie
|
|
810
810
|
] });
|
|
811
|
-
return /* @__PURE__ */ a(St, { children: n.multiple ? Se :
|
|
811
|
+
return /* @__PURE__ */ a(St, { w: "full", ...ee, children: n.multiple ? Se : ie });
|
|
812
812
|
}
|
|
813
813
|
);
|
|
814
814
|
mn.displayName = "Input";
|
|
@@ -831,9 +831,9 @@ const gn = (e) => {
|
|
|
831
831
|
const t = P.Children.map(e, (o, s) => {
|
|
832
832
|
var u;
|
|
833
833
|
if (((u = o == null ? void 0 : o.type) == null ? void 0 : u.displayName) === "AutoCompleteGroup") {
|
|
834
|
-
const
|
|
834
|
+
const i = P.Children.toArray(e)[s + 1];
|
|
835
835
|
return P.cloneElement(o, {
|
|
836
|
-
groupSibling:
|
|
836
|
+
groupSibling: i ? i.type.displayName === "AutoCompleteGroup" : !1
|
|
837
837
|
});
|
|
838
838
|
}
|
|
839
839
|
return o;
|
|
@@ -855,8 +855,8 @@ const gn = (e) => {
|
|
|
855
855
|
), n];
|
|
856
856
|
}, yn = U(
|
|
857
857
|
(e, t) => {
|
|
858
|
-
const { children: n, loadingState: r, ...o } = e, { listRef: s, isLoading: u } = H(),
|
|
859
|
-
return /* @__PURE__ */ a(tn, { width: "auto", children: /* @__PURE__ */ q(rn, { ref:
|
|
858
|
+
const { children: n, loadingState: r, ...o } = e, { listRef: s, isLoading: u } = H(), i = ke(t, s), [f, v] = vn(n);
|
|
859
|
+
return /* @__PURE__ */ a(tn, { width: "auto", children: /* @__PURE__ */ q(rn, { ref: i, w: "inherit", ...bn, ...o, children: [
|
|
860
860
|
u && /* @__PURE__ */ a(xt, { children: r || /* @__PURE__ */ a(nt, { size: "md" }) }),
|
|
861
861
|
!u && /* @__PURE__ */ q(pt, { children: [
|
|
862
862
|
f,
|
|
@@ -891,12 +891,12 @@ const bn = {
|
|
|
891
891
|
endElement: o,
|
|
892
892
|
onClose: s,
|
|
893
893
|
closable: u = !!s,
|
|
894
|
-
children:
|
|
894
|
+
children: i,
|
|
895
895
|
...f
|
|
896
896
|
} = t;
|
|
897
897
|
return /* @__PURE__ */ q(J.Root, { ref: n, ...f, children: [
|
|
898
898
|
r && /* @__PURE__ */ a(J.StartElement, { children: r }),
|
|
899
|
-
/* @__PURE__ */ a(J.Label, { children:
|
|
899
|
+
/* @__PURE__ */ a(J.Label, { children: i }),
|
|
900
900
|
o && /* @__PURE__ */ a(J.EndElement, { children: o }),
|
|
901
901
|
u && /* @__PURE__ */ a(J.EndElement, { children: /* @__PURE__ */ a(J.CloseTrigger, { onClick: s }) })
|
|
902
902
|
] });
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),i=require("react"),f=require("@chakra-ui/react");function ct(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 T=ct(i),[Qe,B]=Ue();function Ue(){const e=T.createContext(void 0);e.displayName="AutoCompleteContext";function t(){var o;const n=T.useContext(e),r="useAutoCompleteContext: `context` is undefined. Seems you forgot to wrap all autoomplete components within `<AutoComplete />`";if(!n){const s=new Error(r);throw s.name="ContextError",(o=Error.captureStackTrace)==null||o.call(Error,s,t),s}return n}return[e.Provider,t,e]}function ft(e){return e==null?void 0:e[0]}function Pe(e){return e!=null&&e.length?e[e.length-1]:void 0}function Ve(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 pt(e,t,n=!0){return Ve(e,t,-1,n)}function dt(e,t,n=!0){const r=Ve(e,t.length,1,n);return t[r]}function mt(e,t,n=!0){const r=pt(e,t.length,n);return t[r]}function Oe(e){return Array.isArray(e)}function gt(e){return Oe(e)&&e.length===0}function Ie(e){return e!==null&&typeof e=="object"&&!Oe(e)}function vt(e){return Ie(e)&&Object.keys(e).length===0}function Re(e){return Oe(e)?gt(e):Ie(e)?vt(e):e==null||e===""}function ue(e){return typeof e>"u"}function Ye(e){return typeof e<"u"}function ht(e,t){const n={};return t.forEach(r=>{r in e&&(n[r]=e[r])}),n}function fe(e,t){const n={...e};return t.forEach(r=>{delete n[r]}),n}function bt(e){return typeof e=="function"}function b(e,...t){return bt(e)?e(...t):e}function yt(e,t){if(e!=null){if(typeof e=="function"){e(t);return}try{e.current=t}catch{throw new Error(`Cannot assign value '${t}' to ref '${e}'`)}}}function xt(...e){return t=>{e.forEach(n=>{yt(n,t)})}}function Te(...e){return i.useMemo(()=>xt(...e),e)}var pe=function(e,t){for(var n,r=T.Children.toArray(e),o=0,s=r;o<s.length;o++){var a=s[o];if(t(a))return a;if(!((n=a.props)===null||n===void 0)&&n.children){var u=pe(a.props.children,t);if(u)return u}}},ie=function(e,t){for(var n=0,r=t.length,o=e.length;n<r;n++,o++)e[o]=t[n];return e},Xe=function(e,t){for(var n,r=T.Children.toArray(e),o=[],s=0,a=r;s<a.length;s++){var u=a[s];t(u)&&(o=ie(ie([],o),[u])),!((n=u.props)===null||n===void 0)&&n.children&&(o=ie(ie([],o),Xe(u.props.children,t)))}return o};function ze(e,t,n=2){function r(g,w){g=" ".repeat(w-1)+g.toLowerCase()+" ".repeat(w-1);let O=new Array(g.length-w+1);for(let E=0;E<O.length;E++)O[E]=g.slice(E,E+w);return O}if(!(e!=null&&e.length)||!(t!=null&&t.length))return 0;let o=e.length<t.length?e:t,s=e.length<t.length?t:e,a=r(o,n),u=r(s,n),d=new Set(a),y=u.length,x=0;for(let g of u)d.delete(g)&&x++;return x/y}const Ne=e=>{var t;return(t=typeof e=="string"||typeof e=="number"?e:e[Object.keys(e)[0]])==null?void 0:t.toString()},Ct=(e,t)=>typeof e!="string"||Re(t)?e:e.toString().replace(new RegExp(At(t),"gi"),r=>`<mark>${r}</mark>`),wt=e=>Xe(e,n=>{var r;return((r=n==null?void 0:n.type)==null?void 0:r.displayName)==="AutoCompleteItem"}).map(n=>{const r=ht(n.props,["value","label","fixed","disabled"]),{getValue:o=Ne}=n.props,s=o(r.value);return{...Ye(r.label)?r:{...r,label:s},value:s,originalValue:r.value}}),jt=()=>({bg:"whiteAlpha.100",_light:{bg:"gray.200"}}),St=(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 At(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}const Et=(e,t)=>pe(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)}),Pt=(e,t)=>pe(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)}),Ot=(e,t)=>Ye(pe(e,n=>{var o,s;const r=b(((o=n.props)==null?void 0:o.getValue)||Ne,((s=n.props)==null?void 0:s.value)||{});return t.some(a=>a.value===r)}));function Je(e){var ke;let{prefocusFirstItem:t=!0,closeOnBlur:n=!0,creatable:r,emphasize:o,emptyState:s=!0,defaultEmptyStateProps:a={},freeSolo:u,isReadOnly:d,listAllValuesOnFocus:y,maxSuggestions:x,multiple:g,closeOnSelect:w=!g,defaultValue:O,defaultValues:E=O?[O]:[],onReady:L,defaultIsOpen:de,disableFilter:ee,isLoading:me=!1,placement:Y="bottom",restoreOnBlurIfEmpty:te=!u,shouldRenderSuggestions:ge=()=>!0,submitKeys:ne=[],suggestWhenEmpty:ve,value:H,values:he=H?typeof H=="string"?[H]:[...H]:void 0}=e;u=u||(g?!0:e.freeSolo);const{open:P,onClose:W,onOpen:Q}=f.useDisclosure({open:de}),be=i.useMemo(()=>b(e.children,{isOpen:P,onClose:W,onOpen:Q}),[e.children,P]),S=i.useMemo(()=>wt(be),[be]),N=i.useRef(null),Le=i.useRef(null),X=i.useRef(null),U=i.useRef(null),[De,re]=i.useState(!1);let oe="";g?oe="":ue(E)?ue(he)||(oe=he[0]):oe=E[0];const[D,J]=i.useState(oe??""),ye=i.useMemo(()=>ee?S:S.filter(l=>l.fixed||b(e.filter||St,D,l.value,l.label)||De).filter((l,p)=>x?l.fixed||p<x:!0),[D,S,De,x,ee]),se=r?[{value:D,noFilter:!0,creatable:!0}]:[],C=i.useMemo(()=>[...ye,...se],[ye,se]),it=i.useMemo(()=>[...S,...se],[S,se]),[M,xe]=f.useControllableState({defaultValue:E.map(l=>l==null?void 0:l.toString()),value:he,onChange:l=>{const p=C.find(I=>I.value===l.at(-1));if(!p)return;const v=l.map(I=>it.find(R=>R.value===I));b(e.onChange,g?l:l[0],g?v:p)}});i.useEffect(()=>{C.length===0&&!s&&P&&W()},[C.length,s,P]);const[V,_]=i.useState(t?(ke=S[0])==null?void 0:ke.value:null),ut=e.maxSelections||M.length+1,Ce=C.findIndex(l=>l.value===V),we=dt(Ce,C,!!e.rollNavigation),je=mt(Ce,C,!!e.rollNavigation),F=ft(C),Se=Pe(C),Me=!C.some(l=>l.value===V);i.useEffect(()=>{var l;Me&&_(t?(l=S[0])==null?void 0:l.value:null)},[Me]),i.useEffect(()=>{t&&_(F==null?void 0:F.value)},[t,_,D,F==null?void 0:F.value]),i.useEffect(()=>{var l;!P&&t&&_((l=S[0])==null?void 0:l.value)},[P]),i.useEffect(()=>{P&&y&&re(!0)},[P,y,re]),i.useEffect(()=>{const l=S.find(p=>p.value===V);b(e.onOptionFocus,{item:l,focusMethod:U.current,isNewInput:l==null?void 0:l.creatable})},[V,e.onOptionFocus]);const Ae=l=>{var I,R;const p=C.find(A=>A.value===l),v=(p==null?void 0:p.label)||(p==null?void 0:p.value);J(()=>g?"":v??""),!M.includes(l)&&M.length<ut&&xe(A=>g?[...A,l]:[l]),g&&((I=N.current)==null||I.focus()),e.focusInputOnSelect&&((R=N.current)==null||R.focus()),b(e.onSelectOption,{item:p,selectMethod:U.current,isNewInput:p==null?void 0:p.creatable}),p!=null&&p.creatable&&b(e.onCreateOption,{item:fe(p,["noFilter"]),selectMethod:U.current}),w&&W()},_e=(l,p)=>{var R;xe(A=>{let z=S.find(G=>G.value===l);return!z&&r===!0&&(z={label:l,value:l}),z?(b(e.onTagRemoved,l,z,A),A.filter(G=>G!==l)):A});const v=S.find(A=>A.value===l),I=(v==null?void 0:v.label)||(v==null?void 0:v.value);D===I&&J(""),p&&((R=N.current)==null||R.focus())},at=l=>{var p;xe([]),l&&((p=N.current)==null||p.focus())},Ge=g?M.map(l=>{var p;return{label:((p=S.find(v=>v.value===(l==null?void 0:l.toString())))==null?void 0:p.label)||l,onRemove:()=>_e(l)}}):[];return i.useEffect(()=>{b(L,{tags:Ge})},[M]),{autoCompleteProps:e,children:be,filteredList:C,filteredResults:ye,focusedValue:V,defaultEmptyStateProps:a,getEmptyStateProps:l=>{if(C.every(v=>v.noFilter)&&s&&!r)return typeof s=="boolean"?l:b(s,{query:D})},getGroupProps:l=>{const p=Ot(l.children,C);return{divider:{hasFirstChild:Et(l.children,F),hasLastChild:Pt(l.children,Pe(C.filter(v=>ue(v==null?void 0:v.noFilter))))},group:{display:p?"initial":"none"}}},getInputProps:(l,p)=>{const{onBlur:v,onChange:I,onFocus:R,onKeyDown:A,variant:z,...G}=l;return{wrapper:{ref:Le,onClick:()=>{var m;(m=N==null?void 0:N.current)==null||m.focus()},...G},input:{isReadOnly:d,onFocus:m=>{b(R,m),e.openOnFocus&&!d&&Q(),e.selectOnFocus&&m.target.select(),y&&re(!0)},onBlur:m=>{var K,le;b(v,m);const j=m.relatedTarget===(X==null?void 0:X.current)||((K=X.current)==null?void 0:K.contains(m.relatedTarget)),h=(le=Le.current)==null?void 0:le.contains(m.relatedTarget);if(!j&&!h&&(n&&W(),!M.includes(m.target.value)&&te)){const k=Pe(M),$=S.find(Z=>Z.value===k),Ee=($==null?void 0:$.label)||($==null?void 0:$.value)||"";J(Ee)}},onChange:m=>{const j=m.target.value;b(I,m),J(j);const h=Re(j);b(ge,j)&&(!h||ve)?Q():W(),re(!1)},onKeyDown:m=>{var K;b(A,m),U.current="keyboard";const{key:j}=m,h=C[Ce];if(["Enter",...ne].includes(j)){h&&!(h!=null&&h.disabled)&&P?Ae(h==null?void 0:h.value):(K=N.current)==null||K.focus(),m.preventDefault();return}if(j==="ArrowDown"){P?_(we==null?void 0:we.value):Q(),m.preventDefault();return}if(j==="ArrowUp"){P?_(je==null?void 0:je.value):Q(),m.preventDefault();return}if(j==="Tab"){P&&h&&!(h!=null&&h.disabled)?Ae(h==null?void 0:h.value):W();return}if(j==="Home"){_(F==null?void 0:F.value),m.preventDefault();return}if(j==="End"){_(Se==null?void 0:Se.value),m.preventDefault();return}j==="Escape"&&(W(),m.preventDefault())},value:D,variant:z,...G}}},getItemProps:(l,p)=>{var Be;const{_fixed:v,_focus:I,children:R,disabled:A,label:z,value:G,fixed:m,getValue:j=Ne,onClick:h,onMouseOver:K,...le}=l,k=p?G:(Be=j(G))==null?void 0:Be.toString(),$=k===V,Ee=C.findIndex(q=>q.value===k)>=0,Z=R||z||k;return{item:{...typeof Z!="string"||!o?{children:Z}:{dangerouslySetInnerHTML:{__html:Ct(Z,D)}},"aria-selected":M.includes(k),"aria-disabled":A,_disabled:{opacity:.4,cursor:"not-allowed",userSelect:"none"},onMouseDown:q=>{var We;b(h,q),A?(We=N.current)==null||We.focus():Ae(k)},onMouseOver:q=>{b(K,q),_(k),U.current="mouse"},sx:{mark:{color:"inherit",bg:"transparent",...Ie(o)?o:{fontWeight:o?"extrabold":"inherit"}}},...$&&(I||jt()),...m&&v,...le},root:{isValidSuggestion:Ee,value:k}}},inputRef:N,interactionRef:U,isLoading:me,isOpen:P,itemList:S,listRef:X,onClose:W,onOpen:Q,placement:Y,query:D,removeItem:_e,resetItems:at,setQuery:J,tags:Ge,value:H,values:M}}var Ze={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},$e=i.createContext&&i.createContext(Ze),It=["attr","size","title"];function Rt(e,t){if(e==null)return{};var n=Tt(e,t),r,o;if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(o=0;o<s.length;o++)r=s[o],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function Tt(e,t){if(e==null)return{};var n={};for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){if(t.indexOf(r)>=0)continue;n[r]=e[r]}return n}function ae(){return ae=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},ae.apply(this,arguments)}function He(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),n.push.apply(n,r)}return n}function ce(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?He(Object(n),!0).forEach(function(r){Nt(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):He(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function Nt(e,t,n){return t=Ft(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ft(e){var t=Lt(e,"string");return typeof t=="symbol"?t:t+""}function Lt(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function qe(e){return e&&e.map((t,n)=>i.createElement(t.tag,ce({key:n},t.attr),qe(t.child)))}function Dt(e){return t=>i.createElement(Mt,ae({attr:ce({},e.attr)},t),qe(e.child))}function Mt(e){var t=n=>{var{attr:r,size:o,title:s}=e,a=Rt(e,It),u=o||n.size||"1em",d;return n.className&&(d=n.className),e.className&&(d=(d?d+" ":"")+e.className),i.createElement("svg",ae({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,r,a,{className:d,style:ce(ce({color:e.color||n.color},n.style),e.style),height:u,width:u,xmlns:"http://www.w3.org/2000/svg"}),s&&i.createElement("title",null,s),e.children)};return $e!==void 0?i.createElement($e.Consumer,null,n=>t(n)):t(Ze)}function _t(e){return Dt({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M18 6 6 18"},child:[]},{tag:"path",attr:{d:"m6 6 12 12"},child:[]}]})(e)}const Gt=T.forwardRef(function(t,n){return c.jsx(f.IconButton,{variant:"ghost","aria-label":"Close",ref:n,...t,children:t.children??c.jsx(_t,{})})}),kt=T.forwardRef(function(t,n){const{portalled:r=!0,portalRef:o,...s}=t;return c.jsx(f.Portal,{disabled:!r,container:o,children:c.jsx(f.Popover.Positioner,{children:c.jsx(f.Popover.Content,{ref:n,...s})})})});T.forwardRef(function(t,n){return c.jsx(f.Popover.Arrow,{...t,ref:n,children:c.jsx(f.Popover.ArrowTip,{})})});T.forwardRef(function(t,n){return c.jsx(f.Popover.CloseTrigger,{position:"absolute",top:"1",insetEnd:"1",...t,asChild:!0,ref:n,children:c.jsx(Gt,{size:"sm"})})});f.Popover.Title;f.Popover.Description;f.Popover.Footer;f.Popover.Header;const Bt=f.Popover.Root,Wt=f.Popover.Body;f.Popover.Trigger;const et=i.forwardRef((e,t)=>{const n=Je(e),{children:r,isOpen:o,onClose:s,onOpen:a,placement:u,resetItems:d,removeItem:y}=n;i.useImperativeHandle(t,()=>({resetItems:d,removeItem:y}));const{matchWidth:x=!0}=n.autoCompleteProps;return c.jsx(Qe,{value:n,children:c.jsx(Bt,{open:o,autoFocus:!1,positioning:{placement:u,sameWidth:x},present:o,children:c.jsx(f.chakra.div,{w:"full",ref:t,children:r})})})});et.displayName="AutoComplete";const tt=i.forwardRef((e,t)=>{const{focusedValue:n,getItemProps:r,interactionRef:o}=B(),s=i.useRef(),a=Te(t,s),u=r(e),{isValidSuggestion:d,value:y}=u.root,x=n===y;i.useEffect(()=>{var L;x&&o.current==="keyboard"&&((L=s==null?void 0:s.current)==null||L.scrollIntoView({behavior:"smooth",block:"nearest"}))},[x,o]),i.useEffect(()=>{typeof y!="string"&&console.warn("wow"),typeof y!="string"&&ue(e.getValue)&&console.error("You must define the `getValue` prop, when an Item's value is not a string")},[]);const{children:g,dangerouslySetInnerHTML:w,...O}=u.item,E=fe(O,["groupId"]);return d?c.jsx(f.Flex,{ref:a,...Fe,...E,children:g||c.jsx("span",{dangerouslySetInnerHTML:w})}):null});tt.displayName="AutoCompleteItem";const Fe={mx:"2",px:"2",py:"2",rounded:"md",cursor:"pointer"};function nt(e){const{alwaysDisplay:t,children:n,...r}=e,{autoCompleteProps:o,getItemProps:s,query:a,filteredResults:u}=B(),{children:d,...y}=s({...e,value:a,children:b(n,{value:a})},!0).item,x=u.some(O=>O.value===a),g=Re(a)?t:!0;return o.creatable&&g&&!x?c.jsx(f.Flex,{...Fe,...y,...r,children:d||`Add ${a}`}):null}nt.displayName="AutoCompleteCreatable";const rt=i.forwardRef((e,t)=>{const{children:n,showDivider:r,...o}=e,s=fe(o,["groupSibling"]),{getGroupProps:a}=B(),{group:u}=a(e),d=$t(e);return c.jsxs(f.Box,{ref:t,...u,...s,children:[c.jsx(f.Separator,{...d.top}),n,c.jsx(f.Separator,{...d.bottom})]})}),ot=i.forwardRef((e,t)=>c.jsx(f.Flex,{...zt,...e,ref:t}));rt.displayName="AutoCompleteGroup";ot.displayName="AutoCompleteGroupTitle";const zt={ml:5,my:1,fontSize:"xs",letterSpacing:"wider",fontWeight:"extrabold",textTransform:"uppercase"},$t=e=>{const{getGroupProps:t}=B(),n=e.groupSibling,{divider:{hasFirstChild:r,hasLastChild:o}}=t(e),s={my:2,borderColor:e.dividerColor},a={...s,mb:4,display:!e.showDivider||r?"none":""},u={...s,display:!e.showDivider||o||n?"none":""};return{top:a,bottom:u}},Ht=T.forwardRef(function(t,n){const{startElement:r,startElementProps:o,endElement:s,endElementProps:a,children:u,startOffset:d="6px",endOffset:y="6px",...x}=t;return c.jsxs(f.Group,{ref:n,...x,children:[r&&c.jsx(f.InputElement,{pointerEvents:"none",...o,children:r}),T.cloneElement(u,{...r&&{ps:`calc(var(--input-height) - ${d})`},...s&&{pe:`calc(var(--input-height) - ${y})`},...u.props}),s&&c.jsx(f.InputElement,{placement:"end",...a,children:s})]})}),Kt=i.forwardRef((e,t)=>{const{isLoading:n}=B(),{loadingIcon:r,...o}=e,s=fe(o,["children","wrapStyles","hidePlaceholder"]),a=c.jsx(f.Input,{...s,ref:t});return n?c.jsx(Ht,{endElement:r||c.jsx(f.Spinner,{}),children:a}):a}),st=i.forwardRef((e,t)=>{const{autoCompleteProps:n,inputRef:r,getInputProps:o,tags:s,setQuery:a,value:u,itemList:d}=B(),{children:y,hidePlaceholder:x,...g}=e,{value:w}=g;i.useEffect(()=>{if(u!==void 0&&(typeof u=="string"||u instanceof String)){const ne=d.find(H=>H.value===u),ve=ne===void 0?u:ne.label;a(ve)}},[u]),i.useEffect(()=>{w!==void 0&&(typeof w=="string"||w instanceof String)&&a(w)},[w]);const O={};let{wrapper:E,input:L}=o(g,O);const{ref:de,...ee}=E,me=Te(t,r),Y=b(y,{tags:s});x&&(L={...L,placeholder:Array.isArray(Y)&&Y.length?void 0:L.placeholder});const te=c.jsx(Kt,{...L,ref:me}),ge=c.jsxs(f.Box,{...ee,ref:de,children:[Y,te]});return c.jsx(f.PopoverAnchor,{children:n.multiple?ge:te})});st.displayName="Input";const Qt=e=>{const{getEmptyStateProps:t,defaultEmptyStateProps:n}=B(),r=t(c.jsx(f.Flex,{...Ut,...n,children:"No options found!"}));return c.jsx(f.Box,{...e,children:r})},Ut={fontSize:"sm",align:"center",justify:"center",fontWeight:"bold",fontStyle:"italic"},Ke=["AutoCompleteGroup","AutoCompleteItem","AutoCompleteCreatable"],Vt=e=>{const t=i.Children.map(e,(o,s)=>{var a;if(((a=o==null?void 0:o.type)==null?void 0:a.displayName)==="AutoCompleteGroup"){const u=i.Children.toArray(e)[s+1];return i.cloneElement(o,{groupSibling:u?u.type.displayName==="AutoCompleteGroup":!1})}return o}),n=i.Children.toArray(t).filter(o=>{var s;return!Ke.includes((s=o==null?void 0:o.type)==null?void 0:s.displayName)});return[i.Children.toArray(t).filter(o=>{var s;return Ke.includes((s=o==null?void 0:o.type)==null?void 0:s.displayName)}),n]},lt=i.forwardRef((e,t)=>{const{children:n,loadingState:r,...o}=e,{listRef:s,isLoading:a}=B(),u=Te(t,s),[d,y]=Vt(n);return c.jsx(kt,{width:"auto",children:c.jsxs(Wt,{ref:u,w:"inherit",...Yt,...o,children:[a&&c.jsx(f.Center,{children:r||c.jsx(f.Spinner,{size:"md"})}),!a&&c.jsxs(c.Fragment,{children:[d,c.jsx(Qt,{}),y]})]})})});lt.displayName="AutoCompleteList";const Yt={px:"0px",bg:"#232934",rounded:"md",maxH:"350px",border:"none",shadow:"base",zIndex:"popover",overflowY:"auto",_light:{bg:"#ffffff"},_focus:{boxShadow:"none"}},Xt=T.forwardRef(function(t,n){const{startElement:r,endElement:o,onClose:s,closable:a=!!s,children:u,...d}=t;return c.jsxs(f.Tag.Root,{ref:n,...d,children:[r&&c.jsx(f.Tag.StartElement,{children:r}),c.jsx(f.Tag.Label,{children:u}),o&&c.jsx(f.Tag.EndElement,{children:o}),a&&c.jsx(f.Tag.EndElement,{children:c.jsx(f.Tag.CloseTrigger,{onClick:s})})]})}),Jt=i.memo(e=>{const{label:t,onRemove:n,disabled:r,...o}=e;return c.jsx(Xt,{borderRadius:"md",fontWeight:"normal",closable:!0,onClose:()=>!r&&b(n),...r&&Zt,...o,children:t})}),Zt={cursor:"text",userSelect:"none",opacity:.4,_focus:{boxShadow:"none"}};exports.AutoComplete=et;exports.AutoCompleteCreatable=nt;exports.AutoCompleteGroup=rt;exports.AutoCompleteGroupTitle=ot;exports.AutoCompleteInput=st;exports.AutoCompleteItem=tt;exports.AutoCompleteList=lt;exports.AutoCompleteProvider=Qe;exports.AutoCompleteTag=Jt;exports.baseItemStyles=Fe;exports.createContext=Ue;exports.useAutoComplete=Je;exports.useAutoCompleteContext=B;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),i=require("react"),f=require("@chakra-ui/react");function ct(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 T=ct(i),[Qe,B]=Ue();function Ue(){const e=T.createContext(void 0);e.displayName="AutoCompleteContext";function t(){var o;const n=T.useContext(e),r="useAutoCompleteContext: `context` is undefined. Seems you forgot to wrap all autoomplete components within `<AutoComplete />`";if(!n){const s=new Error(r);throw s.name="ContextError",(o=Error.captureStackTrace)==null||o.call(Error,s,t),s}return n}return[e.Provider,t,e]}function ft(e){return e==null?void 0:e[0]}function Pe(e){return e!=null&&e.length?e[e.length-1]:void 0}function Ve(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 pt(e,t,n=!0){return Ve(e,t,-1,n)}function dt(e,t,n=!0){const r=Ve(e,t.length,1,n);return t[r]}function mt(e,t,n=!0){const r=pt(e,t.length,n);return t[r]}function Oe(e){return Array.isArray(e)}function gt(e){return Oe(e)&&e.length===0}function Ie(e){return e!==null&&typeof e=="object"&&!Oe(e)}function vt(e){return Ie(e)&&Object.keys(e).length===0}function Re(e){return Oe(e)?gt(e):Ie(e)?vt(e):e==null||e===""}function ue(e){return typeof e>"u"}function Ye(e){return typeof e<"u"}function ht(e,t){const n={};return t.forEach(r=>{r in e&&(n[r]=e[r])}),n}function fe(e,t){const n={...e};return t.forEach(r=>{delete n[r]}),n}function bt(e){return typeof e=="function"}function b(e,...t){return bt(e)?e(...t):e}function yt(e,t){if(e!=null){if(typeof e=="function"){e(t);return}try{e.current=t}catch{throw new Error(`Cannot assign value '${t}' to ref '${e}'`)}}}function xt(...e){return t=>{e.forEach(n=>{yt(n,t)})}}function Te(...e){return i.useMemo(()=>xt(...e),e)}var pe=function(e,t){for(var n,r=T.Children.toArray(e),o=0,s=r;o<s.length;o++){var a=s[o];if(t(a))return a;if(!((n=a.props)===null||n===void 0)&&n.children){var u=pe(a.props.children,t);if(u)return u}}},ie=function(e,t){for(var n=0,r=t.length,o=e.length;n<r;n++,o++)e[o]=t[n];return e},Xe=function(e,t){for(var n,r=T.Children.toArray(e),o=[],s=0,a=r;s<a.length;s++){var u=a[s];t(u)&&(o=ie(ie([],o),[u])),!((n=u.props)===null||n===void 0)&&n.children&&(o=ie(ie([],o),Xe(u.props.children,t)))}return o};function ze(e,t,n=2){function r(g,w){g=" ".repeat(w-1)+g.toLowerCase()+" ".repeat(w-1);let O=new Array(g.length-w+1);for(let E=0;E<O.length;E++)O[E]=g.slice(E,E+w);return O}if(!(e!=null&&e.length)||!(t!=null&&t.length))return 0;let o=e.length<t.length?e:t,s=e.length<t.length?t:e,a=r(o,n),u=r(s,n),d=new Set(a),y=u.length,x=0;for(let g of u)d.delete(g)&&x++;return x/y}const Ne=e=>{var t;return(t=typeof e=="string"||typeof e=="number"?e:e[Object.keys(e)[0]])==null?void 0:t.toString()},Ct=(e,t)=>typeof e!="string"||Re(t)?e:e.toString().replace(new RegExp(At(t),"gi"),r=>`<mark>${r}</mark>`),wt=e=>Xe(e,n=>{var r;return((r=n==null?void 0:n.type)==null?void 0:r.displayName)==="AutoCompleteItem"}).map(n=>{const r=ht(n.props,["value","label","fixed","disabled"]),{getValue:o=Ne}=n.props,s=o(r.value);return{...Ye(r.label)?r:{...r,label:s},value:s,originalValue:r.value}}),jt=()=>({bg:"whiteAlpha.100",_light:{bg:"gray.200"}}),St=(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 At(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}const Et=(e,t)=>pe(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)}),Pt=(e,t)=>pe(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)}),Ot=(e,t)=>Ye(pe(e,n=>{var o,s;const r=b(((o=n.props)==null?void 0:o.getValue)||Ne,((s=n.props)==null?void 0:s.value)||{});return t.some(a=>a.value===r)}));function Je(e){var ke;let{prefocusFirstItem:t=!0,closeOnBlur:n=!0,creatable:r,emphasize:o,emptyState:s=!0,defaultEmptyStateProps:a={},freeSolo:u,isReadOnly:d,listAllValuesOnFocus:y,maxSuggestions:x,multiple:g,closeOnSelect:w=!g,defaultValue:O,defaultValues:E=O?[O]:[],onReady:L,defaultIsOpen:de,disableFilter:Y,isLoading:me=!1,placement:X="bottom",restoreOnBlurIfEmpty:te=!u,shouldRenderSuggestions:ge=()=>!0,submitKeys:ne=[],suggestWhenEmpty:ve,value:H,values:he=H?typeof H=="string"?[H]:[...H]:void 0}=e;u=u||(g?!0:e.freeSolo);const{open:P,onClose:W,onOpen:Q}=f.useDisclosure({open:de}),be=i.useMemo(()=>b(e.children,{isOpen:P,onClose:W,onOpen:Q}),[e.children,P]),S=i.useMemo(()=>wt(be),[be]),N=i.useRef(null),Le=i.useRef(null),J=i.useRef(null),U=i.useRef(null),[De,re]=i.useState(!1);let oe="";g?oe="":ue(E)?ue(he)||(oe=he[0]):oe=E[0];const[D,Z]=i.useState(oe??""),ye=i.useMemo(()=>Y?S:S.filter(l=>l.fixed||b(e.filter||St,D,l.value,l.label)||De).filter((l,p)=>x?l.fixed||p<x:!0),[D,S,De,x,Y]),se=r?[{value:D,noFilter:!0,creatable:!0}]:[],C=i.useMemo(()=>[...ye,...se],[ye,se]),it=i.useMemo(()=>[...S,...se],[S,se]),[M,xe]=f.useControllableState({defaultValue:E.map(l=>l==null?void 0:l.toString()),value:he,onChange:l=>{const p=C.find(I=>I.value===l.at(-1));if(!p)return;const v=l.map(I=>it.find(R=>R.value===I));b(e.onChange,g?l:l[0],g?v:p)}});i.useEffect(()=>{C.length===0&&!s&&P&&W()},[C.length,s,P]);const[V,_]=i.useState(t?(ke=S[0])==null?void 0:ke.value:null),ut=e.maxSelections||M.length+1,Ce=C.findIndex(l=>l.value===V),we=dt(Ce,C,!!e.rollNavigation),je=mt(Ce,C,!!e.rollNavigation),F=ft(C),Se=Pe(C),Me=!C.some(l=>l.value===V);i.useEffect(()=>{var l;Me&&_(t?(l=S[0])==null?void 0:l.value:null)},[Me]),i.useEffect(()=>{t&&_(F==null?void 0:F.value)},[t,_,D,F==null?void 0:F.value]),i.useEffect(()=>{var l;!P&&t&&_((l=S[0])==null?void 0:l.value)},[P]),i.useEffect(()=>{P&&y&&re(!0)},[P,y,re]),i.useEffect(()=>{const l=S.find(p=>p.value===V);b(e.onOptionFocus,{item:l,focusMethod:U.current,isNewInput:l==null?void 0:l.creatable})},[V,e.onOptionFocus]);const Ae=l=>{var I,R;const p=C.find(A=>A.value===l),v=(p==null?void 0:p.label)||(p==null?void 0:p.value);Z(()=>g?"":v??""),!M.includes(l)&&M.length<ut&&xe(A=>g?[...A,l]:[l]),g&&((I=N.current)==null||I.focus()),e.focusInputOnSelect&&((R=N.current)==null||R.focus()),b(e.onSelectOption,{item:p,selectMethod:U.current,isNewInput:p==null?void 0:p.creatable}),p!=null&&p.creatable&&b(e.onCreateOption,{item:fe(p,["noFilter"]),selectMethod:U.current}),w&&W()},_e=(l,p)=>{var R;xe(A=>{let z=S.find(G=>G.value===l);return!z&&r===!0&&(z={label:l,value:l}),z?(b(e.onTagRemoved,l,z,A),A.filter(G=>G!==l)):A});const v=S.find(A=>A.value===l),I=(v==null?void 0:v.label)||(v==null?void 0:v.value);D===I&&Z(""),p&&((R=N.current)==null||R.focus())},at=l=>{var p;xe([]),l&&((p=N.current)==null||p.focus())},Ge=g?M.map(l=>{var p;return{label:((p=S.find(v=>v.value===(l==null?void 0:l.toString())))==null?void 0:p.label)||l,onRemove:()=>_e(l)}}):[];return i.useEffect(()=>{b(L,{tags:Ge})},[M]),{autoCompleteProps:e,children:be,filteredList:C,filteredResults:ye,focusedValue:V,defaultEmptyStateProps:a,getEmptyStateProps:l=>{if(C.every(v=>v.noFilter)&&s&&!r)return typeof s=="boolean"?l:b(s,{query:D})},getGroupProps:l=>{const p=Ot(l.children,C);return{divider:{hasFirstChild:Et(l.children,F),hasLastChild:Pt(l.children,Pe(C.filter(v=>ue(v==null?void 0:v.noFilter))))},group:{display:p?"initial":"none"}}},getInputProps:(l,p)=>{const{onBlur:v,onChange:I,onFocus:R,onKeyDown:A,variant:z,...G}=l;return{wrapper:{ref:Le,onClick:()=>{var m;(m=N==null?void 0:N.current)==null||m.focus()},...G},input:{isReadOnly:d,onFocus:m=>{b(R,m),e.openOnFocus&&!d&&Q(),e.selectOnFocus&&m.target.select(),y&&re(!0)},onBlur:m=>{var K,le;b(v,m);const j=m.relatedTarget===(J==null?void 0:J.current)||((K=J.current)==null?void 0:K.contains(m.relatedTarget)),h=(le=Le.current)==null?void 0:le.contains(m.relatedTarget);if(!j&&!h&&(n&&W(),!M.includes(m.target.value)&&te)){const k=Pe(M),$=S.find(q=>q.value===k),Ee=($==null?void 0:$.label)||($==null?void 0:$.value)||"";Z(Ee)}},onChange:m=>{const j=m.target.value;b(I,m),Z(j);const h=Re(j);b(ge,j)&&(!h||ve)?Q():W(),re(!1)},onKeyDown:m=>{var K;b(A,m),U.current="keyboard";const{key:j}=m,h=C[Ce];if(["Enter",...ne].includes(j)){h&&!(h!=null&&h.disabled)&&P?Ae(h==null?void 0:h.value):(K=N.current)==null||K.focus(),m.preventDefault();return}if(j==="ArrowDown"){P?_(we==null?void 0:we.value):Q(),m.preventDefault();return}if(j==="ArrowUp"){P?_(je==null?void 0:je.value):Q(),m.preventDefault();return}if(j==="Tab"){P&&h&&!(h!=null&&h.disabled)?Ae(h==null?void 0:h.value):W();return}if(j==="Home"){_(F==null?void 0:F.value),m.preventDefault();return}if(j==="End"){_(Se==null?void 0:Se.value),m.preventDefault();return}j==="Escape"&&(W(),m.preventDefault())},value:D,variant:z,...G}}},getItemProps:(l,p)=>{var Be;const{_fixed:v,_focus:I,children:R,disabled:A,label:z,value:G,fixed:m,getValue:j=Ne,onClick:h,onMouseOver:K,...le}=l,k=p?G:(Be=j(G))==null?void 0:Be.toString(),$=k===V,Ee=C.findIndex(ee=>ee.value===k)>=0,q=R||z||k;return{item:{...typeof q!="string"||!o?{children:q}:{dangerouslySetInnerHTML:{__html:Ct(q,D)}},"aria-selected":M.includes(k),"aria-disabled":A,_disabled:{opacity:.4,cursor:"not-allowed",userSelect:"none"},onMouseDown:ee=>{var We;b(h,ee),A?(We=N.current)==null||We.focus():Ae(k)},onMouseOver:ee=>{b(K,ee),_(k),U.current="mouse"},sx:{mark:{color:"inherit",bg:"transparent",...Ie(o)?o:{fontWeight:o?"extrabold":"inherit"}}},...$&&(I||jt()),...m&&v,...le},root:{isValidSuggestion:Ee,value:k}}},inputRef:N,interactionRef:U,isLoading:me,isOpen:P,itemList:S,listRef:J,onClose:W,onOpen:Q,placement:X,query:D,removeItem:_e,resetItems:at,setQuery:Z,tags:Ge,value:H,values:M}}var Ze={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},$e=i.createContext&&i.createContext(Ze),It=["attr","size","title"];function Rt(e,t){if(e==null)return{};var n=Tt(e,t),r,o;if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(o=0;o<s.length;o++)r=s[o],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function Tt(e,t){if(e==null)return{};var n={};for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){if(t.indexOf(r)>=0)continue;n[r]=e[r]}return n}function ae(){return ae=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},ae.apply(this,arguments)}function He(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),n.push.apply(n,r)}return n}function ce(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?He(Object(n),!0).forEach(function(r){Nt(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):He(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function Nt(e,t,n){return t=Ft(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ft(e){var t=Lt(e,"string");return typeof t=="symbol"?t:t+""}function Lt(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function qe(e){return e&&e.map((t,n)=>i.createElement(t.tag,ce({key:n},t.attr),qe(t.child)))}function Dt(e){return t=>i.createElement(Mt,ae({attr:ce({},e.attr)},t),qe(e.child))}function Mt(e){var t=n=>{var{attr:r,size:o,title:s}=e,a=Rt(e,It),u=o||n.size||"1em",d;return n.className&&(d=n.className),e.className&&(d=(d?d+" ":"")+e.className),i.createElement("svg",ae({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,r,a,{className:d,style:ce(ce({color:e.color||n.color},n.style),e.style),height:u,width:u,xmlns:"http://www.w3.org/2000/svg"}),s&&i.createElement("title",null,s),e.children)};return $e!==void 0?i.createElement($e.Consumer,null,n=>t(n)):t(Ze)}function _t(e){return Dt({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M18 6 6 18"},child:[]},{tag:"path",attr:{d:"m6 6 12 12"},child:[]}]})(e)}const Gt=T.forwardRef(function(t,n){return c.jsx(f.IconButton,{variant:"ghost","aria-label":"Close",ref:n,...t,children:t.children??c.jsx(_t,{})})}),kt=T.forwardRef(function(t,n){const{portalled:r=!0,portalRef:o,...s}=t;return c.jsx(f.Portal,{disabled:!r,container:o,children:c.jsx(f.Popover.Positioner,{children:c.jsx(f.Popover.Content,{ref:n,...s})})})});T.forwardRef(function(t,n){return c.jsx(f.Popover.Arrow,{...t,ref:n,children:c.jsx(f.Popover.ArrowTip,{})})});T.forwardRef(function(t,n){return c.jsx(f.Popover.CloseTrigger,{position:"absolute",top:"1",insetEnd:"1",...t,asChild:!0,ref:n,children:c.jsx(Gt,{size:"sm"})})});f.Popover.Title;f.Popover.Description;f.Popover.Footer;f.Popover.Header;const Bt=f.Popover.Root,Wt=f.Popover.Body;f.Popover.Trigger;const et=i.forwardRef((e,t)=>{const n=Je(e),{children:r,isOpen:o,onClose:s,onOpen:a,placement:u,resetItems:d,removeItem:y}=n;i.useImperativeHandle(t,()=>({resetItems:d,removeItem:y}));const{matchWidth:x=!0}=n.autoCompleteProps;return c.jsx(Qe,{value:n,children:c.jsx(Bt,{open:o,autoFocus:!1,positioning:{placement:u,sameWidth:x},present:o,children:c.jsx(f.chakra.div,{w:"full",ref:t,children:r})})})});et.displayName="AutoComplete";const tt=i.forwardRef((e,t)=>{const{focusedValue:n,getItemProps:r,interactionRef:o}=B(),s=i.useRef(),a=Te(t,s),u=r(e),{isValidSuggestion:d,value:y}=u.root,x=n===y;i.useEffect(()=>{var L;x&&o.current==="keyboard"&&((L=s==null?void 0:s.current)==null||L.scrollIntoView({behavior:"smooth",block:"nearest"}))},[x,o]),i.useEffect(()=>{typeof y!="string"&&console.warn("wow"),typeof y!="string"&&ue(e.getValue)&&console.error("You must define the `getValue` prop, when an Item's value is not a string")},[]);const{children:g,dangerouslySetInnerHTML:w,...O}=u.item,E=fe(O,["groupId"]);return d?c.jsx(f.Flex,{ref:a,...Fe,...E,children:g||c.jsx("span",{dangerouslySetInnerHTML:w})}):null});tt.displayName="AutoCompleteItem";const Fe={mx:"2",px:"2",py:"2",rounded:"md",cursor:"pointer"};function nt(e){const{alwaysDisplay:t,children:n,...r}=e,{autoCompleteProps:o,getItemProps:s,query:a,filteredResults:u}=B(),{children:d,...y}=s({...e,value:a,children:b(n,{value:a})},!0).item,x=u.some(O=>O.value===a),g=Re(a)?t:!0;return o.creatable&&g&&!x?c.jsx(f.Flex,{...Fe,...y,...r,children:d||`Add ${a}`}):null}nt.displayName="AutoCompleteCreatable";const rt=i.forwardRef((e,t)=>{const{children:n,showDivider:r,...o}=e,s=fe(o,["groupSibling"]),{getGroupProps:a}=B(),{group:u}=a(e),d=$t(e);return c.jsxs(f.Box,{ref:t,...u,...s,children:[c.jsx(f.Separator,{...d.top}),n,c.jsx(f.Separator,{...d.bottom})]})}),ot=i.forwardRef((e,t)=>c.jsx(f.Flex,{...zt,...e,ref:t}));rt.displayName="AutoCompleteGroup";ot.displayName="AutoCompleteGroupTitle";const zt={ml:5,my:1,fontSize:"xs",letterSpacing:"wider",fontWeight:"extrabold",textTransform:"uppercase"},$t=e=>{const{getGroupProps:t}=B(),n=e.groupSibling,{divider:{hasFirstChild:r,hasLastChild:o}}=t(e),s={my:2,borderColor:e.dividerColor},a={...s,mb:4,display:!e.showDivider||r?"none":""},u={...s,display:!e.showDivider||o||n?"none":""};return{top:a,bottom:u}},Ht=T.forwardRef(function(t,n){const{startElement:r,startElementProps:o,endElement:s,endElementProps:a,children:u,startOffset:d="6px",endOffset:y="6px",...x}=t;return c.jsxs(f.Group,{ref:n,...x,children:[r&&c.jsx(f.InputElement,{pointerEvents:"none",...o,children:r}),T.cloneElement(u,{...r&&{ps:`calc(var(--input-height) - ${d})`},...s&&{pe:`calc(var(--input-height) - ${y})`},...u.props}),s&&c.jsx(f.InputElement,{placement:"end",...a,children:s})]})}),Kt=i.forwardRef((e,t)=>{const{isLoading:n}=B(),{loadingIcon:r,...o}=e,s=fe(o,["children","wrapStyles","hidePlaceholder"]),a=c.jsx(f.Input,{...s,ref:t});return n?c.jsx(Ht,{endElement:r||c.jsx(f.Spinner,{}),children:a}):a}),st=i.forwardRef((e,t)=>{const{autoCompleteProps:n,inputRef:r,getInputProps:o,tags:s,setQuery:a,value:u,itemList:d}=B(),{children:y,hidePlaceholder:x,...g}=e,{value:w}=g;i.useEffect(()=>{if(u!==void 0&&(typeof u=="string"||u instanceof String)){const ne=d.find(H=>H.value===u),ve=ne===void 0?u:ne.label;a(ve)}},[u]),i.useEffect(()=>{w!==void 0&&(typeof w=="string"||w instanceof String)&&a(w)},[w]);const O={};let{wrapper:E,input:L}=o(g,O);const{ref:de,...Y}=E,me=Te(t,r),X=b(y,{tags:s});x&&(L={...L,placeholder:Array.isArray(X)&&X.length?void 0:L.placeholder});const te=c.jsx(Kt,{...L,ref:me}),ge=c.jsxs(f.Box,{...Y,ref:de,children:[X,te]});return c.jsx(f.PopoverAnchor,{w:"full",...Y,children:n.multiple?ge:te})});st.displayName="Input";const Qt=e=>{const{getEmptyStateProps:t,defaultEmptyStateProps:n}=B(),r=t(c.jsx(f.Flex,{...Ut,...n,children:"No options found!"}));return c.jsx(f.Box,{...e,children:r})},Ut={fontSize:"sm",align:"center",justify:"center",fontWeight:"bold",fontStyle:"italic"},Ke=["AutoCompleteGroup","AutoCompleteItem","AutoCompleteCreatable"],Vt=e=>{const t=i.Children.map(e,(o,s)=>{var a;if(((a=o==null?void 0:o.type)==null?void 0:a.displayName)==="AutoCompleteGroup"){const u=i.Children.toArray(e)[s+1];return i.cloneElement(o,{groupSibling:u?u.type.displayName==="AutoCompleteGroup":!1})}return o}),n=i.Children.toArray(t).filter(o=>{var s;return!Ke.includes((s=o==null?void 0:o.type)==null?void 0:s.displayName)});return[i.Children.toArray(t).filter(o=>{var s;return Ke.includes((s=o==null?void 0:o.type)==null?void 0:s.displayName)}),n]},lt=i.forwardRef((e,t)=>{const{children:n,loadingState:r,...o}=e,{listRef:s,isLoading:a}=B(),u=Te(t,s),[d,y]=Vt(n);return c.jsx(kt,{width:"auto",children:c.jsxs(Wt,{ref:u,w:"inherit",...Yt,...o,children:[a&&c.jsx(f.Center,{children:r||c.jsx(f.Spinner,{size:"md"})}),!a&&c.jsxs(c.Fragment,{children:[d,c.jsx(Qt,{}),y]})]})})});lt.displayName="AutoCompleteList";const Yt={px:"0px",bg:"#232934",rounded:"md",maxH:"350px",border:"none",shadow:"base",zIndex:"popover",overflowY:"auto",_light:{bg:"#ffffff"},_focus:{boxShadow:"none"}},Xt=T.forwardRef(function(t,n){const{startElement:r,endElement:o,onClose:s,closable:a=!!s,children:u,...d}=t;return c.jsxs(f.Tag.Root,{ref:n,...d,children:[r&&c.jsx(f.Tag.StartElement,{children:r}),c.jsx(f.Tag.Label,{children:u}),o&&c.jsx(f.Tag.EndElement,{children:o}),a&&c.jsx(f.Tag.EndElement,{children:c.jsx(f.Tag.CloseTrigger,{onClick:s})})]})}),Jt=i.memo(e=>{const{label:t,onRemove:n,disabled:r,...o}=e;return c.jsx(Xt,{borderRadius:"md",fontWeight:"normal",closable:!0,onClose:()=>!r&&b(n),...r&&Zt,...o,children:t})}),Zt={cursor:"text",userSelect:"none",opacity:.4,_focus:{boxShadow:"none"}};exports.AutoComplete=et;exports.AutoCompleteCreatable=nt;exports.AutoCompleteGroup=rt;exports.AutoCompleteGroupTitle=ot;exports.AutoCompleteInput=st;exports.AutoCompleteItem=tt;exports.AutoCompleteList=lt;exports.AutoCompleteProvider=Qe;exports.AutoCompleteTag=Jt;exports.baseItemStyles=Fe;exports.createContext=Ue;exports.useAutoComplete=Je;exports.useAutoCompleteContext=B;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "6.1.
|
|
2
|
+
"version": "6.1.4",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"tsdx": "^0.14.1",
|
|
84
84
|
"tslib": "^2.3.0",
|
|
85
85
|
"typescript": "^5.3.3",
|
|
86
|
-
"vite": "^
|
|
86
|
+
"vite": "^6.3.5",
|
|
87
87
|
"vite-plugin-dts": "^4.2.2",
|
|
88
88
|
"vite-plugin-linter": "^3.0.0",
|
|
89
89
|
"vite-tsconfig-paths": "^5.0.1"
|