@toolbox-web/grid 0.2.5 → 0.2.7

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 (71) hide show
  1. package/all.d.ts +486 -80
  2. package/all.js +1364 -1029
  3. package/all.js.map +1 -1
  4. package/index-DG2CZ_Zo.js +3229 -0
  5. package/index-DG2CZ_Zo.js.map +1 -0
  6. package/index.d.ts +222 -11
  7. package/index.js +25 -3143
  8. package/index.js.map +1 -1
  9. package/lib/plugins/clipboard/index.js +1 -1
  10. package/lib/plugins/clipboard/index.js.map +1 -1
  11. package/lib/plugins/column-virtualization/index.js +1 -1
  12. package/lib/plugins/column-virtualization/index.js.map +1 -1
  13. package/lib/plugins/context-menu/index.js +1 -1
  14. package/lib/plugins/context-menu/index.js.map +1 -1
  15. package/lib/plugins/export/index.js +1 -1
  16. package/lib/plugins/export/index.js.map +1 -1
  17. package/lib/plugins/filtering/index.js +184 -149
  18. package/lib/plugins/filtering/index.js.map +1 -1
  19. package/lib/plugins/grouping-columns/index.js +46 -45
  20. package/lib/plugins/grouping-columns/index.js.map +1 -1
  21. package/lib/plugins/grouping-rows/index.js +117 -83
  22. package/lib/plugins/grouping-rows/index.js.map +1 -1
  23. package/lib/plugins/master-detail/index.js +140 -82
  24. package/lib/plugins/master-detail/index.js.map +1 -1
  25. package/lib/plugins/multi-sort/index.js +18 -18
  26. package/lib/plugins/multi-sort/index.js.map +1 -1
  27. package/lib/plugins/pinned-columns/index.js +1 -1
  28. package/lib/plugins/pinned-columns/index.js.map +1 -1
  29. package/lib/plugins/pinned-rows/index.js +55 -47
  30. package/lib/plugins/pinned-rows/index.js.map +1 -1
  31. package/lib/plugins/pivot/index.js +385 -351
  32. package/lib/plugins/pivot/index.js.map +1 -1
  33. package/lib/plugins/reorder/index.js +278 -85
  34. package/lib/plugins/reorder/index.js.map +1 -1
  35. package/lib/plugins/selection/index.js +28 -27
  36. package/lib/plugins/selection/index.js.map +1 -1
  37. package/lib/plugins/server-side/index.js +2 -2
  38. package/lib/plugins/server-side/index.js.map +1 -1
  39. package/lib/plugins/tree/index.js +181 -170
  40. package/lib/plugins/tree/index.js.map +1 -1
  41. package/lib/plugins/undo-redo/index.js +1 -1
  42. package/lib/plugins/undo-redo/index.js.map +1 -1
  43. package/lib/plugins/visibility/index.js +1 -1
  44. package/lib/plugins/visibility/index.js.map +1 -1
  45. package/package.json +1 -1
  46. package/umd/grid.all.umd.js +22 -22
  47. package/umd/grid.all.umd.js.map +1 -1
  48. package/umd/grid.umd.js +12 -12
  49. package/umd/grid.umd.js.map +1 -1
  50. package/umd/plugins/filtering.umd.js +1 -1
  51. package/umd/plugins/filtering.umd.js.map +1 -1
  52. package/umd/plugins/grouping-columns.umd.js +1 -1
  53. package/umd/plugins/grouping-columns.umd.js.map +1 -1
  54. package/umd/plugins/grouping-rows.umd.js +1 -1
  55. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  56. package/umd/plugins/master-detail.umd.js +1 -1
  57. package/umd/plugins/master-detail.umd.js.map +1 -1
  58. package/umd/plugins/multi-sort.umd.js +1 -1
  59. package/umd/plugins/multi-sort.umd.js.map +1 -1
  60. package/umd/plugins/pinned-rows.umd.js +1 -1
  61. package/umd/plugins/pinned-rows.umd.js.map +1 -1
  62. package/umd/plugins/pivot.umd.js +1 -1
  63. package/umd/plugins/pivot.umd.js.map +1 -1
  64. package/umd/plugins/reorder.umd.js +1 -1
  65. package/umd/plugins/reorder.umd.js.map +1 -1
  66. package/umd/plugins/selection.umd.js +1 -1
  67. package/umd/plugins/selection.umd.js.map +1 -1
  68. package/umd/plugins/server-side.umd.js +1 -1
  69. package/umd/plugins/server-side.umd.js.map +1 -1
  70. package/umd/plugins/tree.umd.js +1 -1
  71. package/umd/plugins/tree.umd.js.map +1 -1
