@toolbox-web/grid 1.4.0 → 1.6.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 (76) hide show
  1. package/all.js +859 -671
  2. package/all.js.map +1 -1
  3. package/index.js +513 -495
  4. package/index.js.map +1 -1
  5. package/lib/core/internal/header.d.ts.map +1 -1
  6. package/lib/core/internal/rows.d.ts +8 -0
  7. package/lib/core/internal/rows.d.ts.map +1 -1
  8. package/lib/core/types.d.ts +82 -17
  9. package/lib/core/types.d.ts.map +1 -1
  10. package/lib/plugins/clipboard/index.js.map +1 -1
  11. package/lib/plugins/column-virtualization/index.js.map +1 -1
  12. package/lib/plugins/context-menu/index.js.map +1 -1
  13. package/lib/plugins/editing/index.js.map +1 -1
  14. package/lib/plugins/editing/types.d.ts +68 -0
  15. package/lib/plugins/editing/types.d.ts.map +1 -1
  16. package/lib/plugins/export/index.d.ts +1 -1
  17. package/lib/plugins/export/index.d.ts.map +1 -1
  18. package/lib/plugins/export/index.js.map +1 -1
  19. package/lib/plugins/filtering/FilteringPlugin.d.ts +18 -1
  20. package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
  21. package/lib/plugins/filtering/index.d.ts +1 -1
  22. package/lib/plugins/filtering/index.d.ts.map +1 -1
  23. package/lib/plugins/filtering/index.js +313 -183
  24. package/lib/plugins/filtering/index.js.map +1 -1
  25. package/lib/plugins/filtering/types.d.ts +81 -2
  26. package/lib/plugins/filtering/types.d.ts.map +1 -1
  27. package/lib/plugins/grouping-columns/index.js.map +1 -1
  28. package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts +12 -3
  29. package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts.map +1 -1
  30. package/lib/plugins/grouping-rows/grouping-rows.d.ts +13 -2
  31. package/lib/plugins/grouping-rows/grouping-rows.d.ts.map +1 -1
  32. package/lib/plugins/grouping-rows/index.d.ts +1 -1
  33. package/lib/plugins/grouping-rows/index.d.ts.map +1 -1
  34. package/lib/plugins/grouping-rows/index.js +199 -125
  35. package/lib/plugins/grouping-rows/index.js.map +1 -1
  36. package/lib/plugins/grouping-rows/types.d.ts +24 -2
  37. package/lib/plugins/grouping-rows/types.d.ts.map +1 -1
  38. package/lib/plugins/master-detail/index.d.ts +1 -1
  39. package/lib/plugins/master-detail/index.d.ts.map +1 -1
  40. package/lib/plugins/master-detail/index.js.map +1 -1
  41. package/lib/plugins/multi-sort/index.js.map +1 -1
  42. package/lib/plugins/pinned-columns/index.js.map +1 -1
  43. package/lib/plugins/pinned-rows/index.js +1 -1
  44. package/lib/plugins/pinned-rows/index.js.map +1 -1
  45. package/lib/plugins/pivot/index.js.map +1 -1
  46. package/lib/plugins/print/index.js.map +1 -1
  47. package/lib/plugins/reorder/index.js.map +1 -1
  48. package/lib/plugins/responsive/index.js.map +1 -1
  49. package/lib/plugins/row-reorder/index.js.map +1 -1
  50. package/lib/plugins/selection/SelectionPlugin.d.ts +5 -0
  51. package/lib/plugins/selection/SelectionPlugin.d.ts.map +1 -1
  52. package/lib/plugins/selection/index.js +90 -77
  53. package/lib/plugins/selection/index.js.map +1 -1
  54. package/lib/plugins/selection/types.d.ts +45 -0
  55. package/lib/plugins/selection/types.d.ts.map +1 -1
  56. package/lib/plugins/server-side/index.js.map +1 -1
  57. package/lib/plugins/tree/index.js.map +1 -1
  58. package/lib/plugins/undo-redo/index.d.ts +1 -1
  59. package/lib/plugins/undo-redo/index.d.ts.map +1 -1
  60. package/lib/plugins/undo-redo/index.js.map +1 -1
  61. package/lib/plugins/visibility/index.d.ts +1 -1
  62. package/lib/plugins/visibility/index.d.ts.map +1 -1
  63. package/lib/plugins/visibility/index.js.map +1 -1
  64. package/package.json +1 -1
  65. package/umd/grid.all.umd.js +27 -24
  66. package/umd/grid.all.umd.js.map +1 -1
  67. package/umd/grid.umd.js +10 -10
  68. package/umd/grid.umd.js.map +1 -1
  69. package/umd/plugins/filtering.umd.js +1 -1
  70. package/umd/plugins/filtering.umd.js.map +1 -1
  71. package/umd/plugins/grouping-rows.umd.js +4 -1
  72. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  73. package/umd/plugins/pinned-rows.umd.js +1 -1
  74. package/umd/plugins/pinned-rows.umd.js.map +1 -1
  75. package/umd/plugins/selection.umd.js +2 -2
  76. package/umd/plugins/selection.umd.js.map +1 -1
