@toolbox-web/grid 0.1.1 → 0.2.2

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 (69) hide show
  1. package/README.md +50 -59
  2. package/all.d.ts +9 -47
  3. package/all.js +1853 -1366
  4. package/all.js.map +1 -1
  5. package/index.d.ts +5 -210
  6. package/index.js +822 -1346
  7. package/index.js.map +1 -1
  8. package/lib/plugins/clipboard/index.js +11 -5
  9. package/lib/plugins/clipboard/index.js.map +1 -1
  10. package/lib/plugins/column-virtualization/index.js +9 -4
  11. package/lib/plugins/column-virtualization/index.js.map +1 -1
  12. package/lib/plugins/context-menu/index.js +11 -5
  13. package/lib/plugins/context-menu/index.js.map +1 -1
  14. package/lib/plugins/export/index.js +7 -3
  15. package/lib/plugins/export/index.js.map +1 -1
  16. package/lib/plugins/filtering/index.js +16 -149
  17. package/lib/plugins/filtering/index.js.map +1 -1
  18. package/lib/plugins/grouping-columns/index.js +13 -6
  19. package/lib/plugins/grouping-columns/index.js.map +1 -1
  20. package/lib/plugins/grouping-rows/index.js +13 -6
  21. package/lib/plugins/grouping-rows/index.js.map +1 -1
  22. package/lib/plugins/master-detail/index.js +11 -5
  23. package/lib/plugins/master-detail/index.js.map +1 -1
  24. package/lib/plugins/multi-sort/index.js +13 -6
  25. package/lib/plugins/multi-sort/index.js.map +1 -1
  26. package/lib/plugins/pinned-columns/index.js +11 -5
  27. package/lib/plugins/pinned-columns/index.js.map +1 -1
  28. package/lib/plugins/pinned-rows/index.js +13 -6
  29. package/lib/plugins/pinned-rows/index.js.map +1 -1
  30. package/lib/plugins/pivot/index.js +19 -9
  31. package/lib/plugins/pivot/index.js.map +1 -1
  32. package/lib/plugins/reorder/index.js +11 -5
  33. package/lib/plugins/reorder/index.js.map +1 -1
  34. package/lib/plugins/selection/index.js +61 -56
  35. package/lib/plugins/selection/index.js.map +1 -1
  36. package/lib/plugins/server-side/index.js +11 -5
  37. package/lib/plugins/server-side/index.js.map +1 -1
  38. package/lib/plugins/tree/index.js +15 -7
  39. package/lib/plugins/tree/index.js.map +1 -1
  40. package/lib/plugins/undo-redo/index.js +3 -1
  41. package/lib/plugins/undo-redo/index.js.map +1 -1
  42. package/lib/plugins/visibility/index.js +13 -6
  43. package/lib/plugins/visibility/index.js.map +1 -1
  44. package/package.json +1 -1
  45. package/umd/grid.all.umd.js +16 -157
  46. package/umd/grid.all.umd.js.map +1 -1
  47. package/umd/grid.umd.js +13 -13
  48. package/umd/grid.umd.js.map +1 -1
  49. package/umd/plugins/clipboard.umd.js.map +1 -1
  50. package/umd/plugins/column-virtualization.umd.js.map +1 -1
  51. package/umd/plugins/context-menu.umd.js.map +1 -1
  52. package/umd/plugins/export.umd.js.map +1 -1
  53. package/umd/plugins/filtering.umd.js +1 -142
  54. package/umd/plugins/filtering.umd.js.map +1 -1
  55. package/umd/plugins/grouping-columns.umd.js.map +1 -1
  56. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  57. package/umd/plugins/master-detail.umd.js.map +1 -1
  58. package/umd/plugins/multi-sort.umd.js.map +1 -1
  59. package/umd/plugins/pinned-columns.umd.js.map +1 -1
  60. package/umd/plugins/pinned-rows.umd.js.map +1 -1
  61. package/umd/plugins/pivot.umd.js.map +1 -1
  62. package/umd/plugins/reorder.umd.js.map +1 -1
  63. package/umd/plugins/selection.umd.js +1 -1
  64. package/umd/plugins/selection.umd.js.map +1 -1
  65. package/umd/plugins/server-side.umd.js.map +1 -1
  66. package/umd/plugins/tree.umd.js.map +1 -1
  67. package/umd/plugins/undo-redo.umd.js.map +1 -1
  68. package/umd/plugins/visibility.umd.js.map +1 -1
  69. package/custom-elements.json +0 -1934
