@toolbox-web/grid 0.2.5 → 0.2.6
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/all.d.ts +56 -23
- package/all.js +841 -809
- package/all.js.map +1 -1
- package/index.d.ts +12 -5
- package/index.js +276 -225
- package/index.js.map +1 -1
- package/lib/plugins/clipboard/index.js +1 -1
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js +1 -1
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/export/index.js +1 -1
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/index.js +1 -1
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/index.js +46 -45
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/index.js +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 +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js +1 -1
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/index.js +55 -47
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js +243 -241
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/reorder/index.js +87 -67
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/selection/index.js +28 -27
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js +2 -2
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/tree/index.js +70 -70
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.js +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +13 -13
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +7 -7
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/grouping-columns.umd.js +1 -1
- package/umd/plugins/grouping-columns.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/reorder.umd.js +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 +1 -1
- package/umd/plugins/server-side.umd.js.map +1 -1
- package/umd/plugins/tree.umd.js +1 -1
- package/umd/plugins/tree.umd.js.map +1 -1
|
@@ -7,11 +7,11 @@ const C = {
|
|
|
7
7
|
submenuArrow: "▶",
|
|
8
8
|
dragHandle: "⋮⋮",
|
|
9
9
|
toolPanel: "☰"
|
|
10
|
-
},
|
|
10
|
+
}, w = {
|
|
11
11
|
/** Ask if a column can be moved. Context: ColumnConfig. Response: boolean | undefined */
|
|
12
12
|
CAN_MOVE_COLUMN: "canMoveColumn"
|
|
13
13
|
};
|
|
14
|
-
class
|
|
14
|
+
class b {
|
|
15
15
|
/** Plugin version - override in subclass if needed */
|
|
16
16
|
version = "1.0.0";
|
|
17
17
|
/** CSS styles to inject into the grid's shadow DOM */
|
|
@@ -62,8 +62,8 @@ class v {
|
|
|
62
62
|
/**
|
|
63
63
|
* Emit a custom event from the grid.
|
|
64
64
|
*/
|
|
65
|
-
emit(e,
|
|
66
|
-
this.grid?.dispatchEvent?.(new CustomEvent(e, { detail:
|
|
65
|
+
emit(e, t) {
|
|
66
|
+
this.grid?.dispatchEvent?.(new CustomEvent(e, { detail: t, bubbles: !0 }));
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
* Request a re-render of the grid.
|
|
@@ -102,7 +102,7 @@ class v {
|
|
|
102
102
|
* Use this for rendering that needs to match the grid template.
|
|
103
103
|
*/
|
|
104
104
|
get visibleColumns() {
|
|
105
|
-
return this.grid?.
|
|
105
|
+
return this.grid?._visibleColumns ?? [];
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
108
|
* Get the shadow root of the grid.
|
|
@@ -146,8 +146,8 @@ class v {
|
|
|
146
146
|
* @param pluginOverride - Optional plugin-level override
|
|
147
147
|
* @returns The resolved icon value
|
|
148
148
|
*/
|
|
149
|
-
resolveIcon(e,
|
|
150
|
-
return
|
|
149
|
+
resolveIcon(e, t) {
|
|
150
|
+
return t !== void 0 ? t : this.gridIcons[e];
|
|
151
151
|
}
|
|
152
152
|
/**
|
|
153
153
|
* Set an icon value on an element.
|
|
@@ -156,8 +156,8 @@ class v {
|
|
|
156
156
|
* @param element - The element to set the icon on
|
|
157
157
|
* @param icon - The icon value (string or HTMLElement)
|
|
158
158
|
*/
|
|
159
|
-
setIcon(e,
|
|
160
|
-
typeof
|
|
159
|
+
setIcon(e, t) {
|
|
160
|
+
typeof t == "string" ? e.innerHTML = t : t instanceof HTMLElement && (e.innerHTML = "", e.appendChild(t.cloneNode(!0)));
|
|
161
161
|
}
|
|
162
162
|
/**
|
|
163
163
|
* Log a warning message.
|
|
@@ -167,23 +167,22 @@ class v {
|
|
|
167
167
|
}
|
|
168
168
|
// #endregion
|
|
169
169
|
}
|
|
170
|
-
function
|
|
171
|
-
const e =
|
|
170
|
+
function O(o) {
|
|
171
|
+
const e = o.meta ?? {};
|
|
172
172
|
return e.lockPosition !== !0 && e.suppressMovable !== !0;
|
|
173
173
|
}
|
|
174
|
-
function
|
|
175
|
-
if (e ===
|
|
176
|
-
const
|
|
177
|
-
return
|
|
174
|
+
function f(o, e, t) {
|
|
175
|
+
if (e === t || e < 0 || e >= o.length || t < 0 || t > o.length) return o;
|
|
176
|
+
const n = [...o], [r] = n.splice(e, 1);
|
|
177
|
+
return n.splice(t, 0, r), n;
|
|
178
178
|
}
|
|
179
|
-
const
|
|
180
|
-
class
|
|
179
|
+
const x = '.header-row>.cell[draggable=true]{cursor:grab;position:relative}.header-row>.cell.dragging{opacity:.5;cursor:grabbing}.header-row>.cell.drop-before:before{content:"";position:absolute;left:0;top:0;bottom:0;width:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent));z-index:1}.header-row>.cell.drop-after:after{content:"";position:absolute;right:0;top:0;bottom:0;width:2px;background:var(--tbw-reorder-indicator, var(--tbw-color-accent));z-index:1}';
|
|
180
|
+
class I extends b {
|
|
181
181
|
name = "reorder";
|
|
182
182
|
version = "1.0.0";
|
|
183
183
|
get defaultConfig() {
|
|
184
184
|
return {
|
|
185
|
-
|
|
186
|
-
animationDuration: 200
|
|
185
|
+
viewTransition: !0
|
|
187
186
|
};
|
|
188
187
|
}
|
|
189
188
|
// #region Internal State
|
|
@@ -196,9 +195,9 @@ class E extends v {
|
|
|
196
195
|
attach(e) {
|
|
197
196
|
super.attach(e), e.addEventListener(
|
|
198
197
|
"column-reorder-request",
|
|
199
|
-
(
|
|
200
|
-
const
|
|
201
|
-
|
|
198
|
+
(t) => {
|
|
199
|
+
const n = t.detail;
|
|
200
|
+
n?.field && typeof n.toIndex == "number" && this.moveColumn(n.field, n.toIndex);
|
|
202
201
|
},
|
|
203
202
|
{ signal: this.disconnectSignal }
|
|
204
203
|
);
|
|
@@ -208,46 +207,45 @@ class E extends v {
|
|
|
208
207
|
}
|
|
209
208
|
// #endregion
|
|
210
209
|
// #region Hooks
|
|
211
|
-
// Note: No processColumns hook needed - we directly update the grid's column order
|
|
212
210
|
afterRender() {
|
|
213
211
|
const e = this.shadowRoot;
|
|
214
212
|
if (!e) return;
|
|
215
|
-
e.querySelectorAll(".header-row > .cell").forEach((
|
|
216
|
-
const
|
|
217
|
-
if (!
|
|
218
|
-
const
|
|
219
|
-
type:
|
|
220
|
-
context:
|
|
213
|
+
e.querySelectorAll(".header-row > .cell").forEach((n) => {
|
|
214
|
+
const r = n, s = r.getAttribute("data-field");
|
|
215
|
+
if (!s) return;
|
|
216
|
+
const a = this.columns.find((i) => i.field === s), p = !this.grid.queryPlugins({
|
|
217
|
+
type: w.CAN_MOVE_COLUMN,
|
|
218
|
+
context: a
|
|
221
219
|
}).includes(!1);
|
|
222
|
-
if (!
|
|
223
|
-
|
|
220
|
+
if (!a || !O(a) || !p) {
|
|
221
|
+
r.draggable = !1;
|
|
224
222
|
return;
|
|
225
223
|
}
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
this.isDragging = !0, this.draggedField =
|
|
229
|
-
}),
|
|
230
|
-
this.isDragging = !1, this.draggedField = null, this.draggedIndex = null, this.dropIndex = null, e.querySelectorAll(".header-row > .cell").forEach((
|
|
231
|
-
|
|
224
|
+
r.draggable = !0, !r.getAttribute("data-dragstart-bound") && (r.setAttribute("data-dragstart-bound", "true"), r.addEventListener("dragstart", (i) => {
|
|
225
|
+
const d = this.getColumnOrder().indexOf(s);
|
|
226
|
+
this.isDragging = !0, this.draggedField = s, this.draggedIndex = d, i.dataTransfer && (i.dataTransfer.effectAllowed = "move", i.dataTransfer.setData("text/plain", s)), r.classList.add("dragging");
|
|
227
|
+
}), r.addEventListener("dragend", () => {
|
|
228
|
+
this.isDragging = !1, this.draggedField = null, this.draggedIndex = null, this.dropIndex = null, e.querySelectorAll(".header-row > .cell").forEach((i) => {
|
|
229
|
+
i.classList.remove("dragging", "drop-target", "drop-before", "drop-after");
|
|
232
230
|
});
|
|
233
|
-
}),
|
|
234
|
-
if (
|
|
235
|
-
const
|
|
236
|
-
this.dropIndex =
|
|
237
|
-
}),
|
|
238
|
-
|
|
239
|
-
}),
|
|
240
|
-
|
|
241
|
-
const
|
|
242
|
-
if (!this.isDragging ||
|
|
231
|
+
}), r.addEventListener("dragover", (i) => {
|
|
232
|
+
if (i.preventDefault(), !this.isDragging || this.draggedField === s) return;
|
|
233
|
+
const l = r.getBoundingClientRect(), d = l.left + l.width / 2, u = this.getColumnOrder().indexOf(s);
|
|
234
|
+
this.dropIndex = i.clientX < d ? u : u + 1, r.classList.add("drop-target"), r.classList.toggle("drop-before", i.clientX < d), r.classList.toggle("drop-after", i.clientX >= d);
|
|
235
|
+
}), r.addEventListener("dragleave", () => {
|
|
236
|
+
r.classList.remove("drop-target", "drop-before", "drop-after");
|
|
237
|
+
}), r.addEventListener("drop", (i) => {
|
|
238
|
+
i.preventDefault();
|
|
239
|
+
const l = this.draggedField, d = this.draggedIndex, g = this.dropIndex;
|
|
240
|
+
if (!this.isDragging || l === null || d === null || g === null)
|
|
243
241
|
return;
|
|
244
|
-
const
|
|
245
|
-
field:
|
|
246
|
-
fromIndex:
|
|
247
|
-
toIndex:
|
|
248
|
-
columnOrder:
|
|
242
|
+
const u = g > d ? g - 1 : g, m = this.getColumnOrder(), h = f(m, d, u), v = {
|
|
243
|
+
field: l,
|
|
244
|
+
fromIndex: d,
|
|
245
|
+
toIndex: u,
|
|
246
|
+
columnOrder: h
|
|
249
247
|
};
|
|
250
|
-
this.
|
|
248
|
+
this.updateColumnOrder(h), this.emit("column-move", v);
|
|
251
249
|
}));
|
|
252
250
|
});
|
|
253
251
|
}
|
|
@@ -265,37 +263,59 @@ class E extends v {
|
|
|
265
263
|
* @param field - The field name of the column to move
|
|
266
264
|
* @param toIndex - The target index
|
|
267
265
|
*/
|
|
268
|
-
moveColumn(e,
|
|
269
|
-
const
|
|
270
|
-
if (
|
|
271
|
-
const
|
|
272
|
-
this.
|
|
266
|
+
moveColumn(e, t) {
|
|
267
|
+
const n = this.getColumnOrder(), r = n.indexOf(e);
|
|
268
|
+
if (r === -1) return;
|
|
269
|
+
const s = f(n, r, t);
|
|
270
|
+
this.updateColumnOrder(s), this.emit("column-move", {
|
|
273
271
|
field: e,
|
|
274
|
-
fromIndex:
|
|
275
|
-
toIndex:
|
|
276
|
-
columnOrder:
|
|
277
|
-
})
|
|
272
|
+
fromIndex: r,
|
|
273
|
+
toIndex: t,
|
|
274
|
+
columnOrder: s
|
|
275
|
+
});
|
|
278
276
|
}
|
|
279
277
|
/**
|
|
280
278
|
* Set a specific column order.
|
|
281
279
|
* @param order - Array of field names in desired order
|
|
282
280
|
*/
|
|
283
281
|
setColumnOrder(e) {
|
|
284
|
-
this.
|
|
282
|
+
this.updateColumnOrder(e);
|
|
285
283
|
}
|
|
286
284
|
/**
|
|
287
285
|
* Reset column order to the original configuration order.
|
|
288
286
|
*/
|
|
289
287
|
resetColumnOrder() {
|
|
290
|
-
const e = this.columns.map((
|
|
291
|
-
this.
|
|
288
|
+
const e = this.columns.map((t) => t.field);
|
|
289
|
+
this.updateColumnOrder(e);
|
|
290
|
+
}
|
|
291
|
+
// #endregion
|
|
292
|
+
// #region View Transition
|
|
293
|
+
/**
|
|
294
|
+
* Update column order with optional view transition animation.
|
|
295
|
+
* Falls back to instant update if View Transitions API is not supported.
|
|
296
|
+
*/
|
|
297
|
+
updateColumnOrder(e) {
|
|
298
|
+
const t = this.grid, n = this.shadowRoot;
|
|
299
|
+
if (this.config.viewTransition && "startViewTransition" in document && n) {
|
|
300
|
+
const r = n.querySelectorAll(".cell[data-field]");
|
|
301
|
+
r.forEach((a) => {
|
|
302
|
+
const c = a.getAttribute("data-field");
|
|
303
|
+
c && (a.style.viewTransitionName = `col-${c}`);
|
|
304
|
+
}), document.startViewTransition(() => t.setColumnOrder(e)).finished.finally(() => {
|
|
305
|
+
r.forEach((a) => {
|
|
306
|
+
a.style.viewTransitionName = "";
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
} else
|
|
310
|
+
t.setColumnOrder(e);
|
|
311
|
+
t.requestStateChange?.();
|
|
292
312
|
}
|
|
293
313
|
// #endregion
|
|
294
314
|
// #region Styles
|
|
295
|
-
styles =
|
|
315
|
+
styles = x;
|
|
296
316
|
// #endregion
|
|
297
317
|
}
|
|
298
318
|
export {
|
|
299
|
-
|
|
319
|
+
I as ReorderPlugin
|
|
300
320
|
};
|
|
301
321
|
//# sourceMappingURL=index.js.map
|