@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.
- package/README.md +50 -59
- package/all.d.ts +9 -47
- package/all.js +1853 -1366
- package/all.js.map +1 -1
- package/index.d.ts +5 -210
- package/index.js +822 -1346
- package/index.js.map +1 -1
- package/lib/plugins/clipboard/index.js +11 -5
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js +9 -4
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js +11 -5
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/export/index.js +7 -3
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/index.js +16 -149
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/index.js +13 -6
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/index.js +13 -6
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js +11 -5
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/multi-sort/index.js +13 -6
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js +11 -5
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/index.js +13 -6
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js +19 -9
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/reorder/index.js +11 -5
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/selection/index.js +61 -56
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js +11 -5
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/tree/index.js +15 -7
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.js +3 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js +13 -6
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +16 -157
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +13 -13
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/clipboard.umd.js.map +1 -1
- package/umd/plugins/column-virtualization.umd.js.map +1 -1
- package/umd/plugins/context-menu.umd.js.map +1 -1
- package/umd/plugins/export.umd.js.map +1 -1
- package/umd/plugins/filtering.umd.js +1 -142
- package/umd/plugins/filtering.umd.js.map +1 -1
- package/umd/plugins/grouping-columns.umd.js.map +1 -1
- package/umd/plugins/grouping-rows.umd.js.map +1 -1
- package/umd/plugins/master-detail.umd.js.map +1 -1
- package/umd/plugins/multi-sort.umd.js.map +1 -1
- package/umd/plugins/pinned-columns.umd.js.map +1 -1
- package/umd/plugins/pinned-rows.umd.js.map +1 -1
- package/umd/plugins/pivot.umd.js.map +1 -1
- package/umd/plugins/reorder.umd.js.map +1 -1
- package/umd/plugins/selection.umd.js +1 -1
- package/umd/plugins/selection.umd.js.map +1 -1
- package/umd/plugins/server-side.umd.js.map +1 -1
- package/umd/plugins/tree.umd.js.map +1 -1
- package/umd/plugins/undo-redo.umd.js.map +1 -1
- package/umd/plugins/visibility.umd.js.map +1 -1
- 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
|
|
195
|
-
e.push({ row: r, col:
|
|
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((
|
|
227
|
-
from: { row:
|
|
228
|
-
to: { row:
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
260
|
+
// #endregion
|
|
261
|
+
// #region Event Handlers
|
|
259
262
|
onCellClick(e) {
|
|
260
|
-
const { rowIndex: t, colIndex: r, originalEvent:
|
|
261
|
-
if (
|
|
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 (
|
|
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 (
|
|
266
|
-
const c =
|
|
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,
|
|
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" &&
|
|
298
|
+
if (t === "cell" && o)
|
|
296
299
|
return queueMicrotask(() => {
|
|
297
|
-
|
|
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
|
-
|
|
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" &&
|
|
306
|
-
const
|
|
306
|
+
if (t === "range" && o) {
|
|
307
|
+
const n = e.shiftKey;
|
|
307
308
|
return queueMicrotask(() => {
|
|
308
|
-
const c = this.grid
|
|
309
|
-
if (
|
|
310
|
-
this.cellAnchor || (this.cellAnchor = { row:
|
|
311
|
-
const
|
|
312
|
-
this.ranges = [
|
|
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:
|
|
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
|
|
320
|
-
if (
|
|
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:
|
|
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
|
|
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(
|
|
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((
|
|
364
|
-
|
|
364
|
+
e.querySelectorAll(".cell").forEach((n) => {
|
|
365
|
+
n.classList.remove("selected", "top", "bottom", "first", "last");
|
|
365
366
|
});
|
|
366
|
-
const
|
|
367
|
-
if (
|
|
368
|
-
|
|
369
|
-
}), t === "row" && (e.querySelectorAll(".cell-focus").forEach((
|
|
370
|
-
const c =
|
|
371
|
-
l >= 0 && this.selected.has(l) &&
|
|
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
|
|
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"),
|
|
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((
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
460
|
+
// #endregion
|
|
461
|
+
// #region Styles
|
|
458
462
|
styles = b;
|
|
463
|
+
// #endregion
|
|
459
464
|
}
|
|
460
465
|
function q(s, e, t, r) {
|
|
461
|
-
const
|
|
462
|
-
let
|
|
466
|
+
const o = new Set(s.selected);
|
|
467
|
+
let n = s.anchor;
|
|
463
468
|
if (t === "single")
|
|
464
|
-
|
|
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
|
-
|
|
471
|
-
} else c ? (
|
|
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:
|
|
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
|
|
484
|
-
s.has(
|
|
485
|
-
for (const
|
|
486
|
-
e.has(
|
|
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 {
|