@toolbox-web/grid 0.4.1 → 0.5.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 (176) hide show
  1. package/README.md +9 -13
  2. package/all.js +1678 -1588
  3. package/all.js.map +1 -1
  4. package/index.js +762 -568
  5. package/index.js.map +1 -1
  6. package/lib/core/grid.d.ts +21 -0
  7. package/lib/core/grid.d.ts.map +1 -1
  8. package/lib/core/internal/config-manager.d.ts +1 -0
  9. package/lib/core/internal/config-manager.d.ts.map +1 -1
  10. package/lib/core/internal/dom-builder.d.ts +2 -0
  11. package/lib/core/internal/dom-builder.d.ts.map +1 -1
  12. package/lib/core/internal/header.d.ts.map +1 -1
  13. package/lib/core/internal/keyboard.d.ts.map +1 -1
  14. package/lib/core/internal/resize.d.ts.map +1 -1
  15. package/lib/core/internal/rows.d.ts.map +1 -1
  16. package/lib/core/internal/shell.d.ts +19 -13
  17. package/lib/core/internal/shell.d.ts.map +1 -1
  18. package/lib/core/internal/utils.d.ts +1 -0
  19. package/lib/core/internal/utils.d.ts.map +1 -1
  20. package/lib/core/plugin/base-plugin.d.ts +70 -3
  21. package/lib/core/plugin/base-plugin.d.ts.map +1 -1
  22. package/lib/core/plugin/expander-column.d.ts +51 -0
  23. package/lib/core/plugin/expander-column.d.ts.map +1 -0
  24. package/lib/core/plugin/plugin-manager.d.ts +6 -2
  25. package/lib/core/plugin/plugin-manager.d.ts.map +1 -1
  26. package/lib/core/plugin/types.d.ts +117 -1
  27. package/lib/core/plugin/types.d.ts.map +1 -1
  28. package/lib/core/types.d.ts +10 -5
  29. package/lib/core/types.d.ts.map +1 -1
  30. package/lib/plugins/clipboard/ClipboardPlugin.d.ts +5 -4
  31. package/lib/plugins/clipboard/ClipboardPlugin.d.ts.map +1 -1
  32. package/lib/plugins/clipboard/index.d.ts +1 -1
  33. package/lib/plugins/clipboard/index.d.ts.map +1 -1
  34. package/lib/plugins/clipboard/index.js +295 -190
  35. package/lib/plugins/clipboard/index.js.map +1 -1
  36. package/lib/plugins/clipboard/types.d.ts +72 -2
  37. package/lib/plugins/clipboard/types.d.ts.map +1 -1
  38. package/lib/plugins/column-virtualization/ColumnVirtualizationPlugin.d.ts +0 -1
  39. package/lib/plugins/column-virtualization/ColumnVirtualizationPlugin.d.ts.map +1 -1
  40. package/lib/plugins/column-virtualization/index.js +143 -56
  41. package/lib/plugins/column-virtualization/index.js.map +1 -1
  42. package/lib/plugins/context-menu/ContextMenuPlugin.d.ts +0 -1
  43. package/lib/plugins/context-menu/ContextMenuPlugin.d.ts.map +1 -1
  44. package/lib/plugins/context-menu/index.js +189 -102
  45. package/lib/plugins/context-menu/index.js.map +1 -1
  46. package/lib/plugins/editing/EditingPlugin.d.ts +2 -7
  47. package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
  48. package/lib/plugins/editing/index.js +227 -150
  49. package/lib/plugins/editing/index.js.map +1 -1
  50. package/lib/plugins/export/ExportPlugin.d.ts +0 -1
  51. package/lib/plugins/export/ExportPlugin.d.ts.map +1 -1
  52. package/lib/plugins/export/index.js +184 -97
  53. package/lib/plugins/export/index.js.map +1 -1
  54. package/lib/plugins/filtering/FilteringPlugin.d.ts +14 -3
  55. package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
  56. package/lib/plugins/filtering/index.js +296 -176
  57. package/lib/plugins/filtering/index.js.map +1 -1
  58. package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts +2 -2
  59. package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts.map +1 -1
  60. package/lib/plugins/grouping-columns/grouping-columns.d.ts +1 -1
  61. package/lib/plugins/grouping-columns/grouping-columns.d.ts.map +1 -1
  62. package/lib/plugins/grouping-columns/index.js +169 -61
  63. package/lib/plugins/grouping-columns/index.js.map +1 -1
  64. package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts +14 -2
  65. package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts.map +1 -1
  66. package/lib/plugins/grouping-rows/index.js +243 -140
  67. package/lib/plugins/grouping-rows/index.js.map +1 -1
  68. package/lib/plugins/master-detail/MasterDetailPlugin.d.ts +13 -11
  69. package/lib/plugins/master-detail/MasterDetailPlugin.d.ts.map +1 -1
  70. package/lib/plugins/master-detail/index.js +278 -196
  71. package/lib/plugins/master-detail/index.js.map +1 -1
  72. package/lib/plugins/master-detail/types.d.ts +0 -10
  73. package/lib/plugins/master-detail/types.d.ts.map +1 -1
  74. package/lib/plugins/multi-sort/MultiSortPlugin.d.ts +1 -2
  75. package/lib/plugins/multi-sort/MultiSortPlugin.d.ts.map +1 -1
  76. package/lib/plugins/multi-sort/index.js +125 -40
  77. package/lib/plugins/multi-sort/index.js.map +1 -1
  78. package/lib/plugins/pinned-columns/PinnedColumnsPlugin.d.ts +0 -1
  79. package/lib/plugins/pinned-columns/PinnedColumnsPlugin.d.ts.map +1 -1
  80. package/lib/plugins/pinned-columns/index.js +156 -75
  81. package/lib/plugins/pinned-columns/index.js.map +1 -1
  82. package/lib/plugins/pinned-columns/pinned-columns.d.ts +2 -2
  83. package/lib/plugins/pinned-columns/pinned-columns.d.ts.map +1 -1
  84. package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts +1 -2
  85. package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts.map +1 -1
  86. package/lib/plugins/pinned-rows/index.js +202 -117
  87. package/lib/plugins/pinned-rows/index.js.map +1 -1
  88. package/lib/plugins/pivot/PivotPlugin.d.ts +26 -4
  89. package/lib/plugins/pivot/PivotPlugin.d.ts.map +1 -1
  90. package/lib/plugins/pivot/index.js +413 -314
  91. package/lib/plugins/pivot/index.js.map +1 -1
  92. package/lib/plugins/pivot/pivot-rows.d.ts +2 -1
  93. package/lib/plugins/pivot/pivot-rows.d.ts.map +1 -1
  94. package/lib/plugins/reorder/ReorderPlugin.d.ts +13 -10
  95. package/lib/plugins/reorder/ReorderPlugin.d.ts.map +1 -1
  96. package/lib/plugins/reorder/index.d.ts +1 -1
  97. package/lib/plugins/reorder/index.d.ts.map +1 -1
  98. package/lib/plugins/reorder/index.js +296 -223
  99. package/lib/plugins/reorder/index.js.map +1 -1
  100. package/lib/plugins/selection/SelectionPlugin.d.ts +21 -3
  101. package/lib/plugins/selection/SelectionPlugin.d.ts.map +1 -1
  102. package/lib/plugins/selection/index.d.ts +2 -2
  103. package/lib/plugins/selection/index.d.ts.map +1 -1
  104. package/lib/plugins/selection/index.js +282 -141
  105. package/lib/plugins/selection/index.js.map +1 -1
  106. package/lib/plugins/selection/types.d.ts +24 -0
  107. package/lib/plugins/selection/types.d.ts.map +1 -1
  108. package/lib/plugins/server-side/ServerSidePlugin.d.ts +0 -1
  109. package/lib/plugins/server-side/ServerSidePlugin.d.ts.map +1 -1
  110. package/lib/plugins/server-side/index.js +96 -9
  111. package/lib/plugins/server-side/index.js.map +1 -1
  112. package/lib/plugins/tree/TreePlugin.d.ts +5 -1
  113. package/lib/plugins/tree/TreePlugin.d.ts.map +1 -1
  114. package/lib/plugins/tree/index.js +209 -113
  115. package/lib/plugins/tree/index.js.map +1 -1
  116. package/lib/plugins/tree/types.d.ts +0 -10
  117. package/lib/plugins/tree/types.d.ts.map +1 -1
  118. package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts +0 -1
  119. package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts.map +1 -1
  120. package/lib/plugins/undo-redo/index.js +98 -11
  121. package/lib/plugins/undo-redo/index.js.map +1 -1
  122. package/lib/plugins/visibility/VisibilityPlugin.d.ts +7 -4
  123. package/lib/plugins/visibility/VisibilityPlugin.d.ts.map +1 -1
  124. package/lib/plugins/visibility/index.js +155 -64
  125. package/lib/plugins/visibility/index.js.map +1 -1
  126. package/package.json +1 -1
  127. package/themes/dg-theme-bootstrap.css +55 -53
  128. package/themes/dg-theme-contrast.css +42 -40
  129. package/themes/dg-theme-large.css +38 -37
  130. package/themes/dg-theme-material.css +54 -52
  131. package/themes/dg-theme-standard.css +19 -17
  132. package/themes/dg-theme-vibrant.css +16 -14
  133. package/umd/grid.all.umd.js +23 -24
  134. package/umd/grid.all.umd.js.map +1 -1
  135. package/umd/grid.umd.js +12 -11
  136. package/umd/grid.umd.js.map +1 -1
  137. package/umd/plugins/clipboard.umd.js +5 -7
  138. package/umd/plugins/clipboard.umd.js.map +1 -1
  139. package/umd/plugins/column-virtualization.umd.js +1 -1
  140. package/umd/plugins/column-virtualization.umd.js.map +1 -1
  141. package/umd/plugins/context-menu.umd.js +1 -1
  142. package/umd/plugins/context-menu.umd.js.map +1 -1
  143. package/umd/plugins/editing.umd.js +1 -1
  144. package/umd/plugins/editing.umd.js.map +1 -1
  145. package/umd/plugins/export.umd.js +1 -1
  146. package/umd/plugins/export.umd.js.map +1 -1
  147. package/umd/plugins/filtering.umd.js +1 -1
  148. package/umd/plugins/filtering.umd.js.map +1 -1
  149. package/umd/plugins/grouping-columns.umd.js +1 -1
  150. package/umd/plugins/grouping-columns.umd.js.map +1 -1
  151. package/umd/plugins/grouping-rows.umd.js +1 -1
  152. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  153. package/umd/plugins/master-detail.umd.js +1 -1
  154. package/umd/plugins/master-detail.umd.js.map +1 -1
  155. package/umd/plugins/multi-sort.umd.js +1 -1
  156. package/umd/plugins/multi-sort.umd.js.map +1 -1
  157. package/umd/plugins/pinned-columns.umd.js +1 -1
  158. package/umd/plugins/pinned-columns.umd.js.map +1 -1
  159. package/umd/plugins/pinned-rows.umd.js +1 -1
  160. package/umd/plugins/pinned-rows.umd.js.map +1 -1
  161. package/umd/plugins/pivot.umd.js +1 -1
  162. package/umd/plugins/pivot.umd.js.map +1 -1
  163. package/umd/plugins/reorder.umd.js +1 -1
  164. package/umd/plugins/reorder.umd.js.map +1 -1
  165. package/umd/plugins/selection.umd.js +1 -1
  166. package/umd/plugins/selection.umd.js.map +1 -1
  167. package/umd/plugins/server-side.umd.js +1 -1
  168. package/umd/plugins/server-side.umd.js.map +1 -1
  169. package/umd/plugins/tree.umd.js +1 -1
  170. package/umd/plugins/tree.umd.js.map +1 -1
  171. package/umd/plugins/undo-redo.umd.js +1 -1
  172. package/umd/plugins/undo-redo.umd.js.map +1 -1
  173. package/umd/plugins/visibility.umd.js +1 -1
  174. package/umd/plugins/visibility.umd.js.map +1 -1
  175. package/lib/core/internal/editing.d.ts +0 -76
  176. package/lib/core/internal/editing.d.ts.map +0 -1
