react-gridix 0.1.1 → 0.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.
@@ -1,8 +1,8 @@
1
- import { jsxs as $, jsx as d, Fragment as gt } from "react/jsx-runtime";
2
- import { useState as V, useRef as W, useCallback as kt, useEffect as ae, createElement as se, useLayoutEffect as bt, useMemo as qe } from "react";
3
- import { createPortal as _t } from "react-dom";
4
- const le = (...o) => o.filter(Boolean).join(" ");
5
- function mt() {
1
+ import { jsxs as D, jsx as d, Fragment as je } from "react/jsx-runtime";
2
+ import { useState as R, useRef as $, useEffect as U, useMemo as ae, useCallback as _e, useLayoutEffect as On, createElement as Te } from "react";
3
+ import { createPortal as Kn } from "react-dom";
4
+ const Be = (...r) => r.filter(Boolean).join(" ");
5
+ function Rn() {
6
6
  return /* @__PURE__ */ d("svg", { viewBox: "0 0 16 16", width: "100%", height: "100%", "aria-hidden": "true", focusable: "false", children: /* @__PURE__ */ d(
7
7
  "path",
8
8
  {
@@ -15,654 +15,1588 @@ function mt() {
15
15
  }
16
16
  ) });
17
17
  }
18
- function vt() {
18
+ function Bn() {
19
19
  return /* @__PURE__ */ d("svg", { viewBox: "0 0 16 16", width: "100%", height: "100%", "aria-hidden": "true", focusable: "false", children: /* @__PURE__ */ d("path", { d: "M4 8h8", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round" }) });
20
20
  }
21
- function Ge({
22
- checked: o,
23
- onChange: s,
21
+ function Fe({
22
+ checked: r,
23
+ onChange: n,
24
24
  indeterminate: c = !1,
25
- variant: h = "native",
26
- disabled: I = !1,
27
- label: b,
28
- "aria-label": m,
29
- id: O,
30
- name: H,
31
- indicator: B,
32
- className: G,
25
+ variant: a = "native",
26
+ disabled: g = !1,
27
+ label: f,
28
+ "aria-label": u,
29
+ id: k,
30
+ name: y,
31
+ indicator: E,
32
+ className: T,
33
33
  style: w,
34
- classNames: k = {},
35
- styles: E = {}
34
+ classNames: v = {},
35
+ styles: _ = {}
36
36
  }) {
37
- const F = c ? "indeterminate" : o ? "checked" : "unchecked";
38
- return /* @__PURE__ */ $(
37
+ const C = c ? "indeterminate" : r ? "checked" : "unchecked";
38
+ return /* @__PURE__ */ D(
39
39
  "label",
40
40
  {
41
- className: le(
42
- "rk-checkbox",
43
- `rk-checkbox--${h}`,
44
- F === "checked" && "rk-checkbox--checked",
45
- c && "rk-checkbox--indeterminate",
46
- I && "rk-checkbox--disabled",
47
- k.root,
48
- G
41
+ className: Be(
42
+ "rg-checkbox",
43
+ `rg-checkbox--${a}`,
44
+ C === "checked" && "rg-checkbox--checked",
45
+ c && "rg-checkbox--indeterminate",
46
+ g && "rg-checkbox--disabled",
47
+ v.root,
48
+ T
49
49
  ),
50
- style: { ...E.root, ...w },
51
- "data-state": F,
50
+ style: { ..._.root, ...w },
51
+ "data-state": C,
52
52
  children: [
53
- h === "native" ? /* @__PURE__ */ d(
53
+ a === "native" ? /* @__PURE__ */ d(
54
54
  "input",
55
55
  {
56
56
  type: "checkbox",
57
- id: O,
58
- name: H,
59
- ref: (y) => {
60
- y && (y.indeterminate = c);
57
+ id: k,
58
+ name: y,
59
+ ref: (P) => {
60
+ P && (P.indeterminate = c);
61
61
  },
62
- className: le("rk-checkbox__control", k.control),
63
- style: E.control,
64
- checked: o,
65
- disabled: I,
66
- "aria-label": m,
67
- "data-state": F,
68
- onChange: (y) => s(y.target.checked)
62
+ className: Be("rg-checkbox__control", v.control),
63
+ style: _.control,
64
+ checked: r,
65
+ disabled: g,
66
+ "aria-label": u,
67
+ "data-state": C,
68
+ onChange: (P) => n(P.target.checked)
69
69
  }
70
70
  ) : /* @__PURE__ */ d(
71
71
  "button",
72
72
  {
73
73
  type: "button",
74
74
  role: "checkbox",
75
- id: O,
76
- className: le("rk-checkbox__control", k.control),
77
- style: E.control,
78
- "aria-checked": c ? "mixed" : o,
79
- "aria-label": m,
80
- disabled: I,
81
- "data-state": F,
82
- onClick: () => s(!o),
75
+ id: k,
76
+ className: Be("rg-checkbox__control", v.control),
77
+ style: _.control,
78
+ "aria-checked": c ? "mixed" : r,
79
+ "aria-label": u,
80
+ disabled: g,
81
+ "data-state": C,
82
+ onClick: () => n(!r),
83
83
  children: /* @__PURE__ */ d(
84
84
  "span",
85
85
  {
86
- className: le(
87
- "rk-checkbox__indicator",
88
- B !== void 0 && !c && "rk-checkbox__indicator--custom",
89
- k.indicator
86
+ className: Be(
87
+ "rg-checkbox__indicator",
88
+ E !== void 0 && !c && "rg-checkbox__indicator--custom",
89
+ v.indicator
90
90
  ),
91
- style: E.indicator,
92
- "data-state": F,
91
+ style: _.indicator,
92
+ "data-state": C,
93
93
  "aria-hidden": "true",
94
- children: c ? h === "tick" ? /* @__PURE__ */ d(vt, {}) : null : B !== void 0 ? B : h === "tick" ? /* @__PURE__ */ d(mt, {}) : null
94
+ children: c ? a === "tick" ? /* @__PURE__ */ d(Bn, {}) : null : E !== void 0 ? E : a === "tick" ? /* @__PURE__ */ d(Rn, {}) : null
95
95
  }
96
96
  )
97
97
  }
98
98
  ),
99
- b != null && b !== !1 && b !== "" && /* @__PURE__ */ d("span", { className: le("rk-checkbox__label", k.label), style: E.label, children: b })
99
+ f != null && f !== !1 && f !== "" && /* @__PURE__ */ d("span", { className: Be("rg-checkbox__label", v.label), style: _.label, children: f })
100
100
  ]
101
101
  }
102
102
  );
103
103
  }
104
- const Ne = (...o) => o.filter(Boolean).join(" "), yt = typeof window < "u" ? bt : ae;
105
- function xt({
106
- column: o,
107
- label: s,
108
- value: c,
109
- onChange: h,
110
- theme: I,
111
- indicatorClassName: b,
112
- indicatorStyle: m,
113
- popupClassName: O,
114
- popupStyle: H,
115
- inputClassName: B,
116
- inputStyle: G
117
- }) {
118
- const [w, k] = V(!1), [E, F] = V({ top: 0, left: 0 }), y = W(null), R = W(null), q = c.trim() !== "", L = kt(() => {
119
- var j;
120
- const g = y.current;
121
- if (!g) return;
122
- const K = g.getBoundingClientRect(), A = ((j = R.current) == null ? void 0 : j.offsetWidth) ?? 260, T = Math.max(8, Math.min(K.left, window.innerWidth - A - 8));
123
- F({ top: K.bottom + 6, left: T });
124
- }, []);
125
- yt(() => {
126
- w && L();
127
- }, [w, L]), ae(() => {
128
- if (!w) return;
129
- const g = (A) => {
130
- var j, de;
131
- const T = A.target;
132
- (j = R.current) != null && j.contains(T) || (de = y.current) != null && de.contains(T) || k(!1);
133
- }, K = (A) => {
134
- var T;
135
- A.key === "Escape" && (k(!1), (T = y.current) == null || T.focus());
104
+ const Yn = /^(\d{4})-(\d{2})-(\d{2})$/, Fr = (r) => String(r).padStart(2, "0");
105
+ function J(r) {
106
+ const n = Yn.exec(r);
107
+ if (!n) return null;
108
+ const [c, a, g] = [Number(n[1]), Number(n[2]), Number(n[3])], f = new Date(c, a - 1, g);
109
+ return f.getFullYear() === c && f.getMonth() === a - 1 && f.getDate() === g ? f : null;
110
+ }
111
+ function Z(r) {
112
+ var n;
113
+ if (r instanceof Date)
114
+ return Number.isNaN(r.getTime()) ? null : `${r.getFullYear()}-${Fr(r.getMonth() + 1)}-${Fr(r.getDate())}`;
115
+ if (typeof r == "number") return Number.isFinite(r) ? Z(new Date(r)) : null;
116
+ if (typeof r == "string") {
117
+ const c = r.trim();
118
+ if (c === "") return null;
119
+ const a = (n = /^\d{4}-\d{2}-\d{2}/.exec(c)) == null ? void 0 : n[0];
120
+ if (a) return J(a) ? a : null;
121
+ const g = Date.parse(c);
122
+ return Number.isNaN(g) ? null : Z(new Date(g));
123
+ }
124
+ return null;
125
+ }
126
+ function Wn(r, n, c) {
127
+ const a = Z(r);
128
+ return a ? J(a).toLocaleDateString(n, c ?? { year: "numeric", month: "short", day: "numeric" }) : r == null ? "" : String(r);
129
+ }
130
+ function jn(r, n) {
131
+ var c;
132
+ return r === "" ? null : n instanceof Date ? J(r) : typeof n == "number" ? ((c = J(r)) == null ? void 0 : c.getTime()) ?? null : r;
133
+ }
134
+ const O = (...r) => r.filter(Boolean).join(" "), _t = (r) => r.headerName ?? (r.type === "boolean" ? "" : r.type === "sequence" ? "#" : r.field), ke = (r) => _t(r) || r.field, Sr = (r) => String(r).padStart(2, "0"), qt = (r, n, c) => `${r}-${Sr(n + 1)}-${Sr(c)}`;
135
+ function Ir(r, n, c, a) {
136
+ const g = [r, n == null ? void 0 : n.from, n == null ? void 0 : n.to].map((y) => y ? J(y) : null).find(Boolean);
137
+ if (g) return new Date(g.getFullYear(), g.getMonth(), 1);
138
+ const f = /* @__PURE__ */ new Date();
139
+ let u = Z(f);
140
+ c && u < c && (u = c), a && u > a && (u = a);
141
+ const k = J(u) ?? f;
142
+ return new Date(k.getFullYear(), k.getMonth(), 1);
143
+ }
144
+ function Kr({ value: r, range: n, min: c, max: a, onPick: g, locale: f, weekStart: u = 0, hideFooter: k, keepFocus: y, className: E }) {
145
+ var Ve;
146
+ const [T, w] = R(() => Ir(r, n, c, a)), [v, _] = R(null), C = $(null), P = $({ value: r, from: n == null ? void 0 : n.from, to: n == null ? void 0 : n.to });
147
+ U(() => {
148
+ const b = P.current;
149
+ P.current = { value: r, from: n == null ? void 0 : n.from, to: n == null ? void 0 : n.to };
150
+ const j = r !== b.value ? r : (n == null ? void 0 : n.from) !== b.from ? n == null ? void 0 : n.from : (n == null ? void 0 : n.to) !== b.to ? n == null ? void 0 : n.to : void 0, I = j ? J(j) : null;
151
+ I && w((K) => K.getFullYear() === I.getFullYear() && K.getMonth() === I.getMonth() ? K : new Date(I.getFullYear(), I.getMonth(), 1));
152
+ }, [r, n == null ? void 0 : n.from, n == null ? void 0 : n.to]);
153
+ const F = Z(/* @__PURE__ */ new Date()), N = T.getFullYear(), S = T.getMonth(), re = ae(() => {
154
+ const b = new Intl.DateTimeFormat(f, { weekday: "short" });
155
+ return Array.from({ length: 7 }, (j, I) => b.format(new Date(2023, 0, 1 + (I + u) % 7)));
156
+ }, [f, u]), ue = new Intl.DateTimeFormat(f, { month: "long", year: "numeric" }).format(T), X = ae(() => {
157
+ const b = (new Date(N, S, 1).getDay() - u + 7) % 7;
158
+ return Array.from({ length: 42 }, (j, I) => {
159
+ const K = new Date(N, S, 1 - b + I);
160
+ return { iso: qt(K.getFullYear(), K.getMonth(), K.getDate()), day: K.getDate(), outside: K.getMonth() !== S };
161
+ });
162
+ }, [N, S, u]), V = (b) => !!c && b < c || !!a && b > a, ce = (b) => w(new Date(N, S + b, 1)), qe = (b) => {
163
+ const j = J(b);
164
+ j && ((j.getFullYear() !== N || j.getMonth() !== S) && w(new Date(j.getFullYear(), j.getMonth(), 1)), _(b), requestAnimationFrame(() => {
165
+ var I, K;
166
+ return (K = (I = C.current) == null ? void 0 : I.querySelector(`[data-iso="${b}"]`)) == null ? void 0 : K.focus();
167
+ }));
168
+ }, Se = (b, j) => {
169
+ const I = J(j), K = (le) => {
170
+ b.preventDefault(), qe(qt(I.getFullYear(), I.getMonth(), I.getDate() + le));
136
171
  };
137
- return document.addEventListener("mousedown", g), document.addEventListener("keydown", K), window.addEventListener("resize", L), window.addEventListener("scroll", L, !0), () => {
138
- document.removeEventListener("mousedown", g), document.removeEventListener("keydown", K), window.removeEventListener("resize", L), window.removeEventListener("scroll", L, !0);
172
+ switch (b.key) {
173
+ case "ArrowLeft":
174
+ return K(-1);
175
+ case "ArrowRight":
176
+ return K(1);
177
+ case "ArrowUp":
178
+ return K(-7);
179
+ case "ArrowDown":
180
+ return K(7);
181
+ case "Home":
182
+ return K(-((I.getDay() - u + 7) % 7));
183
+ case "End":
184
+ return K(6 - (I.getDay() - u + 7) % 7);
185
+ case "PageUp":
186
+ case "PageDown": {
187
+ b.preventDefault();
188
+ const le = b.key === "PageUp" ? -1 : 1, fe = new Date(I.getFullYear(), I.getMonth() + le + 1, 0).getDate();
189
+ qe(qt(I.getFullYear(), I.getMonth() + le, Math.min(I.getDate(), fe)));
190
+ return;
191
+ }
192
+ }
193
+ }, yt = (b) => !!b && X.some((j) => j.iso === b && !j.outside), vt = [v, r, F].find((b) => yt(b) && !V(b)) ?? ((Ve = X.find((b) => !b.outside && !V(b.iso))) == null ? void 0 : Ve.iso), ne = n == null ? void 0 : n.from, W = n == null ? void 0 : n.to;
194
+ return /* @__PURE__ */ D(
195
+ "div",
196
+ {
197
+ className: O("rg-cal", E),
198
+ onMouseDown: y ? (b) => b.preventDefault() : void 0,
199
+ role: "group",
200
+ "aria-label": `Calendar, ${ue}`,
201
+ children: [
202
+ /* @__PURE__ */ D("div", { className: "rg-cal__head", children: [
203
+ /* @__PURE__ */ d("button", { type: "button", className: "rg-cal__nav", "aria-label": "Previous year", onClick: () => ce(-12), children: "«" }),
204
+ /* @__PURE__ */ d("button", { type: "button", className: "rg-cal__nav", "aria-label": "Previous month", onClick: () => ce(-1), children: "‹" }),
205
+ /* @__PURE__ */ d("span", { className: "rg-cal__title", "aria-live": "polite", children: ue }),
206
+ /* @__PURE__ */ d("button", { type: "button", className: "rg-cal__nav", "aria-label": "Next month", onClick: () => ce(1), children: "›" }),
207
+ /* @__PURE__ */ d("button", { type: "button", className: "rg-cal__nav", "aria-label": "Next year", onClick: () => ce(12), children: "»" })
208
+ ] }),
209
+ /* @__PURE__ */ D("div", { className: "rg-cal__grid", ref: C, children: [
210
+ re.map((b) => /* @__PURE__ */ d("span", { className: "rg-cal__dow", "aria-hidden": "true", children: b.slice(0, 2) }, b)),
211
+ X.map(({ iso: b, day: j, outside: I }) => {
212
+ const K = b === r, le = b === ne, fe = b === W, xt = !!ne && !!W && b > ne && b < W;
213
+ return /* @__PURE__ */ d(
214
+ "button",
215
+ {
216
+ type: "button",
217
+ "data-iso": b,
218
+ tabIndex: b === vt ? 0 : -1,
219
+ disabled: V(b),
220
+ "aria-pressed": K || le || fe,
221
+ "aria-label": new Intl.DateTimeFormat(f, { dateStyle: "full" }).format(J(b)),
222
+ className: O(
223
+ "rg-cal__day",
224
+ I && "rg-cal__day--outside",
225
+ b === F && "rg-cal__day--today",
226
+ (K || le || fe) && "rg-cal__day--selected",
227
+ xt && "rg-cal__day--in-range",
228
+ ne && W && le && ne !== W && "rg-cal__day--range-start",
229
+ ne && W && fe && ne !== W && "rg-cal__day--range-end"
230
+ ),
231
+ onClick: () => g(b),
232
+ onKeyDown: (Ue) => Se(Ue, b),
233
+ onFocus: () => _(b),
234
+ children: j
235
+ },
236
+ b
237
+ );
238
+ })
239
+ ] }),
240
+ !k && /* @__PURE__ */ D("div", { className: "rg-cal__foot", children: [
241
+ /* @__PURE__ */ d(
242
+ "button",
243
+ {
244
+ type: "button",
245
+ className: "rg-cal__link",
246
+ disabled: V(F),
247
+ onClick: () => {
248
+ w(Ir(F)), g(F);
249
+ },
250
+ children: "Today"
251
+ }
252
+ ),
253
+ /* @__PURE__ */ d("button", { type: "button", className: "rg-cal__link", onClick: () => g(""), children: "Clear" })
254
+ ] })
255
+ ]
256
+ }
257
+ );
258
+ }
259
+ const Ut = typeof window < "u" ? On : U;
260
+ function Ye(r, n, c) {
261
+ const [a, g] = R(n), f = r !== void 0, u = f ? r : a, k = _e(
262
+ (y) => {
263
+ f || g(y), c == null || c(y);
264
+ },
265
+ [f, c]
266
+ );
267
+ return [u, k];
268
+ }
269
+ function Rr(r, n) {
270
+ const c = $(r);
271
+ c.current = r;
272
+ const a = $(void 0), g = $(null), f = _e(() => {
273
+ a.current !== void 0 && clearTimeout(a.current), a.current = void 0, g.current = null;
274
+ }, []), u = _e(() => {
275
+ a.current !== void 0 && clearTimeout(a.current), a.current = void 0;
276
+ const y = g.current;
277
+ g.current = null, y && c.current(...y);
278
+ }, []), k = _e(
279
+ (...y) => {
280
+ if (n <= 0) {
281
+ f(), c.current(...y);
282
+ return;
283
+ }
284
+ g.current = y, a.current !== void 0 && clearTimeout(a.current), a.current = setTimeout(u, n);
285
+ },
286
+ [n, f, u]
287
+ );
288
+ return U(() => u, [u]), { call: k, flush: u, cancel: f };
289
+ }
290
+ function Jt({ anchorRef: r, open: n, onClose: c, label: a, theme: g, className: f, style: u, keepFocus: k, children: y }) {
291
+ const E = $(null), [T, w] = R({ top: 0, left: 0 }), v = _e(() => {
292
+ var N;
293
+ const _ = r.current;
294
+ if (!_) return;
295
+ const C = _.getBoundingClientRect(), P = ((N = E.current) == null ? void 0 : N.offsetWidth) ?? 260, F = Math.max(8, Math.min(C.left, window.innerWidth - P - 8));
296
+ w({ top: C.bottom + 6, left: F });
297
+ }, [r]);
298
+ return Ut(() => {
299
+ n && v();
300
+ }, [n, v]), U(() => {
301
+ if (!n) return;
302
+ const _ = (P) => {
303
+ var N, S;
304
+ const F = P.target;
305
+ (N = E.current) != null && N.contains(F) || (S = r.current) != null && S.contains(F) || c();
306
+ }, C = (P) => {
307
+ var F;
308
+ P.key === "Escape" && (c(), (F = r.current) == null || F.focus());
139
309
  };
140
- }, [w, L]);
141
- const _e = () => {
142
- var g;
143
- k(!1), (g = y.current) == null || g.focus();
310
+ return document.addEventListener("mousedown", _), document.addEventListener("keydown", C), window.addEventListener("resize", v), window.addEventListener("scroll", v, !0), () => {
311
+ document.removeEventListener("mousedown", _), document.removeEventListener("keydown", C), window.removeEventListener("resize", v), window.removeEventListener("scroll", v, !0);
312
+ };
313
+ }, [n, c, v, r]), !n || typeof document > "u" ? null : Kn(
314
+ /* @__PURE__ */ d(
315
+ "div",
316
+ {
317
+ ref: E,
318
+ role: "dialog",
319
+ onMouseDown: k ? (_) => _.preventDefault() : void 0,
320
+ "aria-label": a,
321
+ "data-rg-theme": g || void 0,
322
+ className: O("rg-grid-popup", f),
323
+ style: { position: "fixed", top: T.top, left: T.left, ...u },
324
+ children: y
325
+ }
326
+ ),
327
+ document.body
328
+ );
329
+ }
330
+ function qn({ value: r, onChange: n, onPick: c, onBlur: a, onKeyDown: g, min: f, max: u, locale: k, invalid: y, label: E, theme: T, className: w, style: v }) {
331
+ const _ = $(null);
332
+ return /* @__PURE__ */ D(je, { children: [
333
+ /* @__PURE__ */ d(
334
+ "input",
335
+ {
336
+ ref: _,
337
+ autoFocus: !0,
338
+ type: "text",
339
+ inputMode: "numeric",
340
+ placeholder: "YYYY-MM-DD",
341
+ autoComplete: "off",
342
+ className: w,
343
+ style: v,
344
+ value: r,
345
+ "aria-label": E,
346
+ "aria-invalid": y || void 0,
347
+ "aria-haspopup": "dialog",
348
+ "aria-expanded": !0,
349
+ onChange: (C) => n(C.target.value.trim()),
350
+ onBlur: a,
351
+ onKeyDown: g,
352
+ onFocus: (C) => C.currentTarget.setSelectionRange(C.currentTarget.value.length, C.currentTarget.value.length)
353
+ }
354
+ ),
355
+ /* @__PURE__ */ d(Jt, { anchorRef: _, open: !0, onClose: () => {
356
+ }, label: E, theme: T, className: "rg-date-popup", keepFocus: !0, children: /* @__PURE__ */ d(Kr, { value: r, min: f, max: u, locale: k, onPick: c, keepFocus: !0 }) })
357
+ ] });
358
+ }
359
+ function Lr(r) {
360
+ return r.filterType ? r.filterType : r.type === "number" ? "number" : r.type === "date" ? "date" : r.type === "boolean" ? "select" : "text";
361
+ }
362
+ const Vn = (r) => typeof r == "object" && r !== null && !Array.isArray(r);
363
+ function Br(r) {
364
+ if (r == null) return !1;
365
+ if (typeof r == "string") return r.trim() !== "";
366
+ if (Array.isArray(r)) return r.length > 0;
367
+ if (Vn(r)) {
368
+ const n = r;
369
+ return typeof n.min == "number" || typeof n.max == "number" || !!n.from || !!n.to;
370
+ }
371
+ return !1;
372
+ }
373
+ function Un(r, n, c, a) {
374
+ switch (r) {
375
+ case "text":
376
+ return c.toLowerCase().includes(String(n).trim().toLowerCase());
377
+ case "exact":
378
+ return c.toLowerCase() === String(n).trim().toLowerCase();
379
+ case "number": {
380
+ const { min: g, max: f } = n, u = typeof a == "number" ? a : a == null || a === "" ? NaN : Number(a);
381
+ return Number.isNaN(u) ? !1 : (typeof g != "number" || u >= g) && (typeof f != "number" || u <= f);
382
+ }
383
+ case "date": {
384
+ const { from: g, to: f } = n, u = Z(a);
385
+ return u ? (!g || u >= g) && (!f || u <= f) : !1;
386
+ }
387
+ case "select":
388
+ return n.includes(String(a ?? ""));
389
+ }
390
+ }
391
+ function zn(r, n, c, a) {
392
+ if (r.filterOptions) return r.filterOptions.map((f) => typeof f == "string" ? { value: f, label: f } : f);
393
+ if (r.type === "boolean")
394
+ return [
395
+ { value: "true", label: "Yes" },
396
+ { value: "false", label: "No" }
397
+ ];
398
+ const g = /* @__PURE__ */ new Map();
399
+ for (const f of n) {
400
+ const u = c(f);
401
+ if (u == null || u === "") continue;
402
+ const k = String(u);
403
+ g.has(k) || g.set(k, a(f));
404
+ }
405
+ return [...g].map(([f, u]) => ({ value: f, label: u })).sort((f, u) => f.label.localeCompare(u.label, void 0, { numeric: !0 }));
406
+ }
407
+ const $r = (r) => {
408
+ if (r.trim() === "") return;
409
+ const n = Number(r);
410
+ return Number.isFinite(n) ? n : void 0;
411
+ }, Yr = (r) => typeof r == "object" && r !== null && !Array.isArray(r);
412
+ function Hn({
413
+ value: r,
414
+ onChange: n,
415
+ label: c,
416
+ debounce: a,
417
+ inputClassName: g,
418
+ inputStyle: f
419
+ }) {
420
+ const u = Yr(r) ? r : {}, [k, y] = R(u.min === void 0 ? "" : String(u.min)), [E, T] = R(u.max === void 0 ? "" : String(u.max)), w = $(u), v = Rr((_, C) => {
421
+ const P = $r(_), F = $r(C);
422
+ w.current = { min: P, max: F }, n(P === void 0 && F === void 0 ? void 0 : { min: P, max: F });
423
+ }, a);
424
+ return U(() => {
425
+ u.min === w.current.min && u.max === w.current.max || (w.current = u, v.cancel(), y(u.min === void 0 ? "" : String(u.min)), T(u.max === void 0 ? "" : String(u.max)));
426
+ }, [u.min, u.max]), /* @__PURE__ */ D("div", { className: "rg-grid__filter-fields", children: [
427
+ /* @__PURE__ */ D("label", { className: "rg-grid__filter-field", children: [
428
+ /* @__PURE__ */ d("span", { children: "Min" }),
429
+ /* @__PURE__ */ d(
430
+ "input",
431
+ {
432
+ autoFocus: !0,
433
+ type: "number",
434
+ className: O("rg-grid__filter-input", g),
435
+ style: f,
436
+ value: k,
437
+ "aria-label": `Minimum ${c}`,
438
+ onChange: (_) => {
439
+ y(_.target.value), v.call(_.target.value, E);
440
+ },
441
+ onKeyDown: (_) => _.key === "Enter" && v.flush()
442
+ }
443
+ )
444
+ ] }),
445
+ /* @__PURE__ */ D("label", { className: "rg-grid__filter-field", children: [
446
+ /* @__PURE__ */ d("span", { children: "Max" }),
447
+ /* @__PURE__ */ d(
448
+ "input",
449
+ {
450
+ type: "number",
451
+ className: O("rg-grid__filter-input", g),
452
+ style: f,
453
+ value: E,
454
+ "aria-label": `Maximum ${c}`,
455
+ onChange: (_) => {
456
+ T(_.target.value), v.call(k, _.target.value);
457
+ },
458
+ onKeyDown: (_) => _.key === "Enter" && v.flush()
459
+ }
460
+ )
461
+ ] })
462
+ ] });
463
+ }
464
+ function Jn({
465
+ value: r,
466
+ onChange: n,
467
+ onEnter: c,
468
+ label: a,
469
+ kind: g,
470
+ placeholder: f,
471
+ debounce: u,
472
+ inputClassName: k,
473
+ inputStyle: y
474
+ }) {
475
+ const [E, T] = R(r), w = $(r), v = Rr((_) => {
476
+ w.current = _, n(_ || void 0);
477
+ }, u);
478
+ return U(() => {
479
+ r !== w.current && (w.current = r, v.cancel(), T(r));
480
+ }, [r]), /* @__PURE__ */ d(
481
+ "input",
482
+ {
483
+ autoFocus: !0,
484
+ type: "text",
485
+ className: O("rg-grid__filter-input", k),
486
+ style: y,
487
+ value: E,
488
+ placeholder: f ?? (g === "exact" ? "Exactly…" : `Filter ${a}…`),
489
+ "aria-label": `Filter text for ${a}`,
490
+ onChange: (_) => {
491
+ T(_.target.value), v.call(_.target.value);
492
+ },
493
+ onKeyDown: (_) => {
494
+ _.key === "Enter" && (_.preventDefault(), v.flush(), c());
495
+ }
496
+ }
497
+ );
498
+ }
499
+ function Xn({
500
+ value: r,
501
+ onChange: n,
502
+ label: c,
503
+ inputClassName: a,
504
+ inputStyle: g,
505
+ min: f,
506
+ max: u,
507
+ locale: k
508
+ }) {
509
+ const y = Yr(r) ? r : {}, E = (N, S) => n(!N && !S ? void 0 : { from: N || void 0, to: S || void 0 }), [T, w] = R(y.from ?? ""), [v, _] = R(y.to ?? "");
510
+ U(() => {
511
+ (J(T) ? T : "") !== (y.from ?? "") && w(y.from ?? ""), (J(v) ? v : "") !== (y.to ?? "") && _(y.to ?? "");
512
+ }, [y.from, y.to]);
513
+ const C = (N, S) => {
514
+ if ((N === "from" ? w : _)(S), S !== "" && !J(S)) return;
515
+ const re = S || void 0;
516
+ N === "from" ? E(re, y.to) : E(y.from, re);
517
+ }, P = (N) => {
518
+ N && (!y.from || y.to ? E(N, void 0) : N < y.from ? E(N, y.from) : E(y.from, N));
519
+ }, F = (N, S, re) => /* @__PURE__ */ D("label", { className: "rg-grid__filter-field", children: [
520
+ /* @__PURE__ */ d("span", { children: N === "from" ? "From" : "To" }),
521
+ /* @__PURE__ */ d(
522
+ "input",
523
+ {
524
+ autoFocus: re,
525
+ type: "text",
526
+ inputMode: "numeric",
527
+ placeholder: "YYYY-MM-DD",
528
+ className: O("rg-grid__filter-input", S !== "" && !J(S) && "rg-grid__filter-input--invalid", a),
529
+ style: g,
530
+ value: S,
531
+ "aria-label": `${c} ${N}`,
532
+ "aria-invalid": S !== "" && !J(S) || void 0,
533
+ onChange: (ue) => C(N, ue.target.value.trim())
534
+ }
535
+ )
536
+ ] });
537
+ return /* @__PURE__ */ D("div", { className: "rg-grid__filter-fields rg-grid__filter-fields--stack", children: [
538
+ /* @__PURE__ */ D("div", { className: "rg-grid__filter-date-row", children: [
539
+ F("from", T, !0),
540
+ F("to", v, !1)
541
+ ] }),
542
+ /* @__PURE__ */ d(Kr, { range: y, min: f, max: u, locale: k, onPick: P, hideFooter: !0 })
543
+ ] });
544
+ }
545
+ function Gn({
546
+ value: r,
547
+ onChange: n,
548
+ options: c
549
+ }) {
550
+ const a = Array.isArray(r) ? r : [], g = (f, u) => {
551
+ const k = u ? [...a, f] : a.filter((y) => y !== f);
552
+ n(k.length ? k : void 0);
144
553
  };
145
- return /* @__PURE__ */ $(gt, { children: [
554
+ return /* @__PURE__ */ D("div", { className: "rg-grid__filter-fields rg-grid__filter-options", role: "group", children: [
555
+ c.length === 0 && /* @__PURE__ */ d("span", { className: "rg-grid__filter-empty", children: "No values" }),
556
+ c.map((f) => /* @__PURE__ */ d(
557
+ Fe,
558
+ {
559
+ checked: a.includes(f.value),
560
+ onChange: (u) => g(f.value, u),
561
+ label: f.label ?? f.value
562
+ },
563
+ f.value
564
+ ))
565
+ ] });
566
+ }
567
+ function Qn({
568
+ column: r,
569
+ label: n,
570
+ kind: c,
571
+ value: a,
572
+ onChange: g,
573
+ options: f,
574
+ debounce: u = 300,
575
+ theme: k,
576
+ indicatorClassName: y,
577
+ indicatorStyle: E,
578
+ popupClassName: T,
579
+ popupStyle: w,
580
+ inputClassName: v,
581
+ inputStyle: _
582
+ }) {
583
+ const [C, P] = R(!1), F = $(null), N = Br(a), S = _e(() => P(!1), []), re = typeof a == "string" ? a : "", ue = () => {
584
+ if (r.filterRenderer)
585
+ return Te(r.filterRenderer, { column: r, value: re, onChange: (X) => g(X || void 0) });
586
+ switch (c) {
587
+ case "number":
588
+ return /* @__PURE__ */ d(Hn, { value: a, onChange: g, label: n, debounce: u, inputClassName: v, inputStyle: _ });
589
+ case "date":
590
+ return /* @__PURE__ */ d(Xn, { value: a, onChange: g, label: n, min: r.dateMin, max: r.dateMax, locale: r.dateLocale, inputClassName: v, inputStyle: _ });
591
+ case "select":
592
+ return /* @__PURE__ */ d(Gn, { value: a, onChange: g, options: f });
593
+ default:
594
+ return /* @__PURE__ */ d(
595
+ Jn,
596
+ {
597
+ value: re,
598
+ onChange: g,
599
+ onEnter: () => {
600
+ var X;
601
+ P(!1), (X = F.current) == null || X.focus();
602
+ },
603
+ label: n,
604
+ kind: c,
605
+ placeholder: r.filterPlaceholder,
606
+ debounce: u,
607
+ inputClassName: v,
608
+ inputStyle: _
609
+ }
610
+ );
611
+ }
612
+ };
613
+ return /* @__PURE__ */ D(je, { children: [
146
614
  /* @__PURE__ */ d(
147
615
  "button",
148
616
  {
149
- ref: y,
617
+ ref: F,
150
618
  type: "button",
151
- className: Ne(
152
- "rk-grid__filter-btn",
153
- q && "rk-grid__filter-btn--active",
154
- w && "rk-grid__filter-btn--open",
155
- b
619
+ className: O(
620
+ "rg-grid__filter-btn",
621
+ N && "rg-grid__filter-btn--active",
622
+ C && "rg-grid__filter-btn--open",
623
+ y
156
624
  ),
157
- style: m,
158
- "aria-label": `Filter ${s}`,
625
+ style: E,
626
+ "aria-label": `Filter ${n}`,
159
627
  "aria-haspopup": "dialog",
160
- "aria-expanded": w,
161
- "data-active": q || void 0,
162
- onClick: (g) => {
163
- g.stopPropagation(), w || L(), k((K) => !K);
628
+ "aria-expanded": C,
629
+ "data-active": N || void 0,
630
+ onClick: (X) => {
631
+ X.stopPropagation(), P((V) => !V);
164
632
  },
165
- children: o.filterIndicator ? se(o.filterIndicator, { column: o, active: q, open: w }) : /* @__PURE__ */ d("span", { className: "rk-grid__filter-dot", "aria-hidden": "true" })
633
+ onKeyDown: (X) => X.stopPropagation(),
634
+ children: r.filterIndicator ? Te(r.filterIndicator, { column: r, active: N, open: C }) : /* @__PURE__ */ d("span", { className: "rg-grid__filter-dot", "aria-hidden": "true" })
166
635
  }
167
636
  ),
168
- w && typeof document < "u" && _t(
169
- /* @__PURE__ */ $(
170
- "div",
171
- {
172
- ref: R,
173
- role: "dialog",
174
- "aria-label": `Filter ${s}`,
175
- "data-rk-theme": I || void 0,
176
- className: Ne("rk-grid-popup", O),
177
- style: { position: "fixed", top: E.top, left: E.left, ...H },
178
- children: [
179
- o.filterRenderer ? se(o.filterRenderer, { column: o, value: c, onChange: h }) : /* @__PURE__ */ d(
180
- "input",
181
- {
182
- autoFocus: !0,
183
- type: "text",
184
- className: Ne("rk-grid__filter-input", B),
185
- style: G,
186
- value: c,
187
- placeholder: o.filterPlaceholder ?? `Filter ${s}…`,
188
- "aria-label": `Filter text for ${s}`,
189
- onChange: (g) => h(g.target.value),
190
- onKeyDown: (g) => {
191
- g.key === "Enter" && _e();
192
- }
193
- }
194
- ),
195
- q && /* @__PURE__ */ d("button", { type: "button", className: "rk-grid__filter-clear", onClick: () => h(""), children: "Clear" })
196
- ]
197
- }
198
- ),
199
- document.body
637
+ /* @__PURE__ */ D(
638
+ Jt,
639
+ {
640
+ anchorRef: F,
641
+ open: C,
642
+ onClose: S,
643
+ label: `Filter ${n}`,
644
+ theme: k,
645
+ className: T,
646
+ style: w,
647
+ children: [
648
+ ue(),
649
+ N && /* @__PURE__ */ d("button", { type: "button", className: "rg-grid__filter-clear", onClick: () => g(void 0), children: "Clear" })
650
+ ]
651
+ }
200
652
  )
201
653
  ] });
202
654
  }
203
- const Se = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]), Ye = (o, s) => Object.prototype.hasOwnProperty.call(o, s);
204
- function z(o, s) {
205
- if (o === null || typeof o != "object") return;
206
- if (Ye(o, s)) return o[s];
207
- let c = o;
208
- for (const h of s.split(".")) {
209
- if (c == null || typeof c != "object" || Se.has(h)) return;
210
- c = c[h];
655
+ function Zn({ columns: r, hidden: n, onToggle: c, theme: a, className: g, style: f }) {
656
+ const [u, k] = R(!1), y = $(null), E = _e(() => k(!1), []), T = r.filter((w) => !n.has(w.field)).length;
657
+ return /* @__PURE__ */ D(je, { children: [
658
+ /* @__PURE__ */ d(
659
+ "button",
660
+ {
661
+ ref: y,
662
+ type: "button",
663
+ className: O("rg-grid__tool-btn", g),
664
+ style: f,
665
+ "aria-haspopup": "dialog",
666
+ "aria-expanded": u,
667
+ onClick: () => k((w) => !w),
668
+ children: "Columns"
669
+ }
670
+ ),
671
+ /* @__PURE__ */ d(Jt, { anchorRef: y, open: u, onClose: E, label: "Show or hide columns", theme: a, children: /* @__PURE__ */ d("div", { className: "rg-grid__filter-fields rg-grid__filter-options", role: "group", "aria-label": "Columns", children: r.filter((w) => w.hideable !== !1).map((w) => {
672
+ const v = !n.has(w.field);
673
+ return /* @__PURE__ */ d(
674
+ Fe,
675
+ {
676
+ checked: v,
677
+ disabled: v && T <= 1,
678
+ onChange: (_) => c(w.field, !_),
679
+ label: ke(w)
680
+ },
681
+ w.field
682
+ );
683
+ }) }) })
684
+ ] });
685
+ }
686
+ const eo = /^[=+\-@\t\r]/;
687
+ function to(r, n, c) {
688
+ if (r == null) return "";
689
+ let a = String(r);
690
+ return c && typeof r == "string" && eo.test(a) && !Number.isFinite(Number(a)) && (a = `'${a}`), a.includes(n) || /["\r\n]/.test(a) ? `"${a.replace(/"/g, '""')}"` : a;
691
+ }
692
+ function ro(r, n, c = {}) {
693
+ const { delimiter: a = ",", sanitize: g = !0 } = c, f = (u) => u.map((k) => to(k, a, g)).join(a);
694
+ return [f(r), ...n.map(f)].join(`\r
695
+ `);
696
+ }
697
+ function no(r, n) {
698
+ if (typeof document > "u") return;
699
+ const c = new Blob(["\uFEFF", r], { type: "text/csv;charset=utf-8" }), a = URL.createObjectURL(c), g = document.createElement("a");
700
+ g.href = a, g.download = n, g.style.display = "none", document.body.appendChild(g), g.click(), g.remove(), setTimeout(() => URL.revokeObjectURL(a), 1e3);
701
+ }
702
+ const zt = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]), Wr = (r, n) => Object.prototype.hasOwnProperty.call(r, n);
703
+ function te(r, n) {
704
+ if (r === null || typeof r != "object") return;
705
+ if (Wr(r, n)) return r[n];
706
+ let c = r;
707
+ for (const a of n.split(".")) {
708
+ if (c == null || typeof c != "object" || zt.has(a)) return;
709
+ c = c[a];
211
710
  }
212
711
  return c;
213
712
  }
214
- function Je(o, s, c) {
215
- if (Array.isArray(o)) {
216
- const h = [...o];
217
- return h[s] = c, h;
713
+ function Pr(r, n, c) {
714
+ if (Array.isArray(r)) {
715
+ const a = [...r];
716
+ return a[n] = c, a;
717
+ }
718
+ return { ...r, [n]: c };
719
+ }
720
+ function Ht(r, n, c) {
721
+ const a = r ?? {};
722
+ if (Wr(a, n) || !n.includes("."))
723
+ return zt.has(n) ? r : Pr(a, n, c);
724
+ const [g, ...f] = n.split(".");
725
+ if (zt.has(g)) return r;
726
+ const u = a[g];
727
+ return Pr(a, g, Ht(u !== null && typeof u == "object" ? u : {}, f.join("."), c));
728
+ }
729
+ const be = 38, oo = 150, Ar = 10, Vt = (r, n) => `${typeof r}:${r}\0${n}`;
730
+ function We(r, n) {
731
+ const c = te(n, r.field);
732
+ return r.valueFormatter ? r.valueFormatter(c, n) : r.type === "boolean" && typeof c == "boolean" ? c ? "Yes" : "No" : r.type === "date" ? Wn(c, r.dateLocale, r.dateFormat) : c == null ? "" : c instanceof Date ? c.toLocaleDateString() : String(c);
733
+ }
734
+ function io(r, n, c) {
735
+ if (c.type === "date") {
736
+ const a = Z(r) ?? "", g = Z(n) ?? "";
737
+ return a < g ? -1 : a > g ? 1 : 0;
218
738
  }
219
- return { ...o, [s]: c };
220
- }
221
- function De(o, s, c) {
222
- const h = o ?? {};
223
- if (Ye(h, s) || !s.includes("."))
224
- return Se.has(s) ? o : Je(h, s, c);
225
- const [I, ...b] = s.split(".");
226
- if (Se.has(I)) return o;
227
- const m = h[I];
228
- return Je(h, I, De(m !== null && typeof m == "object" ? m : {}, b.join("."), c));
229
- }
230
- const D = (...o) => o.filter(Boolean).join(" "), Ue = (o, s) => `${typeof o}:${o}\0${s}`, Ie = (o) => o.headerName ?? (o.type === "boolean" ? "" : o.field), be = (o) => Ie(o) || o.field;
231
- function Ce(o, s) {
232
- const c = z(s, o.field);
233
- return o.valueFormatter ? o.valueFormatter(c, s) : o.type === "boolean" && typeof c == "boolean" ? c ? "Yes" : "No" : c == null ? "" : c instanceof Date ? c.toLocaleDateString() : String(c);
234
- }
235
- function wt(o, s) {
236
- return typeof o == "number" && typeof s == "number" ? o - s : o instanceof Date && s instanceof Date ? o.getTime() - s.getTime() : typeof o == "boolean" && typeof s == "boolean" ? Number(o) - Number(s) : String(o).localeCompare(String(s), void 0, { numeric: !0, sensitivity: "base" });
237
- }
238
- function St({
239
- columns: o,
240
- rows: s,
739
+ return typeof r == "number" && typeof n == "number" ? r - n : r instanceof Date && n instanceof Date ? r.getTime() - n.getTime() : typeof r == "boolean" && typeof n == "boolean" ? Number(r) - Number(n) : String(r).localeCompare(String(n), void 0, { numeric: !0, sensitivity: "base" });
740
+ }
741
+ const lo = (r) => r ? Array.isArray(r) ? r : [r] : [], Or = (r) => r.type === "date" && r.validity.badInput;
742
+ function fo({
743
+ columns: r,
744
+ rows: n,
241
745
  getRowId: c,
242
- editable: h = !1,
243
- enterMovesDown: I = !0,
244
- onCellEdit: b,
245
- onRowsChange: m,
246
- sortable: O = !0,
247
- defaultSort: H = null,
248
- onSortChange: B,
249
- searchable: G = !0,
250
- searchPlaceholder: w = "Search…",
251
- pagination: k = !0,
252
- paginationPosition: E = "bottom",
253
- pageSize: F = 10,
254
- pageSizeOptions: y = [5, 10, 25, 50],
255
- onRowClick: R,
256
- toolbar: q,
257
- emptyMessage: L = "No rows to show",
258
- striped: _e = !1,
259
- stripeColors: g,
260
- checkboxVariant: K = "native",
261
- animateRows: A = !0,
262
- theme: T,
263
- maxHeight: j,
264
- className: de,
265
- style: He,
266
- classNames: N = {},
267
- styles: x = {},
268
- rowClassName: me,
269
- rowStyle: ve
746
+ editable: a = !1,
747
+ enterMovesDown: g = !0,
748
+ onCellEdit: f,
749
+ onRowsChange: u,
750
+ rowSelection: k = !1,
751
+ selectedRowIds: y,
752
+ defaultSelectedRowIds: E,
753
+ onSelectionChange: T,
754
+ isRowSelectable: w,
755
+ sort: v,
756
+ defaultSort: _ = null,
757
+ onSortChange: C,
758
+ multiSort: P = !1,
759
+ searchable: F = !1,
760
+ searchPlaceholder: N = "Search…",
761
+ search: S,
762
+ onSearchChange: re,
763
+ filters: ue,
764
+ onFiltersChange: X,
765
+ pagination: V = !1,
766
+ paginationPosition: ce = "bottom",
767
+ pageSize: qe = 10,
768
+ pageSizeOptions: Se = [5, 10, 25, 50],
769
+ page: yt,
770
+ onPageChange: vt,
771
+ onPageSizeChange: ne,
772
+ serverSide: W = !1,
773
+ rowCount: Ve,
774
+ onQueryChange: b,
775
+ queryDebounce: j = 250,
776
+ filterDebounce: I = 300,
777
+ loading: K,
778
+ loadingRows: le,
779
+ skeletonRow: fe,
780
+ errorMessage: xt = "Could not load the data.",
781
+ columnMenu: Ue = !1,
782
+ onColumnVisibilityChange: kt,
783
+ keyboardNavigation: wt = !1,
784
+ virtualize: oe = !1,
785
+ rowHeight: de = 40,
786
+ overscan: Xt = 6,
787
+ exportable: ze = !1,
788
+ apiRef: Ie,
789
+ onRowClick: Dt,
790
+ toolbar: Gt,
791
+ emptyMessage: jr = "No rows to show",
792
+ striped: qr = !1,
793
+ stripeColors: He,
794
+ checkboxVariant: Nt = "native",
795
+ animateRows: Qt = !0,
796
+ rowAnimationClassName: Mt,
797
+ theme: Je,
798
+ maxHeight: Xe,
799
+ className: Vr,
800
+ style: Ur,
801
+ classNames: B = {},
802
+ styles: L = {},
803
+ rowClassName: Ct,
804
+ rowStyle: Et
270
805
  }) {
271
- const _ = (e, t) => ({
272
- className: D(t, N[e]),
273
- style: x[e]
274
- }), [Pe, $e] = V(s), Q = W(s);
275
- ae(() => {
276
- Q.current = s, $e(s);
277
- }, [s]);
278
- const Le = (e) => {
279
- Q.current = e, $e(e);
280
- }, [X, Qe] = V(""), [Z, Xe] = V({}), [v, Ze] = V(H), [et, ee] = V(0), [P, tt] = V(F), [te, re] = V(null), J = W(0), ce = W(null), ye = W(/* @__PURE__ */ new Map()), Te = qe(
281
- () => Pe.map((e, t) => ({ row: e, index: t, id: c ? c(e, t) : t })),
282
- [Pe, c]
283
- ), ne = qe(() => {
284
- const e = X.trim().toLowerCase(), t = Object.entries(Z).filter(
285
- ([n, i]) => i.trim() !== "" && o.some((l) => l.field === n && l.filterable)
286
- );
287
- let r = Te.filter(({ row: n }) => e && !o.some((l) => Ce(l, n).toLowerCase().includes(e)) ? !1 : t.every(([i, l]) => {
288
- const f = o.find((a) => a.field === i);
289
- return f ? Ce(f, n).toLowerCase().includes(l.trim().toLowerCase()) : !0;
806
+ const q = (e, t) => ({
807
+ className: O(t, B[e]),
808
+ style: L[e]
809
+ }), [Ge, Zt] = R(n), we = $(n);
810
+ U(() => {
811
+ we.current = n, Zt(n);
812
+ }, [n]);
813
+ const er = (e) => {
814
+ we.current = e, Zt(e);
815
+ }, [Le, zr] = Ye(S, "", re), [De, Hr] = Ye(ue, {}, X), [G, Jr] = Ye(v, lo(_), C), [Tt, Ne] = Ye(yt, 0, vt), [z, Xr] = R(qe), Gr = (e) => {
816
+ Xr(e), ne == null || ne(e);
817
+ }, [Qe, Qr] = R(() => new Set(r.filter((e) => e.hidden).map((e) => e.field))), Zr = (e, t) => {
818
+ const o = new Set(Qe);
819
+ t ? o.add(e) : o.delete(e), Qr(o), kt == null || kt([...o]);
820
+ }, [Ft, tr] = R({}), [Ze, en] = R({}), [so, tn] = R(0), $e = $(/* @__PURE__ */ new Map()), [Pe, ye] = R(null), ge = $(0), et = $(null), tt = $(/* @__PURE__ */ new Map()), [St, rr] = R(null), It = $(null), Ae = $(null), [Lt, nr] = R({ top: 0, height: 0 }), M = ae(() => {
821
+ const e = r.filter((t) => !Qe.has(t.field)).map((t) => t.type === "sequence" ? { ...t, sortable: !1, filterable: !1, editable: !1, filterRenderer: void 0 } : t);
822
+ return [
823
+ ...e.filter((t) => t.pinned === "left"),
824
+ ...e.filter((t) => t.pinned !== "left" && t.pinned !== "right"),
825
+ ...e.filter((t) => t.pinned === "right")
826
+ ];
827
+ }, [r, Qe]), $t = (e) => e.sortable === !0, Q = k === "single" ? "single" : k ? "multiple" : null, Oe = M.length + (Q ? 1 : 0), Me = ae(
828
+ () => Ge.map((e, t) => ({ row: e, index: t, id: c ? c(e, t) : t })),
829
+ [Ge, c]
830
+ ), or = $(/* @__PURE__ */ new Map());
831
+ Me.forEach((e) => or.current.set(e.id, e.row));
832
+ const rt = ae(
833
+ () => Object.entries(De).filter(([e, t]) => {
834
+ const o = M.find((s) => s.field === e);
835
+ return !!o && !!o.filterable && Br(t);
836
+ }),
837
+ [De, M]
838
+ ), [rn, nn] = R(Le);
839
+ U(() => {
840
+ if (!W) return;
841
+ const e = setTimeout(() => nn(Le), j);
842
+ return () => clearTimeout(e);
843
+ }, [Le, W, j]);
844
+ const Ce = W ? rn : Le, ir = (e) => e.filterRenderer ? "text" : Lr(e), he = ae(() => {
845
+ if (W) return Me;
846
+ const e = Ce.trim().toLowerCase();
847
+ let t = Me.filter(({ row: s }) => e && !M.some((i) => We(i, s).toLowerCase().includes(e)) ? !1 : rt.every(([i, l]) => {
848
+ const m = M.find((p) => p.field === i);
849
+ return Un(ir(m), l, We(m, s), te(s, i));
290
850
  }));
291
- if (v) {
292
- const n = o.find((i) => i.field === v.field);
293
- if (n) {
294
- const i = v.direction === "asc" ? 1 : -1;
295
- r = [...r].sort((l, f) => {
296
- const a = z(l.row, n.field), u = z(f.row, n.field), p = a == null || a === "", C = u == null || u === "";
297
- return p || C ? p === C ? 0 : p ? 1 : -1 : (n.comparator ? n.comparator(a, u, l.row, f.row) : wt(a, u)) * i;
298
- });
851
+ const o = G.map((s) => ({ col: M.find((i) => i.field === s.field), dir: s.direction === "asc" ? 1 : -1 })).filter((s) => !!s.col);
852
+ return o.length && (t = [...t].sort((s, i) => {
853
+ for (const { col: l, dir: m } of o) {
854
+ const p = te(s.row, l.field), x = te(i.row, l.field), h = p == null || p === "", Y = x == null || x === "";
855
+ if (h || Y) {
856
+ if (h !== Y) return h ? 1 : -1;
857
+ continue;
858
+ }
859
+ const ee = l.comparator ? l.comparator(p, x, s.row, i.row) : io(p, x, l);
860
+ if (ee !== 0) return ee * m;
299
861
  }
300
- }
301
- return r;
302
- }, [Te, o, X, Z, v]);
303
- ae(() => ee(0), [X, Z, v, P]);
304
- const Be = W(null), U = ne.length, oe = k ? Math.max(1, Math.ceil(U / P)) : 1, S = Math.min(et, oe - 1), M = k ? ne.slice(S * P, S * P + P) : ne, rt = U === 0 ? 0 : k ? S * P + 1 : 1, nt = k ? Math.min(U, (S + 1) * P) : U, Fe = (e) => e.sortable ?? O, Ke = `${S}|${P}|${v ? `${v.field}:${v.direction}` : ""}|${X}|${JSON.stringify(Z)}`, Me = W(!0);
305
- ae(() => {
306
- if (Me.current) {
307
- Me.current = !1;
862
+ return 0;
863
+ })), t;
864
+ }, [Me, M, Ce, rt, G, W]), nt = JSON.stringify([Ce, De, G, z]), lr = $(nt);
865
+ U(() => {
866
+ lr.current !== nt && (lr.current = nt, Ne(0));
867
+ }, [nt]);
868
+ const Ee = W ? Ve ?? Me.length : he.length, pe = V ? Math.max(1, Math.ceil(Ee / z)) : 1, H = Math.min(Tt, pe - 1), A = V && !W ? he.slice(H * z, H * z + z) : he, on = Ee === 0 ? 0 : V ? H * z + 1 : 1, ln = V ? Math.min(Ee, (H + 1) * z) : Ee, Pt = ae(
869
+ () => ({
870
+ sort: G.filter((e) => {
871
+ const t = r.find((o) => o.field === e.field);
872
+ return !!t && $t(t);
873
+ }),
874
+ filters: Object.fromEntries(rt),
875
+ search: Ce.trim(),
876
+ page: H,
877
+ pageSize: z
878
+ }),
879
+ // eslint-disable-next-line react-hooks/exhaustive-deps
880
+ [G, r, rt, Ce, H, z]
881
+ ), sn = JSON.stringify(Pt), ot = $(Pt);
882
+ ot.current = Pt;
883
+ const it = $(b);
884
+ it.current = b;
885
+ const [an, lt] = R(!1), [cn, At] = R(!1), Ot = $(0), st = _e((e) => {
886
+ var s;
887
+ const t = ++Ot.current, o = (s = it.current) == null ? void 0 : s.call(it, e);
888
+ o && typeof o.then == "function" ? (lt(!0), At(!1), o.then(
889
+ () => {
890
+ t === Ot.current && lt(!1);
891
+ },
892
+ () => {
893
+ t === Ot.current && (lt(!1), At(!0));
894
+ }
895
+ )) : (lt(!1), At(!1));
896
+ }, []);
897
+ U(() => {
898
+ W && st(ot.current);
899
+ }, [W, sn, st]), U(() => {
900
+ W && V && Tt > pe - 1 && Ne(pe - 1);
901
+ }, [W, V, Tt, pe]);
902
+ const Kt = K ?? an, sr = (e) => e.map((t) => or.current.get(t)).filter((t) => t !== void 0), [se, at] = Ye(
903
+ y,
904
+ E ?? [],
905
+ (e) => T == null ? void 0 : T({ ids: e, rows: sr(e) })
906
+ ), Rt = ae(() => new Set(se), [se]), ct = (e) => w ? w(e) : !0, dt = $(null), ar = $(!1), dn = (e, t) => {
907
+ if (!Q || !ct(e.row)) return;
908
+ if (Q === "single") {
909
+ at(t ? [e.id] : []), dt.current = e.id;
308
910
  return;
309
911
  }
310
- const e = Be.current;
311
- e && typeof e.scrollTo == "function" && e.scrollTop > 0 && e.scrollTo({ top: 0, behavior: "smooth" });
312
- }, [Ke]);
313
- const ue = (e, t, r) => ({
314
- value: z(t, e.field),
315
- formattedValue: Ce(e, t),
912
+ const o = new Set(se), s = ar.current && dt.current !== null ? A.findIndex((l) => l.id === dt.current) : -1, i = A.findIndex((l) => l.id === e.id);
913
+ if (s >= 0 && i >= 0)
914
+ for (let l = Math.min(s, i); l <= Math.max(s, i); l++)
915
+ ct(A[l].row) && (t ? o.add(A[l].id) : o.delete(A[l].id));
916
+ else t ? o.add(e.id) : o.delete(e.id);
917
+ dt.current = e.id, at([...o]);
918
+ }, Ke = ae(() => he.filter((e) => ct(e.row)), [he, w]), cr = Ke.filter((e) => Rt.has(e.id)).length, dr = Ke.length > 0 && cr === Ke.length, ur = (e) => {
919
+ const t = new Set(se);
920
+ Ke.forEach((o) => e ? t.add(o.id) : t.delete(o.id)), at([...t]);
921
+ }, ut = (e, t, o) => ({
922
+ value: te(t, e.field),
923
+ formattedValue: We(e, t),
316
924
  row: t,
317
- rowIndex: r,
925
+ rowIndex: o,
318
926
  field: e.field,
319
927
  column: e
320
- }), xe = (e, t) => {
321
- const r = e.editable ?? h;
322
- return typeof r == "function" ? r(t) : !!r;
323
- }, fe = (e, t) => xe(e, t) && !(e.type === "boolean" && !e.cellEditor), ot = (e, t) => {
324
- const r = ue(e, t.row, t.index), n = xe(e, r);
928
+ }), Bt = (e, t) => {
929
+ const o = e.editable ?? a;
930
+ return typeof o == "function" ? o(t) : !!o;
931
+ }, ft = (e, t) => Bt(e, t) && !(e.type === "boolean" && !e.cellEditor), un = (e, t) => {
932
+ const o = ut(e, t.row, t.index), s = Bt(e, o);
325
933
  return {
326
- ...r,
327
- editable: n,
328
- updateValue: (i) => n && Ae(t, e, { value: i })
934
+ ...o,
935
+ editable: s,
936
+ updateValue: (i) => s && gr(t, e, { value: i })
329
937
  };
330
- }, Ve = (e) => {
331
- if (!Fe(e)) return;
332
- let t;
333
- !v || v.field !== e.field ? t = { field: e.field, direction: "asc" } : v.direction === "asc" ? t = { field: e.field, direction: "desc" } : t = null, Ze(t), B == null || B(t);
334
- }, pe = (e, t) => {
335
- var r;
336
- return (r = ye.current.get(Ue(e, t))) == null ? void 0 : r.focus();
337
- }, Y = () => {
338
- J.current += 1, re(null);
339
- }, he = (e, t, r = {}) => {
340
- if (!fe(t, ue(t, e.row, e.index))) return !1;
341
- const n = z(e.row, t.field), i = t.cellEditor ? n : r.text ?? (n == null ? "" : String(n));
342
- return ce.current = i, J.current += 1, re({
938
+ }, fr = (e, t) => {
939
+ if (!$t(e)) return;
940
+ const o = G.find((l) => l.field === e.field), s = o ? o.direction === "asc" ? "desc" : null : "asc";
941
+ let i;
942
+ t && P ? s ? o ? i = G.map((l) => l.field === e.field ? { ...l, direction: s } : l) : i = [...G, { field: e.field, direction: s }] : i = G.filter((l) => l.field !== e.field) : i = s ? [{ field: e.field, direction: s }] : [], Jr(i);
943
+ }, gt = (e, t) => {
944
+ var o;
945
+ return (o = tt.current.get(Vt(e, t))) == null ? void 0 : o.focus();
946
+ }, me = () => {
947
+ ge.current += 1, ye(null);
948
+ }, fn = (e) => {
949
+ for (const t of we.current) {
950
+ const o = te(t, e.field);
951
+ if (o != null && o !== "") return o;
952
+ }
953
+ }, ht = (e, t, o = {}) => {
954
+ if (!ft(t, ut(t, e.row, e.index))) return !1;
955
+ const s = te(e.row, t.field);
956
+ let i;
957
+ return t.cellEditor ? i = s : t.type === "date" ? i = Z(s) ?? "" : i = o.text ?? (s == null ? "" : String(s)), et.current = i, ge.current += 1, ye({
343
958
  id: e.id,
344
959
  field: t.field,
345
960
  draft: i,
346
- session: J.current,
347
- select: r.select ?? "end",
961
+ session: ge.current,
962
+ select: o.select ?? "end",
348
963
  invalid: !1
349
964
  }), !0;
350
- }, Ae = (e, t, r) => {
351
- const n = Q.current[e.index] ?? e.row, i = z(n, t.field);
965
+ }, gr = (e, t, o) => {
966
+ const s = we.current[e.index] ?? e.row, i = te(s, t.field);
352
967
  let l;
353
- if ("value" in r)
354
- l = r.value;
968
+ if ("value" in o)
969
+ l = o.value;
355
970
  else if (t.valueParser)
356
- l = t.valueParser(r.text, n);
357
- else if (t.type === "number")
358
- if (r.text.trim() === "") l = null;
971
+ l = t.valueParser(o.text, s);
972
+ else if (t.type === "date") {
973
+ if (o.text !== "" && !J(o.text)) return !1;
974
+ l = jn(o.text, i ?? fn(t));
975
+ } else if (t.type === "number")
976
+ if (o.text.trim() === "") l = null;
359
977
  else {
360
- const u = Number(r.text);
361
- if (!Number.isFinite(u)) return !1;
362
- l = u;
978
+ const x = Number(o.text);
979
+ if (!Number.isFinite(x)) return !1;
980
+ l = x;
363
981
  }
364
982
  else
365
- l = r.text;
366
- if (Object.is(l, i)) return !0;
367
- if (t.validate && !t.validate(l, n)) return !1;
368
- const f = De(n, t.field, l), a = Q.current.map((u, p) => p === e.index ? f : u);
369
- return Le(a), b == null || b({ rowId: e.id, rowIndex: e.index, field: t.field, oldValue: i, newValue: l, row: f }), m == null || m(a), !0;
370
- }, je = (e, t, r) => {
371
- const n = M.findIndex((p) => p.id === e.id), i = o.findIndex((p) => p.field === t);
372
- if (n < 0 || i < 0) return null;
373
- const l = (p, C) => fe(C, ue(C, p.row, p.index));
374
- if (r === "down" || r === "up") {
375
- const p = r === "down" ? 1 : -1;
376
- for (let C = n + p; C >= 0 && C < M.length; C += p)
377
- if (l(M[C], o[i])) return { entry: M[C], col: o[i] };
983
+ l = o.text;
984
+ if (t.type === "date") {
985
+ if (Z(l) === Z(i)) return !0;
986
+ const x = Z(l);
987
+ if (x && (t.dateMin && x < t.dateMin || t.dateMax && x > t.dateMax)) return !1;
988
+ } else if (Object.is(l, i))
989
+ return !0;
990
+ if (t.validate && !t.validate(l, s)) return !1;
991
+ const m = Ht(s, t.field, l), p = we.current.map((x, h) => h === e.index ? m : x);
992
+ return er(p), f == null || f({ rowId: e.id, rowIndex: e.index, field: t.field, oldValue: i, newValue: l, row: m }), u == null || u(p), !0;
993
+ }, hr = (e, t, o) => {
994
+ const s = A.findIndex((h) => h.id === e.id), i = M.findIndex((h) => h.field === t);
995
+ if (s < 0 || i < 0) return null;
996
+ const l = (h, Y) => ft(Y, ut(Y, h.row, h.index));
997
+ if (o === "down" || o === "up") {
998
+ const h = o === "down" ? 1 : -1;
999
+ for (let Y = s + h; Y >= 0 && Y < A.length; Y += h)
1000
+ if (l(A[Y], M[i])) return { entry: A[Y], col: M[i] };
378
1001
  return null;
379
1002
  }
380
- const f = r === "right" ? 1 : -1;
381
- let a = n, u = i + f;
382
- for (; a >= 0 && a < M.length; ) {
383
- for (; u >= 0 && u < o.length; ) {
384
- if (l(M[a], o[u])) return { entry: M[a], col: o[u] };
385
- u += f;
1003
+ const m = o === "right" ? 1 : -1;
1004
+ let p = s, x = i + m;
1005
+ for (; p >= 0 && p < A.length; ) {
1006
+ for (; x >= 0 && x < M.length; ) {
1007
+ if (l(A[p], M[x])) return { entry: A[p], col: M[x] };
1008
+ x += m;
386
1009
  }
387
- a += f, u = f > 0 ? 0 : o.length - 1;
1010
+ p += m, x = m > 0 ? 0 : M.length - 1;
388
1011
  }
389
1012
  return null;
390
- }, ie = (e, t, r, n = {}) => {
391
- const { move: i = "none", focus: l = !0 } = n;
392
- if (!Ae(e, t, r))
393
- return re((a) => a && { ...a, invalid: !0 }), !1;
394
- const f = i === "none" ? null : je(e, t.field, i);
395
- return f ? he(f.entry, f.col, { select: "all" }) : (Y(), l && pe(e.id, t.field)), !0;
396
- }, it = (e, t, r) => {
1013
+ }, ve = (e, t, o, s = {}) => {
1014
+ const { move: i = "none", focus: l = !0 } = s;
1015
+ if (!gr(e, t, o))
1016
+ return ye((p) => p && { ...p, invalid: !0 }), !1;
1017
+ const m = i === "none" ? null : hr(e, t.field, i);
1018
+ return m ? ht(m.entry, m.col, { select: "all" }) : (me(), l && gt(e.id, t.field)), !0;
1019
+ }, pr = (e, t, o) => {
397
1020
  if (e.nativeEvent.isComposing) return;
398
- const n = e.currentTarget.value;
1021
+ const s = e.currentTarget.value, i = Or(e.currentTarget);
399
1022
  if (e.key === "Enter") {
400
- e.preventDefault();
401
- const i = I ? e.shiftKey ? "up" : "down" : "none";
402
- ie(t, r, { text: n }, { move: i });
1023
+ if (e.preventDefault(), i) return ye((m) => m && { ...m, invalid: !0 });
1024
+ const l = g ? e.shiftKey ? "up" : "down" : "none";
1025
+ ve(t, o, { text: s }, { move: l });
403
1026
  } else if (e.key === "Escape")
404
- e.preventDefault(), Y(), pe(t.id, r.field);
405
- else if (e.key === "Tab") {
406
- const i = e.shiftKey ? "left" : "right";
407
- je(t, r.field, i) && (e.preventDefault(), ie(t, r, { text: n }, { move: i }));
1027
+ e.preventDefault(), me(), gt(t.id, o.field);
1028
+ else if (e.key === "Tab" && !i) {
1029
+ const l = e.shiftKey ? "left" : "right";
1030
+ hr(t, o.field, l) && (e.preventDefault(), ve(t, o, { text: s }, { move: l }));
408
1031
  }
409
- }, lt = (e, t, r, n) => {
410
- e.target !== e.currentTarget || !fe(r, n) || (e.key === "Enter" || e.key === "F2" ? (e.preventDefault(), he(t, r)) : !r.cellEditor && e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey && (e.preventDefault(), he(t, r, { text: e.key })));
411
- }, at = (e, t, r) => t.cellEditor ? /* @__PURE__ */ d(
412
- "div",
413
- {
414
- className: "rk-grid__custom-editor",
415
- onBlur: (n) => {
416
- n.currentTarget.contains(n.relatedTarget) || r.session === J.current && (ie(e, t, { value: ce.current }, { focus: !1 }) || Y());
417
- },
418
- onKeyDown: (n) => {
419
- n.key === "Escape" && (n.preventDefault(), n.stopPropagation(), Y(), pe(e.id, t.field));
420
- },
421
- children: se(t.cellEditor, {
422
- value: r.draft,
423
- row: e.row,
424
- rowIndex: e.index,
425
- field: t.field,
426
- column: t,
427
- onChange: (n) => {
428
- ce.current = n, re((i) => i && i.session === r.session ? { ...i, draft: n, invalid: !1 } : i);
429
- },
430
- onCommit: (n, i = "none") => {
431
- r.session === J.current && ie(e, t, { value: n === void 0 ? ce.current : n }, { move: i });
432
- },
433
- onCancel: () => {
434
- Y(), pe(e.id, t.field);
435
- }
436
- })
1032
+ }, gn = (e, t) => {
1033
+ var l;
1034
+ const o = A[e], s = M[t];
1035
+ if (!o || !s) return;
1036
+ rr({ id: o.id, field: s.field }), It.current = Vt(o.id, s.field);
1037
+ const i = Ae.current;
1038
+ if (oe && i) {
1039
+ const m = ((l = i.querySelector("thead")) == null ? void 0 : l.clientHeight) ?? 0, p = e * de;
1040
+ p < i.scrollTop ? i.scrollTo({ top: p, behavior: "auto" }) : p + de > i.scrollTop + i.clientHeight - m && i.scrollTo({ top: p + de - i.clientHeight + m, behavior: "auto" });
437
1041
  }
438
- ) : /* @__PURE__ */ d(
439
- "input",
440
- {
441
- autoFocus: !0,
442
- className: D("rk-grid__editor", r.invalid && "rk-grid__editor--invalid", N.editor),
443
- style: { textAlign: t.align, ...x.editor },
444
- value: r.draft === null || r.draft === void 0 ? "" : String(r.draft),
445
- inputMode: t.type === "number" ? "decimal" : void 0,
446
- "aria-label": `Edit ${be(t)}`,
447
- "aria-invalid": r.invalid || void 0,
448
- onChange: (n) => {
449
- const i = n.target.value;
450
- re((l) => l && { ...l, draft: i, invalid: !1 });
451
- },
452
- onFocus: (n) => {
453
- const i = n.currentTarget;
454
- r.select === "all" ? i.select() : i.setSelectionRange(i.value.length, i.value.length);
455
- },
456
- onBlur: (n) => {
457
- r.session === J.current && (ie(e, t, { text: n.currentTarget.value }, { focus: !1 }) || Y());
458
- },
459
- onKeyDown: (n) => it(n, e, t)
1042
+ };
1043
+ U(() => {
1044
+ const e = It.current;
1045
+ if (!e) return;
1046
+ const t = tt.current.get(e);
1047
+ t && (It.current = null, t.focus());
1048
+ });
1049
+ const hn = (e, t, o) => {
1050
+ if (!wt) return !1;
1051
+ let s = A.findIndex((l) => l.id === t.id), i = M.findIndex((l) => l.field === o.field);
1052
+ if (s < 0 || i < 0) return !1;
1053
+ switch (e.key) {
1054
+ case "ArrowDown":
1055
+ s += 1;
1056
+ break;
1057
+ case "ArrowUp":
1058
+ s -= 1;
1059
+ break;
1060
+ case "ArrowRight":
1061
+ i += 1;
1062
+ break;
1063
+ case "ArrowLeft":
1064
+ i -= 1;
1065
+ break;
1066
+ case "PageDown":
1067
+ s += Ar;
1068
+ break;
1069
+ case "PageUp":
1070
+ s -= Ar;
1071
+ break;
1072
+ case "Home":
1073
+ i = 0, (e.ctrlKey || e.metaKey) && (s = 0);
1074
+ break;
1075
+ case "End":
1076
+ i = M.length - 1, (e.ctrlKey || e.metaKey) && (s = A.length - 1);
1077
+ break;
1078
+ default:
1079
+ return !1;
460
1080
  }
461
- ), ze = (e) => {
462
- var r, n, i, l, f, a, u, p;
1081
+ return e.preventDefault(), gn(Math.max(0, Math.min(A.length - 1, s)), Math.max(0, Math.min(M.length - 1, i))), !0;
1082
+ }, pn = (e, t, o, s) => {
1083
+ e.target === e.currentTarget && (hn(e, t, o) || ft(o, s) && (e.key === "Enter" || e.key === "F2" ? (e.preventDefault(), ht(t, o)) : !o.cellEditor && o.type !== "date" && e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey && (e.preventDefault(), ht(t, o, { text: e.key }))));
1084
+ };
1085
+ Ut(() => {
1086
+ if (!oe || !Ae.current) return;
1087
+ const e = Ae.current, t = () => nr((s) => s.height === e.clientHeight ? s : { ...s, height: e.clientHeight });
1088
+ if (t(), typeof ResizeObserver > "u") return;
1089
+ const o = new ResizeObserver(t);
1090
+ return o.observe(e), () => o.disconnect();
1091
+ }, [oe]);
1092
+ const Re = oe && !Kt && A.length > 0, mn = Lt.height || (typeof Xe == "number" ? Xe : 400), pt = Re ? Math.max(0, Math.floor(Lt.top / de) - Xt) : 0, Yt = Re ? Math.min(A.length, Math.ceil((Lt.top + mn) / de) + Xt) : A.length, bn = Re ? A.slice(pt, Yt) : A, mr = `${H}|${z}|${JSON.stringify(G)}|${Ce}|${JSON.stringify(De)}`, br = $(!0);
1093
+ U(() => {
1094
+ if (br.current) {
1095
+ br.current = !1;
1096
+ return;
1097
+ }
1098
+ const e = Ae.current;
1099
+ e && typeof e.scrollTo == "function" && e.scrollTop > 0 && e.scrollTo({ top: 0, behavior: "smooth" });
1100
+ }, [mr]);
1101
+ const Wt = Object.keys(Ft).length > 0, mt = (e) => Ft[e.field] ?? (typeof e.width == "number" ? e.width : oo), _n = (e) => Math.max(40, typeof e.minWidth == "number" ? e.minWidth : 60), yn = (e, t) => {
1102
+ e.preventDefault(), e.stopPropagation();
1103
+ const o = { ...Ft };
1104
+ Wt || M.forEach((h) => {
1105
+ var Y;
1106
+ return o[h.field] = ((Y = $e.current.get(h.field)) == null ? void 0 : Y.offsetWidth) ?? mt(h);
1107
+ });
1108
+ const s = e.clientX, i = o[t.field] ?? mt(t), l = e.currentTarget;
1109
+ l.setPointerCapture(e.pointerId), tr(o);
1110
+ const m = (h) => Math.min(t.maxWidth ?? 1 / 0, Math.max(_n(t), Math.round(h))), p = (h) => tr((Y) => ({ ...Y, [t.field]: m(i + h.clientX - s) })), x = () => {
1111
+ l.removeEventListener("pointermove", p), l.removeEventListener("pointerup", x), l.removeEventListener("pointercancel", x);
1112
+ };
1113
+ l.addEventListener("pointermove", p), l.addEventListener("pointerup", x), l.addEventListener("pointercancel", x);
1114
+ };
1115
+ Ut(() => {
1116
+ var i, l;
1117
+ const e = {};
1118
+ let t = Q && M.some((m) => m.pinned === "left") ? be : 0;
1119
+ for (const m of M)
1120
+ m.pinned === "left" && (e[m.field] = t, t += ((i = $e.current.get(m.field)) == null ? void 0 : i.offsetWidth) ?? 0);
1121
+ let o = 0;
1122
+ for (const m of [...M].reverse())
1123
+ m.pinned === "right" && (e[m.field] = o, o += ((l = $e.current.get(m.field)) == null ? void 0 : l.offsetWidth) ?? 0);
1124
+ const s = Object.keys(e);
1125
+ (s.length !== Object.keys(Ze).length || s.some((m) => e[m] !== Ze[m])) && en(e);
1126
+ }), U(() => {
1127
+ const e = () => tn((t) => t + 1);
1128
+ return window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
1129
+ }, []);
1130
+ const _r = M.map((e) => e.pinned).lastIndexOf("left"), vn = M.findIndex((e) => e.pinned === "right"), bt = _r >= 0, yr = (e, t) => ({
1131
+ className: e.pinned ? O("rg-grid__pinned", `rg-grid__pinned--${e.pinned}`, t === _r && "rg-grid__pinned--edge", t === vn && "rg-grid__pinned--edge") : void 0,
1132
+ style: e.pinned === "left" ? { left: Ze[e.field] ?? 0 } : e.pinned === "right" ? { right: Ze[e.field] ?? 0 } : void 0
1133
+ }), vr = typeof ze == "object" ? ze : {}, xr = (e = {}) => {
1134
+ const t = { ...vr, ...e }, o = t.scope ?? "filtered", s = o === "page" ? A : o === "selected" ? Me.filter((p) => Rt.has(p.id)) : he, i = t.includeHidden ? r : M, l = i.map((p) => _t(p) || p.field), m = s.map(
1135
+ ({ row: p }, x) => i.map((h) => {
1136
+ if (h.type === "sequence") return Mr(h, x, o === "page" && V && !h.sequenceRestartEachPage ? H * z : 0);
1137
+ const Y = te(p, h.field);
1138
+ return h.exportValue ? h.exportValue(Y, p) : h.type === "date" ? Z(Y) ?? "" : We(h, p);
1139
+ })
1140
+ );
1141
+ return ro(l, m, { sanitize: t.sanitize });
1142
+ }, kr = (e = {}) => {
1143
+ const t = { ...vr, ...e };
1144
+ no(xr(e), `${t.filename ?? "export"}.csv`);
1145
+ };
1146
+ U(() => {
1147
+ Ie && (Ie.current = {
1148
+ getCsv: xr,
1149
+ exportCsv: kr,
1150
+ getSelectedRows: () => sr(se),
1151
+ getSelectedRowIds: () => se,
1152
+ selectAll: () => ur(!0),
1153
+ clearSelection: () => at([]),
1154
+ refresh: () => {
1155
+ W && st(ot.current);
1156
+ }
1157
+ });
1158
+ }), U(
1159
+ () => () => {
1160
+ Ie && (Ie.current = null);
1161
+ },
1162
+ [Ie]
1163
+ );
1164
+ const wr = (e) => {
1165
+ var o, s, i, l, m, p, x, h;
463
1166
  const t = e.checkbox ?? {};
464
1167
  return {
465
- variant: t.variant ?? K,
1168
+ variant: t.variant ?? Nt,
466
1169
  indicator: t.indicator,
467
1170
  className: t.className,
468
1171
  style: t.style,
469
1172
  classNames: {
470
- root: D(N.checkbox, (r = t.classNames) == null ? void 0 : r.root),
471
- control: D(N.checkboxControl, (n = t.classNames) == null ? void 0 : n.control),
472
- indicator: D(N.checkboxIndicator, (i = t.classNames) == null ? void 0 : i.indicator),
1173
+ root: O(B.checkbox, (o = t.classNames) == null ? void 0 : o.root),
1174
+ control: O(B.checkboxControl, (s = t.classNames) == null ? void 0 : s.control),
1175
+ indicator: O(B.checkboxIndicator, (i = t.classNames) == null ? void 0 : i.indicator),
473
1176
  label: (l = t.classNames) == null ? void 0 : l.label
474
1177
  },
475
1178
  styles: {
476
- root: { ...x.checkbox, ...(f = t.styles) == null ? void 0 : f.root },
477
- control: { ...x.checkboxControl, ...(a = t.styles) == null ? void 0 : a.control },
478
- indicator: { ...x.checkboxIndicator, ...(u = t.styles) == null ? void 0 : u.indicator },
479
- label: (p = t.styles) == null ? void 0 : p.label
1179
+ root: { ...L.checkbox, ...(m = t.styles) == null ? void 0 : m.root },
1180
+ control: { ...L.checkboxControl, ...(p = t.styles) == null ? void 0 : p.control },
1181
+ indicator: { ...L.checkboxIndicator, ...(x = t.styles) == null ? void 0 : x.indicator },
1182
+ label: (h = t.styles) == null ? void 0 : h.label
480
1183
  }
481
1184
  };
482
- }, ge = (e) => e.stopPropagation(), st = (e, t) => /* @__PURE__ */ d("span", { className: "rk-grid__checkbox-cell", onClick: ge, onDoubleClick: ge, children: /* @__PURE__ */ d(
483
- Ge,
1185
+ }, xe = (e) => e.stopPropagation(), xn = (e, t) => /* @__PURE__ */ d("span", { className: "rg-grid__checkbox-cell", onClick: xe, onDoubleClick: xe, children: /* @__PURE__ */ d(
1186
+ Fe,
484
1187
  {
485
- ...ze(e),
1188
+ ...wr(e),
486
1189
  checked: !!t.value,
487
1190
  disabled: !t.editable,
488
- "aria-label": `Toggle ${be(e)}`,
489
- onChange: (r) => t.updateValue(r)
1191
+ "aria-label": `Toggle ${ke(e)}`,
1192
+ onChange: (o) => t.updateValue(o)
490
1193
  }
491
- ) }), We = (e) => ne.filter((t) => xe(e, ue(e, t.row, t.index))), dt = (e, t) => {
492
- const r = new Map(We(e).map((l) => [l.index, l])), n = [], i = Q.current.map((l, f) => {
493
- const a = r.get(f);
494
- if (!a) return l;
495
- const u = z(l, e.field);
496
- if (!!u === t || e.validate && !e.validate(t, l)) return l;
497
- const p = De(l, e.field, t);
498
- return n.push({ rowId: a.id, rowIndex: f, field: e.field, oldValue: u, newValue: t, row: p }), p;
1194
+ ) }), Dr = (e) => he.filter((t) => Bt(e, ut(e, t.row, t.index))), kn = (e, t) => {
1195
+ const o = new Map(Dr(e).map((l) => [l.index, l])), s = [], i = we.current.map((l, m) => {
1196
+ const p = o.get(m);
1197
+ if (!p) return l;
1198
+ const x = te(l, e.field);
1199
+ if (!!x === t || e.validate && !e.validate(t, l)) return l;
1200
+ const h = Ht(l, e.field, t);
1201
+ return s.push({ rowId: p.id, rowIndex: m, field: e.field, oldValue: x, newValue: t, row: h }), h;
499
1202
  });
500
- n.length !== 0 && (Le(i), n.forEach((l) => b == null ? void 0 : b(l)), m == null || m(i));
501
- }, ct = (e) => {
502
- const t = We(e), r = t.length > 0 ? t : ne, n = r.filter((l) => !!z(l.row, e.field)).length, i = r.length > 0 && n === r.length;
503
- return /* @__PURE__ */ d("span", { className: "rk-grid__header-checkbox", onClick: ge, onDoubleClick: ge, children: /* @__PURE__ */ d(
504
- Ge,
1203
+ s.length !== 0 && (er(i), s.forEach((l) => f == null ? void 0 : f(l)), u == null || u(i));
1204
+ }, wn = (e) => {
1205
+ const t = Dr(e), o = t.length > 0 ? t : he, s = o.filter((l) => !!te(l.row, e.field)).length, i = o.length > 0 && s === o.length;
1206
+ return /* @__PURE__ */ d("span", { className: "rg-grid__header-checkbox", onClick: xe, onDoubleClick: xe, children: /* @__PURE__ */ d(
1207
+ Fe,
505
1208
  {
506
- ...ze(e),
1209
+ ...wr(e),
507
1210
  checked: i,
508
- indeterminate: n > 0 && !i,
1211
+ indeterminate: s > 0 && !i,
509
1212
  disabled: t.length === 0,
510
- label: Ie(e) || void 0,
511
- "aria-label": `Select all ${be(e)}`,
512
- onChange: (l) => dt(e, l)
1213
+ label: _t(e) || void 0,
1214
+ "aria-label": `Select all ${ke(e)}`,
1215
+ onChange: (l) => kn(e, l)
513
1216
  }
514
1217
  ) });
515
- }, ut = _e || !!g, ft = g ? { "--rk-stripe-a": g[0], "--rk-stripe-b": g[1] } : void 0, pt = k && (E === "top" || E === "both"), ht = !k || E === "bottom" || E === "both", Oe = (e) => /* @__PURE__ */ $(
1218
+ }, Dn = (e, t, o) => {
1219
+ if (t.cellEditor)
1220
+ return /* @__PURE__ */ d(
1221
+ "div",
1222
+ {
1223
+ className: "rg-grid__custom-editor",
1224
+ onBlur: (i) => {
1225
+ i.currentTarget.contains(i.relatedTarget) || o.session === ge.current && (ve(e, t, { value: et.current }, { focus: !1 }) || me());
1226
+ },
1227
+ onKeyDown: (i) => {
1228
+ i.key === "Escape" && (i.preventDefault(), i.stopPropagation(), me(), gt(e.id, t.field));
1229
+ },
1230
+ children: Te(t.cellEditor, {
1231
+ value: o.draft,
1232
+ row: e.row,
1233
+ rowIndex: e.index,
1234
+ field: t.field,
1235
+ column: t,
1236
+ onChange: (i) => {
1237
+ et.current = i, ye((l) => l && l.session === o.session ? { ...l, draft: i, invalid: !1 } : l);
1238
+ },
1239
+ onCommit: (i, l = "none") => {
1240
+ o.session === ge.current && ve(e, t, { value: i === void 0 ? et.current : i }, { move: l });
1241
+ },
1242
+ onCancel: () => {
1243
+ me(), gt(e.id, t.field);
1244
+ }
1245
+ })
1246
+ }
1247
+ );
1248
+ const s = t.type === "date";
1249
+ return s ? /* @__PURE__ */ d(
1250
+ qn,
1251
+ {
1252
+ value: o.draft === null || o.draft === void 0 ? "" : String(o.draft),
1253
+ label: `Edit ${ke(t)}`,
1254
+ invalid: o.invalid,
1255
+ min: t.dateMin,
1256
+ max: t.dateMax,
1257
+ locale: t.dateLocale,
1258
+ theme: Je,
1259
+ className: O("rg-grid__editor", o.invalid && "rg-grid__editor--invalid", B.editor),
1260
+ style: { textAlign: t.align, ...L.editor },
1261
+ onChange: (i) => ye((l) => l && { ...l, draft: i, invalid: !1 }),
1262
+ onPick: (i) => {
1263
+ o.session === ge.current && ve(e, t, { text: i }, { focus: !0 });
1264
+ },
1265
+ onBlur: (i) => {
1266
+ o.session === ge.current && (ve(e, t, { text: i.currentTarget.value }, { focus: !1 }) || me());
1267
+ },
1268
+ onKeyDown: (i) => pr(i, e, t)
1269
+ }
1270
+ ) : /* @__PURE__ */ d(
1271
+ "input",
1272
+ {
1273
+ autoFocus: !0,
1274
+ type: s ? "date" : "text",
1275
+ min: s ? t.dateMin : void 0,
1276
+ max: s ? t.dateMax : void 0,
1277
+ className: O("rg-grid__editor", o.invalid && "rg-grid__editor--invalid", B.editor),
1278
+ style: { textAlign: t.align, ...L.editor },
1279
+ value: o.draft === null || o.draft === void 0 ? "" : String(o.draft),
1280
+ inputMode: t.type === "number" ? "decimal" : void 0,
1281
+ "aria-label": `Edit ${ke(t)}`,
1282
+ "aria-invalid": o.invalid || void 0,
1283
+ onChange: (i) => {
1284
+ const l = i.target.value;
1285
+ ye((m) => m && { ...m, draft: l, invalid: !1 });
1286
+ },
1287
+ onFocus: (i) => {
1288
+ const l = i.currentTarget;
1289
+ s || (o.select === "all" ? l.select() : l.setSelectionRange(l.value.length, l.value.length));
1290
+ },
1291
+ onBlur: (i) => {
1292
+ if (o.session === ge.current) {
1293
+ if (Or(i.currentTarget)) return me();
1294
+ ve(e, t, { text: i.currentTarget.value }, { focus: !1 }) || me();
1295
+ }
1296
+ },
1297
+ onKeyDown: (i) => pr(i, e, t)
1298
+ }
1299
+ );
1300
+ }, Nn = ae(() => {
1301
+ const e = /* @__PURE__ */ new Map();
1302
+ for (const t of M)
1303
+ t.filterable && !t.filterRenderer && Lr(t) === "select" && e.set(t.field, zn(t, Ge, (o) => te(o, t.field), (o) => We(t, o)));
1304
+ return e;
1305
+ }, [M, Ge]), Mn = qr || !!He, Cn = He ? { "--rg-stripe-a": He[0], "--rg-stripe-b": He[1] } : void 0, En = V && (ce === "top" || ce === "both"), Tn = V && (ce === "bottom" || ce === "both"), Fn = F || !!Gt || Ue || !!ze, Nr = (e) => /* @__PURE__ */ D(
516
1306
  "div",
517
1307
  {
518
- className: D("rk-grid__footer", e === "top" && "rk-grid__footer--top", N.footer),
519
- style: x.footer,
1308
+ className: O("rg-grid__footer", e === "top" && "rg-grid__footer--top", B.footer),
1309
+ style: L.footer,
520
1310
  "data-position": e,
521
1311
  children: [
522
- /* @__PURE__ */ d("span", { ..._("rowCount", "rk-grid__count"), children: U === 0 ? "0 rows" : `${rt}–${nt} of ${U}` }),
523
- k && /* @__PURE__ */ $("div", { ..._("pagination", "rk-grid__pagination"), children: [
524
- /* @__PURE__ */ $("label", { className: "rk-grid__page-size-label", children: [
1312
+ /* @__PURE__ */ D("span", { ...q("rowCount", "rg-grid__count"), children: [
1313
+ Ee === 0 ? "0 rows" : `${on}–${ln} of ${Ee}`,
1314
+ Q && se.length > 0 ? ` · ${se.length} selected` : ""
1315
+ ] }),
1316
+ /* @__PURE__ */ D("div", { ...q("pagination", "rg-grid__pagination"), children: [
1317
+ /* @__PURE__ */ D("label", { className: "rg-grid__page-size-label", children: [
525
1318
  "Rows per page",
526
- /* @__PURE__ */ d(
527
- "select",
528
- {
529
- value: P,
530
- onChange: (t) => tt(Number(t.target.value)),
531
- ..._("pageSize", "rk-grid__page-size"),
532
- children: (y.includes(P) ? y : [...y, P].sort((t, r) => t - r)).map(
533
- (t) => /* @__PURE__ */ d("option", { value: t, children: t }, t)
534
- )
535
- }
536
- )
1319
+ /* @__PURE__ */ d("select", { value: z, onChange: (t) => Gr(Number(t.target.value)), ...q("pageSize", "rg-grid__page-size"), children: (Se.includes(z) ? Se : [...Se, z].sort((t, o) => t - o)).map((t) => /* @__PURE__ */ d("option", { value: t, children: t }, t)) })
537
1320
  ] }),
538
- /* @__PURE__ */ d("button", { type: "button", "aria-label": "First page", disabled: S === 0, onClick: () => ee(0), ..._("pageButton", "rk-grid__page-btn"), children: "«" }),
539
- /* @__PURE__ */ d("button", { type: "button", "aria-label": "Previous page", disabled: S === 0, onClick: () => ee(S - 1), ..._("pageButton", "rk-grid__page-btn"), children: "‹" }),
540
- /* @__PURE__ */ $("span", { ..._("pageInfo", "rk-grid__page-info"), children: [
1321
+ /* @__PURE__ */ d("button", { type: "button", "aria-label": "First page", disabled: H === 0, onClick: () => Ne(0), ...q("pageButton", "rg-grid__page-btn"), children: "«" }),
1322
+ /* @__PURE__ */ d("button", { type: "button", "aria-label": "Previous page", disabled: H === 0, onClick: () => Ne(H - 1), ...q("pageButton", "rg-grid__page-btn"), children: "‹" }),
1323
+ /* @__PURE__ */ D("span", { ...q("pageInfo", "rg-grid__page-info"), children: [
541
1324
  "Page ",
542
- S + 1,
1325
+ H + 1,
543
1326
  " of ",
544
- oe
1327
+ pe
545
1328
  ] }),
546
- /* @__PURE__ */ d("button", { type: "button", "aria-label": "Next page", disabled: S >= oe - 1, onClick: () => ee(S + 1), ..._("pageButton", "rk-grid__page-btn"), children: "›" }),
547
- /* @__PURE__ */ d("button", { type: "button", "aria-label": "Last page", disabled: S >= oe - 1, onClick: () => ee(oe - 1), ..._("pageButton", "rk-grid__page-btn"), children: "»" })
1329
+ /* @__PURE__ */ d("button", { type: "button", "aria-label": "Next page", disabled: H >= pe - 1, onClick: () => Ne(H + 1), ...q("pageButton", "rg-grid__page-btn"), children: "›" }),
1330
+ /* @__PURE__ */ d("button", { type: "button", "aria-label": "Last page", disabled: H >= pe - 1, onClick: () => Ne(pe - 1), ...q("pageButton", "rg-grid__page-btn"), children: "»" })
548
1331
  ] })
549
1332
  ]
550
1333
  }
551
- );
552
- return /* @__PURE__ */ $(
553
- "div",
554
- {
555
- className: D("rk-grid", N.root, de),
556
- style: { ...ft, ...x.root, ...He },
557
- "data-rk-theme": T || void 0,
558
- children: [
559
- (G || q) && /* @__PURE__ */ $("div", { ..._("toolbar", "rk-grid__toolbar"), children: [
560
- G ? /* @__PURE__ */ d(
561
- "input",
1334
+ ), Sn = (e) => /* @__PURE__ */ d("tr", { className: "rg-grid__tr rg-grid__skeleton-row", "aria-hidden": "true", style: oe ? { height: de } : void 0, children: fe ? (
1335
+ // A custom component draws the whole row content inside one wide cell
1336
+ /* @__PURE__ */ d("td", { colSpan: Oe, className: "rg-grid__td rg-grid__skeleton-cell", children: Te(fe, { rowIndex: e, columns: M }) })
1337
+ ) : /* @__PURE__ */ D(je, { children: [
1338
+ Q && /* @__PURE__ */ d("td", { className: "rg-grid__td", children: /* @__PURE__ */ d("span", { ...q("skeleton", "rg-grid__skeleton"), style: { ...L.skeleton, width: 18 } }) }),
1339
+ M.map((t, o) => /* @__PURE__ */ d("td", { className: "rg-grid__td", style: { textAlign: t.align }, children: /* @__PURE__ */ d("span", { ...q("skeleton", "rg-grid__skeleton"), style: { ...L.skeleton, width: `${55 + (e * 7 + o * 13) % 35}%` } }) }, t.field))
1340
+ ] }) }, `sk${e}`), Mr = (e, t, o = V && !e.sequenceRestartEachPage ? H * z : 0) => (e.sequenceStart ?? 1) + o + t, In = (e, t) => {
1341
+ const { row: o, id: s, index: i } = e, l = typeof Ct == "function" ? Ct(o, i) : Ct, m = typeof Et == "function" ? Et(o, i) : Et, p = Rt.has(s), x = typeof Mt == "function" ? Mt(o, i) : Mt;
1342
+ return /* @__PURE__ */ D(
1343
+ "tr",
1344
+ {
1345
+ onClick: Dt ? () => Dt(o, i) : void 0,
1346
+ "aria-selected": Q ? p : void 0,
1347
+ className: O(
1348
+ "rg-grid__tr",
1349
+ "rg-grid__row",
1350
+ Mn && (t % 2 === 0 ? "rg-grid__row--stripe-a" : "rg-grid__row--stripe-b"),
1351
+ // A custom animation class replaces the built-in slide-up. Rows are not animated while virtualizing.
1352
+ Qt && !oe && (x || "rg-grid__row--enter"),
1353
+ p && "rg-grid__row--selected",
1354
+ Dt && "rg-grid__row--clickable",
1355
+ B.row,
1356
+ l
1357
+ ),
1358
+ style: {
1359
+ ...Qt && !oe ? { "--rg-i": Math.min(t, 24) } : null,
1360
+ ...oe ? { height: de } : null,
1361
+ ...L.row,
1362
+ ...m
1363
+ },
1364
+ children: [
1365
+ Q && /* @__PURE__ */ d(
1366
+ "td",
562
1367
  {
563
- type: "search",
564
- value: X,
565
- onChange: (e) => Qe(e.target.value),
566
- placeholder: w,
567
- "aria-label": "Search all columns",
568
- ..._("search", "rk-grid__search")
1368
+ className: O("rg-grid__td rg-grid__select-cell", bt && "rg-grid__pinned rg-grid__pinned--left"),
1369
+ style: { width: be, minWidth: be, maxWidth: be, ...bt ? { left: 0 } : null },
1370
+ onClick: xe,
1371
+ children: /* @__PURE__ */ d("span", { className: "rg-grid__checkbox-cell", onClickCapture: (h) => ar.current = h.shiftKey, children: /* @__PURE__ */ d(
1372
+ Fe,
1373
+ {
1374
+ variant: Nt,
1375
+ checked: p,
1376
+ disabled: !ct(o),
1377
+ "aria-label": Q === "single" ? "Select row" : `Select row ${i + 1}`,
1378
+ onChange: (h) => dn(e, h),
1379
+ classNames: { root: B.checkbox, control: B.checkboxControl, indicator: B.checkboxIndicator },
1380
+ styles: { root: L.checkbox, control: L.checkboxControl, indicator: L.checkboxIndicator }
1381
+ }
1382
+ ) })
569
1383
  }
570
- ) : /* @__PURE__ */ d("span", {}),
571
- q
572
- ] }),
573
- pt && Oe("top"),
574
- /* @__PURE__ */ d("div", { ref: Be, ..._("scroll", "rk-grid__scroll"), style: { ...x.scroll, ...j !== void 0 ? { maxHeight: j } : null }, children: /* @__PURE__ */ $("table", { ..._("table", "rk-grid__table"), role: "grid", children: [
575
- /* @__PURE__ */ d("thead", { ..._("thead", "rk-grid__thead"), children: /* @__PURE__ */ d("tr", { ..._("headerRow", "rk-grid__tr"), children: o.map((e) => {
576
- const t = (v == null ? void 0 : v.field) === e.field ? v.direction : null, r = Fe(e);
1384
+ ),
1385
+ M.map((h, Y) => {
1386
+ let ee = un(h, e);
1387
+ if (h.type === "sequence") {
1388
+ const ie = Mr(h, t);
1389
+ ee = { ...ee, value: ie, formattedValue: h.valueFormatter ? h.valueFormatter(ie, o) : String(ie), editable: !1 };
1390
+ }
1391
+ const $n = typeof h.cellClassName == "function" ? h.cellClassName(ee) : h.cellClassName, Pn = typeof h.cellStyle == "function" ? h.cellStyle(ee) : h.cellStyle, Cr = Pe !== null && Pe.id === s && Pe.field === h.field, jt = ft(h, ee), Er = yr(h, Y), An = St ? St.id === s && St.field === h.field : t === 0 && Y === 0;
577
1392
  return /* @__PURE__ */ d(
578
- "th",
1393
+ "td",
579
1394
  {
580
- scope: "col",
581
- "aria-sort": t ? t === "asc" ? "ascending" : "descending" : r ? "none" : void 0,
582
- tabIndex: r ? 0 : void 0,
583
- onClick: () => Ve(e),
584
- onKeyDown: (n) => {
585
- r && n.target === n.currentTarget && (n.key === "Enter" || n.key === " ") && (n.preventDefault(), Ve(e));
1395
+ ref: (ie) => {
1396
+ const Tr = Vt(s, h.field);
1397
+ ie ? tt.current.set(Tr, ie) : tt.current.delete(Tr);
586
1398
  },
587
- className: D("rk-grid__th", r && "rk-grid__th--sortable", N.headerCell, e.className, e.headerClassName),
588
- style: { width: e.width, minWidth: e.minWidth, textAlign: e.align, ...x.headerCell, ...e.style, ...e.headerStyle },
589
- children: /* @__PURE__ */ $("span", { className: "rk-grid__th-content", children: [
590
- e.headerRenderer ? se(e.headerRenderer, { column: e, sortDirection: t }) : e.headerCheckbox && e.type === "boolean" ? ct(e) : Ie(e),
591
- e.filterable && /* @__PURE__ */ d(
592
- xt,
593
- {
594
- column: e,
595
- label: be(e),
596
- value: Z[e.field] ?? "",
597
- onChange: (n) => Xe((i) => ({ ...i, [e.field]: n })),
598
- theme: T,
599
- indicatorClassName: D(N.filterIndicator, e.filterIndicatorClassName),
600
- indicatorStyle: { ...x.filterIndicator, ...e.filterIndicatorStyle },
601
- popupClassName: D(N.filterPopup, e.filterPopupClassName),
602
- popupStyle: { ...x.filterPopup, ...e.filterPopupStyle },
603
- inputClassName: N.filterInput,
604
- inputStyle: x.filterInput
605
- }
606
- ),
607
- r && /* @__PURE__ */ d("span", { className: "rk-grid__sort", "aria-hidden": "true", children: t === "asc" ? "▲" : t === "desc" ? "▼" : "↕" })
608
- ] })
609
- },
610
- e.field
611
- );
612
- }) }) }),
613
- /* @__PURE__ */ d("tbody", { ..._("tbody", "rk-grid__tbody"), children: M.length === 0 ? /* @__PURE__ */ d("tr", { children: /* @__PURE__ */ d("td", { colSpan: o.length, ..._("empty", "rk-grid__empty"), children: L }) }) : M.map((e, t) => {
614
- const { row: r, id: n, index: i } = e, l = typeof me == "function" ? me(r, i) : me, f = typeof ve == "function" ? ve(r, i) : ve;
615
- return /* @__PURE__ */ d(
616
- "tr",
617
- {
618
- onClick: R ? () => R(r, i) : void 0,
619
- className: D(
620
- "rk-grid__tr",
621
- "rk-grid__row",
622
- ut && (t % 2 === 0 ? "rk-grid__row--stripe-a" : "rk-grid__row--stripe-b"),
623
- A && "rk-grid__row--enter",
624
- R && "rk-grid__row--clickable",
625
- N.row,
626
- l
1399
+ tabIndex: wt ? An ? 0 : -1 : jt ? 0 : void 0,
1400
+ onFocus: wt ? (ie) => ie.target === ie.currentTarget && rr({ id: s, field: h.field }) : void 0,
1401
+ onDoubleClick: jt ? () => ht(e, h) : void 0,
1402
+ onKeyDown: (ie) => pn(ie, e, h, ee),
1403
+ className: O(
1404
+ "rg-grid__td",
1405
+ jt && "rg-grid__td--editable",
1406
+ Cr && "rg-grid__td--editing",
1407
+ Er.className,
1408
+ B.cell,
1409
+ h.className,
1410
+ $n
627
1411
  ),
628
- style: { ...A ? { "--rk-i": Math.min(t, 24) } : null, ...x.row, ...f },
629
- children: o.map((a) => {
630
- const u = ot(a, e), p = typeof a.cellClassName == "function" ? a.cellClassName(u) : a.cellClassName, C = typeof a.cellStyle == "function" ? a.cellStyle(u) : a.cellStyle, we = te !== null && te.id === n && te.field === a.field, Ee = fe(a, u);
631
- return /* @__PURE__ */ d(
632
- "td",
633
- {
634
- ref: (ke) => {
635
- const Re = Ue(n, a.field);
636
- ke ? ye.current.set(Re, ke) : ye.current.delete(Re);
637
- },
638
- tabIndex: Ee ? 0 : void 0,
639
- onDoubleClick: Ee ? () => he(e, a) : void 0,
640
- onKeyDown: (ke) => lt(ke, e, a, u),
641
- className: D(
642
- "rk-grid__td",
643
- Ee && "rk-grid__td--editable",
644
- we && "rk-grid__td--editing",
645
- N.cell,
646
- a.className,
647
- p
648
- ),
649
- style: { textAlign: a.align, ...x.cell, ...a.style, ...C },
650
- children: we && te ? at(e, a, te) : a.cellRenderer ? se(a.cellRenderer, u) : a.type === "boolean" && !a.cellEditor ? st(a, u) : u.formattedValue
651
- },
652
- a.field
653
- );
654
- })
1412
+ style: { textAlign: h.align, ...L.cell, ...h.style, ...Pn, ...Er.style },
1413
+ children: Cr && Pe ? Dn(e, h, Pe) : h.cellRenderer ? Te(h.cellRenderer, ee) : h.type === "boolean" && !h.cellEditor ? xn(h, ee) : ee.formattedValue
655
1414
  },
656
- n
1415
+ h.field
657
1416
  );
658
- }) }, Ke)
659
- ] }) }),
660
- ht && Oe("bottom")
1417
+ })
1418
+ ]
1419
+ },
1420
+ s
1421
+ );
1422
+ }, Ln = le ?? (V ? Math.min(z, 20) : 5);
1423
+ return /* @__PURE__ */ D(
1424
+ "div",
1425
+ {
1426
+ className: O("rg-grid", oe && "rg-grid--virtual", B.root, Vr),
1427
+ style: { ...Cn, ...L.root, ...Ur },
1428
+ "data-rg-theme": Je || void 0,
1429
+ "aria-busy": Kt || void 0,
1430
+ children: [
1431
+ Fn && /* @__PURE__ */ D("div", { ...q("toolbar", "rg-grid__toolbar"), children: [
1432
+ /* @__PURE__ */ D("div", { className: "rg-grid__toolbar-left", children: [
1433
+ F && /* @__PURE__ */ d(
1434
+ "input",
1435
+ {
1436
+ type: "search",
1437
+ value: Le,
1438
+ onChange: (e) => zr(e.target.value),
1439
+ placeholder: N,
1440
+ "aria-label": "Search all columns",
1441
+ ...q("search", "rg-grid__search")
1442
+ }
1443
+ ),
1444
+ Q && se.length > 0 && /* @__PURE__ */ D("span", { className: "rg-grid__selected-count", role: "status", children: [
1445
+ se.length,
1446
+ " selected"
1447
+ ] })
1448
+ ] }),
1449
+ /* @__PURE__ */ D("div", { className: "rg-grid__toolbar-actions", children: [
1450
+ Gt,
1451
+ Ue && /* @__PURE__ */ d(
1452
+ Zn,
1453
+ {
1454
+ columns: r,
1455
+ hidden: Qe,
1456
+ onToggle: Zr,
1457
+ theme: Je,
1458
+ className: B.toolButton,
1459
+ style: L.toolButton
1460
+ }
1461
+ ),
1462
+ ze && /* @__PURE__ */ d("button", { type: "button", onClick: () => kr(), ...q("toolButton", "rg-grid__tool-btn"), children: "Export CSV" })
1463
+ ] })
1464
+ ] }),
1465
+ En && Nr("top"),
1466
+ /* @__PURE__ */ d(
1467
+ "div",
1468
+ {
1469
+ ref: Ae,
1470
+ ...q("scroll", "rg-grid__scroll"),
1471
+ onScroll: oe ? (e) => nr({ top: e.currentTarget.scrollTop, height: e.currentTarget.clientHeight }) : void 0,
1472
+ style: { ...L.scroll, ...Xe !== void 0 ? { maxHeight: Xe } : oe ? { maxHeight: 400 } : null },
1473
+ children: /* @__PURE__ */ D(
1474
+ "table",
1475
+ {
1476
+ ...q("table", "rg-grid__table"),
1477
+ role: "grid",
1478
+ style: Wt ? {
1479
+ ...L.table,
1480
+ tableLayout: "fixed",
1481
+ width: M.reduce((e, t) => e + mt(t), Q ? be : 0),
1482
+ minWidth: "100%"
1483
+ } : L.table,
1484
+ children: [
1485
+ /* @__PURE__ */ d("thead", { ...q("thead", "rg-grid__thead"), children: /* @__PURE__ */ D("tr", { ...q("headerRow", "rg-grid__tr"), children: [
1486
+ Q && /* @__PURE__ */ d(
1487
+ "th",
1488
+ {
1489
+ scope: "col",
1490
+ className: O("rg-grid__th rg-grid__select-cell", bt && "rg-grid__pinned rg-grid__pinned--left", B.headerCell),
1491
+ style: { width: be, minWidth: be, maxWidth: be, ...bt ? { left: 0 } : null, ...L.headerCell },
1492
+ children: Q === "multiple" && /* @__PURE__ */ d("span", { className: "rg-grid__checkbox-cell", children: /* @__PURE__ */ d(
1493
+ Fe,
1494
+ {
1495
+ variant: Nt,
1496
+ checked: dr,
1497
+ indeterminate: cr > 0 && !dr,
1498
+ disabled: Ke.length === 0,
1499
+ "aria-label": "Select all rows",
1500
+ onChange: ur,
1501
+ classNames: { root: B.checkbox, control: B.checkboxControl, indicator: B.checkboxIndicator },
1502
+ styles: { root: L.checkbox, control: L.checkboxControl, indicator: L.checkboxIndicator }
1503
+ }
1504
+ ) })
1505
+ }
1506
+ ),
1507
+ M.map((e, t) => {
1508
+ const o = G.findIndex((p) => p.field === e.field), s = o >= 0 ? G[o].direction : null, i = $t(e), l = ir(e), m = yr(e, t);
1509
+ return /* @__PURE__ */ D(
1510
+ "th",
1511
+ {
1512
+ ref: (p) => {
1513
+ p ? $e.current.set(e.field, p) : $e.current.delete(e.field);
1514
+ },
1515
+ scope: "col",
1516
+ "aria-sort": s ? s === "asc" ? "ascending" : "descending" : i ? "none" : void 0,
1517
+ tabIndex: i ? 0 : void 0,
1518
+ onClick: (p) => fr(e, p.shiftKey),
1519
+ onKeyDown: (p) => {
1520
+ i && p.target === p.currentTarget && (p.key === "Enter" || p.key === " ") && (p.preventDefault(), fr(e, p.shiftKey));
1521
+ },
1522
+ className: O("rg-grid__th", i && "rg-grid__th--sortable", m.className, B.headerCell, e.className, e.headerClassName),
1523
+ style: {
1524
+ width: Wt ? mt(e) : e.width,
1525
+ minWidth: e.minWidth,
1526
+ textAlign: e.align,
1527
+ ...L.headerCell,
1528
+ ...e.style,
1529
+ ...e.headerStyle,
1530
+ ...m.style
1531
+ },
1532
+ children: [
1533
+ /* @__PURE__ */ D("span", { className: "rg-grid__th-content", children: [
1534
+ e.headerRenderer ? Te(e.headerRenderer, { column: e, sortDirection: s }) : e.headerCheckbox && e.type === "boolean" ? wn(e) : _t(e),
1535
+ e.filterable && /* @__PURE__ */ d(
1536
+ Qn,
1537
+ {
1538
+ column: e,
1539
+ label: ke(e),
1540
+ kind: l,
1541
+ value: De[e.field],
1542
+ onChange: (p) => {
1543
+ const x = { ...De };
1544
+ p === void 0 ? delete x[e.field] : x[e.field] = p, Hr(x);
1545
+ },
1546
+ options: Nn.get(e.field) ?? [],
1547
+ debounce: e.filterDebounce ?? I,
1548
+ theme: Je,
1549
+ indicatorClassName: O(B.filterIndicator, e.filterIndicatorClassName),
1550
+ indicatorStyle: { ...L.filterIndicator, ...e.filterIndicatorStyle },
1551
+ popupClassName: O(B.filterPopup, e.filterPopupClassName),
1552
+ popupStyle: { ...L.filterPopup, ...e.filterPopupStyle },
1553
+ inputClassName: B.filterInput,
1554
+ inputStyle: L.filterInput
1555
+ }
1556
+ ),
1557
+ i && /* @__PURE__ */ D("span", { className: "rg-grid__sort", "aria-hidden": "true", children: [
1558
+ s === "asc" ? "▲" : s === "desc" ? "▼" : "↕",
1559
+ s && G.length > 1 && /* @__PURE__ */ d("sup", { className: "rg-grid__sort-order", children: o + 1 })
1560
+ ] })
1561
+ ] }),
1562
+ e.resizable && /* @__PURE__ */ d(
1563
+ "span",
1564
+ {
1565
+ className: "rg-grid__resizer",
1566
+ role: "separator",
1567
+ "aria-orientation": "vertical",
1568
+ "aria-label": `Resize ${ke(e)}`,
1569
+ onPointerDown: (p) => yn(p, e),
1570
+ onClick: xe,
1571
+ onDoubleClick: xe
1572
+ }
1573
+ )
1574
+ ]
1575
+ },
1576
+ e.field
1577
+ );
1578
+ })
1579
+ ] }) }),
1580
+ /* @__PURE__ */ d("tbody", { ...q("tbody", "rg-grid__tbody"), children: Kt ? Array.from({ length: Ln }, (e, t) => Sn(t)) : cn ? /* @__PURE__ */ d("tr", { children: /* @__PURE__ */ D("td", { colSpan: Oe, ...q("empty", "rg-grid__empty rg-grid__error"), role: "alert", children: [
1581
+ xt,
1582
+ " ",
1583
+ /* @__PURE__ */ d("button", { type: "button", className: "rg-grid__tool-btn", onClick: () => st(ot.current), children: "Retry" })
1584
+ ] }) }) : A.length === 0 ? /* @__PURE__ */ d("tr", { children: /* @__PURE__ */ d("td", { colSpan: Oe, ...q("empty", "rg-grid__empty"), children: jr }) }) : /* @__PURE__ */ D(je, { children: [
1585
+ Re && pt > 0 && /* @__PURE__ */ d("tr", { "aria-hidden": "true", className: "rg-grid__spacer", children: /* @__PURE__ */ d("td", { colSpan: Oe, style: { height: pt * de } }) }),
1586
+ bn.map((e, t) => In(e, pt + t)),
1587
+ Re && Yt < A.length && /* @__PURE__ */ d("tr", { "aria-hidden": "true", className: "rg-grid__spacer", children: /* @__PURE__ */ d("td", { colSpan: Oe, style: { height: (A.length - Yt) * de } }) })
1588
+ ] }) }, mr)
1589
+ ]
1590
+ }
1591
+ )
1592
+ }
1593
+ ),
1594
+ Tn && Nr("bottom")
661
1595
  ]
662
1596
  }
663
1597
  );
664
1598
  }
665
1599
  export {
666
- Ge as Checkbox,
667
- St as DataGrid
1600
+ Fe as Checkbox,
1601
+ fo as DataGrid
668
1602
  };