@toolbox-web/grid 0.1.0 → 0.2.1

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 (46) hide show
  1. package/README.md +1 -1
  2. package/all.d.ts +13 -0
  3. package/all.js +1684 -1196
  4. package/all.js.map +1 -1
  5. package/index.d.ts +4 -163
  6. package/index.js +1278 -1702
  7. package/index.js.map +1 -1
  8. package/lib/plugins/clipboard/index.js.map +1 -1
  9. package/lib/plugins/column-virtualization/index.js.map +1 -1
  10. package/lib/plugins/context-menu/index.js +35 -78
  11. package/lib/plugins/context-menu/index.js.map +1 -1
  12. package/lib/plugins/export/index.js.map +1 -1
  13. package/lib/plugins/filtering/index.js.map +1 -1
  14. package/lib/plugins/grouping-columns/index.js.map +1 -1
  15. package/lib/plugins/grouping-rows/index.js.map +1 -1
  16. package/lib/plugins/master-detail/index.js +1 -1
  17. package/lib/plugins/master-detail/index.js.map +1 -1
  18. package/lib/plugins/multi-sort/index.js.map +1 -1
  19. package/lib/plugins/pinned-columns/index.js.map +1 -1
  20. package/lib/plugins/pinned-rows/index.js +8 -8
  21. package/lib/plugins/pinned-rows/index.js.map +1 -1
  22. package/lib/plugins/pivot/index.js +160 -160
  23. package/lib/plugins/pivot/index.js.map +1 -1
  24. package/lib/plugins/reorder/index.js.map +1 -1
  25. package/lib/plugins/selection/index.js +93 -72
  26. package/lib/plugins/selection/index.js.map +1 -1
  27. package/lib/plugins/server-side/index.js.map +1 -1
  28. package/lib/plugins/tree/index.js.map +1 -1
  29. package/lib/plugins/undo-redo/index.js.map +1 -1
  30. package/lib/plugins/visibility/index.js.map +1 -1
  31. package/package.json +1 -1
  32. package/umd/grid.all.umd.js +27 -78
  33. package/umd/grid.all.umd.js.map +1 -1
  34. package/umd/grid.umd.js +28 -28
  35. package/umd/grid.umd.js.map +1 -1
  36. package/umd/plugins/context-menu.umd.js +1 -52
  37. package/umd/plugins/context-menu.umd.js.map +1 -1
  38. package/umd/plugins/master-detail.umd.js +1 -1
  39. package/umd/plugins/master-detail.umd.js.map +1 -1
  40. package/umd/plugins/pinned-rows.umd.js +1 -1
  41. package/umd/plugins/pinned-rows.umd.js.map +1 -1
  42. package/umd/plugins/pivot.umd.js +1 -1
  43. package/umd/plugins/pivot.umd.js.map +1 -1
  44. package/umd/plugins/selection.umd.js +1 -1
  45. package/umd/plugins/selection.umd.js.map +1 -1
  46. package/custom-elements.json +0 -1934
@@ -178,31 +178,31 @@ function R(s) {
178
178
  to: { row: e.endRow, col: e.endCol }
179
179
  };
180
180
  }
181
- function d(s) {
181
+ function g(s) {
182
182
  return s.map(R);
183
183
  }
184
184
  function C(s, e, t) {
185
185
  const r = h(t);
186
186
  return s >= r.startRow && s <= r.endRow && e >= r.startCol && e <= r.endCol;
187
187
  }
188
- function g(s, e, t) {
188
+ function u(s, e, t) {
189
189
  return t.some((r) => C(s, e, r));
190
190
  }
191
191
  function m(s) {
192
192
  const e = [], t = h(s);
193
193
  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 });
194
+ for (let o = t.startCol; o <= t.endCol; o++)
195
+ e.push({ row: r, col: o });
196
196
  return e;
197
197
  }
