@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.
- package/README.md +43 -0
- package/all.d.ts +1680 -129
- package/all.js +440 -340
- package/all.js.map +1 -1
- package/custom-elements.json +1852 -0
- package/index.d.ts +133 -1
- package/index.js +726 -637
- package/index.js.map +1 -1
- package/lib/plugins/clipboard/index.js +62 -24
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js +82 -44
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js +141 -93
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/export/index.js +47 -9
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/index.js +89 -51
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/index.js +71 -33
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/index.js +91 -55
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js +176 -54
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/multi-sort/index.js +83 -45
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js +54 -16
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/index.js +45 -7
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js +97 -59
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/reorder/index.js +71 -33
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/selection/index.js +132 -94
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js +76 -38
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/tree/index.js +76 -38
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.js +50 -12
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js +62 -24
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +31 -31
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +14 -14
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/context-menu.umd.js +2 -2
- package/umd/plugins/context-menu.umd.js.map +1 -1
- package/umd/plugins/grouping-rows.umd.js +2 -2
- package/umd/plugins/grouping-rows.umd.js.map +1 -1
- package/umd/plugins/master-detail.umd.js +2 -2
- package/umd/plugins/master-detail.umd.js.map +1 -1
- package/umd/plugins/multi-sort.umd.js +1 -1
- package/umd/plugins/multi-sort.umd.js.map +1 -1
- package/umd/plugins/tree.umd.js +2 -2
- package/umd/plugins/tree.umd.js.map +1 -1
- package/umd/plugins/visibility.umd.js +1 -1
- package/umd/plugins/visibility.umd.js.map +1 -1
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
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
|
|
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
|
|
136
|
-
const e =
|
|
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
|
|
143
|
-
return s.map(
|
|
180
|
+
function h(s) {
|
|
181
|
+
return s.map(R);
|
|
144
182
|
}
|
|
145
|
-
function
|
|
146
|
-
const
|
|
147
|
-
return s >=
|
|
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((
|
|
188
|
+
return t.some((r) => C(s, e, r));
|
|
151
189
|
}
|
|
152
|
-
function
|
|
153
|
-
const e = [], t =
|
|
154
|
-
for (let
|
|
155
|
-
for (let
|
|
156
|
-
e.push({ row:
|
|
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
|
|
197
|
+
function b(s) {
|
|
160
198
|
const e = /* @__PURE__ */ new Map();
|
|
161
199
|
for (const t of s)
|
|
162
|
-
for (const
|
|
163
|
-
e.set(`${
|
|
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
|
|
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
|
|
187
|
-
from: { row:
|
|
188
|
-
to: { row:
|
|
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:
|
|
228
|
+
return { mode: s, ranges: r };
|
|
191
229
|
}
|
|
192
|
-
return s === "range" && e.ranges.length > 0 ? { 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
|
|
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:
|
|
221
|
-
if (
|
|
222
|
-
return this.selectedCell = { row: t, col:
|
|
223
|
-
if (
|
|
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 (
|
|
226
|
-
const a =
|
|
263
|
+
if (o === "range") {
|
|
264
|
+
const a = n.shiftKey, i = n.ctrlKey || n.metaKey;
|
|
227
265
|
if (a && this.cellAnchor) {
|
|
228
|
-
const
|
|
229
|
-
i ? this.ranges.length > 0 ? this.ranges[this.ranges.length - 1] =
|
|
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
|
|
269
|
+
const l = {
|
|
232
270
|
startRow: t,
|
|
233
|
-
startCol:
|
|
271
|
+
startCol: r,
|
|
234
272
|
endRow: t,
|
|
235
|
-
endCol:
|
|
273
|
+
endCol: r
|
|
236
274
|
};
|
|
237
|
-
this.ranges.push(
|
|
275
|
+
this.ranges.push(l), this.activeRange = l, this.cellAnchor = { row: t, col: r };
|
|
238
276
|
} else {
|
|
239
|
-
const
|
|
277
|
+
const l = {
|
|
240
278
|
startRow: t,
|
|
241
|
-
startCol:
|
|
279
|
+
startCol: r,
|
|
242
280
|
endRow: t,
|
|
243
|
-
endCol:
|
|
281
|
+
endCol: r
|
|
244
282
|
};
|
|
245
|
-
this.ranges = [
|
|
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
|
|
257
|
-
if (
|
|
258
|
-
const
|
|
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:
|
|
262
|
-
endCol:
|
|
299
|
+
endRow: r - 1,
|
|
300
|
+
endCol: n - 1
|
|
263
301
|
};
|
|
264
|
-
return this.ranges = [
|
|
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,
|
|
274
|
-
this.cellAnchor = { row: t, col:
|
|
275
|
-
const
|
|
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:
|
|
315
|
+
startCol: r,
|
|
278
316
|
endRow: t,
|
|
279
|
-
endCol:
|
|
317
|
+
endCol: r
|
|
280
318
|
};
|
|
281
|
-
return this.ranges.push(
|
|
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((
|
|
301
|
-
|
|
338
|
+
e.querySelectorAll(".cell").forEach((o) => {
|
|
339
|
+
o.classList.remove("selected", "top", "bottom", "first", "last");
|
|
302
340
|
});
|
|
303
|
-
const
|
|
304
|
-
if (
|
|
305
|
-
|
|
306
|
-
}), t === "row" &&
|
|
307
|
-
const a =
|
|
308
|
-
i >= 0 && this.selected.has(i) && (
|
|
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
|
|
348
|
+
const o = this.activeRange ? d(this.activeRange) : null;
|
|
311
349
|
e.querySelectorAll(".cell[data-row][data-col]").forEach((i) => {
|
|
312
|
-
const
|
|
313
|
-
|
|
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((
|
|
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:
|
|
322
|
-
this.grid.setAttribute("data-selection-mode",
|
|
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
|
|
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
|
|
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:
|
|
417
|
+
ranges: h(this.ranges)
|
|
380
418
|
}), this.requestAfterRender();
|
|
381
419
|
}
|
|
382
420
|
// ===== Private Helpers =====
|
|
383
421
|
#e() {
|
|
384
|
-
return
|
|
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
|
|
430
|
-
const
|
|
431
|
-
let
|
|
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
|
-
|
|
471
|
+
n.clear(), n.add(e), o = e;
|
|
434
472
|
else if (t === "multiple") {
|
|
435
|
-
const a =
|
|
436
|
-
if (
|
|
437
|
-
const i = Math.min(s.anchor, e),
|
|
438
|
-
for (let c = i; c <=
|
|
439
|
-
|
|
440
|
-
} else a ? (
|
|
441
|
-
}
|
|
442
|
-
return { selected:
|
|
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
|
|
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
|
|
451
|
-
const t = [],
|
|
452
|
-
for (const
|
|
453
|
-
s.has(
|
|
454
|
-
for (const
|
|
455
|
-
e.has(
|
|
456
|
-
return { added: t, removed:
|
|
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
|
-
|
|
461
|
-
|
|
462
|
-
|
|
498
|
+
I as computeSelectionDiff,
|
|
499
|
+
y as handleRowClick,
|
|
500
|
+
S as selectAll
|
|
463
501
|
};
|
|
464
502
|
//# sourceMappingURL=index.js.map
|