@caspeco/casper-ui-library 10.3.0 → 10.3.1

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,EAGb,MAAM,SAAS,CAAC;AA0GjB;;;;;;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,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,SAAiB,EACjB,WAAuB,EACvB,qBAAiD,EACjD,qBAAqB,EACrB,GAAG,KAAK,EACR,EAAE,aAAa,+BA2Uf"}
1
+ {"version":3,"file":"combobox.d.ts","sourceRoot":"","sources":["../../../lib/components/combobox/combobox.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAIX,aAAa,EAGb,MAAM,SAAS,CAAC;AA0GjB;;;;;;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,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,SAAiB,EACjB,WAAuB,EACvB,qBAAiD,EACjD,qBAAqB,EACrB,GAAG,KAAK,EACR,EAAE,aAAa,+BA8Vf"}
@@ -1,263 +1,275 @@
1
1
  import { jsx as U, jsxs as Se } from "react/jsx-runtime";
2
2
  import { c as V } from "../../_virtual/compiler-runtime.js";
3
3
  import { useFieldContext as Ce, Box as Oe } from "@chakra-ui/react";
4
- import { useState as y, useRef as Z } from "react";
5
- import { ComboboxButton as ke } from "./combobox-button.js";
6
- import { ComboboxMenu as we } from "./combobox-menu.js";
7
- import { translations as xe } from "./translations.js";
8
- const Pe = (o, a) => {
9
- const e = V.c(15), [n, f] = y(0);
10
- let h;
11
- e[0] !== a ? (h = (g) => {
4
+ import { useState as y, useRef as Y, useEffect as ke } from "react";
5
+ import { ComboboxButton as we } from "./combobox-button.js";
6
+ import { ComboboxMenu as xe } from "./combobox-menu.js";
7
+ import { translations as Ee } from "./translations.js";
8
+ const ye = (l, a) => {
9
+ const e = V.c(15), [n, u] = y(0);
10
+ let p;
11
+ e[0] !== a ? (p = (b) => {
12
12
  if (!a.current)
13
13
  return;
14
14
  const v = [...a.current.querySelectorAll("li")];
15
- v[g] && (v[g]?.scrollIntoView({
15
+ v[b] && (v[b]?.scrollIntoView({
16
16
  behavior: "smooth",
17
17
  block: "nearest"
18
- }), f(g));
19
- }, e[0] = a, e[1] = h) : h = e[1];
20
- const t = h;
18
+ }), u(b));
19
+ }, e[0] = a, e[1] = p) : p = e[1];
20
+ const t = p;
21
21
  let i;
22
- e[2] !== n || e[3] !== o || e[4] !== t ? (i = () => t((n + 1) % o.length), e[2] = n, e[3] = o, e[4] = t, e[5] = i) : i = e[5];
23
- const p = i;
24
- let l;
25
- e[6] !== n || e[7] !== o || e[8] !== t ? (l = () => t((n - 1 + o.length) % o.length), e[6] = n, e[7] = o, e[8] = t, e[9] = l) : l = e[9];
26
- const c = l;
22
+ e[2] !== n || e[3] !== l || e[4] !== t ? (i = () => t((n + 1) % l.length), e[2] = n, e[3] = l, e[4] = t, e[5] = i) : i = e[5];
23
+ const g = i;
24
+ let s;
25
+ e[6] !== n || e[7] !== l || e[8] !== t ? (s = () => t((n - 1 + l.length) % l.length), e[6] = n, e[7] = l, e[8] = t, e[9] = s) : s = e[9];
26
+ const c = s;
27
27
  let d;
28
- return e[10] !== n || e[11] !== t || e[12] !== p || e[13] !== c ? (d = {
28
+ return e[10] !== n || e[11] !== t || e[12] !== g || e[13] !== c ? (d = {
29
29
  index: n,
30
30
  set: t,
31
- next: p,
31
+ next: g,
32
32
  previous: c
33
- }, e[10] = n, e[11] = t, e[12] = p, e[13] = c, e[14] = d) : d = e[14], d;
34
- }, ye = (o, a, e, n, f, h) => {
35
- const t = V.c(13), [i, p] = y(!1), l = i && !n;
33
+ }, e[10] = n, e[11] = t, e[12] = g, e[13] = c, e[14] = d) : d = e[14], d;
34
+ }, Pe = (l, a, e, n, u, p) => {
35
+ const t = V.c(13), [i, g] = y(!1), s = i && !n;
36
36
  let c;
37
- t[0] !== a || t[1] !== f || t[2] !== e ? (c = () => {
38
- a || (e(""), f?.("")), p(!1);
39
- }, t[0] = a, t[1] = f, t[2] = e, t[3] = c) : c = t[3];
37
+ t[0] !== a || t[1] !== u || t[2] !== e ? (c = () => {
38
+ a || (e(""), u?.("")), g(!1);
39
+ }, t[0] = a, t[1] = u, t[2] = e, t[3] = c) : c = t[3];
40
40
  const d = c;
41
- let g;
42
- t[4] !== o || t[5] !== n || t[6] !== l || t[7] !== h ? (g = () => {
43
- l || n || (p(!0), o.set(0), h?.());
44
- }, t[4] = o, t[5] = n, t[6] = l, t[7] = h, t[8] = g) : g = t[8];
45
- const v = g;
46
- let O;
47
- return t[9] !== d || t[10] !== l || t[11] !== v ? (O = {
48
- isOpen: l,
41
+ let b;
42
+ t[4] !== l || t[5] !== n || t[6] !== s || t[7] !== p ? (b = () => {
43
+ s || n || (g(!0), l.set(0), p?.());
44
+ }, t[4] = l, t[5] = n, t[6] = s, t[7] = p, t[8] = b) : b = t[8];
45
+ const v = b;
46
+ let k;
47
+ return t[9] !== d || t[10] !== s || t[11] !== v ? (k = {
48
+ isOpen: s,
49
49
  close: d,
50
50
  open: v
51
- }, t[9] = d, t[10] = l, t[11] = v, t[12] = O) : O = t[12], O;
52
- }, m = (o, a) => {
53
- for (const e of o) {
51
+ }, t[9] = d, t[10] = s, t[11] = v, t[12] = k) : k = t[12], k;
52
+ }, Z = (l, a) => {
53
+ for (const e of l) {
54
54
  if (e.id === a) return [];
55
55
  if (e.children) {
56
- const n = m(e.children, a);
56
+ const n = Z(e.children, a);
57
57
  if (n !== void 0) return [e, ...n];
58
58
  }
59
59
  }
60
- }, He = (o, a) => {
60
+ }, qe = (l, a) => {
61
61
  const e = V.c(14);
62
62
  let n;
63
63
  e[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (n = [], e[0] = n) : n = e[0];
64
- const [f, h] = y(n);
64
+ const [u, p] = y(n);
65
65
  let t;
66
- if (!f.length)
67
- t = o;
66
+ if (!u.length)
67
+ t = l;
68
68
  else {
69
- const c = f[f.length - 1];
69
+ const c = u[u.length - 1];
70
70
  let d;
71
71
  e[1] !== a.back ? (d = {
72
72
  id: "_back",
73
73
  label: a.back
74
74
  }, e[1] = a.back, e[2] = d) : d = e[2];
75
- const g = d;
75
+ const b = d;
76
76
  let v;
77
77
  e[3] !== c?.children ? (v = c?.children || [], e[3] = c?.children, e[4] = v) : v = e[4];
78
- const O = v;
79
- let H;
80
- e[5] !== g || e[6] !== O || e[7] !== c ? (H = c?.isSelectableParent ? [g, c, ...O] : [g, ...O], e[5] = g, e[6] = O, e[7] = c, e[8] = H) : H = e[8], t = H;
78
+ const k = v;
79
+ let P;
80
+ e[5] !== b || e[6] !== k || e[7] !== c ? (P = c?.isSelectableParent ? [b, c, ...k] : [b, ...k], e[5] = b, e[6] = k, e[7] = c, e[8] = P) : P = e[8], t = P;
81
81
  }
82
- let i, p;
82
+ let i, g;
83
83
  e[9] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (i = (c) => {
84
- h((d) => [...d, c]);
85
- }, p = () => {
86
- h(Ee);
87
- }, e[9] = i, e[10] = p) : (i = e[9], p = e[10]);
88
- let l;
89
- return e[11] !== t || e[12] !== f ? (l = {
84
+ p((d) => [...d, c]);
85
+ }, g = () => {
86
+ p(Ie);
87
+ }, e[9] = i, e[10] = g) : (i = e[9], g = e[10]);
88
+ let s;
89
+ return e[11] !== t || e[12] !== u ? (s = {
90
90
  open: i,
91
- back: p,
92
- setPath: h,
93
- opened: f,
91
+ back: g,
92
+ setPath: p,
93
+ opened: u,
94
94
  current: t
95
- }, e[11] = t, e[12] = f, e[13] = l) : l = e[13], l;
96
- }, qe = (o) => {
95
+ }, e[11] = t, e[12] = u, e[13] = s) : s = e[13], s;
96
+ }, He = (l) => {
97
97
  const a = {};
98
- function e(n, f) {
99
- a[n.id] = [...f], n.children && n.children.forEach((h) => e(h, [...f, n.label]));
98
+ function e(n, u) {
99
+ a[n.id] = [...u], n.children && n.children.forEach((p) => e(p, [...u, n.label]));
100
100
  }
101
- return o.forEach((n) => e(n, [])), a;
101
+ return l.forEach((n) => e(n, [])), a;
102
102
  };
103
103
  function Ne({
104
- id: o,
104
+ id: l,
105
105
  label: a = "",
106
106
  isSingleSelect: e = !1,
107
107
  selectedItems: n = [],
108
- locale: f = "en-US",
109
- size: h = "md",
108
+ locale: u = "en-US",
109
+ size: p = "md",
110
110
  variant: t = "outline",
111
111
  asPlainText: i = !1,
112
- onSearch: p,
113
- items: l,
112
+ onSearch: g,
113
+ items: s,
114
114
  maxVisibleItems: c,
115
115
  onChange: d,
116
- onBlur: g,
116
+ onBlur: b,
117
117
  isDisabled: v,
118
- isReadOnly: O,
119
- isRequired: H,
118
+ isReadOnly: k,
119
+ isRequired: P,
120
120
  placeholder: T,
121
121
  footerContent: _,
122
122
  popoverWidth: ee,
123
123
  popoverPlacement: ne,
124
124
  collapsed: te = !1,
125
- folderStyle: E = "grouped",
126
- keepSearchAfterSelect: re = E === "stacked",
125
+ folderStyle: H = "grouped",
126
+ keepSearchAfterSelect: re = H === "stacked",
127
127
  parentSelectsChildren: W,
128
128
  ...oe
129
129
  }) {
130
- const [I, q] = y(i ? n[0]?.label ?? "" : ""), [le, z] = y(!1), R = xe[f], F = Z(null), N = Z(null), x = He(l, R), se = I.toLowerCase() === n[0]?.label.toLowerCase(), A = I.length > 0 && !(i && se), B = Ce(), J = B?.invalid ?? !1, L = v ?? B?.disabled ?? !1, M = O ?? B?.readOnly ?? !1, ie = H ?? B?.required ?? !1;
130
+ const [I, q] = y(i ? n[0]?.label ?? "" : ""), [le, m] = y(!1), R = Ee[u], D = Y(null), A = Y(null), x = qe(s, R), se = I.toLowerCase() === n[0]?.label.toLowerCase(), B = I.length > 0 && !(i && se), F = Ce(), z = F?.invalid ?? !1, L = v ?? F?.disabled ?? !1, M = k ?? F?.readOnly ?? !1, ie = P ?? F?.required ?? !1;
131
131
  let w = x.current;
132
- if (A) {
133
- const r = [], s = I.toLowerCase();
134
- if (E === "stacked") {
135
- const b = (S) => S.map((C) => {
136
- const G = C.label.toLowerCase().includes(s), u = C.children && C.children.length > 0;
132
+ if (B) {
133
+ const r = [], o = I.toLowerCase();
134
+ if (H === "stacked") {
135
+ const f = (C) => C.map((O) => {
136
+ const G = O.label.toLowerCase().includes(o), h = O.children && O.children.length > 0;
137
137
  if (G)
138
- return C;
139
- if (u) {
140
- const P = b(C.children);
141
- if (P.length > 0) {
142
- const Y = {
143
- ...C
138
+ return O;
139
+ if (h) {
140
+ const E = f(O.children);
141
+ if (E.length > 0) {
142
+ const X = {
143
+ ...O
144
144
  };
145
- return Y.children = P, Y;
145
+ return X.children = E, X;
146
146
  }
147
147
  }
148
148
  }).filter(Boolean);
149
- w = b(l);
149
+ w = f(s);
150
150
  } else {
151
- const b = (S) => {
152
- r.push(S), S.children && S.children.forEach(b);
151
+ const f = (C) => {
152
+ r.push(C), C.children && C.children.forEach(f);
153
153
  };
154
- l.forEach(b), w = r.filter((S) => {
155
- const C = S.label.toLowerCase().includes(I.toLowerCase());
156
- return (!(S.children && S.children.length > 0) || S.isSelectableParent) && C;
154
+ s.forEach(f), w = r.filter((C) => {
155
+ const O = C.label.toLowerCase().includes(I.toLowerCase());
156
+ return (!(C.children && C.children.length > 0) || C.isSelectableParent) && O;
157
157
  });
158
158
  }
159
159
  }
160
- const $ = Pe(w, N), [j, ce] = y([]), k = ye($, i, q, L, p, () => {
161
- if (E !== "stacked") {
160
+ const N = ye(w, A), [$, ce] = y([]), S = Pe(N, i, q, L, g, () => {
161
+ if (H !== "stacked") {
162
162
  if (e) {
163
- const r = n[0]?.id, s = r ? m(l, r) ?? [] : [];
164
- x.setPath(s);
163
+ const r = n[0]?.id, o = r ? Z(s, r) ?? [] : [];
164
+ x.setPath(o);
165
165
  return;
166
166
  }
167
167
  ce(n);
168
168
  }
169
- }), [D, ae] = y({
170
- isOpen: k.isOpen,
169
+ }), [j, ae] = y({
170
+ isOpen: S.isOpen,
171
171
  selectedItems: n,
172
172
  asPlainText: i
173
173
  });
174
- (D.isOpen !== k.isOpen || D.selectedItems !== n || D.asPlainText !== i) && (ae({
175
- isOpen: k.isOpen,
174
+ (j.isOpen !== S.isOpen || j.selectedItems !== n || j.asPlainText !== i) && (ae({
175
+ isOpen: S.isOpen,
176
176
  selectedItems: n,
177
177
  asPlainText: i
178
- }), i && !k.isOpen && q(n[0]?.label ?? "")), A || (w = [...j, ...w.filter((r) => !j.find((s) => s.label === r.label))]);
179
- let K = !1;
180
- M ? w = n : (K = w.length > (c ?? 1 / 0), w = w.slice(0, c));
181
- const de = qe(l), fe = (r) => {
182
- const s = x.opened.length > 0 && x.opened[x.opened.length - 1]?.id === r.id, b = r.children && r.children.length > 0;
183
- if (!A && !s && b) {
184
- x.open(r), requestAnimationFrame(() => $.set(1));
178
+ }), i && !S.isOpen && q(n[0]?.label ?? "")), B || (w = [...$, ...w.filter((r) => !$.find((o) => o.label === r.label))]);
179
+ let J = !1;
180
+ M ? w = n : (J = w.length > (c ?? 1 / 0), w = w.slice(0, c));
181
+ const de = He(s), fe = (r) => {
182
+ const o = x.opened.length > 0 && x.opened[x.opened.length - 1]?.id === r.id, f = r.children && r.children.length > 0;
183
+ if (!B && !o && f) {
184
+ x.open(r), requestAnimationFrame(() => N.set(1));
185
185
  return;
186
186
  }
187
- return e ? [r] : Q(r);
187
+ return e ? [r] : K(r);
188
188
  }, ue = (r) => {
189
- const s = r.children && r.children.length > 0;
190
- if (!(s && !r.isSelectableParent && (e || !W)))
191
- return e ? [r] : s ? he(r) : Q(r);
192
- }, Q = (r) => n.some((b) => b.id === r.id) ? n.filter((b) => b.id !== r.id) : [...n, r];
189
+ const o = r.children && r.children.length > 0;
190
+ if (!(o && !r.isSelectableParent && (e || !W)))
191
+ return e ? [r] : o ? he(r) : K(r);
192
+ }, K = (r) => n.some((f) => f.id === r.id) ? n.filter((f) => f.id !== r.id) : [...n, r];
193
193
  function he(r) {
194
- let s;
195
- const b = [], S = (u) => {
196
- u.children && u.children.length > 0 ? (u.isSelectableParent && b.push(u), u.children.forEach(S)) : b.push(u);
194
+ let o;
195
+ const f = [], C = (h) => {
196
+ h.children && h.children.length > 0 ? (h.isSelectableParent && f.push(h), h.children.forEach(C)) : f.push(h);
197
197
  };
198
- S(r);
199
- const C = n.filter((u) => b.some((P) => P.id === u.id));
200
- return C.length > 0 && (!r.isSelectableParent || C.some((u) => u.id === r.id)) ? s = n.filter((u) => !C.some((P) => P.id === u.id)) : s = [...n, ...b.filter((u) => !n.some((P) => P.id === u.id))], s;
198
+ C(r);
199
+ const O = n.filter((h) => f.some((E) => E.id === h.id));
200
+ return O.length > 0 && (!r.isSelectableParent || O.some((h) => h.id === r.id)) ? o = n.filter((h) => !O.some((E) => E.id === h.id)) : o = [...n, ...f.filter((h) => !n.some((E) => E.id === h.id))], o;
201
201
  }
202
202
  const pe = (r) => {
203
203
  if (!r || M || L)
204
204
  return;
205
- if (N.current?.parentNode?.querySelector("input")?.focus(), r.id === "_back") {
205
+ if (A.current?.parentNode?.querySelector("input")?.focus(), r.id === "_back") {
206
206
  x.back();
207
207
  return;
208
208
  }
209
- let s;
210
- E === "grouped" ? s = fe(r) : s = ue(r), s && (i ? q(s[0]?.label ?? "") : re || (q(""), p?.("")), e && (s.length === 0 ? k.open() : k.close()), d && d(s));
209
+ let o;
210
+ H === "grouped" ? o = fe(r) : o = ue(r), o && (i ? q(o[0]?.label ?? "") : re || (q(""), g?.("")), e && (o.length === 0 ? S.open() : S.close()), d && d(o));
211
211
  }, ge = () => {
212
- M || L || n.length === 0 || (q(""), p?.(""), d?.([]));
213
- }, be = n.length === 0 ? T ?? R.search : void 0, ve = (r) => {
214
- F.current?.contains(r.relatedTarget) || (k.close(), z(!1), g && g(n));
215
- }, X = {
216
- id: o,
212
+ M || L || n.length === 0 || (q(""), g?.(""), d?.([]));
213
+ }, be = n.length === 0 ? T ?? R.search : void 0;
214
+ ke(() => {
215
+ const r = A.current?.querySelector("[role='listbox']");
216
+ if (!r || !S.isOpen)
217
+ return;
218
+ const o = (f) => {
219
+ f.target === r && f.preventDefault();
220
+ };
221
+ return r.addEventListener("mousedown", o, !0), () => {
222
+ r.removeEventListener("mousedown", o, !0);
223
+ };
224
+ }, [S.isOpen]);
225
+ const ve = (r) => {
226
+ D.current?.contains(r.relatedTarget) || (S.close(), m(!1), b && b(n));
227
+ }, Q = {
228
+ id: l,
217
229
  asPlainText: i,
218
230
  inputValue: I,
219
231
  selectedItems: n,
220
232
  displayItems: w,
221
233
  toggleItem: pe,
222
234
  clearSelection: ge,
223
- highlightState: $,
224
- openState: k,
235
+ highlightState: N,
236
+ openState: S,
225
237
  parentStrings: de,
226
238
  // Button
227
- size: h,
239
+ size: p,
228
240
  variant: t,
229
241
  label: a,
230
242
  placeHolderText: be,
231
243
  isDisabled: L,
232
244
  isReadOnly: M,
233
- isInvalid: J,
245
+ isInvalid: z,
234
246
  collapsed: te,
235
247
  hasPendingDelete: le,
236
- setHasPendingDelete: z,
248
+ setHasPendingDelete: m,
237
249
  setInputValue: q,
238
- onSearch: p,
250
+ onSearch: g,
239
251
  // Menu
240
252
  isSingleSelect: e,
241
- isSearching: A,
242
- isHidingItems: K,
253
+ isSearching: B,
254
+ isHidingItems: J,
243
255
  popoverWidth: ee,
244
256
  popoverPlacement: ne,
245
- previousSelectedItems: j,
246
- parentRef: F,
247
- popupRef: N,
257
+ previousSelectedItems: $,
258
+ parentRef: D,
259
+ popupRef: A,
248
260
  footerContent: _,
249
261
  subMenuState: x,
250
262
  translation: R,
251
- folderStyle: E,
263
+ folderStyle: H,
252
264
  parentSelectsChildren: W
253
265
  };
254
- return /* @__PURE__ */ U(Oe, { role: "combobox", asChild: !0, className: "combobox", ref: F, onClick: k.open, onBlur: ve, overflow: "visible", width: "100%", "aria-expanded": k.isOpen, "aria-required": ie, "aria-disabled": L, "aria-readonly": M, "aria-invalid": J, ...oe, children: /* @__PURE__ */ Se("label", { htmlFor: o, children: [
255
- /* @__PURE__ */ U(ke, { ...X }),
256
- k.isOpen && /* @__PURE__ */ U(we, { ...X })
266
+ return /* @__PURE__ */ U(Oe, { role: "combobox", asChild: !0, className: "combobox", ref: D, onClick: S.open, onBlur: ve, overflow: "visible", width: "100%", "aria-expanded": S.isOpen, "aria-required": ie, "aria-disabled": L, "aria-readonly": M, "aria-invalid": z, ...oe, children: /* @__PURE__ */ Se("label", { htmlFor: l, children: [
267
+ /* @__PURE__ */ U(we, { ...Q }),
268
+ S.isOpen && /* @__PURE__ */ U(xe, { ...Q })
257
269
  ] }) });
258
270
  }
259
- function Ee(o) {
260
- return o.slice(0, -1);
271
+ function Ie(l) {
272
+ return l.slice(0, -1);
261
273
  }
262
274
  export {
263
275
  Ne as Combobox
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caspeco/casper-ui-library",
3
- "version": "10.3.0",
3
+ "version": "10.3.1",
4
4
  "prettier": "@caspeco/prettier-config",
5
5
  "type": "module",
6
6
  "sideEffects": false,