@toolbox-web/grid 1.14.1 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/all.js +2013 -1564
- package/all.js.map +1 -1
- package/index.js +918 -880
- package/index.js.map +1 -1
- package/lib/core/grid.d.ts.map +1 -1
- package/lib/core/internal/columns.d.ts +0 -5
- package/lib/core/internal/columns.d.ts.map +1 -1
- package/lib/core/internal/rows.d.ts.map +1 -1
- package/lib/core/internal/validate-config.d.ts.map +1 -1
- package/lib/core/types.d.ts +12 -0
- package/lib/core/types.d.ts.map +1 -1
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/ColumnVirtualizationPlugin.d.ts.map +1 -1
- package/lib/plugins/column-virtualization/index.js +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/ContextMenuPlugin.d.ts +20 -1
- package/lib/plugins/context-menu/ContextMenuPlugin.d.ts.map +1 -1
- package/lib/plugins/context-menu/index.d.ts +1 -1
- package/lib/plugins/context-menu/index.d.ts.map +1 -1
- package/lib/plugins/context-menu/index.js +177 -84
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/context-menu/menu.d.ts +7 -0
- package/lib/plugins/context-menu/menu.d.ts.map +1 -1
- package/lib/plugins/context-menu/types.d.ts +48 -2
- package/lib/plugins/context-menu/types.d.ts.map +1 -1
- package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
- package/lib/plugins/editing/index.js +327 -298
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/FilteringPlugin.d.ts +7 -1
- package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
- package/lib/plugins/filtering/filter-model.d.ts.map +1 -1
- package/lib/plugins/filtering/index.js +173 -138
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts +5 -1
- package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts.map +1 -1
- package/lib/plugins/grouping-columns/index.js +242 -109
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-columns/types.d.ts +7 -0
- package/lib/plugins/grouping-columns/types.d.ts.map +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/PinnedColumnsPlugin.d.ts +11 -1
- package/lib/plugins/pinned-columns/PinnedColumnsPlugin.d.ts.map +1 -1
- package/lib/plugins/pinned-columns/index.d.ts +1 -1
- package/lib/plugins/pinned-columns/index.d.ts.map +1 -1
- package/lib/plugins/pinned-columns/index.js +174 -79
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-columns/pinned-columns.d.ts +23 -4
- package/lib/plugins/pinned-columns/pinned-columns.d.ts.map +1 -1
- package/lib/plugins/pinned-columns/types.d.ts +21 -9
- package/lib/plugins/pinned-columns/types.d.ts.map +1 -1
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/print/index.js.map +1 -1
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/row-reorder/index.js.map +1 -1
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/VisibilityPlugin.d.ts +42 -2
- package/lib/plugins/visibility/VisibilityPlugin.d.ts.map +1 -1
- package/lib/plugins/visibility/index.d.ts +1 -1
- package/lib/plugins/visibility/index.d.ts.map +1 -1
- package/lib/plugins/visibility/index.js +219 -59
- package/lib/plugins/visibility/index.js.map +1 -1
- package/lib/plugins/visibility/types.d.ts +25 -0
- package/lib/plugins/visibility/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +27 -27
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +21 -21
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/column-virtualization.umd.js +1 -1
- package/umd/plugins/column-virtualization.umd.js.map +1 -1
- package/umd/plugins/context-menu.umd.js +1 -1
- package/umd/plugins/context-menu.umd.js.map +1 -1
- package/umd/plugins/editing.umd.js +1 -1
- package/umd/plugins/editing.umd.js.map +1 -1
- package/umd/plugins/filtering.umd.js +1 -1
- package/umd/plugins/filtering.umd.js.map +1 -1
- package/umd/plugins/grouping-columns.umd.js +1 -1
- package/umd/plugins/grouping-columns.umd.js.map +1 -1
- package/umd/plugins/pinned-columns.umd.js +1 -1
- package/umd/plugins/pinned-columns.umd.js.map +1 -1
- package/umd/plugins/visibility.umd.js +1 -1
- package/umd/plugins/visibility.umd.js.map +1 -1
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
1
|
+
function M(o) {
|
|
2
|
+
o && o.querySelectorAll(".cell-focus").forEach((e) => e.classList.remove("cell-focus"));
|
|
3
3
|
}
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
function L(
|
|
9
|
-
if (
|
|
10
|
-
const { rowHeight:
|
|
4
|
+
const v = 'input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])', P = document.createElement("template");
|
|
5
|
+
P.innerHTML = '<div class="cell" role="gridcell" part="cell"></div>';
|
|
6
|
+
const D = document.createElement("template");
|
|
7
|
+
D.innerHTML = '<div class="data-grid-row" role="row" part="row"></div>';
|
|
8
|
+
function L(o, e) {
|
|
9
|
+
if (o._virtualization?.enabled) {
|
|
10
|
+
const { rowHeight: n, container: l, viewportEl: c } = o._virtualization, a = l, d = c?.clientHeight ?? a?.clientHeight ?? 0;
|
|
11
11
|
if (a && d > 0) {
|
|
12
|
-
const g =
|
|
13
|
-
g < a.scrollTop ? a.scrollTop = g : g +
|
|
12
|
+
const g = o._focusRow * n;
|
|
13
|
+
g < a.scrollTop ? a.scrollTop = g : g + n > a.scrollTop + d && (a.scrollTop = g - d + n);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
const t =
|
|
17
|
-
t ||
|
|
18
|
-
|
|
16
|
+
const t = o._activeEditRows !== void 0 && o._activeEditRows !== -1;
|
|
17
|
+
t || o.refreshVirtualWindow(!1), M(o._bodyEl), Array.from(o._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach((n) => {
|
|
18
|
+
n.setAttribute("aria-selected", "false");
|
|
19
19
|
});
|
|
20
|
-
const i =
|
|
21
|
-
if (i >=
|
|
22
|
-
const
|
|
23
|
-
let
|
|
24
|
-
if ((!
|
|
25
|
-
|
|
26
|
-
const c =
|
|
27
|
-
if (c &&
|
|
20
|
+
const i = o._focusRow, r = o._virtualization.start ?? 0, s = o._virtualization.end ?? o._rows.length;
|
|
21
|
+
if (i >= r && i < s) {
|
|
22
|
+
const n = o._bodyEl.querySelectorAll(".data-grid-row")[i - r];
|
|
23
|
+
let l = n?.children[o._focusCol];
|
|
24
|
+
if ((!l || !l.classList?.contains("cell")) && (l = n?.querySelector(`.cell[data-col="${o._focusCol}"]`) ?? n?.querySelector(".cell[data-col]")), l) {
|
|
25
|
+
l.classList.add("cell-focus"), l.setAttribute("aria-selected", "true");
|
|
26
|
+
const c = o.querySelector(".tbw-scroll-area");
|
|
27
|
+
if (c && l && (!t || e?.forceHorizontalScroll))
|
|
28
28
|
if (e?.forceScrollLeft)
|
|
29
29
|
c.scrollLeft = 0;
|
|
30
30
|
else if (e?.forceScrollRight)
|
|
31
31
|
c.scrollLeft = c.scrollWidth - c.clientWidth;
|
|
32
32
|
else {
|
|
33
|
-
const a =
|
|
33
|
+
const a = o._getHorizontalScrollOffsets?.(n ?? void 0, l) ?? { left: 0, right: 0 };
|
|
34
34
|
if (!a.skipScroll) {
|
|
35
|
-
const d =
|
|
35
|
+
const d = l.getBoundingClientRect(), g = c.getBoundingClientRect(), f = d.left - g.left + c.scrollLeft, E = f + d.width, p = c.scrollLeft + a.left, m = c.scrollLeft + c.clientWidth - a.right;
|
|
36
36
|
f < p ? c.scrollLeft = f - a.left : E > m && (c.scrollLeft = E - c.clientWidth + a.right);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
if (
|
|
40
|
-
const a =
|
|
39
|
+
if (o._activeEditRows !== void 0 && o._activeEditRows !== -1 && l.classList.contains("editing")) {
|
|
40
|
+
const a = l.querySelector(v);
|
|
41
41
|
if (a && document.activeElement !== a)
|
|
42
42
|
try {
|
|
43
43
|
a.focus({ preventScroll: !0 });
|
|
44
44
|
} catch {
|
|
45
45
|
}
|
|
46
|
-
} else if (!
|
|
47
|
-
|
|
46
|
+
} else if (!l.contains(document.activeElement)) {
|
|
47
|
+
l.hasAttribute("tabindex") || l.setAttribute("tabindex", "-1");
|
|
48
48
|
try {
|
|
49
|
-
|
|
49
|
+
l.focus({ preventScroll: !0 });
|
|
50
50
|
} catch {
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
const I = '<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>',
|
|
56
|
+
const I = '<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>', H = {
|
|
57
57
|
expand: "▶",
|
|
58
58
|
collapse: "▼",
|
|
59
59
|
sortAsc: "▲",
|
|
@@ -356,7 +356,7 @@ class O {
|
|
|
356
356
|
*/
|
|
357
357
|
get gridIcons() {
|
|
358
358
|
const e = this.grid?.gridConfig?.icons ?? {};
|
|
359
|
-
return { ...
|
|
359
|
+
return { ...H, ...e };
|
|
360
360
|
}
|
|
361
361
|
// #region Animation Helpers
|
|
362
362
|
/**
|
|
@@ -432,123 +432,123 @@ class O {
|
|
|
432
432
|
}
|
|
433
433
|
// #endregion
|
|
434
434
|
}
|
|
435
|
-
const
|
|
436
|
-
function
|
|
437
|
-
const e =
|
|
435
|
+
const B = "@layer tbw-plugins{tbw-grid{--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-row-bg: var(--tbw-editing-bg);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-editing-row-outline-color: var(--tbw-color-accent);--tbw-editing-row-outline-width: 1px;--tbw-invalid-bg: light-dark(#fef2f2, #450a0a);--tbw-invalid-border-color: light-dark(#ef4444, #f87171)}tbw-grid:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex;min-height:calc(var(--tbw-row-height) + 2px);align-items:center;justify-content:center}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{width:100%;height:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}tbw-grid .tbw-editor-host{display:contents}tbw-grid .data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}";
|
|
436
|
+
function x(o) {
|
|
437
|
+
const e = o.options;
|
|
438
438
|
return e ? typeof e == "function" ? e() : e : [];
|
|
439
439
|
}
|
|
440
|
-
function N(
|
|
440
|
+
function N(o) {
|
|
441
441
|
return (e) => {
|
|
442
|
-
const t =
|
|
442
|
+
const t = o.editorParams, i = document.createElement("input");
|
|
443
443
|
i.type = "number", i.value = e.value != null ? String(e.value) : "", t?.min !== void 0 && (i.min = String(t.min)), t?.max !== void 0 && (i.max = String(t.max)), t?.step !== void 0 && (i.step = String(t.step)), t?.placeholder && (i.placeholder = t.placeholder);
|
|
444
|
-
const
|
|
445
|
-
return i.addEventListener("blur",
|
|
446
|
-
s.key === "Enter" &&
|
|
444
|
+
const r = () => e.commit(i.value === "" ? null : Number(i.value));
|
|
445
|
+
return i.addEventListener("blur", r), i.addEventListener("keydown", (s) => {
|
|
446
|
+
s.key === "Enter" && r(), s.key === "Escape" && e.cancel();
|
|
447
447
|
}), i;
|
|
448
448
|
};
|
|
449
449
|
}
|
|
450
450
|
function $() {
|
|
451
|
-
return (
|
|
451
|
+
return (o) => {
|
|
452
452
|
const e = document.createElement("input");
|
|
453
|
-
return e.type = "checkbox", e.checked = !!
|
|
453
|
+
return e.type = "checkbox", e.checked = !!o.value, e.addEventListener("change", () => o.commit(e.checked)), e;
|
|
454
454
|
};
|
|
455
455
|
}
|
|
456
|
-
function
|
|
456
|
+
function G(o) {
|
|
457
457
|
return (e) => {
|
|
458
|
-
const t =
|
|
458
|
+
const t = o.editorParams, i = document.createElement("input");
|
|
459
459
|
i.type = "date", e.value instanceof Date ? i.valueAsDate = e.value : typeof e.value == "string" && e.value && (i.value = e.value.split("T")[0]), t?.min && (i.min = t.min), t?.max && (i.max = t.max), t?.placeholder && (i.placeholder = t.placeholder);
|
|
460
|
-
const
|
|
460
|
+
const r = () => {
|
|
461
461
|
typeof e.value == "string" ? e.commit(i.value) : e.commit(i.valueAsDate);
|
|
462
462
|
};
|
|
463
|
-
return i.addEventListener("change",
|
|
463
|
+
return i.addEventListener("change", r), i.addEventListener("keydown", (s) => {
|
|
464
464
|
s.key === "Escape" && e.cancel();
|
|
465
465
|
}), i;
|
|
466
466
|
};
|
|
467
467
|
}
|
|
468
|
-
function
|
|
468
|
+
function z(o) {
|
|
469
469
|
return (e) => {
|
|
470
|
-
const t =
|
|
471
|
-
if (
|
|
472
|
-
const
|
|
473
|
-
|
|
470
|
+
const t = o.editorParams, i = document.createElement("select");
|
|
471
|
+
if (o.multi && (i.multiple = !0), t?.includeEmpty) {
|
|
472
|
+
const n = document.createElement("option");
|
|
473
|
+
n.value = "", n.textContent = t.emptyLabel ?? "", i.appendChild(n);
|
|
474
474
|
}
|
|
475
|
-
|
|
476
|
-
const
|
|
477
|
-
|
|
475
|
+
x(o).forEach((n) => {
|
|
476
|
+
const l = document.createElement("option");
|
|
477
|
+
l.value = String(n.value), l.textContent = n.label, (o.multi && Array.isArray(e.value) && e.value.includes(n.value) || !o.multi && e.value === n.value) && (l.selected = !0), i.appendChild(l);
|
|
478
478
|
});
|
|
479
479
|
const s = () => {
|
|
480
|
-
if (
|
|
481
|
-
const
|
|
482
|
-
e.commit(
|
|
480
|
+
if (o.multi) {
|
|
481
|
+
const n = Array.from(i.selectedOptions).map((l) => l.value);
|
|
482
|
+
e.commit(n);
|
|
483
483
|
} else
|
|
484
484
|
e.commit(i.value);
|
|
485
485
|
};
|
|
486
|
-
return i.addEventListener("change", s), i.addEventListener("blur", s), i.addEventListener("keydown", (
|
|
487
|
-
|
|
486
|
+
return i.addEventListener("change", s), i.addEventListener("blur", s), i.addEventListener("keydown", (n) => {
|
|
487
|
+
n.key === "Escape" && e.cancel();
|
|
488
488
|
}), i;
|
|
489
489
|
};
|
|
490
490
|
}
|
|
491
|
-
function F(
|
|
491
|
+
function F(o) {
|
|
492
492
|
return (e) => {
|
|
493
|
-
const t =
|
|
493
|
+
const t = o.editorParams, i = document.createElement("input");
|
|
494
494
|
i.type = "text", i.value = e.value != null ? String(e.value) : "", t?.maxLength !== void 0 && (i.maxLength = t.maxLength), t?.pattern && (i.pattern = t.pattern), t?.placeholder && (i.placeholder = t.placeholder);
|
|
495
|
-
const
|
|
495
|
+
const r = () => {
|
|
496
496
|
const s = i.value;
|
|
497
497
|
(e.value === null || e.value === void 0) && s === "" || typeof e.value == "string" && s === e.value.replace(/[\n\r]/g, "") || (typeof e.value == "number" && s !== "" ? e.commit(Number(s)) : e.commit(s));
|
|
498
498
|
};
|
|
499
|
-
return i.addEventListener("blur",
|
|
500
|
-
s.key === "Enter" &&
|
|
499
|
+
return i.addEventListener("blur", r), i.addEventListener("keydown", (s) => {
|
|
500
|
+
s.key === "Enter" && r(), s.key === "Escape" && e.cancel();
|
|
501
501
|
}), i;
|
|
502
502
|
};
|
|
503
503
|
}
|
|
504
|
-
function
|
|
505
|
-
switch (
|
|
504
|
+
function K(o) {
|
|
505
|
+
switch (o.type) {
|
|
506
506
|
case "number":
|
|
507
|
-
return N(
|
|
507
|
+
return N(o);
|
|
508
508
|
case "boolean":
|
|
509
509
|
return $();
|
|
510
510
|
case "date":
|
|
511
|
-
return
|
|
511
|
+
return G(o);
|
|
512
512
|
case "select":
|
|
513
|
-
return
|
|
513
|
+
return z(o);
|
|
514
514
|
default:
|
|
515
|
-
return F(
|
|
515
|
+
return F(o);
|
|
516
516
|
}
|
|
517
517
|
}
|
|
518
|
-
function
|
|
518
|
+
function j(o, e) {
|
|
519
519
|
if (e.editor) return e.editor;
|
|
520
520
|
if (e.__editorTemplate) return "template";
|
|
521
521
|
if (!e.type) return;
|
|
522
|
-
const i =
|
|
522
|
+
const i = o.effectiveConfig?.typeDefaults;
|
|
523
523
|
if (i?.[e.type]?.editor)
|
|
524
524
|
return i[e.type].editor;
|
|
525
|
-
const
|
|
526
|
-
if (
|
|
527
|
-
const s =
|
|
525
|
+
const r = o.__frameworkAdapter;
|
|
526
|
+
if (r?.getTypeDefault) {
|
|
527
|
+
const s = r.getTypeDefault(e.type);
|
|
528
528
|
if (s?.editor)
|
|
529
529
|
return s.editor;
|
|
530
530
|
}
|
|
531
531
|
}
|
|
532
|
-
function S(
|
|
533
|
-
return !(typeof
|
|
532
|
+
function S(o) {
|
|
533
|
+
return !(typeof o != "string" || o === "__proto__" || o === "constructor" || o === "prototype");
|
|
534
534
|
}
|
|
535
|
-
function
|
|
536
|
-
const e = (
|
|
537
|
-
|
|
535
|
+
function W(o) {
|
|
536
|
+
const e = (o.__editingCellCount ?? 0) + 1;
|
|
537
|
+
o.__editingCellCount = e, o.setAttribute("data-has-editing", "");
|
|
538
538
|
}
|
|
539
|
-
function U(
|
|
540
|
-
|
|
539
|
+
function U(o) {
|
|
540
|
+
o.__editingCellCount = 0, o.removeAttribute("data-has-editing");
|
|
541
541
|
}
|
|
542
|
-
function _(
|
|
543
|
-
return
|
|
542
|
+
function _(o, e, t) {
|
|
543
|
+
return o instanceof HTMLInputElement ? o.type === "checkbox" ? o.checked : o.type === "number" ? o.value === "" ? null : Number(o.value) : o.type === "date" ? typeof t == "string" ? o.value : o.valueAsDate : typeof t == "number" ? o.value === "" ? null : Number(o.value) : t == null && o.value === "" || typeof t == "string" && o.value === t.replace(/[\n\r]/g, "") ? t : o.value : e?.type === "number" && o.value !== "" || typeof t == "number" && o.value !== "" ? Number(o.value) : t == null && o.value === "" ? t : o.value;
|
|
544
544
|
}
|
|
545
|
-
function T(
|
|
545
|
+
function T(o) {
|
|
546
546
|
}
|
|
547
|
-
function Q(
|
|
548
|
-
const
|
|
549
|
-
|
|
550
|
-
t(_(
|
|
551
|
-
}),
|
|
547
|
+
function Q(o, e, t, i) {
|
|
548
|
+
const r = o.querySelector("input,textarea,select");
|
|
549
|
+
r && (r.addEventListener("blur", () => {
|
|
550
|
+
t(_(r, e, i));
|
|
551
|
+
}), r instanceof HTMLInputElement && r.type === "checkbox" ? r.addEventListener("change", () => t(r.checked)) : r instanceof HTMLSelectElement && r.addEventListener("change", () => t(_(r, e, i))));
|
|
552
552
|
}
|
|
553
553
|
class X extends O {
|
|
554
554
|
/**
|
|
@@ -590,7 +590,7 @@ class X extends O {
|
|
|
590
590
|
/** @internal */
|
|
591
591
|
name = "editing";
|
|
592
592
|
/** @internal */
|
|
593
|
-
styles =
|
|
593
|
+
styles = B;
|
|
594
594
|
/** @internal */
|
|
595
595
|
get defaultConfig() {
|
|
596
596
|
return {
|
|
@@ -608,11 +608,11 @@ class X extends O {
|
|
|
608
608
|
/** Currently active edit row index, or -1 if not editing */
|
|
609
609
|
#e = -1;
|
|
610
610
|
/** Currently active edit column index, or -1 if not editing */
|
|
611
|
-
#
|
|
611
|
+
#u = -1;
|
|
612
612
|
/** Snapshots of row data before editing started */
|
|
613
613
|
#l = /* @__PURE__ */ new Map();
|
|
614
614
|
/** Set of row IDs that have been modified (ID-based for stability) */
|
|
615
|
-
#
|
|
615
|
+
#r = /* @__PURE__ */ new Set();
|
|
616
616
|
/** Set of cells currently in edit mode: "rowIndex:colIndex" */
|
|
617
617
|
#o = /* @__PURE__ */ new Set();
|
|
618
618
|
/**
|
|
@@ -622,9 +622,9 @@ class X extends O {
|
|
|
622
622
|
*/
|
|
623
623
|
#c = /* @__PURE__ */ new Map();
|
|
624
624
|
/** Flag to restore focus after next render (used when exiting edit mode) */
|
|
625
|
-
#
|
|
625
|
+
#f = !1;
|
|
626
626
|
/** Row index pending animation after render, or -1 if none */
|
|
627
|
-
#
|
|
627
|
+
#h = -1;
|
|
628
628
|
/**
|
|
629
629
|
* Invalid cell tracking: Map<rowId, Map<field, message>>
|
|
630
630
|
* Used for validation feedback without canceling edits.
|
|
@@ -636,13 +636,18 @@ class X extends O {
|
|
|
636
636
|
* When false: arrow keys navigate between cells (navigation mode).
|
|
637
637
|
* Escape switches to navigation mode, Enter switches to edit mode.
|
|
638
638
|
*/
|
|
639
|
-
#
|
|
639
|
+
#n = !1;
|
|
640
640
|
/**
|
|
641
641
|
* In grid mode, when true, prevents inputs from auto-focusing.
|
|
642
642
|
* This is set when Escape is pressed (navigation mode) and cleared
|
|
643
643
|
* when Enter is pressed or user explicitly clicks an input.
|
|
644
644
|
*/
|
|
645
645
|
#a = !1;
|
|
646
|
+
/**
|
|
647
|
+
* When true, only a single cell is being edited (triggered by F2 or `beginCellEdit`).
|
|
648
|
+
* Tab and Arrow keys commit and close the editor instead of navigating to adjacent cells.
|
|
649
|
+
*/
|
|
650
|
+
#d = !1;
|
|
646
651
|
// #endregion
|
|
647
652
|
// #region Lifecycle
|
|
648
653
|
/** @internal */
|
|
@@ -655,77 +660,80 @@ class X extends O {
|
|
|
655
660
|
}), Object.defineProperty(e, "changedRowIds", {
|
|
656
661
|
get: () => this.changedRowIds,
|
|
657
662
|
configurable: !0
|
|
658
|
-
}), e.resetChangedRows = (
|
|
659
|
-
s && this.beginCellEdit(
|
|
663
|
+
}), e.resetChangedRows = (r) => this.resetChangedRows(r), e.beginBulkEdit = (r, s) => {
|
|
664
|
+
s && this.beginCellEdit(r, s);
|
|
660
665
|
}, document.addEventListener(
|
|
661
666
|
"keydown",
|
|
662
|
-
(
|
|
663
|
-
if (!this.#t &&
|
|
664
|
-
if (this.config.onBeforeEditClose && this.config.onBeforeEditClose(
|
|
667
|
+
(r) => {
|
|
668
|
+
if (!this.#t && r.key === "Escape" && this.#e !== -1) {
|
|
669
|
+
if (this.config.onBeforeEditClose && this.config.onBeforeEditClose(r) === !1)
|
|
665
670
|
return;
|
|
666
|
-
this.#
|
|
671
|
+
this.#s(this.#e, !0);
|
|
667
672
|
}
|
|
668
673
|
},
|
|
669
674
|
{ capture: !0, signal: t }
|
|
670
675
|
), document.addEventListener(
|
|
671
676
|
"mousedown",
|
|
672
|
-
(
|
|
677
|
+
(r) => {
|
|
673
678
|
if (this.#t || this.#e === -1) return;
|
|
674
679
|
const s = i.findRenderedRowElement?.(this.#e);
|
|
675
|
-
!s || (
|
|
676
|
-
this.#e !== -1 && this.#
|
|
680
|
+
!s || (r.composedPath && r.composedPath() || []).includes(s) || this.config.onBeforeEditClose && this.config.onBeforeEditClose(r) === !1 || queueMicrotask(() => {
|
|
681
|
+
this.#e !== -1 && this.#s(this.#e, !1);
|
|
677
682
|
});
|
|
678
683
|
},
|
|
679
684
|
{ signal: t }
|
|
680
685
|
), this.gridElement.addEventListener(
|
|
681
686
|
"cell-change",
|
|
682
|
-
(
|
|
683
|
-
const s =
|
|
687
|
+
(r) => {
|
|
688
|
+
const s = r.detail;
|
|
684
689
|
if (s.source === "user") return;
|
|
685
|
-
const
|
|
686
|
-
|
|
690
|
+
const n = `${s.rowIndex}:${s.field}`, l = this.#c.get(n);
|
|
691
|
+
l && l(s.newValue);
|
|
687
692
|
},
|
|
688
693
|
{ signal: t }
|
|
689
|
-
), this.#t && (this.gridElement.classList.add("tbw-grid-mode"), this.requestRender(), this.gridElement.addEventListener(
|
|
694
|
+
), this.#t && (i._isGridEditMode = !0, this.gridElement.classList.add("tbw-grid-mode"), this.requestRender(), this.gridElement.addEventListener(
|
|
690
695
|
"focusin",
|
|
691
|
-
(
|
|
692
|
-
const s =
|
|
693
|
-
if (s.matches(
|
|
696
|
+
(r) => {
|
|
697
|
+
const s = r.target;
|
|
698
|
+
if (s.matches(v)) {
|
|
694
699
|
if (this.#a) {
|
|
695
700
|
s.blur(), this.gridElement.focus();
|
|
696
701
|
return;
|
|
697
702
|
}
|
|
698
|
-
this.#
|
|
703
|
+
this.#n = !0;
|
|
699
704
|
}
|
|
700
705
|
},
|
|
701
706
|
{ signal: t }
|
|
702
707
|
), this.gridElement.addEventListener(
|
|
703
708
|
"focusout",
|
|
704
|
-
(
|
|
705
|
-
const s =
|
|
706
|
-
(!s || !this.gridElement.contains(s) || !s.matches(
|
|
709
|
+
(r) => {
|
|
710
|
+
const s = r.relatedTarget;
|
|
711
|
+
(!s || !this.gridElement.contains(s) || !s.matches(v)) && (this.#n = !1);
|
|
707
712
|
},
|
|
708
713
|
{ signal: t }
|
|
709
714
|
), this.gridElement.addEventListener(
|
|
710
715
|
"keydown",
|
|
711
|
-
(
|
|
712
|
-
if (
|
|
716
|
+
(r) => {
|
|
717
|
+
if (r.key === "Escape" && this.#n) {
|
|
718
|
+
if (this.config.onBeforeEditClose && this.config.onBeforeEditClose(r) === !1)
|
|
719
|
+
return;
|
|
713
720
|
const s = document.activeElement;
|
|
714
|
-
s && this.gridElement.contains(s) && (s.blur(), this.gridElement.focus()), this.#
|
|
721
|
+
s && this.gridElement.contains(s) && (s.blur(), this.gridElement.focus()), this.#n = !1, this.#a = !0, r.preventDefault(), r.stopPropagation();
|
|
715
722
|
}
|
|
716
723
|
},
|
|
717
724
|
{ capture: !0, signal: t }
|
|
718
725
|
), this.gridElement.addEventListener(
|
|
719
726
|
"mousedown",
|
|
720
|
-
(
|
|
721
|
-
|
|
727
|
+
(r) => {
|
|
728
|
+
r.target.matches(v) && (this.#a = !1);
|
|
722
729
|
},
|
|
723
730
|
{ signal: t }
|
|
724
731
|
));
|
|
725
732
|
}
|
|
726
733
|
/** @internal */
|
|
727
734
|
detach() {
|
|
728
|
-
|
|
735
|
+
const e = this.gridElement;
|
|
736
|
+
e._isGridEditMode = !1, this.gridElement.classList.remove("tbw-grid-mode"), this.#e = -1, this.#u = -1, this.#l.clear(), this.#r.clear(), this.#o.clear(), this.#c.clear(), this.#n = !1, this.#a = !1, this.#d = !1, super.detach();
|
|
729
737
|
}
|
|
730
738
|
/**
|
|
731
739
|
* Handle plugin queries.
|
|
@@ -747,10 +755,10 @@ class X extends O {
|
|
|
747
755
|
if (this.#t) return !1;
|
|
748
756
|
const t = this.grid, i = this.config.editOn ?? t.effectiveConfig?.editOn;
|
|
749
757
|
if (i === !1 || i === "manual" || i !== "click" && i !== "dblclick") return !1;
|
|
750
|
-
const
|
|
751
|
-
if (i === "click" &&
|
|
758
|
+
const r = e.originalEvent.type === "dblclick";
|
|
759
|
+
if (i === "click" && r || i === "dblclick" && !r) return !1;
|
|
752
760
|
const { rowIndex: s } = e;
|
|
753
|
-
return t._columns?.some((
|
|
761
|
+
return t._columns?.some((l) => l.editable) ? (e.originalEvent.stopPropagation(), this.beginBulkEdit(s), !0) : !1;
|
|
754
762
|
}
|
|
755
763
|
/**
|
|
756
764
|
* Handle keyboard events for edit lifecycle.
|
|
@@ -759,56 +767,61 @@ class X extends O {
|
|
|
759
767
|
onKeyDown(e) {
|
|
760
768
|
const t = this.grid;
|
|
761
769
|
if (e.key === "Escape") {
|
|
762
|
-
if (this.#t && this.#
|
|
770
|
+
if (this.#t && this.#n) {
|
|
771
|
+
if (this.config.onBeforeEditClose && this.config.onBeforeEditClose(e) === !1)
|
|
772
|
+
return !0;
|
|
763
773
|
const i = document.activeElement;
|
|
764
|
-
return i && this.gridElement.contains(i) && i.blur(), this.#
|
|
774
|
+
return i && this.gridElement.contains(i) && i.blur(), this.#n = !1, this.requestAfterRender(), !0;
|
|
765
775
|
}
|
|
766
776
|
if (this.#e !== -1 && !this.#t)
|
|
767
|
-
return this.config.onBeforeEditClose && this.config.onBeforeEditClose(e) === !1 || this.#
|
|
777
|
+
return this.config.onBeforeEditClose && this.config.onBeforeEditClose(e) === !1 || this.#s(this.#e, !0), !0;
|
|
768
778
|
}
|
|
769
|
-
if (this.#t && !this.#
|
|
779
|
+
if (this.#t && !this.#n && (e.key === "ArrowUp" || e.key === "ArrowDown" || e.key === "ArrowLeft" || e.key === "ArrowRight"))
|
|
770
780
|
return !1;
|
|
781
|
+
if (this.#t && this.#n && (e.key === "ArrowUp" || e.key === "ArrowDown"))
|
|
782
|
+
return !0;
|
|
771
783
|
if ((e.key === "ArrowUp" || e.key === "ArrowDown") && this.#e !== -1 && !this.#t) {
|
|
772
784
|
if (this.config.onBeforeEditClose && this.config.onBeforeEditClose(e) === !1)
|
|
773
785
|
return !0;
|
|
774
|
-
const i = t._rows.length - 1,
|
|
775
|
-
return this.#
|
|
786
|
+
const i = t._rows.length - 1, r = this.#e;
|
|
787
|
+
return this.#s(r, !1), e.key === "ArrowDown" ? t._focusRow = Math.min(i, t._focusRow + 1) : t._focusRow = Math.max(0, t._focusRow - 1), e.preventDefault(), L(t), this.requestAfterRender(), !0;
|
|
776
788
|
}
|
|
777
789
|
if (e.key === "Tab" && (this.#e !== -1 || this.#t)) {
|
|
778
|
-
e.preventDefault()
|
|
790
|
+
if (e.preventDefault(), this.#d)
|
|
791
|
+
return this.#s(this.#e, !1), !0;
|
|
779
792
|
const i = !e.shiftKey;
|
|
780
|
-
return this.#
|
|
793
|
+
return this.#C(i), !0;
|
|
781
794
|
}
|
|
782
795
|
if (e.key === " " || e.key === "Spacebar") {
|
|
783
796
|
if (this.#e !== -1)
|
|
784
797
|
return !1;
|
|
785
|
-
const i = t._focusRow,
|
|
786
|
-
if (i >= 0 &&
|
|
787
|
-
const s = t._visibleColumns[
|
|
788
|
-
if (s?.editable && s.type === "boolean" &&
|
|
789
|
-
const
|
|
790
|
-
if (S(
|
|
791
|
-
const a = !l
|
|
792
|
-
return this.#
|
|
798
|
+
const i = t._focusRow, r = t._focusCol;
|
|
799
|
+
if (i >= 0 && r >= 0) {
|
|
800
|
+
const s = t._visibleColumns[r], n = t._rows[i];
|
|
801
|
+
if (s?.editable && s.type === "boolean" && n) {
|
|
802
|
+
const l = s.field;
|
|
803
|
+
if (S(l)) {
|
|
804
|
+
const a = !n[l];
|
|
805
|
+
return this.#E(i, s, a, n), e.preventDefault(), this.requestRender(), !0;
|
|
793
806
|
}
|
|
794
807
|
}
|
|
795
808
|
}
|
|
796
809
|
return !1;
|
|
797
810
|
}
|
|
798
|
-
if (e.key === "Enter" && !e.shiftKey) {
|
|
799
|
-
if (this.#t && !this.#
|
|
800
|
-
return this.#
|
|
811
|
+
if (e.key === "Enter" && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) {
|
|
812
|
+
if (this.#t && !this.#n)
|
|
813
|
+
return this.#y(), !0;
|
|
801
814
|
if (this.#e !== -1)
|
|
802
815
|
return !!(this.config.onBeforeEditClose && this.config.onBeforeEditClose(e) === !1);
|
|
803
816
|
const i = this.config.editOn ?? t.effectiveConfig?.editOn;
|
|
804
817
|
if (i === !1 || i === "manual") return !1;
|
|
805
|
-
const
|
|
806
|
-
if (
|
|
807
|
-
const
|
|
818
|
+
const r = t._focusRow, s = t._focusCol;
|
|
819
|
+
if (r >= 0 && t._columns?.some((l) => l.editable)) {
|
|
820
|
+
const l = t._visibleColumns[s], c = t._rows[r], a = l?.field ?? "", d = a && c ? c[a] : void 0, g = this.gridElement.querySelector(`[data-row="${r}"][data-col="${s}"]`), f = new CustomEvent("cell-activate", {
|
|
808
821
|
cancelable: !0,
|
|
809
822
|
bubbles: !0,
|
|
810
823
|
detail: {
|
|
811
|
-
rowIndex:
|
|
824
|
+
rowIndex: r,
|
|
812
825
|
colIndex: s,
|
|
813
826
|
field: a,
|
|
814
827
|
value: d,
|
|
@@ -822,9 +835,19 @@ class X extends O {
|
|
|
822
835
|
const E = new CustomEvent("activate-cell", {
|
|
823
836
|
cancelable: !0,
|
|
824
837
|
bubbles: !0,
|
|
825
|
-
detail: { row:
|
|
838
|
+
detail: { row: r, col: s }
|
|
826
839
|
});
|
|
827
|
-
return this.gridElement.dispatchEvent(E), f.defaultPrevented || E.defaultPrevented ? (e.preventDefault(), !0) : (this.beginBulkEdit(
|
|
840
|
+
return this.gridElement.dispatchEvent(E), f.defaultPrevented || E.defaultPrevented ? (e.preventDefault(), !0) : (this.beginBulkEdit(r), !0);
|
|
841
|
+
}
|
|
842
|
+
return !1;
|
|
843
|
+
}
|
|
844
|
+
if (e.key === "F2") {
|
|
845
|
+
if (this.#e !== -1 || this.#t || (this.config.editOn ?? t.effectiveConfig?.editOn) === !1) return !1;
|
|
846
|
+
const r = t._focusRow, s = t._focusCol;
|
|
847
|
+
if (r >= 0 && s >= 0) {
|
|
848
|
+
const n = t._visibleColumns[s];
|
|
849
|
+
if (n?.editable && n.field)
|
|
850
|
+
return e.preventDefault(), this.beginCellEdit(r, n.field), !0;
|
|
828
851
|
}
|
|
829
852
|
return !1;
|
|
830
853
|
}
|
|
@@ -838,17 +861,17 @@ class X extends O {
|
|
|
838
861
|
* @internal
|
|
839
862
|
*/
|
|
840
863
|
processColumns(e) {
|
|
841
|
-
const t = this.grid, i = t.effectiveConfig?.typeDefaults,
|
|
842
|
-
return !i && !
|
|
864
|
+
const t = this.grid, i = t.effectiveConfig?.typeDefaults, r = t.__frameworkAdapter;
|
|
865
|
+
return !i && !r?.getTypeDefault ? e : e.map((s) => {
|
|
843
866
|
if (!s.type) return s;
|
|
844
|
-
let
|
|
845
|
-
if (i?.[s.type]?.editorParams && (
|
|
846
|
-
const
|
|
847
|
-
|
|
867
|
+
let n;
|
|
868
|
+
if (i?.[s.type]?.editorParams && (n = i[s.type].editorParams), !n && r?.getTypeDefault) {
|
|
869
|
+
const l = r.getTypeDefault(s.type);
|
|
870
|
+
l?.editorParams && (n = l.editorParams);
|
|
848
871
|
}
|
|
849
|
-
return
|
|
872
|
+
return n ? {
|
|
850
873
|
...s,
|
|
851
|
-
editorParams: { ...
|
|
874
|
+
editorParams: { ...n, ...s.editorParams }
|
|
852
875
|
} : s;
|
|
853
876
|
});
|
|
854
877
|
}
|
|
@@ -860,18 +883,18 @@ class X extends O {
|
|
|
860
883
|
*/
|
|
861
884
|
afterRender() {
|
|
862
885
|
const e = this.grid;
|
|
863
|
-
if (this.#
|
|
864
|
-
const t = this.#
|
|
865
|
-
this.#
|
|
886
|
+
if (this.#f && (this.#f = !1, this.#v(e)), this.#h !== -1) {
|
|
887
|
+
const t = this.#h;
|
|
888
|
+
this.#h = -1, e.animateRow?.(t, "change");
|
|
866
889
|
}
|
|
867
890
|
if (!this.#t && this.#o.size !== 0)
|
|
868
891
|
for (const t of this.#o) {
|
|
869
|
-
const [i,
|
|
870
|
-
if (!
|
|
871
|
-
const c =
|
|
892
|
+
const [i, r] = t.split(":"), s = parseInt(i, 10), n = parseInt(r, 10), l = e.findRenderedRowElement?.(s);
|
|
893
|
+
if (!l) continue;
|
|
894
|
+
const c = l.querySelector(`.cell[data-col="${n}"]`);
|
|
872
895
|
if (!c || c.classList.contains("editing")) continue;
|
|
873
|
-
const a = e._rows[s], d = e._visibleColumns[
|
|
874
|
-
a && d && this.#
|
|
896
|
+
const a = e._rows[s], d = e._visibleColumns[n];
|
|
897
|
+
a && d && this.#m(a, s, d, n, c, !0);
|
|
875
898
|
}
|
|
876
899
|
}
|
|
877
900
|
/**
|
|
@@ -881,8 +904,8 @@ class X extends O {
|
|
|
881
904
|
*/
|
|
882
905
|
afterCellRender(e) {
|
|
883
906
|
if (!this.#t) return;
|
|
884
|
-
const { row: t, rowIndex: i, column:
|
|
885
|
-
|
|
907
|
+
const { row: t, rowIndex: i, column: r, colIndex: s, cellElement: n } = e;
|
|
908
|
+
r.editable && (n.classList.contains("editing") || this.#m(t, i, r, s, n, !0));
|
|
886
909
|
}
|
|
887
910
|
/**
|
|
888
911
|
* On scroll render, reapply editors to recycled cells.
|
|
@@ -899,7 +922,7 @@ class X extends O {
|
|
|
899
922
|
*/
|
|
900
923
|
get changedRows() {
|
|
901
924
|
const e = [];
|
|
902
|
-
for (const t of this.#
|
|
925
|
+
for (const t of this.#r) {
|
|
903
926
|
const i = this.grid.getRow(t);
|
|
904
927
|
i && e.push(i);
|
|
905
928
|
}
|
|
@@ -909,7 +932,7 @@ class X extends O {
|
|
|
909
932
|
* Get IDs of all modified rows.
|
|
910
933
|
*/
|
|
911
934
|
get changedRowIds() {
|
|
912
|
-
return Array.from(this.#
|
|
935
|
+
return Array.from(this.#r);
|
|
913
936
|
}
|
|
914
937
|
/**
|
|
915
938
|
* Get the currently active edit row index, or -1 if not editing.
|
|
@@ -921,7 +944,7 @@ class X extends O {
|
|
|
921
944
|
* Get the currently active edit column index, or -1 if not editing.
|
|
922
945
|
*/
|
|
923
946
|
get activeEditCol() {
|
|
924
|
-
return this.#
|
|
947
|
+
return this.#u;
|
|
925
948
|
}
|
|
926
949
|
/**
|
|
927
950
|
* Check if a specific row is currently being edited.
|
|
@@ -943,8 +966,8 @@ class X extends O {
|
|
|
943
966
|
const t = this.grid, i = t._rows[e];
|
|
944
967
|
if (!i) return !1;
|
|
945
968
|
try {
|
|
946
|
-
const
|
|
947
|
-
return
|
|
969
|
+
const r = t.getRowId?.(i);
|
|
970
|
+
return r ? this.#r.has(r) : !1;
|
|
948
971
|
} catch {
|
|
949
972
|
return !1;
|
|
950
973
|
}
|
|
@@ -954,7 +977,7 @@ class X extends O {
|
|
|
954
977
|
* @param rowId - Row ID to check
|
|
955
978
|
*/
|
|
956
979
|
isRowChangedById(e) {
|
|
957
|
-
return this.#
|
|
980
|
+
return this.#r.has(e);
|
|
958
981
|
}
|
|
959
982
|
// #region Cell Validation
|
|
960
983
|
/**
|
|
@@ -979,8 +1002,8 @@ class X extends O {
|
|
|
979
1002
|
* ```
|
|
980
1003
|
*/
|
|
981
1004
|
setInvalid(e, t, i = "") {
|
|
982
|
-
let
|
|
983
|
-
|
|
1005
|
+
let r = this.#i.get(e);
|
|
1006
|
+
r || (r = /* @__PURE__ */ new Map(), this.#i.set(e, r)), r.set(t, i), this.#g(e, t, !0);
|
|
984
1007
|
}
|
|
985
1008
|
/**
|
|
986
1009
|
* Clear the invalid state for a specific cell.
|
|
@@ -990,7 +1013,7 @@ class X extends O {
|
|
|
990
1013
|
*/
|
|
991
1014
|
clearInvalid(e, t) {
|
|
992
1015
|
const i = this.#i.get(e);
|
|
993
|
-
i && (i.delete(t), i.size === 0 && this.#i.delete(e)), this.#
|
|
1016
|
+
i && (i.delete(t), i.size === 0 && this.#i.delete(e)), this.#g(e, t, !1);
|
|
994
1017
|
}
|
|
995
1018
|
/**
|
|
996
1019
|
* Clear all invalid cells for a specific row.
|
|
@@ -1001,7 +1024,7 @@ class X extends O {
|
|
|
1001
1024
|
const t = this.#i.get(e);
|
|
1002
1025
|
if (t) {
|
|
1003
1026
|
const i = Array.from(t.keys());
|
|
1004
|
-
this.#i.delete(e), i.forEach((
|
|
1027
|
+
this.#i.delete(e), i.forEach((r) => this.#g(e, r, !1));
|
|
1005
1028
|
}
|
|
1006
1029
|
}
|
|
1007
1030
|
/**
|
|
@@ -1010,7 +1033,7 @@ class X extends O {
|
|
|
1010
1033
|
clearAllInvalid() {
|
|
1011
1034
|
const e = Array.from(this.#i.entries());
|
|
1012
1035
|
this.#i.clear(), e.forEach(([t, i]) => {
|
|
1013
|
-
i.forEach((
|
|
1036
|
+
i.forEach((r, s) => this.#g(t, s, !1));
|
|
1014
1037
|
});
|
|
1015
1038
|
}
|
|
1016
1039
|
/**
|
|
@@ -1055,18 +1078,18 @@ class X extends O {
|
|
|
1055
1078
|
/**
|
|
1056
1079
|
* Sync the data-invalid attribute on a cell element.
|
|
1057
1080
|
*/
|
|
1058
|
-
#
|
|
1059
|
-
const
|
|
1081
|
+
#g(e, t, i) {
|
|
1082
|
+
const r = this.grid, s = r._visibleColumns?.findIndex((d) => d.field === t);
|
|
1060
1083
|
if (s === -1 || s === void 0) return;
|
|
1061
|
-
const
|
|
1084
|
+
const l = r._rows?.findIndex((d) => {
|
|
1062
1085
|
try {
|
|
1063
|
-
return
|
|
1086
|
+
return r.getRowId?.(d) === e;
|
|
1064
1087
|
} catch {
|
|
1065
1088
|
return !1;
|
|
1066
1089
|
}
|
|
1067
1090
|
});
|
|
1068
|
-
if (
|
|
1069
|
-
const a =
|
|
1091
|
+
if (l === -1 || l === void 0) return;
|
|
1092
|
+
const a = r.findRenderedRowElement?.(l)?.querySelector(`.cell[data-col="${s}"]`);
|
|
1070
1093
|
if (a)
|
|
1071
1094
|
if (i) {
|
|
1072
1095
|
a.setAttribute("data-invalid", "true");
|
|
@@ -1083,7 +1106,7 @@ class X extends O {
|
|
|
1083
1106
|
*/
|
|
1084
1107
|
resetChangedRows(e) {
|
|
1085
1108
|
const t = this.changedRows, i = this.changedRowIds;
|
|
1086
|
-
this.#
|
|
1109
|
+
this.#r.clear(), this.#p(), e || this.emit("changed-rows-reset", { rows: t, ids: i }), this.grid._rowPool?.forEach((s) => s.classList.remove("changed"));
|
|
1087
1110
|
}
|
|
1088
1111
|
/**
|
|
1089
1112
|
* Programmatically begin editing a cell.
|
|
@@ -1092,10 +1115,10 @@ class X extends O {
|
|
|
1092
1115
|
* @fires cell-commit - Emitted when the cell value is committed (on blur or Enter)
|
|
1093
1116
|
*/
|
|
1094
1117
|
beginCellEdit(e, t) {
|
|
1095
|
-
const i = this.grid,
|
|
1096
|
-
if (
|
|
1097
|
-
const
|
|
1098
|
-
|
|
1118
|
+
const i = this.grid, r = i._visibleColumns.findIndex((c) => c.field === t);
|
|
1119
|
+
if (r === -1 || !i._visibleColumns[r]?.editable) return;
|
|
1120
|
+
const l = i.findRenderedRowElement?.(e)?.querySelector(`.cell[data-col="${r}"]`);
|
|
1121
|
+
l && (this.#d = !0, this.#b(e, r, l));
|
|
1099
1122
|
}
|
|
1100
1123
|
/**
|
|
1101
1124
|
* Programmatically begin editing all editable cells in a row.
|
|
@@ -1105,20 +1128,21 @@ class X extends O {
|
|
|
1105
1128
|
*/
|
|
1106
1129
|
beginBulkEdit(e) {
|
|
1107
1130
|
const t = this.grid;
|
|
1108
|
-
if ((this.config.editOn ?? t.effectiveConfig?.editOn) === !1 || !t._columns?.some((
|
|
1131
|
+
if ((this.config.editOn ?? t.effectiveConfig?.editOn) === !1 || !t._columns?.some((l) => l.editable)) return;
|
|
1109
1132
|
const s = t.findRenderedRowElement?.(e);
|
|
1110
1133
|
if (!s) return;
|
|
1111
|
-
|
|
1112
|
-
|
|
1134
|
+
this.#d = !1;
|
|
1135
|
+
const n = t._rows[e];
|
|
1136
|
+
this.#w(e, n), Array.from(s.children).forEach((l, c) => {
|
|
1113
1137
|
const a = t._visibleColumns[c];
|
|
1114
1138
|
if (a?.editable) {
|
|
1115
|
-
const d =
|
|
1116
|
-
d.classList.contains("editing") || this.#
|
|
1139
|
+
const d = l;
|
|
1140
|
+
d.classList.contains("editing") || this.#m(n, e, a, c, d, !0);
|
|
1117
1141
|
}
|
|
1118
1142
|
}), setTimeout(() => {
|
|
1119
|
-
let
|
|
1120
|
-
if (
|
|
1121
|
-
const c =
|
|
1143
|
+
let l = s.querySelector(`.cell[data-col="${t._focusCol}"]`);
|
|
1144
|
+
if (l?.classList.contains("editing") || (l = s.querySelector(".cell.editing")), l?.classList.contains("editing")) {
|
|
1145
|
+
const c = l.querySelector(v);
|
|
1122
1146
|
try {
|
|
1123
1147
|
c?.focus({ preventScroll: !0 });
|
|
1124
1148
|
} catch {
|
|
@@ -1131,34 +1155,34 @@ class X extends O {
|
|
|
1131
1155
|
* @fires row-commit - Emitted after the row edit is committed
|
|
1132
1156
|
*/
|
|
1133
1157
|
commitActiveRowEdit() {
|
|
1134
|
-
this.#e !== -1 && this.#
|
|
1158
|
+
this.#e !== -1 && this.#s(this.#e, !1);
|
|
1135
1159
|
}
|
|
1136
1160
|
/**
|
|
1137
1161
|
* Cancel the currently active row edit.
|
|
1138
1162
|
*/
|
|
1139
1163
|
cancelActiveRowEdit() {
|
|
1140
|
-
this.#e !== -1 && this.#
|
|
1164
|
+
this.#e !== -1 && this.#s(this.#e, !0);
|
|
1141
1165
|
}
|
|
1142
1166
|
// #endregion
|
|
1143
1167
|
// #region Internal Methods
|
|
1144
1168
|
/**
|
|
1145
1169
|
* Begin editing a single cell.
|
|
1146
1170
|
*/
|
|
1147
|
-
#
|
|
1148
|
-
const
|
|
1149
|
-
!s || !
|
|
1171
|
+
#b(e, t, i) {
|
|
1172
|
+
const r = this.grid, s = r._rows[e], n = r._visibleColumns[t];
|
|
1173
|
+
!s || !n?.editable || i.classList.contains("editing") || (this.#e !== e && this.#w(e, s), this.#u = t, this.#m(s, e, n, t, i, !1));
|
|
1150
1174
|
}
|
|
1151
1175
|
/**
|
|
1152
1176
|
* Focus the editor input in the currently focused cell (grid mode only).
|
|
1153
1177
|
* Used when pressing Enter to enter edit mode from navigation mode.
|
|
1154
1178
|
*/
|
|
1155
|
-
#
|
|
1179
|
+
#y() {
|
|
1156
1180
|
const e = this.grid, t = e._focusRow, i = e._focusCol;
|
|
1157
1181
|
if (t < 0 || i < 0) return;
|
|
1158
1182
|
const s = e.findRenderedRowElement?.(t)?.querySelector(`.cell[data-col="${i}"]`);
|
|
1159
1183
|
if (s?.classList.contains("editing")) {
|
|
1160
|
-
const
|
|
1161
|
-
|
|
1184
|
+
const n = s.querySelector(v);
|
|
1185
|
+
n && (this.#a = !1, n.focus(), this.#n = !0, n instanceof HTMLInputElement && (n.type === "text" || n.type === "number") && n.select());
|
|
1162
1186
|
}
|
|
1163
1187
|
}
|
|
1164
1188
|
/**
|
|
@@ -1166,43 +1190,43 @@ class X extends O {
|
|
|
1166
1190
|
* Moves to next/previous editable cell, staying in edit mode.
|
|
1167
1191
|
* Wraps to next/previous row when reaching row boundaries.
|
|
1168
1192
|
*/
|
|
1169
|
-
#
|
|
1170
|
-
const t = this.grid, i = t._rows,
|
|
1193
|
+
#C(e) {
|
|
1194
|
+
const t = this.grid, i = t._rows, r = this.#t ? t._focusRow : this.#e, s = t._visibleColumns.map((a, d) => a.editable ? d : -1).filter((a) => a >= 0);
|
|
1171
1195
|
if (s.length === 0) return;
|
|
1172
|
-
const
|
|
1173
|
-
if (
|
|
1174
|
-
t._focusCol = s[
|
|
1175
|
-
const d = t.findRenderedRowElement?.(
|
|
1176
|
-
d?.classList.contains("editing") && d.querySelector(
|
|
1196
|
+
const l = s.indexOf(t._focusCol) + (e ? 1 : -1);
|
|
1197
|
+
if (l >= 0 && l < s.length) {
|
|
1198
|
+
t._focusCol = s[l];
|
|
1199
|
+
const d = t.findRenderedRowElement?.(r)?.querySelector(`.cell[data-col="${s[l]}"]`);
|
|
1200
|
+
d?.classList.contains("editing") && d.querySelector(v)?.focus({ preventScroll: !0 }), L(t, { forceHorizontalScroll: !0 });
|
|
1177
1201
|
return;
|
|
1178
1202
|
}
|
|
1179
|
-
const c =
|
|
1203
|
+
const c = r + (e ? 1 : -1);
|
|
1180
1204
|
c >= 0 && c < i.length && (this.#t ? (t._focusRow = c, t._focusCol = e ? s[0] : s[s.length - 1], L(t, { forceHorizontalScroll: !0 }), this.requestAfterRender(), setTimeout(() => {
|
|
1181
1205
|
const d = t.findRenderedRowElement?.(c)?.querySelector(`.cell[data-col="${t._focusCol}"]`);
|
|
1182
|
-
d?.classList.contains("editing") && d.querySelector(
|
|
1183
|
-
}, 0)) : (this.#
|
|
1206
|
+
d?.classList.contains("editing") && d.querySelector(v)?.focus({ preventScroll: !0 });
|
|
1207
|
+
}, 0)) : (this.#s(r, !1), t._focusRow = c, t._focusCol = e ? s[0] : s[s.length - 1], this.beginBulkEdit(c), L(t, { forceHorizontalScroll: !0 })));
|
|
1184
1208
|
}
|
|
1185
1209
|
/**
|
|
1186
1210
|
* Sync the internal grid state with the plugin's editing state.
|
|
1187
1211
|
*/
|
|
1188
|
-
#
|
|
1212
|
+
#p() {
|
|
1189
1213
|
const e = this.grid;
|
|
1190
1214
|
e._activeEditRows = this.#e, e._rowEditSnapshots = this.#l;
|
|
1191
1215
|
}
|
|
1192
1216
|
/**
|
|
1193
1217
|
* Snapshot original row data and mark as editing.
|
|
1194
1218
|
*/
|
|
1195
|
-
#
|
|
1196
|
-
if (this.#e !== e && (this.#l.set(e, { ...t }), this.#e = e, this.#
|
|
1219
|
+
#w(e, t) {
|
|
1220
|
+
if (this.#e !== e && (this.#l.set(e, { ...t }), this.#e = e, this.#p(), !this.#t)) {
|
|
1197
1221
|
const i = this.grid;
|
|
1198
|
-
let
|
|
1222
|
+
let r = "";
|
|
1199
1223
|
try {
|
|
1200
|
-
|
|
1224
|
+
r = i.getRowId?.(t) ?? "";
|
|
1201
1225
|
} catch {
|
|
1202
1226
|
}
|
|
1203
1227
|
this.emit("edit-open", {
|
|
1204
1228
|
rowIndex: e,
|
|
1205
|
-
rowId:
|
|
1229
|
+
rowId: r,
|
|
1206
1230
|
row: t
|
|
1207
1231
|
});
|
|
1208
1232
|
}
|
|
@@ -1210,16 +1234,16 @@ class X extends O {
|
|
|
1210
1234
|
/**
|
|
1211
1235
|
* Exit editing for a row.
|
|
1212
1236
|
*/
|
|
1213
|
-
#
|
|
1237
|
+
#s(e, t) {
|
|
1214
1238
|
if (this.#e !== e) return;
|
|
1215
|
-
const i = this.grid,
|
|
1216
|
-
let
|
|
1239
|
+
const i = this.grid, r = this.#l.get(e), s = i._rows[e], n = i.findRenderedRowElement?.(e);
|
|
1240
|
+
let l;
|
|
1217
1241
|
if (s)
|
|
1218
1242
|
try {
|
|
1219
|
-
|
|
1243
|
+
l = i.getRowId?.(s);
|
|
1220
1244
|
} catch {
|
|
1221
1245
|
}
|
|
1222
|
-
if (!t &&
|
|
1246
|
+
if (!t && n && s && n.querySelectorAll(".cell.editing").forEach((a) => {
|
|
1223
1247
|
const d = Number(a.getAttribute("data-col"));
|
|
1224
1248
|
if (isNaN(d)) return;
|
|
1225
1249
|
const g = i._visibleColumns[d];
|
|
@@ -1228,37 +1252,37 @@ class X extends O {
|
|
|
1228
1252
|
const f = a.querySelector("input,textarea,select");
|
|
1229
1253
|
if (f) {
|
|
1230
1254
|
const E = g.field, p = s[E], m = _(f, g, p);
|
|
1231
|
-
p !== m && this.#
|
|
1255
|
+
p !== m && this.#E(e, g, m, s);
|
|
1232
1256
|
}
|
|
1233
|
-
}), t &&
|
|
1234
|
-
Object.keys(
|
|
1235
|
-
s[c] =
|
|
1236
|
-
}),
|
|
1257
|
+
}), t && r && s)
|
|
1258
|
+
Object.keys(r).forEach((c) => {
|
|
1259
|
+
s[c] = r[c];
|
|
1260
|
+
}), l && (this.#r.delete(l), this.clearRowInvalid(l));
|
|
1237
1261
|
else if (!t && s) {
|
|
1238
|
-
const c = this.#
|
|
1262
|
+
const c = this.#_(r, s), a = l ? this.#r.has(l) : c, d = this.emitCancelable("row-commit", {
|
|
1239
1263
|
rowIndex: e,
|
|
1240
|
-
rowId:
|
|
1264
|
+
rowId: l ?? "",
|
|
1241
1265
|
row: s,
|
|
1242
|
-
oldValue:
|
|
1266
|
+
oldValue: r,
|
|
1243
1267
|
newValue: s,
|
|
1244
1268
|
changed: a,
|
|
1245
1269
|
changedRows: this.changedRows,
|
|
1246
1270
|
changedRowIds: this.changedRowIds
|
|
1247
1271
|
});
|
|
1248
|
-
d &&
|
|
1249
|
-
s[g] =
|
|
1250
|
-
}),
|
|
1272
|
+
d && r ? (Object.keys(r).forEach((g) => {
|
|
1273
|
+
s[g] = r[g];
|
|
1274
|
+
}), l && (this.#r.delete(l), this.clearRowInvalid(l))) : !d && c && this.isAnimationEnabled && (this.#h = e);
|
|
1251
1275
|
}
|
|
1252
|
-
this.#l.delete(e), this.#e = -1, this.#
|
|
1276
|
+
this.#l.delete(e), this.#e = -1, this.#u = -1, this.#d = !1, this.#p();
|
|
1253
1277
|
for (const c of this.#o)
|
|
1254
1278
|
c.startsWith(`${e}:`) && this.#o.delete(c);
|
|
1255
1279
|
for (const c of this.#c.keys())
|
|
1256
1280
|
c.startsWith(`${e}:`) && this.#c.delete(c);
|
|
1257
|
-
|
|
1281
|
+
n && (n.querySelectorAll(".cell.editing").forEach((c) => {
|
|
1258
1282
|
c.classList.remove("editing"), U(c.parentElement);
|
|
1259
|
-
}), this.requestRender()), this.#
|
|
1283
|
+
}), this.requestRender()), this.#f = !0, n || (this.#v(i), this.#f = !1), !this.#t && s && this.emit("edit-close", {
|
|
1260
1284
|
rowIndex: e,
|
|
1261
|
-
rowId:
|
|
1285
|
+
rowId: l ?? "",
|
|
1262
1286
|
row: s,
|
|
1263
1287
|
reverted: t
|
|
1264
1288
|
});
|
|
@@ -1267,28 +1291,28 @@ class X extends O {
|
|
|
1267
1291
|
* Commit a single cell value change.
|
|
1268
1292
|
* Uses ID-based change tracking for stability when rows are reordered.
|
|
1269
1293
|
*/
|
|
1270
|
-
#
|
|
1294
|
+
#E(e, t, i, r) {
|
|
1271
1295
|
const s = t.field;
|
|
1272
1296
|
if (!S(s)) return;
|
|
1273
|
-
const
|
|
1274
|
-
if (
|
|
1275
|
-
const
|
|
1297
|
+
const n = r[s];
|
|
1298
|
+
if (n === i) return;
|
|
1299
|
+
const l = this.grid;
|
|
1276
1300
|
let c;
|
|
1277
1301
|
try {
|
|
1278
|
-
c = this.grid.getRowId(
|
|
1302
|
+
c = this.grid.getRowId(r);
|
|
1279
1303
|
} catch {
|
|
1280
1304
|
}
|
|
1281
|
-
const a = c ? !this.#
|
|
1305
|
+
const a = c ? !this.#r.has(c) : !0, d = c ? (m) => this.grid.updateRow(c, m, "cascade") : T;
|
|
1282
1306
|
let g = !1;
|
|
1283
1307
|
const f = c ? (m) => {
|
|
1284
1308
|
g = !0, this.setInvalid(c, s, m ?? "");
|
|
1285
1309
|
} : () => {
|
|
1286
1310
|
};
|
|
1287
1311
|
if (this.emitCancelable("cell-commit", {
|
|
1288
|
-
row:
|
|
1312
|
+
row: r,
|
|
1289
1313
|
rowId: c ?? "",
|
|
1290
1314
|
field: s,
|
|
1291
|
-
oldValue:
|
|
1315
|
+
oldValue: n,
|
|
1292
1316
|
value: i,
|
|
1293
1317
|
rowIndex: e,
|
|
1294
1318
|
changedRows: this.changedRows,
|
|
@@ -1297,34 +1321,39 @@ class X extends O {
|
|
|
1297
1321
|
updateRow: d,
|
|
1298
1322
|
setInvalid: f
|
|
1299
1323
|
})) return;
|
|
1300
|
-
c && !g && this.isCellInvalid(c, s) && this.clearInvalid(c, s),
|
|
1324
|
+
c && !g && this.isCellInvalid(c, s) && this.clearInvalid(c, s), r[s] = i, c && this.#r.add(c), this.#p(), this.emitPluginEvent("cell-edit-committed", {
|
|
1301
1325
|
rowIndex: e,
|
|
1302
1326
|
field: s,
|
|
1303
|
-
oldValue:
|
|
1327
|
+
oldValue: n,
|
|
1304
1328
|
newValue: i
|
|
1305
1329
|
});
|
|
1306
|
-
const p =
|
|
1330
|
+
const p = l.findRenderedRowElement?.(e);
|
|
1307
1331
|
p && p.classList.add("changed");
|
|
1308
1332
|
}
|
|
1309
1333
|
/**
|
|
1310
1334
|
* Inject an editor into a cell.
|
|
1311
1335
|
*/
|
|
1312
|
-
#
|
|
1336
|
+
#m(e, t, i, r, s, n) {
|
|
1313
1337
|
if (!i.editable || s.classList.contains("editing")) return;
|
|
1314
|
-
let
|
|
1338
|
+
let l;
|
|
1315
1339
|
try {
|
|
1316
|
-
|
|
1340
|
+
l = this.grid.getRowId(e);
|
|
1317
1341
|
} catch {
|
|
1318
1342
|
}
|
|
1319
|
-
const c =
|
|
1320
|
-
s.classList.add("editing"), this.#o.add(`${t}:${
|
|
1343
|
+
const c = l ? (u) => this.grid.updateRow(l, u, "cascade") : T, a = S(i.field) ? e[i.field] : void 0;
|
|
1344
|
+
s.classList.add("editing"), this.#o.add(`${t}:${r}`);
|
|
1321
1345
|
const d = s.parentElement;
|
|
1322
|
-
d &&
|
|
1346
|
+
d && W(d);
|
|
1323
1347
|
let g = !1;
|
|
1324
1348
|
const f = (u) => {
|
|
1325
|
-
g || !this.#t && this.#e === -1
|
|
1349
|
+
if (g || !this.#t && this.#e === -1) return;
|
|
1350
|
+
const h = this.grid._rows[t] ?? e;
|
|
1351
|
+
this.#E(t, i, u, h);
|
|
1326
1352
|
}, E = () => {
|
|
1327
|
-
g = !0, S(i.field)
|
|
1353
|
+
if (g = !0, S(i.field)) {
|
|
1354
|
+
const u = this.grid._rows[t] ?? e;
|
|
1355
|
+
u[i.field] = a;
|
|
1356
|
+
}
|
|
1328
1357
|
}, p = document.createElement("div");
|
|
1329
1358
|
p.className = "tbw-editor-host", s.innerHTML = "", s.appendChild(p), p.addEventListener("keydown", (u) => {
|
|
1330
1359
|
if (u.key === "Enter") {
|
|
@@ -1336,7 +1365,7 @@ class X extends O {
|
|
|
1336
1365
|
}
|
|
1337
1366
|
if (this.config.onBeforeEditClose && this.config.onBeforeEditClose(u) === !1)
|
|
1338
1367
|
return;
|
|
1339
|
-
u.stopPropagation(), u.preventDefault(), g = !0, this.#
|
|
1368
|
+
u.stopPropagation(), u.preventDefault(), g = !0, this.#s(t, !1);
|
|
1340
1369
|
}
|
|
1341
1370
|
if (u.key === "Escape") {
|
|
1342
1371
|
if (this.#t) {
|
|
@@ -1345,34 +1374,34 @@ class X extends O {
|
|
|
1345
1374
|
}
|
|
1346
1375
|
if (this.config.onBeforeEditClose && this.config.onBeforeEditClose(u) === !1)
|
|
1347
1376
|
return;
|
|
1348
|
-
u.stopPropagation(), u.preventDefault(), E(), this.#
|
|
1377
|
+
u.stopPropagation(), u.preventDefault(), E(), this.#s(t, !0);
|
|
1349
1378
|
}
|
|
1350
1379
|
});
|
|
1351
|
-
const m = i, y = m.__editorTemplate,
|
|
1380
|
+
const m = i, y = m.__editorTemplate, w = j(this.grid, m) ?? K(i), k = a, q = `${t}:${i.field}`, A = [];
|
|
1352
1381
|
this.#c.set(q, (u) => {
|
|
1353
1382
|
for (const h of A) h(u);
|
|
1354
1383
|
});
|
|
1355
1384
|
const C = (u) => {
|
|
1356
1385
|
A.push(u);
|
|
1357
1386
|
};
|
|
1358
|
-
if (
|
|
1359
|
-
this.#
|
|
1387
|
+
if (w === "template" && y)
|
|
1388
|
+
this.#R(p, m, e, a, f, E, n, t), C((u) => {
|
|
1360
1389
|
const h = p.querySelector(
|
|
1361
1390
|
"input,textarea,select"
|
|
1362
1391
|
);
|
|
1363
1392
|
h && (h instanceof HTMLInputElement && h.type === "checkbox" ? h.checked = !!u : h.value = String(u ?? ""));
|
|
1364
1393
|
});
|
|
1365
|
-
else if (typeof
|
|
1366
|
-
const u = document.createElement(
|
|
1394
|
+
else if (typeof w == "string") {
|
|
1395
|
+
const u = document.createElement(w);
|
|
1367
1396
|
u.value = k, u.addEventListener("change", () => f(u.value)), C((h) => {
|
|
1368
1397
|
u.value = h;
|
|
1369
|
-
}), p.appendChild(u),
|
|
1370
|
-
p.querySelector(
|
|
1398
|
+
}), p.appendChild(u), n || queueMicrotask(() => {
|
|
1399
|
+
p.querySelector(v)?.focus({ preventScroll: !0 });
|
|
1371
1400
|
});
|
|
1372
|
-
} else if (typeof
|
|
1401
|
+
} else if (typeof w == "function") {
|
|
1373
1402
|
const u = {
|
|
1374
1403
|
row: e,
|
|
1375
|
-
rowId:
|
|
1404
|
+
rowId: l ?? "",
|
|
1376
1405
|
value: k,
|
|
1377
1406
|
field: i.field,
|
|
1378
1407
|
column: i,
|
|
@@ -1380,7 +1409,7 @@ class X extends O {
|
|
|
1380
1409
|
cancel: E,
|
|
1381
1410
|
updateRow: c,
|
|
1382
1411
|
onValueChange: C
|
|
1383
|
-
}, h =
|
|
1412
|
+
}, h = w(u);
|
|
1384
1413
|
typeof h == "string" ? (p.innerHTML = h, Q(p, i, f, a), C((R) => {
|
|
1385
1414
|
const b = p.querySelector(
|
|
1386
1415
|
"input,textarea,select"
|
|
@@ -1388,15 +1417,15 @@ class X extends O {
|
|
|
1388
1417
|
b && (b instanceof HTMLInputElement && b.type === "checkbox" ? b.checked = !!R : b.value = String(R ?? ""));
|
|
1389
1418
|
})) : h instanceof Node && (p.appendChild(h), h instanceof HTMLInputElement || h instanceof HTMLSelectElement || h instanceof HTMLTextAreaElement ? C((b) => {
|
|
1390
1419
|
h instanceof HTMLInputElement && h.type === "checkbox" ? h.checked = !!b : h.value = String(b ?? "");
|
|
1391
|
-
}) : s.setAttribute("data-editor-managed", "")),
|
|
1392
|
-
p.querySelector(
|
|
1420
|
+
}) : s.setAttribute("data-editor-managed", "")), n || queueMicrotask(() => {
|
|
1421
|
+
p.querySelector(v)?.focus({ preventScroll: !0 });
|
|
1393
1422
|
});
|
|
1394
|
-
} else if (
|
|
1423
|
+
} else if (w && typeof w == "object") {
|
|
1395
1424
|
const u = document.createElement("div");
|
|
1396
1425
|
u.setAttribute("data-external-editor", ""), u.setAttribute("data-field", i.field), p.appendChild(u), s.setAttribute("data-editor-managed", "");
|
|
1397
1426
|
const h = {
|
|
1398
1427
|
row: e,
|
|
1399
|
-
rowId:
|
|
1428
|
+
rowId: l ?? "",
|
|
1400
1429
|
value: k,
|
|
1401
1430
|
field: i.field,
|
|
1402
1431
|
column: i,
|
|
@@ -1405,34 +1434,34 @@ class X extends O {
|
|
|
1405
1434
|
updateRow: c,
|
|
1406
1435
|
onValueChange: C
|
|
1407
1436
|
};
|
|
1408
|
-
if (
|
|
1437
|
+
if (w.mount)
|
|
1409
1438
|
try {
|
|
1410
|
-
|
|
1439
|
+
w.mount({ placeholder: u, context: h, spec: w });
|
|
1411
1440
|
} catch (R) {
|
|
1412
1441
|
console.warn(`[tbw-grid] External editor mount error for column '${i.field}':`, R);
|
|
1413
1442
|
}
|
|
1414
1443
|
else
|
|
1415
1444
|
this.grid.dispatchEvent(
|
|
1416
|
-
new CustomEvent("mount-external-editor", { detail: { placeholder: u, spec:
|
|
1445
|
+
new CustomEvent("mount-external-editor", { detail: { placeholder: u, spec: w, context: h } })
|
|
1417
1446
|
);
|
|
1418
1447
|
}
|
|
1419
1448
|
}
|
|
1420
1449
|
/**
|
|
1421
1450
|
* Render a template-based editor.
|
|
1422
1451
|
*/
|
|
1423
|
-
#
|
|
1452
|
+
#R(e, t, i, r, s, n, l, c) {
|
|
1424
1453
|
const a = t.__editorTemplate;
|
|
1425
1454
|
if (!a) return;
|
|
1426
1455
|
const d = a.cloneNode(!0), g = t.__compiledEditor;
|
|
1427
1456
|
g ? d.innerHTML = g({
|
|
1428
1457
|
row: i,
|
|
1429
|
-
value:
|
|
1458
|
+
value: r,
|
|
1430
1459
|
field: t.field,
|
|
1431
1460
|
column: t,
|
|
1432
1461
|
commit: s,
|
|
1433
|
-
cancel:
|
|
1462
|
+
cancel: n
|
|
1434
1463
|
}) : d.querySelectorAll("*").forEach((E) => {
|
|
1435
|
-
E.childNodes.length === 1 && E.firstChild?.nodeType === Node.TEXT_NODE && (E.textContent = E.textContent?.replace(/{{\s*value\s*}}/g,
|
|
1464
|
+
E.childNodes.length === 1 && E.firstChild?.nodeType === Node.TEXT_NODE && (E.textContent = E.textContent?.replace(/{{\s*value\s*}}/g, r == null ? "" : String(r)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g, (p, m) => {
|
|
1436
1465
|
if (!S(m)) return "";
|
|
1437
1466
|
const y = i[m];
|
|
1438
1467
|
return y == null ? "" : String(y);
|
|
@@ -1442,23 +1471,23 @@ class X extends O {
|
|
|
1442
1471
|
"input,textarea,select"
|
|
1443
1472
|
);
|
|
1444
1473
|
if (f) {
|
|
1445
|
-
f instanceof HTMLInputElement && f.type === "checkbox" ? f.checked = !!
|
|
1474
|
+
f instanceof HTMLInputElement && f.type === "checkbox" ? f.checked = !!r : f.value = String(r ?? "");
|
|
1446
1475
|
let E = !1;
|
|
1447
1476
|
f.addEventListener("blur", () => {
|
|
1448
|
-
E || s(_(f, t,
|
|
1477
|
+
E || s(_(f, t, r));
|
|
1449
1478
|
}), f.addEventListener("keydown", (p) => {
|
|
1450
1479
|
const m = p;
|
|
1451
1480
|
if (m.key === "Enter") {
|
|
1452
1481
|
if (this.config.onBeforeEditClose && this.config.onBeforeEditClose(m) === !1)
|
|
1453
1482
|
return;
|
|
1454
|
-
m.stopPropagation(), m.preventDefault(), E = !0, s(_(f, t,
|
|
1483
|
+
m.stopPropagation(), m.preventDefault(), E = !0, s(_(f, t, r)), this.#s(c, !1);
|
|
1455
1484
|
}
|
|
1456
1485
|
if (m.key === "Escape") {
|
|
1457
1486
|
if (this.config.onBeforeEditClose && this.config.onBeforeEditClose(m) === !1)
|
|
1458
1487
|
return;
|
|
1459
|
-
m.stopPropagation(), m.preventDefault(),
|
|
1488
|
+
m.stopPropagation(), m.preventDefault(), n(), this.#s(c, !0);
|
|
1460
1489
|
}
|
|
1461
|
-
}), f instanceof HTMLInputElement && f.type === "checkbox" && f.addEventListener("change", () => s(f.checked)),
|
|
1490
|
+
}), f instanceof HTMLInputElement && f.type === "checkbox" && f.addEventListener("change", () => s(f.checked)), l || setTimeout(() => f.focus({ preventScroll: !0 }), 0);
|
|
1462
1491
|
}
|
|
1463
1492
|
e.appendChild(d);
|
|
1464
1493
|
}
|
|
@@ -1466,11 +1495,11 @@ class X extends O {
|
|
|
1466
1495
|
* Compare snapshot vs current row to detect if any values changed during this edit session.
|
|
1467
1496
|
* Uses shallow comparison of all properties.
|
|
1468
1497
|
*/
|
|
1469
|
-
#
|
|
1498
|
+
#_(e, t) {
|
|
1470
1499
|
if (!e) return !1;
|
|
1471
|
-
const i = e,
|
|
1472
|
-
for (const
|
|
1473
|
-
if (i[
|
|
1500
|
+
const i = e, r = t, s = /* @__PURE__ */ new Set([...Object.keys(i), ...Object.keys(r)]);
|
|
1501
|
+
for (const n of s)
|
|
1502
|
+
if (i[n] !== r[n])
|
|
1474
1503
|
return !0;
|
|
1475
1504
|
return !1;
|
|
1476
1505
|
}
|
|
@@ -1480,12 +1509,12 @@ class X extends O {
|
|
|
1480
1509
|
#v(e) {
|
|
1481
1510
|
queueMicrotask(() => {
|
|
1482
1511
|
try {
|
|
1483
|
-
const t = e._focusRow, i = e._focusCol,
|
|
1484
|
-
if (
|
|
1512
|
+
const t = e._focusRow, i = e._focusCol, r = e.findRenderedRowElement?.(t);
|
|
1513
|
+
if (r) {
|
|
1485
1514
|
Array.from(e._bodyEl.querySelectorAll(".cell-focus")).forEach(
|
|
1486
|
-
(
|
|
1515
|
+
(n) => n.classList.remove("cell-focus")
|
|
1487
1516
|
);
|
|
1488
|
-
const s =
|
|
1517
|
+
const s = r.querySelector(`.cell[data-row="${t}"][data-col="${i}"]`);
|
|
1489
1518
|
s && (s.classList.add("cell-focus"), s.setAttribute("aria-selected", "true"), s.hasAttribute("tabindex") || s.setAttribute("tabindex", "-1"), s.focus({ preventScroll: !0 }));
|
|
1490
1519
|
}
|
|
1491
1520
|
} catch {
|
|
@@ -1496,6 +1525,6 @@ class X extends O {
|
|
|
1496
1525
|
}
|
|
1497
1526
|
export {
|
|
1498
1527
|
X as EditingPlugin,
|
|
1499
|
-
|
|
1528
|
+
K as defaultEditorFor
|
|
1500
1529
|
};
|
|
1501
1530
|
//# sourceMappingURL=index.js.map
|