@toolbox-web/grid 1.17.0 → 1.18.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.
Files changed (61) hide show
  1. package/README.md +126 -41
  2. package/all.js +1045 -935
  3. package/all.js.map +1 -1
  4. package/index.js +39 -33
  5. package/index.js.map +1 -1
  6. package/lib/core/grid.d.ts +12 -2
  7. package/lib/core/grid.d.ts.map +1 -1
  8. package/lib/core/internal/header.d.ts.map +1 -1
  9. package/lib/core/internal/keyboard.d.ts.map +1 -1
  10. package/lib/core/types.d.ts +34 -1
  11. package/lib/core/types.d.ts.map +1 -1
  12. package/lib/plugins/clipboard/index.js.map +1 -1
  13. package/lib/plugins/column-virtualization/index.js.map +1 -1
  14. package/lib/plugins/context-menu/index.js.map +1 -1
  15. package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
  16. package/lib/plugins/editing/index.js +155 -145
  17. package/lib/plugins/editing/index.js.map +1 -1
  18. package/lib/plugins/export/index.js.map +1 -1
  19. package/lib/plugins/filtering/FilteringPlugin.d.ts +31 -0
  20. package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
  21. package/lib/plugins/filtering/filter-model.d.ts +30 -3
  22. package/lib/plugins/filtering/filter-model.d.ts.map +1 -1
  23. package/lib/plugins/filtering/index.d.ts +1 -0
  24. package/lib/plugins/filtering/index.d.ts.map +1 -1
  25. package/lib/plugins/filtering/index.js +471 -361
  26. package/lib/plugins/filtering/index.js.map +1 -1
  27. package/lib/plugins/filtering/types.d.ts +32 -0
  28. package/lib/plugins/filtering/types.d.ts.map +1 -1
  29. package/lib/plugins/grouping-columns/index.js.map +1 -1
  30. package/lib/plugins/grouping-rows/index.js.map +1 -1
  31. package/lib/plugins/master-detail/index.js.map +1 -1
  32. package/lib/plugins/multi-sort/MultiSortPlugin.d.ts +4 -0
  33. package/lib/plugins/multi-sort/MultiSortPlugin.d.ts.map +1 -1
  34. package/lib/plugins/multi-sort/index.js +49 -39
  35. package/lib/plugins/multi-sort/index.js.map +1 -1
  36. package/lib/plugins/pinned-columns/index.js.map +1 -1
  37. package/lib/plugins/pinned-rows/index.js.map +1 -1
  38. package/lib/plugins/pivot/index.js.map +1 -1
  39. package/lib/plugins/print/index.js.map +1 -1
  40. package/lib/plugins/reorder/index.js +81 -78
  41. package/lib/plugins/reorder/index.js.map +1 -1
  42. package/lib/plugins/responsive/index.js +58 -55
  43. package/lib/plugins/responsive/index.js.map +1 -1
  44. package/lib/plugins/row-reorder/index.js +5 -2
  45. package/lib/plugins/row-reorder/index.js.map +1 -1
  46. package/lib/plugins/selection/index.js.map +1 -1
  47. package/lib/plugins/server-side/index.js.map +1 -1
  48. package/lib/plugins/tree/index.js.map +1 -1
  49. package/lib/plugins/undo-redo/index.js.map +1 -1
  50. package/lib/plugins/visibility/index.js.map +1 -1
  51. package/package.json +1 -1
  52. package/umd/grid.all.umd.js +29 -29
  53. package/umd/grid.all.umd.js.map +1 -1
  54. package/umd/grid.umd.js +2 -2
  55. package/umd/grid.umd.js.map +1 -1
  56. package/umd/plugins/editing.umd.js +1 -1
  57. package/umd/plugins/editing.umd.js.map +1 -1
  58. package/umd/plugins/filtering.umd.js +1 -1
  59. package/umd/plugins/filtering.umd.js.map +1 -1
  60. package/umd/plugins/multi-sort.umd.js +1 -1
  61. package/umd/plugins/multi-sort.umd.js.map +1 -1
