@stackone/malachite 2.27.0 → 2.27.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,387 +1,491 @@
1
- import { jsx as r, jsxs as b, Fragment as st } from "react/jsx-runtime";
2
- import ct, { useId as dt, useState as H, useRef as R, useMemo as _, useCallback as m, useEffect as He, useLayoutEffect as ut, useInsertionEffect as ft } from "react";
3
- import { createPortal as mt } from "react-dom";
4
- import ht, { useFormFieldIds as pt } from "./BaseFormComponent.js";
5
- import gt from "./CustomIcons/CaretDownIcon.js";
6
- import vt from "./CustomIcons/InfoFilledIcon.js";
7
- import xt from "./CustomIcons/SearchIcon.js";
1
+ import { jsx as r, jsxs as w, Fragment as dt } from "react/jsx-runtime";
2
+ import ut, { useId as ft, useState as H, useRef as T, useMemo as D, useCallback as p, useEffect as Pe, useLayoutEffect as mt, useInsertionEffect as ht } from "react";
3
+ import { createPortal as pt } from "react-dom";
4
+ import gt, { useFormFieldIds as bt } from "./BaseFormComponent.js";
5
+ import vt from "./CustomIcons/CaretDownIcon.js";
6
+ import xt from "./CustomIcons/InfoFilledIcon.js";
7
+ import yt from "./CustomIcons/SearchIcon.js";
8
8
  import Me from "./LoadingInput.js";
