@toolbox-web/grid 0.0.5 → 0.0.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 (61) hide show
  1. package/README.md +43 -0
  2. package/all.d.ts +1680 -129
  3. package/all.js +440 -340
  4. package/all.js.map +1 -1
  5. package/custom-elements.json +1852 -0
  6. package/index.d.ts +133 -1
  7. package/index.js +726 -637
  8. package/index.js.map +1 -1
  9. package/lib/plugins/clipboard/index.js +62 -24
  10. package/lib/plugins/clipboard/index.js.map +1 -1
  11. package/lib/plugins/column-virtualization/index.js +82 -44
  12. package/lib/plugins/column-virtualization/index.js.map +1 -1
  13. package/lib/plugins/context-menu/index.js +141 -93
  14. package/lib/plugins/context-menu/index.js.map +1 -1
  15. package/lib/plugins/export/index.js +47 -9
  16. package/lib/plugins/export/index.js.map +1 -1
  17. package/lib/plugins/filtering/index.js +89 -51
  18. package/lib/plugins/filtering/index.js.map +1 -1
  19. package/lib/plugins/grouping-columns/index.js +71 -33
  20. package/lib/plugins/grouping-columns/index.js.map +1 -1
  21. package/lib/plugins/grouping-rows/index.js +91 -55
  22. package/lib/plugins/grouping-rows/index.js.map +1 -1
  23. package/lib/plugins/master-detail/index.js +176 -54
  24. package/lib/plugins/master-detail/index.js.map +1 -1
  25. package/lib/plugins/multi-sort/index.js +83 -45
  26. package/lib/plugins/multi-sort/index.js.map +1 -1
  27. package/lib/plugins/pinned-columns/index.js +54 -16
  28. package/lib/plugins/pinned-columns/index.js.map +1 -1
  29. package/lib/plugins/pinned-rows/index.js +45 -7
  30. package/lib/plugins/pinned-rows/index.js.map +1 -1
  31. package/lib/plugins/pivot/index.js +97 -59
  32. package/lib/plugins/pivot/index.js.map +1 -1
  33. package/lib/plugins/reorder/index.js +71 -33
  34. package/lib/plugins/reorder/index.js.map +1 -1
  35. package/lib/plugins/selection/index.js +132 -94
  36. package/lib/plugins/selection/index.js.map +1 -1
  37. package/lib/plugins/server-side/index.js +76 -38
  38. package/lib/plugins/server-side/index.js.map +1 -1
  39. package/lib/plugins/tree/index.js +76 -38
  40. package/lib/plugins/tree/index.js.map +1 -1
  41. package/lib/plugins/undo-redo/index.js +50 -12
  42. package/lib/plugins/undo-redo/index.js.map +1 -1
  43. package/lib/plugins/visibility/index.js +62 -24
  44. package/lib/plugins/visibility/index.js.map +1 -1
  45. package/package.json +1 -1
  46. package/umd/grid.all.umd.js +31 -31
  47. package/umd/grid.all.umd.js.map +1 -1
  48. package/umd/grid.umd.js +14 -14
  49. package/umd/grid.umd.js.map +1 -1
  50. package/umd/plugins/context-menu.umd.js +2 -2
  51. package/umd/plugins/context-menu.umd.js.map +1 -1
  52. package/umd/plugins/grouping-rows.umd.js +2 -2
  53. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  54. package/umd/plugins/master-detail.umd.js +2 -2
  55. package/umd/plugins/master-detail.umd.js.map +1 -1
  56. package/umd/plugins/multi-sort.umd.js +1 -1
  57. package/umd/plugins/multi-sort.umd.js.map +1 -1
  58. package/umd/plugins/tree.umd.js +2 -2
  59. package/umd/plugins/tree.umd.js.map +1 -1
  60. package/umd/plugins/visibility.umd.js +1 -1
  61. package/umd/plugins/visibility.umd.js.map +1 -1
