@mikestools/usetable 0.0.3 → 0.0.4

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/dist/usetable.js CHANGED
@@ -1,1800 +1,903 @@
1
- import { shallowRef as Kt, ref as p, watch as H, computed as m, customRef as De } from "vue";
2
- function Jt(s) {
3
- return typeof s != "object" || s === null || !("row" in s) || !("column" in s) || !("message" in s) || !("value" in s) ? !1 : typeof s.row == "number" && typeof s.column == "number" && typeof s.message == "string";
4
- }
5
- function Al(s) {
6
- return Array.isArray(s) && s.every(Jt);
1
+ import { ref as N, computed as U, onUnmounted as ut } from "vue";
2
+ function dt() {
3
+ return crypto.randomUUID();
7
4
  }
8
- function Dl(s) {
9
- return typeof s != "object" || s === null || !("valid" in s) || !("errors" in s) ? !1 : typeof s.valid == "boolean" && Array.isArray(s.errors) && s.errors.every(Jt);
5
+ function S(l, C) {
6
+ l.textContent = "", C != null && (C instanceof Node ? l.appendChild(C) : l.textContent = String(C));
10
7
  }
11
- function Ae(s) {
12
- return s === null || typeof s != "object" || "nodeType" in s ? !1 : "value" in s;
8
+ function A(l) {
9
+ return l.childNodes.length === 1 && l.firstChild instanceof HTMLElement ? l.firstChild : l.textContent ?? "";
13
10
  }
14
- const al = /* @__PURE__ */ new Set([
15
- "opacity",
16
- "z-index",
17
- "font-weight",
18
- "line-height",
19
- "flex",
20
- "flex-grow",
21
- "flex-shrink",
22
- "flex-basis",
23
- "order",
24
- "zoom",
25
- "counter-increment",
26
- "counter-reset",
27
- "orphans",
28
- "widows",
29
- "fill-opacity",
30
- "flood-opacity",
31
- "stop-opacity",
32
- "stroke-opacity",
33
- "stroke-miterlimit",
34
- "column-count",
35
- "tab-size"
36
- ]);
37
- function cl(s) {
38
- return !al.has(s);
11
+ function oe(l) {
12
+ const C = document.createElement("th");
13
+ return C.scope = "col", C.textContent = l, C;
39
14
  }
40
- function me(s, u) {
41
- if (!u) return;
42
- if (u.class !== void 0 && (typeof u.class == "string" ? s.className = u.class : Array.isArray(u.class) ? s.className = u.class.join(" ") : s.className = Object.entries(u.class).filter(([, h]) => h).map(([h]) => h).join(" ")), u.style !== void 0) {
43
- if (typeof u.style == "string")
44
- s.setAttribute("style", u.style);
45
- else if (typeof u.style == "object")
46
- for (const [h, v] of Object.entries(u.style)) {
47
- if (v == null) continue;
48
- const C = h.replace(/([A-Z])/g, "-$1").toLowerCase(), fe = typeof v == "number" && cl(C) ? `${v}px` : String(v);
49
- s.style.setProperty(C, fe);
50
- }
15
+ function it(l, C, H) {
16
+ let c = H?.idGenerator ?? dt;
17
+ const F = /* @__PURE__ */ new Set(), f = /* @__PURE__ */ new Set(), h = /* @__PURE__ */ new Set(), D = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Set(), I = /* @__PURE__ */ new Set();
18
+ function E() {
19
+ const e = l.tBodies;
20
+ return e.length > 0 ? e[0] : l.createTBody();
51
21
  }
52
- if (u.dataset)
53
- for (const [h, v] of Object.entries(u.dataset))
54
- v != null && (s.dataset[h] = String(v));
55
- u.id !== void 0 && (s.id = u.id), u.title !== void 0 && (s.title = u.title);
56
- const c = /* @__PURE__ */ new Set(["class", "style", "dataset", "id", "title"]);
57
- for (const [h, v] of Object.entries(u))
58
- c.has(h) || v === void 0 || v === null || (h.startsWith("on") && typeof v == "function" ? s.addEventListener(h.slice(2).toLowerCase(), v) : h.startsWith("data-") || h.startsWith("aria-") || h === "role" ? s.setAttribute(h, String(v)) : h in s ? typeof v == "boolean" ? v ? s.setAttribute(h, "") : s.removeAttribute(h) : s.setAttribute(h, String(v)) : typeof v == "boolean" ? v && s.setAttribute(h, "") : s.setAttribute(h, String(v)));
59
- }
60
- function Ee(s, u) {
61
- const c = document.createElement("th");
62
- return c.textContent = s, u?.scope || (c.scope = "col"), me(c, u), c;
63
- }
64
- function b(s, u) {
65
- let c = u, h, v, C;
66
- u instanceof Node ? c = u : Ae(u) && (c = u.value, h = u.attributes, v = u.columnSpan, C = u.rowSpan), c == null ? s.textContent = "" : c instanceof Node ? (s.textContent = "", s.appendChild(c)) : s.textContent = String(c), v !== void 0 && v > 1 && (s.colSpan = v), C !== void 0 && C > 0 && (s.rowSpan = C), me(s, h);
67
- }
68
- function re(s) {
69
- return s.children.length === 1 && s.textContent === s.children[0]?.textContent ? s.children[0] : s.textContent || "";
70
- }
71
- function ul(s) {
72
- const u = p(s);
73
- return {
74
- element: u,
75
- cellIndex: m(() => u.value.cellIndex),
76
- columnSpan: m({ get: () => u.value.colSpan, set: (c) => {
77
- u.value.colSpan = c;
78
- } }),
79
- rowSpan: m({ get: () => u.value.rowSpan, set: (c) => {
80
- u.value.rowSpan = c;
81
- } }),
82
- headers: m({ get: () => u.value.headers, set: (c) => {
83
- u.value.headers = c;
84
- } }),
85
- abbr: m({ get: () => u.value.abbr, set: (c) => {
86
- u.value.abbr = c;
87
- } }),
88
- scope: m({ get: () => u.value.scope, set: (c) => {
89
- u.value.scope = c;
90
- } })
91
- };
92
- }
93
- function Ut(s) {
94
- const u = p(s), c = De(() => ({ get: () => Array.from(u.value.cells), set: () => {
95
- } })), h = De(() => ({ get: () => u.value.cells.length, set: () => {
96
- } }));
97
- return {
98
- element: u,
99
- cells: c,
100
- cellCount: h,
101
- rowIndex: m(() => u.value.rowIndex),
102
- sectionRowIndex: m(() => u.value.sectionRowIndex),
103
- insertCell: (v) => u.value.insertCell(v),
104
- deleteCell: (v) => u.value.deleteCell(v),
105
- getCell: (v) => {
106
- const C = u.value.cells[v];
107
- return C ? ul(C) : void 0;
108
- }
109
- };
110
- }
111
- function Ze(s) {
112
- const u = p(s), c = De(() => ({ get: () => Array.from(u.value.rows), set: () => {
113
- } })), h = De(() => ({ get: () => u.value.rows.length, set: () => {
114
- } }));
115
- return {
116
- element: u,
117
- rows: c,
118
- rowCount: h,
119
- insertRow: (v) => u.value.insertRow(v),
120
- deleteRow: (v) => u.value.deleteRow(v),
121
- getRow: (v) => {
122
- const C = u.value.rows[v];
123
- return C ? Ut(C) : void 0;
22
+ function v() {
23
+ const e = [], o = l.tBodies;
24
+ for (let n = 0; n < o.length; n++) {
25
+ const s = o[n];
26
+ for (let a = 0; a < s.rows.length; a++)
27
+ e.push(s.rows[a]);
124
28
  }
125
- };
126
- }
127
- function zt(s) {
128
- return s.includes(",") || s.includes('"') || s.includes(`
129
- `) ? `"${s.replace(/"/g, '""')}"` : s;
130
- }
131
- function $t(s) {
132
- const u = [];
133
- let c = "", h = !1;
134
- for (let v = 0; v < s.length; v++) {
135
- const C = s[v];
136
- C === '"' ? h && v + 1 < s.length && s[v + 1] === '"' ? (c += '"', v++) : h = !h : C === "," && !h ? (u.push(c), c = "") : c += C;
29
+ return e;
137
30
  }
138
- return u.push(c), u;
139
- }
140
- function Tl(s) {
141
- const u = Kt([]), c = Kt([]), h = p(null), v = p(null), C = p(null), fe = p(0), E = () => {
142
- fe.value++;
143
- }, N = () => {
144
- s.value && (u.value = Array.from(s.value.rows), c.value = Array.from(s.value.tBodies), h.value = s.value.caption, v.value = s.value.tHead, C.value = s.value.tFoot);
145
- }, M = () => {
146
- N(), E();
147
- };
148
- N(), H(s, M, { immediate: !0, deep: !1 });
149
- const Te = m(() => u.value), jt = m(() => Te.value.length), Me = m(() => c.value), Wt = m(() => Me.value.length), Gt = m({
150
- get: () => h.value,
151
- set: (e) => {
152
- s.value.caption = e, h.value = e;
153
- }
154
- }), _t = m({
155
- get: () => v.value,
156
- set: (e) => {
157
- s.value.tHead = e, v.value = e;
158
- }
159
- }), Qt = m({
160
- get: () => C.value,
161
- set: (e) => {
162
- s.value.tFoot = e, C.value = e;
163
- }
164
- }), g = m({
165
- get: () => {
166
- fe.value;
167
- const e = s.value.tHead;
168
- return !e || e.rows.length === 0 ? [] : Array.from(e.rows[0].cells).map((t) => t.textContent || "");
169
- },
170
- set: (e) => {
171
- let t = s.value.tHead;
172
- for (t || (t = s.value.createTHead()); t.rows.length > 0; ) t.deleteRow(0);
173
- const o = t.insertRow();
174
- e.forEach((n) => {
175
- const r = document.createElement("th");
176
- r.textContent = n, r.scope = "col", o.appendChild(r);
177
- }), M();
178
- }
179
- }), f = m({
180
- get: () => {
181
- fe.value;
182
- const e = c.value[0];
183
- return e ? Array.from(e.rows).map((t) => Array.from(t.cells).map(re)) : [];
184
- },
185
- set: (e) => {
186
- let t = c.value[0];
187
- for (t || (t = s.value.createTBody()); t.rows.length > 0; ) t.deleteRow(0);
188
- e.forEach((o) => {
189
- const n = t.insertRow();
190
- o.forEach((r) => b(n.insertCell(), r));
191
- }), M();
192
- }
193
- }), It = m(() => g.value.length), qe = () => {
194
- const e = s.value.createCaption();
195
- return N(), e;
196
- }, xe = () => {
197
- s.value.deleteCaption(), N();
198
- }, Yt = () => {
199
- const e = s.value.createTHead();
200
- return N(), e;
201
- }, et = () => {
202
- s.value.deleteTHead(), N();
203
- }, tt = () => {
204
- const e = s.value.createTFoot();
205
- return N(), e;
206
- }, ot = () => {
207
- s.value.deleteTFoot(), N();
208
- }, Zt = () => {
209
- const e = s.value.createTBody();
210
- return N(), e;
211
- }, Xt = (e) => {
212
- const t = s.value.insertRow(e);
213
- return N(), t;
214
- }, qt = (e) => {
215
- s.value.deleteRow(e), N();
216
- }, xt = () => {
217
- const e = s.value.tHead;
218
- return e ? Ze(e) : void 0;
219
- }, eo = () => {
220
- const e = s.value.tFoot;
221
- return e ? Ze(e) : void 0;
222
- }, to = (e) => {
223
- const t = Me.value[e];
224
- return t ? Ze(t) : void 0;
225
- }, oo = (e) => {
226
- const t = Te.value[e];
227
- return t ? Ut(t) : void 0;
228
- }, de = (e, t) => {
229
- let o = c.value[0];
230
- o || (o = s.value.createTBody(), M());
231
- const n = t === void 0 || t === -1 ? o.rows.length : t, r = o.insertRow(n);
232
- return e.forEach((l) => b(r.insertCell(), l)), M(), r;
233
- }, Fe = (e) => {
234
- const t = c.value[0];
235
- t && (e === -1 && t.rows.length > 0 ? t.deleteRow(-1) : e >= 0 && e < t.rows.length && t.deleteRow(e), M());
236
- }, nt = (e = "", t = "", o) => {
237
- const n = g.value.length, r = o === void 0 || o === -1 ? n : o;
238
- let l = s.value.tHead;
239
- l || (l = s.value.createTHead(), l.insertRow()), l.rows.length === 0 && l.insertRow();
240
- const a = l.rows[0], i = Ee(e);
241
- r >= a.cells.length ? a.appendChild(i) : a.insertBefore(i, a.cells[r]);
242
- const d = c.value[0];
243
- d && Array.from(d.rows).forEach((y) => {
244
- const R = y.insertCell(r >= y.cells.length ? -1 : r);
245
- b(R, t);
246
- });
247
- const w = s.value.tFoot;
248
- if (w && w.rows.length > 0) {
249
- const y = w.rows[0];
250
- y.insertCell(r >= y.cells.length ? -1 : r).textContent = "";
251
- }
252
- M();
253
- }, rt = (e) => {
254
- if (e < 0 || e >= g.value.length) return;
255
- const t = s.value.tHead;
256
- t && t.rows.length > 0 && t.rows[0].cells[e] && t.rows[0].deleteCell(e);
257
- const o = c.value[0];
258
- o && Array.from(o.rows).forEach((r) => {
259
- r.cells[e] && r.deleteCell(e);
260
- });
261
- const n = s.value.tFoot;
262
- n && n.rows.length > 0 && n.rows[0].cells[e] && n.rows[0].deleteCell(e), M();
263
- }, Le = (e, t, o) => {
264
- const n = c.value[0];
265
- if (!n) return;
266
- const r = n.rows[e];
267
- if (!r) return;
268
- const l = r.cells[t];
269
- l && (b(l, o), E());
270
- }, ve = (e, t) => f.value[e]?.[t], no = (e) => {
271
- const t = s.value.caption || qe();
272
- t.textContent = e;
273
- }, z = (e) => {
274
- g.value = [...e];
275
- }, ro = (e) => {
276
- let t = s.value.tFoot;
277
- for (t || (t = tt()); t.rows.length > 0; ) t.deleteRow(0);
278
- const o = t.insertRow();
279
- e.forEach((n) => b(o.insertCell(), n));
280
- }, k = (e) => {
281
- f.value = e.map((t) => [...t]);
282
- }, so = () => {
283
- f.value = [];
284
- }, lo = () => {
285
- for (xe(), et(), ot(); c.value.length > 0; ) {
286
- const e = c.value[0];
287
- e && s.value.removeChild(e), M();
288
- }
289
- }, ao = () => {
290
- M();
291
- }, co = (e, t, o) => {
292
- let n = c.value[0];
293
- n || (n = s.value.createTBody(), M());
294
- const r = o === void 0 || o === -1 ? n.rows.length : o, l = n.insertRow(r);
295
- return me(l, t), e.forEach((a) => b(l.insertCell(), a)), M(), l;
296
- }, uo = (e, t) => {
297
- const o = g.value.length, n = t === void 0 || t === -1 ? o : t, r = typeof e.header == "string" ? e.header : String(e.header.value), l = typeof e.header == "string" ? void 0 : e.header.attributes, a = e.defaultValue ?? "";
298
- let i = s.value.tHead;
299
- i || (i = s.value.createTHead(), i.insertRow()), i.rows.length === 0 && i.insertRow();
300
- const d = i.rows[0], w = Ee(r, l);
301
- n >= d.cells.length ? d.appendChild(w) : d.insertBefore(w, d.cells[n]);
302
- const y = c.value[0];
303
- y && Array.from(y.rows).forEach((R) => {
304
- const ie = R.insertCell(n >= R.cells.length ? -1 : n);
305
- e.defaultAttributes && me(ie, e.defaultAttributes), b(ie, a);
306
- }), M();
307
- }, io = (e) => {
308
- let t = s.value.tHead;
309
- for (t || (t = s.value.createTHead()); t.rows.length > 0; ) t.deleteRow(0);
310
- const o = t.insertRow();
311
- e.forEach((n) => {
312
- if (typeof n == "string")
313
- o.appendChild(Ee(n));
314
- else {
315
- const r = Ee(String(n.value), n.attributes);
316
- n.columnSpan !== void 0 && (r.colSpan = n.columnSpan), n.rowSpan !== void 0 && (r.rowSpan = n.rowSpan), o.appendChild(r);
317
- }
318
- }), M();
319
- }, st = (e, t, o, n) => {
320
- const r = c.value[0];
321
- if (!r) return;
322
- const l = r.rows[e];
323
- if (!l) return;
324
- const a = l.cells[t];
325
- a && (b(a, o), me(a, n), E());
326
- }, lt = (e) => {
327
- const t = f.value[e];
328
- return t ? [...t] : void 0;
329
- }, He = (e, t) => {
330
- const o = c.value[0];
331
- if (!o) return;
332
- const n = o.rows[e];
333
- n && (t.forEach((r, l) => {
334
- n.cells[l] && b(n.cells[l], r);
335
- }), E());
336
- }, fo = () => f.value.map((e) => [...e]), vo = (e) => e < 0 || e >= g.value.length ? [] : f.value.map((t) => t[e]), wo = (e, t) => {
337
- const o = c.value[0];
338
- !o || e < 0 || e >= g.value.length || (t.forEach((n, r) => {
339
- const l = o.rows[r];
340
- l && l.cells[e] && b(l.cells[e], n);
341
- }), E());
342
- }, ho = (e, t, o, n) => {
343
- const r = [];
344
- for (let l = e; l < t && l < f.value.length; l++) {
345
- const a = f.value[l], i = [];
346
- for (let d = o; d < n && d < a.length; d++) i.push(a[d]);
347
- r.push(i);
348
- }
349
- return r;
350
- }, go = (e, t, o) => {
351
- const n = c.value[0];
352
- n && (o.forEach((r, l) => {
353
- const a = n.rows[e + l];
354
- a && r.forEach((i, d) => {
355
- const w = a.cells[t + d];
356
- w && b(w, i);
357
- });
358
- }), E());
359
- }, po = () => [...g.value], yo = () => {
360
- const e = s.value.tFoot;
361
- if (!(!e || e.rows.length === 0))
362
- return Array.from(e.rows[0].cells).map(re);
363
- }, mo = (e, t) => {
364
- const o = s.value.tFoot;
365
- if (!o || o.rows.length === 0) return;
366
- const n = o.rows[0].cells[e];
367
- n && b(n, t);
368
- }, Co = (e) => {
369
- const t = s.value.tFoot;
370
- if (!t || t.rows.length === 0) return;
371
- const o = t.rows[0].cells[e];
372
- return o ? re(o) : void 0;
373
- }, Ne = (e, t, o) => {
374
- st(e, t, o.value, o.attributes);
375
- const n = c.value[0];
376
- if (n && n.rows[e]) {
377
- const r = n.rows[e].cells[t];
378
- r && (o.columnSpan !== void 0 && (r.colSpan = o.columnSpan), o.rowSpan !== void 0 && (r.rowSpan = o.rowSpan));
379
- }
380
- }, ke = (e, t) => {
381
- const o = c.value[0];
382
- if (!o) return;
383
- const n = o.rows[e];
384
- n && (t.forEach((r, l) => {
385
- const a = n.cells[l];
386
- a && b(a, r);
387
- }), E());
388
- }, at = (e, t) => {
389
- const o = c.value[0];
390
- return o ? o.rows[e]?.cells[t] : void 0;
391
- }, Ro = (e) => c.value[0]?.rows[e], So = (e) => e.filter((t) => t >= 0 && t < f.value.length).map((t) => [...f.value[t]]), bo = (e) => e.filter((t) => t >= 0 && t < g.value.length).map((t) => f.value.map((o) => o[t])), Eo = (e) => {
392
- e.forEach((t, o) => ke(o, t));
393
- }, Ao = (e) => {
394
- e.forEach((t, [o, n]) => {
395
- Ae(t) ? Ne(o, n, t) : Le(o, n, t);
396
- });
397
- }, Do = () => {
398
- const e = c.value[0];
399
- return e ? Array.from(e.rows) : [];
400
- }, To = (e) => {
401
- const t = c.value[0];
402
- return !t || e < 0 || e >= t.rows.length ? [] : Array.from(t.rows[e].cells);
403
- }, Mo = (e, t) => {
404
- e < 0 || t.forEach((o, n) => {
405
- const r = e + n;
406
- if (r < f.value.length)
407
- ke(r, o);
408
- else {
409
- const l = o.map((a) => Ae(a) ? a.value : a);
410
- de(l, r), o.forEach((a, i) => {
411
- Ae(a) && (a.attributes || a.columnSpan !== void 0 || a.rowSpan !== void 0) && Ne(r, i, a);
412
- });
413
- }
414
- });
415
- }, Fo = (e, t, o) => {
416
- const n = f.value[e]?.[t], r = o(n);
417
- return r === !0 ? !0 : { row: e, column: t, value: n, message: typeof r == "string" ? r : "Validation failed" };
418
- }, Lo = (e, t) => {
419
- const o = f.value[e];
420
- if (!o) return [{ row: e, column: -1, value: void 0, message: "Row not found" }];
421
- const n = t([...o]);
422
- return n === !0 ? !0 : [{ row: e, column: -1, value: o, message: typeof n == "string" ? n : "Validation failed" }];
423
- }, Ho = (e, t) => {
424
- const o = [];
425
- return f.value.forEach((n, r) => {
426
- const l = n[e], a = t(l);
427
- a !== !0 && o.push({ row: r, column: e, value: l, message: typeof a == "string" ? a : "Validation failed" });
428
- }), o.length === 0 ? !0 : o;
429
- }, No = (e) => {
430
- const t = [];
431
- return f.value.forEach((o, n) => {
432
- o.forEach((r, l) => {
433
- const a = e(r, n, l);
434
- a !== null && t.push({ row: n, column: l, value: r, message: a });
435
- });
436
- }), { valid: t.length === 0, errors: t };
437
- }, ko = (e) => f.value.reduce((t, o) => {
438
- const n = Number(o[e]);
439
- return t + (isNaN(n) ? 0 : n);
440
- }, 0), Vo = (e) => {
441
- let t = 0;
442
- const o = f.value.reduce((n, r) => {
443
- const l = Number(r[e]);
444
- return isNaN(l) ? n : (t++, n + l);
445
- }, 0);
446
- return t > 0 ? o / t : 0;
447
- }, Bo = (e) => {
448
- const t = f.value.map((o) => o[e]).filter((o) => o != null);
449
- if (t.length !== 0)
450
- return t.reduce((o, n) => o < n ? o : n);
451
- }, Oo = (e) => {
452
- const t = f.value.map((o) => o[e]).filter((o) => o != null);
453
- if (t.length !== 0)
454
- return t.reduce((o, n) => o > n ? o : n);
455
- }, Po = (e, t) => {
456
- const o = f.value.map((n) => n[e]);
457
- return t ? o.filter(t).length : o.length;
458
- }, Ko = (e, t) => f.value.reduce((o, n, r) => t.reducer(o, n[e], r), t.initial), zo = (e, t) => {
459
- const o = c.value[0];
460
- o && (Array.from(o.rows).forEach((n, r) => {
461
- const l = n.cells[e];
462
- if (l) {
463
- const a = t(re(l), r);
464
- b(l, a);
465
- }
466
- }), E());
467
- }, $o = (e, t) => {
468
- const o = c.value[0];
469
- if (!o) return;
470
- const n = o.rows[e];
471
- n && (Array.from(n.cells).forEach((r, l) => {
472
- const a = t(re(r), l);
473
- b(r, a);
474
- }), E());
475
- }, Jo = (e) => {
476
- const t = c.value[0];
477
- t && (Array.from(t.rows).forEach((o, n) => {
478
- Array.from(o.cells).forEach((r, l) => {
479
- const a = e(re(r), n, l);
480
- b(r, a);
481
- });
482
- }), E());
483
- }, Uo = () => {
484
- const e = [];
485
- return g.value.length > 0 && e.push(g.value.map((t) => zt(t)).join(",")), f.value.forEach((t) => {
486
- e.push(t.map((o) => zt(String(o ?? ""))).join(","));
487
- }), e.join(`
488
- `);
489
- }, jo = () => JSON.stringify({ headers: g.value, data: f.value }), Wo = (e) => {
490
- k(e);
491
- }, Go = (e) => {
492
- const t = e.split(`
493
- `).filter((r) => r.trim());
494
- if (t.length === 0) return;
495
- const o = $t(t[0]);
496
- z(o);
497
- const n = t.slice(1).map($t);
498
- k(n);
499
- }, _o = (e) => {
500
- const t = JSON.parse(e);
501
- t.headers && z(t.headers), t.data && k(t.data);
502
- }, Qo = (e, t) => {
503
- const o = [], n = t?.caseSensitive ? e : e.toLowerCase();
504
- return f.value.forEach((r, l) => {
505
- r.forEach((a, i) => {
506
- const d = String(a ?? "");
507
- (t?.caseSensitive ? d : d.toLowerCase()).includes(n) && o.push({ row: l, column: i, value: a });
508
- });
509
- }), o;
510
- }, Io = (e, t, o) => {
511
- const n = [], r = o?.caseSensitive ? t : t.toLowerCase();
512
- return f.value.forEach((l, a) => {
513
- const i = l[e], d = String(i ?? "");
514
- (o?.caseSensitive ? d : d.toLowerCase()).includes(r) && n.push({ row: a, column: e, value: i });
515
- }), n;
516
- }, S = p(/* @__PURE__ */ new Set()), se = p(/* @__PURE__ */ new Set()), Ve = (e) => {
517
- S.value = /* @__PURE__ */ new Set([...S.value, e]);
518
- }, Be = (e) => {
519
- const t = new Set(S.value);
520
- t.delete(e), S.value = t;
521
- }, Yo = (e) => {
522
- S.value.has(e) ? Be(e) : Ve(e);
523
- }, Zo = (e) => S.value.has(e), Xo = (e, t) => {
524
- se.value = /* @__PURE__ */ new Set([...se.value, `${e},${t}`]);
525
- }, qo = () => {
526
- S.value = /* @__PURE__ */ new Set(), se.value = /* @__PURE__ */ new Set();
527
- }, Oe = /* @__PURE__ */ new Map();
528
- function ct(e, t, o, n) {
529
- let r = e.textContent;
530
- const l = () => {
531
- const d = e.textContent ?? "";
532
- if ("validator" in n && n.validator && n.validator(d, t, o) !== !0) {
533
- e.textContent = r;
534
- return;
535
- }
536
- const w = "parser" in n && n.parser ? n.parser(d, t, o) : d;
537
- E(), n.onEdit?.(w, t, o);
538
- }, a = (d) => {
539
- ut(d) && (d.key === "Enter" ? (d.preventDefault(), e.blur()) : d.key === "Escape" && (d.preventDefault(), e.textContent = r, e.blur()));
540
- }, i = () => {
541
- r = e.textContent;
542
- };
543
- e.addEventListener("blur", l), e.addEventListener("keydown", a), e.addEventListener("focus", i), Oe.set(e, { blur: l, keydown: a, focus: i });
31
+ function P(e, o, n) {
32
+ F.forEach((s) => s(e, o, n)), y();
33
+ }
34
+ function j(e, o, n) {
35
+ f.forEach((s) => s(e, o, n)), y();
544
36
  }
545
- function Ce(e) {
546
- const t = Oe.get(e);
547
- t && (e.removeEventListener("blur", t.blur), e.removeEventListener("keydown", t.keydown), e.removeEventListener("focus", t.focus), Oe.delete(e)), e.contentEditable = "false";
37
+ function z(e, o, n, s) {
38
+ h.forEach((a) => a(e, o, n, s)), y();
548
39
  }
549
- function ut(e) {
550
- return "key" in e;
40
+ function V(e, o, n, s) {
41
+ D.forEach((a) => a(e, o, n, s)), y();
551
42
  }
552
- function xo(e, t, o) {
553
- return o.editableRows && !o.editableRows.includes(e) ? !1 : !(o.editableColumns && !o.editableColumns.includes(t));
43
+ function T() {
44
+ const e = d.getHeaders();
45
+ p.forEach((o) => o(e));
554
46
  }
555
- let Re = null, Pe = null;
556
- const Ke = (e = {}) => {
557
- Re = { cells: !0, ...e };
558
- const t = c.value[0];
559
- t && Array.from(t.rows).forEach((o, n) => {
560
- Array.from(o.cells).forEach((r, l) => {
561
- xo(n, l, Re) && (r.contentEditable = "true", ct(r, n, l, Re));
47
+ function y() {
48
+ if (I.size > 0) {
49
+ const e = d.getData();
50
+ I.forEach((o) => o(e));
51
+ }
52
+ }
53
+ function L(e) {
54
+ const o = [];
55
+ for (let n = 0; n < e.cells.length; n++)
56
+ o.push(A(e.cells[n]));
57
+ return o;
58
+ }
59
+ const d = {
60
+ // ======================================================================
61
+ // ELEMENT ACCESS
62
+ // ======================================================================
63
+ element: l,
64
+ getCaption() {
65
+ return l.caption;
66
+ },
67
+ getTHead() {
68
+ return l.tHead;
69
+ },
70
+ getTFoot() {
71
+ return l.tFoot;
72
+ },
73
+ getTBodies() {
74
+ return l.tBodies;
75
+ },
76
+ getPrimaryTBody() {
77
+ return E();
78
+ },
79
+ getBodyRows() {
80
+ return v();
81
+ },
82
+ getRow(e) {
83
+ return v()[e];
84
+ },
85
+ getRowById(e) {
86
+ const o = v();
87
+ for (const n of o)
88
+ if (n.dataset.id === e)
89
+ return n;
90
+ },
91
+ getCell(e, o) {
92
+ const n = d.getRow(e);
93
+ if (n)
94
+ return n.cells[o];
95
+ },
96
+ getCellByRowId(e, o) {
97
+ const n = d.getRowById(e);
98
+ if (n)
99
+ return n.cells[o];
100
+ },
101
+ // ======================================================================
102
+ // DATA ACCESS
103
+ // ======================================================================
104
+ getHeaders() {
105
+ const e = l.tHead;
106
+ if (!e || e.rows.length === 0) return [];
107
+ const o = e.rows[0], n = [];
108
+ for (let s = 0; s < o.cells.length; s++)
109
+ n.push(o.cells[s].textContent ?? "");
110
+ return n;
111
+ },
112
+ getHeader(e) {
113
+ return d.getHeaders()[e];
114
+ },
115
+ getData() {
116
+ return v().map(L);
117
+ },
118
+ getRowData(e) {
119
+ const o = d.getRow(e);
120
+ if (o)
121
+ return L(o);
122
+ },
123
+ getRowDataById(e) {
124
+ const o = d.getRowById(e);
125
+ if (o)
126
+ return L(o);
127
+ },
128
+ getCellValue(e, o) {
129
+ const n = d.getCell(e, o);
130
+ if (n)
131
+ return A(n);
132
+ },
133
+ getColumnData(e) {
134
+ return v().map((n) => {
135
+ const s = n.cells[e];
136
+ return s ? A(s) : void 0;
562
137
  });
563
- });
564
- }, en = () => {
565
- Re = null;
566
- const e = c.value[0];
567
- e && Array.from(e.rows).forEach((t) => {
568
- Array.from(t.cells).forEach(Ce);
569
- });
570
- }, tn = (e = {}) => {
571
- Pe = e;
572
- const o = s.value.tHead?.rows[0];
573
- o && Array.from(o.cells).forEach((n, r) => {
574
- n.contentEditable = "true", ct(n, -1, r, Pe);
575
- });
576
- }, on = () => {
577
- Pe = null;
578
- const t = s.value.tHead?.rows[0];
579
- t && Array.from(t.cells).forEach(Ce);
580
- }, nn = (e, t = {}) => {
581
- Ke({ ...t, editableColumns: [e] });
582
- }, rn = (e) => {
583
- const t = c.value[0];
584
- t && Array.from(t.rows).forEach((o) => {
585
- const n = o.cells[e];
586
- n && Ce(n);
587
- });
588
- }, sn = (e, t = {}) => {
589
- Ke({ ...t, editableRows: [e] });
590
- }, ln = (e) => {
591
- const t = c.value[0];
592
- if (!t) return;
593
- const o = t.rows[e];
594
- o && Array.from(o.cells).forEach(Ce);
595
- }, an = () => {
596
- const e = c.value[0];
597
- if (!e) return () => {
598
- };
599
- const t = (o) => {
600
- const n = o.target;
601
- if (!(n instanceof HTMLTableCellElement) || n.tagName !== "TD" || !(n.parentElement instanceof HTMLTableRowElement)) return;
602
- n.contentEditable = "true", n.focus();
603
- const l = window.getSelection();
604
- if (l) {
605
- const w = document.createRange();
606
- w.selectNodeContents(n), l.removeAllRanges(), l.addRange(w);
138
+ },
139
+ getFooterData() {
140
+ const e = l.tFoot;
141
+ if (!(!e || e.rows.length === 0))
142
+ return L(e.rows[0]);
143
+ },
144
+ getRowCount() {
145
+ return v().length;
146
+ },
147
+ getColumnCount() {
148
+ const e = d.getHeaders();
149
+ if (e.length > 0) return e.length;
150
+ const o = v();
151
+ return o.length > 0 ? o[0].cells.length : 0;
152
+ },
153
+ getRowId(e) {
154
+ return d.getRow(e)?.dataset.id;
155
+ },
156
+ getRowIndex(e) {
157
+ const o = v();
158
+ for (let n = 0; n < o.length; n++)
159
+ if (o[n].dataset.id === e)
160
+ return n;
161
+ return -1;
162
+ },
163
+ getAllRowIds() {
164
+ const e = v(), o = [];
165
+ for (const n of e)
166
+ n.dataset.id && o.push(n.dataset.id);
167
+ return o;
168
+ },
169
+ // ======================================================================
170
+ // STRUCTURE METHODS
171
+ // ======================================================================
172
+ createCaption() {
173
+ return l.createCaption();
174
+ },
175
+ deleteCaption() {
176
+ l.deleteCaption();
177
+ },
178
+ createTHead() {
179
+ return l.createTHead();
180
+ },
181
+ deleteTHead() {
182
+ l.deleteTHead(), T();
183
+ },
184
+ createTFoot() {
185
+ return l.createTFoot();
186
+ },
187
+ deleteTFoot() {
188
+ l.deleteTFoot();
189
+ },
190
+ createTBody() {
191
+ return l.createTBody();
192
+ },
193
+ // ======================================================================
194
+ // HEADER METHODS
195
+ // ======================================================================
196
+ setHeaders(e) {
197
+ let o = l.tHead;
198
+ for (o || (o = l.createTHead()); o.rows.length > 0; )
199
+ o.deleteRow(0);
200
+ const n = o.insertRow();
201
+ for (const s of e)
202
+ n.appendChild(oe(s));
203
+ T();
204
+ },
205
+ setHeader(e, o) {
206
+ const n = l.tHead;
207
+ if (!n || n.rows.length === 0) return;
208
+ const s = n.rows[0].cells[e];
209
+ s && (s.textContent = o, T());
210
+ },
211
+ addHeader(e, o) {
212
+ let n = l.tHead;
213
+ n || (n = l.createTHead(), n.insertRow()), n.rows.length === 0 && n.insertRow();
214
+ const s = n.rows[0], a = oe(e);
215
+ o === void 0 || o >= s.cells.length ? s.appendChild(a) : s.insertBefore(a, s.cells[o]), T();
216
+ },
217
+ removeHeader(e) {
218
+ const o = l.tHead;
219
+ if (!o || o.rows.length === 0) return;
220
+ const n = o.rows[0];
221
+ e >= 0 && e < n.cells.length && (n.deleteCell(e), T());
222
+ },
223
+ // ======================================================================
224
+ // ROW METHODS
225
+ // ======================================================================
226
+ addRow(e, o, n) {
227
+ const s = E(), a = o ?? s.rows.length, i = s.insertRow(a), g = n ?? c();
228
+ i.dataset.id = g;
229
+ for (const w of e) {
230
+ const B = i.insertCell();
231
+ S(B, w);
607
232
  }
608
- const a = n.textContent, i = () => {
609
- n.contentEditable = "false", n.removeEventListener("blur", i), n.removeEventListener("keydown", d), E();
610
- }, d = (w) => {
611
- ut(w) && (w.key === "Enter" ? (w.preventDefault(), n.blur()) : w.key === "Escape" && (n.textContent = a, n.blur()));
612
- };
613
- n.addEventListener("blur", i), n.addEventListener("keydown", d);
614
- };
615
- return e.addEventListener("dblclick", t), () => e.removeEventListener("dblclick", t);
616
- }, cn = (e) => {
617
- const t = /* @__PURE__ */ new Map();
618
- return f.value.forEach((o, n) => {
619
- const r = e(o), l = t.get(r) || [];
620
- l.push(n), t.set(r, l);
621
- }), t;
622
- }, ze = /* @__PURE__ */ new Map(), un = (e) => {
623
- const t = e.index ?? g.value.length, o = f.value.map((l) => [...l]);
624
- nt(e.label, void 0, t);
625
- const n = c.value[0];
626
- n && Array.from(n.rows).forEach((l, a) => {
627
- const i = l.cells[t];
628
- if (i) {
629
- const d = o[a] ?? [], w = e.computeFunction(d);
630
- b(i, w);
233
+ return P([...e], a, g), i;
234
+ },
235
+ removeRow(e) {
236
+ const o = v();
237
+ if (e < 0 || e >= o.length) return;
238
+ const n = o[e], s = L(n), a = n.dataset.id;
239
+ return n.remove(), j(s, e, a), s;
240
+ },
241
+ removeRowById(e) {
242
+ const o = d.getRowIndex(e);
243
+ if (o !== -1)
244
+ return d.removeRow(o);
245
+ },
246
+ updateRow(e, o) {
247
+ const n = d.getRow(e);
248
+ if (!n) return;
249
+ const s = L(n), a = n.dataset.id;
250
+ for (let i = 0; i < o.length; i++) {
251
+ let g = n.cells[i];
252
+ g || (g = n.insertCell()), S(g, o[i]);
631
253
  }
632
- }), E();
633
- const r = H(() => f.value, () => {
634
- const l = c.value[0];
635
- l && Array.from(l.rows).forEach((a, i) => {
636
- const d = a.cells[t];
637
- if (d) {
638
- const y = (f.value[i] ?? []).filter((ie, ll) => ll !== t), R = e.computeFunction(y);
639
- b(d, R);
640
- }
641
- });
642
- }, { deep: !0, flush: "sync" });
643
- return ze.set(t, { config: e, stopWatcher: r }), t;
644
- }, fn = (e) => {
645
- const t = ze.get(e);
646
- t && (t.stopWatcher && t.stopWatcher(), ze.delete(e), rt(e));
647
- };
648
- let A = null;
649
- const we = () => {
650
- if (!A) return;
651
- const { currentPage: e, pageSize: t } = A, o = f.value.length, n = (e.value - 1) * t.value, r = Math.min(n + t.value, o), l = [];
652
- for (let i = n; i < r; i++) l.push(i);
653
- A.visibleRows.value = l;
654
- const a = c.value[0];
655
- a && Array.from(a.rows).forEach((i, d) => {
656
- i.style.display = l.includes(d) ? "" : "none";
657
- });
658
- }, dn = (e) => {
659
- const t = p(e.currentPage ?? 1), o = p(e.pageSize), n = p([]);
660
- A = {
661
- totalPages: m(() => Math.ceil(f.value.length / o.value) || 1),
662
- currentPage: t,
663
- pageSize: o,
664
- visibleRows: n
665
- }, we(), H(() => f.value.length, () => {
666
- const r = A.totalPages.value;
667
- t.value > r && (t.value = r), we();
668
- });
669
- }, vn = () => {
670
- A && A.currentPage.value < A.totalPages.value && (A.currentPage.value++, we());
671
- }, wn = () => {
672
- A && A.currentPage.value > 1 && (A.currentPage.value--, we());
673
- }, hn = (e) => {
674
- A && e >= 1 && e <= A.totalPages.value && (A.currentPage.value = e, we());
675
- };
676
- let D = null;
677
- const it = () => {
678
- if (!D) return;
679
- const { scrollTop: e, rowHeight: t, overscan: o, containerHeight: n } = D, r = f.value.length, l = Math.floor(e.value / t), a = Math.min(Math.ceil((e.value + n) / t), r), i = Math.max(0, l - o), d = Math.min(r, a + o), w = [];
680
- for (let R = i; R < d; R++) w.push(R);
681
- D.visibleRows.value = w, D.startIndex.value = i, D.endIndex.value = d;
682
- const y = c.value[0];
683
- y && (Array.from(y.rows).forEach((R, ie) => {
684
- w.includes(ie) ? (R.style.display = "", R.style.transform = `translateY(${ie * t}px)`) : R.style.display = "none";
685
- }), y.style.height = `${r * t}px`, y.style.position = "relative");
686
- }, gn = (e) => {
687
- const t = p(0);
688
- D = {
689
- scrollTop: t,
690
- rowHeight: e.rowHeight,
691
- overscan: e.overscan,
692
- containerHeight: e.containerHeight,
693
- visibleRows: p([]),
694
- startIndex: p(0),
695
- endIndex: p(0)
696
- };
697
- const o = s.value.parentElement;
698
- if (o) {
699
- const n = () => {
700
- t.value = o.scrollTop, it();
701
- };
702
- o.addEventListener("scroll", n), D.scrollHandler = n, D.container = o, it();
703
- const r = c.value[0];
704
- r && Array.from(r.rows).forEach((l) => {
705
- l.style.position = "absolute", l.style.width = "100%", l.style.left = "0";
706
- });
707
- }
708
- }, pn = () => {
709
- if (!D) return;
710
- D.container && D.scrollHandler && D.container.removeEventListener("scroll", D.scrollHandler);
711
- const e = c.value[0];
712
- e && (e.style.height = "", e.style.position = "", Array.from(e.rows).forEach((t) => {
713
- t.style.display = "", t.style.position = "", t.style.transform = "", t.style.width = "", t.style.left = "";
714
- })), D = null;
715
- }, yn = () => ({
716
- data: JSON.parse(JSON.stringify(f.value)),
717
- headers: [...g.value]
718
- }), ft = (e) => {
719
- g.value = [...e.headers], f.value = e.data.map((t) => [...t]);
720
- }, mn = (e) => {
721
- const t = yn();
722
- try {
723
- const o = e();
724
- return o instanceof Promise ? o.catch((n) => {
725
- throw ft(t), n;
726
- }) : o;
727
- } catch (o) {
728
- throw ft(t), o;
729
- }
730
- }, Cn = (e) => H(() => f.value, (t) => {
731
- e([...t.map((o) => [...o])]);
732
- }, { deep: !0 }), W = p(null), $ = p(!1), G = p(!1), Rn = {
733
- columnIndex: W,
734
- ascending: $,
735
- descending: G
736
- }, dt = (e, t) => {
737
- const o = String(e ?? ""), n = String(t ?? ""), r = Number(o), l = Number(n);
738
- return !isNaN(r) && !isNaN(l) ? r - l : o.localeCompare(n);
739
- }, Se = (e, t, o) => {
740
- const n = c.value[0];
741
- if (!n || n.rows.length === 0) return;
742
- const r = [];
743
- for (let l = 0; l < n.rows.length; l++) {
744
- const a = n.rows[l];
745
- if (a) {
746
- const i = a.cells[e], d = i ? re(i) : "";
747
- r.push({ element: a, value: d });
254
+ for (; n.cells.length > o.length; )
255
+ n.deleteCell(n.cells.length - 1);
256
+ z(e, s, [...o], a);
257
+ },
258
+ updateRowById(e, o) {
259
+ const n = d.getRowIndex(e);
260
+ n !== -1 && d.updateRow(n, o);
261
+ },
262
+ moveRow(e, o) {
263
+ const n = v();
264
+ if (e < 0 || e >= n.length || o < 0 || o >= n.length || e === o) return;
265
+ const s = n[e], a = s.parentElement;
266
+ if (o > e) {
267
+ const i = n[o];
268
+ a.insertBefore(s, i.nextSibling);
269
+ } else {
270
+ const i = n[o];
271
+ a.insertBefore(s, i);
748
272
  }
749
- }
750
- r.sort((l, a) => {
751
- const i = t(l.value, a.value);
752
- return o ? i : -i;
753
- }), r.forEach(({ element: l }) => {
754
- n.appendChild(l);
755
- }), W.value = e, $.value = o, G.value = !o, E();
756
- }, Sn = (e) => {
757
- Se(e, dt, !0);
758
- }, bn = (e) => {
759
- Se(e, dt, !1);
760
- }, En = (e, t) => {
761
- Se(e, t, !0);
762
- }, An = (e, t) => {
763
- Se(e, t, !1);
764
- }, Dn = () => {
765
- W.value = null, $.value = !1, G.value = !1;
766
- }, Tn = () => W.value, Mn = () => W.value === null || $.value === G.value ? !1 : $.value, Fn = () => W.value === null || $.value === G.value ? !1 : G.value, Ln = () => W.value === null || $.value === G.value ? !1 : $.value || G.value, Q = p([]), vt = m(() => Q.value.length > 0), Hn = m(() => vt.value ? Q.value.length : f.value.length), Nn = {
767
- isFiltered: vt,
768
- filteredRowCount: Hn,
769
- filteredIndices: Q
770
- }, wt = (e) => {
771
- const t = c.value[0];
772
- if (!t) return;
773
- const o = [], n = f.value;
774
- for (let r = 0; r < n.length; r++) {
775
- const l = n[r];
776
- l && e(l, r) && o.push(r);
777
- }
778
- Q.value = o;
779
- for (let r = 0; r < t.rows.length; r++) {
780
- const l = t.rows[r];
781
- l && (l.style.display = o.includes(r) ? "" : "none");
782
- }
783
- }, $e = (e, t) => {
784
- wt((o) => {
785
- const n = o[e];
786
- return t(n);
787
- });
788
- }, kn = (e, t) => {
789
- const o = String(t ?? "");
790
- $e(e, (n) => String(n ?? "") === o);
791
- }, Vn = (e, t) => {
792
- const o = new Set(t.map((n) => String(n ?? "")));
793
- $e(e, (n) => o.has(String(n ?? "")));
794
- }, Bn = () => {
795
- const e = c.value[0];
796
- if (e)
797
- for (let t = 0; t < e.rows.length; t++) {
798
- const o = e.rows[t];
799
- o && (o.style.display = "");
273
+ y();
274
+ },
275
+ swapRows(e, o) {
276
+ const n = v();
277
+ if (e < 0 || e >= n.length || o < 0 || o >= n.length || e === o) return;
278
+ const s = n[e], a = n[o], i = s.parentElement, g = document.createElement("tr");
279
+ i.insertBefore(g, s), i.insertBefore(s, a), i.insertBefore(a, g), g.remove(), y();
280
+ },
281
+ clearRows() {
282
+ const e = l.tBodies;
283
+ for (let o = 0; o < e.length; o++) {
284
+ const n = e[o];
285
+ for (; n.rows.length > 0; )
286
+ n.deleteRow(0);
800
287
  }
801
- Q.value = [];
802
- }, On = () => Q.value;
803
- let J = null;
804
- const Pn = (e) => {
805
- J = e;
806
- }, Kn = () => {
807
- J = null;
808
- }, zn = () => J !== null, $n = (e) => {
809
- if (!J) return;
810
- const t = f.value[e];
811
- if (t)
812
- return J(t, e);
813
- }, Jn = () => J ? f.value.map((e, t) => J(e, t)) : [], he = (e) => {
814
- if (!J) return;
815
- const t = f.value;
816
- for (let o = 0; o < t.length; o++) {
817
- const n = t[o];
818
- if (n && J(n, o) === e)
819
- return o;
820
- }
821
- }, Un = (e) => {
822
- const t = he(e);
823
- if (t === void 0) return;
824
- const o = f.value[t];
825
- return o ? [...o] : void 0;
826
- }, jn = (e, t) => {
827
- const o = he(e);
828
- return o === void 0 ? !1 : (He(o, t), !0);
829
- }, Wn = (e) => {
830
- const t = he(e);
831
- return t === void 0 ? !1 : (Fe(t), !0);
832
- }, Gn = (e) => he(e) !== void 0, P = /* @__PURE__ */ new Map(), _n = (e, t) => {
833
- P.set(e, t);
834
- }, Qn = (e) => {
835
- P.clear(), e.forEach((t, o) => {
836
- t && P.set(o, t);
837
- });
838
- }, In = (e) => {
839
- P.delete(e);
840
- }, Yn = () => {
841
- P.clear();
842
- }, Zn = (e) => P.get(e), Xn = (e) => P.has(e), Je = (e, t) => {
843
- if (t.parser)
844
- return t.parser(e);
845
- const o = String(e ?? "");
846
- if (t.nullable && (e == null || o === ""))
847
- return null;
848
- switch (t.type) {
849
- case "number":
850
- return Number(o);
851
- case "boolean":
852
- return o === "true" || o === "1";
853
- case "date":
854
- return new Date(o);
855
- default:
856
- return o;
857
- }
858
- }, qn = (e, t) => {
859
- const o = ve(e, t), n = P.get(t);
860
- return n ? Je(o, n) : o;
861
- }, ht = (e) => {
862
- const t = f.value[e];
863
- return t ? t.map((o, n) => {
864
- const r = P.get(n);
865
- return r ? Je(o, r) : o;
866
- }) : [];
867
- }, xn = (e) => {
868
- const t = P.get(e);
869
- return f.value.map((o) => {
870
- const n = o[e];
871
- return t ? Je(n, t) : n;
872
- });
873
- }, er = () => f.value.map((e, t) => ht(t)), ge = p(!1), Ue = p(null), I = /* @__PURE__ */ new Map(), tr = () => {
874
- ge.value = !1, Ue.value = JSON.parse(JSON.stringify(f.value)), I.clear();
875
- }, or = () => {
876
- ge.value = !0;
877
- }, nr = () => ge.value, rr = () => I.size > 0, sr = () => Array.from(I.values()), lr = () => {
878
- const e = /* @__PURE__ */ new Set();
879
- for (const t of I.values())
880
- e.add(t.row);
881
- return Array.from(e).sort((t, o) => t - o);
882
- }, ar = () => {
883
- const e = /* @__PURE__ */ new Set();
884
- for (const t of I.values())
885
- e.add(t.column);
886
- return Array.from(e).sort((t, o) => t - o);
887
- };
888
- H(() => f.value, (e) => {
889
- if (Ue.value === null) return;
890
- const t = Ue.value;
891
- for (let o = 0; o < Math.max(e.length, t.length); o++) {
892
- const n = e[o] ?? [], r = t[o] ?? [], l = Math.max(n.length, r.length);
893
- for (let a = 0; a < l; a++) {
894
- const i = n[a], d = r[a], w = `${o},${a}`;
895
- String(i ?? "") !== String(d ?? "") ? (I.set(w, { row: o, column: a, oldValue: d, newValue: i }), ge.value = !0) : I.delete(w);
288
+ y();
289
+ },
290
+ // ======================================================================
291
+ // COLUMN METHODS
292
+ // ======================================================================
293
+ addColumn(e, o, n) {
294
+ d.addHeader(e, n);
295
+ const s = v();
296
+ for (const i of s) {
297
+ const g = i.insertCell(n ?? i.cells.length);
298
+ S(g, o ?? "");
896
299
  }
897
- }
898
- }, { deep: !0 });
899
- const U = [], Y = [];
900
- let je = 50, le = "", Z = !1;
901
- const gt = () => ({
902
- data: JSON.parse(JSON.stringify(f.value)),
903
- headers: [...g.value]
904
- }), We = () => JSON.stringify({ data: f.value, headers: g.value });
905
- H([() => f.value, () => g.value], () => {
906
- if (Z) return;
907
- const e = We();
908
- if (e !== le) {
909
- if (le !== "") {
910
- const t = JSON.parse(le);
911
- (t.data.length > 0 || t.headers.length > 0) && (U.push({ data: t.data, headers: t.headers }), U.length > je && U.shift(), Y.length = 0);
300
+ const a = l.tFoot;
301
+ if (a && a.rows.length > 0) {
302
+ const i = a.rows[0], g = i.insertCell(n ?? i.cells.length);
303
+ S(g, "");
912
304
  }
913
- le = e;
914
- }
915
- }, { deep: !0, flush: "sync" });
916
- const cr = () => {
917
- if (U.length === 0) return !1;
918
- Z = !0, Y.push(gt());
919
- const e = U.pop();
920
- return e ? (k(e.data), z(e.headers), le = We(), Z = !1, !0) : (Z = !1, !1);
921
- }, ur = () => {
922
- if (Y.length === 0) return !1;
923
- Z = !0, U.push(gt());
924
- const e = Y.pop();
925
- return e ? (k(e.data), z(e.headers), le = We(), Z = !1, !0) : (Z = !1, !1);
926
- }, ir = () => {
927
- U.length = 0, Y.length = 0;
928
- }, fr = () => U.length > 0, dr = () => Y.length > 0, vr = () => U.length, wr = () => Y.length, hr = (e) => {
929
- je = e;
930
- }, gr = () => je, pr = () => {
931
- const e = f.value.length;
932
- for (let t = 0; t < e; t++)
933
- S.value.add(t);
934
- }, yr = () => {
935
- S.value.clear();
936
- }, mr = (e, t) => {
937
- const o = Math.min(e, t), n = Math.max(e, t);
938
- for (let r = o; r <= n; r++)
939
- r >= 0 && r < f.value.length && S.value.add(r);
940
- }, Cr = () => {
941
- const e = f.value.length, t = /* @__PURE__ */ new Set();
942
- for (let o = 0; o < e; o++)
943
- S.value.has(o) || t.add(o);
944
- S.value = t;
945
- }, Rr = () => {
946
- const e = [], t = Array.from(S.value).sort((o, n) => o - n);
947
- for (const o of t) {
948
- const n = f.value[o];
949
- n && e.push([...n]);
950
- }
951
- return e;
952
- }, pt = () => Array.from(S.value).sort((e, t) => e - t), yt = () => {
953
- const e = [];
954
- for (const t of se.value) {
955
- const o = t.split(",");
956
- if (o.length === 2) {
957
- const n = parseInt(o[0] ?? "", 10), r = parseInt(o[1] ?? "", 10);
958
- !isNaN(n) && !isNaN(r) && e.push({ row: n, column: r });
305
+ y();
306
+ },
307
+ removeColumn(e) {
308
+ d.removeHeader(e);
309
+ const o = v();
310
+ for (const s of o)
311
+ e >= 0 && e < s.cells.length && s.deleteCell(e);
312
+ const n = l.tFoot;
313
+ if (n && n.rows.length > 0) {
314
+ const s = n.rows[0];
315
+ e >= 0 && e < s.cells.length && s.deleteCell(e);
959
316
  }
960
- }
961
- return e.sort((t, o) => t.row === o.row ? t.column - o.column : t.row - o.row);
962
- }, F = p(null), j = (e, t) => {
963
- if (e >= 0 && e < f.value.length && t >= 0 && t < g.value.length) {
964
- F.value = { row: e, column: t };
965
- const o = at(e, t);
966
- o && o.focus();
967
- }
968
- }, Sr = () => {
969
- F.value = null;
970
- }, br = () => F.value ? { ...F.value } : null, Er = (e, t) => {
971
- const o = F.value;
972
- return o !== null && o.row === e && o.column === t;
973
- }, mt = () => {
974
- const e = F.value;
975
- return !e || e.row <= 0 ? !1 : (j(e.row - 1, e.column), !0);
976
- }, Ct = () => {
977
- const e = F.value;
978
- return !e || e.row >= f.value.length - 1 ? !1 : (j(e.row + 1, e.column), !0);
979
- }, Rt = () => {
980
- const e = F.value;
981
- return !e || e.column <= 0 ? !1 : (j(e.row, e.column - 1), !0);
982
- }, St = () => {
983
- const e = F.value;
984
- return !e || e.column >= g.value.length - 1 ? !1 : (j(e.row, e.column + 1), !0);
985
- }, bt = () => {
986
- f.value.length > 0 && g.value.length > 0 && j(0, 0);
987
- }, Et = () => {
988
- const e = f.value.length, t = g.value.length;
989
- e > 0 && t > 0 && j(e - 1, t - 1);
990
- }, At = () => {
991
- const e = F.value;
992
- e && j(e.row, 0);
993
- }, Dt = () => {
994
- const e = F.value;
995
- e && g.value.length > 0 && j(e.row, g.value.length - 1);
996
- }, Ar = () => {
997
- const e = (t) => {
998
- if (F.value)
999
- switch (t.key) {
1000
- case "ArrowUp":
1001
- mt() && t.preventDefault();
1002
- break;
1003
- case "ArrowDown":
1004
- Ct() && t.preventDefault();
1005
- break;
1006
- case "ArrowLeft":
1007
- Rt() && t.preventDefault();
1008
- break;
1009
- case "ArrowRight":
1010
- St() && t.preventDefault();
1011
- break;
1012
- case "Home":
1013
- t.ctrlKey ? bt() : At(), t.preventDefault();
1014
- break;
1015
- case "End":
1016
- t.ctrlKey ? Et() : Dt(), t.preventDefault();
1017
- break;
317
+ y();
318
+ },
319
+ moveColumn(e, o) {
320
+ const n = d.getColumnCount();
321
+ if (e < 0 || e >= n || o < 0 || o >= n || e === o) return;
322
+ const s = (w) => {
323
+ if (e >= w.cells.length) return;
324
+ const B = w.cells[e];
325
+ o >= w.cells.length ? w.appendChild(B) : o > e ? w.insertBefore(B, w.cells[o + 1]) : w.insertBefore(B, w.cells[o]);
326
+ }, a = l.tHead;
327
+ if (a)
328
+ for (let w = 0; w < a.rows.length; w++)
329
+ s(a.rows[w]);
330
+ const i = v();
331
+ for (const w of i)
332
+ s(w);
333
+ const g = l.tFoot;
334
+ if (g)
335
+ for (let w = 0; w < g.rows.length; w++)
336
+ s(g.rows[w]);
337
+ T(), y();
338
+ },
339
+ swapColumns(e, o) {
340
+ const n = d.getColumnCount();
341
+ if (e < 0 || e >= n || o < 0 || o >= n || e === o) return;
342
+ const s = (w) => {
343
+ if (e >= w.cells.length || o >= w.cells.length) return;
344
+ const B = w.cells[e], G = w.cells[o], K = document.createElement("td");
345
+ w.insertBefore(K, B), w.insertBefore(B, G), w.insertBefore(G, K), K.remove();
346
+ }, a = l.tHead;
347
+ if (a)
348
+ for (let w = 0; w < a.rows.length; w++)
349
+ s(a.rows[w]);
350
+ const i = v();
351
+ for (const w of i)
352
+ s(w);
353
+ const g = l.tFoot;
354
+ if (g)
355
+ for (let w = 0; w < g.rows.length; w++)
356
+ s(g.rows[w]);
357
+ T(), y();
358
+ },
359
+ setColumnData(e, o) {
360
+ const n = v();
361
+ for (let s = 0; s < n.length && s < o.length; s++) {
362
+ const a = n[s].cells[e];
363
+ if (a) {
364
+ const i = A(a);
365
+ S(a, o[s]), i !== o[s] && V(s, e, i, o[s]);
1018
366
  }
1019
- };
1020
- return s.value.addEventListener("keydown", e), () => s.value.removeEventListener("keydown", e);
1021
- }, V = p(/* @__PURE__ */ new Set()), Dr = m(() => g.value.length - V.value.size), Tt = () => {
1022
- const e = s.value.tHead, t = c.value[0], o = s.value.tFoot, n = (r) => {
1023
- for (let l = 0; l < r.cells.length; l++) {
1024
- const a = r.cells[l];
1025
- a && (a.style.display = V.value.has(l) ? "none" : "");
1026
367
  }
1027
- };
1028
- if (e)
1029
- for (let r = 0; r < e.rows.length; r++) {
1030
- const l = e.rows[r];
1031
- l && n(l);
368
+ },
369
+ // ======================================================================
370
+ // CELL METHODS
371
+ // ======================================================================
372
+ setCell(e, o, n) {
373
+ const s = d.getCell(e, o);
374
+ if (!s) return;
375
+ const a = A(s);
376
+ S(s, n), V(e, o, a, n);
377
+ },
378
+ setCellByRowId(e, o, n) {
379
+ const s = d.getRowIndex(e);
380
+ s !== -1 && d.setCell(s, o, n);
381
+ },
382
+ setCellRange(e, o, n) {
383
+ for (let s = 0; s < n.length; s++) {
384
+ const a = n[s];
385
+ for (let i = 0; i < a.length; i++)
386
+ d.setCell(e + s, o + i, a[i]);
1032
387
  }
1033
- if (t)
1034
- for (let r = 0; r < t.rows.length; r++) {
1035
- const l = t.rows[r];
1036
- l && n(l);
388
+ },
389
+ // ======================================================================
390
+ // FOOTER METHODS
391
+ // ======================================================================
392
+ setFooter(e) {
393
+ let o = l.tFoot;
394
+ for (o || (o = l.createTFoot()); o.rows.length > 0; )
395
+ o.deleteRow(0);
396
+ const n = o.insertRow();
397
+ for (const s of e) {
398
+ const a = n.insertCell();
399
+ S(a, s);
1037
400
  }
1038
- if (o)
1039
- for (let r = 0; r < o.rows.length; r++) {
1040
- const l = o.rows[r];
1041
- l && n(l);
401
+ },
402
+ setFooterCell(e, o) {
403
+ const n = l.tFoot;
404
+ if (!n || n.rows.length === 0) return;
405
+ const s = n.rows[0].cells[e];
406
+ s && S(s, o);
407
+ },
408
+ getFooterCell(e) {
409
+ const o = l.tFoot;
410
+ if (!o || o.rows.length === 0) return;
411
+ const n = o.rows[0].cells[e];
412
+ return n ? A(n) : void 0;
413
+ },
414
+ clearFooter() {
415
+ const e = l.tFoot;
416
+ if (e)
417
+ for (; e.rows.length > 0; )
418
+ e.deleteRow(0);
419
+ },
420
+ // ======================================================================
421
+ // CAPTION METHODS
422
+ // ======================================================================
423
+ setCaption(e) {
424
+ const o = l.createCaption();
425
+ o.textContent = e;
426
+ },
427
+ getCaptionText() {
428
+ return l.caption?.textContent ?? void 0;
429
+ },
430
+ // ======================================================================
431
+ // BULK OPERATIONS
432
+ // ======================================================================
433
+ setData(e) {
434
+ d.clearRows();
435
+ const o = E();
436
+ for (const n of e) {
437
+ const s = o.insertRow();
438
+ s.dataset.id = c();
439
+ for (const a of n) {
440
+ const i = s.insertCell();
441
+ S(i, a);
442
+ }
1042
443
  }
1043
- }, Mt = (e) => {
1044
- const t = new Set(V.value);
1045
- t.add(e), V.value = t, Tt();
1046
- }, Ft = (e) => {
1047
- const t = new Set(V.value);
1048
- t.delete(e), V.value = t, Tt();
1049
- }, Tr = (e) => {
1050
- V.value.has(e) ? Ft(e) : Mt(e);
1051
- }, Mr = (e) => !V.value.has(e), Fr = () => {
1052
- const e = [];
1053
- for (let t = 0; t < g.value.length; t++)
1054
- V.value.has(t) || e.push(t);
1055
- return e;
1056
- }, Lr = () => Array.from(V.value).sort((e, t) => e - t), pe = (e, t) => {
1057
- const o = c.value[0];
1058
- if (!o || e < 0 || e >= o.rows.length || t < 0 || t >= o.rows.length || e === t) return;
1059
- const n = o.rows[e];
1060
- if (n) {
1061
- if (t < e) {
1062
- const r = o.rows[t];
1063
- r && o.insertBefore(n, r);
1064
- } else {
1065
- const r = o.rows[t + 1];
1066
- r ? o.insertBefore(n, r) : o.appendChild(n);
444
+ y();
445
+ },
446
+ reset() {
447
+ for (l.deleteCaption(), l.deleteTHead(), l.deleteTFoot(); l.tBodies.length > 0; )
448
+ l.removeChild(l.tBodies[0]);
449
+ T(), y();
450
+ },
451
+ sync() {
452
+ const e = v();
453
+ for (const o of e)
454
+ o.dataset.id || (o.dataset.id = c());
455
+ },
456
+ // ======================================================================
457
+ // RECORD-BASED OPERATIONS
458
+ // ======================================================================
459
+ setRecords(e, o) {
460
+ d.clearRows();
461
+ const n = E();
462
+ for (const s of e) {
463
+ const a = n.insertRow();
464
+ a.dataset.id = s.id;
465
+ for (const i of o) {
466
+ const g = a.insertCell(), w = typeof i == "function" ? i(s) : s[i];
467
+ S(g, w);
468
+ }
1067
469
  }
1068
- E();
1069
- }
1070
- }, Hr = (e) => e <= 0 ? !1 : (pe(e, e - 1), !0), Nr = (e) => {
1071
- const t = c.value[0];
1072
- return !t || e >= t.rows.length - 1 ? !1 : (pe(e, e + 1), !0);
1073
- }, kr = (e) => {
1074
- pe(e, 0);
1075
- }, Vr = (e) => {
1076
- const t = c.value[0];
1077
- t && pe(e, t.rows.length - 1);
1078
- }, Br = (e, t) => {
1079
- const o = c.value[0];
1080
- if (!o || e < 0 || e >= o.rows.length || t < 0 || t >= o.rows.length || e === t) return;
1081
- const n = o.rows[e], r = o.rows[t];
1082
- if (!n || !r) return;
1083
- const l = document.createElement("tr");
1084
- o.insertBefore(l, n), o.insertBefore(n, r), o.insertBefore(r, l), o.removeChild(l), E();
1085
- }, ye = (e, t) => {
1086
- if (e < 0 || e >= g.value.length || t < 0 || t >= g.value.length || e === t) return;
1087
- const o = [...g.value], [n] = o.splice(e, 1);
1088
- n !== void 0 && o.splice(t, 0, n);
1089
- const r = f.value.map((l) => {
1090
- const a = [...l], [i] = a.splice(e, 1);
1091
- return i !== void 0 && a.splice(t, 0, i), a;
1092
- });
1093
- z(o), k(r);
1094
- }, Or = (e) => e <= 0 ? !1 : (ye(e, e - 1), !0), Pr = (e) => e >= g.value.length - 1 ? !1 : (ye(e, e + 1), !0), Kr = (e) => {
1095
- ye(e, 0);
1096
- }, zr = (e) => {
1097
- ye(e, g.value.length - 1);
1098
- }, $r = (e, t) => {
1099
- if (e < 0 || e >= g.value.length || t < 0 || t >= g.value.length || e === t) return;
1100
- const o = [...g.value], n = o[e];
1101
- o[e] = o[t] ?? "", o[t] = n ?? "";
1102
- const r = f.value.map((l) => {
1103
- const a = [...l], i = a[e];
1104
- return a[e] = a[t], a[t] = i, a;
1105
- });
1106
- z(o), k(r);
1107
- }, Ge = (e) => e.map((t) => t.map((o) => String(o ?? "")).join(" ")).join(`
1108
- `), Jr = () => {
1109
- const e = yt();
1110
- if (e.length === 0) return "";
1111
- const t = new Set(e.map((d) => d.row)), o = new Set(e.map((d) => d.column)), n = Math.min(...t), r = Math.max(...t), l = Math.min(...o), a = Math.max(...o), i = [];
1112
- for (let d = n; d <= r; d++) {
1113
- const w = [];
1114
- for (let y = l; y <= a; y++)
1115
- e.some((R) => R.row === d && R.column === y) ? w.push(ve(d, y)) : w.push("");
1116
- i.push(w);
1117
- }
1118
- return Ge(i);
1119
- }, Ur = () => {
1120
- const t = pt().map((o) => f.value[o] ?? []);
1121
- return Ge(t);
1122
- }, jr = (e) => {
1123
- const t = f.value[e];
1124
- return t ? t.map((o) => String(o ?? "")).join(" ") : "";
1125
- }, Wr = (e) => f.value.map((t) => String(t[e] ?? "")).join(`
1126
- `), Gr = (e, t) => String(ve(e, t) ?? ""), _r = (e, t, o, n) => {
1127
- const r = [], l = Math.min(e, o), a = Math.max(e, o), i = Math.min(t, n), d = Math.max(t, n);
1128
- for (let w = l; w <= a; w++) {
1129
- const y = [];
1130
- for (let R = i; R <= d; R++)
1131
- y.push(ve(w, R));
1132
- r.push(y);
470
+ y();
471
+ },
472
+ getRecordData(e) {
473
+ return d.getRowDataById(e);
474
+ },
475
+ addRecord(e, o, n) {
476
+ const s = "id" in e && typeof e.id == "string" && e.id.length > 0 ? e.id : c(), a = { ...e, id: s }, i = o.map((g) => typeof g == "function" ? g(a) : a[g]);
477
+ return d.addRow(i, n, s), s;
478
+ },
479
+ updateRecordRow(e, o) {
480
+ const n = d.getRowIndex(e);
481
+ return n === -1 ? !1 : (d.updateRow(n, o), !0);
482
+ },
483
+ removeRecord(e) {
484
+ return d.removeRowById(e) !== void 0;
485
+ },
486
+ hasRecord(e) {
487
+ return d.getRowIndex(e) !== -1;
488
+ },
489
+ // ======================================================================
490
+ // ID GENERATOR
491
+ // ======================================================================
492
+ setIdGenerator(e) {
493
+ c = e;
494
+ },
495
+ generateId() {
496
+ return c();
497
+ },
498
+ // ======================================================================
499
+ // EVENT HOOKS
500
+ // ======================================================================
501
+ onRowAdd(e) {
502
+ return F.add(e), () => F.delete(e);
503
+ },
504
+ onRowRemove(e) {
505
+ return f.add(e), () => f.delete(e);
506
+ },
507
+ onRowUpdate(e) {
508
+ return h.add(e), () => h.delete(e);
509
+ },
510
+ onCellChange(e) {
511
+ return D.add(e), () => D.delete(e);
512
+ },
513
+ onHeaderChange(e) {
514
+ return p.add(e), () => p.delete(e);
515
+ },
516
+ onDataChange(e) {
517
+ return I.add(e), () => I.delete(e);
518
+ },
519
+ // ======================================================================
520
+ // CLEANUP
521
+ // ======================================================================
522
+ destroy() {
523
+ F.clear(), f.clear(), h.clear(), D.clear(), p.clear(), I.clear();
1133
524
  }
1134
- return Ge(r);
1135
- }, Qr = (e, t, o) => {
1136
- const n = o.split(`
1137
- `);
1138
- for (let r = 0; r < n.length; r++) {
1139
- const l = n[r];
1140
- if (l === void 0) continue;
1141
- const a = l.split(" ");
1142
- for (let i = 0; i < a.length; i++) {
1143
- const d = a[i];
1144
- d !== void 0 && Le(e + r, t + i, d);
525
+ };
526
+ return H?.caption && d.setCaption(H.caption), H?.headers && d.setHeaders(H.headers), C && d.setData(C), H?.footer && d.setFooter(H.footer), d.sync(), d;
527
+ }
528
+ function Ct(l, C, H) {
529
+ const c = it(l.value, C, H), F = N(0), f = () => {
530
+ F.value++;
531
+ }, h = N(/* @__PURE__ */ new Set()), D = N(/* @__PURE__ */ new Set()), p = N(null), I = /* @__PURE__ */ new Set(), E = /* @__PURE__ */ new Set(), v = U(() => (F.value, c.element)), P = U(() => (F.value, c.getHeaders())), j = U(() => (F.value, c.getData())), z = U(() => (F.value, c.getRowCount())), V = U(() => (F.value, c.getColumnCount())), T = U(() => (F.value, c.getAllRowIds())), y = U(() => (F.value, c.getFooterData())), L = U(() => (F.value, c.getCaptionText())), d = () => {
532
+ I.forEach((t) => t(h.value, D.value));
533
+ }, e = () => {
534
+ E.forEach((t) => t(p.value));
535
+ }, o = (t, r) => `${t},${r}`, n = c.onDataChange(() => f()), s = c.onHeaderChange(() => f()), a = (t) => {
536
+ if (t < 0 || t >= c.getRowCount()) return;
537
+ const r = new Set(h.value);
538
+ r.add(t), h.value = r, d();
539
+ }, i = (t) => {
540
+ const r = new Set(h.value);
541
+ r.delete(t), h.value = r, d();
542
+ }, g = (t) => {
543
+ h.value.has(t) ? i(t) : a(t);
544
+ }, w = () => {
545
+ const t = c.getRowCount(), r = /* @__PURE__ */ new Set();
546
+ for (let u = 0; u < t; u++)
547
+ r.add(u);
548
+ h.value = r, d();
549
+ }, B = () => {
550
+ h.value = /* @__PURE__ */ new Set(), d();
551
+ }, G = (t, r) => {
552
+ const u = Math.min(t, r), R = Math.max(t, r), m = c.getRowCount(), M = new Set(h.value);
553
+ for (let k = u; k <= R && k < m; k++)
554
+ k >= 0 && M.add(k);
555
+ h.value = M, d();
556
+ }, K = (t) => h.value.has(t), $ = () => Array.from(h.value).sort((t, r) => t - r), ne = () => $().map((t) => c.getRowData(t)).filter((t) => t !== void 0), J = (t, r) => {
557
+ const u = o(t, r), R = new Set(D.value);
558
+ R.add(u), D.value = R, d();
559
+ }, O = (t, r) => {
560
+ const u = o(t, r), R = new Set(D.value);
561
+ R.delete(u), D.value = R, d();
562
+ }, re = (t, r) => {
563
+ const u = o(t, r);
564
+ D.value.has(u) ? O(t, r) : J(t, r);
565
+ }, se = (t, r) => D.value.has(o(t, r)), _ = () => {
566
+ h.value = /* @__PURE__ */ new Set(), D.value = /* @__PURE__ */ new Set(), d();
567
+ }, b = (t, r) => {
568
+ const u = c.getRowCount(), R = c.getColumnCount();
569
+ if (t < 0 || t >= u || r < 0 || r >= R) return;
570
+ p.value = { row: t, column: r };
571
+ const m = c.getCell(t, r);
572
+ m && (m.tabIndex = 0, m.focus()), e();
573
+ }, Q = () => {
574
+ p.value = null, e();
575
+ }, ce = () => p.value ? { ...p.value } : null, le = (t, r) => {
576
+ const u = p.value;
577
+ return u !== null && u.row === t && u.column === r;
578
+ }, W = () => {
579
+ const t = p.value;
580
+ return !t || t.row <= 0 ? !1 : (b(t.row - 1, t.column), !0);
581
+ }, X = () => {
582
+ const t = p.value;
583
+ if (!t) return !1;
584
+ const r = c.getRowCount();
585
+ return t.row >= r - 1 ? !1 : (b(t.row + 1, t.column), !0);
586
+ }, Y = () => {
587
+ const t = p.value;
588
+ return !t || t.column <= 0 ? !1 : (b(t.row, t.column - 1), !0);
589
+ }, Z = () => {
590
+ const t = p.value;
591
+ if (!t) return !1;
592
+ const r = c.getColumnCount();
593
+ return t.column >= r - 1 ? !1 : (b(t.row, t.column + 1), !0);
594
+ }, x = () => {
595
+ const t = c.getRowCount(), r = c.getColumnCount();
596
+ t > 0 && r > 0 && b(0, 0);
597
+ }, ee = () => {
598
+ const t = c.getRowCount(), r = c.getColumnCount();
599
+ t > 0 && r > 0 && b(t - 1, r - 1);
600
+ }, ae = () => {
601
+ const t = c.element, r = (u) => {
602
+ const R = p.value;
603
+ if (!R) return;
604
+ let m = !1;
605
+ switch (u.key) {
606
+ case "ArrowUp":
607
+ m = W();
608
+ break;
609
+ case "ArrowDown":
610
+ m = X();
611
+ break;
612
+ case "ArrowLeft":
613
+ m = Y();
614
+ break;
615
+ case "ArrowRight":
616
+ m = Z();
617
+ break;
618
+ case "Home":
619
+ u.ctrlKey ? x() : b(R.row, 0), m = !0;
620
+ break;
621
+ case "End":
622
+ if (u.ctrlKey)
623
+ ee();
624
+ else {
625
+ const M = c.getColumnCount();
626
+ b(R.row, M - 1);
627
+ }
628
+ m = !0;
629
+ break;
630
+ case "Enter":
631
+ case " ":
632
+ u.shiftKey ? G(R.row, R.row) : u.ctrlKey || u.metaKey ? g(R.row) : (B(), a(R.row)), m = !0;
633
+ break;
634
+ case "Escape":
635
+ _(), m = !0;
636
+ break;
637
+ case "a":
638
+ (u.ctrlKey || u.metaKey) && (h.value.size === c.getRowCount() ? B() : w(), m = !0);
639
+ break;
1145
640
  }
1146
- }
1147
- }, K = p(/* @__PURE__ */ new Set()), B = p([]), O = p([]), Lt = (e) => {
1148
- const t = new Set(K.value);
1149
- t.add(e), K.value = t;
1150
- }, Ht = (e) => {
1151
- const t = new Set(K.value);
1152
- t.delete(e), K.value = t;
1153
- }, Ir = (e) => {
1154
- K.value.has(e) ? Ht(e) : Lt(e);
1155
- }, Yr = () => {
1156
- const e = /* @__PURE__ */ new Set();
1157
- for (let t = 0; t < f.value.length; t++)
1158
- e.add(t);
1159
- K.value = e;
1160
- }, Zr = () => {
1161
- K.value = /* @__PURE__ */ new Set();
1162
- }, Xr = (e) => K.value.has(e), qr = () => Array.from(K.value).sort((e, t) => e - t), xr = (e) => {
1163
- B.value.includes(e) || (B.value = [...B.value, e], O.value = O.value.filter((t) => t !== e));
1164
- }, es = (e) => {
1165
- O.value.includes(e) || (O.value = [...O.value, e], B.value = B.value.filter((t) => t !== e));
1166
- }, ts = (e) => {
1167
- B.value = B.value.filter((t) => t !== e), O.value = O.value.filter((t) => t !== e);
1168
- }, os = () => {
1169
- B.value = [], O.value = [];
1170
- }, ns = (e) => B.value.includes(e), rs = (e) => O.value.includes(e), ss = () => [...B.value], ls = () => [...O.value], X = /* @__PURE__ */ new Map(), q = /* @__PURE__ */ new Map(), x = /* @__PURE__ */ new Map(), as = (e, t, o, n) => {
1171
- const r = `${e},${t}`;
1172
- X.has(r) || X.set(r, /* @__PURE__ */ new Map()), X.get(r)?.set(o, n);
1173
- }, cs = (e, t, o) => {
1174
- const n = `${e},${t}`;
1175
- return X.get(n)?.get(o);
1176
- }, us = (e, t, o) => {
1177
- const n = `${e},${t}`;
1178
- return X.get(n)?.has(o) ?? !1;
1179
- }, is = (e, t) => {
1180
- const o = `${e},${t}`;
1181
- X.delete(o);
1182
- }, fs = (e, t, o) => {
1183
- const n = `${e},${t}`;
1184
- X.get(n)?.delete(o);
1185
- }, ds = (e, t, o) => {
1186
- q.has(e) || q.set(e, /* @__PURE__ */ new Map()), q.get(e)?.set(t, o);
1187
- }, vs = (e, t) => q.get(e)?.get(t), ws = (e, t) => q.get(e)?.has(t) ?? !1, hs = (e) => {
1188
- q.delete(e);
1189
- }, gs = (e, t) => {
1190
- q.get(e)?.delete(t);
1191
- }, ps = (e, t, o) => {
1192
- x.has(e) || x.set(e, /* @__PURE__ */ new Map()), x.get(e)?.set(t, o);
1193
- }, ys = (e, t) => x.get(e)?.get(t), ms = (e, t) => x.get(e)?.has(t) ?? !1, Cs = (e) => {
1194
- x.delete(e);
1195
- }, Rs = (e, t) => {
1196
- x.get(e)?.delete(t);
1197
- }, Ss = (e) => () => {
1198
- }, bs = (e) => () => {
1199
- }, Es = (e) => () => {
1200
- }, As = (e) => () => {
1201
- }, Ds = (e) => {
1202
- const t = H(() => S.value, (o) => {
1203
- e(o);
1204
- }, { deep: !0 });
1205
- return () => {
1206
- t();
1207
- };
1208
- }, Ts = (e) => {
1209
- const t = H(() => se.value, (o) => {
1210
- e(o);
1211
- }, { deep: !0 });
1212
- return () => {
1213
- t();
641
+ m && (u.preventDefault(), u.stopPropagation());
1214
642
  };
1215
- }, Ms = (e) => {
1216
- const t = H([W, $], ([o, n]) => {
1217
- e(o, n);
1218
- });
1219
- return () => {
1220
- t();
643
+ return t.addEventListener("keydown", r), () => {
644
+ t.removeEventListener("keydown", r);
1221
645
  };
1222
- }, Fs = (e) => {
1223
- const t = H(() => Q.value, (o) => {
1224
- e(o);
1225
- });
1226
- return () => {
1227
- t();
1228
- };
1229
- }, Ls = (e) => {
1230
- const t = H(() => F.value, (o) => {
1231
- e(o ? { ...o } : null);
1232
- });
1233
- return () => {
1234
- t();
1235
- };
1236
- }, Hs = (e) => {
1237
- const t = H(() => V.value, (o, n) => {
1238
- for (const r of o)
1239
- n?.has(r) || e(r, !1);
1240
- if (n)
1241
- for (const r of n)
1242
- o.has(r) || e(r, !0);
1243
- });
1244
- return () => {
1245
- t();
1246
- };
1247
- };
1248
- let _ = 0, ae = null;
1249
- const Nt = () => {
1250
- _ === 0 && (ae = {
1251
- data: JSON.parse(JSON.stringify(f.value)),
1252
- headers: [...g.value]
1253
- }), _++;
1254
- }, kt = () => {
1255
- _ > 0 && (_--, _ === 0 && (ae = null, E()));
1256
- }, Vt = () => {
1257
- _ > 0 && ae && (k(ae.data), z(ae.headers), _ = 0, ae = null);
1258
- }, Ns = () => _ > 0, ks = (e) => {
1259
- Nt();
1260
- try {
1261
- e(), kt();
1262
- } catch (t) {
1263
- throw Vt(), t;
1264
- }
1265
- }, _e = p(!1), Qe = /* @__PURE__ */ new Set(), Ie = /* @__PURE__ */ new Set(), Ye = /* @__PURE__ */ new Set(), ee = (e) => {
1266
- _e.value = e;
1267
- }, Vs = (e, t, o) => {
1268
- const n = `${e},${t}`;
1269
- o ? Qe.add(n) : Qe.delete(n);
1270
- }, Bs = (e, t) => {
1271
- t ? Ie.add(e) : Ie.delete(e);
1272
- }, Os = (e, t) => {
1273
- t ? Ye.add(e) : Ye.delete(e);
1274
- }, Ps = () => _e.value, Ks = (e, t) => Qe.has(`${e},${t}`), zs = (e) => Ie.has(e), $s = (e) => Ye.has(e), Js = async (e) => {
1275
- ee(!0);
1276
- try {
1277
- const t = await e();
1278
- k(t);
1279
- } finally {
1280
- ee(!1);
1281
- }
1282
- }, Us = async (e) => {
1283
- ee(!0);
1284
- try {
1285
- const t = await e();
1286
- for (const o of t)
1287
- de(o);
1288
- } finally {
1289
- ee(!1);
1290
- }
1291
- }, js = async (e) => {
1292
- ee(!0);
1293
- try {
1294
- const t = await e();
1295
- for (let o = t.length - 1; o >= 0; o--) {
1296
- const n = t[o];
1297
- n && de(n, 0);
1298
- }
1299
- } finally {
1300
- ee(!1);
1301
- }
1302
- }, te = p(0), oe = p(0), Ws = (e) => {
1303
- te.value = Math.max(0, e);
1304
- }, Gs = (e) => {
1305
- oe.value = Math.max(0, e);
1306
- }, _s = () => {
1307
- te.value = 0;
1308
- }, Qs = () => {
1309
- oe.value = 0;
1310
- }, Is = () => {
1311
- te.value = 0, oe.value = 0;
1312
- }, Ys = () => te.value, Zs = () => oe.value, Xs = (e) => e < te.value, qs = (e) => {
1313
- const t = g.value.length;
1314
- return e >= t - oe.value;
1315
- }, xs = () => te.value > 0 || oe.value > 0;
1316
- let L, Bt = () => crypto.randomUUID();
1317
- const T = /* @__PURE__ */ new Map(), ce = [], el = (e) => {
1318
- L = e, z(e.map((t) => t.header));
1319
- }, tl = () => {
1320
- L = void 0, T.clear();
1321
- }, ol = () => L !== void 0, nl = () => L, be = (e) => L ? L.map((t) => typeof t.field == "function" ? t.field(e) : e[t.field]) : [], ue = (e) => {
1322
- if (!L) return;
1323
- const t = lt(e);
1324
- if (!t) return;
1325
- const o = T.get(e);
1326
- if (!o) return;
1327
- const n = { id: o };
1328
- return L.forEach((r, l) => {
1329
- if (typeof r.field == "string") {
1330
- const a = t[l];
1331
- r.parse ? n[r.field] = r.parse(String(a ?? ""), n) : n[r.field] = a;
1332
- }
1333
- }), n;
1334
- }, Ot = (e) => {
1335
- if (!L) return;
1336
- T.clear();
1337
- const t = e.map((o) => be(o));
1338
- k(t), e.forEach((o, n) => {
1339
- T.set(n, o.id);
1340
- });
1341
- }, Pt = () => {
1342
- if (!L) return [];
1343
- const e = [], t = f.value.length;
1344
- for (let o = 0; o < t; o++) {
1345
- const n = ue(o);
1346
- n && e.push(n);
1347
- }
1348
- return e;
1349
- }, rl = (e) => {
1350
- const t = ne(e);
1351
- if (t !== void 0)
1352
- return ue(t);
1353
- }, sl = (e) => T.get(e), ne = (e) => {
1354
- for (const [t, o] of T.entries())
1355
- if (o === e) return t;
646
+ }, ue = (t, r) => {
647
+ c.setRecords(t, r), f();
648
+ }, de = (t) => c.getRecordData(t), ie = (t, r, u) => {
649
+ const R = c.addRecord(t, r, u);
650
+ return f(), R;
651
+ }, we = (t, r) => {
652
+ const u = c.updateRecordRow(t, r);
653
+ return u && f(), u;
654
+ }, fe = (t) => {
655
+ const r = c.removeRecord(t);
656
+ return r && f(), r;
657
+ }, ge = (t) => c.hasRecord(t), Ce = () => $().map((r) => c.getRowId(r)).filter((r) => r !== void 0), Re = (t) => {
658
+ for (const r of t) {
659
+ const u = c.getRowIndex(r);
660
+ u !== -1 && a(u);
661
+ }
662
+ }, he = (t) => {
663
+ for (const r of t) {
664
+ const u = c.getRowIndex(r);
665
+ u !== -1 && i(u);
666
+ }
667
+ }, ve = (t) => {
668
+ c.setHeaders(t), f();
669
+ }, pe = (t, r) => {
670
+ c.setHeader(t, r), f();
671
+ }, ye = (t, r) => {
672
+ c.addHeader(t, r), f();
673
+ }, me = (t) => {
674
+ c.removeHeader(t), f();
675
+ }, He = (t, r, u) => {
676
+ const R = c.addRow(t, r, u);
677
+ return f(), R;
678
+ }, Fe = (t) => {
679
+ const r = c.removeRow(t);
680
+ return r && f(), r;
681
+ }, De = (t) => {
682
+ const r = c.removeRowById(t);
683
+ return r && f(), r;
684
+ }, Be = (t, r) => {
685
+ c.updateRow(t, r), f();
686
+ }, Ie = (t, r) => {
687
+ c.updateRowById(t, r), f();
688
+ }, Te = (t, r) => {
689
+ c.moveRow(t, r), f();
690
+ }, Se = (t, r) => {
691
+ c.swapRows(t, r), f();
692
+ }, Ee = () => {
693
+ c.clearRows(), f();
694
+ }, be = (t, r, u) => {
695
+ c.addColumn(t, r, u), f();
696
+ }, Le = (t) => {
697
+ c.removeColumn(t), f();
698
+ }, Ue = (t, r) => {
699
+ c.moveColumn(t, r), f();
700
+ }, Ae = (t, r) => {
701
+ c.swapColumns(t, r), f();
702
+ }, Ge = (t, r) => {
703
+ c.setColumnData(t, r), f();
704
+ }, Ke = (t, r) => c.getCellValue(t, r), ke = (t, r, u) => {
705
+ c.setCell(t, r, u), f();
706
+ }, Ve = (t, r, u) => {
707
+ c.setCellByRowId(t, r, u), f();
708
+ }, Me = (t, r, u) => {
709
+ c.setCellRange(t, r, u), f();
710
+ }, Ne = (t, r) => c.getCell(t, r), Pe = (t) => c.getRowData(t), je = (t) => c.getRowDataById(t), ze = (t) => c.getRow(t), $e = (t) => c.getRowById(t), _e = (t) => c.getRowId(t), qe = (t) => c.getRowIndex(t), Je = (t) => c.getColumnData(t), Oe = (t) => {
711
+ c.setFooter(t), f();
712
+ }, Qe = (t, r) => {
713
+ c.setFooterCell(t, r), f();
714
+ }, We = (t) => c.getFooterCell(t), Xe = () => {
715
+ c.clearFooter(), f();
716
+ }, Ye = (t) => {
717
+ c.setCaption(t), f();
718
+ }, Ze = (t) => {
719
+ c.setData(t), f();
720
+ }, xe = () => {
721
+ c.reset(), _(), Q(), f();
722
+ }, et = () => {
723
+ c.sync(), f();
724
+ }, tt = (t) => c.onRowAdd(t), ot = (t) => c.onRowRemove(t), nt = (t) => c.onRowUpdate(t), rt = (t) => c.onCellChange(t), st = (t) => c.onHeaderChange(t), ct = (t) => c.onDataChange(t), lt = (t) => (I.add(t), () => I.delete(t)), at = (t) => (E.add(t), () => E.delete(t)), te = () => {
725
+ n(), s(), I.clear(), E.clear(), c.destroy();
1356
726
  };
1357
- return {
1358
- element: s,
1359
- caption: Gt,
1360
- tHead: _t,
1361
- tFoot: Qt,
1362
- rows: Te,
1363
- rowCount: jt,
1364
- tBodies: Me,
1365
- tBodyCount: Wt,
1366
- data: f,
1367
- headers: g,
1368
- columnCount: It,
1369
- createCaption: qe,
1370
- deleteCaption: xe,
1371
- createTHead: Yt,
1372
- deleteTHead: et,
1373
- createTFoot: tt,
1374
- deleteTFoot: ot,
1375
- createTBody: Zt,
1376
- insertRow: Xt,
1377
- deleteRow: qt,
1378
- getTHead: xt,
1379
- getTFoot: eo,
1380
- getTBody: to,
1381
- getRow: oo,
1382
- addRow: de,
1383
- removeRow: Fe,
1384
- addColumn: nt,
1385
- removeColumn: rt,
1386
- setCell: Le,
1387
- getCell: ve,
1388
- setCaption: no,
1389
- setHeaders: z,
1390
- setFooter: ro,
1391
- setData: k,
1392
- clearData: so,
1393
- reset: lo,
1394
- sync: ao,
1395
- addRowWithAttributes: co,
1396
- addColumnWithAttributes: uo,
1397
- setHeadersWithAttributes: io,
1398
- setCellWithAttributes: st,
1399
- getRowData: lt,
1400
- setRowData: He,
1401
- getAllRowData: fo,
1402
- getColumnData: vo,
1403
- setColumnData: wo,
1404
- getCellRange: ho,
1405
- setCellRange: go,
1406
- getHeaderData: po,
1407
- getFooterData: yo,
1408
- setFooterCell: mo,
1409
- getFooterCell: Co,
1410
- updateCell: Ne,
1411
- updateRow: ke,
1412
- getCellElement: at,
1413
- getRowElement: Ro,
1414
- selectRows: So,
1415
- selectColumns: bo,
1416
- updateRows: Eo,
1417
- updateCells: Ao,
1418
- getRowElements: Do,
1419
- getRowCellElements: To,
1420
- setRows: Mo,
1421
- validateCell: Fo,
1422
- validateRow: Lo,
1423
- validateColumn: Ho,
1424
- validateAll: No,
1425
- sum: ko,
1426
- average: Vo,
1427
- min: Bo,
1428
- max: Oo,
1429
- count: Po,
1430
- aggregate: Ko,
1431
- transformColumn: zo,
1432
- transformRow: $o,
1433
- transformCells: Jo,
1434
- exportToCSV: Uo,
1435
- exportToJSON: jo,
1436
- importFromArray: Wo,
1437
- importFromCSV: Go,
1438
- importFromJSON: _o,
1439
- search: Qo,
1440
- searchColumn: Io,
1441
- selectedRows: S,
1442
- selectedCells: se,
1443
- selectRow: Ve,
1444
- deselectRow: Be,
1445
- toggleRowSelection: Yo,
1446
- isRowSelected: Zo,
1447
- selectCell: Xo,
1448
- clearSelection: qo,
1449
- enableCellEditing: Ke,
1450
- disableCellEditing: en,
1451
- enableHeaderEditing: tn,
1452
- disableHeaderEditing: on,
1453
- enableColumnEditing: nn,
1454
- disableColumnEditing: rn,
1455
- enableRowEditing: sn,
1456
- disableRowEditing: ln,
1457
- enableEditing: an,
1458
- groupBy: cn,
1459
- addComputedColumn: un,
1460
- removeComputedColumn: fn,
1461
- get pagination() {
1462
- return A;
1463
- },
1464
- paginate: dn,
1465
- nextPage: vn,
1466
- previousPage: wn,
1467
- goToPage: hn,
1468
- get virtualScroll() {
1469
- return D;
1470
- },
1471
- enableVirtualScrolling: gn,
1472
- disableVirtualScrolling: pn,
1473
- transaction: mn,
1474
- onDataChange: Cn,
1475
- sortState: Rn,
1476
- sortColumnAscending: Sn,
1477
- sortColumnDescending: bn,
1478
- sortColumnAscendingWith: En,
1479
- sortColumnDescendingWith: An,
1480
- clearColumnSort: Dn,
1481
- getSortedColumnIndex: Tn,
1482
- isSortedAscending: Mn,
1483
- isSortedDescending: Fn,
1484
- isSorted: Ln,
1485
- filterState: Nn,
1486
- filterRows: wt,
1487
- filterColumn: $e,
1488
- filterColumnByValue: kn,
1489
- filterColumnByValues: Vn,
1490
- clearFilters: Bn,
1491
- getFilteredRowIndices: On,
1492
- setRowKeyFunction: Pn,
1493
- clearRowKeyFunction: Kn,
1494
- hasRowKeyFunction: zn,
1495
- getRowByKey: Un,
1496
- getRowIndexByKey: he,
1497
- updateRowByKey: jn,
1498
- removeRowByKey: Wn,
1499
- hasRowWithKey: Gn,
1500
- getRowKey: $n,
1501
- getAllRowKeys: Jn,
1502
- setColumnDefinition: _n,
1503
- setColumnDefinitions: Qn,
1504
- clearColumnDefinition: In,
1505
- clearColumnDefinitions: Yn,
1506
- getColumnDefinition: Zn,
1507
- hasColumnDefinition: Xn,
1508
- getParsedCell: qn,
1509
- getParsedRowData: ht,
1510
- getParsedColumnData: xn,
1511
- getParsedData: er,
1512
- dirtyState: ge,
1513
- markClean: tr,
1514
- markDirty: or,
1515
- isDirty: nr,
1516
- hasChanges: rr,
1517
- getChangedCells: sr,
1518
- getChangedRowIndices: lr,
1519
- getChangedColumnIndices: ar,
1520
- undo: cr,
1521
- redo: ur,
1522
- clearHistory: ir,
1523
- canUndo: fr,
1524
- canRedo: dr,
1525
- getUndoStackSize: vr,
1526
- getRedoStackSize: wr,
1527
- setHistoryLimit: hr,
1528
- getHistoryLimit: gr,
1529
- selectAllRows: pr,
1530
- deselectAllRows: yr,
1531
- selectRowRange: mr,
1532
- invertRowSelection: Cr,
1533
- getSelectedRowData: Rr,
1534
- getSelectedRowIndices: pt,
1535
- getSelectedCellIndices: yt,
1536
- focusedCell: F,
1537
- focusCell: j,
1538
- clearCellFocus: Sr,
1539
- getFocusedCell: br,
1540
- isCellFocused: Er,
1541
- moveFocusUp: mt,
1542
- moveFocusDown: Ct,
1543
- moveFocusLeft: Rt,
1544
- moveFocusRight: St,
1545
- moveFocusToFirstCell: bt,
1546
- moveFocusToLastCell: Et,
1547
- moveFocusToRowStart: At,
1548
- moveFocusToRowEnd: Dt,
1549
- enableKeyboardNavigation: Ar,
1550
- visibleColumnCount: Dr,
1551
- hideColumn: Mt,
1552
- showColumn: Ft,
1553
- toggleColumnVisibility: Tr,
1554
- isColumnVisible: Mr,
1555
- getVisibleColumnIndices: Fr,
1556
- getHiddenColumnIndices: Lr,
1557
- moveRow: pe,
1558
- moveRowUp: Hr,
1559
- moveRowDown: Nr,
1560
- moveRowToTop: kr,
1561
- moveRowToBottom: Vr,
1562
- swapRows: Br,
1563
- moveColumn: ye,
1564
- moveColumnLeft: Or,
1565
- moveColumnRight: Pr,
1566
- moveColumnToStart: Kr,
1567
- moveColumnToEnd: zr,
1568
- swapColumns: $r,
1569
- copySelectedCells: Jr,
1570
- copySelectedRows: Ur,
1571
- copyRow: jr,
1572
- copyColumn: Wr,
1573
- copyCell: Gr,
1574
- copyCellRange: _r,
1575
- pasteAtCell: Qr,
1576
- expandedRows: K,
1577
- pinnedTopRows: B,
1578
- pinnedBottomRows: O,
1579
- expandRow: Lt,
1580
- collapseRow: Ht,
1581
- toggleRowExpansion: Ir,
1582
- expandAllRows: Yr,
1583
- collapseAllRows: Zr,
1584
- isRowExpanded: Xr,
1585
- getExpandedRowIndices: qr,
1586
- pinRowTop: xr,
1587
- pinRowBottom: es,
1588
- unpinRow: ts,
1589
- unpinAllRows: os,
1590
- isRowPinnedTop: ns,
1591
- isRowPinnedBottom: rs,
1592
- getPinnedTopRowIndices: ss,
1593
- getPinnedBottomRowIndices: ls,
1594
- setCellMeta: as,
1595
- getCellMeta: cs,
1596
- hasCellMeta: us,
1597
- clearCellMeta: is,
1598
- clearCellMetaKey: fs,
1599
- setRowMeta: ds,
1600
- getRowMeta: vs,
1601
- hasRowMeta: ws,
1602
- clearRowMeta: hs,
1603
- clearRowMetaKey: gs,
1604
- setColumnMeta: ps,
1605
- getColumnMeta: ys,
1606
- hasColumnMeta: ms,
1607
- clearColumnMeta: Cs,
1608
- clearColumnMetaKey: Rs,
1609
- onRowAdd: Ss,
1610
- onRowRemove: bs,
1611
- onRowUpdate: Es,
1612
- onCellChange: As,
1613
- onRowSelectionChange: Ds,
1614
- onCellSelectionChange: Ts,
1615
- onSortChange: Ms,
1616
- onFilterChange: Fs,
1617
- onCellFocusChange: Ls,
1618
- onColumnVisibilityChange: Hs,
1619
- beginBatchUpdate: Nt,
1620
- endBatchUpdate: kt,
1621
- cancelBatchUpdate: Vt,
1622
- isBatchUpdating: Ns,
1623
- batchUpdate: ks,
1624
- tableLoading: _e,
1625
- setTableLoading: ee,
1626
- setCellLoading: Vs,
1627
- setRowLoading: Bs,
1628
- setColumnLoading: Os,
1629
- isTableLoading: Ps,
1630
- isCellLoading: Ks,
1631
- isRowLoading: zs,
1632
- isColumnLoading: $s,
1633
- loadData: Js,
1634
- appendRowsAsync: Us,
1635
- prependRowsAsync: js,
1636
- frozenLeftColumnCount: te,
1637
- frozenRightColumnCount: oe,
1638
- freezeColumnsLeft: Ws,
1639
- freezeColumnsRight: Gs,
1640
- unfreezeColumnsLeft: _s,
1641
- unfreezeColumnsRight: Qs,
1642
- unfreezeAllColumns: Is,
1643
- getFrozenLeftColumnCount: Ys,
1644
- getFrozenRightColumnCount: Zs,
1645
- isColumnFrozenLeft: Xs,
1646
- isColumnFrozenRight: qs,
1647
- hasFrozenColumns: xs,
1648
- // Record-based data (Shared Reactive Data Schema)
1649
- setRecordColumns: el,
1650
- clearRecordColumns: tl,
1651
- hasRecordColumns: ol,
1652
- getRecordColumns: nl,
1653
- setRecords: Ot,
1654
- getRecords: Pt,
1655
- getRecordById: rl,
1656
- getRecordId: sl,
1657
- getRowIndexForRecord: ne,
1658
- updateRecord: (e, t) => {
1659
- if (!L) return !1;
1660
- const o = ne(e);
1661
- if (o === void 0) return !1;
1662
- const n = ue(o);
1663
- if (!n) return !1;
1664
- const r = { ...n, ...t }, l = be(r);
1665
- return He(o, l), ce.forEach((a) => a(e, r, "update")), !0;
1666
- },
1667
- addRecord: (e, t) => {
1668
- const o = "id" in e && typeof e.id == "string" && e.id.length > 0 ? e.id : Bt(), n = { ...e, id: o };
1669
- if (L) {
1670
- const r = be(n);
1671
- de(r, t);
1672
- const l = t ?? f.value.length - 1;
1673
- if (t !== void 0 && t < f.value.length - 1) {
1674
- const a = Array.from(T.entries()).sort((i, d) => d[0] - i[0]);
1675
- for (const [i, d] of a)
1676
- i >= l && (T.delete(i), T.set(i + 1, d));
1677
- }
1678
- T.set(l, o), ce.forEach((a) => a(o, n, "add"));
1679
- }
1680
- return o;
727
+ return ut(() => {
728
+ te();
729
+ }), {
730
+ // Table instance
731
+ instance: c,
732
+ // Reactive state
733
+ element: v,
734
+ headers: P,
735
+ data: j,
736
+ rowCount: z,
737
+ columnCount: V,
738
+ rowIds: T,
739
+ footerData: y,
740
+ captionText: L,
741
+ version: F,
742
+ // Selection state
743
+ selection: {
744
+ rows: h,
745
+ cells: D
1681
746
  },
1682
- removeRecord: (e) => {
1683
- const t = ne(e);
1684
- if (t === void 0) return !1;
1685
- const o = ue(t);
1686
- Fe(t), T.delete(t);
1687
- const n = Array.from(T.entries()).sort((r, l) => r[0] - l[0]);
1688
- for (const [r, l] of n)
1689
- r > t && (T.delete(r), T.set(r - 1, l));
1690
- return o && ce.forEach((r) => r(e, o, "remove")), !0;
1691
- },
1692
- hasRecord: (e) => ne(e) !== void 0,
1693
- getSelectedRecordIds: () => {
1694
- const e = [];
1695
- for (const t of S.value) {
1696
- const o = T.get(t);
1697
- o && e.push(o);
1698
- }
1699
- return e;
747
+ // Focus state
748
+ focus: {
749
+ cell: p
1700
750
  },
1701
- selectRecords: (e) => {
1702
- for (const t of e) {
1703
- const o = ne(t);
1704
- o !== void 0 && Ve(o);
1705
- }
751
+ // Structure methods
752
+ createCaption: () => c.createCaption(),
753
+ deleteCaption: () => {
754
+ c.deleteCaption(), f();
1706
755
  },
1707
- deselectRecords: (e) => {
1708
- for (const t of e) {
1709
- const o = ne(t);
1710
- o !== void 0 && Be(o);
1711
- }
756
+ createTHead: () => c.createTHead(),
757
+ deleteTHead: () => {
758
+ c.deleteTHead(), f();
1712
759
  },
1713
- getSelectedRecords: () => {
1714
- const e = [];
1715
- for (const t of S.value) {
1716
- const o = ue(t);
1717
- o && e.push(o);
1718
- }
1719
- return e;
1720
- },
1721
- onRecordChange: (e) => {
1722
- const t = (o, n, r) => {
1723
- e(o, n, r);
1724
- };
1725
- return ce.push(t), () => {
1726
- const o = ce.indexOf(t);
1727
- o >= 0 && ce.splice(o, 1);
1728
- };
1729
- },
1730
- setIdGenerator: (e) => {
1731
- Bt = e;
1732
- },
1733
- rowToRecord: ue,
1734
- recordToRow: be,
1735
- exportRecordsToJSON: () => {
1736
- const e = Pt();
1737
- return JSON.stringify(e, null, 2);
1738
- },
1739
- importRecordsFromJSON: (e) => {
1740
- try {
1741
- const t = JSON.parse(e);
1742
- if (!Array.isArray(t))
1743
- throw new Error("JSON must be an array of records");
1744
- for (const o of t) {
1745
- if (typeof o != "object" || o === null)
1746
- throw new Error("Each record must be an object");
1747
- if (!("id" in o) || typeof o.id != "string")
1748
- throw new Error("Each record must have a string id field");
1749
- }
1750
- Ot(t);
1751
- } catch (t) {
1752
- throw new Error(`Invalid JSON: ${t instanceof Error ? t.message : String(t)}`);
1753
- }
1754
- }
760
+ createTFoot: () => c.createTFoot(),
761
+ deleteTFoot: () => {
762
+ c.deleteTFoot(), f();
763
+ },
764
+ createTBody: () => c.createTBody(),
765
+ // Header methods
766
+ setHeaders: ve,
767
+ setHeader: pe,
768
+ addHeader: ye,
769
+ removeHeader: me,
770
+ // Row methods
771
+ addRow: He,
772
+ removeRow: Fe,
773
+ removeRowById: De,
774
+ updateRow: Be,
775
+ updateRowById: Ie,
776
+ moveRow: Te,
777
+ swapRows: Se,
778
+ clearRows: Ee,
779
+ // Column methods
780
+ addColumn: be,
781
+ removeColumn: Le,
782
+ moveColumn: Ue,
783
+ swapColumns: Ae,
784
+ setColumnData: Ge,
785
+ // Cell methods
786
+ getCell: Ke,
787
+ setCell: ke,
788
+ setCellByRowId: Ve,
789
+ setCellRange: Me,
790
+ getCellElement: Ne,
791
+ // Row access methods
792
+ getRowData: Pe,
793
+ getRowDataById: je,
794
+ getRowElement: ze,
795
+ getRowById: $e,
796
+ getRowId: _e,
797
+ getRowIndex: qe,
798
+ getColumnData: Je,
799
+ // Footer methods
800
+ setFooter: Oe,
801
+ setFooterCell: Qe,
802
+ getFooterCell: We,
803
+ clearFooter: Xe,
804
+ // Caption methods
805
+ setCaption: Ye,
806
+ // Bulk operations
807
+ setData: Ze,
808
+ reset: xe,
809
+ sync: et,
810
+ // Selection methods
811
+ selectRow: a,
812
+ deselectRow: i,
813
+ toggleRowSelection: g,
814
+ selectAllRows: w,
815
+ deselectAllRows: B,
816
+ selectRowRange: G,
817
+ isRowSelected: K,
818
+ getSelectedRowIndices: $,
819
+ getSelectedRowData: ne,
820
+ selectCell: J,
821
+ deselectCell: O,
822
+ toggleCellSelection: re,
823
+ isCellSelected: se,
824
+ clearSelection: _,
825
+ // Focus methods
826
+ focusCell: b,
827
+ clearFocus: Q,
828
+ getFocusedCell: ce,
829
+ isCellFocused: le,
830
+ moveFocusUp: W,
831
+ moveFocusDown: X,
832
+ moveFocusLeft: Y,
833
+ moveFocusRight: Z,
834
+ moveFocusToFirst: x,
835
+ moveFocusToLast: ee,
836
+ enableKeyboardNavigation: ae,
837
+ // Record-based operations
838
+ setRecords: ue,
839
+ getRecordData: de,
840
+ addRecord: ie,
841
+ updateRecordRow: we,
842
+ removeRecord: fe,
843
+ hasRecord: ge,
844
+ getSelectedRecordIds: Ce,
845
+ selectRecords: Re,
846
+ deselectRecords: he,
847
+ // ID generator
848
+ setIdGenerator: (t) => c.setIdGenerator(t),
849
+ generateId: () => c.generateId(),
850
+ // Event hooks
851
+ onRowAdd: tt,
852
+ onRowRemove: ot,
853
+ onRowUpdate: nt,
854
+ onCellChange: rt,
855
+ onHeaderChange: st,
856
+ onDataChange: ct,
857
+ onSelectionChange: lt,
858
+ onFocusChange: at,
859
+ // Cleanup
860
+ destroy: te
1755
861
  };
1756
862
  }
1757
- const Xe = Symbol("idGenerated");
1758
- function il() {
863
+ const q = /* @__PURE__ */ Symbol("idGenerated");
864
+ function wt() {
1759
865
  return crypto.randomUUID();
1760
866
  }
1761
- function Ml(s, u = il) {
1762
- return "id" in s && typeof s.id == "string" && s.id.length > 0 ? s : {
1763
- ...s,
1764
- id: u(),
1765
- [Xe]: !0
867
+ function Rt(l, C = wt) {
868
+ return "id" in l && typeof l.id == "string" && l.id.length > 0 ? l : {
869
+ ...l,
870
+ id: C(),
871
+ [q]: !0
1766
872
  };
1767
873
  }
1768
- function fl(s) {
1769
- return Xe in s && s[Xe] === !0;
874
+ function ft(l) {
875
+ return q in l && l[q] === !0;
1770
876
  }
1771
- function Fl(s) {
1772
- return typeof s == "string" && s.length > 0;
877
+ function ht(l) {
878
+ return typeof l == "string" && l.length > 0;
1773
879
  }
1774
- function Ll(s, u) {
1775
- return s.find((c) => c.id === u);
880
+ function vt(l, C) {
881
+ return l.find((H) => H.id === C);
1776
882
  }
1777
- function Hl(s, u) {
1778
- return s.findIndex((c) => c.id === u);
883
+ function pt(l, C) {
884
+ return l.findIndex((H) => H.id === C);
1779
885
  }
1780
- function Nl(s) {
1781
- if (!fl(s))
1782
- return s;
1783
- const { id: u, ...c } = s;
1784
- return c;
886
+ function yt(l) {
887
+ if (!ft(l))
888
+ return l;
889
+ const { id: C, ...H } = l;
890
+ return H;
1785
891
  }
1786
892
  export {
1787
- Xe as ID_GENERATED,
1788
- Ml as ensureId,
1789
- Ll as findById,
1790
- il as generateId,
1791
- Hl as indexById,
1792
- Ae as isCellConfig,
1793
- Fl as isValidId,
1794
- Jt as isValidationError,
1795
- Al as isValidationErrorArray,
1796
- Dl as isValidationResult,
1797
- Nl as stripGeneratedId,
1798
- Tl as useTable,
1799
- fl as wasIdGenerated
893
+ q as ID_GENERATED,
894
+ it as createTable,
895
+ Rt as ensureId,
896
+ vt as findById,
897
+ wt as generateId,
898
+ pt as indexById,
899
+ ht as isValidId,
900
+ yt as stripGeneratedId,
901
+ Ct as useTable,
902
+ ft as wasIdGenerated
1800
903
  };