@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.
- package/README.md +1 -1
- package/all.d.ts +13 -0
- package/all.js +1684 -1196
- package/all.js.map +1 -1
- package/index.d.ts +4 -163
- package/index.js +1278 -1702
- package/index.js.map +1 -1
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js +35 -78
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js +1 -1
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/index.js +8 -8
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js +160 -160
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/selection/index.js +93 -72
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +27 -78
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +28 -28
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/context-menu.umd.js +1 -52
- package/umd/plugins/context-menu.umd.js.map +1 -1
- package/umd/plugins/master-detail.umd.js +1 -1
- package/umd/plugins/master-detail.umd.js.map +1 -1
- package/umd/plugins/pinned-rows.umd.js +1 -1
- package/umd/plugins/pinned-rows.umd.js.map +1 -1
- package/umd/plugins/pivot.umd.js +1 -1
- package/umd/plugins/pivot.umd.js.map +1 -1
- package/umd/plugins/selection.umd.js +1 -1
- package/umd/plugins/selection.umd.js.map +1 -1
- 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
|
|
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
|
|
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
|
|
195
|
-
e.push({ row: r, col:
|
|
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
|
|
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
|
|
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
|
|
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((
|
|
227
|
-
from: { row:
|
|
228
|
-
to: { row:
|
|
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:
|
|
232
|
+
return s === "range" && e.ranges.length > 0 ? { mode: s, ranges: g(e.ranges) } : { mode: s, ranges: [] };
|
|
233
233
|
}
|
|
234
|
-
class
|
|
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:
|
|
261
|
-
if (
|
|
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 (
|
|
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 (
|
|
266
|
-
const
|
|
267
|
-
if (
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
} else if (
|
|
271
|
-
const
|
|
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(
|
|
277
|
+
this.ranges.push(i), this.activeRange = i, this.cellAnchor = { row: t, col: r };
|
|
278
278
|
} else {
|
|
279
|
-
const
|
|
279
|
+
const i = {
|
|
280
280
|
startRow: t,
|
|
281
281
|
startCol: r,
|
|
282
282
|
endRow: t,
|
|
283
283
|
endCol: r
|
|
284
284
|
};
|
|
285
|
-
this.ranges = [
|
|
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
|
|
297
|
-
if (
|
|
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:
|
|
302
|
-
endCol:
|
|
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
|
|
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(
|
|
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 =
|
|
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((
|
|
341
|
-
|
|
361
|
+
e.querySelectorAll(".cell").forEach((n) => {
|
|
362
|
+
n.classList.remove("selected", "top", "bottom", "first", "last");
|
|
342
363
|
});
|
|
343
|
-
const
|
|
344
|
-
if (
|
|
345
|
-
|
|
346
|
-
}), t === "row" && n.forEach((
|
|
347
|
-
const
|
|
348
|
-
|
|
349
|
-
}), t === "range" && this.ranges.length > 0) {
|
|
350
|
-
const
|
|
351
|
-
e.querySelectorAll(".cell[data-row][data-col]").forEach((
|
|
352
|
-
const
|
|
353
|
-
|
|
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((
|
|
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
|
|
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
|
|
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
|
|
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:
|
|
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 =
|
|
456
|
+
styles = b;
|
|
436
457
|
}
|
|
437
|
-
function
|
|
438
|
-
const
|
|
439
|
-
let
|
|
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
|
-
|
|
462
|
+
o.clear(), o.add(e), n = e;
|
|
442
463
|
else if (t === "multiple") {
|
|
443
|
-
const
|
|
464
|
+
const c = r.ctrlKey || r.metaKey;
|
|
444
465
|
if (r.shiftKey && s.anchor !== null) {
|
|
445
|
-
const
|
|
446
|
-
for (let
|
|
447
|
-
|
|
448
|
-
} else
|
|
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:
|
|
471
|
+
return { selected: o, lastSelected: e, anchor: n };
|
|
451
472
|
}
|
|
452
|
-
function
|
|
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
|
|
479
|
+
function K(s, e) {
|
|
459
480
|
const t = [], r = [];
|
|
460
|
-
for (const
|
|
461
|
-
s.has(
|
|
462
|
-
for (const
|
|
463
|
-
e.has(
|
|
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
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
488
|
+
v as SelectionPlugin,
|
|
489
|
+
K as computeSelectionDiff,
|
|
490
|
+
q as handleRowClick,
|
|
491
|
+
S as selectAll
|
|
471
492
|
};
|
|
472
493
|
//# sourceMappingURL=index.js.map
|