@stackone/malachite 2.138.0 → 2.141.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,31 +1,75 @@
1
- import { jsxs as E, jsx as d } from "react/jsx-runtime";
2
- import { useId as yt, useState as T, useRef as b, useCallback as H, useLayoutEffect as M, useEffect as St, useInsertionEffect as vt } from "react";
3
- import { createPortal as Et } from "react-dom";
4
- import { Spinner as Tt } from "./Spinner.js";
5
- import { CODE_TOKEN_COLOR as rt } from "./codeBlockStyles.js";
6
- import { CONTROL_TEXT_SIZE as O, CONTROL_TEXT_SIZE_CLASS as nt } from "./controlTextSize.js";
7
- import { pushEscapeLayer as Mt } from "./escapeLayers.js";
8
- import { ensureMultiSelectPanelStyles as kt } from "./optionRowStyles.js";
9
- import { usePopupLayer as Lt } from "./overlayLayers.js";
10
- import { useOwnedByPopover as Rt } from "./popoverTree.js";
11
- import { computeCaretMenuGeometry as It } from "./queryInputGeometry.js";
12
- import { useFollowTrigger as _t } from "./useFollowTrigger.js";
13
- const Dt = {
14
- small: "h-[var(--malachite-control-height-small,28px)] px-[10px] rounded-[var(--malachite-radius-10,10px)]",
15
- medium: "h-[var(--malachite-control-height-medium,32px)] px-[10px] rounded-xl",
16
- large: "h-[var(--malachite-control-height-large,42px)] px-[12px] rounded-[var(--malachite-radius-xxl,14px)]"
17
- }, Ht = {
18
- key: rt.keyword,
19
- value: rt.string,
1
+ import { jsxs as d, jsx as n } from "react/jsx-runtime";
2
+ import { useId as Zt, useState as $, useRef as u, useEffect as rt, useCallback as G, useLayoutEffect as O, useInsertionEffect as qt } from "react";
3
+ import { createPortal as Jt } from "react-dom";
4
+ import Qt from "./CustomIcons/DismissIcon.js";
5
+ import te from "./CustomIcons/SearchIcon.js";
6
+ import { Spinner as ee } from "./Spinner.js";
7
+ import re from "./Tooltip.js";
8
+ import { getVariantClasses as ae } from "./buttonStyles.js";
9
+ import { CODE_TOKEN_COLOR as wt } from "./codeBlockStyles.js";
10
+ import { CONTROL_TEXT_SIZE as K, CONTROL_TEXT_SIZE_CLASS as Et } from "./controlTextSize.js";
11
+ import { pushEscapeLayer as ne } from "./escapeLayers.js";
12
+ import { holdsFocus as oe } from "./collapseFocus.js";
13
+ import { FOCUS_RING_INSET as ie, FOCUS_RING as le } from "./focusRing.js";
14
+ import { MENU_VIEWPORT_PADDING_PX as _t } from "./floatingMenuGeometry.js";
15
+ import { ensureMultiSelectPanelStyles as ce } from "./optionRowStyles.js";
16
+ import { usePopupLayer as se } from "./overlayLayers.js";
17
+ import { useOwnedByPopover as de } from "./popoverTree.js";
18
+ import { computeCaretMenuGeometry as pe } from "./queryInputGeometry.js";
19
+ import { useFollowTrigger as me } from "./useFollowTrigger.js";
20
+ const ue = {
21
+ small: "px-[10px] rounded-[var(--malachite-radius-10,10px)]",
22
+ medium: "px-[10px] rounded-xl",
23
+ large: "px-[12px] rounded-[var(--malachite-radius-xxl,14px)]"
24
+ }, he = {
25
+ small: "h-[var(--malachite-control-height-small,28px)]",
26
+ medium: "h-[var(--malachite-control-height-medium,32px)]",
27
+ large: "h-[var(--malachite-control-height-large,42px)]"
28
+ }, fe = {
29
+ small: "min-h-[var(--malachite-control-height-small,28px)]",
30
+ medium: "min-h-[var(--malachite-control-height-medium,32px)]",
31
+ large: "min-h-[var(--malachite-control-height-large,42px)]"
32
+ }, xe = {
33
+ small: "flex-wrap gap-x-[6px] gap-y-[4px] py-[2px]",
34
+ medium: "flex-wrap gap-x-[6px] gap-y-[4px] py-[3px]",
35
+ large: "flex-wrap gap-x-[8px] gap-y-[4px] py-[5px]"
36
+ }, ge = {
37
+ small: "h-[22px]",
38
+ medium: "h-[24px]",
39
+ large: "h-[30px]"
40
+ }, be = {
41
+ small: "h-[20px] text-[length:var(--malachite-font-size-xsmall,11px)]",
42
+ medium: "h-[20px] text-[length:var(--malachite-font-size-xsmall,11px)]",
43
+ large: "h-[24px] text-xs"
44
+ }, ye = "inline-flex max-w-full items-center gap-[2px] rounded-[5px] pl-[7px] whitespace-nowrap font-mono text-[var(--malachite-text-primary,rgb(10,10,10))]", kt = "text-[var(--malachite-text-destructive,rgb(237,53,54))] supports-[color:color-mix(in_srgb,red,red)]:text-[color-mix(in_srgb,var(--malachite-text-destructive,rgb(237,53,54))_70%,var(--malachite-text-primary,rgb(10,10,10)))]", Se = {
45
+ include: {
46
+ chip: "bg-[var(--malachite-card-dimmed-background,rgb(247,247,247))]",
47
+ key: "text-[var(--malachite-text-secondary,rgb(123,123,123))]"
48
+ },
49
+ exclude: {
50
+ chip: "bg-[var(--malachite-error-background-glass,rgba(197,63,63,0.08))] supports-[color:color-mix(in_srgb,red,red)]:bg-[color-mix(in_srgb,var(--malachite-text-destructive,rgb(237,53,54))_10%,var(--malachite-card-background,rgb(255,255,255)))]",
51
+ key: kt
52
+ },
53
+ invalid: {
54
+ chip: "border border-dashed border-[var(--malachite-text-destructive,rgb(237,53,54))] bg-[var(--malachite-card-background,rgb(255,255,255))]",
55
+ key: kt
56
+ }
57
+ }, ve = {
58
+ include: "",
59
+ exclude: ", excluded",
60
+ invalid: ", invalid"
61
+ }, we = `inline-flex shrink-0 h-full items-center rounded-[4px] px-[4px] bg-transparent border-none cursor-pointer text-[var(--malachite-text-secondary,rgb(123,123,123))] enabled:hover:text-[var(--malachite-text-primary,rgb(10,10,10))] disabled:cursor-not-allowed ${le}`, Ee = `${ae("quiet", "rounded-md")} ml-auto shrink-0 h-[22px] px-[6px] text-xs whitespace-nowrap`, _e = 5e3, ot = (r) => `${r.label}${r.operator}${r.value}`, Tt = (r) => `Removed ${ot(r)} filter`, ke = {
62
+ key: wt.keyword,
63
+ value: wt.string,
20
64
  operator: "var(--malachite-codeblock-type, rgb(12, 88, 174))",
21
65
  negation: "var(--malachite-text-destructive, rgb(237, 53, 54))",
22
66
  punctuation: "var(--malachite-codeblock-foreground, rgb(10, 10, 10))",
23
67
  error: "var(--malachite-text-error, rgb(237, 53, 54))",
24
68
  plain: "var(--malachite-text-primary, rgb(10, 10, 10))"
25
- }, Ot = {
69
+ }, Te = {
26
70
  small: {
27
71
  fontFamily: "inherit",
28
- fontSize: O.small,
72
+ fontSize: K.small,
29
73
  fontWeight: 500,
30
74
  letterSpacing: "normal",
31
75
  lineHeight: "normal",
@@ -33,7 +77,7 @@ const Dt = {
33
77
  },
34
78
  medium: {
35
79
  fontFamily: "inherit",
36
- fontSize: O.medium,
80
+ fontSize: K.medium,
37
81
  fontWeight: 500,
38
82
  letterSpacing: "normal",
39
83
  lineHeight: "normal",
@@ -41,13 +85,63 @@ const Dt = {
41
85
  },
42
86
  large: {
43
87
  fontFamily: "inherit",
44
- fontSize: O.large,
88
+ fontSize: K.large,
45
89
  fontWeight: 500,
46
90
  letterSpacing: "normal",
47
91
  lineHeight: "normal",
48
92
  padding: 0
49
93
  }
50
- }, B = 220, ot = 360, it = {
94
+ }, It = 220, Ie = 360, at = 4, Ne = /* @__PURE__ */ new Set(["Shift", "Control", "Alt", "Meta"]), Le = 420, $e = {
95
+ position: "sticky",
96
+ top: -4,
97
+ zIndex: 1,
98
+ margin: "-4px -4px 0",
99
+ padding: "8px 12px 6px",
100
+ fontSize: "var(--malachite-font-size-xsmall, 11px)",
101
+ color: "var(--malachite-text-dimmed, rgb(161, 161, 161))",
102
+ background: "var(--malachite-card-background, rgb(255, 255, 255))",
103
+ borderBottom: "1px solid var(--malachite-card-subtle-divider, rgb(241, 241, 241))",
104
+ whiteSpace: "nowrap",
105
+ overflow: "hidden",
106
+ textOverflow: "ellipsis",
107
+ flexShrink: 0
108
+ }, Me = {
109
+ position: "sticky",
110
+ bottom: -4,
111
+ zIndex: 1,
112
+ margin: "0 -4px -4px",
113
+ padding: "8px 12px",
114
+ display: "flex",
115
+ flexWrap: "wrap",
116
+ columnGap: 14,
117
+ rowGap: 4,
118
+ fontSize: "var(--malachite-font-size-xsmall, 11px)",
119
+ color: "var(--malachite-text-secondary, rgb(123, 123, 123))",
120
+ background: "var(--malachite-card-sunken-background, rgb(250, 250, 250))",
121
+ borderTop: "1px solid var(--malachite-card-subtle-divider, rgb(241, 241, 241))",
122
+ flexShrink: 0
123
+ }, Re = {
124
+ display: "inline-flex",
125
+ alignItems: "center",
126
+ justifyContent: "center",
127
+ minWidth: 18,
128
+ height: 18,
129
+ padding: "0 5px",
130
+ marginRight: 5,
131
+ boxSizing: "border-box",
132
+ borderRadius: 6,
133
+ border: "1px solid var(--malachite-card-border, rgb(232, 232, 232))",
134
+ background: "var(--malachite-card-background, rgb(255, 255, 255))",
135
+ boxShadow: "var(--malachite-shadow-default, 0px 1px 0px 0px rgba(0, 0, 0, 0.15))",
136
+ fontFamily: "var(--malachite-font-mono, monospace)",
137
+ fontSize: 10,
138
+ color: "var(--malachite-text-secondary, rgb(123, 123, 123))"
139
+ }, nt = {
140
+ minWidth: 0,
141
+ overflow: "hidden",
142
+ textOverflow: "ellipsis",
143
+ whiteSpace: "nowrap"
144
+ }, Nt = {
51
145
  display: "flex",
52
146
  alignItems: "center",
53
147
  justifyContent: "center",
@@ -55,159 +149,214 @@ const Dt = {
55
149
  padding: "10px 12px",
56
150
  color: "var(--malachite-text-dimmed, rgb(161, 161, 161))",
57
151
  whiteSpace: "nowrap"
58
- }, Wt = (r) => {
152
+ }, Ae = (r) => {
59
153
  r.preventDefault();
60
- }, Nt = (r, u) => {
61
- const l = [...u.filter(
62
- (n) => n.start >= 0 && n.end <= r.length && n.start < n.end
63
- )].sort((n, k) => n.start - k.start), s = [];
64
- let m = 0;
65
- for (const n of l)
66
- n.start < m || (s.push(n), m = n.end);
67
- return s;
68
- }, $t = (r, u) => {
69
- const h = [];
70
- let l = 0;
71
- for (const s of Nt(r, u))
72
- s.start > l && h.push({ start: l, end: s.start, kind: "plain" }), h.push(s), l = s.end;
73
- return l < r.length && h.push({ start: l, end: r.length, kind: "plain" }), h;
74
- }, Jt = ({
154
+ }, De = (r, k) => {
155
+ const c = [...k.filter(
156
+ (i) => i.start >= 0 && i.end <= r.length && i.start < i.end
157
+ )].sort((i, H) => i.start - H.start), h = [];
158
+ let T = 0;
159
+ for (const i of c)
160
+ i.start < T || (h.push(i), T = i.end);
161
+ return h;
162
+ }, Oe = (r, k) => {
163
+ const v = [];
164
+ let c = 0;
165
+ for (const h of De(r, k))
166
+ h.start > c && v.push({ start: c, end: h.start, kind: "plain" }), v.push(h), c = h.end;
167
+ return c < r.length && v.push({ start: c, end: r.length, kind: "plain" }), v;
168
+ }, nr = ({
75
169
  value: r,
76
- onChange: u,
77
- tokens: h = [],
78
- suggestions: l,
79
- activeRange: s,
80
- onAccept: m,
81
- onQueryContextChange: n,
82
- onSubmit: k,
83
- placeholder: K,
84
- size: w = "large",
85
- disabled: L = !1,
86
- loading: R = !1,
87
- emptyMessage: W,
88
- className: at = "",
89
- style: lt,
90
- "aria-label": st,
91
- "aria-labelledby": C
170
+ onChange: k,
171
+ tokens: v = [],
172
+ suggestions: c,
173
+ activeRange: h,
174
+ onAccept: T,
175
+ onQueryContextChange: i,
176
+ onSubmit: H,
177
+ placeholder: it,
178
+ size: s = "large",
179
+ disabled: x = !1,
180
+ loading: C = !1,
181
+ emptyMessage: P,
182
+ chips: Y,
183
+ onChipRemove: g,
184
+ onClear: M,
185
+ searchIcon: j = !1,
186
+ menuTitle: W,
187
+ menuHints: B,
188
+ className: Lt = "",
189
+ style: $t,
190
+ "aria-label": Mt,
191
+ "aria-labelledby": lt
92
192
  }) => {
93
- const N = `${yt()}-listbox`, U = (t) => `${N}-option-${t}`, [$, j] = T(!1), [P, A] = T(() => r.length), [ct, z] = T(0), [dt, I] = T(!1), [i, Y] = T(null), g = b(null), Z = b(null), G = b(null), x = b(null), V = b([]), F = b(null), pt = Array.isArray(l), y = l ?? [], S = y.length > 0, a = $ && (R || S || pt && !S && !!W) && !dt && !L, ht = Lt("dropdown", a, x);
94
- Rt(
95
- H(() => x.current, []),
96
- a
193
+ const V = `${Zt()}-listbox`, ct = (t) => `${V}-option-${t}`, [Z, st] = $(!1), [dt, q] = $(() => r.length), [Rt, J] = $(0), [At, F] = $(!1), [b, pt] = $(null), [U, mt] = $({ message: "", count: 0 }), I = u(null), z = u(null), p = u(null), ut = u(null), ht = u(null), N = u(null), ft = u(null), xt = u(null), gt = u([]), Q = u(null), w = Y ?? [], E = Y !== void 0 || j || M !== void 0, Dt = !!M && w.length > 0, bt = `${s}${!!g}${w.map((t) => `${t.id}\0${t.tone ?? ""}\0${ot(t)}`).join("")}`, Ot = `${Array.isArray(c)}${(c ?? []).map(
194
+ (t) => [t.id, t.label, t.description, t.detail].join(
195
+ "\0"
196
+ )
197
+ ).join("")}`, Ht = (B ?? []).map((t) => `${t.keys}\0${t.label}`).join("");
198
+ rt(() => {
199
+ if (!U.message)
200
+ return;
201
+ const t = window.setTimeout(
202
+ () => mt((e) => ({ ...e, message: "" })),
203
+ _e
204
+ );
205
+ return () => window.clearTimeout(t);
206
+ }, [U]), rt(() => {
207
+ I.current = null;
208
+ }, [bt]);
209
+ const tt = (t) => {
210
+ mt((e) => ({ message: t, count: e.count + 1 }));
211
+ }, Ct = Array.isArray(c), L = c ?? [], R = L.length > 0, l = Z && (C || R || Ct && !R && !!P) && !At && !x, Pt = se("dropdown", l, N);
212
+ de(
213
+ G(() => N.current, []),
214
+ l
97
215
  );
98
- const v = a && S && !R, c = S ? Math.min(ct, y.length - 1) : -1;
99
- M(() => {
100
- A((t) => Math.min(t, r.length));
216
+ const A = l && R && !C, f = R ? Math.min(Rt, L.length - 1) : -1;
217
+ O(() => {
218
+ q((t) => Math.min(t, r.length));
101
219
  }, [r]);
102
- const _ = H(() => {
103
- const t = g.current, e = Z.current;
220
+ const X = G(() => {
221
+ const t = p.current, e = ut.current;
104
222
  t && e && (e.style.transform = `translateX(${-t.scrollLeft}px)`);
105
223
  }, []);
106
- M(() => {
107
- _();
108
- }, [r, _]);
109
- const f = H(() => {
110
- var o, p, D;
111
- const t = g.current;
224
+ O(() => {
225
+ X();
226
+ }, [r, X]);
227
+ const _ = G(() => {
228
+ var m, y, S, D;
229
+ const t = p.current;
112
230
  if (!t)
113
231
  return;
114
- const e = (((o = G.current) == null ? void 0 : o.offsetWidth) ?? 0) - t.scrollLeft;
115
- Y(
116
- It({
117
- inputRect: t.getBoundingClientRect(),
232
+ const e = (((m = ht.current) == null ? void 0 : m.offsetWidth) ?? 0) - t.scrollLeft, a = t.getBoundingClientRect(), o = E ? (y = z.current) == null ? void 0 : y.getBoundingClientRect() : void 0;
233
+ pt(
234
+ pe({
235
+ inputRect: o ? {
236
+ left: a.left,
237
+ right: a.right,
238
+ top: o.top,
239
+ bottom: o.bottom
240
+ } : a,
118
241
  caretOffsetPx: e,
119
- menuWidth: ((p = x.current) == null ? void 0 : p.offsetWidth) ?? B,
120
- menuHeight: ((D = x.current) == null ? void 0 : D.offsetHeight) ?? 0,
242
+ menuWidth: ((S = N.current) == null ? void 0 : S.offsetWidth) ?? It,
243
+ menuHeight: ((D = N.current) == null ? void 0 : D.offsetHeight) ?? 0,
121
244
  viewportWidth: window.innerWidth,
122
245
  viewportHeight: window.innerHeight
123
246
  })
124
247
  );
125
- }, []);
126
- M(() => {
127
- a ? f() : Y(null);
128
- }, [a, r, P, l, R, f]);
129
- const ft = H(() => I(!0), []);
130
- _t(a, g, f, ft), St(() => {
131
- if (!a)
248
+ }, [E]);
249
+ O(() => {
250
+ l ? _() : pt(null);
251
+ }, [
252
+ l,
253
+ r,
254
+ dt,
255
+ Ot,
256
+ C,
257
+ P,
258
+ bt,
259
+ j,
260
+ W,
261
+ Ht,
262
+ _
263
+ ]);
264
+ const Wt = G(() => F(!0), []);
265
+ me(l, E ? z : p, _, Wt), rt(() => {
266
+ if (!l)
132
267
  return;
133
- const t = () => f();
268
+ const t = () => _();
134
269
  window.addEventListener("resize", t);
135
- const e = Mt(() => I(!0));
270
+ const e = ne(() => F(!0));
136
271
  return () => {
137
272
  window.removeEventListener("resize", t), e();
138
273
  };
139
- }, [a, f]), M(() => {
140
- const t = F.current;
274
+ }, [l, _]), O(() => {
275
+ const t = Q.current;
141
276
  if (t === null)
142
277
  return;
143
- F.current = null;
144
- const e = g.current;
145
- !e || t.value !== r || (e.setSelectionRange(t.caret, t.caret), A(t.caret), n == null || n({ value: r, caret: t.caret }), _(), f());
146
- }, [r]), M(() => {
147
- if (!v)
278
+ Q.current = null;
279
+ const e = p.current;
280
+ !e || t.value !== r || (e.setSelectionRange(t.caret, t.caret), q(t.caret), i == null || i({ value: r, caret: t.caret }), X(), _());
281
+ }, [r]), O(() => {
282
+ var y, S;
283
+ if (!A)
148
284
  return;
149
- const t = V.current[c], e = x.current;
285
+ const t = gt.current[f], e = N.current;
150
286
  if (!t || !e)
151
287
  return;
152
- const o = t.offsetTop + t.offsetHeight;
153
- o > e.scrollTop + e.clientHeight ? e.scrollTop = o - e.clientHeight : t.offsetTop < e.scrollTop && (e.scrollTop = t.offsetTop);
154
- }, [c, v]), vt(() => {
155
- a && kt();
156
- }, [a]);
157
- const q = (t, e) => {
158
- A(e), n == null || n({ value: t, caret: e });
159
- }, ut = (t) => {
288
+ const a = Math.max(0, (((y = ft.current) == null ? void 0 : y.offsetHeight) ?? 0) - at), o = Math.max(
289
+ 0,
290
+ (((S = xt.current) == null ? void 0 : S.offsetHeight) ?? 0) - at
291
+ ), m = t.offsetTop + t.offsetHeight;
292
+ m > e.scrollTop + e.clientHeight - o ? e.scrollTop = m - e.clientHeight + o : t.offsetTop - a < e.scrollTop && (e.scrollTop = t.offsetTop - a);
293
+ }, [f, A]), qt(() => {
294
+ l && ce();
295
+ }, [l]);
296
+ const yt = (t, e) => {
297
+ q(e), i == null || i({ value: t, caret: e });
298
+ }, Bt = (t) => {
160
299
  const e = t.target.value;
161
- I(!1), z(0), u(e), q(e, t.target.selectionStart ?? e.length);
162
- }, mt = (t) => {
300
+ F(!1), J(0), k(e), yt(e, t.target.selectionStart ?? e.length);
301
+ }, Ft = (t) => {
163
302
  const e = t.currentTarget;
164
- q(e.value, e.selectionStart ?? e.value.length);
165
- }, X = (t) => {
166
- var et;
167
- const e = ((et = g.current) == null ? void 0 : et.selectionStart) ?? r.length, o = s ?? { start: e, end: e }, p = Math.max(0, Math.min(o.start, r.length)), D = Math.max(p, Math.min(o.end, r.length)), Q = t.insertText ?? t.label, tt = r.slice(0, p) + Q + r.slice(D);
168
- F.current = { value: tt, caret: p + Q.length }, u(tt), m == null || m(t);
169
- }, gt = (t) => {
170
- if (v && (t.key === "ArrowDown" || t.key === "ArrowUp")) {
303
+ yt(e.value, e.selectionStart ?? e.value.length);
304
+ }, et = (t) => {
305
+ var D;
306
+ const e = ((D = p.current) == null ? void 0 : D.selectionStart) ?? r.length, a = h ?? { start: e, end: e }, o = Math.max(0, Math.min(a.start, r.length)), m = Math.max(o, Math.min(a.end, r.length)), y = t.insertText ?? t.label, S = r.slice(0, o) + y + r.slice(m);
307
+ Q.current = { value: S, caret: o + y.length }, k(S), T == null || T(t);
308
+ }, Ut = (t) => {
309
+ if (t.key !== "Backspace" && !Ne.has(t.key) && (I.current = null), t.nativeEvent.isComposing || t.keyCode === 229 && t.key !== "Backspace")
310
+ return;
311
+ if (t.key === "Backspace" && g && w.length > 0 && r === "" && !t.repeat) {
171
312
  t.preventDefault();
172
- const o = y.length;
173
- z(
174
- t.key === "ArrowDown" ? (c + 1) % o : (c - 1 + o) % o
313
+ const a = w[w.length - 1];
314
+ if (I.current === a.id)
315
+ return;
316
+ I.current = a.id, tt(Tt(a)), g(a.id);
317
+ return;
318
+ }
319
+ if (A && (t.key === "ArrowDown" || t.key === "ArrowUp")) {
320
+ t.preventDefault();
321
+ const a = L.length;
322
+ J(
323
+ t.key === "ArrowDown" ? (f + 1) % a : (f - 1 + a) % a
175
324
  );
176
325
  return;
177
326
  }
178
- const e = v && c >= 0 ? y[c] : void 0;
327
+ const e = A && f >= 0 ? L[f] : void 0;
179
328
  if (t.key === "Enter") {
180
329
  if (e) {
181
- t.preventDefault(), X(e);
330
+ t.preventDefault(), et(e);
182
331
  return;
183
332
  }
184
- k && (t.preventDefault(), k(r));
333
+ H && (t.preventDefault(), H(r));
185
334
  return;
186
335
  }
187
- t.key === "Tab" && e && (t.preventDefault(), X(e));
188
- }, xt = $t(r, h), J = Ot[w], bt = R ? (
336
+ t.key === "Tab" && e && (t.preventDefault(), et(e));
337
+ }, zt = Oe(r, v), St = Te[s], Xt = C ? (
189
338
  // `role="listbox"` admits only option/group children.
190
- /* @__PURE__ */ E("div", { role: "presentation", style: it, children: [
191
- /* @__PURE__ */ d(Tt, { size: "xxxsmall" }),
192
- /* @__PURE__ */ d("span", { children: "Loading…" })
339
+ /* @__PURE__ */ d("div", { role: "presentation", style: Nt, children: [
340
+ /* @__PURE__ */ n(ee, { size: "xxxsmall" }),
341
+ /* @__PURE__ */ n("span", { children: "Loading…" })
193
342
  ] })
194
- ) : S ? y.map((t, e) => {
195
- const o = e === c;
196
- return /* @__PURE__ */ E(
343
+ ) : R ? L.map((t, e) => {
344
+ const a = e === f;
345
+ return /* @__PURE__ */ d(
197
346
  "button",
198
347
  {
199
- ref: (p) => {
200
- V.current[e] = p;
348
+ ref: (o) => {
349
+ gt.current[e] = o;
201
350
  },
202
351
  type: "button",
203
- id: U(e),
352
+ id: ct(e),
204
353
  role: "option",
205
- "aria-selected": o,
354
+ "aria-selected": a,
206
355
  tabIndex: -1,
207
- onClick: () => X(t),
208
- onMouseEnter: () => z(e),
356
+ onClick: () => et(t),
357
+ onMouseEnter: () => J(e),
209
358
  className: "malachite-multiselect-option",
210
- "data-highlighted": o,
359
+ "data-highlighted": a,
211
360
  style: {
212
361
  display: "flex",
213
362
  alignItems: "center",
@@ -223,20 +372,33 @@ const Dt = {
223
372
  color: "var(--malachite-text-primary, rgb(10, 10, 10))"
224
373
  },
225
374
  children: [
226
- /* @__PURE__ */ d(
375
+ t.description ? /* @__PURE__ */ d(
227
376
  "span",
228
377
  {
229
378
  style: {
230
379
  flex: 1,
231
380
  minWidth: 0,
232
- overflow: "hidden",
233
- textOverflow: "ellipsis",
234
- whiteSpace: "nowrap"
381
+ display: "flex",
382
+ flexDirection: "column",
383
+ gap: 1
235
384
  },
236
- children: t.label
385
+ children: [
386
+ /* @__PURE__ */ n("span", { style: nt, children: t.label }),
387
+ /* @__PURE__ */ n(
388
+ "span",
389
+ {
390
+ style: {
391
+ ...nt,
392
+ fontSize: "var(--malachite-font-size-xsmall, 11px)",
393
+ color: "var(--malachite-text-secondary, rgb(123, 123, 123))"
394
+ },
395
+ children: t.description
396
+ }
397
+ )
398
+ ]
237
399
  }
238
- ),
239
- t.detail && /* @__PURE__ */ d(
400
+ ) : /* @__PURE__ */ n("span", { style: { flex: 1, ...nt }, children: t.label }),
401
+ t.detail && /* @__PURE__ */ n(
240
402
  "span",
241
403
  {
242
404
  style: {
@@ -251,120 +413,239 @@ const Dt = {
251
413
  },
252
414
  t.id
253
415
  );
254
- }) : W ? /* @__PURE__ */ d("div", { role: "presentation", style: it, children: W }) : null, wt = L ? "" : "hover:border-[var(--malachite-text-placeholder)]";
255
- return /* @__PURE__ */ E(
416
+ }) : P ? /* @__PURE__ */ n("div", { role: "presentation", style: Nt, children: P }) : null, Gt = x ? "" : "hover:border-[var(--malachite-text-placeholder)]", Kt = L.some((t) => t.description) ? Le : Ie, Yt = (t) => {
417
+ var a;
418
+ const e = vt();
419
+ tt(Tt(t)), g == null || g(t.id), e && ((a = p.current) == null || a.focus());
420
+ }, vt = () => {
421
+ const t = z.current;
422
+ return !!t && oe(t, t.getRootNode());
423
+ }, jt = (t) => {
424
+ var m;
425
+ I.current = null;
426
+ const e = t.currentTarget, a = t.target;
427
+ if (x || t.button !== 0 || !e.contains(a) || a === p.current)
428
+ return;
429
+ t.preventDefault();
430
+ const o = a.closest("button");
431
+ (!o || !e.contains(o)) && ((m = p.current) == null || m.focus());
432
+ }, Vt = () => {
433
+ var e;
434
+ const t = vt();
435
+ tt("Removed all filters"), M == null || M(), t && ((e = p.current) == null || e.focus());
436
+ };
437
+ return /* @__PURE__ */ d(
256
438
  "div",
257
439
  {
258
- className: `relative w-full ${Dt[w]} bg-[var(--malachite-card-background)] border border-solid border-[var(--malachite-card-border)] ${wt} transition-colors flex items-center ${L ? "opacity-60 cursor-not-allowed" : ""} ${at}`,
440
+ ref: z,
441
+ className: `relative w-full ${ue[s]} ${E ? `${fe[s]} ${xe[s]}` : he[s]} bg-[var(--malachite-card-background)] border border-solid border-[var(--malachite-card-border)] ${Gt} transition-colors flex items-center ${x ? "opacity-60 cursor-not-allowed" : E ? "cursor-text" : ""} ${Lt}`,
259
442
  style: {
260
- boxShadow: $ ? "var(--malachite-shadow-accent, 0px 1px 0px 0px rgba(0, 175, 102, 0.15))" : "0px 1px 1px 0px rgba(0, 0, 0, 0.15)",
261
- borderColor: $ ? "var(--malachite-control-border-hover, rgba(0, 175, 102, 0.4))" : void 0,
262
- ...lt
443
+ boxShadow: Z ? "var(--malachite-shadow-accent, 0px 1px 0px 0px rgba(0, 175, 102, 0.15))" : "0px 1px 1px 0px rgba(0, 0, 0, 0.15)",
444
+ borderColor: Z ? "var(--malachite-control-border-hover, rgba(0, 175, 102, 0.4))" : void 0,
445
+ ...$t
263
446
  },
447
+ onMouseDown: E ? jt : void 0,
264
448
  children: [
265
- /* @__PURE__ */ E("div", { className: "relative flex-1 h-full min-w-0 overflow-hidden", children: [
266
- /* @__PURE__ */ E(
267
- "div",
449
+ j && /* @__PURE__ */ n(
450
+ te,
451
+ {
452
+ size: 14,
453
+ className: "shrink-0 pointer-events-none text-[var(--malachite-text-secondary,rgb(123,123,123))]"
454
+ }
455
+ ),
456
+ w.length > 0 && // `contents` lets each chip wrap in the bar's own row beside the text.
457
+ // role: WebKit drops the list role from an unstyled list, and from display: contents.
458
+ /* @__PURE__ */ n("ul", { role: "list", "aria-label": "Filters", className: "contents", children: w.map((t) => {
459
+ const e = t.tone ?? "include", a = Se[e], o = /* @__PURE__ */ d(
460
+ "span",
268
461
  {
269
- ref: Z,
270
- "aria-hidden": "true",
271
- className: `absolute inset-0 flex items-center pointer-events-none ${nt[w]}`,
272
- style: { ...J, whiteSpace: "pre" },
462
+ tabIndex: t.tooltip && !x ? 0 : void 0,
463
+ className: `inline-flex min-w-0 items-center gap-[2px] rounded-[3px] ${ie}`,
273
464
  children: [
274
- xt.map((t) => /* @__PURE__ */ d(
275
- "span",
276
- {
277
- style: {
278
- color: Ht[t.kind],
279
- ...t.kind === "error" ? { textDecoration: "underline wavy" } : {}
280
- },
281
- children: r.slice(t.start, t.end)
282
- },
283
- t.start
284
- )),
285
- /* @__PURE__ */ d(
286
- "span",
465
+ /* @__PURE__ */ n("span", { className: `min-w-0 truncate ${a.key}`, children: t.label }),
466
+ /* @__PURE__ */ n("span", { className: "text-[var(--malachite-text-dimmed,rgb(161,161,161))]", children: t.operator }),
467
+ /* @__PURE__ */ n("span", { className: "min-w-0 truncate", children: t.value }),
468
+ /* @__PURE__ */ d("span", { className: "sr-only", children: [
469
+ ve[e],
470
+ t.tooltip ? `, ${t.tooltip}` : ""
471
+ ] })
472
+ ]
473
+ }
474
+ );
475
+ return /* @__PURE__ */ d(
476
+ "li",
477
+ {
478
+ "data-tone": e,
479
+ className: `${ye} ${g ? "pr-[2px]" : "pr-[7px]"} ${be[s]} ${a.chip}`,
480
+ children: [
481
+ t.tooltip ? (
482
+ // The sr-only copy above already carries the text.
483
+ /* @__PURE__ */ n(
484
+ re,
485
+ {
486
+ text: t.tooltip,
487
+ inline: !0,
488
+ isShrinkable: !0,
489
+ describesTrigger: !1,
490
+ children: o
491
+ }
492
+ )
493
+ ) : o,
494
+ g && /* @__PURE__ */ n(
495
+ "button",
287
496
  {
288
- ref: G,
289
- style: { position: "absolute", top: 0, left: 0, visibility: "hidden" },
290
- children: r.slice(0, P)
497
+ type: "button",
498
+ "aria-label": `Remove ${ot(t)} filter`,
499
+ onClick: () => Yt(t),
500
+ disabled: x,
501
+ className: we,
502
+ children: /* @__PURE__ */ n(Qt, { size: 8 })
291
503
  }
292
504
  )
293
505
  ]
294
- }
295
- ),
296
- /* @__PURE__ */ d(
297
- "input",
298
- {
299
- ref: g,
300
- type: "text",
301
- role: "combobox",
302
- "aria-expanded": a,
303
- "aria-controls": a ? N : void 0,
304
- "aria-activedescendant": v && c >= 0 ? U(c) : void 0,
305
- "aria-autocomplete": "list",
306
- autoComplete: "off",
307
- spellCheck: !1,
308
- "aria-labelledby": C,
309
- "aria-label": C ? void 0 : st ?? K,
310
- value: r,
311
- onChange: ut,
312
- onSelect: mt,
313
- onScroll: () => {
314
- _(), a && f();
315
- },
316
- onKeyDown: gt,
317
- onFocus: () => {
318
- j(!0), I(!1);
319
- },
320
- onBlur: () => j(!1),
321
- placeholder: K,
322
- disabled: L,
323
- className: `absolute inset-0 w-full h-full bg-transparent border-none outline-none ${nt[w]} placeholder:text-[var(--malachite-text-placeholder)] placeholder:font-medium disabled:cursor-not-allowed`,
324
- style: {
325
- ...J,
326
- color: "transparent",
327
- caretColor: "var(--malachite-text-primary, rgb(10, 10, 10))"
328
- }
329
- }
330
- )
331
- ] }),
332
- a && Et(
506
+ },
507
+ t.id
508
+ );
509
+ }) }),
510
+ /* @__PURE__ */ d(
511
+ "div",
512
+ {
513
+ className: `relative flex-1 overflow-hidden ${E ? `min-w-[min(160px,100%)] ${ge[s]}` : "min-w-0 self-stretch"}`,
514
+ children: [
515
+ /* @__PURE__ */ d(
516
+ "div",
517
+ {
518
+ ref: ut,
519
+ "aria-hidden": "true",
520
+ className: `absolute inset-0 flex items-center pointer-events-none ${Et[s]}`,
521
+ style: { ...St, whiteSpace: "pre" },
522
+ children: [
523
+ zt.map((t) => /* @__PURE__ */ n(
524
+ "span",
525
+ {
526
+ style: {
527
+ color: ke[t.kind],
528
+ ...t.kind === "error" ? { textDecoration: "underline wavy" } : {}
529
+ },
530
+ children: r.slice(t.start, t.end)
531
+ },
532
+ t.start
533
+ )),
534
+ /* @__PURE__ */ n(
535
+ "span",
536
+ {
537
+ ref: ht,
538
+ style: { position: "absolute", top: 0, left: 0, visibility: "hidden" },
539
+ children: r.slice(0, dt)
540
+ }
541
+ )
542
+ ]
543
+ }
544
+ ),
545
+ /* @__PURE__ */ n(
546
+ "input",
547
+ {
548
+ ref: p,
549
+ type: "text",
550
+ role: "combobox",
551
+ "aria-expanded": l,
552
+ "aria-controls": l ? V : void 0,
553
+ "aria-activedescendant": A && f >= 0 ? ct(f) : void 0,
554
+ "aria-autocomplete": "list",
555
+ autoComplete: "off",
556
+ spellCheck: !1,
557
+ "aria-labelledby": lt,
558
+ "aria-label": lt ? void 0 : Mt ?? it,
559
+ value: r,
560
+ onChange: Bt,
561
+ onSelect: Ft,
562
+ onScroll: () => {
563
+ X(), l && _();
564
+ },
565
+ onKeyDown: Ut,
566
+ onFocus: () => {
567
+ I.current = null, st(!0), F(!1);
568
+ },
569
+ onBlur: () => st(!1),
570
+ placeholder: it,
571
+ disabled: x,
572
+ className: `absolute inset-0 w-full h-full bg-transparent border-none outline-none ${Et[s]} placeholder:text-[var(--malachite-text-placeholder)] placeholder:font-medium disabled:cursor-not-allowed`,
573
+ style: {
574
+ ...St,
575
+ color: "transparent",
576
+ caretColor: "var(--malachite-text-primary, rgb(10, 10, 10))"
577
+ }
578
+ }
579
+ )
580
+ ]
581
+ }
582
+ ),
583
+ Y !== void 0 && // Not role="status": one per bar would collide with a page's own status queries.
584
+ /* @__PURE__ */ n("span", { "aria-live": "polite", className: "sr-only", children: /* @__PURE__ */ n("span", { children: U.message }, U.count) }),
585
+ Dt && // Not for text alone: typing then never changes the bar's layout.
586
+ /* @__PURE__ */ n(
587
+ "button",
588
+ {
589
+ type: "button",
590
+ onClick: Vt,
591
+ disabled: x,
592
+ className: Ee,
593
+ children: "Clear All"
594
+ }
595
+ ),
596
+ l && Jt(
333
597
  /* @__PURE__ */ d(
334
598
  "div",
335
599
  {
336
- ref: x,
337
- id: N,
600
+ ref: N,
601
+ id: V,
338
602
  role: "listbox",
339
- ...ht,
340
- onMouseDown: Wt,
603
+ "aria-label": W,
604
+ ...Pt,
605
+ onMouseDown: Ae,
341
606
  style: {
342
607
  position: "fixed",
343
- top: (i == null ? void 0 : i.top) ?? 0,
344
- left: (i == null ? void 0 : i.left) ?? 0,
345
- minWidth: Math.min(
346
- B,
347
- (i == null ? void 0 : i.width) ?? B
348
- ),
349
- maxWidth: Math.min(
350
- ot,
351
- (i == null ? void 0 : i.width) ?? ot
352
- ),
608
+ // Its own width, not what is left right of `left`: positioning reads
609
+ // the width, so it must not depend on the position it produces.
610
+ width: "max-content",
611
+ top: (b == null ? void 0 : b.top) ?? 0,
612
+ left: (b == null ? void 0 : b.left) ?? 0,
613
+ minWidth: `min(${It}px, calc(100vw - ${_t * 2}px))`,
614
+ // Capped by the viewport, not the last measured width, which would
615
+ // keep a menu that narrowed for short rows from widening again.
616
+ maxWidth: `min(${Kt}px, calc(100vw - ${_t * 2}px))`,
353
617
  background: "var(--malachite-card-background, rgb(255, 255, 255))",
354
618
  border: "1px solid var(--malachite-card-border, rgb(232, 232, 232))",
355
619
  borderRadius: 12,
356
620
  boxShadow: "0px 2px 5px 0px rgba(0, 0, 0, 0.1)",
357
- padding: 4,
621
+ padding: at,
358
622
  display: "flex",
359
623
  flexDirection: "column",
360
624
  gap: 2,
361
625
  maxHeight: 320,
362
626
  overflowY: "auto",
363
- fontSize: O[w],
364
- visibility: i ? "visible" : "hidden",
365
- opacity: i ? 1 : 0
627
+ fontSize: K[s],
628
+ visibility: b ? "visible" : "hidden",
629
+ opacity: b ? 1 : 0
366
630
  },
367
- children: bt
631
+ children: [
632
+ W && // aria-hidden: a listbox admits only options. The title is the
633
+ // listbox's own label instead.
634
+ /* @__PURE__ */ n("div", { ref: ft, "aria-hidden": "true", style: $e, children: W }),
635
+ Xt,
636
+ B && B.length > 0 && // Pointer and keyboard both already work without reading these.
637
+ /* @__PURE__ */ n("div", { ref: xt, "aria-hidden": "true", style: Me, children: B.map((t) => /* @__PURE__ */ d(
638
+ "span",
639
+ {
640
+ style: { display: "inline-flex", alignItems: "center" },
641
+ children: [
642
+ /* @__PURE__ */ n("kbd", { style: Re, children: t.keys }),
643
+ t.label
644
+ ]
645
+ },
646
+ JSON.stringify([t.keys, t.label])
647
+ )) })
648
+ ]
368
649
  }
369
650
  ),
370
651
  document.body
@@ -374,7 +655,7 @@ const Dt = {
374
655
  );
375
656
  };
376
657
  export {
377
- Jt as QueryInput,
378
- Jt as default
658
+ nr as QueryInput,
659
+ nr as default
379
660
  };
380
661
  //# sourceMappingURL=QueryInput.js.map