@@ -1,4 +1,4 @@
1
- const y = '<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>', R = {
1
+ const x = '<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>', R = {
2
2
  expand: "▶",
3
3
  collapse: "▼",
4
4
  sortAsc: "▲",
@@ -7,11 +7,11 @@ const y = '<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentCo
7
7
  submenuArrow: "▶",
8
8
  dragHandle: "⋮⋮",
9
9
  toolPanel: "☰",
10
- filter: y,
11
- filterActive: y,
10
+ filter: x,
11
+ filterActive: x,
12
12
  print: "🖨️"
13
13
  };
14
- class x {
14
+ class C {
15
15
  /**
16
16
  * Plugin dependencies - declare other plugins this one requires.
17
17
  *
@@ -311,14 +311,14 @@ class x {
311
311
  }
312
312
  // #endregion
313
313
  }
314
- const C = "__tbw_expander";
314
+ const E = "__tbw_expander";
315
315
  function A(n) {
316
- return n.field === C;
316
+ return n.field === E;
317
317
  }
318
- const _ = {
318
+ const y = {
319
319
  sum: (n, e) => n.reduce((t, r) => t + (Number(r[e]) || 0), 0),
320
320
  avg: (n, e) => {
321
- const t = n.reduce((r, i) => r + (Number(i[e]) || 0), 0);
321
+ const t = n.reduce((r, s) => r + (Number(s[e]) || 0), 0);
322
322
  return n.length ? t / n.length : 0;
323
323
  },
324
324
  count: (n) => n.length,
@@ -326,106 +326,138 @@ const _ = {
326
326
  max: (n, e) => Math.max(...n.map((t) => Number(t[e]) || -1 / 0)),
327
327
  first: (n, e) => n[0]?.[e],
328
328
  last: (n, e) => n[n.length - 1]?.[e]
329
- }, w = /* @__PURE__ */ new Map(), c = {
329
+ }, b = /* @__PURE__ */ new Map(), m = {
330
330
  /**
331
331
  * Register a custom aggregator function.
332
332
  */
333
333
  register(n, e) {
334
- w.set(n, e);
334
+ b.set(n, e);
335
335
  },
336
336
  /**
337
337
  * Unregister a custom aggregator function.
338
338
  */
339
339
  unregister(n) {
340
- w.delete(n);
340
+ b.delete(n);
341
341
  },
342
342
  /**
343
343
  * Get an aggregator function by reference.
344
344
  */
345
345
  get(n) {
346
346
  if (n !== void 0)
347
- return typeof n == "function" ? n : w.get(n) ?? _[n];
347
+ return typeof n == "function" ? n : b.get(n) ?? y[n];
348
348
  },
349
349
  /**
350
350
  * Run an aggregator on a set of rows.
351
351
  */
352
352
  run(n, e, t, r) {
353
- const i = this.get(n);
354
- return i ? i(e, t, r) : void 0;
353
+ const s = this.get(n);
354
+ return s ? s(e, t, r) : void 0;
355
355
  },
356
356
  /**
357
357
  * Check if an aggregator exists.
358
358
  */
359
359
  has(n) {
360
- return w.has(n) || n in _;
360
+ return b.has(n) || n in y;
361
361
  },
362
362
  /**
363
363
  * List all available aggregator names.
364
364
  */
365
365
  list() {
366
- return [...Object.keys(_), ...w.keys()];
366
+ return [...Object.keys(y), ...b.keys()];
367
367
  }
368
368
  };
369
- c.register.bind(c);
370
- c.unregister.bind(c);
371
- c.get.bind(c);
372
- const v = c.run.bind(c);
373
- c.list.bind(c);
374
- function k({ rows: n, config: e, expanded: t }) {
375
- const r = e.groupOn;
376
- if (typeof r != "function")
369
+ m.register.bind(m);
370
+ m.unregister.bind(m);
371
+ m.get.bind(m);
372
+ const _ = m.run.bind(m);
373
+ m.list.bind(m);
374
+ function v({ rows: n, config: e, expanded: t, initialExpanded: r }) {
375
+ const s = e.groupOn;
376
+ if (typeof s != "function")
377
377
  return [];
378
- const i = { key: "__root__", value: null, depth: -1, rows: [], children: /* @__PURE__ */ new Map() };
379
- if (n.forEach((o) => {
380
- let a = r(o);
381
- a == null || a === !1 ? a = ["__ungrouped__"] : Array.isArray(a) || (a = [a]);
382
- let u = i;
383
- a.forEach((h, p) => {
384
- const f = h == null ? "∅" : String(h), l = u.key === "__root__" ? f : u.key + "||" + f;
385
- let g = u.children.get(f);
386
- g || (g = { key: l, value: h, depth: p, rows: [], children: /* @__PURE__ */ new Map(), parent: u }, u.children.set(f, g)), u = g;
387
- }), u.rows.push(o);
388
- }), i.children.size === 1 && i.children.has("__ungrouped__") && i.children.get("__ungrouped__").rows.length === n.length)
378
+ const o = { key: "__root__", value: null, depth: -1, rows: [], children: /* @__PURE__ */ new Map() };
379
+ if (n.forEach((d) => {
380
+ let u = s(d);
381
+ u == null || u === !1 ? u = ["__ungrouped__"] : Array.isArray(u) || (u = [u]);
382
+ let a = o;
383
+ u.forEach((w, p) => {
384
+ const c = w == null ? "∅" : String(w), h = a.key === "__root__" ? c : a.key + "||" + c;
385
+ let f = a.children.get(c);
386
+ f || (f = { key: h, value: w, depth: p, rows: [], children: /* @__PURE__ */ new Map(), parent: a }, a.children.set(c, f)), a = f;
387
+ }), a.rows.push(d);
388
+ }), o.children.size === 1 && o.children.has("__ungrouped__") && o.children.get("__ungrouped__").rows.length === n.length)
389
389
  return [];
390
- const s = [], d = (o) => {
391
- if (o === i) {
392
- o.children.forEach((u) => d(u));
390
+ const g = /* @__PURE__ */ new Set([...t, ...r ?? []]), i = [], l = (d) => {
391
+ if (d === o) {
392
+ d.children.forEach((a) => l(a));
393
393
  return;
394
394
  }
395
- const a = t.has(o.key);
396
- s.push({
395
+ const u = g.has(d.key);
396
+ i.push({
397
397
  kind: "group",
398
- key: o.key,
399
- value: o.value,
400
- depth: o.depth,
401
- rows: o.rows,
402
- expanded: a
403
- }), a && (o.children.size ? o.children.forEach((u) => d(u)) : o.rows.forEach((u) => s.push({ kind: "data", row: u, rowIndex: n.indexOf(u) })));
398
+ key: d.key,
399
+ value: d.value,
400
+ depth: d.depth,
401
+ rows: d.rows,
402
+ expanded: u
403
+ }), u && (d.children.size ? d.children.forEach((a) => l(a)) : d.rows.forEach((a) => i.push({ kind: "data", row: a, rowIndex: n.indexOf(a) })));
404
404
  };
405
- return d(i), s;
405
+ return l(o), i;
406
406
  }
407
- function E(n, e) {
407
+ function S(n, e) {
408
408
  const t = new Set(n);
409
409
  return t.has(e) ? t.delete(e) : t.add(e), t;
410
410
  }
411
- function S(n) {
411
+ function K(n) {
412
412
  const e = /* @__PURE__ */ new Set();
413
413
  for (const t of n)
414
414
  t.kind === "group" && e.add(t.key);
415
415
  return e;
416
416
  }
417
- function K() {
417
+ function k() {
418
418
  return /* @__PURE__ */ new Set();
419
419
  }
420
- function G(n) {
420
+ function G(n, e) {
421
+ if (n === !0)
422
+ return new Set(e);
423
+ if (n === !1 || n == null)
424
+ return /* @__PURE__ */ new Set();
425
+ if (typeof n == "number") {
426
+ const t = e[n];
427
+ return t ? /* @__PURE__ */ new Set([t]) : /* @__PURE__ */ new Set();
428
+ }
429
+ return typeof n == "string" ? /* @__PURE__ */ new Set([n]) : Array.isArray(n) ? new Set(n) : /* @__PURE__ */ new Set();
430
+ }
431
+ function T(n) {
432
+ return n.filter((e) => e.kind === "group").map((e) => e.key);
433
+ }
434
+ function I(n) {
421
435
  return n.kind !== "group" ? 0 : n.rows.length;
422
436
  }
423
- const T = "@layer tbw-plugins{.group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-grouping-rows-bg, var(--tbw-color-panel-bg));font-weight:500;border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height)}.group-row .cell{display:flex;align-items:center;padding:var(--tbw-cell-padding, .125rem .5rem)}.group-row:hover{background:var(--tbw-grouping-rows-bg-hover, var(--tbw-color-row-hover))}.group-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-toggle-size, 1.25rem);height:var(--tbw-toggle-size, 1.25rem);margin-right:.25rem;background:none;border:0;font:inherit}.group-toggle:hover{background:var(--tbw-grouping-rows-toggle-hover, var(--tbw-color-row-hover));border-radius:var(--tbw-border-radius, .125rem)}.group-label{display:inline-flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.group-count{color:var(--tbw-grouping-rows-count-color, var(--tbw-color-fg-muted));font-size:var(--tbw-font-size-xs, .85em);font-weight:400}.group-row{padding-left:calc(var(--tbw-group-depth, 0) * var(--tbw-group-indent-width, 1.25em))}.data-grid-row.tbw-group-slide-in{animation:tbw-group-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-group-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.data-grid-row.tbw-group-fade-in{animation:tbw-group-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-group-fade-in{0%{opacity:0}to{opacity:1}}}";
424
- class I extends x {
437
+ const N = "@layer tbw-plugins{.group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-grouping-rows-bg, var(--tbw-color-panel-bg));font-weight:500;border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height)}.group-row .cell{display:flex;align-items:center;padding:var(--tbw-cell-padding, .125rem .5rem)}.group-row:hover{background:var(--tbw-grouping-rows-bg-hover, var(--tbw-color-row-hover))}.group-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-toggle-size, 1.25rem);height:var(--tbw-toggle-size, 1.25rem);margin-right:.25rem;background:none;border:0;font:inherit}.group-toggle:hover{background:var(--tbw-grouping-rows-toggle-hover, var(--tbw-color-row-hover));border-radius:var(--tbw-border-radius, .125rem)}.group-label{display:inline-flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.group-count{color:var(--tbw-grouping-rows-count-color, var(--tbw-color-fg-muted));font-size:var(--tbw-font-size-xs, .85em);font-weight:400}.group-aggregates{display:inline-flex;align-items:center;gap:var(--tbw-spacing-lg, 1rem);margin-left:var(--tbw-spacing-lg, 1rem);font-weight:400;font-size:var(--tbw-font-size-sm, .875em);color:var(--tbw-grouping-rows-aggregate-color, var(--tbw-color-fg-muted))}.group-aggregate{white-space:nowrap}.group-row{padding-left:calc(var(--tbw-group-depth, 0) * var(--tbw-group-indent-width, 1.25em))}.data-grid-row.tbw-group-slide-in{animation:tbw-group-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-group-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.data-grid-row.tbw-group-fade-in{animation:tbw-group-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-group-fade-in{0%{opacity:0}to{opacity:1}}}";
438
+ class D extends C {
439
+ /**
440
+ * Plugin manifest - declares configuration validation rules.
441
+ * @internal
442
+ */
443
+ static manifest = {
444
+ configRules: [
445
+ {
446
+ id: "groupingRows/accordion-defaultExpanded",
447
+ severity: "warn",
448
+ message: `"accordion: true" and "defaultExpanded" (non-false) are used together.
449
+ → In accordion mode, only one group can be open at a time.
450
+ → Using defaultExpanded with multiple groups will collapse to one on first toggle.
451
+ → Consider using "defaultExpanded: false" or a single group key/index with accordion mode.`,
452
+ check: (e) => e.accordion === !0 && e.defaultExpanded !== !1 && e.defaultExpanded !== void 0 && typeof e.defaultExpanded != "number" && typeof e.defaultExpanded != "string" && // Warn if true or array with multiple items
453
+ (e.defaultExpanded === !0 || Array.isArray(e.defaultExpanded) && e.defaultExpanded.length > 1)
454
+ }
455
+ ]
456
+ };
425
457
  /** @internal */
426
458
  name = "groupingRows";
427
459
  /** @internal */
428
- styles = T;
460
+ styles = N;
429
461
  /** @internal */
430
462
  get defaultConfig() {
431
463
  return {
@@ -433,7 +465,8 @@ class I extends x {
433
465
  showRowCount: !0,
434
466
  indentWidth: 20,
435
467
  aggregators: {},
436
- animation: "slide"
468
+ animation: "slide",
469
+ accordion: !1
437
470
  };
438
471
  }
439
472
  // #region Internal State
@@ -442,6 +475,8 @@ class I extends x {
442
475
  isActive = !1;
443
476
  previousVisibleKeys = /* @__PURE__ */ new Set();
444
477
  keysToAnimate = /* @__PURE__ */ new Set();
478
+ /** Track if initial defaultExpanded has been applied */
479
+ hasAppliedDefaultExpanded = !1;
445
480
  // #endregion
446
481
  // #region Animation
447
482
  /**
@@ -455,7 +490,7 @@ class I extends x {
455
490
  // #region Lifecycle
456
491
  /** @internal */
457
492
  detach() {
458
- this.expandedKeys.clear(), this.flattenedRows = [], this.isActive = !1, this.previousVisibleKeys.clear(), this.keysToAnimate.clear();
493
+ this.expandedKeys.clear(), this.flattenedRows = [], this.isActive = !1, this.previousVisibleKeys.clear(), this.keysToAnimate.clear(), this.hasAppliedDefaultExpanded = !1;
459
494
  }
460
495
  // #endregion
461
496
  // #region Hooks
@@ -471,29 +506,41 @@ class I extends x {
471
506
  const t = this.config;
472
507
  if (typeof t.groupOn != "function")
473
508
  return this.isActive = !1, this.flattenedRows = [], [...e];
474
- const r = k({
509
+ const r = v({
475
510
  rows: [...e],
476
511
  config: t,
477
- expanded: this.expandedKeys
512
+ expanded: /* @__PURE__ */ new Set()
513
+ // Empty to get all root groups
478
514
  });
479
515
  if (r.length === 0)
480
516
  return this.isActive = !1, this.flattenedRows = [], [...e];
481
- this.isActive = !0, this.flattenedRows = r, this.keysToAnimate.clear();
482
- const i = /* @__PURE__ */ new Set();
483
- return r.forEach((s, d) => {
484
- if (s.kind === "data") {
485
- const o = `data-${d}`;
486
- i.add(o), this.previousVisibleKeys.has(o) || this.keysToAnimate.add(o);
517
+ let s;
518
+ if (!this.hasAppliedDefaultExpanded && this.expandedKeys.size === 0 && t.defaultExpanded !== !1) {
519
+ const i = T(r);
520
+ s = G(t.defaultExpanded ?? !1, i), s.size > 0 && (this.expandedKeys = new Set(s), this.hasAppliedDefaultExpanded = !0);
521
+ }
522
+ const o = v({
523
+ rows: [...e],
524
+ config: t,
525
+ expanded: this.expandedKeys,
526
+ initialExpanded: s
527
+ });
528
+ this.isActive = !0, this.flattenedRows = o, this.keysToAnimate.clear();
529
+ const g = /* @__PURE__ */ new Set();
530
+ return o.forEach((i, l) => {
531
+ if (i.kind === "data") {
532
+ const d = `data-${l}`;
533
+ g.add(d), this.previousVisibleKeys.has(d) || this.keysToAnimate.add(d);
487
534
  }
488
- }), this.previousVisibleKeys = i, r.map((s) => s.kind === "group" ? {
535
+ }), this.previousVisibleKeys = g, o.map((i) => i.kind === "group" ? {
489
536
  __isGroupRow: !0,
490
- __groupKey: s.key,
491
- __groupValue: s.value,
492
- __groupDepth: s.depth,
493
- __groupRows: s.rows,
494
- __groupExpanded: s.expanded,
495
- __groupRowCount: G(s)
496
- } : s.row);
537
+ __groupKey: i.key,
538
+ __groupValue: i.value,
539
+ __groupDepth: i.depth,
540
+ __groupRows: i.rows,
541
+ __groupExpanded: i.expanded,
542
+ __groupRowCount: I(i)
543
+ } : i.row);
497
544
  }
498
545
  /** @internal */
499
546
  onCellClick(e) {
@@ -515,25 +562,25 @@ class I extends x {
515
562
  renderRow(e, t, r) {
516
563
  if (!e?.__isGroupRow)
517
564
  return !1;
518
- const i = this.config;
519
- if (i.groupRowRenderer) {
520
- const o = () => {
565
+ const s = this.config;
566
+ if (s.groupRowRenderer) {
567
+ const i = () => {
521
568
  this.toggle(e.__groupKey);
522
- }, a = i.groupRowRenderer({
569
+ }, l = s.groupRowRenderer({
523
570
  key: e.__groupKey,
524
571
  value: e.__groupValue,
525
572
  depth: e.__groupDepth,
526
573
  rows: e.__groupRows,
527
574
  expanded: e.__groupExpanded,
528
- toggleExpand: o
575
+ toggleExpand: i
529
576
  });
530
- if (a)
531
- return t.className = "data-grid-row group-row", t.__isCustomRow = !0, t.setAttribute("data-group-depth", String(e.__groupDepth)), typeof a == "string" ? t.innerHTML = a : (t.innerHTML = "", t.appendChild(a)), !0;
577
+ if (l)
578
+ return t.className = "data-grid-row group-row", t.__isCustomRow = !0, t.setAttribute("data-group-depth", String(e.__groupDepth)), typeof l == "string" ? t.innerHTML = l : (t.innerHTML = "", t.appendChild(l)), !0;
532
579
  }
533
- const s = () => {
580
+ const o = () => {
534
581
  this.toggle(e.__groupKey);
535
582
  };
536
- return t.className = "data-grid-row group-row", t.__isCustomRow = !0, t.setAttribute("data-group-depth", String(e.__groupDepth)), t.setAttribute("role", "row"), t.setAttribute("aria-expanded", String(e.__groupExpanded)), t.style.setProperty("--tbw-group-depth", String(e.__groupDepth || 0)), i.indentWidth !== void 0 && t.style.setProperty("--tbw-group-indent-width", `${i.indentWidth}px`), t.style.height = "", t.innerHTML = "", i.fullWidth !== !1 ? this.renderFullWidthGroupRow(e, t, s) : this.renderPerColumnGroupRow(e, t, s), !0;
583
+ return t.className = "data-grid-row group-row", t.__isCustomRow = !0, t.setAttribute("data-group-depth", String(e.__groupDepth)), t.setAttribute("role", "row"), t.setAttribute("aria-expanded", String(e.__groupExpanded)), t.style.setProperty("--tbw-group-depth", String(e.__groupDepth || 0)), s.indentWidth !== void 0 && t.style.setProperty("--tbw-group-indent-width", `${s.indentWidth}px`), t.style.height = "", t.innerHTML = "", s.fullWidth !== !1 ? this.renderFullWidthGroupRow(e, t, o) : this.renderPerColumnGroupRow(e, t, o), !0;
537
584
  }
538
585
  /** @internal */
539
586
  afterRender() {
@@ -542,9 +589,9 @@ class I extends x {
542
589
  const t = this.gridElement?.querySelector(".rows");
543
590
  if (!t) return;
544
591
  const r = e === "fade" ? "tbw-group-fade-in" : "tbw-group-slide-in";
545
- for (const i of t.querySelectorAll(".data-grid-row:not(.group-row)")) {
546
- const s = i.querySelector(".cell[data-row]"), d = s ? parseInt(s.getAttribute("data-row") ?? "-1", 10) : -1, a = this.flattenedRows[d]?.kind === "data" ? `data-${d}` : void 0;
547
- a && this.keysToAnimate.has(a) && (i.classList.add(r), i.addEventListener("animationend", () => i.classList.remove(r), { once: !0 }));
592
+ for (const s of t.querySelectorAll(".data-grid-row:not(.group-row)")) {
593
+ const o = s.querySelector(".cell[data-row]"), g = o ? parseInt(o.getAttribute("data-row") ?? "-1", 10) : -1, l = this.flattenedRows[g]?.kind === "data" ? `data-${g}` : void 0;
594
+ l && this.keysToAnimate.has(l) && (s.classList.add(r), s.addEventListener("animationend", () => s.classList.remove(r), { once: !0 }));
548
595
  }
549
596
  this.keysToAnimate.clear();
550
597
  }
@@ -555,58 +602,73 @@ class I extends x {
555
602
  */
556
603
  createToggleButton(e, t) {
557
604
  const r = document.createElement("button");
558
- return r.type = "button", r.className = `group-toggle${e ? " expanded" : ""}`, r.setAttribute("aria-label", e ? "Collapse group" : "Expand group"), this.setIcon(r, this.resolveIcon(e ? "collapse" : "expand")), r.addEventListener("click", (i) => {
559
- i.stopPropagation(), t();
605
+ return r.type = "button", r.className = `group-toggle${e ? " expanded" : ""}`, r.setAttribute("aria-label", e ? "Collapse group" : "Expand group"), this.setIcon(r, this.resolveIcon(e ? "collapse" : "expand")), r.addEventListener("click", (s) => {
606
+ s.stopPropagation(), t();
560
607
  }), r;
561
608
  }
562
609
  /**
563
610
  * Get the formatted label text for a group.
564
611
  */
565
612
  getGroupLabelText(e, t, r) {
566
- const i = this.config;
567
- return i.formatLabel ? i.formatLabel(e, t, r) : String(e);
613
+ const s = this.config;
614
+ return s.formatLabel ? s.formatLabel(e, t, r) : String(e);
568
615
  }
569
616
  renderFullWidthGroupRow(e, t, r) {
570
- const i = this.config, s = document.createElement("div");
571
- s.className = "cell group-full", s.style.gridColumn = "1 / -1", s.setAttribute("role", "gridcell"), s.setAttribute("data-col", "0"), s.appendChild(this.createToggleButton(e.__groupExpanded, r));
572
- const d = document.createElement("span");
573
- if (d.className = "group-label", d.textContent = this.getGroupLabelText(e.__groupValue, e.__groupDepth || 0, e.__groupKey), s.appendChild(d), i.showRowCount !== !1) {
574
- const o = document.createElement("span");
575
- o.className = "group-count", o.textContent = `(${e.__groupRowCount ?? e.__groupRows?.length ?? 0})`, s.appendChild(o);
617
+ const s = this.config, o = s.aggregators ?? {}, g = e.__groupRows ?? [], i = document.createElement("div");
618
+ i.className = "cell group-full", i.style.gridColumn = "1 / -1", i.setAttribute("role", "gridcell"), i.setAttribute("data-col", "0"), i.appendChild(this.createToggleButton(e.__groupExpanded, r));
619
+ const l = document.createElement("span");
620
+ if (l.className = "group-label", l.textContent = this.getGroupLabelText(e.__groupValue, e.__groupDepth || 0, e.__groupKey), i.appendChild(l), s.showRowCount !== !1) {
621
+ const u = document.createElement("span");
622
+ u.className = "group-count", u.textContent = `(${e.__groupRowCount ?? e.__groupRows?.length ?? 0})`, i.appendChild(u);
576
623
  }
577
- t.appendChild(s);
624
+ const d = Object.entries(o);
625
+ if (d.length > 0) {
626
+ const u = document.createElement("span");
627
+ u.className = "group-aggregates";
628
+ for (const [a, w] of d) {
629
+ const p = this.columns.find((h) => h.field === a), c = _(w, g, a, p);
630
+ if (c != null) {
631
+ const h = document.createElement("span");
632
+ h.className = "group-aggregate", h.setAttribute("data-field", a);
633
+ const f = p?.header ?? a;
634
+ h.textContent = `${f}: ${c}`, u.appendChild(h);
635
+ }
636
+ }
637
+ u.children.length > 0 && i.appendChild(u);
638
+ }
639
+ t.appendChild(i);
578
640
  }
579
641
  renderPerColumnGroupRow(e, t, r) {
580
- const i = this.config, s = i.aggregators ?? {}, d = this.columns, o = e.__groupRows ?? [], u = this.gridElement?.querySelector(".body")?.style.gridTemplateColumns || "";
581
- u && (t.style.display = "grid", t.style.gridTemplateColumns = u);
582
- let h = !1;
583
- d.forEach((p, f) => {
584
- const l = document.createElement("div");
585
- if (l.className = "cell group-cell", l.setAttribute("data-col", String(f)), l.setAttribute("role", "gridcell"), A(p)) {
586
- l.setAttribute("data-field", p.field), t.appendChild(l);
642
+ const s = this.config, o = s.aggregators ?? {}, g = this.columns, i = e.__groupRows ?? [], d = this.gridElement?.querySelector(".body")?.style.gridTemplateColumns || "";
643
+ d && (t.style.display = "grid", t.style.gridTemplateColumns = d);
644
+ let u = !1;
645
+ g.forEach((a, w) => {
646
+ const p = document.createElement("div");
647
+ if (p.className = "cell group-cell", p.setAttribute("data-col", String(w)), p.setAttribute("role", "gridcell"), A(a)) {
648
+ p.setAttribute("data-field", a.field), t.appendChild(p);
587
649
  return;
588
650
  }
589
- if (h) {
590
- const g = s[p.field];
591
- if (g) {
592
- const b = v(g, o, p.field, p);
593
- l.textContent = b != null ? String(b) : "";
651
+ if (u) {
652
+ const c = o[a.field];
653
+ if (c) {
654
+ const h = _(c, i, a.field, a);
655
+ p.textContent = h != null ? String(h) : "";
594
656
  } else
595
- l.textContent = "";
657
+ p.textContent = "";
596
658
  } else {
597
- h = !0, l.appendChild(this.createToggleButton(e.__groupExpanded, r));
598
- const g = document.createElement("span"), b = s[p.field];
599
- if (b) {
600
- const m = v(b, o, p.field, p);
601
- g.textContent = m != null ? String(m) : String(e.__groupValue);
659
+ u = !0, p.appendChild(this.createToggleButton(e.__groupExpanded, r));
660
+ const c = document.createElement("span"), h = o[a.field];
661
+ if (h) {
662
+ const f = _(h, i, a.field, a);
663
+ c.textContent = f != null ? String(f) : String(e.__groupValue);
602
664
  } else
603
- g.textContent = this.getGroupLabelText(e.__groupValue, e.__groupDepth || 0, e.__groupKey);
604
- if (l.appendChild(g), i.showRowCount !== !1) {
605
- const m = document.createElement("span");
606
- m.className = "group-count", m.textContent = ` (${o.length})`, l.appendChild(m);
665
+ c.textContent = this.getGroupLabelText(e.__groupValue, e.__groupDepth || 0, e.__groupKey);
666
+ if (p.appendChild(c), s.showRowCount !== !1) {
667
+ const f = document.createElement("span");
668
+ f.className = "group-count", f.textContent = ` (${i.length})`, p.appendChild(f);
607
669
  }
608
670
  }
609
- t.appendChild(l);
671
+ t.appendChild(p);
610
672
  });
611
673
  }
612
674
  // #endregion
@@ -615,26 +677,38 @@ class I extends x {
615
677
  * Expand all groups.
616
678
  */
617
679
  expandAll() {
618
- this.expandedKeys = S(this.flattenedRows), this.requestRender();
680
+ this.expandedKeys = K(this.flattenedRows), this.requestRender();
619
681
  }
620
682
  /**
621
683
  * Collapse all groups.
622
684
  */
623
685
  collapseAll() {
624
- this.expandedKeys = K(), this.requestRender();
686
+ this.expandedKeys = k(), this.requestRender();
625
687
  }
626
688
  /**
627
689
  * Toggle expansion of a specific group.
690
+ * In accordion mode, expanding a group will collapse all sibling groups.
628
691
  * @param key - The group key to toggle
629
692
  */
630
693
  toggle(e) {
631
- this.expandedKeys = E(this.expandedKeys, e);
632
- const t = this.flattenedRows.find((r) => r.kind === "group" && r.key === e);
694
+ const t = !this.expandedKeys.has(e), r = this.config, s = this.flattenedRows.find((o) => o.kind === "group" && o.key === e);
695
+ if (r.accordion && t && s) {
696
+ const o = /* @__PURE__ */ new Set();
697
+ for (const g of this.expandedKeys)
698
+ if (e.startsWith(g + "||") || g.startsWith(e + "||"))
699
+ e.startsWith(g + "||") && o.add(g);
700
+ else {
701
+ const i = this.flattenedRows.find((l) => l.kind === "group" && l.key === g);
702
+ i && i.depth !== s.depth && o.add(g);
703
+ }
704
+ o.add(e), this.expandedKeys = o;
705
+ } else
706
+ this.expandedKeys = S(this.expandedKeys, e);
633
707
  this.emit("group-toggle", {
634
708
  key: e,
635
709
  expanded: this.expandedKeys.has(e),
636
- value: t?.value,
637
- depth: t?.depth ?? 0
710
+ value: s?.value,
711
+ depth: s?.depth ?? 0
638
712
  }), this.requestRender();
639
713
  }
640
714
  /**
@@ -720,6 +794,6 @@ class I extends x {
720
794
  // #endregion
721
795
  }
722
796
  export {
723
- I as GroupingRowsPlugin
797
+ D as GroupingRowsPlugin
724
798
  };
725
799
  //# sourceMappingURL=index.js.map