@@ -1,4 +1,4 @@
1
- const p = {
1
+ const w = {
2
2
  expand: "▶",
3
3
  collapse: "▼",
4
4
  sortAsc: "▲",
@@ -8,7 +8,7 @@ const p = {
8
8
  dragHandle: "⋮⋮",
9
9
  toolPanel: "☰"
10
10
  };
11
- class x {
11
+ class m {
12
12
  /** Plugin version - override in subclass if needed */
13
13
  version = "1.0.0";
14
14
  /** CSS styles to inject into the grid's shadow DOM */
@@ -99,7 +99,7 @@ class x {
99
99
  * Use this for rendering that needs to match the grid template.
100
100
  */
101
101
  get visibleColumns() {
102
- return this.grid?.visibleColumns ?? [];
102
+ return this.grid?._visibleColumns ?? [];
103
103
  }
104
104
  /**
105
105
  * Get the shadow root of the grid.
@@ -133,7 +133,7 @@ class x {
133
133
  */
134
134
  get gridIcons() {
135
135
  const e = this.grid?.gridConfig?.icons ?? {};
136
- return { ...p, ...e };
136
+ return { ...w, ...e };
137
137
  }
138
138
  /**
139
139
  * Resolve an icon value to string or HTMLElement.
@@ -164,31 +164,31 @@ class x {
164
164
  }
165
165
  // #endregion
166
166
  }
167
- function g(a, e) {
168
- const t = new Set(a);
167
+ function p(c, e) {
168
+ const t = new Set(c);
169
169
  return t.has(e) ? t.delete(e) : t.add(e), t;
170
170
  }
171
- function R(a, e) {
172
- const t = new Set(a);
171
+ function x(c, e) {
172
+ const t = new Set(c);
173
173
  return t.add(e), t;
174
174
  }
175
- function m(a, e) {
176
- const t = new Set(a);
175
+ function R(c, e) {
176
+ const t = new Set(c);
177
177
  return t.delete(e), t;
178
178
  }
179
- function E(a, e) {
180
- return a.has(e);
179
+ function b(c, e) {
180
+ return c.has(e);
181
181
  }
182
- function b(a, e, t, r) {
182
+ function E(c, e, t, i) {
183
183
  const o = document.createElement("div");
184
184
  o.className = "master-detail-row", o.setAttribute("data-detail-for", String(e)), o.setAttribute("role", "row");
185
- const d = document.createElement("div");
186
- d.className = "master-detail-cell", d.setAttribute("role", "cell"), d.style.gridColumn = `1 / ${r + 1}`;
187
- const n = t(a, e);
188
- return typeof n == "string" ? d.innerHTML = n : n instanceof HTMLElement && d.appendChild(n), o.appendChild(d), o;
185
+ const a = document.createElement("div");
186
+ a.className = "master-detail-cell", a.setAttribute("role", "cell"), a.style.gridColumn = `1 / ${i + 1}`;
187
+ const r = t(c, e);
188
+ return typeof r == "string" ? a.innerHTML = r : r instanceof HTMLElement && a.appendChild(r), o.appendChild(a), o;
189
189
  }
190
- const C = ".master-detail-cell-wrapper{display:flex;align-items:center;gap:4px}.master-detail-toggle{cursor:pointer;font-size:10px;opacity:.7;-webkit-user-select:none;user-select:none}.master-detail-toggle:hover{opacity:1}.master-detail-row{grid-column:1 / -1;display:grid;background:var(--tbw-master-detail-bg, var(--tbw-color-row-alt));border-bottom:1px solid var(--tbw-master-detail-border, var(--tbw-color-border))}.master-detail-cell{padding:16px;overflow:auto}";
191
- class v extends x {
190
+ const y = ".master-detail-cell-wrapper{display:flex;align-items:center;gap:4px}.master-detail-toggle{cursor:pointer;opacity:.7;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center}.master-detail-toggle:hover{opacity:1}.master-detail-row{grid-column:1 / -1;display:grid;background:var(--tbw-master-detail-bg, var(--tbw-color-row-alt));border-bottom:1px solid var(--tbw-master-detail-border, var(--tbw-color-border));overflow:hidden}.master-detail-cell{padding:16px;overflow:auto}.master-detail-row.tbw-expanding{animation:tbw-detail-expand var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}.master-detail-row.tbw-collapsing{animation:tbw-detail-collapse var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-detail-expand{0%{opacity:0;max-height:0;padding-top:0;padding-bottom:0}to{opacity:1;max-height:500px;padding-top:16px;padding-bottom:16px}}@keyframes tbw-detail-collapse{0%{opacity:1;max-height:500px}to{opacity:0;max-height:0}}";
191
+ class C extends m {
192
192
  name = "masterDetail";
193
193
  version = "1.0.0";
194
194
  get defaultConfig() {
@@ -196,9 +196,67 @@ class v extends x {
196
196
  detailHeight: "auto",
197
197
  expandOnRowClick: !1,
198
198
  collapseOnClickOutside: !1,
199
- showExpandColumn: !0
199
+ showExpandColumn: !0,
200
+ animation: "slide"
201
+ // Plugin's own default
200
202
  };
201
203
  }
204
+ // #region Animation Helpers
205
+ /**
206
+ * Check if animations are enabled at the grid level.
207
+ * Respects gridConfig.animation.mode and CSS variable.
208
+ */
209
+ get isAnimationEnabled() {
210
+ const t = this.grid.effectiveConfig?.animation?.mode ?? "reduced-motion";
211
+ if (t === !1 || t === "off") return !1;
212
+ if (t === !0 || t === "on") return !0;
213
+ const i = this.shadowRoot?.host;
214
+ return i ? getComputedStyle(i).getPropertyValue("--tbw-animation-enabled").trim() !== "0" : !0;
215
+ }
216
+ /**
217
+ * Get expand/collapse animation style from plugin config.
218
+ */
219
+ get animationStyle() {
220
+ return this.isAnimationEnabled ? this.config.animation ?? "slide" : !1;
221
+ }
222
+ /**
223
+ * Get animation duration from CSS variable (set by grid).
224
+ */
225
+ get animationDuration() {
226
+ const e = this.shadowRoot?.host;
227
+ if (e) {
228
+ const t = getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(), i = parseInt(t, 10);
229
+ if (!isNaN(i)) return i;
230
+ }
231
+ return 200;
232
+ }
233
+ /**
234
+ * Apply expand animation to a detail element.
235
+ */
236
+ animateExpand(e) {
237
+ !this.isAnimationEnabled || this.animationStyle === !1 || (e.classList.add("tbw-expanding"), e.addEventListener(
238
+ "animationend",
239
+ () => {
240
+ e.classList.remove("tbw-expanding");
241
+ },
242
+ { once: !0 }
243
+ ));
244
+ }
245
+ /**
246
+ * Apply collapse animation to a detail element and remove after animation.
247
+ */
248
+ animateCollapse(e, t) {
249
+ if (!this.isAnimationEnabled || this.animationStyle === !1) {
250
+ t();
251
+ return;
252
+ }
253
+ e.classList.add("tbw-collapsing");
254
+ const i = () => {
255
+ e.classList.remove("tbw-collapsing"), t();
256
+ };
257
+ e.addEventListener("animationend", i, { once: !0 }), setTimeout(i, this.animationDuration + 50);
258
+ }
259
+ // #endregion
202
260
  // #region Internal State
203
261
  expandedRows = /* @__PURE__ */ new Set();
204
262
  detailElements = /* @__PURE__ */ new Map();
@@ -214,37 +272,37 @@ class v extends x {
214
272
  return [...e];
215
273
  const t = [...e];
216
274
  if (t.length > 0) {
217
- const r = { ...t[0] }, o = r.viewRenderer;
275
+ const i = { ...t[0] }, o = i.viewRenderer;
218
276
  if (o?.__masterDetailWrapped)
219
277
  return t;
220
- const d = (n) => {
221
- const { value: i, row: s } = n, l = this.expandedRows.has(s), c = document.createElement("span");
222
- c.className = "master-detail-cell-wrapper";
278
+ const a = (r) => {
279
+ const { value: s, row: n } = r, d = this.expandedRows.has(n), l = document.createElement("span");
280
+ l.className = "master-detail-cell-wrapper";
223
281
  const h = document.createElement("span");
224
- h.className = "master-detail-toggle", this.setIcon(h, this.resolveIcon(l ? "collapse" : "expand")), h.setAttribute("role", "button"), h.setAttribute("tabindex", "0"), h.setAttribute("aria-expanded", String(l)), h.setAttribute("aria-label", l ? "Collapse details" : "Expand details"), h.addEventListener("click", (f) => {
225
- f.stopPropagation();
226
- const w = this.rows.indexOf(s);
227
- this.expandedRows = g(this.expandedRows, s), this.emit("detail-expand", {
228
- rowIndex: w,
229
- row: s,
230
- expanded: this.expandedRows.has(s)
282
+ h.className = `master-detail-toggle${d ? " expanded" : ""}`, this.setIcon(h, this.resolveIcon(d ? "collapse" : "expand")), h.setAttribute("role", "button"), h.setAttribute("tabindex", "0"), h.setAttribute("aria-expanded", String(d)), h.setAttribute("aria-label", d ? "Collapse details" : "Expand details"), h.addEventListener("click", (g) => {
283
+ g.stopPropagation();
284
+ const f = this.rows.indexOf(n);
285
+ this.expandedRows = p(this.expandedRows, n), this.emit("detail-expand", {
286
+ rowIndex: f,
287
+ row: n,
288
+ expanded: this.expandedRows.has(n)
231
289
  }), this.requestRender();
232
- }), c.appendChild(h);
290
+ }), l.appendChild(h);
233
291
  const u = document.createElement("span");
234
292
  if (o) {
235
- const f = o(n);
236
- f instanceof Node ? u.appendChild(f) : u.textContent = String(f ?? i ?? "");
293
+ const g = o(r);
294
+ g instanceof Node ? u.appendChild(g) : u.textContent = String(g ?? s ?? "");
237
295
  } else
238
- u.textContent = String(i ?? "");
239
- return c.appendChild(u), c;
296
+ u.textContent = String(s ?? "");
297
+ return l.appendChild(u), l;
240
298
  };
241
- d.__masterDetailWrapped = !0, r.viewRenderer = d, t[0] = r;
299
+ a.__masterDetailWrapped = !0, i.viewRenderer = a, t[0] = i;
242
300
  }
243
301
  return t;
244
302
  }
245
303
  onRowClick(e) {
246
304
  if (!(!this.config.expandOnRowClick || !this.config.detailRenderer))
247
- return this.expandedRows = g(this.expandedRows, e.row), this.emit("detail-expand", {
305
+ return this.expandedRows = p(this.expandedRows, e.row), this.emit("detail-expand", {
248
306
  rowIndex: e.rowIndex,
249
307
  row: e.row,
250
308
  expanded: this.expandedRows.has(e.row)
@@ -271,26 +329,26 @@ class v extends x {
271
329
  if (!this.config.detailRenderer) return;
272
330
  const e = this.shadowRoot?.querySelector(".rows");
273
331
  if (!e) return;
274
- const t = /* @__PURE__ */ new Map(), r = e.querySelectorAll(".data-grid-row"), o = this.columns.length;
275
- for (const n of r) {
276
- const i = n.querySelector(".cell[data-row]"), s = i ? parseInt(i.getAttribute("data-row") ?? "-1", 10) : -1;
277
- s >= 0 && t.set(s, n);
332
+ const t = /* @__PURE__ */ new Map(), i = e.querySelectorAll(".data-grid-row"), o = this.columns.length;
333
+ for (const r of i) {
334
+ const s = r.querySelector(".cell[data-row]"), n = s ? parseInt(s.getAttribute("data-row") ?? "-1", 10) : -1;
335
+ n >= 0 && t.set(n, r);
278
336
  }
279
- const d = e.querySelectorAll(".master-detail-row");
280
- for (const n of d) {
281
- const i = parseInt(n.getAttribute("data-detail-for") ?? "-1", 10), s = i >= 0 ? this.rows[i] : void 0, l = s && this.expandedRows.has(s), c = t.has(i);
282
- (!l || !c) && (n.remove(), s && this.detailElements.delete(s));
337
+ const a = e.querySelectorAll(".master-detail-row");
338
+ for (const r of a) {
339
+ const s = parseInt(r.getAttribute("data-detail-for") ?? "-1", 10), n = s >= 0 ? this.rows[s] : void 0, d = n && this.expandedRows.has(n), l = t.has(s);
340
+ (!d || !l) && (r.remove(), n && this.detailElements.delete(n));
283
341
  }
284
- for (const [n, i] of t) {
285
- const s = this.rows[n];
286
- if (!s || !this.expandedRows.has(s)) continue;
287
- const l = this.detailElements.get(s);
288
- if (l) {
289
- l.previousElementSibling !== i && i.after(l);
342
+ for (const [r, s] of t) {
343
+ const n = this.rows[r];
344
+ if (!n || !this.expandedRows.has(n)) continue;
345
+ const d = this.detailElements.get(n);
346
+ if (d) {
347
+ d.previousElementSibling !== s && s.after(d);
290
348
  continue;
291
349
  }
292
- const c = b(s, n, this.config.detailRenderer, o);
293
- typeof this.config.detailHeight == "number" && (c.style.height = `${this.config.detailHeight}px`), i.after(c), this.detailElements.set(s, c);
350
+ const l = E(n, r, this.config.detailRenderer, o);
351
+ typeof this.config.detailHeight == "number" && (l.style.height = `${this.config.detailHeight}px`), s.after(l), this.detailElements.set(n, l), this.animateExpand(l);
294
352
  }
295
353
  }
296
354
  /**
@@ -300,9 +358,9 @@ class v extends x {
300
358
  getExtraHeight() {
301
359
  let e = 0;
302
360
  for (const t of this.expandedRows) {
303
- const r = this.detailElements.get(t);
304
- if (r)
305
- e += r.offsetHeight;
361
+ const i = this.detailElements.get(t);
362
+ if (i)
363
+ e += i.offsetHeight;
306
364
  else {
307
365
  const o = this.config?.detailHeight;
308
366
  e += typeof o == "number" ? o : 150;
@@ -316,15 +374,15 @@ class v extends x {
316
374
  */
317
375
  getExtraHeightBefore(e) {
318
376
  let t = 0;
319
- for (const r of this.expandedRows) {
320
- const o = this.rows.indexOf(r);
377
+ for (const i of this.expandedRows) {
378
+ const o = this.rows.indexOf(i);
321
379
  if (o >= 0 && o < e) {
322
- const d = this.detailElements.get(r);
323
- if (d)
324
- t += d.offsetHeight;
380
+ const a = this.detailElements.get(i);
381
+ if (a)
382
+ t += a.offsetHeight;
325
383
  else {
326
- const n = this.config?.detailHeight;
327
- t += typeof n == "number" ? n : 150;
384
+ const r = this.config?.detailHeight;
385
+ t += typeof r == "number" ? r : 150;
328
386
  }
329
387
  }
330
388
  }
@@ -334,20 +392,20 @@ class v extends x {
334
392
  * Adjust the virtualization start index to keep expanded row visible while its detail is visible.
335
393
  * This ensures the detail scrolls smoothly out of view instead of disappearing abruptly.
336
394
  */
337
- adjustVirtualStart(e, t, r) {
395
+ adjustVirtualStart(e, t, i) {
338
396
  if (this.expandedRows.size === 0) return e;
339
397
  const o = [];
340
- for (const i of this.expandedRows) {
341
- const s = this.rows.indexOf(i);
342
- s >= 0 && o.push({ index: s, row: i });
398
+ for (const s of this.expandedRows) {
399
+ const n = this.rows.indexOf(s);
400
+ n >= 0 && o.push({ index: n, row: s });
343
401
  }
344
- o.sort((i, s) => i.index - s.index);
345
- let d = e, n = 0;
346
- for (const { index: i, row: s } of o) {
347
- const l = i * r + n, h = this.detailElements.get(s)?.offsetHeight ?? (typeof this.config?.detailHeight == "number" ? this.config.detailHeight : 150), u = l + r + h;
348
- n += h, !(i >= e) && u > t && i < d && (d = i);
402
+ o.sort((s, n) => s.index - n.index);
403
+ let a = e, r = 0;
404
+ for (const { index: s, row: n } of o) {
405
+ const d = s * i + r, h = this.detailElements.get(n)?.offsetHeight ?? (typeof this.config?.detailHeight == "number" ? this.config.detailHeight : 150), u = d + i + h;
406
+ r += h, !(s >= e) && u > t && s < a && (a = s);
349
407
  }
350
- return d;
408
+ return a;
351
409
  }
352
410
  // #endregion
353
411
  // #region Public API
@@ -357,7 +415,7 @@ class v extends x {
357
415
  */
358
416
  expand(e) {
359
417
  const t = this.rows[e];
360
- t && (this.expandedRows = R(this.expandedRows, t), this.requestRender());
418
+ t && (this.expandedRows = x(this.expandedRows, t), this.requestRender());
361
419
  }
362
420
  /**
363
421
  * Collapse the detail row at the given index.
@@ -365,7 +423,7 @@ class v extends x {
365
423
  */
366
424
  collapse(e) {
367
425
  const t = this.rows[e];
368
- t && (this.expandedRows = m(this.expandedRows, t), this.requestRender());
426
+ t && (this.expandedRows = R(this.expandedRows, t), this.requestRender());
369
427
  }
370
428
  /**
371
429
  * Toggle the detail row at the given index.
@@ -373,7 +431,7 @@ class v extends x {
373
431
  */
374
432
  toggle(e) {
375
433
  const t = this.rows[e];
376
- t && (this.expandedRows = g(this.expandedRows, t), this.requestRender());
434
+ t && (this.expandedRows = p(this.expandedRows, t), this.requestRender());
377
435
  }
378
436
  /**
379
437
  * Check if the detail row at the given index is expanded.
@@ -382,7 +440,7 @@ class v extends x {
382
440
  */
383
441
  isExpanded(e) {
384
442
  const t = this.rows[e];
385
- return t ? E(this.expandedRows, t) : !1;
443
+ return t ? b(this.expandedRows, t) : !1;
386
444
  }
387
445
  /**
388
446
  * Expand all detail rows.
@@ -405,8 +463,8 @@ class v extends x {
405
463
  getExpandedRows() {
406
464
  const e = [];
407
465
  for (const t of this.expandedRows) {
408
- const r = this.rows.indexOf(t);
409
- r >= 0 && e.push(r);
466
+ const i = this.rows.indexOf(t);
467
+ i >= 0 && e.push(i);
410
468
  }
411
469
  return e;
412
470
  }
@@ -421,10 +479,10 @@ class v extends x {
421
479
  }
422
480
  // #endregion
423
481
  // #region Styles
424
- styles = C;
482
+ styles = y;
425
483
  // #endregion
426
484
  }
427
485
  export {
428
- v as MasterDetailPlugin
486
+ C as MasterDetailPlugin
429
487
  };
430
488
  //# sourceMappingURL=index.js.map