@@ -7,43 +7,46 @@ const w = document.createElement("template");
7
7
  w.innerHTML = '<div class="data-grid-row" role="row" part="row"></div>';
8
8
  function y(l, e) {
9
9
  if (l._virtualization?.enabled) {
10
- const { rowHeight: a, container: r, viewportEl: s } = l._virtualization, o = r, c = s?.clientHeight ?? o?.clientHeight ?? 0;
11
- if (o && c > 0) {
10
+ const { rowHeight: a, container: r, viewportEl: s } = l._virtualization, i = r, c = s?.clientHeight ?? i?.clientHeight ?? 0;
11
+ if (i && c > 0) {
12
12
  const u = l._focusRow * a;
13
- u < o.scrollTop ? o.scrollTop = u : u + a > o.scrollTop + c && (o.scrollTop = u - c + a);
13
+ u < i.scrollTop ? i.scrollTop = u : u + a > i.scrollTop + c && (i.scrollTop = u - c + a);
14
14
  }
15
15
  }
16
16
  const t = l._activeEditRows !== void 0 && l._activeEditRows !== -1;
17
17
  t || l.refreshVirtualWindow(!1), v(l._bodyEl), Array.from(l._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach((a) => {
18
18
  a.setAttribute("aria-selected", "false");
19
19
  });
20
- const i = l._focusRow, n = l._virtualization.start ?? 0, d = l._virtualization.end ?? l._rows.length;
21
- if (i >= n && i < d) {
22
- const a = l._bodyEl.querySelectorAll(".data-grid-row")[i - n];
20
+ const n = l._focusRow, o = l._virtualization.start ?? 0, d = l._virtualization.end ?? l._rows.length;
21
+ if (n >= o && n < d) {
22
+ const a = l._bodyEl.querySelectorAll(".data-grid-row")[n - o];
23
23
  let r = a?.children[l._focusCol];
24
24
  if ((!r || !r.classList?.contains("cell")) && (r = a?.querySelector(`.cell[data-col="${l._focusCol}"]`) ?? a?.querySelector(".cell[data-col]")), r) {
25
25
  r.classList.add("cell-focus"), r.setAttribute("aria-selected", "true");
26
26
  const s = l.querySelector(".tbw-scroll-area");
27
27
  if (s && r && (!t || e?.forceHorizontalScroll)) {
28
- const o = l._getHorizontalScrollOffsets?.(a ?? void 0, r) ?? { left: 0, right: 0 };
29
- if (!o.skipScroll) {
30
- const c = r.getBoundingClientRect(), u = s.getBoundingClientRect(), f = c.left - u.left + s.scrollLeft, g = f + c.width, h = s.scrollLeft + o.left, m = s.scrollLeft + s.clientWidth - o.right;
31
- f < h ? s.scrollLeft = f - o.left : g > m && (s.scrollLeft = g - s.clientWidth + o.right);
28
+ const i = l._getHorizontalScrollOffsets?.(a ?? void 0, r) ?? { left: 0, right: 0 };
29
+ if (!i.skipScroll) {
30
+ const c = r.getBoundingClientRect(), u = s.getBoundingClientRect(), f = c.left - u.left + s.scrollLeft, g = f + c.width, h = s.scrollLeft + i.left, m = s.scrollLeft + s.clientWidth - i.right;
31
+ f < h ? s.scrollLeft = f - i.left : g > m && (s.scrollLeft = g - s.clientWidth + i.right);
32
32
  }
33
33
  }
34
- if (l._activeEditRows !== void 0 && l._activeEditRows !== -1 && r.classList.contains("editing")) {
35
- const o = r.querySelector(C);
36
- if (o && document.activeElement !== o)
34
+ if (t && r.classList.contains("editing")) {
35
+ const i = r.querySelector(C);
36
+ if (i && document.activeElement !== i)
37
37
  try {
38
- o.focus({ preventScroll: !0 });
38
+ i.focus({ preventScroll: !0 });
39
39
  } catch {
40
40
  }
41
- } else if (!r.contains(document.activeElement)) {
41
+ } else if (t && !r.contains(document.activeElement)) {
42
42
  r.hasAttribute("tabindex") || r.setAttribute("tabindex", "-1");
43
43
  try {
44
44
  r.focus({ preventScroll: !0 });
45
45
  } catch {
46
46
  }
47
+ } else if (!t) {
48
+ const i = l;
49
+ document.activeElement !== i && i.focus({ preventScroll: !0 });
47
50
  }
48
51
  }
49
52
  }
@@ -196,8 +199,8 @@ class A {
196
199
  * @returns `true` if the event was cancelled (preventDefault called), `false` otherwise
197
200
  */
198
201
  emitCancelable(e, t) {
199
- const i = new CustomEvent(e, { detail: t, bubbles: !0, cancelable: !0 });
200
- return this.grid?.dispatchEvent?.(i), i.defaultPrevented;
202
+ const n = new CustomEvent(e, { detail: t, bubbles: !0, cancelable: !0 });
203
+ return this.grid?.dispatchEvent?.(n), n.defaultPrevented;
201
204
  }
202
205
  // =========================================================================
203
206
  // Event Bus - Plugin-to-Plugin Communication
@@ -392,8 +395,8 @@ class A {
392
395
  get animationDuration() {
393
396
  const e = this.gridElement;
394
397
  if (e) {
395
- const t = getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(), i = parseInt(t, 10);
396
- if (!isNaN(i)) return i;
398
+ const t = getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(), n = parseInt(t, 10);
399
+ if (!isNaN(n)) return n;
397
400
  }
398
401
  return 200;
399
402
  }
@@ -427,21 +430,21 @@ class A {
427
430
  }
428
431
  // #endregion
429
432
  }
430
- function _(l) {
433
+ function O(l) {
431
434
  const e = l.meta ?? {};
432
435
  return e.lockPosition !== !0 && e.suppressMovable !== !0;
433
436
  }
434
437
  function b(l, e, t) {
435
438
  if (e === t || e < 0 || e >= l.length || t < 0 || t > l.length) return l;
436
- const i = [...l], [n] = i.splice(e, 1);
437
- return i.splice(t, 0, n), i;
439
+ const n = [...l], [o] = n.splice(e, 1);
440
+ return n.splice(t, 0, o), n;
438
441
  }
439
- const R = '@layer tbw-plugins{.header-row>.cell[draggable=true]{cursor:grab;position:relative}.header-row>.cell.dragging{opacity:.5;cursor:grabbing}.header-row>.cell.drop-before:before{content:"";position:absolute;left:0;top:0;bottom:0;width:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent));z-index:1}.header-row>.cell.drop-after:after{content:"";position:absolute;right:0;top:0;bottom:0;width:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent));z-index:1}.cell.flip-animating{transition:transform var(--tbw-animation-duration, .2s) ease-out;will-change:transform;z-index:1}@keyframes reorder-fade-in{0%{opacity:0}to{opacity:1}}.cell.fade-animating{animation:reorder-fade-in var(--tbw-animation-duration, .2s) ease-out backwards}}';
440
- class O extends A {
442
+ const _ = '@layer tbw-plugins{.header-row>.cell[draggable=true]{cursor:grab;position:relative}.header-row>.cell.dragging{opacity:.5;cursor:grabbing}.header-row>.cell.drop-before:before{content:"";position:absolute;left:0;top:0;bottom:0;width:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent));z-index:1}.header-row>.cell.drop-after:after{content:"";position:absolute;right:0;top:0;bottom:0;width:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent));z-index:1}.cell.flip-animating{transition:transform var(--tbw-animation-duration, .2s) ease-out;will-change:transform;z-index:1}@keyframes reorder-fade-in{0%{opacity:0}to{opacity:1}}.cell.fade-animating{animation:reorder-fade-in var(--tbw-animation-duration, .2s) ease-out backwards}}';
443
+ class R extends A {
441
444
  /** @internal */
442
445
  name = "reorder";
443
446
  /** @internal */
444
- styles = R;
447
+ styles = _;
445
448
  /** @internal */
446
449
  get defaultConfig() {
447
450
  return {
@@ -472,7 +475,7 @@ class O extends A {
472
475
  * Check if a column can be moved, considering both column config and plugin queries.
473
476
  */
474
477
  canMoveColumnWithPlugins(e) {
475
- return !e || !_(e) ? !1 : !this.grid.query("canMoveColumn", e).includes(!1);
478
+ return !e || !O(e) ? !1 : !this.grid.query("canMoveColumn", e).includes(!1);
476
479
  }
477
480
  /**
478
481
  * Clear all drag-related classes from header cells.
@@ -489,8 +492,8 @@ class O extends A {
489
492
  super.attach(e), e.addEventListener(
490
493
  "column-reorder-request",
491
494
  (t) => {
492
- const i = t.detail;
493
- i?.field && typeof i.toIndex == "number" && this.moveColumn(i.field, i.toIndex);
495
+ const n = t.detail;
496
+ n?.field && typeof n.toIndex == "number" && this.moveColumn(n.field, n.toIndex);
494
497
  },
495
498
  { signal: this.disconnectSignal }
496
499
  );
@@ -505,33 +508,33 @@ class O extends A {
505
508
  afterRender() {
506
509
  const e = this.gridElement;
507
510
  if (!e) return;
508
- e.querySelectorAll(".header-row > .cell").forEach((i) => {
509
- const n = i, d = n.getAttribute("data-field");
511
+ e.querySelectorAll(".header-row > .cell").forEach((n) => {
512
+ const o = n, d = o.getAttribute("data-field");
510
513
  if (!d) return;
511
514
  const a = this.columns.find((r) => r.field === d);
512
515
  if (!this.canMoveColumnWithPlugins(a)) {
513
- n.draggable = !1;
516
+ o.draggable = !1;
514
517
  return;
515
518
  }
516
- n.draggable = !0, !n.getAttribute("data-dragstart-bound") && (n.setAttribute("data-dragstart-bound", "true"), n.addEventListener("dragstart", (r) => {
517
- const o = this.getColumnOrder().indexOf(d);
518
- this.isDragging = !0, this.draggedField = d, this.draggedIndex = o, r.dataTransfer && (r.dataTransfer.effectAllowed = "move", r.dataTransfer.setData("text/plain", d)), n.classList.add("dragging");
519
- }), n.addEventListener("dragend", () => {
519
+ o.draggable = !0, !o.getAttribute("data-dragstart-bound") && (o.setAttribute("data-dragstart-bound", "true"), o.addEventListener("dragstart", (r) => {
520
+ const i = this.getColumnOrder().indexOf(d);
521
+ this.isDragging = !0, this.draggedField = d, this.draggedIndex = i, r.dataTransfer && (r.dataTransfer.effectAllowed = "move", r.dataTransfer.setData("text/plain", d)), o.classList.add("dragging");
522
+ }), o.addEventListener("dragend", () => {
520
523
  this.isDragging = !1, this.draggedField = null, this.draggedIndex = null, this.dropIndex = null, this.clearDragClasses();
521
- }), n.addEventListener("dragover", (r) => {
524
+ }), o.addEventListener("dragover", (r) => {
522
525
  if (r.preventDefault(), !this.isDragging || this.draggedField === d) return;
523
- const s = n.getBoundingClientRect(), o = s.left + s.width / 2, u = this.getColumnOrder().indexOf(d);
524
- this.dropIndex = r.clientX < o ? u : u + 1, n.classList.add("drop-target"), n.classList.toggle("drop-before", r.clientX < o), n.classList.toggle("drop-after", r.clientX >= o);
525
- }), n.addEventListener("dragleave", () => {
526
- n.classList.remove("drop-target", "drop-before", "drop-after");
527
- }), n.addEventListener("drop", (r) => {
526
+ const s = o.getBoundingClientRect(), i = s.left + s.width / 2, u = this.getColumnOrder().indexOf(d);
527
+ this.dropIndex = r.clientX < i ? u : u + 1, o.classList.add("drop-target"), o.classList.toggle("drop-before", r.clientX < i), o.classList.toggle("drop-after", r.clientX >= i);
528
+ }), o.addEventListener("dragleave", () => {
529
+ o.classList.remove("drop-target", "drop-before", "drop-after");
530
+ }), o.addEventListener("drop", (r) => {
528
531
  r.preventDefault();
529
- const s = this.draggedField, o = this.draggedIndex, c = this.dropIndex;
530
- if (!this.isDragging || s === null || o === null || c === null)
532
+ const s = this.draggedField, i = this.draggedIndex, c = this.dropIndex;
533
+ if (!this.isDragging || s === null || i === null || c === null)
531
534
  return;
532
- const u = c > o ? c - 1 : c, f = this.getColumnOrder(), g = b(f, o, u), h = {
535
+ const u = c > i ? c - 1 : c, f = this.getColumnOrder(), g = b(f, i, u), h = {
533
536
  field: s,
534
- fromIndex: o,
537
+ fromIndex: i,
535
538
  toIndex: u,
536
539
  columnOrder: g
537
540
  };
@@ -546,16 +549,16 @@ class O extends A {
546
549
  onKeyDown(e) {
547
550
  if (!e.altKey || e.key !== "ArrowLeft" && e.key !== "ArrowRight")
548
551
  return;
549
- const t = this.grid, i = t._focusCol, n = t._visibleColumns;
550
- if (i < 0 || i >= n.length) return;
551
- const d = n[i];
552
+ const t = this.grid, n = t._focusCol, o = t._visibleColumns;
553
+ if (n < 0 || n >= o.length) return;
554
+ const d = o[n];
552
555
  if (!this.canMoveColumnWithPlugins(d)) return;
553
556
  const a = this.getColumnOrder(), r = a.indexOf(d.field);
554
557
  if (r === -1) return;
555
558
  const s = e.key === "ArrowLeft" ? r - 1 : r + 1;
556
559
  if (s < 0 || s >= a.length) return;
557
- const o = n.find((c) => c.field === a[s]);
558
- if (this.canMoveColumnWithPlugins(o))
560
+ const i = o.find((c) => c.field === a[s]);
561
+ if (this.canMoveColumnWithPlugins(i))
559
562
  return this.moveColumn(d.field, s), t._focusCol = s, y(this.grid), e.preventDefault(), e.stopPropagation(), !0;
560
563
  }
561
564
  // #endregion
@@ -573,12 +576,12 @@ class O extends A {
573
576
  * @param toIndex - The target index
574
577
  */
575
578
  moveColumn(e, t) {
576
- const i = this.getColumnOrder(), n = i.indexOf(e);
577
- if (n === -1) return;
578
- const d = b(i, n, t);
579
+ const n = this.getColumnOrder(), o = n.indexOf(e);
580
+ if (o === -1) return;
581
+ const d = b(n, o, t);
579
582
  this.emitCancelable("column-move", {
580
583
  field: e,
581
- fromIndex: n,
584
+ fromIndex: o,
582
585
  toIndex: t,
583
586
  columnOrder: d
584
587
  }) || this.updateColumnOrder(d);
@@ -605,8 +608,8 @@ class O extends A {
605
608
  captureHeaderPositions() {
606
609
  const e = /* @__PURE__ */ new Map();
607
610
  return this.gridElement?.querySelectorAll(".header-row > .cell[data-field]").forEach((t) => {
608
- const i = t.getAttribute("data-field");
609
- i && e.set(i, t.getBoundingClientRect().left);
611
+ const n = t.getAttribute("data-field");
612
+ n && e.set(n, t.getBoundingClientRect().left);
610
613
  }), e;
611
614
  }
612
615
  /**
@@ -617,30 +620,30 @@ class O extends A {
617
620
  animateFLIP(e) {
618
621
  const t = this.gridElement;
619
622
  if (!t || e.size === 0) return;
620
- const i = /* @__PURE__ */ new Map();
623
+ const n = /* @__PURE__ */ new Map();
621
624
  if (t.querySelectorAll(".header-row > .cell[data-field]").forEach((a) => {
622
625
  const r = a.getAttribute("data-field");
623
626
  if (!r) return;
624
627
  const s = e.get(r);
625
628
  if (s === void 0) return;
626
- const o = s - a.getBoundingClientRect().left;
627
- Math.abs(o) > 1 && i.set(r, o);
628
- }), i.size === 0) return;
629
- const n = [];
629
+ const i = s - a.getBoundingClientRect().left;
630
+ Math.abs(i) > 1 && n.set(r, i);
631
+ }), n.size === 0) return;
632
+ const o = [];
630
633
  if (t.querySelectorAll(".cell[data-field]").forEach((a) => {
631
- const r = i.get(a.getAttribute("data-field") ?? "");
634
+ const r = n.get(a.getAttribute("data-field") ?? "");
632
635
  if (r !== void 0) {
633
636
  const s = a;
634
- s.style.transform = `translateX(${r}px)`, n.push(s);
637
+ s.style.transform = `translateX(${r}px)`, o.push(s);
635
638
  }
636
- }), n.length === 0) return;
639
+ }), o.length === 0) return;
637
640
  this.gridElement.offsetHeight;
638
641
  const d = this.animationDuration;
639
642
  requestAnimationFrame(() => {
640
- n.forEach((a) => {
643
+ o.forEach((a) => {
641
644
  a.classList.add("flip-animating"), a.style.transform = "";
642
645
  }), setTimeout(() => {
643
- n.forEach((a) => {
646
+ o.forEach((a) => {
644
647
  a.style.transform = "", a.classList.remove("flip-animating");
645
648
  });
646
649
  }, d + 50);
@@ -656,23 +659,23 @@ class O extends A {
656
659
  e();
657
660
  return;
658
661
  }
659
- const i = this.captureHeaderPositions();
662
+ const n = this.captureHeaderPositions();
660
663
  e();
661
- const n = /* @__PURE__ */ new Set();
664
+ const o = /* @__PURE__ */ new Set();
662
665
  if (t.querySelectorAll(".header-row > .cell[data-field]").forEach((r) => {
663
666
  const s = r.getAttribute("data-field");
664
667
  if (!s) return;
665
- const o = i.get(s);
666
- if (o === void 0) return;
668
+ const i = n.get(s);
669
+ if (i === void 0) return;
667
670
  const c = r.getBoundingClientRect().left;
668
- Math.abs(o - c) > 1 && n.add(s);
669
- }), n.size === 0) return;
671
+ Math.abs(i - c) > 1 && o.add(s);
672
+ }), o.size === 0) return;
670
673
  const d = [];
671
674
  if (t.querySelectorAll(".cell[data-field]").forEach((r) => {
672
675
  const s = r.getAttribute("data-field");
673
- if (s && n.has(s)) {
674
- const o = r;
675
- o.classList.add("fade-animating"), d.push(o);
676
+ if (s && o.has(s)) {
677
+ const i = r;
678
+ i.classList.add("fade-animating"), d.push(i);
676
679
  }
677
680
  }), d.length === 0) return;
678
681
  const a = this.animationDuration;
@@ -686,9 +689,9 @@ class O extends A {
686
689
  updateColumnOrder(e) {
687
690
  const t = this.animationType;
688
691
  if (t === "flip" && this.gridElement) {
689
- const i = this.captureHeaderPositions();
692
+ const n = this.captureHeaderPositions();
690
693
  this.grid.setColumnOrder(e), requestAnimationFrame(() => {
691
- this.gridElement.offsetHeight, this.animateFLIP(i);
694
+ this.gridElement.offsetHeight, this.animateFLIP(n);
692
695
  });
693
696
  } else t === "fade" ? this.animateFade(() => this.grid.setColumnOrder(e)) : this.grid.setColumnOrder(e);
694
697
  this.grid.requestStateChange?.();
@@ -696,6 +699,6 @@ class O extends A {
696
699
  // #endregion
697
700
  }
698
701
  export {
699
- O as ReorderPlugin
702
+ R as ReorderPlugin
700
703
  };
701
704
  //# sourceMappingURL=index.js.map