react-gridix 0.0.0-stage → 0.1.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.
- package/README.html +1742 -0
- package/README.md +1042 -2
- package/dist/index.d.ts +305 -0
- package/dist/react-gridix.cjs +1 -0
- package/dist/react-gridix.js +668 -0
- package/dist/style.css +1 -0
- package/package.json +39 -4
|
@@ -0,0 +1,668 @@
|
|
|
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() {
|
|
6
|
+
return /* @__PURE__ */ d("svg", { viewBox: "0 0 16 16", width: "100%", height: "100%", "aria-hidden": "true", focusable: "false", children: /* @__PURE__ */ d(
|
|
7
|
+
"path",
|
|
8
|
+
{
|
|
9
|
+
d: "M3.5 8.5l3 3 6-7",
|
|
10
|
+
fill: "none",
|
|
11
|
+
stroke: "currentColor",
|
|
12
|
+
strokeWidth: "2.2",
|
|
13
|
+
strokeLinecap: "round",
|
|
14
|
+
strokeLinejoin: "round"
|
|
15
|
+
}
|
|
16
|
+
) });
|
|
17
|
+
}
|
|
18
|
+
function vt() {
|
|
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
|
+
}
|
|
21
|
+
function Ge({
|
|
22
|
+
checked: o,
|
|
23
|
+
onChange: s,
|
|
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,
|
|
33
|
+
style: w,
|
|
34
|
+
classNames: k = {},
|
|
35
|
+
styles: E = {}
|
|
36
|
+
}) {
|
|
37
|
+
const F = c ? "indeterminate" : o ? "checked" : "unchecked";
|
|
38
|
+
return /* @__PURE__ */ $(
|
|
39
|
+
"label",
|
|
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
|
|
49
|
+
),
|
|
50
|
+
style: { ...E.root, ...w },
|
|
51
|
+
"data-state": F,
|
|
52
|
+
children: [
|
|
53
|
+
h === "native" ? /* @__PURE__ */ d(
|
|
54
|
+
"input",
|
|
55
|
+
{
|
|
56
|
+
type: "checkbox",
|
|
57
|
+
id: O,
|
|
58
|
+
name: H,
|
|
59
|
+
ref: (y) => {
|
|
60
|
+
y && (y.indeterminate = c);
|
|
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)
|
|
69
|
+
}
|
|
70
|
+
) : /* @__PURE__ */ d(
|
|
71
|
+
"button",
|
|
72
|
+
{
|
|
73
|
+
type: "button",
|
|
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),
|
|
83
|
+
children: /* @__PURE__ */ d(
|
|
84
|
+
"span",
|
|
85
|
+
{
|
|
86
|
+
className: le(
|
|
87
|
+
"rk-checkbox__indicator",
|
|
88
|
+
B !== void 0 && !c && "rk-checkbox__indicator--custom",
|
|
89
|
+
k.indicator
|
|
90
|
+
),
|
|
91
|
+
style: E.indicator,
|
|
92
|
+
"data-state": F,
|
|
93
|
+
"aria-hidden": "true",
|
|
94
|
+
children: c ? h === "tick" ? /* @__PURE__ */ d(vt, {}) : null : B !== void 0 ? B : h === "tick" ? /* @__PURE__ */ d(mt, {}) : null
|
|
95
|
+
}
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
),
|
|
99
|
+
b != null && b !== !1 && b !== "" && /* @__PURE__ */ d("span", { className: le("rk-checkbox__label", k.label), style: E.label, children: b })
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
);
|
|
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());
|
|
136
|
+
};
|
|
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);
|
|
139
|
+
};
|
|
140
|
+
}, [w, L]);
|
|
141
|
+
const _e = () => {
|
|
142
|
+
var g;
|
|
143
|
+
k(!1), (g = y.current) == null || g.focus();
|
|
144
|
+
};
|
|
145
|
+
return /* @__PURE__ */ $(gt, { children: [
|
|
146
|
+
/* @__PURE__ */ d(
|
|
147
|
+
"button",
|
|
148
|
+
{
|
|
149
|
+
ref: y,
|
|
150
|
+
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
|
|
156
|
+
),
|
|
157
|
+
style: m,
|
|
158
|
+
"aria-label": `Filter ${s}`,
|
|
159
|
+
"aria-haspopup": "dialog",
|
|
160
|
+
"aria-expanded": w,
|
|
161
|
+
"data-active": q || void 0,
|
|
162
|
+
onClick: (g) => {
|
|
163
|
+
g.stopPropagation(), w || L(), k((K) => !K);
|
|
164
|
+
},
|
|
165
|
+
children: o.filterIndicator ? se(o.filterIndicator, { column: o, active: q, open: w }) : /* @__PURE__ */ d("span", { className: "rk-grid__filter-dot", "aria-hidden": "true" })
|
|
166
|
+
}
|
|
167
|
+
),
|
|
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
|
|
200
|
+
)
|
|
201
|
+
] });
|
|
202
|
+
}
|
|
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];
|
|
211
|
+
}
|
|
212
|
+
return c;
|
|
213
|
+
}
|
|
214
|
+
function Je(o, s, c) {
|
|
215
|
+
if (Array.isArray(o)) {
|
|
216
|
+
const h = [...o];
|
|
217
|
+
return h[s] = c, h;
|
|
218
|
+
}
|
|
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,
|
|
241
|
+
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
|
|
270
|
+
}) {
|
|
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;
|
|
290
|
+
}));
|
|
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
|
+
});
|
|
299
|
+
}
|
|
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;
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
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),
|
|
316
|
+
row: t,
|
|
317
|
+
rowIndex: r,
|
|
318
|
+
field: e.field,
|
|
319
|
+
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);
|
|
325
|
+
return {
|
|
326
|
+
...r,
|
|
327
|
+
editable: n,
|
|
328
|
+
updateValue: (i) => n && Ae(t, e, { value: i })
|
|
329
|
+
};
|
|
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({
|
|
343
|
+
id: e.id,
|
|
344
|
+
field: t.field,
|
|
345
|
+
draft: i,
|
|
346
|
+
session: J.current,
|
|
347
|
+
select: r.select ?? "end",
|
|
348
|
+
invalid: !1
|
|
349
|
+
}), !0;
|
|
350
|
+
}, Ae = (e, t, r) => {
|
|
351
|
+
const n = Q.current[e.index] ?? e.row, i = z(n, t.field);
|
|
352
|
+
let l;
|
|
353
|
+
if ("value" in r)
|
|
354
|
+
l = r.value;
|
|
355
|
+
else if (t.valueParser)
|
|
356
|
+
l = t.valueParser(r.text, n);
|
|
357
|
+
else if (t.type === "number")
|
|
358
|
+
if (r.text.trim() === "") l = null;
|
|
359
|
+
else {
|
|
360
|
+
const u = Number(r.text);
|
|
361
|
+
if (!Number.isFinite(u)) return !1;
|
|
362
|
+
l = u;
|
|
363
|
+
}
|
|
364
|
+
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] };
|
|
378
|
+
return null;
|
|
379
|
+
}
|
|
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;
|
|
386
|
+
}
|
|
387
|
+
a += f, u = f > 0 ? 0 : o.length - 1;
|
|
388
|
+
}
|
|
389
|
+
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) => {
|
|
397
|
+
if (e.nativeEvent.isComposing) return;
|
|
398
|
+
const n = e.currentTarget.value;
|
|
399
|
+
if (e.key === "Enter") {
|
|
400
|
+
e.preventDefault();
|
|
401
|
+
const i = I ? e.shiftKey ? "up" : "down" : "none";
|
|
402
|
+
ie(t, r, { text: n }, { move: i });
|
|
403
|
+
} 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 }));
|
|
408
|
+
}
|
|
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
|
+
})
|
|
437
|
+
}
|
|
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)
|
|
460
|
+
}
|
|
461
|
+
), ze = (e) => {
|
|
462
|
+
var r, n, i, l, f, a, u, p;
|
|
463
|
+
const t = e.checkbox ?? {};
|
|
464
|
+
return {
|
|
465
|
+
variant: t.variant ?? K,
|
|
466
|
+
indicator: t.indicator,
|
|
467
|
+
className: t.className,
|
|
468
|
+
style: t.style,
|
|
469
|
+
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),
|
|
473
|
+
label: (l = t.classNames) == null ? void 0 : l.label
|
|
474
|
+
},
|
|
475
|
+
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
|
|
480
|
+
}
|
|
481
|
+
};
|
|
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,
|
|
484
|
+
{
|
|
485
|
+
...ze(e),
|
|
486
|
+
checked: !!t.value,
|
|
487
|
+
disabled: !t.editable,
|
|
488
|
+
"aria-label": `Toggle ${be(e)}`,
|
|
489
|
+
onChange: (r) => t.updateValue(r)
|
|
490
|
+
}
|
|
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;
|
|
499
|
+
});
|
|
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,
|
|
505
|
+
{
|
|
506
|
+
...ze(e),
|
|
507
|
+
checked: i,
|
|
508
|
+
indeterminate: n > 0 && !i,
|
|
509
|
+
disabled: t.length === 0,
|
|
510
|
+
label: Ie(e) || void 0,
|
|
511
|
+
"aria-label": `Select all ${be(e)}`,
|
|
512
|
+
onChange: (l) => dt(e, l)
|
|
513
|
+
}
|
|
514
|
+
) });
|
|
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__ */ $(
|
|
516
|
+
"div",
|
|
517
|
+
{
|
|
518
|
+
className: D("rk-grid__footer", e === "top" && "rk-grid__footer--top", N.footer),
|
|
519
|
+
style: x.footer,
|
|
520
|
+
"data-position": e,
|
|
521
|
+
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: [
|
|
525
|
+
"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
|
+
)
|
|
537
|
+
] }),
|
|
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: [
|
|
541
|
+
"Page ",
|
|
542
|
+
S + 1,
|
|
543
|
+
" of ",
|
|
544
|
+
oe
|
|
545
|
+
] }),
|
|
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: "»" })
|
|
548
|
+
] })
|
|
549
|
+
]
|
|
550
|
+
}
|
|
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",
|
|
562
|
+
{
|
|
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")
|
|
569
|
+
}
|
|
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);
|
|
577
|
+
return /* @__PURE__ */ d(
|
|
578
|
+
"th",
|
|
579
|
+
{
|
|
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));
|
|
586
|
+
},
|
|
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
|
|
627
|
+
),
|
|
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
|
+
})
|
|
655
|
+
},
|
|
656
|
+
n
|
|
657
|
+
);
|
|
658
|
+
}) }, Ke)
|
|
659
|
+
] }) }),
|
|
660
|
+
ht && Oe("bottom")
|
|
661
|
+
]
|
|
662
|
+
}
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
export {
|
|
666
|
+
Ge as Checkbox,
|
|
667
|
+
St as DataGrid
|
|
668
|
+
};
|