@@ -162,6 +162,7 @@ class w {
162
162
  warn(e) {
163
163
  console.warn(`[tbw-grid:${this.name}] ${e}`);
164
164
  }
165
+ // #endregion
165
166
  }
166
167
  function h(s) {
167
168
  return {
@@ -191,8 +192,8 @@ function u(s, e, t) {
191
192
  function m(s) {
192
193
  const e = [], t = h(s);
193
194
  for (let r = t.startRow; r <= t.endRow; r++)
194
- for (let n = t.startCol; n <= t.endCol; n++)
195
- e.push({ row: r, col: n });
195
+ for (let o = t.startCol; o <= t.endCol; o++)
196
+ e.push({ row: r, col: o });
196
197
  return e;
197
198
  }
198
199
  function A(s) {
@@ -223,9 +224,9 @@ function p(s, e, t) {
223
224
  ]
224
225
  };
225
226
  if (s === "row" && e.selected.size > 0) {
226
- const r = [...e.selected].map((n) => ({
227
- from: { row: n, col: 0 },
228
- to: { row: n, col: t - 1 }
227
+ const r = [...e.selected].map((o) => ({
228
+ from: { row: o, col: 0 },
229
+ to: { row: o, col: t - 1 }
229
230
  }));
230
231
  return { mode: s, ranges: r };
231
232
  }
@@ -239,7 +240,7 @@ class v extends w {
239
240
  mode: "cell"
240
241
  };
241
242
  }
242
- // ===== Internal State =====
243
+ // #region Internal State
243
244
  /** Row selection state (row mode) */
244
245
  selected = /* @__PURE__ */ new Set();
245
246
  lastSelected = null;
@@ -251,19 +252,21 @@ class v extends w {
251
252
  isDragging = !1;
252
253
  /** Cell selection state (cell mode) */
253
254
  selectedCell = null;
254
- // ===== Lifecycle =====
255
+ // #endregion
256
+ // #region Lifecycle
255
257
  detach() {
256
258
  this.selected.clear(), this.ranges = [], this.activeRange = null, this.cellAnchor = null, this.isDragging = !1, this.selectedCell = null;
257
259
  }
258
- // ===== Event Handlers =====
260
+ // #endregion
261
+ // #region Event Handlers
259
262
  onCellClick(e) {
260
- const { rowIndex: t, colIndex: r, originalEvent: n } = e, { mode: o } = this.config;
261
- if (o === "cell")
263
+ const { rowIndex: t, colIndex: r, originalEvent: o } = e, { mode: n } = this.config;
264
+ if (n === "cell")
262
265
  return this.selectedCell = { row: t, col: r }, this.emit("selection-change", this.#e()), this.requestAfterRender(), !1;
263
- if (o === "row")
266
+ if (n === "row")
264
267
  return this.selected.clear(), this.selected.add(t), this.lastSelected = t, this.emit("selection-change", this.#e()), this.requestAfterRender(), !1;
265
- if (o === "range") {
266
- const c = n.shiftKey, l = n.ctrlKey || n.metaKey;
268
+ if (n === "range") {
269
+ const c = o.shiftKey, l = o.ctrlKey || o.metaKey;
267
270
  if (c && this.cellAnchor) {
268
271
  const i = d(this.cellAnchor, { row: t, col: r });
269
272
  l ? this.ranges.length > 0 ? this.ranges[this.ranges.length - 1] = i : this.ranges.push(i) : this.ranges = [i], this.activeRange = i;
@@ -289,39 +292,37 @@ class v extends w {
289
292
  return !1;
290
293
  }
291
294
  onKeyDown(e) {
292
- const { mode: t } = this.config, n = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Tab", "Home", "End", "PageUp", "PageDown"].includes(e.key);
295
+ const { mode: t } = this.config, o = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Tab", "Home", "End", "PageUp", "PageDown"].includes(e.key);
293
296
  if (e.key === "Escape")
294
297
  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;
295
- if (t === "cell" && n)
298
+ if (t === "cell" && o)
296
299
  return queueMicrotask(() => {
297
- const o = this.grid;
298
- this.selectedCell = { row: o.focusRow, col: o.focusCol }, this.emit("selection-change", this.#e()), this.requestAfterRender();
300
+ this.selectedCell = { row: this.grid.focusRow, col: this.grid.focusCol }, this.emit("selection-change", this.#e()), this.requestAfterRender();
299
301
  }), !1;
300
302
  if (t === "row" && (e.key === "ArrowUp" || e.key === "ArrowDown"))
301
303
  return queueMicrotask(() => {
302
- const o = this.grid;
303
- this.selected.clear(), this.selected.add(o.focusRow), this.lastSelected = o.focusRow, this.emit("selection-change", this.#e()), this.requestAfterRender();
304
+ this.selected.clear(), this.selected.add(this.grid.focusRow), this.lastSelected = this.grid.focusRow, this.emit("selection-change", this.#e()), this.requestAfterRender();
304
305
  }), !1;
305
- if (t === "range" && n) {
306
- const o = e.shiftKey;
306
+ if (t === "range" && o) {
307
+ const n = e.shiftKey;
307
308
  return queueMicrotask(() => {
308
- const c = this.grid, l = c.focusRow, i = c.focusCol;
309
- if (o) {
310
- this.cellAnchor || (this.cellAnchor = { row: l, col: i });
311
- const a = d(this.cellAnchor, { row: l, col: i });
312
- this.ranges = [a], this.activeRange = a;
309
+ const c = this.grid.focusRow, l = this.grid.focusCol;
310
+ if (n) {
311
+ this.cellAnchor || (this.cellAnchor = { row: c, col: l });
312
+ const i = d(this.cellAnchor, { row: c, col: l });
313
+ this.ranges = [i], this.activeRange = i;
313
314
  } else
314
- this.ranges = [], this.activeRange = null, this.cellAnchor = { row: l, col: i };
315
+ this.ranges = [], this.activeRange = null, this.cellAnchor = { row: c, col: l };
315
316
  this.emit("selection-change", this.#e()), this.requestAfterRender();
316
317
  }), !1;
317
318
  }
318
319
  if (t === "range" && e.key === "a" && (e.ctrlKey || e.metaKey)) {
319
- const o = this.rows.length, c = this.columns.length;
320
- if (o > 0 && c > 0) {
320
+ const n = this.rows.length, c = this.columns.length;
321
+ if (n > 0 && c > 0) {
321
322
  const l = {
322
323
  startRow: 0,
323
324
  startCol: 0,
324
- endRow: o - 1,
325
+ endRow: n - 1,
325
326
  endCol: c - 1
326
327
  };
327
328
  return this.ranges = [l], this.activeRange = l, this.emit("selection-change", this.#e()), this.requestAfterRender(), !0;
@@ -335,13 +336,13 @@ class v extends w {
335
336
  this.isDragging = !0;
336
337
  const t = e.rowIndex, r = e.colIndex;
337
338
  this.cellAnchor = { row: t, col: r }, e.originalEvent.ctrlKey || e.originalEvent.metaKey || (this.ranges = []);
338
- const o = {
339
+ const n = {
339
340
  startRow: t,
340
341
  startCol: r,
341
342
  endRow: t,
342
343
  endCol: r
343
344
  };
344
- return this.ranges.push(o), this.activeRange = o, this.emit("selection-change", this.#e()), this.requestAfterRender(), !0;
345
+ return this.ranges.push(n), this.activeRange = n, this.emit("selection-change", this.#e()), this.requestAfterRender(), !0;
345
346
  }
346
347
  onCellMouseMove(e) {
347
348
  if (this.config.mode !== "range" || !this.isDragging || !this.cellAnchor || e.rowIndex === void 0 || e.colIndex === void 0 || e.rowIndex < 0) return;
@@ -360,23 +361,23 @@ class v extends w {
360
361
  const e = this.shadowRoot;
361
362
  if (!e) return;
362
363
  const { mode: t } = this.config;
363
- e.querySelectorAll(".cell").forEach((o) => {
364
- o.classList.remove("selected", "top", "bottom", "first", "last");
364
+ e.querySelectorAll(".cell").forEach((n) => {
365
+ n.classList.remove("selected", "top", "bottom", "first", "last");
365
366
  });
366
- const n = e.querySelectorAll(".data-grid-row");
367
- if (n.forEach((o) => {
368
- o.classList.remove("selected", "row-focus");
369
- }), t === "row" && (e.querySelectorAll(".cell-focus").forEach((o) => o.classList.remove("cell-focus")), n.forEach((o) => {
370
- const c = o.querySelector(".cell[data-row]"), l = parseInt(c?.getAttribute("data-row") ?? "-1", 10);
371
- l >= 0 && this.selected.has(l) && o.classList.add("selected", "row-focus");
367
+ const o = e.querySelectorAll(".data-grid-row");
368
+ if (o.forEach((n) => {
369
+ n.classList.remove("selected", "row-focus");
370
+ }), t === "row" && (e.querySelectorAll(".cell-focus").forEach((n) => n.classList.remove("cell-focus")), o.forEach((n) => {
371
+ const c = n.querySelector(".cell[data-row]"), l = parseInt(c?.getAttribute("data-row") ?? "-1", 10);
372
+ l >= 0 && this.selected.has(l) && n.classList.add("selected", "row-focus");
372
373
  })), t === "range" && this.ranges.length > 0) {
373
- const o = this.activeRange ? h(this.activeRange) : null;
374
+ const n = this.activeRange ? h(this.activeRange) : null;
374
375
  e.querySelectorAll(".cell[data-row][data-col]").forEach((l) => {
375
376
  const i = parseInt(l.getAttribute("data-row") ?? "-1", 10), a = parseInt(l.getAttribute("data-col") ?? "-1", 10);
376
- i >= 0 && a >= 0 && u(i, a, this.ranges) && (l.classList.add("selected"), l.classList.remove("cell-focus"), o && (i === o.startRow && l.classList.add("top"), i === o.endRow && l.classList.add("bottom"), a === o.startCol && l.classList.add("first"), a === o.endCol && l.classList.add("last")));
377
+ i >= 0 && a >= 0 && u(i, a, this.ranges) && (l.classList.add("selected"), l.classList.remove("cell-focus"), n && (i === n.startRow && l.classList.add("top"), i === n.endRow && l.classList.add("bottom"), a === n.startCol && l.classList.add("first"), a === n.endCol && l.classList.add("last")));
377
378
  });
378
379
  }
379
- t === "cell" && this.selectedCell && e.querySelectorAll(".cell-focus").forEach((o) => o.classList.remove("cell-focus"));
380
+ t === "cell" && this.selectedCell && e.querySelectorAll(".cell-focus").forEach((n) => n.classList.remove("cell-focus"));
380
381
  }
381
382
  afterRender() {
382
383
  const e = this.shadowRoot;
@@ -391,7 +392,8 @@ class v extends w {
391
392
  onScrollRender() {
392
393
  this.#t();
393
394
  }
394
- // ===== Public API =====
395
+ // #endregion
396
+ // #region Public API
395
397
  /**
396
398
  * Get the selected cell (cell mode only).
397
399
  */
@@ -442,7 +444,8 @@ class v extends w {
442
444
  ranges: g(this.ranges)
443
445
  }), this.requestAfterRender();
444
446
  }
445
- // ===== Private Helpers =====
447
+ // #endregion
448
+ // #region Private Helpers
446
449
  #e() {
447
450
  return p(
448
451
  this.config.mode,
@@ -454,23 +457,25 @@ class v extends w {
454
457
  this.columns.length
455
458
  );
456
459
  }
457
- // ===== Styles =====
460
+ // #endregion
461
+ // #region Styles
458
462
  styles = b;
463
+ // #endregion
459
464
  }
460
465
  function q(s, e, t, r) {
461
- const n = new Set(s.selected);
462
- let o = s.anchor;
466
+ const o = new Set(s.selected);
467
+ let n = s.anchor;
463
468
  if (t === "single")
464
- n.clear(), n.add(e), o = e;
469
+ o.clear(), o.add(e), n = e;
465
470
  else if (t === "multiple") {
466
471
  const c = r.ctrlKey || r.metaKey;
467
472
  if (r.shiftKey && s.anchor !== null) {
468
473
  const l = Math.min(s.anchor, e), i = Math.max(s.anchor, e);
469
474
  for (let a = l; a <= i; a++)
470
- n.add(a);
471
- } else c ? (n.has(e) ? n.delete(e) : n.add(e), o = e) : (n.clear(), n.add(e), o = e);
475
+ o.add(a);
476
+ } else c ? (o.has(e) ? o.delete(e) : o.add(e), n = e) : (o.clear(), o.add(e), n = e);
472
477
  }
473
- return { selected: n, lastSelected: e, anchor: o };
478
+ return { selected: o, lastSelected: e, anchor: n };
474
479
  }
475
480
  function S(s) {
476
481
  const e = /* @__PURE__ */ new Set();
@@ -480,10 +485,10 @@ function S(s) {
480
485
  }
481
486
  function K(s, e) {
482
487
  const t = [], r = [];
483
- for (const n of e)
484
- s.has(n) || t.push(n);
485
- for (const n of s)
486
- e.has(n) || r.push(n);
488
+ for (const o of e)
489
+ s.has(o) || t.push(o);
490
+ for (const o of s)
491
+ e.has(o) || r.push(o);
487
492
  return { added: t, removed: r };
488
493
  }
489
494
  export {