@@ -1,4 +1,13 @@
1
- class f {
1
+ const f = {
2
+ expand: "▶",
3
+ collapse: "▼",
4
+ sortAsc: "▲",
5
+ sortDesc: "▼",
6
+ sortNone: "⇅",
7
+ submenuArrow: "▶",
8
+ dragHandle: "⋮⋮"
9
+ };
10
+ class w {
2
11
  /** Plugin version - override in subclass if needed */
3
12
  version = "1.0.0";
4
13
  /** CSS styles to inject into the grid's shadow DOM */
@@ -117,6 +126,35 @@ class f {
117
126
  get disconnectSignal() {
118
127
  return this.grid?.disconnectSignal;
119
128
  }
129
+ /**
130
+ * Get the grid-level icons configuration.
131
+ * Returns merged icons (user config + defaults).
132
+ */
133
+ get gridIcons() {
134
+ const e = this.grid?.gridConfig?.icons ?? {};
135
+ return { ...f, ...e };
136
+ }
137
+ /**
138
+ * Resolve an icon value to string or HTMLElement.
139
+ * Checks plugin config first, then grid-level icons, then defaults.
140
+ *
141
+ * @param iconKey - The icon key in GridIcons (e.g., 'expand', 'collapse')
142
+ * @param pluginOverride - Optional plugin-level override
143
+ * @returns The resolved icon value
144
+ */
145
+ resolveIcon(e, t) {
146
+ return t !== void 0 ? t : this.gridIcons[e];
147
+ }
148
+ /**
149
+ * Set an icon value on an element.
150
+ * Handles both string (text/HTML) and HTMLElement values.
151
+ *
152
+ * @param element - The element to set the icon on
153
+ * @param icon - The icon value (string or HTMLElement)
154
+ */
155
+ setIcon(e, t) {
156
+ typeof t == "string" ? e.innerHTML = t : t instanceof HTMLElement && (e.innerHTML = "", e.appendChild(t.cloneNode(!0)));
157
+ }
120
158
  /**
121
159
  * Log a warning message.
122
160
  */
@@ -124,7 +162,7 @@ class f {
124
162
  console.warn(`[tbw-grid:${this.name}] ${e}`);
125
163
  }
126
164
  }
127
- function h(s) {
165
+ function d(s) {
128
166
  return {
129
167
  startRow: Math.min(s.startRow, s.endRow),
130
168
  startCol: Math.min(s.startCol, s.endCol),
@@ -132,35 +170,35 @@ function h(s) {
132
170
  endCol: Math.max(s.startCol, s.endCol)
133
171
  };
134
172
  }
135
- function w(s) {
136
- const e = h(s);
173
+ function R(s) {
174
+ const e = d(s);
137
175
  return {
138
176
  from: { row: e.startRow, col: e.startCol },
139
177
  to: { row: e.endRow, col: e.endCol }
140
178
  };
141
179
  }
142
- function d(s) {
143
- return s.map(w);
180
+ function h(s) {
181
+ return s.map(R);
144
182
  }
145
- function R(s, e, t) {
146
- const l = h(t);
147
- return s >= l.startRow && s <= l.endRow && e >= l.startCol && e <= l.endCol;
183
+ function C(s, e, t) {
184
+ const r = d(t);
185
+ return s >= r.startRow && s <= r.endRow && e >= r.startCol && e <= r.endCol;
148
186
  }
149
187
  function g(s, e, t) {
150
- return t.some((l) => R(s, e, l));
188
+ return t.some((r) => C(s, e, r));
151
189
  }
152
- function C(s) {
153
- const e = [], t = h(s);
154
- for (let l = t.startRow; l <= t.endRow; l++)
155
- for (let r = t.startCol; r <= t.endCol; r++)
156
- e.push({ row: l, col: r });
190
+ function m(s) {
191
+ const e = [], t = d(s);
192
+ for (let r = t.startRow; r <= t.endRow; r++)
193
+ for (let n = t.startCol; n <= t.endCol; n++)
194
+ e.push({ row: r, col: n });
157
195
  return e;
158
196
  }
159
- function m(s) {
197
+ function b(s) {
160
198
  const e = /* @__PURE__ */ new Map();
161
199
  for (const t of s)
162
- for (const l of C(t))
163
- e.set(`${l.row},${l.col}`, l);
200
+ for (const r of m(t))
201
+ e.set(`${r.row},${r.col}`, r);
164
202
  return [...e.values()];
165
203
  }
166
204
  function u(s, e) {
@@ -171,7 +209,7 @@ function u(s, e) {
171
209
  endCol: e.col
172
210
  };
173
211
  }
174
- function b(s, e, t) {
212
+ function A(s, e, t) {
175
213
  if (s === "cell" && e.selectedCell)
176
214
  return {
177
215
  mode: s,
@@ -183,15 +221,15 @@ function b(s, e, t) {
183
221
  ]
184
222
  };
185
223
  if (s === "row" && e.selected.size > 0) {
186
- const l = [...e.selected].map((r) => ({
187
- from: { row: r, col: 0 },
188
- to: { row: r, col: t - 1 }
224
+ const r = [...e.selected].map((n) => ({
225
+ from: { row: n, col: 0 },
226
+ to: { row: n, col: t - 1 }
189
227
  }));
190
- return { mode: s, ranges: l };
228
+ return { mode: s, ranges: r };
191
229
  }
192
- return s === "range" && e.ranges.length > 0 ? { mode: s, ranges: d(e.ranges) } : { mode: s, ranges: [] };
230
+ return s === "range" && e.ranges.length > 0 ? { mode: s, ranges: h(e.ranges) } : { mode: s, ranges: [] };
193
231
  }
194
- class v extends f {
232
+ class v extends w {
195
233
  name = "selection";
196
234
  version = "1.0.0";
197
235
  get defaultConfig() {
@@ -217,32 +255,32 @@ class v extends f {
217
255
  }
218
256
  // ===== Event Handlers =====
219
257
  onCellClick(e) {
220
- const { rowIndex: t, colIndex: l, originalEvent: r } = e, { mode: n } = this.config;
221
- if (n === "cell")
222
- return this.selectedCell = { row: t, col: l }, this.emit("selection-change", this.#e()), this.requestAfterRender(), !1;
223
- if (n === "row")
258
+ const { rowIndex: t, colIndex: r, originalEvent: n } = e, { mode: o } = this.config;
259
+ if (o === "cell")
260
+ return this.selectedCell = { row: t, col: r }, this.emit("selection-change", this.#e()), this.requestAfterRender(), !1;
261
+ if (o === "row")
224
262
  return this.selected.clear(), this.selected.add(t), this.lastSelected = t, this.emit("selection-change", this.#e()), this.requestAfterRender(), !1;
225
- if (n === "range") {
226
- const a = r.shiftKey, i = r.ctrlKey || r.metaKey;
263
+ if (o === "range") {
264
+ const a = n.shiftKey, i = n.ctrlKey || n.metaKey;
227
265
  if (a && this.cellAnchor) {
228
- const o = u(this.cellAnchor, { row: t, col: l });
229
- i ? this.ranges.length > 0 ? this.ranges[this.ranges.length - 1] = o : this.ranges.push(o) : this.ranges = [o], this.activeRange = o;
266
+ const l = u(this.cellAnchor, { row: t, col: r });
267
+ i ? this.ranges.length > 0 ? this.ranges[this.ranges.length - 1] = l : this.ranges.push(l) : this.ranges = [l], this.activeRange = l;
230
268
  } else if (i) {
231
- const o = {
269
+ const l = {
232
270
  startRow: t,
233
- startCol: l,
271
+ startCol: r,
234
272
  endRow: t,
235
- endCol: l
273
+ endCol: r
236
274
  };
237
- this.ranges.push(o), this.activeRange = o, this.cellAnchor = { row: t, col: l };
275
+ this.ranges.push(l), this.activeRange = l, this.cellAnchor = { row: t, col: r };
238
276
  } else {
239
- const o = {
277
+ const l = {
240
278
  startRow: t,
241
- startCol: l,
279
+ startCol: r,
242
280
  endRow: t,
243
- endCol: l
281
+ endCol: r
244
282
  };
245
- this.ranges = [o], this.activeRange = o, this.cellAnchor = { row: t, col: l };
283
+ this.ranges = [l], this.activeRange = l, this.cellAnchor = { row: t, col: r };
246
284
  }
247
285
  return this.emit("selection-change", this.#e()), this.requestAfterRender(), !1;
248
286
  }
@@ -253,15 +291,15 @@ class v extends f {
253
291
  if (e.key === "Escape")
254
292
  return t === "cell" ? this.selectedCell = null : t === "row" ? (this.selected.clear(), this.anchor = null) : t === "range" && (this.ranges = [], this.activeRange = null, this.cellAnchor = null), this.emit("selection-change", this.#e()), this.requestAfterRender(), !0;
255
293
  if (t === "range" && e.key === "a" && (e.ctrlKey || e.metaKey)) {
256
- const l = this.rows.length, r = this.columns.length;
257
- if (l > 0 && r > 0) {
258
- const n = {
294
+ const r = this.rows.length, n = this.columns.length;
295
+ if (r > 0 && n > 0) {
296
+ const o = {
259
297
  startRow: 0,
260
298
  startCol: 0,
261
- endRow: l - 1,
262
- endCol: r - 1
299
+ endRow: r - 1,
300
+ endCol: n - 1
263
301
  };
264
- return this.ranges = [n], this.activeRange = n, this.emit("selection-change", this.#e()), this.requestAfterRender(), !0;
302
+ return this.ranges = [o], this.activeRange = o, this.emit("selection-change", this.#e()), this.requestAfterRender(), !0;
265
303
  }
266
304
  }
267
305
  return !1;
@@ -270,15 +308,15 @@ class v extends f {
270
308
  if (this.config.mode !== "range" || e.rowIndex === void 0 || e.colIndex === void 0 || e.rowIndex < 0 || e.originalEvent.shiftKey && this.cellAnchor)
271
309
  return;
272
310
  this.isDragging = !0;
273
- const t = e.rowIndex, l = e.colIndex;
274
- this.cellAnchor = { row: t, col: l }, e.originalEvent.ctrlKey || e.originalEvent.metaKey || (this.ranges = []);
275
- const n = {
311
+ const t = e.rowIndex, r = e.colIndex;
312
+ this.cellAnchor = { row: t, col: r }, e.originalEvent.ctrlKey || e.originalEvent.metaKey || (this.ranges = []);
313
+ const o = {
276
314
  startRow: t,
277
- startCol: l,
315
+ startCol: r,
278
316
  endRow: t,
279
- endCol: l
317
+ endCol: r
280
318
  };
281
- return this.ranges.push(n), this.activeRange = n, this.emit("selection-change", this.#e()), this.requestAfterRender(), !0;
319
+ return this.ranges.push(o), this.activeRange = o, this.emit("selection-change", this.#e()), this.requestAfterRender(), !0;
282
320
  }
283
321
  onCellMouseMove(e) {
284
322
  if (this.config.mode !== "range" || !this.isDragging || !this.cellAnchor || e.rowIndex === void 0 || e.colIndex === void 0 || e.rowIndex < 0) return;
@@ -297,29 +335,29 @@ class v extends f {
297
335
  const e = this.shadowRoot;
298
336
  if (!e) return;
299
337
  const { mode: t } = this.config;
300
- e.querySelectorAll(".cell").forEach((n) => {
301
- n.classList.remove("selected", "top", "bottom", "first", "last");
338
+ e.querySelectorAll(".cell").forEach((o) => {
339
+ o.classList.remove("selected", "top", "bottom", "first", "last");
302
340
  });
303
- const r = e.querySelectorAll(".data-grid-row");
304
- if (r.forEach((n) => {
305
- n.classList.remove("selected", "row-focus");
306
- }), t === "row" && r.forEach((n) => {
307
- const a = n.querySelector(".cell[data-row]"), i = parseInt(a?.getAttribute("data-row") ?? "-1", 10);
308
- i >= 0 && this.selected.has(i) && (n.classList.add("selected", "row-focus"), n.querySelectorAll(".cell-focus").forEach((o) => o.classList.remove("cell-focus")));
341
+ const n = e.querySelectorAll(".data-grid-row");
342
+ if (n.forEach((o) => {
343
+ o.classList.remove("selected", "row-focus");
344
+ }), t === "row" && n.forEach((o) => {
345
+ const a = o.querySelector(".cell[data-row]"), i = parseInt(a?.getAttribute("data-row") ?? "-1", 10);
346
+ i >= 0 && this.selected.has(i) && (o.classList.add("selected", "row-focus"), o.querySelectorAll(".cell-focus").forEach((l) => l.classList.remove("cell-focus")));
309
347
  }), t === "range" && this.ranges.length > 0) {
310
- const n = this.activeRange ? h(this.activeRange) : null;
348
+ const o = this.activeRange ? d(this.activeRange) : null;
311
349
  e.querySelectorAll(".cell[data-row][data-col]").forEach((i) => {
312
- const o = parseInt(i.getAttribute("data-row") ?? "-1", 10), c = parseInt(i.getAttribute("data-col") ?? "-1", 10);
313
- o >= 0 && c >= 0 && g(o, c, this.ranges) && (i.classList.add("selected"), i.classList.remove("cell-focus"), n && (o === n.startRow && i.classList.add("top"), o === n.endRow && i.classList.add("bottom"), c === n.startCol && i.classList.add("first"), c === n.endCol && i.classList.add("last")));
350
+ const l = parseInt(i.getAttribute("data-row") ?? "-1", 10), c = parseInt(i.getAttribute("data-col") ?? "-1", 10);
351
+ l >= 0 && c >= 0 && g(l, c, this.ranges) && (i.classList.add("selected"), i.classList.remove("cell-focus"), o && (l === o.startRow && i.classList.add("top"), l === o.endRow && i.classList.add("bottom"), c === o.startCol && i.classList.add("first"), c === o.endCol && i.classList.add("last")));
314
352
  });
315
353
  }
316
- t === "cell" && this.selectedCell && e.querySelectorAll(".cell-focus").forEach((n) => n.classList.remove("cell-focus"));
354
+ t === "cell" && this.selectedCell && e.querySelectorAll(".cell-focus").forEach((o) => o.classList.remove("cell-focus"));
317
355
  }
318
356
  afterRender() {
319
357
  const e = this.shadowRoot;
320
358
  if (!e) return;
321
- const t = e.children[0], { mode: l } = this.config;
322
- this.grid.setAttribute("data-selection-mode", l), t && t.classList.toggle("selecting", this.isDragging), this.#t();
359
+ const t = e.children[0], { mode: r } = this.config;
360
+ this.grid.setAttribute("data-selection-mode", r), t && t.classList.toggle("selecting", this.isDragging), this.#t();
323
361
  }
324
362
  /**
325
363
  * Called after scroll-triggered row rendering.
@@ -345,13 +383,13 @@ class v extends f {
345
383
  * Get all selected cell ranges in public format.
346
384
  */
347
385
  getRanges() {
348
- return d(this.ranges);
386
+ return h(this.ranges);
349
387
  }
350
388
  /**
351
389
  * Get all selected cells across all ranges.
352
390
  */
353
391
  getSelectedCells() {
354
- return m(this.ranges);
392
+ return b(this.ranges);
355
393
  }
356
394
  /**
357
395
  * Check if a specific cell is in range selection.
@@ -376,12 +414,12 @@ class v extends f {
376
414
  endCol: t.to.col
377
415
  })), this.activeRange = this.ranges.length > 0 ? this.ranges[this.ranges.length - 1] : null, this.emit("selection-change", {
378
416
  mode: this.config.mode,
379
- ranges: d(this.ranges)
417
+ ranges: h(this.ranges)
380
418
  }), this.requestAfterRender();
381
419
  }
382
420
  // ===== Private Helpers =====
383
421
  #e() {
384
- return b(
422
+ return A(
385
423
  this.config.mode,
386
424
  {
387
425
  selectedCell: this.selectedCell,
@@ -426,39 +464,39 @@ class v extends f {
426
464
  }
427
465
  `;
428
466
  }
429
- function p(s, e, t, l) {
430
- const r = new Set(s.selected);
431
- let n = s.anchor;
467
+ function y(s, e, t, r) {
468
+ const n = new Set(s.selected);
469
+ let o = s.anchor;
432
470
  if (t === "single")
433
- r.clear(), r.add(e), n = e;
471
+ n.clear(), n.add(e), o = e;
434
472
  else if (t === "multiple") {
435
- const a = l.ctrlKey || l.metaKey;
436
- if (l.shiftKey && s.anchor !== null) {
437
- const i = Math.min(s.anchor, e), o = Math.max(s.anchor, e);
438
- for (let c = i; c <= o; c++)
439
- r.add(c);
440
- } else a ? (r.has(e) ? r.delete(e) : r.add(e), n = e) : (r.clear(), r.add(e), n = e);
441
- }
442
- return { selected: r, lastSelected: e, anchor: n };
473
+ const a = r.ctrlKey || r.metaKey;
474
+ if (r.shiftKey && s.anchor !== null) {
475
+ const i = Math.min(s.anchor, e), l = Math.max(s.anchor, e);
476
+ for (let c = i; c <= l; c++)
477
+ n.add(c);
478
+ } else a ? (n.has(e) ? n.delete(e) : n.add(e), o = e) : (n.clear(), n.add(e), o = e);
479
+ }
480
+ return { selected: n, lastSelected: e, anchor: o };
443
481
  }
444
- function y(s) {
482
+ function S(s) {
445
483
  const e = /* @__PURE__ */ new Set();
446
484
  for (let t = 0; t < s; t++)
447
485
  e.add(t);
448
486
  return e;
449
487
  }
450
- function S(s, e) {
451
- const t = [], l = [];
452
- for (const r of e)
453
- s.has(r) || t.push(r);
454
- for (const r of s)
455
- e.has(r) || l.push(r);
456
- return { added: t, removed: l };
488
+ function I(s, e) {
489
+ const t = [], r = [];
490
+ for (const n of e)
491
+ s.has(n) || t.push(n);
492
+ for (const n of s)
493
+ e.has(n) || r.push(n);
494
+ return { added: t, removed: r };
457
495
  }
458
496
  export {
459
497
  v as SelectionPlugin,
460
- S as computeSelectionDiff,
461
- p as handleRowClick,
462
- y as selectAll
498
+ I as computeSelectionDiff,
499
+ y as handleRowClick,
500
+ S as selectAll
463
501
  };
464
502
  //# sourceMappingURL=index.js.map