@@ -1,4 +1,4 @@
1
- const x = {
1
+ const v = {
2
2
  expand: "▶",
3
3
  collapse: "▼",
4
4
  sortAsc: "▲",
@@ -25,8 +25,11 @@ class R {
25
25
  * ```
26
26
  */
27
27
  static dependencies;
28
- /** Plugin version - override in subclass if needed */
29
- version = "1.0.0";
28
+ /**
29
+ * Plugin version - defaults to grid version for built-in plugins.
30
+ * Third-party plugins can override with their own semver.
31
+ */
32
+ version = typeof __GRID_VERSION__ < "u" ? __GRID_VERSION__ : "dev";
30
33
  /** CSS styles to inject into the grid's shadow DOM */
31
34
  styles;
32
35
  /** Custom cell renderers keyed by type name */
@@ -113,12 +116,28 @@ class R {
113
116
  emit(e, t) {
114
117
  this.grid?.dispatchEvent?.(new CustomEvent(e, { detail: t, bubbles: !0 }));
115
118
  }
119
+ /**
120
+ * Emit a cancelable custom event from the grid.
121
+ * @returns `true` if the event was cancelled (preventDefault called), `false` otherwise
122
+ */
123
+ emitCancelable(e, t) {
124
+ const r = new CustomEvent(e, { detail: t, bubbles: !0, cancelable: !0 });
125
+ return this.grid?.dispatchEvent?.(r), r.defaultPrevented;
126
+ }
116
127
  /**
117
128
  * Request a re-render of the grid.
118
129
  */
119
130
  requestRender() {
120
131
  this.grid?.requestRender?.();
121
132
  }
133
+ /**
134
+ * Request a re-render and restore focus styling afterward.
135
+ * Use this when a plugin action (like expand/collapse) triggers a render
136
+ * but needs to maintain keyboard navigation focus.
137
+ */
138
+ requestRenderWithFocus() {
139
+ this.grid?.requestRenderWithFocus?.();
140
+ }
122
141
  /**
123
142
  * Request a lightweight style update without rebuilding DOM.
124
143
  * Use this instead of requestRender() when only CSS classes need updating.
@@ -153,10 +172,34 @@ class R {
153
172
  return this.grid?._visibleColumns ?? [];
154
173
  }
155
174
  /**
156
- * Get the shadow root of the grid.
175
+ * Get the grid as an HTMLElement for direct DOM operations.
176
+ * Use sparingly - prefer the typed GridElementRef API when possible.
177
+ *
178
+ * @example
179
+ * ```ts
180
+ * const width = this.gridElement.clientWidth;
181
+ * this.gridElement.classList.add('my-plugin-active');
182
+ * ```
183
+ */
184
+ get gridElement() {
185
+ return this.grid;
186
+ }
187
+ /**
188
+ * Get the render root of the grid for DOM queries.
189
+ * @deprecated Use `gridElement` instead. This getter exists only for backward compatibility.
190
+ *
191
+ * With Shadow DOM removed, the grid element itself is the render root.
192
+ * All new code should use `this.gridElement` for DOM queries.
193
+ *
194
+ * @example
195
+ * // OLD (deprecated)
196
+ * const rows = this.shadowRoot?.querySelector('.rows');
197
+ *
198
+ * // NEW (preferred)
199
+ * const rows = this.gridElement.querySelector('.rows');
157
200
  */
158
201
  get shadowRoot() {
159
- return this.grid?.shadowRoot ?? null;
202
+ return this.gridElement;
160
203
  }
161
204
  /**
162
205
  * Get the disconnect signal for event listener cleanup.
@@ -184,8 +227,53 @@ class R {
184
227
  */
185
228
  get gridIcons() {
186
229
  const e = this.grid?.gridConfig?.icons ?? {};
187
- return { ...x, ...e };
230
+ return { ...v, ...e };
231
+ }
232
+ // #region Animation Helpers
233
+ /**
234
+ * Check if animations are enabled at the grid level.
235
+ * Respects gridConfig.animation.mode and the CSS variable set by the grid.
236
+ *
237
+ * Plugins should use this to skip animations when:
238
+ * - Animation mode is 'off' or `false`
239
+ * - User prefers reduced motion and mode is 'reduced-motion' (default)
240
+ *
241
+ * @example
242
+ * ```ts
243
+ * private get animationStyle(): 'slide' | 'fade' | false {
244
+ * if (!this.isAnimationEnabled) return false;
245
+ * return this.config.animation ?? 'slide';
246
+ * }
247
+ * ```
248
+ */
249
+ get isAnimationEnabled() {
250
+ const e = this.grid?.effectiveConfig?.animation?.mode ?? "reduced-motion";
251
+ if (e === !1 || e === "off") return !1;
252
+ if (e === !0 || e === "on") return !0;
253
+ const t = this.gridElement;
254
+ return t ? getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim() !== "0" : !0;
188
255
  }
256
+ /**
257
+ * Get the animation duration in milliseconds from CSS variable.
258
+ * Falls back to 200ms if not set.
259
+ *
260
+ * Plugins can use this for their animation timing to stay consistent
261
+ * with the grid-level animation.duration setting.
262
+ *
263
+ * @example
264
+ * ```ts
265
+ * element.animate(keyframes, { duration: this.animationDuration });
266
+ * ```
267
+ */
268
+ get animationDuration() {
269
+ const e = this.gridElement;
270
+ if (e) {
271
+ const t = getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(), r = parseInt(t, 10);
272
+ if (!isNaN(r)) return r;
273
+ }
274
+ return 200;
275
+ }
276
+ // #endregion
189
277
  /**
190
278
  * Resolve an icon value to string or HTMLElement.
191
279
  * Checks plugin config first, then grid-level icons, then defaults.
@@ -215,10 +303,14 @@ class R {
215
303
  }
216
304
  // #endregion
217
305
  }
218
- const m = {
219
- sum: (n, e) => n.reduce((t, i) => t + (Number(i[e]) || 0), 0),
306
+ const x = "__tbw_expander";
307
+ function C(n) {
308
+ return n.field === x;
309
+ }
310
+ const _ = {
311
+ sum: (n, e) => n.reduce((t, r) => t + (Number(r[e]) || 0), 0),
220
312
  avg: (n, e) => {
221
- const t = n.reduce((i, r) => i + (Number(r[e]) || 0), 0);
313
+ const t = n.reduce((r, s) => r + (Number(s[e]) || 0), 0);
222
314
  return n.length ? t / n.length : 0;
223
315
  },
224
316
  count: (n) => n.length,
@@ -226,104 +318,104 @@ const m = {
226
318
  max: (n, e) => Math.max(...n.map((t) => Number(t[e]) || -1 / 0)),
227
319
  first: (n, e) => n[0]?.[e],
228
320
  last: (n, e) => n[n.length - 1]?.[e]
229
- }, _ = /* @__PURE__ */ new Map(), f = {
321
+ }, w = /* @__PURE__ */ new Map(), c = {
230
322
  /**
231
323
  * Register a custom aggregator function.
232
324
  */
233
325
  register(n, e) {
234
- _.set(n, e);
326
+ w.set(n, e);
235
327
  },
236
328
  /**
237
329
  * Unregister a custom aggregator function.
238
330
  */
239
331
  unregister(n) {
240
- _.delete(n);
332
+ w.delete(n);
241
333
  },
242
334
  /**
243
335
  * Get an aggregator function by reference.
244
336
  */
245
337
  get(n) {
246
338
  if (n !== void 0)
247
- return typeof n == "function" ? n : _.get(n) ?? m[n];
339
+ return typeof n == "function" ? n : w.get(n) ?? _[n];
248
340
  },
249
341
  /**
250
342
  * Run an aggregator on a set of rows.
251
343
  */
252
- run(n, e, t, i) {
253
- const r = this.get(n);
254
- return r ? r(e, t, i) : void 0;
344
+ run(n, e, t, r) {
345
+ const s = this.get(n);
346
+ return s ? s(e, t, r) : void 0;
255
347
  },
256
348
  /**
257
349
  * Check if an aggregator exists.
258
350
  */
259
351
  has(n) {
260
- return _.has(n) || n in m;
352
+ return w.has(n) || n in _;
261
353
  },
262
354
  /**
263
355
  * List all available aggregator names.
264
356
  */
265
357
  list() {
266
- return [...Object.keys(m), ..._.keys()];
358
+ return [...Object.keys(_), ...w.keys()];
267
359
  }
268
360
  };
269
- f.register.bind(f);
270
- f.unregister.bind(f);
271
- f.get.bind(f);
272
- const w = f.run.bind(f);
273
- f.list.bind(f);
274
- function v({ rows: n, config: e, expanded: t }) {
275
- const i = e.groupOn;
276
- if (typeof i != "function")
361
+ c.register.bind(c);
362
+ c.unregister.bind(c);
363
+ c.get.bind(c);
364
+ const y = c.run.bind(c);
365
+ c.list.bind(c);
366
+ function A({ rows: n, config: e, expanded: t }) {
367
+ const r = e.groupOn;
368
+ if (typeof r != "function")
277
369
  return [];
278
- const r = { key: "__root__", value: null, depth: -1, rows: [], children: /* @__PURE__ */ new Map() };
279
- if (n.forEach((s) => {
280
- let d = i(s);
281
- d == null || d === !1 ? d = ["__ungrouped__"] : Array.isArray(d) || (d = [d]);
282
- let a = r;
283
- d.forEach((c, b) => {
284
- const l = c == null ? "∅" : String(c), g = a.key === "__root__" ? l : a.key + "||" + l;
285
- let p = a.children.get(l);
286
- p || (p = { key: g, value: c, depth: b, rows: [], children: /* @__PURE__ */ new Map(), parent: a }, a.children.set(l, p)), a = p;
287
- }), a.rows.push(s);
288
- }), r.children.size === 1 && r.children.has("__ungrouped__") && r.children.get("__ungrouped__").rows.length === n.length)
370
+ const s = { key: "__root__", value: null, depth: -1, rows: [], children: /* @__PURE__ */ new Map() };
371
+ if (n.forEach((o) => {
372
+ let a = r(o);
373
+ a == null || a === !1 ? a = ["__ungrouped__"] : Array.isArray(a) || (a = [a]);
374
+ let u = s;
375
+ a.forEach((h, p) => {
376
+ const f = h == null ? "∅" : String(h), l = u.key === "__root__" ? f : u.key + "||" + f;
377
+ let g = u.children.get(f);
378
+ g || (g = { key: l, value: h, depth: p, rows: [], children: /* @__PURE__ */ new Map(), parent: u }, u.children.set(f, g)), u = g;
379
+ }), u.rows.push(o);
380
+ }), s.children.size === 1 && s.children.has("__ungrouped__") && s.children.get("__ungrouped__").rows.length === n.length)
289
381
  return [];
290
- const o = [], u = (s) => {
291
- if (s === r) {
292
- s.children.forEach((a) => u(a));
382
+ const i = [], d = (o) => {
383
+ if (o === s) {
384
+ o.children.forEach((u) => d(u));
293
385
  return;
294
386
  }
295
- const d = t.has(s.key);
296
- o.push({
387
+ const a = t.has(o.key);
388
+ i.push({
297
389
  kind: "group",
298
- key: s.key,
299
- value: s.value,
300
- depth: s.depth,
301
- rows: s.rows,
302
- expanded: d
303
- }), d && (s.children.size ? s.children.forEach((a) => u(a)) : s.rows.forEach((a) => o.push({ kind: "data", row: a, rowIndex: n.indexOf(a) })));
390
+ key: o.key,
391
+ value: o.value,
392
+ depth: o.depth,
393
+ rows: o.rows,
394
+ expanded: a
395
+ }), a && (o.children.size ? o.children.forEach((u) => d(u)) : o.rows.forEach((u) => i.push({ kind: "data", row: u, rowIndex: n.indexOf(u) })));
304
396
  };
305
- return u(r), o;
397
+ return d(s), i;
306
398
  }
307
- function C(n, e) {
399
+ function k(n, e) {
308
400
  const t = new Set(n);
309
401
  return t.has(e) ? t.delete(e) : t.add(e), t;
310
402
  }
311
- function A(n) {
403
+ function E(n) {
312
404
  const e = /* @__PURE__ */ new Set();
313
405
  for (const t of n)
314
406
  t.kind === "group" && e.add(t.key);
315
407
  return e;
316
408
  }
317
- function k() {
409
+ function S() {
318
410
  return /* @__PURE__ */ new Set();
319
411
  }
320
412
  function K(n) {
321
413
  return n.kind !== "group" ? 0 : n.rows.length;
322
414
  }
323
- const S = '.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, 2px 8px)}.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:20px;height:20px;margin-right:4px;background:none;border:0;font:inherit}.group-toggle:hover{background:var(--tbw-grouping-rows-toggle-hover, var(--tbw-color-row-hover));border-radius:2px}.group-label{display:inline-flex;align-items:center;gap:8px}.group-count{color:var(--tbw-grouping-rows-count-color, var(--tbw-color-fg-muted));font-size:.85em;font-weight:400}[data-group-depth="0"] .group-label{padding-left:0}[data-group-depth="1"] .group-label{padding-left:20px}[data-group-depth="2"] .group-label{padding-left:40px}[data-group-depth="3"] .group-label{padding-left:60px}[data-group-depth="4"] .group-label{padding-left:80px}.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}}';
324
- class E extends R {
415
+ const G = "@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}}}";
416
+ class T extends R {
325
417
  name = "groupingRows";
326
- version = "1.0.0";
418
+ styles = G;
327
419
  get defaultConfig() {
328
420
  return {
329
421
  defaultExpanded: !1,
@@ -341,15 +433,12 @@ class E extends R {
341
433
  keysToAnimate = /* @__PURE__ */ new Set();
342
434
  // #endregion
343
435
  // #region Animation
436
+ /**
437
+ * Get expand/collapse animation style from plugin config.
438
+ * Uses base class isAnimationEnabled to respect grid-level settings.
439
+ */
344
440
  get animationStyle() {
345
- const t = this.grid.effectiveConfig?.animation?.mode ?? "reduced-motion";
346
- if (t === !1 || t === "off") return !1;
347
- if (t !== !0 && t !== "on") {
348
- const i = this.shadowRoot?.host;
349
- if (i && getComputedStyle(i).getPropertyValue("--tbw-animation-enabled").trim() === "0")
350
- return !1;
351
- }
352
- return this.config.animation ?? "slide";
441
+ return this.isAnimationEnabled ? this.config.animation ?? "slide" : !1;
353
442
  }
354
443
  // #endregion
355
444
  // #region Lifecycle
@@ -369,119 +458,136 @@ class E extends R {
369
458
  const t = this.config;
370
459
  if (typeof t.groupOn != "function")
371
460
  return this.isActive = !1, this.flattenedRows = [], [...e];
372
- const i = v({
461
+ const r = A({
373
462
  rows: [...e],
374
463
  config: t,
375
464
  expanded: this.expandedKeys
376
465
  });
377
- if (i.length === 0)
466
+ if (r.length === 0)
378
467
  return this.isActive = !1, this.flattenedRows = [], [...e];
379
- this.isActive = !0, this.flattenedRows = i, this.keysToAnimate.clear();
380
- const r = /* @__PURE__ */ new Set();
381
- return i.forEach((o, u) => {
382
- if (o.kind === "data") {
383
- const s = `data-${u}`;
384
- r.add(s), this.previousVisibleKeys.has(s) || this.keysToAnimate.add(s);
468
+ this.isActive = !0, this.flattenedRows = r, this.keysToAnimate.clear();
469
+ const s = /* @__PURE__ */ new Set();
470
+ return r.forEach((i, d) => {
471
+ if (i.kind === "data") {
472
+ const o = `data-${d}`;
473
+ s.add(o), this.previousVisibleKeys.has(o) || this.keysToAnimate.add(o);
385
474
  }
386
- }), this.previousVisibleKeys = r, i.map((o) => o.kind === "group" ? {
475
+ }), this.previousVisibleKeys = s, r.map((i) => i.kind === "group" ? {
387
476
  __isGroupRow: !0,
388
- __groupKey: o.key,
389
- __groupValue: o.value,
390
- __groupDepth: o.depth,
391
- __groupRows: o.rows,
392
- __groupExpanded: o.expanded,
393
- __groupRowCount: K(o)
394
- } : o.row);
477
+ __groupKey: i.key,
478
+ __groupValue: i.value,
479
+ __groupDepth: i.depth,
480
+ __groupRows: i.rows,
481
+ __groupExpanded: i.expanded,
482
+ __groupRowCount: K(i)
483
+ } : i.row);
395
484
  }
396
485
  onCellClick(e) {
397
486
  const t = e.row;
398
487
  if (t?.__isGroupRow && e.originalEvent.target?.closest(".group-toggle"))
399
488
  return this.toggle(t.__groupKey), !0;
400
489
  }
490
+ onKeyDown(e) {
491
+ if (e.key !== " ") return;
492
+ const t = this.grid._focusRow, r = this.rows[t];
493
+ if (r?.__isGroupRow)
494
+ return e.preventDefault(), this.toggle(r.__groupKey), this.requestRenderWithFocus(), !0;
495
+ }
401
496
  /**
402
497
  * Render a row. Returns true if we handled the row (group row), false otherwise.
403
498
  */
404
- renderRow(e, t, i) {
499
+ renderRow(e, t, r) {
405
500
  if (!e?.__isGroupRow)
406
501
  return !1;
407
- const r = this.config;
408
- if (r.groupRowRenderer) {
409
- const s = () => {
502
+ const s = this.config;
503
+ if (s.groupRowRenderer) {
504
+ const o = () => {
410
505
  this.toggle(e.__groupKey);
411
- }, d = r.groupRowRenderer({
506
+ }, a = s.groupRowRenderer({
412
507
  key: e.__groupKey,
413
508
  value: e.__groupValue,
414
509
  depth: e.__groupDepth,
415
510
  rows: e.__groupRows,
416
511
  expanded: e.__groupExpanded,
417
- toggleExpand: s
512
+ toggleExpand: o
418
513
  });
419
- if (d)
420
- return t.className = "group-row", t.__isCustomRow = !0, t.setAttribute("data-group-depth", String(e.__groupDepth)), typeof d == "string" ? t.innerHTML = d : (t.innerHTML = "", t.appendChild(d)), !0;
514
+ if (a)
515
+ 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;
421
516
  }
422
- const o = () => {
517
+ const i = () => {
423
518
  this.toggle(e.__groupKey);
424
519
  };
425
- return t.className = "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.paddingLeft = `${(e.__groupDepth || 0) * (r.indentWidth ?? 20)}px`, t.innerHTML = "", r.fullWidth !== !1 ? this.renderFullWidthGroupRow(e, t, o) : this.renderPerColumnGroupRow(e, t, o), !0;
520
+ 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.innerHTML = "", s.fullWidth !== !1 ? this.renderFullWidthGroupRow(e, t, i) : this.renderPerColumnGroupRow(e, t, i), !0;
426
521
  }
427
522
  afterRender() {
428
523
  const e = this.animationStyle;
429
524
  if (e === !1 || this.keysToAnimate.size === 0) return;
430
- const t = this.shadowRoot?.querySelector(".rows");
525
+ const t = this.gridElement?.querySelector(".rows");
431
526
  if (!t) return;
432
- const i = e === "fade" ? "tbw-group-fade-in" : "tbw-group-slide-in";
433
- for (const r of t.querySelectorAll(".data-grid-row:not(.group-row)")) {
434
- const o = r.querySelector(".cell[data-row]"), u = o ? parseInt(o.getAttribute("data-row") ?? "-1", 10) : -1, d = this.flattenedRows[u]?.kind === "data" ? `data-${u}` : void 0;
435
- d && this.keysToAnimate.has(d) && (r.classList.add(i), r.addEventListener("animationend", () => r.classList.remove(i), { once: !0 }));
527
+ const r = e === "fade" ? "tbw-group-fade-in" : "tbw-group-slide-in";
528
+ for (const s of t.querySelectorAll(".data-grid-row:not(.group-row)")) {
529
+ const i = s.querySelector(".cell[data-row]"), d = i ? parseInt(i.getAttribute("data-row") ?? "-1", 10) : -1, a = this.flattenedRows[d]?.kind === "data" ? `data-${d}` : void 0;
530
+ a && this.keysToAnimate.has(a) && (s.classList.add(r), s.addEventListener("animationend", () => s.classList.remove(r), { once: !0 }));
436
531
  }
437
532
  this.keysToAnimate.clear();
438
533
  }
439
534
  // #endregion
440
535
  // #region Private Rendering Helpers
441
- renderFullWidthGroupRow(e, t, i) {
442
- const r = this.config, o = document.createElement("div");
443
- o.className = "cell group-full", o.style.gridColumn = "1 / -1", o.setAttribute("role", "gridcell");
444
- const u = document.createElement("button");
445
- u.type = "button", u.className = `group-toggle${e.__groupExpanded ? " expanded" : ""}`, u.setAttribute("aria-label", e.__groupExpanded ? "Collapse group" : "Expand group"), this.setIcon(u, this.resolveIcon(e.__groupExpanded ? "collapse" : "expand")), u.addEventListener("click", (a) => {
446
- a.stopPropagation(), i();
447
- }), o.appendChild(u);
448
- const s = document.createElement("span");
449
- s.className = "group-label";
450
- const d = r.formatLabel ? r.formatLabel(e.__groupValue, e.__groupDepth || 0, e.__groupKey) : String(e.__groupValue);
451
- if (s.textContent = d, o.appendChild(s), r.showRowCount !== !1) {
452
- const a = document.createElement("span");
453
- a.className = "group-count", a.textContent = `(${e.__groupRowCount ?? e.__groupRows?.length ?? 0})`, o.appendChild(a);
536
+ /**
537
+ * Create a toggle button for expanding/collapsing a group.
538
+ */
539
+ createToggleButton(e, t) {
540
+ const r = document.createElement("button");
541
+ 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) => {
542
+ s.stopPropagation(), t();
543
+ }), r;
544
+ }
545
+ /**
546
+ * Get the formatted label text for a group.
547
+ */
548
+ getGroupLabelText(e, t, r) {
549
+ const s = this.config;
550
+ return s.formatLabel ? s.formatLabel(e, t, r) : String(e);
551
+ }
552
+ renderFullWidthGroupRow(e, t, r) {
553
+ const s = this.config, i = document.createElement("div");
554
+ 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));
555
+ const d = document.createElement("span");
556
+ if (d.className = "group-label", d.textContent = this.getGroupLabelText(e.__groupValue, e.__groupDepth || 0, e.__groupKey), i.appendChild(d), s.showRowCount !== !1) {
557
+ const o = document.createElement("span");
558
+ o.className = "group-count", o.textContent = `(${e.__groupRowCount ?? e.__groupRows?.length ?? 0})`, i.appendChild(o);
454
559
  }
455
- t.appendChild(o);
560
+ t.appendChild(i);
456
561
  }
457
- renderPerColumnGroupRow(e, t, i) {
458
- const r = this.config, o = r.aggregators ?? {}, u = this.columns, s = e.__groupRows ?? [], a = this.shadowRoot?.querySelector(".body")?.style.gridTemplateColumns || "";
459
- a && (t.style.display = "grid", t.style.gridTemplateColumns = a), u.forEach((c, b) => {
562
+ renderPerColumnGroupRow(e, t, r) {
563
+ const s = this.config, i = s.aggregators ?? {}, d = this.columns, o = e.__groupRows ?? [], u = this.gridElement?.querySelector(".body")?.style.gridTemplateColumns || "";
564
+ u && (t.style.display = "grid", t.style.gridTemplateColumns = u);
565
+ let h = !1;
566
+ d.forEach((p, f) => {
460
567
  const l = document.createElement("div");
461
- if (l.className = "cell group-cell", l.setAttribute("data-col", String(b)), l.setAttribute("role", "gridcell"), b === 0) {
462
- const g = document.createElement("button");
463
- g.type = "button", g.className = `group-toggle${e.__groupExpanded ? " expanded" : ""}`, g.setAttribute("aria-label", e.__groupExpanded ? "Collapse group" : "Expand group"), this.setIcon(g, this.resolveIcon(e.__groupExpanded ? "collapse" : "expand")), g.addEventListener("click", (h) => {
464
- h.stopPropagation(), i();
465
- }), l.appendChild(g);
466
- const p = document.createElement("span"), y = o[c.field];
467
- if (y) {
468
- const h = w(y, s, c.field, c);
469
- p.textContent = h != null ? String(h) : String(e.__groupValue);
470
- } else {
471
- const h = r.formatLabel ? r.formatLabel(e.__groupValue, e.__groupDepth || 0, e.__groupKey) : String(e.__groupValue);
472
- p.textContent = h;
473
- }
474
- if (l.appendChild(p), r.showRowCount !== !1) {
475
- const h = document.createElement("span");
476
- h.className = "group-count", h.textContent = ` (${s.length})`, l.appendChild(h);
477
- }
478
- } else {
479
- const g = o[c.field];
568
+ if (l.className = "cell group-cell", l.setAttribute("data-col", String(f)), l.setAttribute("role", "gridcell"), C(p)) {
569
+ l.setAttribute("data-field", p.field), t.appendChild(l);
570
+ return;
571
+ }
572
+ if (h) {
573
+ const g = i[p.field];
480
574
  if (g) {
481
- const p = w(g, s, c.field, c);
482
- l.textContent = p != null ? String(p) : "";
575
+ const b = y(g, o, p.field, p);
576
+ l.textContent = b != null ? String(b) : "";
483
577
  } else
484
578
  l.textContent = "";
579
+ } else {
580
+ h = !0, l.appendChild(this.createToggleButton(e.__groupExpanded, r));
581
+ const g = document.createElement("span"), b = i[p.field];
582
+ if (b) {
583
+ const m = y(b, o, p.field, p);
584
+ g.textContent = m != null ? String(m) : String(e.__groupValue);
585
+ } else
586
+ g.textContent = this.getGroupLabelText(e.__groupValue, e.__groupDepth || 0, e.__groupKey);
587
+ if (l.appendChild(g), s.showRowCount !== !1) {
588
+ const m = document.createElement("span");
589
+ m.className = "group-count", m.textContent = ` (${o.length})`, l.appendChild(m);
590
+ }
485
591
  }
486
592
  t.appendChild(l);
487
593
  });
@@ -492,21 +598,21 @@ class E extends R {
492
598
  * Expand all groups.
493
599
  */
494
600
  expandAll() {
495
- this.expandedKeys = A(this.flattenedRows), this.requestRender();
601
+ this.expandedKeys = E(this.flattenedRows), this.requestRender();
496
602
  }
497
603
  /**
498
604
  * Collapse all groups.
499
605
  */
500
606
  collapseAll() {
501
- this.expandedKeys = k(), this.requestRender();
607
+ this.expandedKeys = S(), this.requestRender();
502
608
  }
503
609
  /**
504
610
  * Toggle expansion of a specific group.
505
611
  * @param key - The group key to toggle
506
612
  */
507
613
  toggle(e) {
508
- this.expandedKeys = C(this.expandedKeys, e);
509
- const t = this.flattenedRows.find((i) => i.kind === "group" && i.key === e);
614
+ this.expandedKeys = k(this.expandedKeys, e);
615
+ const t = this.flattenedRows.find((r) => r.kind === "group" && r.key === e);
510
616
  this.emit("group-toggle", {
511
617
  key: e,
512
618
  expanded: this.expandedKeys.has(e),
@@ -595,11 +701,8 @@ class E extends R {
595
701
  this.config.groupOn = e, this.requestRender();
596
702
  }
597
703
  // #endregion
598
- // #region Styles
599
- styles = S;
600
- // #endregion
601
704
  }
602
705
  export {
603
- E as GroupingRowsPlugin
706
+ T as GroupingRowsPlugin
604
707
  };
605
708
  //# sourceMappingURL=index.js.map