9
- import bt from "./Spinner.js";
10
- import { Tag as yt } from "./Tag.js";
11
- import Pe from "./Tooltip.js";
12
- import { CONTROL_TEXT_SIZE_CLASS as ie, CONTROL_TEXT_SIZE as wt } from "./controlTextSize.js";
13
- import { controlWidthStyle as We } from "./controlWidth.js";
14
- import { getTriggerVisual as Et, DROPDOWN_TRIGGER_ATTR as It } from "./dropdownTriggerStyle.js";
15
- import { pushEscapeLayer as St } from "./escapeLayers.js";
16
- import { measureMenuGeometry as kt, MENU_MAX_HEIGHT_PX as Rt, MENU_SPECS as M } from "./floatingMenuGeometry.js";
17
- import { ensureMultiSelectPanelStyles as Tt } from "./optionRowStyles.js";
18
- import { overlayIdentity as Lt } from "./portalOverlay.js";
19
- import { useTopLayer as _t } from "./topLayer.js";
20
- const Nt = {
9
+ import wt from "./Spinner.js";
10
+ import { Tag as Et } from "./Tag.js";
11
+ import We from "./Tooltip.js";
12
+ import { CONTROL_TEXT_SIZE_CLASS as de, CONTROL_TEXT_SIZE as It } from "./controlTextSize.js";
13
+ import { controlWidthStyle as $e } from "./controlWidth.js";
14
+ import { getTriggerVisual as St, DROPDOWN_TRIGGER_ATTR as Tt } from "./dropdownTriggerStyle.js";
15
+ import { pushEscapeLayer as kt } from "./escapeLayers.js";
16
+ import { measureMenuGeometry as Lt, MENU_MAX_HEIGHT_PX as Rt, MENU_SPECS as K } from "./floatingMenuGeometry.js";
17
+ import { ensureMultiSelectPanelStyles as Ot } from "./optionRowStyles.js";
18
+ import { overlayIdentity as _t } from "./portalOverlay.js";
19
+ import { useTopLayer as Nt } from "./topLayer.js";
20
+ import { tooltipLines as Ct, isCut as At, isClamped as Dt } from "./truncatedLines.js";
21
+ const Ht = {
21
22
  padding: "8px 10px",
22
23
  color: "var(--malachite-text-secondary, rgb(123, 123, 123))"
23
- }, P = {
24
+ }, z = {
24
25
  small: "h-[var(--malachite-control-height-small,28px)]",
25
26
  medium: "h-[var(--malachite-control-height-medium,32px)]",
26
27
  large: "h-[var(--malachite-control-height-large,42px)]"
27
- }, Ot = {
28
- small: `${P.small} gap-[6px] px-2.5 ${ie.small} rounded-[var(--malachite-radius-10,10px)]`,
29
- medium: `${P.medium} gap-[8px] px-3 ${ie.medium} rounded-xl`,
30
- large: `${P.large} gap-[10px] px-4 ${ie.large} rounded-[var(--malachite-radius-xxl,14px)]`
31
- }, At = 10, $e = "ArrowDown", Be = "ArrowUp", Ge = "Enter", Ct = "Backspace", Dt = /* @__PURE__ */ new Set([$e, Be, Ge]), Ke = ct.forwardRef(
32
- ({ triggerRole: i, disabled: N, children: W, ...E }, I) => i !== "button" ? /* @__PURE__ */ r(
28
+ }, Pt = {
29
+ small: `${z.small} gap-[6px] px-2.5 ${de.small} rounded-[var(--malachite-radius-10,10px)]`,
30
+ medium: `${z.medium} gap-[8px] px-3 ${de.medium} rounded-xl`,
31
+ large: `${z.large} gap-[10px] px-4 ${de.large} rounded-[var(--malachite-radius-xxl,14px)]`
32
+ }, Mt = 10, Ke = "ArrowDown", ze = "ArrowUp", Fe = "Enter", Wt = "Backspace", $t = /* @__PURE__ */ new Set([Ke, ze, Fe]), Ye = ut.forwardRef(
33
+ ({ triggerRole: n, disabled: k, children: R, ...u }, g) => n !== "button" ? /* @__PURE__ */ r(
33
34
  "div",
34
35
  {
35
- ref: I,
36
- role: i,
37
- tabIndex: N ? -1 : 0,
38
- ...E,
39
- children: W
36
+ ref: g,
37
+ role: n,
38
+ tabIndex: k ? -1 : 0,
39
+ ...u,
40
+ children: R
40
41
  }
41
42
  ) : /* @__PURE__ */ r(
42
43
  "button",
43
44
  {
44
- ref: I,
45
+ ref: g,
45
46
  type: "button",
46
- disabled: N,
47
- ...E,
48
- children: W
47
+ disabled: k,
48
+ ...u,
49
+ children: R
49
50
  }
50
51
  )
51
52
  );
52
- Ke.displayName = "TriggerElement";
53
- const er = ({
54
- options: i,
55
- value: N,
56
- defaultValue: W,
57
- onChange: E,
58
- placeholder: I = "Select",
59
- renderTrigger: U,
60
- searchable: ze,
61
- size: $ = "large",
62
- width: V = "auto",
63
- minWidth: se,
64
- disabled: S = !1,
65
- error: ce = !1,
66
- loading: y = !1,
67
- label: B,
68
- name: de,
69
- description: j,
70
- tooltip: ue,
71
- hint: X,
72
- rightSideContent: fe,
73
- required: Z = !1,
74
- requiredIndicator: Fe,
75
- formControl: me,
76
- chips: q = !1,
77
- chipsRemovable: J = !0,
78
- chipsMax: he = "auto",
79
- inlineSearch: h = !1,
80
- onSearchChange: O,
81
- localFilter: pe = !0,
82
- className: Ye = "",
83
- style: Ue,
84
- id: Ve,
85
- "aria-label": ge,
86
- "aria-labelledby": je
53
+ Ye.displayName = "TriggerElement";
54
+ const Be = 0.6, Ge = 420, Bt = ({ option: n }) => {
55
+ const k = T(null), R = T(null), u = n.description ? n.descriptionMode ?? "icon" : null, g = u === "subtitle", [_, Z] = H({ label: !0, subtitle: !0 }), N = () => {
56
+ const E = At(k.current), m = Dt(R.current);
57
+ return !E && !m && u !== "hover" ? !1 : (Z({ label: E, subtitle: m }), !0);
58
+ }, P = u === "hover" || g && _.subtitle, M = (E) => /* @__PURE__ */ r(
59
+ We,
60
+ {
61
+ text: Ct([
62
+ ["label", _.label && n.label],
63
+ ["description", P && n.description]
64
+ ]),
65
+ shouldShow: N,
66
+ delay: Be,
67
+ maxWidth: Ge,
68
+ triggerAs: "span",
69
+ isShrinkable: !0,
70
+ describesTrigger: u === "hover",
71
+ children: E
72
+ }
73
+ ), b = /* @__PURE__ */ r(
74
+ "span",
75
+ {
76
+ ref: k,
77
+ style: {
78
+ display: "block",
79
+ overflow: "hidden",
80
+ textOverflow: "ellipsis",
81
+ whiteSpace: "nowrap"
82
+ },
83
+ children: n.label
84
+ }
85
+ );
86
+ return g ? M(
87
+ /* @__PURE__ */ w(
88
+ "span",
89
+ {
90
+ style: {
91
+ flex: 1,
92
+ minWidth: 0,
93
+ display: "flex",
94
+ flexDirection: "column",
95
+ alignItems: "stretch",
96
+ gap: 2
97
+ },
98
+ children: [
99
+ b,
100
+ /* @__PURE__ */ r(
101
+ "span",
102
+ {
103
+ ref: R,
104
+ style: {
105
+ fontSize: 12,
106
+ color: "var(--malachite-text-secondary, rgb(123, 123, 123))",
107
+ whiteSpace: "normal",
108
+ lineHeight: 1.3,
109
+ ...n.descriptionMaxLines ? {
110
+ display: "-webkit-box",
111
+ WebkitLineClamp: n.descriptionMaxLines,
112
+ WebkitBoxOrient: "vertical",
113
+ overflow: "hidden"
114
+ } : {}
115
+ },
116
+ children: n.description
117
+ }
118
+ )
119
+ ]
120
+ }
121
+ )
122
+ ) : /* @__PURE__ */ w(
123
+ "span",
124
+ {
125
+ style: {
126
+ flex: 1,
127
+ minWidth: 0,
128
+ display: "flex",
129
+ alignItems: "center",
130
+ gap: 6
131
+ },
132
+ children: [
133
+ M(b),
134
+ u === "icon" && /* @__PURE__ */ r(
135
+ We,
136
+ {
137
+ text: n.description,
138
+ delay: Be,
139
+ maxWidth: Ge,
140
+ children: /* @__PURE__ */ r(
141
+ "span",
142
+ {
143
+ style: {
144
+ cursor: "help",
145
+ color: "var(--malachite-text-placeholder, rgb(187, 187, 187))"
146
+ },
147
+ "aria-label": "More information",
148
+ onClick: (E) => E.stopPropagation(),
149
+ children: n.descriptionIcon ?? /* @__PURE__ */ r(xt, { size: 14 })
150
+ }
151
+ )
152
+ }
153
+ )
154
+ ]
155
+ }
156
+ );
157
+ }, sr = ({
158
+ options: n,
159
+ value: k,
160
+ defaultValue: R,
161
+ onChange: u,
162
+ placeholder: g = "Select",
163
+ renderTrigger: _,
164
+ searchable: Z,
165
+ size: N = "large",
166
+ width: P = "auto",
167
+ minWidth: M,
168
+ disabled: b = !1,
169
+ error: E = !1,
170
+ loading: m = !1,
171
+ label: F,
172
+ name: ue,
173
+ description: q,
174
+ tooltip: fe,
175
+ hint: J,
176
+ rightSideContent: me,
177
+ required: Q = !1,
178
+ requiredIndicator: Ue,
179
+ formControl: he,
180
+ chips: ee = !1,
181
+ chipsRemovable: te = !0,
182
+ chipsMax: pe = "auto",
183
+ inlineSearch: v = !1,
184
+ onSearchChange: W,
185
+ localFilter: ge = !0,
186
+ className: Ve = "",
187
+ style: Xe,
188
+ id: je,
189
+ "aria-label": be,
190
+ "aria-labelledby": Ze
87
191
  }) => {
88
- const ve = dt(), xe = `${ve}-listbox`, be = (e) => `${ve}-option-${e}`, { controlId: ye, labelId: we, descriptionId: Xe, hintId: Ze, describedBy: qe } = pt({
89
- id: Ve,
90
- label: B,
91
- description: j,
92
- hint: X
93
- }), [Je, Qe] = H(() => W ?? []), Q = N !== void 0, u = Q ? N : Je, [s, G] = H(!1), [d, Ee] = H(null), [w, et] = H(""), [p, T] = H(-1), ee = R(null), A = R(null), C = R(null), Ie = R(null);
94
- _t(C, s);
95
- const Se = R([]), te = _(() => new Set(u), [u]), c = _(
96
- () => i.filter((e) => te.has(e.value)),
97
- [i, te]
98
- ), re = typeof he == "number" ? he : void 0, k = _(() => {
99
- if (!pe) return i;
100
- const e = w.trim().toLowerCase();
101
- return e ? i.filter((t) => (t.searchText ?? (typeof t.label == "string" ? t.label : "")).toLowerCase().includes(e)) : i;
102
- }, [i, w, pe]), ne = R(!1), ke = R(""), K = m(
192
+ const ve = ft(), xe = `${ve}-listbox`, ye = (e) => `${ve}-option-${e}`, { controlId: we, labelId: Ee, descriptionId: qe, hintId: Je, describedBy: Qe } = bt({
193
+ id: je,
194
+ label: F,
195
+ description: q,
196
+ hint: J
197
+ }), [et, tt] = H(() => R ?? []), re = k !== void 0, f = re ? k : et, [o, Y] = H(!1), [c, Ie] = H(null), [L, rt] = H(""), [x, C] = H(-1), ne = T(null), $ = T(null), B = T(null), Se = T(null);
198
+ Nt(B, o);
199
+ const Te = T([]), ae = D(() => new Set(f), [f]), s = D(
200
+ () => n.filter((e) => ae.has(e.value)),
201
+ [n, ae]
202
+ ), le = typeof pe == "number" ? pe : void 0, O = D(() => {
203
+ if (!ge) return n;
204
+ const e = L.trim().toLowerCase();
205
+ return e ? n.filter((t) => (t.searchText ?? (typeof t.label == "string" ? t.label : "")).toLowerCase().includes(e)) : n;
206
+ }, [n, L, ge]), oe = T(!1), ke = T(""), U = p(
103
207
  (e, t) => {
104
- ke.current !== e && (ke.current = e, t && (ne.current = !0), et(e), O == null || O(e));
208
+ ke.current !== e && (ke.current = e, t && (oe.current = !0), rt(e), W == null || W(e));
105
209
  },
106
- [O]
107
- ), ae = m(
108
- (e) => K(e, !0),
109
- [K]
110
- ), D = m(() => K("", !1), [K]);
111
- He(() => {
112
- ne.current && (T(-1), ne.current = !1);
113
- }, [w]);
114
- const tt = ze ?? (O !== void 0 || i.length > At), Re = h ? !1 : tt, L = m(() => {
115
- const e = ee.current;
210
+ [W]
211
+ ), se = p(
212
+ (e) => U(e, !0),
213
+ [U]
214
+ ), G = p(() => U("", !1), [U]);
215
+ Pe(() => {
216
+ oe.current && (C(-1), oe.current = !1);
217
+ }, [L]);
218
+ const nt = Z ?? (W !== void 0 || n.length > Mt), Le = v ? !1 : nt, A = p(() => {
219
+ const e = ne.current;
116
220
  if (!e) return;
117
- const t = kt(C.current, {
221
+ const t = Lt(B.current, {
118
222
  triggerRect: e.getBoundingClientRect(),
119
223
  preset: "standard",
120
- minWidth: se,
224
+ minWidth: M,
121
225
  viewportWidth: window.innerWidth,
122
226
  viewportHeight: window.innerHeight
123
227
  });
124
- Ee(t);
125
- }, [se]);
126
- He(() => {
127
- var x;
128
- if (!s) {
129
- D(), T(-1), Ee(null);
228
+ Ie(t);
229
+ }, [M]);
230
+ Pe(() => {
231
+ var S;
232
+ if (!o) {
233
+ G(), C(-1), Ie(null);
130
234
  return;
131
235
  }
132
- L(), h && ((x = A.current) == null || x.focus());
133
- const e = () => L(), t = (g) => {
134
- const a = g.composedPath(), n = ee.current, o = C.current;
135
- (!n || !a.includes(n)) && (!o || !a.includes(o)) && G(!1);
136
- }, l = St(() => G(!1));
236
+ A(), v && ((S = $.current) == null || S.focus());
237
+ const e = () => A(), t = (y) => {
238
+ const d = y.composedPath(), a = ne.current, i = B.current;
239
+ (!a || !d.includes(a)) && (!i || !d.includes(i)) && Y(!1);
240
+ }, l = kt(() => Y(!1));
137
241
  return window.addEventListener("scroll", e, !0), window.addEventListener("resize", e), document.addEventListener("mousedown", t), () => {
138
242
  window.removeEventListener("scroll", e, !0), window.removeEventListener("resize", e), document.removeEventListener("mousedown", t), l();
139
243
  };
140
- }, [s, L, h, D]), ut(() => {
141
- if (!s)
244
+ }, [o, A, v, G]), mt(() => {
245
+ if (!o)
142
246
  return;
143
- L();
144
- const e = C.current;
247
+ A();
248
+ const e = B.current;
145
249
  if (!e || typeof ResizeObserver > "u")
146
250
  return;
147
- const t = new ResizeObserver(() => L());
251
+ const t = new ResizeObserver(() => A());
148
252
  return t.observe(e), () => t.disconnect();
149
- }, [s, L]);
150
- const v = m(
253
+ }, [o, A]);
254
+ const I = p(
151
255
  (e) => {
152
- Q || Qe(e), E == null || E(e);
256
+ re || tt(e), u == null || u(e);
153
257
  },
154
- [Q, E]
155
- ), z = m(
156
- (e) => i.some((t) => t.value === e && t.disabled),
157
- [i]
158
- ), le = m(
258
+ [re, u]
259
+ ), V = p(
260
+ (e) => n.some((t) => t.value === e && t.disabled),
261
+ [n]
262
+ ), ie = p(
159
263
  (e) => {
160
- z(e) || (u.includes(e) ? v(u.filter((t) => t !== e)) : v([...u, e]));
264
+ V(e) || (f.includes(e) ? I(f.filter((t) => t !== e)) : I([...f, e]));
161
265
  },
162
- [u, v, z]
163
- ), F = _(() => {
266
+ [f, I, V]
267
+ ), X = D(() => {
164
268
  const e = /* @__PURE__ */ new Set();
165
- for (const t of i)
269
+ for (const t of n)
166
270
  t.disabled && e.add(t.value);
167
271
  return e;
168
- }, [i]), rt = m(
272
+ }, [n]), at = p(
169
273
  (e) => {
170
274
  e.stopPropagation();
171
- const t = u.filter((l) => F.has(l));
172
- v(t);
275
+ const t = f.filter((l) => X.has(l));
276
+ I(t);
173
277
  },
174
- [v, u, F]
175
- ), Te = m(
278
+ [I, f, X]
279
+ ), Re = p(
176
280
  (e, t) => {
177
- t.stopPropagation(), !z(e) && v(u.filter((l) => l !== e));
281
+ t.stopPropagation(), !V(e) && I(f.filter((l) => l !== e));
178
282
  },
179
- [u, v, z]
180
- ), Y = m(
283
+ [f, I, V]
284
+ ), j = p(
181
285
  (e) => {
182
- if (!Dt.has(e.key)) return;
183
- if (e.preventDefault(), e.stopPropagation(), !s) {
184
- G(!0);
286
+ if (!$t.has(e.key)) return;
287
+ if (e.preventDefault(), e.stopPropagation(), !o) {
288
+ Y(!0);
185
289
  return;
186
290
  }
187
- const t = k.length;
291
+ const t = O.length;
188
292
  if (t === 0) return;
189
- const l = (a) => {
293
+ const l = (d) => {
190
294
  requestAnimationFrame(() => {
191
- const n = Se.current[a], o = Ie.current;
192
- if (!n || !o) return;
193
- const f = n.offsetTop, Ce = f + n.offsetHeight, De = o.scrollTop, it = De + o.clientHeight;
194
- Ce > it ? o.scrollTo({
195
- top: Ce - o.clientHeight,
295
+ const a = Te.current[d], i = Se.current;
296
+ if (!a || !i) return;
297
+ const h = a.offsetTop, De = h + a.offsetHeight, He = i.scrollTop, ct = He + i.clientHeight;
298
+ De > ct ? i.scrollTo({
299
+ top: De - i.clientHeight,
196
300
  behavior: "smooth"
197
- }) : f < De && o.scrollTo({ top: f, behavior: "smooth" });
301
+ }) : h < He && i.scrollTo({ top: h, behavior: "smooth" });
198
302
  });
199
- }, x = (a) => {
200
- var o;
201
- let n = p;
202
- for (let f = 0; f < t; f++)
203
- if (n = a === 1 ? n < t - 1 ? n + 1 : 0 : n > 0 ? n - 1 : t - 1, !((o = k[n]) != null && o.disabled)) {
204
- l(n), T(n);
303
+ }, S = (d) => {
304
+ var i;
305
+ let a = x;
306
+ for (let h = 0; h < t; h++)
307
+ if (a = d === 1 ? a < t - 1 ? a + 1 : 0 : a > 0 ? a - 1 : t - 1, !((i = O[a]) != null && i.disabled)) {
308
+ l(a), C(a);
205
309
  return;
206
310
  }
207
- }, g = () => {
208
- var o;
209
- if (p < 0 || p >= t || (o = k[p]) != null && o.disabled) return;
210
- const a = k[p].value;
211
- le(a), D();
212
- const n = i.findIndex((f) => f.value === a);
213
- T(n >= 0 ? n : -1), l(n >= 0 ? n : 0), requestAnimationFrame(() => {
214
- var f;
215
- return (f = A.current) == null ? void 0 : f.focus();
311
+ }, y = () => {
312
+ var i;
313
+ if (x < 0 || x >= t || (i = O[x]) != null && i.disabled) return;
314
+ const d = O[x].value;
315
+ ie(d), G();
316
+ const a = n.findIndex((h) => h.value === d);
317
+ C(a >= 0 ? a : -1), l(a >= 0 ? a : 0), requestAnimationFrame(() => {
318
+ var h;
319
+ return (h = $.current) == null ? void 0 : h.focus();
216
320
  });
217
321
  };
218
322
  switch (e.key) {
219
- case $e:
220
- x(1);
323
+ case Ke:
324
+ S(1);
221
325
  break;
222
- case Be:
223
- x(-1);
326
+ case ze:
327
+ S(-1);
224
328
  break;
225
- case Ge:
226
- g();
329
+ case Fe:
330
+ y();
227
331
  break;
228
332
  }
229
333
  },
230
- [s, k, p, le, i, D]
231
- ), Le = m(
334
+ [o, O, x, ie, n, G]
335
+ ), Oe = p(
232
336
  (e) => {
233
- if (e.key === Ct && w === "" && u.length > 0) {
234
- e.preventDefault(), v(u.slice(0, -1)), requestAnimationFrame(() => {
337
+ if (e.key === Wt && L === "" && f.length > 0) {
338
+ e.preventDefault(), I(f.slice(0, -1)), requestAnimationFrame(() => {
235
339
  var t;
236
- return (t = A.current) == null ? void 0 : t.focus();
340
+ return (t = $.current) == null ? void 0 : t.focus();
237
341
  });
238
342
  return;
239
343
  }
240
- Y(e);
344
+ j(e);
241
345
  },
242
- [Y, w, u, v]
243
- ), _e = c.length > 0 && !S && !y, nt = Et({
244
- disabled: S,
245
- error: ce,
246
- open: s,
247
- loading: y,
248
- hasSelection: c.length > 0
249
- }), oe = _(() => h ? /* @__PURE__ */ r(
346
+ [j, L, f, I]
347
+ ), _e = s.length > 0 && !b && !m, lt = St({
348
+ disabled: b,
349
+ error: E,
350
+ open: o,
351
+ loading: m,
352
+ hasSelection: s.length > 0
353
+ }), ce = D(() => v ? /* @__PURE__ */ r(
250
354
  "input",
251
355
  {
252
- ref: A,
356
+ ref: $,
253
357
  type: "text",
254
- value: w,
255
- onChange: (e) => ae(e.target.value),
256
- onKeyDown: Le,
257
- placeholder: c.length === 0 ? I : "",
358
+ value: L,
359
+ onChange: (e) => se(e.target.value),
360
+ onKeyDown: Oe,
361
+ placeholder: s.length === 0 ? g : "",
258
362
  className: "flex-1 w-full min-w-[40px] border-none outline-none bg-transparent text-[length:inherit] p-0 text-[var(--malachite-text-primary,rgb(10,10,10))]",
259
363
  onMouseDown: (e) => {
260
364
  e.preventDefault();
261
365
  }
262
366
  }
263
367
  ) : null, [
264
- h,
265
- w,
266
- ae,
267
- Le,
268
- c.length,
269
- I
270
- ]), at = _(() => {
271
- if (U && c.length > 0)
272
- return U(c);
273
- if (q && c.length > 0) {
274
- const e = re != null ? c.slice(0, re) : c, t = c.length - e.length;
275
- return /* @__PURE__ */ b(
368
+ v,
369
+ L,
370
+ se,
371
+ Oe,
372
+ s.length,
373
+ g
374
+ ]), ot = D(() => {
375
+ if (_ && s.length > 0)
376
+ return _(s);
377
+ if (ee && s.length > 0) {
378
+ const e = le != null ? s.slice(0, le) : s, t = s.length - e.length;
379
+ return /* @__PURE__ */ w(
276
380
  "div",
277
381
  {
278
382
  className: "flex items-center gap-1 overflow-hidden min-w-0 flex-1",
279
383
  style: { flexWrap: "nowrap" },
280
384
  children: [
281
385
  e.map((l) => {
282
- const x = F.has(l.value);
386
+ const S = X.has(l.value);
283
387
  return /* @__PURE__ */ r(
284
- yt,
388
+ Et,
285
389
  {
286
390
  value: l.label,
287
391
  type: "default",
288
392
  textTransform: "none",
289
- onRemove: J && !S && !x ? (g) => Te(l.value, g) : void 0,
393
+ onRemove: te && !b && !S ? (y) => Re(l.value, y) : void 0,
290
394
  className: "shrink-0"
291
395
  },
292
396
  l.value
293
397
  );
294
398
  }),
295
- t > 0 && /* @__PURE__ */ b("span", { className: "shrink-0 text-xs text-[var(--malachite-text-secondary,rgb(123,123,123))]", children: [
399
+ t > 0 && /* @__PURE__ */ w("span", { className: "shrink-0 text-xs text-[var(--malachite-text-secondary,rgb(123,123,123))]", children: [
296
400
  "+",
297
401
  t
298
402
  ] }),
299
- oe
403
+ ce
300
404
  ]
301
405
  }
302
406
  );
303
407
  }
304
- return h && c.length === 0 ? oe : c.length === 0 ? /* @__PURE__ */ r("span", { className: "text-[var(--malachite-text-placeholder)]", children: I }) : c.length === 1 ? /* @__PURE__ */ r("span", { children: c[0].label }) : /* @__PURE__ */ r("span", { children: `${c.length} selected` });
408
+ return v && s.length === 0 ? ce : s.length === 0 ? /* @__PURE__ */ r("span", { className: "text-[var(--malachite-text-placeholder)]", children: g }) : s.length === 1 ? /* @__PURE__ */ r("span", { children: s[0].label }) : /* @__PURE__ */ r("span", { children: `${s.length} selected` });
305
409
  }, [
306
- c,
307
- U,
308
- q,
309
- re,
310
- J,
311
- S,
312
- Te,
313
- h,
314
- oe,
315
- I,
316
- F
317
- ]), lt = i.length === 0 ? "No options available" : "No results found";
318
- ft(() => {
319
- s && Tt();
320
- }, [s]);
321
- const ot = {
410
+ s,
411
+ _,
412
+ ee,
413
+ le,
414
+ te,
415
+ b,
416
+ Re,
417
+ v,
418
+ ce,
419
+ g,
420
+ X
421
+ ]), st = n.length === 0 ? "No options available" : "No results found";
422
+ ht(() => {
423
+ o && Ot();
424
+ }, [o]);
425
+ const it = {
322
426
  position: "fixed",
323
- top: (d == null ? void 0 : d.top) ?? 0,
324
- left: (d == null ? void 0 : d.left) ?? 0,
325
- width: d == null ? void 0 : d.width,
326
- background: M.standard.background,
327
- border: M.standard.border,
328
- borderRadius: M.standard.radius,
329
- boxShadow: M.standard.shadow,
330
- padding: M.standard.padding,
427
+ top: (c == null ? void 0 : c.top) ?? 0,
428
+ left: (c == null ? void 0 : c.left) ?? 0,
429
+ width: c == null ? void 0 : c.width,
430
+ background: K.standard.background,
431
+ border: K.standard.border,
432
+ borderRadius: K.standard.radius,
433
+ boxShadow: K.standard.shadow,
434
+ padding: K.standard.padding,
331
435
  display: "flex",
332
436
  flexDirection: "column",
333
437
  gap: 4,
334
- maxHeight: (d == null ? void 0 : d.maxHeight) ?? Rt,
335
- fontSize: wt[$],
336
- visibility: d ? "visible" : "hidden",
337
- opacity: d ? 1 : 0
338
- }, Ne = !!(j || ue || X || fe || de || me || Z), Oe = Ne && !!B, Ae = /* @__PURE__ */ b(st, { children: [
339
- /* @__PURE__ */ b("div", { className: "relative", style: We(V), children: [
340
- /* @__PURE__ */ b(
341
- Ke,
438
+ maxHeight: (c == null ? void 0 : c.maxHeight) ?? Rt,
439
+ fontSize: It[N],
440
+ visibility: c ? "visible" : "hidden",
441
+ opacity: c ? 1 : 0
442
+ }, Ne = !!(q || fe || J || me || ue || he || Q), Ce = Ne && !!F, Ae = /* @__PURE__ */ w(dt, { children: [
443
+ /* @__PURE__ */ w("div", { className: "relative", style: $e(P), children: [
444
+ /* @__PURE__ */ w(
445
+ Ye,
342
446
  {
343
- ref: ee,
344
- id: ye,
345
- triggerRole: h ? "combobox" : q && J ? "group" : "button",
346
- disabled: S || y,
347
- [It]: "",
447
+ ref: ne,
448
+ id: we,
449
+ triggerRole: v ? "combobox" : ee && te ? "group" : "button",
450
+ disabled: b || m,
451
+ [Tt]: "",
348
452
  "aria-haspopup": "listbox",
349
- "aria-expanded": s,
350
- "aria-controls": s ? xe : void 0,
351
- "aria-activedescendant": h && s && p >= 0 ? be(p) : void 0,
352
- "aria-labelledby": je ?? (Oe && !ge ? we : void 0),
353
- "aria-label": ge ?? (Oe ? void 0 : B),
354
- "aria-invalid": ce || void 0,
355
- "aria-required": Z || void 0,
356
- "aria-describedby": qe,
357
- "aria-busy": y || void 0,
453
+ "aria-expanded": o,
454
+ "aria-controls": o ? xe : void 0,
455
+ "aria-activedescendant": v && o && x >= 0 ? ye(x) : void 0,
456
+ "aria-labelledby": Ze ?? (Ce && !be ? Ee : void 0),
457
+ "aria-label": be ?? (Ce ? void 0 : F),
458
+ "aria-invalid": E || void 0,
459
+ "aria-required": Q || void 0,
460
+ "aria-describedby": Qe,
461
+ "aria-busy": m || void 0,
358
462
  onClick: () => {
359
- S || y || G((e) => !e);
463
+ b || m || Y((e) => !e);
360
464
  },
361
- onKeyDown: Y,
465
+ onKeyDown: j,
362
466
  style: {
363
467
  transition: "border-color 0.15s ease, box-shadow 0.15s ease",
364
- ...nt,
365
- ...Ue
468
+ ...lt,
469
+ ...Xe
366
470
  },
367
- className: `w-full ${Ot[$]} border border-solid flex items-center font-normal text-[var(--malachite-text-primary)] ${S || y ? "cursor-not-allowed" : "cursor-pointer"} ${Ye}`,
471
+ className: `w-full ${Pt[N]} border border-solid flex items-center font-normal text-[var(--malachite-text-primary)] ${b || m ? "cursor-not-allowed" : "cursor-pointer"} ${Ve}`,
368
472
  children: [
369
473
  /* @__PURE__ */ r(
370
474
  "span",
371
475
  {
372
- className: `flex-1 min-w-0 text-left ${h ? "flex" : "truncate"} ${_e ? "pr-[18px]" : ""}`,
373
- children: at
476
+ className: `flex-1 min-w-0 text-left ${v ? "flex" : "truncate"} ${_e ? "pr-[18px]" : ""}`,
477
+ children: ot
374
478
  }
375
479
  ),
376
- y ? /* @__PURE__ */ r("span", { className: "flex items-center justify-center shrink-0 size-[14px]", children: /* @__PURE__ */ r(bt, { size: "xxxsmall" }) }) : /* @__PURE__ */ r(
377
- gt,
480
+ m ? /* @__PURE__ */ r("span", { className: "flex items-center justify-center shrink-0 size-[14px]", children: /* @__PURE__ */ r(wt, { size: "xxxsmall" }) }) : /* @__PURE__ */ r(
481
+ vt,
378
482
  {
379
483
  size: 13,
380
484
  className: "shrink-0",
381
485
  style: {
382
- color: s ? "var(--malachite-text-primary, rgb(10, 10, 10))" : "var(--malachite-text-placeholder, rgb(187, 187, 187))",
486
+ color: o ? "var(--malachite-text-primary, rgb(10, 10, 10))" : "var(--malachite-text-placeholder, rgb(187, 187, 187))",
383
487
  transition: "transform 0.2s ease, color 0.2s ease",
384
- transform: s ? "rotate(180deg)" : "rotate(0deg)"
488
+ transform: o ? "rotate(180deg)" : "rotate(0deg)"
385
489
  }
386
490
  }
387
491
  )
@@ -393,24 +497,24 @@ const er = ({
393
497
  {
394
498
  type: "button",
395
499
  "aria-label": "Clear selection",
396
- onClick: rt,
500
+ onClick: at,
397
501
  className: "absolute top-0 bottom-0 right-[28px] flex items-center justify-center px-[2px] leading-none bg-transparent border-none text-[var(--malachite-text-placeholder)] hover:text-[var(--malachite-text-primary)] cursor-pointer",
398
502
  children: "×"
399
503
  }
400
504
  )
401
505
  ] }),
402
- s && mt(
403
- /* @__PURE__ */ b(
506
+ o && pt(
507
+ /* @__PURE__ */ w(
404
508
  "div",
405
509
  {
406
- ref: C,
510
+ ref: B,
407
511
  id: xe,
408
512
  role: "listbox",
409
513
  "aria-multiselectable": "true",
410
- ...Lt("multiselect"),
411
- style: ot,
514
+ ..._t("multiselect"),
515
+ style: it,
412
516
  children: [
413
- Re && /* @__PURE__ */ b(
517
+ Le && /* @__PURE__ */ w(
414
518
  "div",
415
519
  {
416
520
  style: {
@@ -425,7 +529,7 @@ const er = ({
425
529
  },
426
530
  children: [
427
531
  /* @__PURE__ */ r(
428
- xt,
532
+ yt,
429
533
  {
430
534
  size: 13,
431
535
  style: {
@@ -438,9 +542,9 @@ const er = ({
438
542
  "input",
439
543
  {
440
544
  type: "text",
441
- value: w,
442
- onChange: (e) => ae(e.target.value),
443
- onKeyDown: Y,
545
+ value: L,
546
+ onChange: (e) => se(e.target.value),
547
+ onKeyDown: j,
444
548
  placeholder: "Search",
445
549
  "aria-label": "Search options",
446
550
  autoFocus: !0,
@@ -458,7 +562,7 @@ const er = ({
458
562
  ]
459
563
  }
460
564
  ),
461
- Re && /* @__PURE__ */ r(
565
+ Le && /* @__PURE__ */ r(
462
566
  "div",
463
567
  {
464
568
  "aria-hidden": "true",
@@ -473,7 +577,7 @@ const er = ({
473
577
  /* @__PURE__ */ r(
474
578
  "div",
475
579
  {
476
- ref: Ie,
580
+ ref: Se,
477
581
  style: {
478
582
  display: "flex",
479
583
  flexDirection: "column",
@@ -485,34 +589,34 @@ const er = ({
485
589
  scrollbarWidth: "thin",
486
590
  scrollbarColor: "var(--malachite-text-placeholder, rgb(187, 187, 187)) transparent"
487
591
  },
488
- children: k.length === 0 ? (
592
+ children: O.length === 0 ? (
489
593
  // `role="listbox"` admits only option/group children.
490
- /* @__PURE__ */ r("div", { role: "presentation", style: Nt, children: lt })
491
- ) : k.map((e, t) => {
492
- const l = te.has(e.value), x = t === p, g = !!e.disabled;
493
- return /* @__PURE__ */ b(
594
+ /* @__PURE__ */ r("div", { role: "presentation", style: Ht, children: st })
595
+ ) : O.map((e, t) => {
596
+ const l = ae.has(e.value), S = t === x, y = !!e.disabled;
597
+ return /* @__PURE__ */ w(
494
598
  "button",
495
599
  {
496
- id: be(t),
497
- ref: (a) => {
498
- Se.current[t] = a;
600
+ id: ye(t),
601
+ ref: (d) => {
602
+ Te.current[t] = d;
499
603
  },
500
604
  type: "button",
501
605
  role: "option",
502
606
  "aria-selected": l,
503
- "aria-disabled": g || void 0,
607
+ "aria-disabled": y || void 0,
504
608
  onClick: () => {
505
- var a;
506
- le(e.value), D(), (a = A.current) == null || a.focus();
609
+ var d;
610
+ ie(e.value), G(), (d = $.current) == null || d.focus();
507
611
  },
508
- onMouseEnter: () => T(t),
612
+ onMouseEnter: () => C(t),
509
613
  onMouseLeave: () => {
510
- p === t && T(-1);
614
+ x === t && C(-1);
511
615
  },
512
616
  className: "malachite-multiselect-option",
513
617
  "data-checked": l,
514
- "data-highlighted": x,
515
- "data-disabled": g,
618
+ "data-highlighted": S,
619
+ "data-disabled": y,
516
620
  style: {
517
621
  display: "flex",
518
622
  alignItems: "center",
@@ -524,86 +628,12 @@ const er = ({
524
628
  borderRadius: 8,
525
629
  padding: "8px 10px",
526
630
  font: "inherit",
527
- cursor: g ? "not-allowed" : "pointer",
528
- opacity: g ? 0.6 : 1,
631
+ cursor: y ? "not-allowed" : "pointer",
632
+ opacity: y ? 0.6 : 1,
529
633
  color: l ? "var(--malachite-accent-foreground, rgb(2, 122, 66))" : "var(--malachite-text-primary, rgb(10, 10, 10))"
530
634
  },
531
635
  children: [
532
- (() => {
533
- const a = e.description ? e.descriptionMode ?? "icon" : null, n = a === "subtitle", o = /* @__PURE__ */ r(
534
- "span",
535
- {
536
- style: {
537
- overflow: "hidden",
538
- textOverflow: "ellipsis",
539
- whiteSpace: "nowrap"
540
- },
541
- children: e.label
542
- }
543
- );
544
- return /* @__PURE__ */ b(
545
- "span",
546
- {
547
- style: {
548
- flex: 1,
549
- minWidth: 0,
550
- display: "flex",
551
- flexDirection: n ? "column" : "row",
552
- alignItems: n ? "flex-start" : "center",
553
- gap: n ? 2 : 6
554
- },
555
- children: [
556
- a === "hover" ? /* @__PURE__ */ r(
557
- Pe,
558
- {
559
- text: e.description,
560
- delay: 0.6,
561
- maxWidth: 420,
562
- children: o
563
- }
564
- ) : o,
565
- a === "icon" && /* @__PURE__ */ r(
566
- Pe,
567
- {
568
- text: e.description,
569
- delay: 0.6,
570
- maxWidth: 420,
571
- children: /* @__PURE__ */ r(
572
- "span",
573
- {
574
- style: {
575
- cursor: "help",
576
- color: "var(--malachite-text-placeholder, rgb(187, 187, 187))"
577
- },
578
- "aria-label": "More information",
579
- onClick: (f) => f.stopPropagation(),
580
- children: e.descriptionIcon ?? /* @__PURE__ */ r(vt, { size: 14 })
581
- }
582
- )
583
- }
584
- ),
585
- a === "subtitle" && /* @__PURE__ */ r(
586
- "span",
587
- {
588
- style: {
589
- fontSize: 12,
590
- color: "var(--malachite-text-secondary, rgb(123, 123, 123))",
591
- whiteSpace: "normal",
592
- lineHeight: 1.3,
593
- ...e.descriptionMaxLines ? {
594
- display: "-webkit-box",
595
- WebkitLineClamp: e.descriptionMaxLines,
596
- WebkitBoxOrient: "vertical",
597
- overflow: "hidden"
598
- } : {}
599
- },
600
- children: e.description
601
- }
602
- )
603
- ]
604
- }
605
- );
606
- })(),
636
+ /* @__PURE__ */ r(Bt, { option: e }),
607
637
  e.badge && /* @__PURE__ */ r(
608
638
  "span",
609
639
  {
@@ -629,28 +659,28 @@ const er = ({
629
659
  )
630
660
  ] });
631
661
  return Ne ? /* @__PURE__ */ r(
632
- ht,
662
+ gt,
633
663
  {
634
- label: B,
635
- hint: X,
636
- rightSideContent: fe,
637
- tooltip: ue,
638
- name: de ?? "",
639
- required: Z,
640
- requiredIndicator: Fe,
641
- loading: y,
642
- formControl: me,
643
- description: j,
644
- controlId: ye,
645
- labelId: we,
646
- descriptionId: Xe,
647
- hintId: Ze,
648
- loadingComponent: V === void 0 ? /* @__PURE__ */ r(Me, { heightClass: P[$] }) : /* @__PURE__ */ r("div", { style: We(V), children: /* @__PURE__ */ r(Me, { heightClass: P[$] }) }),
664
+ label: F,
665
+ hint: J,
666
+ rightSideContent: me,
667
+ tooltip: fe,
668
+ name: ue ?? "",
669
+ required: Q,
670
+ requiredIndicator: Ue,
671
+ loading: m,
672
+ formControl: he,
673
+ description: q,
674
+ controlId: we,
675
+ labelId: Ee,
676
+ descriptionId: qe,
677
+ hintId: Je,
678
+ loadingComponent: P === void 0 ? /* @__PURE__ */ r(Me, { heightClass: z[N] }) : /* @__PURE__ */ r("div", { style: $e(P), children: /* @__PURE__ */ r(Me, { heightClass: z[N] }) }),
649
679
  children: Ae
650
680
  }
651
681
  ) : Ae;
652
682
  };
653
683
  export {
654
- er as default
684
+ sr as default
655
685
  };
656
686
  //# sourceMappingURL=MultiSelect.js.map