@caspeco/casper-ui-library 7.7.2 → 7.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combobox.d.ts","sourceRoot":"","sources":["../../../lib/components/combobox/combobox.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAIX,aAAa,EAKb,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"combobox.d.ts","sourceRoot":"","sources":["../../../lib/components/combobox/combobox.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAIX,aAAa,EAKb,MAAM,SAAS,CAAC;AAqGjB;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,EACxB,EAAE,EACF,KAAU,EACV,cAAsB,EACtB,aAAkB,EAClB,MAAgB,EAChB,IAAW,EACX,OAAmB,EACnB,WAAmB,EACnB,QAAQ,EACR,KAAK,EACL,eAAe,EACf,QAAQ,EACR,MAAM,EACN,UAAU,EACV,UAAU,EACV,UAAU,EACV,WAAW,EACX,SAAS,EACT,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,SAAiB,EACjB,GAAG,KAAK,EACR,EAAE,aAAa,2CAgMf"}
|
|
@@ -1,69 +1,69 @@
|
|
|
1
1
|
import { jsxs as ee, jsx as V } from "react/jsx-runtime";
|
|
2
2
|
import { Box as ne } from "@chakra-ui/react";
|
|
3
|
-
import { useState as
|
|
3
|
+
import { useState as g, useRef as _, useEffect as q, useMemo as U } from "react";
|
|
4
4
|
import { ComboboxButton as te } from "./combobox-button.js";
|
|
5
5
|
import { ComboboxMenu as re } from "./combobox-menu.js";
|
|
6
6
|
import { translations as oe } from "./translations.js";
|
|
7
|
-
const le = (
|
|
8
|
-
const [n, e] =
|
|
9
|
-
if (!
|
|
10
|
-
const
|
|
11
|
-
|
|
7
|
+
const le = (r, i) => {
|
|
8
|
+
const [n, e] = g(0), c = (l) => {
|
|
9
|
+
if (!i.current) return;
|
|
10
|
+
const f = [...i.current.querySelectorAll("li")];
|
|
11
|
+
f[l] && (f[l]?.scrollIntoView({
|
|
12
12
|
behavior: "smooth",
|
|
13
13
|
block: "nearest"
|
|
14
14
|
}), e(l));
|
|
15
15
|
};
|
|
16
16
|
return {
|
|
17
17
|
index: n,
|
|
18
|
-
set:
|
|
19
|
-
next: () =>
|
|
20
|
-
previous: () =>
|
|
18
|
+
set: c,
|
|
19
|
+
next: () => c((n + 1) % r.length),
|
|
20
|
+
previous: () => c((n - 1 + r.length) % r.length)
|
|
21
21
|
};
|
|
22
|
-
}, se = (
|
|
23
|
-
const [
|
|
22
|
+
}, se = (r, i, n, e, c) => {
|
|
23
|
+
const [o, a] = g(!1);
|
|
24
24
|
return q(() => {
|
|
25
|
-
e &&
|
|
26
|
-
}, [e,
|
|
27
|
-
|
|
25
|
+
e && a(!1);
|
|
26
|
+
}, [e, a]), { isOpen: o, close: () => {
|
|
27
|
+
i || (n(""), c?.("")), a(!1);
|
|
28
28
|
}, open: () => {
|
|
29
|
-
|
|
29
|
+
o || e || (a(!0), r.set(0));
|
|
30
30
|
} };
|
|
31
|
-
}, ie = (
|
|
32
|
-
const [n, e] =
|
|
33
|
-
if (!n.length) return
|
|
34
|
-
const
|
|
31
|
+
}, ie = (r, i) => {
|
|
32
|
+
const [n, e] = g([]), c = U(() => {
|
|
33
|
+
if (!n.length) return r;
|
|
34
|
+
const o = n[n.length - 1], a = {
|
|
35
35
|
id: "_back",
|
|
36
|
-
label:
|
|
36
|
+
label: i.back
|
|
37
37
|
}, l = n[n.length - 1]?.children || [];
|
|
38
|
-
return
|
|
39
|
-
}, [n,
|
|
38
|
+
return o?.isSelectableParent ? [a, o, ...l] : [a, ...l];
|
|
39
|
+
}, [n, r, i]);
|
|
40
40
|
return {
|
|
41
|
-
open: (
|
|
42
|
-
e((
|
|
41
|
+
open: (o) => {
|
|
42
|
+
e((a) => [...a, o]);
|
|
43
43
|
},
|
|
44
44
|
back: () => {
|
|
45
|
-
n.length && e((
|
|
45
|
+
n.length && e((o) => [...o.slice(0, n.length - 1)]);
|
|
46
46
|
},
|
|
47
47
|
opened: n,
|
|
48
|
-
current:
|
|
48
|
+
current: c
|
|
49
49
|
};
|
|
50
|
-
}, ce = (
|
|
51
|
-
const
|
|
52
|
-
function n(e,
|
|
53
|
-
|
|
50
|
+
}, ce = (r) => U(() => {
|
|
51
|
+
const i = {};
|
|
52
|
+
function n(e, c) {
|
|
53
|
+
i[e.id] = [...c], e.children && e.children.forEach((o) => n(o, [...c, e.label]));
|
|
54
54
|
}
|
|
55
|
-
return
|
|
56
|
-
}, [
|
|
55
|
+
return r.forEach((e) => n(e, [])), i;
|
|
56
|
+
}, [r]);
|
|
57
57
|
function be({
|
|
58
|
-
id:
|
|
59
|
-
label:
|
|
58
|
+
id: r,
|
|
59
|
+
label: i = "",
|
|
60
60
|
isSingleSelect: n = !1,
|
|
61
61
|
selectedItems: e = [],
|
|
62
|
-
locale:
|
|
63
|
-
size:
|
|
64
|
-
variant:
|
|
62
|
+
locale: c = "en-US",
|
|
63
|
+
size: o = "md",
|
|
64
|
+
variant: a = "outline",
|
|
65
65
|
asPlainText: l = !1,
|
|
66
|
-
onSearch:
|
|
66
|
+
onSearch: f,
|
|
67
67
|
items: I,
|
|
68
68
|
maxVisibleItems: M,
|
|
69
69
|
onChange: L,
|
|
@@ -79,60 +79,60 @@ function be({
|
|
|
79
79
|
collapsed: K = !1,
|
|
80
80
|
...Q
|
|
81
81
|
}) {
|
|
82
|
-
const [H,
|
|
83
|
-
let
|
|
82
|
+
const [H, b] = g(""), [X, j] = g(!1), k = oe[c], w = _(null), O = _(null), d = ie(I, k), Y = H.toLowerCase() === e[0]?.label.toLowerCase(), v = H.length > 0 && !(l && Y);
|
|
83
|
+
let h = d.current;
|
|
84
84
|
if (v) {
|
|
85
|
-
const t = [],
|
|
86
|
-
t.push(s), s.children && s.children.forEach(
|
|
85
|
+
const t = [], p = (s) => {
|
|
86
|
+
t.push(s), s.children && s.children.forEach(p);
|
|
87
87
|
};
|
|
88
|
-
I.forEach(
|
|
88
|
+
I.forEach(p), h = t.filter((s) => {
|
|
89
89
|
const F = s.label.toLowerCase().includes(H.toLowerCase());
|
|
90
90
|
return (!(s.children && s.children.length > 0) || s.isSelectableParent) && F;
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
|
-
const E = le(
|
|
93
|
+
const E = le(h, O), u = se(E, l, b, S, f);
|
|
94
94
|
q(() => {
|
|
95
|
-
l && !
|
|
96
|
-
}, [
|
|
97
|
-
const [P, Z] =
|
|
95
|
+
l && !u.isOpen && b(e[0]?.label || "");
|
|
96
|
+
}, [u.isOpen, e, l]);
|
|
97
|
+
const [P, Z] = g([]);
|
|
98
98
|
q(() => {
|
|
99
|
-
!
|
|
100
|
-
}, [
|
|
99
|
+
!u.isOpen || n || Z(e);
|
|
100
|
+
}, [u.isOpen]), v || (h = [
|
|
101
101
|
...P,
|
|
102
|
-
...
|
|
102
|
+
...h.filter((t) => !P.find((p) => p.label === t.label))
|
|
103
103
|
]);
|
|
104
104
|
let y = !1;
|
|
105
|
-
x ?
|
|
105
|
+
x ? h = e : (y = h.length > (M ?? 1 / 0), h = h.slice(0, M));
|
|
106
106
|
const $ = ce(I), R = (t) => {
|
|
107
107
|
if (!t || x || S)
|
|
108
108
|
return;
|
|
109
109
|
if (O.current?.parentNode?.querySelector("input")?.focus(), t.id === "_back") {
|
|
110
|
-
|
|
110
|
+
d.back();
|
|
111
111
|
return;
|
|
112
112
|
}
|
|
113
|
-
const
|
|
114
|
-
if (!v && !
|
|
115
|
-
|
|
113
|
+
const p = d.opened.length > 0 && d.opened[d.opened.length - 1]?.id === t.id;
|
|
114
|
+
if (!v && !p && t.children && t.children.length > 0) {
|
|
115
|
+
d.open(t), requestAnimationFrame(() => E.set(1));
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
118
|
let s = [t];
|
|
119
|
-
n || (e.some((C) => C.id === t.id) ? s = e.filter((C) => C.id !== t.id) : s = [...e, t]),
|
|
119
|
+
n || (e.some((C) => C.id === t.id) ? s = e.filter((C) => C.id !== t.id) : s = [...e, t]), l ? b(s[0]?.label ?? "") : (b(""), f?.("")), n && (s.length === 0 ? u.open() : u.close()), L && L(s);
|
|
120
120
|
}, T = e.length === 0 ? m ?? k.search : void 0, D = (t) => {
|
|
121
|
-
w.current?.contains(t.relatedTarget) || (
|
|
121
|
+
w.current?.contains(t.relatedTarget) || (u.close(), j(!1), N && N(e));
|
|
122
122
|
}, A = {
|
|
123
|
-
id:
|
|
123
|
+
id: r,
|
|
124
124
|
asPlainText: l,
|
|
125
125
|
inputValue: H,
|
|
126
126
|
selectedItems: e,
|
|
127
|
-
displayItems:
|
|
127
|
+
displayItems: h,
|
|
128
128
|
toggleItem: R,
|
|
129
129
|
highlightState: E,
|
|
130
|
-
openState:
|
|
130
|
+
openState: u,
|
|
131
131
|
parentStrings: $,
|
|
132
132
|
// Button
|
|
133
|
-
size:
|
|
134
|
-
variant:
|
|
135
|
-
label:
|
|
133
|
+
size: o,
|
|
134
|
+
variant: a,
|
|
135
|
+
label: i,
|
|
136
136
|
placeHolderText: T,
|
|
137
137
|
isDisabled: S,
|
|
138
138
|
isReadOnly: x,
|
|
@@ -140,8 +140,8 @@ function be({
|
|
|
140
140
|
collapsed: K,
|
|
141
141
|
hasPendingDelete: X,
|
|
142
142
|
setHasPendingDelete: j,
|
|
143
|
-
setInputValue:
|
|
144
|
-
onSearch:
|
|
143
|
+
setInputValue: b,
|
|
144
|
+
onSearch: f,
|
|
145
145
|
// Menu
|
|
146
146
|
isSingleSelect: n,
|
|
147
147
|
isSearching: v,
|
|
@@ -152,7 +152,7 @@ function be({
|
|
|
152
152
|
parentRef: w,
|
|
153
153
|
popupRef: O,
|
|
154
154
|
footerContent: z,
|
|
155
|
-
subMenuState:
|
|
155
|
+
subMenuState: d,
|
|
156
156
|
translation: k
|
|
157
157
|
};
|
|
158
158
|
return /* @__PURE__ */ ee(
|
|
@@ -160,14 +160,14 @@ function be({
|
|
|
160
160
|
{
|
|
161
161
|
role: "combobox",
|
|
162
162
|
as: "label",
|
|
163
|
-
htmlFor:
|
|
163
|
+
htmlFor: r,
|
|
164
164
|
className: "combobox",
|
|
165
165
|
ref: w,
|
|
166
|
-
onClick:
|
|
166
|
+
onClick: u.open,
|
|
167
167
|
onBlur: D,
|
|
168
168
|
overflow: "visible",
|
|
169
169
|
width: "100%",
|
|
170
|
-
"aria-expanded":
|
|
170
|
+
"aria-expanded": u.isOpen,
|
|
171
171
|
"aria-invalid": B,
|
|
172
172
|
"aria-required": W,
|
|
173
173
|
"aria-disabled": S,
|
|
@@ -175,7 +175,7 @@ function be({
|
|
|
175
175
|
...Q,
|
|
176
176
|
children: [
|
|
177
177
|
/* @__PURE__ */ V(te, { ...A }),
|
|
178
|
-
|
|
178
|
+
u.isOpen && /* @__PURE__ */ V(re, { ...A })
|
|
179
179
|
]
|
|
180
180
|
}
|
|
181
181
|
);
|