@svgrid/grid-wc 2.0.1 → 2.2.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.
@@ -0,0 +1,251 @@
1
+ import { t as e } from "./rolldown-runtime-Dy4uBu1J.js";
2
+ import { A as t, B as n, C as r, D as i, F as a, G as o, I as s, J as c, K as l, L as u, M as d, O as f, P as p, Q as m, T as h, V as g, X as _, Y as v, _ as y, a as b, b as x, d as S, et as C, k as ee, n as w, nt as T, q as E, rt as D, s as te, tt as ne, u as re, v as O } from "./client-DOa609yZ.js";
3
+ import { n as ie, r as ae, t as k } from "./popover-WsGlvtQv.js";
4
+ //#region ../grid/dist/SvGridDropdown.svelte
5
+ var A = /* @__PURE__ */ e({ default: () => j }), oe = t("<span class=\"sv-grid-chip sv-grid-chip-removable svelte-13rpzh6\"> <span class=\"sv-grid-chip-remove svelte-13rpzh6\" role=\"button\">×</span></span>"), se = t("<span class=\"sv-grid-dropdown-chips svelte-13rpzh6\"></span>"), ce = t("<span class=\"sv-grid-chip svelte-13rpzh6\"> </span>"), le = t("<span class=\"sv-grid-dropdown-label svelte-13rpzh6\"> </span>"), ue = t("<input type=\"search\" class=\"sv-grid-dropdown-search\" placeholder=\"Search…\"/>"), de = t("<div class=\"sv-grid-dropdown-empty\"> </div>"), fe = t("<span class=\"sv-grid-dropdown-check\" aria-hidden=\"true\"> </span>"), pe = t("<span class=\"sv-grid-dropdown-option-chip\"> </span>"), me = t("<span class=\"sv-grid-dropdown-option-label\"> </span>"), he = t("<div role=\"option\"><!> <!></div>"), ge = t("<div class=\"sv-grid-dropdown-footer\"><button type=\"button\" class=\"sv-grid-dropdown-done\">Done</button></div>"), _e = t("<div role=\"listbox\"><!> <!> <!></div>"), ve = t("<div><button type=\"button\" aria-haspopup=\"listbox\"><!> <span class=\"sv-grid-dropdown-caret svelte-13rpzh6\" aria-hidden=\"true\">▾</span></button> <!></div>");
6
+ function j(e, t) {
7
+ let p = d();
8
+ ne(t, !0);
9
+ let A = w(t, "multiple", 3, !1), j = w(t, "placeholder", 3, "Select…"), M = w(t, "renderChipsInTrigger", 3, !1), N = w(t, "searchable", 3, !1), ye = w(t, "autoOpen", 3, !0);
10
+ function P(e) {
11
+ return e >= 0 && e < u(L).length ? `${p}-opt-${e}` : void 0;
12
+ }
13
+ let F = m(() => t.options.some((e) => e.color) ? 40 : 32), I = _(""), L = m(() => !N() || !u(I).trim() ? t.options : (() => {
14
+ let e = u(I).trim().toLowerCase();
15
+ return t.options.filter((t) => t.label.toLowerCase().includes(e));
16
+ })()), R = _(!1), z = _(-1), B = _(null), V = _(null), H = _(null), U = _(c({
17
+ top: 0,
18
+ left: 0,
19
+ width: 0,
20
+ openUpward: !1,
21
+ maxHeight: 0,
22
+ availHeight: 0
23
+ })), W = m(() => Array.isArray(t.value) ? t.value : t.value == null || t.value === "" ? [] : [t.value]), be = m(() => {
24
+ if (u(W).length === 0) return j();
25
+ if (!A()) {
26
+ let e = u(W)[0], n = t.options.find((t) => String(t.value) === String(e));
27
+ return n ? n.label : String(e);
28
+ }
29
+ return `${u(W).length} selected`;
30
+ }), xe = m(() => {
31
+ if (A() || u(W).length !== 1) return;
32
+ let e = u(W)[0];
33
+ return t.options.find((t) => String(t.value) === String(e))?.color;
34
+ });
35
+ function G(e) {
36
+ return u(W).some((t) => String(t) === String(e.value));
37
+ }
38
+ function K(e) {
39
+ if (A()) {
40
+ let n = G(e) ? u(W).filter((t) => String(t) !== String(e.value)) : [...u(W), e.value];
41
+ t.onChange?.(n);
42
+ } else t.onChange?.(e.value), v(R, !1), t.onCommit?.();
43
+ }
44
+ function q() {
45
+ if (!u(R)) {
46
+ if (v(R, !0), u(z) < 0) {
47
+ let e = t.options.findIndex((e) => G(e));
48
+ v(z, e >= 0 ? e : 0, !0);
49
+ }
50
+ Se();
51
+ }
52
+ }
53
+ function Se() {
54
+ if (!u(V)) return;
55
+ let e = Math.min(t.options.length, 10) * u(F) + (A() ? 40 : 0) + 8;
56
+ v(U, k(u(V).getBoundingClientRect(), {
57
+ estimatedHeight: e,
58
+ clampHorizontal: !1
59
+ }), !0);
60
+ }
61
+ g(() => {
62
+ if (!u(R)) return;
63
+ let e = () => Se();
64
+ return window.addEventListener("scroll", e, !0), window.addEventListener("resize", e), () => {
65
+ window.removeEventListener("scroll", e, !0), window.removeEventListener("resize", e);
66
+ };
67
+ });
68
+ function J() {
69
+ v(R, !1), v(z, -1);
70
+ }
71
+ function Ce(e) {
72
+ if (e.stopPropagation(), e.key === "Escape") {
73
+ e.preventDefault(), J(), t.onCancel?.();
74
+ return;
75
+ }
76
+ if (e.key === "ArrowDown") {
77
+ if (e.preventDefault(), !u(R)) {
78
+ q();
79
+ return;
80
+ }
81
+ v(z, Math.min(u(z) + 1, t.options.length - 1), !0), Y();
82
+ } else if (e.key === "ArrowUp") {
83
+ if (e.preventDefault(), !u(R)) {
84
+ q();
85
+ return;
86
+ }
87
+ v(z, Math.max(u(z) - 1, 0), !0), Y();
88
+ } else if (e.key === "Home") {
89
+ if (!u(R)) return;
90
+ e.preventDefault(), v(z, 0), Y();
91
+ } else if (e.key === "End") {
92
+ if (!u(R)) return;
93
+ e.preventDefault(), v(z, t.options.length - 1), Y();
94
+ } else if (e.key === "Enter") {
95
+ if (e.preventDefault(), !u(R)) {
96
+ q();
97
+ return;
98
+ }
99
+ let n = t.options[u(z)];
100
+ n ? K(n) : A() && (J(), t.onCommit?.());
101
+ } else if (e.key === " " && u(R)) {
102
+ e.preventDefault();
103
+ let n = t.options[u(z)];
104
+ n && K(n);
105
+ } else e.key === "Tab" && (u(R) && J(), t.onCommit?.());
106
+ }
107
+ function Y() {
108
+ queueMicrotask(() => {
109
+ u(H) && u(H).querySelector(`[data-opt-idx="${u(z)}"]`)?.scrollIntoView({ block: "nearest" });
110
+ });
111
+ }
112
+ function we(e) {
113
+ let n = e.relatedTarget;
114
+ n && u(B)?.contains(n) || (u(R) && J(), t.onCommit?.());
115
+ }
116
+ function Te(e, n) {
117
+ n.preventDefault(), n.stopPropagation();
118
+ let r = u(W).filter((t) => String(t) !== String(e));
119
+ t.onChange?.(A() ? r : r[0] ?? null);
120
+ }
121
+ function Ee(e) {
122
+ ye() && (e.focus(), q());
123
+ }
124
+ g(() => {
125
+ if (!u(R)) return;
126
+ let e = (e) => {
127
+ let n = e.target;
128
+ n && (u(B)?.contains(n) || u(H)?.contains(n) || (J(), t.onCommit?.()));
129
+ };
130
+ return document.addEventListener("pointerdown", e, !0), () => document.removeEventListener("pointerdown", e, !0);
131
+ });
132
+ function X(e) {
133
+ return `background: color-mix(in srgb, ${e} 22%, transparent);border-color: color-mix(in srgb, ${e} 45%, transparent);color: color-mix(in srgb, ${e} 80%, var(--sg-fg, #0f172a));`;
134
+ }
135
+ var Z = ve();
136
+ let De;
137
+ var Q = o(Z);
138
+ let $;
139
+ var Oe = o(Q), ke = (e) => {
140
+ var s = se();
141
+ r(s, 21, () => u(W), (e) => String(e), (e, r) => {
142
+ let s = m(() => t.options.find((e) => String(e.value) === String(u(r))));
143
+ var c = oe(), l = o(c), d = E(l);
144
+ S(d, "tabindex", -1), D(c), n((e, t, n) => {
145
+ y(c, e), i(l, `${t ?? ""} `), S(d, "aria-label", `Remove ${n ?? ""}`);
146
+ }, [
147
+ () => u(s)?.color ? X(u(s).color) : "",
148
+ () => u(s) ? u(s).label : String(u(r)),
149
+ () => u(s) ? u(s).label : String(u(r))
150
+ ]), a("mousedown", d, (e) => e.preventDefault()), a("click", d, (e) => Te(u(r), e)), f(e, c);
151
+ }), D(s), f(e, s);
152
+ }, Ae = (e) => {
153
+ var t = ce(), r = o(t, !0);
154
+ D(t), n((e) => {
155
+ y(t, e), i(r, u(be));
156
+ }, [() => X(u(xe))]), f(e, t);
157
+ }, je = (e) => {
158
+ var t = le(), r = o(t, !0);
159
+ D(t), n(() => i(r, u(be))), f(e, t);
160
+ };
161
+ h(Oe, (e) => {
162
+ M() && u(W).length > 0 ? e(ke) : !A() && u(W).length === 1 && u(xe) ? e(Ae, 1) : e(je, -1);
163
+ }), T(2), D(Q), b(Q, (e) => v(V, e), () => u(V)), x(Q, (e) => Ee?.(e));
164
+ var Me = E(Q, 2), Ne = (e) => {
165
+ let c = m(() => t.options.length > 10), d = m(() => Math.min(u(c) ? 10 * u(F) + (A() ? 40 : 0) + 8 : Infinity, u(U).maxHeight));
166
+ var p = _e();
167
+ let g, _;
168
+ var C = o(p), w = (e) => {
169
+ var n = ue();
170
+ re(n), a("mousedown", n, (e) => e.stopPropagation()), a("click", n, (e) => e.stopPropagation()), a("keydown", n, (e) => {
171
+ e.key === "Escape" && (e.preventDefault(), v(R, !1), t.onCancel?.());
172
+ }), te(n, () => u(I), (e) => v(I, e)), f(e, n);
173
+ };
174
+ h(C, (e) => {
175
+ N() && e(w);
176
+ });
177
+ var T = E(C, 2), ne = (e) => {
178
+ var t = de(), r = o(t, !0);
179
+ D(t), n(() => i(r, N() && u(I) ? `No matches for "${u(I)}"` : "No options")), f(e, t);
180
+ }, k = (e) => {
181
+ var t = ee();
182
+ r(l(t), 19, () => u(L), (e) => String(e.value), (e, t, r) => {
183
+ let c = m(() => G(u(t)));
184
+ var l = he();
185
+ let d;
186
+ var p = o(l), g = (e) => {
187
+ var t = fe(), r = o(t, !0);
188
+ D(t), n(() => i(r, u(c) ? "✓" : "")), f(e, t);
189
+ };
190
+ h(p, (e) => {
191
+ A() && e(g);
192
+ });
193
+ var _ = E(p, 2), b = (e) => {
194
+ var r = pe(), a = o(r, !0);
195
+ D(r), n((e) => {
196
+ y(r, e), i(a, u(t).label);
197
+ }, [() => X(u(t).color)]), f(e, r);
198
+ }, x = (e) => {
199
+ var r = me(), a = o(r, !0);
200
+ D(r), n(() => i(a, u(t).label)), f(e, r);
201
+ };
202
+ h(_, (e) => {
203
+ u(t).color ? e(b) : e(x, -1);
204
+ }), D(l), n((e) => {
205
+ d = O(l, 1, "sv-grid-dropdown-option", null, d, {
206
+ "sv-grid-dropdown-option-selected": u(c),
207
+ "sv-grid-dropdown-option-highlighted": u(r) === u(z)
208
+ }), S(l, "id", e), S(l, "aria-selected", u(c)), S(l, "data-opt-idx", u(r));
209
+ }, [() => P(u(r))]), a("mousedown", l, (e) => {
210
+ e.preventDefault(), K(u(t));
211
+ }), s("mouseenter", l, () => v(z, u(r), !0)), f(e, l);
212
+ }), f(e, t);
213
+ };
214
+ h(T, (e) => {
215
+ u(L).length === 0 ? e(ne) : e(k, -1);
216
+ });
217
+ var oe = E(T, 2), se = (e) => {
218
+ var n = ge(), r = o(n);
219
+ D(n), a("mousedown", r, (e) => e.preventDefault()), a("click", r, () => {
220
+ J(), t.onCommit?.();
221
+ }), f(e, n);
222
+ };
223
+ h(oe, (e) => {
224
+ A() && e(se);
225
+ }), D(p), b(p, (e) => v(H, e), () => u(H)), x(p, (e) => ae?.(e)), x(p, (e, t) => ie?.(e, t), () => ({ up: u(U).openUpward })), n(() => {
226
+ g = O(p, 1, "sv-grid-dropdown-panel", null, g, { "sv-grid-dropdown-panel-fits": !u(c) }), S(p, "aria-multiselectable", A()), _ = y(p, "", _, {
227
+ position: "fixed",
228
+ top: `${u(U).top}px`,
229
+ left: `${u(U).left}px`,
230
+ width: `${u(U).width}px`,
231
+ "max-height": u(d) === null ? null : `${u(d)}px`,
232
+ "z-index": "2147483647"
233
+ });
234
+ }), a("pointerdown", p, (e) => e.stopPropagation()), a("mousedown", p, (e) => e.stopPropagation()), a("click", p, (e) => e.stopPropagation()), f(e, p);
235
+ };
236
+ h(Me, (e) => {
237
+ u(R) && e(Ne);
238
+ }), D(Z), b(Z, (e) => v(B, e), () => u(B)), n((e) => {
239
+ De = O(Z, 1, "sv-grid-dropdown svelte-13rpzh6", null, De, { "sv-grid-dropdown-open": u(R) }), $ = O(Q, 1, "sv-grid-dropdown-trigger svelte-13rpzh6", null, $, { "sv-grid-dropdown-trigger-chips": M() && u(W).length > 0 }), S(Q, "aria-expanded", u(R)), S(Q, "aria-activedescendant", e);
240
+ }, [() => u(R) ? P(u(z)) : void 0]), a("focusout", Z, we), a("click", Z, (e) => e.stopPropagation()), a("dblclick", Z, (e) => e.stopPropagation()), a("pointerdown", Z, (e) => e.stopPropagation()), a("mousedown", Z, (e) => e.stopPropagation()), a("click", Q, () => u(R) ? J() : q()), a("keydown", Q, Ce), f(e, Z), C();
241
+ }
242
+ p([
243
+ "focusout",
244
+ "click",
245
+ "dblclick",
246
+ "pointerdown",
247
+ "mousedown",
248
+ "keydown"
249
+ ]);
250
+ //#endregion
251
+ export { A as n, j as t };