198
- function b(s) {
198
+ function A(s) {
199
199
  const e = /* @__PURE__ */ new Map();
200
200
  for (const t of s)
201
201
  for (const r of m(t))
202
202
  e.set(`${r.row},${r.col}`, r);
203
203
  return [...e.values()];
204
204
  }
205
- function u(s, e) {
205
+ function d(s, e) {
206
206
  return {
207
207
  startRow: s.row,
208
208
  startCol: s.col,
@@ -210,7 +210,7 @@ function u(s, e) {
210
210
  endCol: e.col
211
211
  };
212
212
  }
213
- const A = ':host .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}:host .data-grid-row.row-focus{background-color:var(--tbw-focus-background, rgba(from var(--tbw-color-accent) r g b / 12%))}:host([data-selection-mode="row"]) .cell-focus{outline:none}:host .data-grid-row>.cell.selected{background-color:var(--tbw-range-selection-bg)}:host .data-grid-row>.cell.selected.top{border-top:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.bottom{border-bottom:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.first{border-left:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.last{border-right:2px solid var(--tbw-range-border-color)}';
213
+ const b = ':host .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}:host .data-grid-row.row-focus{background-color:var(--tbw-focus-background, rgba(from var(--tbw-color-accent) r g b / 12%))}:host([data-selection-mode="row"]) .cell-focus{outline:none}:host .data-grid-row>.cell.selected{background-color:var(--tbw-range-selection-bg)}:host .data-grid-row>.cell.selected.top{border-top:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.bottom{border-bottom:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.first{border-left:2px solid var(--tbw-range-border-color)}:host .data-grid-row>.cell.selected.last{border-right:2px solid var(--tbw-range-border-color)}';
214
214
  function p(s, e, t) {
215
215
  if (s === "cell" && e.selectedCell)
216
216
  return {
@@ -223,15 +223,15 @@ function p(s, e, t) {
223
223
  ]
224
224
  };
225
225
  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 }
226
+ const r = [...e.selected].map((o) => ({
227
+ from: { row: o, col: 0 },
228
+ to: { row: o, col: t - 1 }
229
229
  }));
230
230
  return { mode: s, ranges: r };
231
231
  }
232
- return s === "range" && e.ranges.length > 0 ? { mode: s, ranges: d(e.ranges) } : { mode: s, ranges: [] };
232
+ return s === "range" && e.ranges.length > 0 ? { mode: s, ranges: g(e.ranges) } : { mode: s, ranges: [] };
233
233
  }
234
- class y extends w {
234
+ class v extends w {
235
235
  name = "selection";
236
236
  version = "1.0.0";
237
237
  get defaultConfig() {
@@ -257,49 +257,70 @@ class y extends w {
257
257
  }
258
258
  // ===== Event Handlers =====
259
259
  onCellClick(e) {
260
- const { rowIndex: t, colIndex: r, originalEvent: n } = e, { mode: l } = this.config;
261
- if (l === "cell")
260
+ const { rowIndex: t, colIndex: r, originalEvent: o } = e, { mode: n } = this.config;
261
+ if (n === "cell")
262
262
  return this.selectedCell = { row: t, col: r }, this.emit("selection-change", this.#e()), this.requestAfterRender(), !1;
263
- if (l === "row")
263
+ if (n === "row")
264
264
  return this.selected.clear(), this.selected.add(t), this.lastSelected = t, this.emit("selection-change", this.#e()), this.requestAfterRender(), !1;
265
- if (l === "range") {
266
- const a = n.shiftKey, i = n.ctrlKey || n.metaKey;
267
- if (a && this.cellAnchor) {
268
- const o = u(this.cellAnchor, { row: t, col: r });
269
- i ? this.ranges.length > 0 ? this.ranges[this.ranges.length - 1] = o : this.ranges.push(o) : this.ranges = [o], this.activeRange = o;
270
- } else if (i) {
271
- const o = {
265
+ if (n === "range") {
266
+ const c = o.shiftKey, l = o.ctrlKey || o.metaKey;
267
+ if (c && this.cellAnchor) {
268
+ const i = d(this.cellAnchor, { row: t, col: r });
269
+ l ? this.ranges.length > 0 ? this.ranges[this.ranges.length - 1] = i : this.ranges.push(i) : this.ranges = [i], this.activeRange = i;
270
+ } else if (l) {
271
+ const i = {
272
272
  startRow: t,
273
273
  startCol: r,
274
274
  endRow: t,
275
275
  endCol: r
276
276
  };
277
- this.ranges.push(o), this.activeRange = o, this.cellAnchor = { row: t, col: r };
277
+ this.ranges.push(i), this.activeRange = i, this.cellAnchor = { row: t, col: r };
278
278
  } else {
279
- const o = {
279
+ const i = {
280
280
  startRow: t,
281
281
  startCol: r,
282
282
  endRow: t,
283
283
  endCol: r
284
284
  };
285
- this.ranges = [o], this.activeRange = o, this.cellAnchor = { row: t, col: r };
285
+ this.ranges = [i], this.activeRange = i, this.cellAnchor = { row: t, col: r };
286
286
  }
287
287
  return this.emit("selection-change", this.#e()), this.requestAfterRender(), !1;
288
288
  }
289
289
  return !1;
290
290
  }
291
291
  onKeyDown(e) {
292
- const { mode: t } = this.config;
292
+ const { mode: t } = this.config, o = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Tab", "Home", "End", "PageUp", "PageDown"].includes(e.key);
293
293
  if (e.key === "Escape")
294
294
  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" && o)
296
+ return queueMicrotask(() => {
297
+ this.selectedCell = { row: this.grid.focusRow, col: this.grid.focusCol }, this.emit("selection-change", this.#e()), this.requestAfterRender();
298
+ }), !1;
299
+ if (t === "row" && (e.key === "ArrowUp" || e.key === "ArrowDown"))
300
+ return queueMicrotask(() => {
301
+ this.selected.clear(), this.selected.add(this.grid.focusRow), this.lastSelected = this.grid.focusRow, this.emit("selection-change", this.#e()), this.requestAfterRender();
302
+ }), !1;
303
+ if (t === "range" && o) {
304
+ const n = e.shiftKey;
305
+ return queueMicrotask(() => {
306
+ const c = this.grid.focusRow, l = this.grid.focusCol;
307
+ if (n) {
308
+ this.cellAnchor || (this.cellAnchor = { row: c, col: l });
309
+ const i = d(this.cellAnchor, { row: c, col: l });
310
+ this.ranges = [i], this.activeRange = i;
311
+ } else
312
+ this.ranges = [], this.activeRange = null, this.cellAnchor = { row: c, col: l };
313
+ this.emit("selection-change", this.#e()), this.requestAfterRender();
314
+ }), !1;
315
+ }
295
316
  if (t === "range" && e.key === "a" && (e.ctrlKey || e.metaKey)) {
296
- const r = this.rows.length, n = this.columns.length;
297
- if (r > 0 && n > 0) {
317
+ const n = this.rows.length, c = this.columns.length;
318
+ if (n > 0 && c > 0) {
298
319
  const l = {
299
320
  startRow: 0,
300
321
  startCol: 0,
301
- endRow: r - 1,
302
- endCol: n - 1
322
+ endRow: n - 1,
323
+ endCol: c - 1
303
324
  };
304
325
  return this.ranges = [l], this.activeRange = l, this.emit("selection-change", this.#e()), this.requestAfterRender(), !0;
305
326
  }
@@ -312,17 +333,17 @@ class y extends w {
312
333
  this.isDragging = !0;
313
334
  const t = e.rowIndex, r = e.colIndex;
314
335
  this.cellAnchor = { row: t, col: r }, e.originalEvent.ctrlKey || e.originalEvent.metaKey || (this.ranges = []);
315
- const l = {
336
+ const n = {
316
337
  startRow: t,
317
338
  startCol: r,
318
339
  endRow: t,
319
340
  endCol: r
320
341
  };
321
- return this.ranges.push(l), this.activeRange = l, this.emit("selection-change", this.#e()), this.requestAfterRender(), !0;
342
+ return this.ranges.push(n), this.activeRange = n, this.emit("selection-change", this.#e()), this.requestAfterRender(), !0;
322
343
  }
323
344
  onCellMouseMove(e) {
324
345
  if (this.config.mode !== "range" || !this.isDragging || !this.cellAnchor || e.rowIndex === void 0 || e.colIndex === void 0 || e.rowIndex < 0) return;
325
- const t = u(this.cellAnchor, { row: e.rowIndex, col: e.colIndex });
346
+ const t = d(this.cellAnchor, { row: e.rowIndex, col: e.colIndex });
326
347
  return this.ranges.length > 0 ? this.ranges[this.ranges.length - 1] = t : this.ranges.push(t), this.activeRange = t, this.emit("selection-change", this.#e()), this.requestAfterRender(), !0;
327
348
  }
328
349
  onCellMouseUp(e) {
@@ -337,23 +358,23 @@ class y extends w {
337
358
  const e = this.shadowRoot;
338
359
  if (!e) return;
339
360
  const { mode: t } = this.config;
340
- e.querySelectorAll(".cell").forEach((l) => {
341
- l.classList.remove("selected", "top", "bottom", "first", "last");
361
+ e.querySelectorAll(".cell").forEach((n) => {
362
+ n.classList.remove("selected", "top", "bottom", "first", "last");
342
363
  });
343
- const n = e.querySelectorAll(".data-grid-row");
344
- if (n.forEach((l) => {
345
- l.classList.remove("selected", "row-focus");
346
- }), t === "row" && n.forEach((l) => {
347
- const a = l.querySelector(".cell[data-row]"), i = parseInt(a?.getAttribute("data-row") ?? "-1", 10);
348
- i >= 0 && this.selected.has(i) && (l.classList.add("selected", "row-focus"), l.querySelectorAll(".cell-focus").forEach((o) => o.classList.remove("cell-focus")));
349
- }), t === "range" && this.ranges.length > 0) {
350
- const l = this.activeRange ? h(this.activeRange) : null;
351
- e.querySelectorAll(".cell[data-row][data-col]").forEach((i) => {
352
- const o = parseInt(i.getAttribute("data-row") ?? "-1", 10), c = parseInt(i.getAttribute("data-col") ?? "-1", 10);
353
- o >= 0 && c >= 0 && g(o, c, this.ranges) && (i.classList.add("selected"), i.classList.remove("cell-focus"), l && (o === l.startRow && i.classList.add("top"), o === l.endRow && i.classList.add("bottom"), c === l.startCol && i.classList.add("first"), c === l.endCol && i.classList.add("last")));
364
+ const o = e.querySelectorAll(".data-grid-row");
365
+ if (o.forEach((n) => {
366
+ n.classList.remove("selected", "row-focus");
367
+ }), t === "row" && (e.querySelectorAll(".cell-focus").forEach((n) => n.classList.remove("cell-focus")), o.forEach((n) => {
368
+ const c = n.querySelector(".cell[data-row]"), l = parseInt(c?.getAttribute("data-row") ?? "-1", 10);
369
+ l >= 0 && this.selected.has(l) && n.classList.add("selected", "row-focus");
370
+ })), t === "range" && this.ranges.length > 0) {
371
+ const n = this.activeRange ? h(this.activeRange) : null;
372
+ e.querySelectorAll(".cell[data-row][data-col]").forEach((l) => {
373
+ const i = parseInt(l.getAttribute("data-row") ?? "-1", 10), a = parseInt(l.getAttribute("data-col") ?? "-1", 10);
374
+ 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")));
354
375
  });
355
376
  }
356
- t === "cell" && this.selectedCell && e.querySelectorAll(".cell-focus").forEach((l) => l.classList.remove("cell-focus"));
377
+ t === "cell" && this.selectedCell && e.querySelectorAll(".cell-focus").forEach((n) => n.classList.remove("cell-focus"));
357
378
  }
358
379
  afterRender() {
359
380
  const e = this.shadowRoot;
@@ -385,19 +406,19 @@ class y extends w {
385
406
  * Get all selected cell ranges in public format.
386
407
  */
387
408
  getRanges() {
388
- return d(this.ranges);
409
+ return g(this.ranges);
389
410
  }
390
411
  /**
391
412
  * Get all selected cells across all ranges.
392
413
  */
393
414
  getSelectedCells() {
394
- return b(this.ranges);
415
+ return A(this.ranges);
395
416
  }
396
417
  /**
397
418
  * Check if a specific cell is in range selection.
398
419
  */
399
420
  isCellSelected(e, t) {
400
- return g(e, t, this.ranges);
421
+ return u(e, t, this.ranges);
401
422
  }
402
423
  /**
403
424
  * Clear all selection.
@@ -416,7 +437,7 @@ class y extends w {
416
437
  endCol: t.to.col
417
438
  })), this.activeRange = this.ranges.length > 0 ? this.ranges[this.ranges.length - 1] : null, this.emit("selection-change", {
418
439
  mode: this.config.mode,
419
- ranges: d(this.ranges)
440
+ ranges: g(this.ranges)
420
441
  }), this.requestAfterRender();
421
442
  }
422
443
  // ===== Private Helpers =====
@@ -432,41 +453,41 @@ class y extends w {
432
453
  );
433
454
  }
434
455
  // ===== Styles =====
435
- styles = A;
456
+ styles = b;
436
457
  }
437
- function S(s, e, t, r) {
438
- const n = new Set(s.selected);
439
- let l = s.anchor;
458
+ function q(s, e, t, r) {
459
+ const o = new Set(s.selected);
460
+ let n = s.anchor;
440
461
  if (t === "single")
441
- n.clear(), n.add(e), l = e;
462
+ o.clear(), o.add(e), n = e;
442
463
  else if (t === "multiple") {
443
- const a = r.ctrlKey || r.metaKey;
464
+ const c = r.ctrlKey || r.metaKey;
444
465
  if (r.shiftKey && s.anchor !== null) {
445
- const i = Math.min(s.anchor, e), o = Math.max(s.anchor, e);
446
- for (let c = i; c <= o; c++)
447
- n.add(c);
448
- } else a ? (n.has(e) ? n.delete(e) : n.add(e), l = e) : (n.clear(), n.add(e), l = e);
466
+ const l = Math.min(s.anchor, e), i = Math.max(s.anchor, e);
467
+ for (let a = l; a <= i; a++)
468
+ o.add(a);
469
+ } else c ? (o.has(e) ? o.delete(e) : o.add(e), n = e) : (o.clear(), o.add(e), n = e);
449
470
  }
450
- return { selected: n, lastSelected: e, anchor: l };
471
+ return { selected: o, lastSelected: e, anchor: n };
451
472
  }
452
- function I(s) {
473
+ function S(s) {
453
474
  const e = /* @__PURE__ */ new Set();
454
475
  for (let t = 0; t < s; t++)
455
476
  e.add(t);
456
477
  return e;
457
478
  }
458
- function q(s, e) {
479
+ function K(s, e) {
459
480
  const t = [], r = [];
460
- for (const n of e)
461
- s.has(n) || t.push(n);
462
- for (const n of s)
463
- e.has(n) || r.push(n);
481
+ for (const o of e)
482
+ s.has(o) || t.push(o);
483
+ for (const o of s)
484
+ e.has(o) || r.push(o);
464
485
  return { added: t, removed: r };
465
486
  }
466
487
  export {
467
- y as SelectionPlugin,
468
- q as computeSelectionDiff,
469
- S as handleRowClick,
470
- I as selectAll
488
+ v as SelectionPlugin,
489
+ K as computeSelectionDiff,
490
+ q as handleRowClick,
491
+ S as selectAll
471
492
  };
472
493
  //# sourceMappingURL=index.js.map