@toolbox-web/grid 0.4.0 → 0.4.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 +10 -13
- package/all.js +1124 -1047
- package/all.js.map +1 -1
- package/index.js +688 -515
- package/index.js.map +1 -1
- package/lib/core/grid.d.ts +10 -0
- package/lib/core/grid.d.ts.map +1 -1
- package/lib/core/internal/config-manager.d.ts +1 -0
- package/lib/core/internal/config-manager.d.ts.map +1 -1
- package/lib/core/internal/keyboard.d.ts.map +1 -1
- package/lib/core/internal/utils.d.ts +1 -0
- package/lib/core/internal/utils.d.ts.map +1 -1
- package/lib/core/internal/validate-config.d.ts +14 -0
- package/lib/core/internal/validate-config.d.ts.map +1 -1
- package/lib/core/plugin/base-plugin.d.ts +105 -1
- package/lib/core/plugin/base-plugin.d.ts.map +1 -1
- package/lib/core/plugin/expander-column.d.ts +51 -0
- package/lib/core/plugin/expander-column.d.ts.map +1 -0
- package/lib/core/plugin/index.d.ts +1 -0
- package/lib/core/plugin/index.d.ts.map +1 -1
- package/lib/core/plugin/plugin-manager.d.ts +1 -1
- package/lib/core/plugin/plugin-manager.d.ts.map +1 -1
- package/lib/core/plugin/types.d.ts +117 -1
- package/lib/core/plugin/types.d.ts.map +1 -1
- package/lib/core/types.d.ts +4 -2
- package/lib/core/types.d.ts.map +1 -1
- package/lib/plugins/clipboard/ClipboardPlugin.d.ts +9 -2
- package/lib/plugins/clipboard/ClipboardPlugin.d.ts.map +1 -1
- package/lib/plugins/clipboard/index.d.ts +1 -1
- package/lib/plugins/clipboard/index.d.ts.map +1 -1
- package/lib/plugins/clipboard/index.js +303 -185
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/clipboard/types.d.ts +72 -2
- package/lib/plugins/clipboard/types.d.ts.map +1 -1
- package/lib/plugins/column-virtualization/ColumnVirtualizationPlugin.d.ts +0 -1
- package/lib/plugins/column-virtualization/ColumnVirtualizationPlugin.d.ts.map +1 -1
- package/lib/plugins/column-virtualization/index.js +116 -24
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/ContextMenuPlugin.d.ts +0 -1
- package/lib/plugins/context-menu/ContextMenuPlugin.d.ts.map +1 -1
- package/lib/plugins/context-menu/index.js +164 -72
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/editing/EditingPlugin.d.ts +1 -7
- package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
- package/lib/plugins/editing/index.js +213 -133
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/export/ExportPlugin.d.ts +0 -1
- package/lib/plugins/export/ExportPlugin.d.ts.map +1 -1
- package/lib/plugins/export/index.js +195 -103
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/FilteringPlugin.d.ts +5 -2
- package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
- package/lib/plugins/filtering/index.js +145 -43
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts +1 -2
- package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts.map +1 -1
- package/lib/plugins/grouping-columns/grouping-columns.d.ts +1 -1
- package/lib/plugins/grouping-columns/grouping-columns.d.ts.map +1 -1
- package/lib/plugins/grouping-columns/index.js +162 -68
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts +14 -2
- package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts.map +1 -1
- package/lib/plugins/grouping-rows/index.js +246 -138
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/MasterDetailPlugin.d.ts +13 -11
- package/lib/plugins/master-detail/MasterDetailPlugin.d.ts.map +1 -1
- package/lib/plugins/master-detail/index.js +281 -196
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/master-detail/types.d.ts +0 -10
- package/lib/plugins/master-detail/types.d.ts.map +1 -1
- package/lib/plugins/multi-sort/MultiSortPlugin.d.ts +1 -2
- package/lib/plugins/multi-sort/MultiSortPlugin.d.ts.map +1 -1
- package/lib/plugins/multi-sort/index.js +121 -31
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/PinnedColumnsPlugin.d.ts +0 -1
- package/lib/plugins/pinned-columns/PinnedColumnsPlugin.d.ts.map +1 -1
- package/lib/plugins/pinned-columns/index.js +144 -52
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts +1 -2
- package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts.map +1 -1
- package/lib/plugins/pinned-rows/index.js +178 -88
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/PivotPlugin.d.ts +26 -4
- package/lib/plugins/pivot/PivotPlugin.d.ts.map +1 -1
- package/lib/plugins/pivot/index.js +414 -310
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/pivot/pivot-rows.d.ts +2 -1
- package/lib/plugins/pivot/pivot-rows.d.ts.map +1 -1
- package/lib/plugins/reorder/ReorderPlugin.d.ts +13 -10
- package/lib/plugins/reorder/ReorderPlugin.d.ts.map +1 -1
- package/lib/plugins/reorder/index.js +304 -226
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/selection/SelectionPlugin.d.ts +21 -3
- package/lib/plugins/selection/SelectionPlugin.d.ts.map +1 -1
- package/lib/plugins/selection/index.d.ts +2 -2
- package/lib/plugins/selection/index.d.ts.map +1 -1
- package/lib/plugins/selection/index.js +292 -145
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/selection/types.d.ts +24 -0
- package/lib/plugins/selection/types.d.ts.map +1 -1
- package/lib/plugins/server-side/ServerSidePlugin.d.ts +0 -1
- package/lib/plugins/server-side/ServerSidePlugin.d.ts.map +1 -1
- package/lib/plugins/server-side/index.js +95 -3
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/tree/TreePlugin.d.ts +5 -1
- package/lib/plugins/tree/TreePlugin.d.ts.map +1 -1
- package/lib/plugins/tree/index.js +213 -112
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/tree/types.d.ts +0 -10
- package/lib/plugins/tree/types.d.ts.map +1 -1
- package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts +7 -2
- package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts.map +1 -1
- package/lib/plugins/undo-redo/index.js +112 -12
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/VisibilityPlugin.d.ts +14 -5
- package/lib/plugins/visibility/VisibilityPlugin.d.ts.map +1 -1
- package/lib/plugins/visibility/index.js +168 -65
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +21 -17
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +14 -8
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/clipboard.umd.js +5 -7
- package/umd/plugins/clipboard.umd.js.map +1 -1
- package/umd/plugins/column-virtualization.umd.js +1 -1
- package/umd/plugins/column-virtualization.umd.js.map +1 -1
- package/umd/plugins/context-menu.umd.js +1 -1
- package/umd/plugins/context-menu.umd.js.map +1 -1
- package/umd/plugins/editing.umd.js +1 -1
- package/umd/plugins/editing.umd.js.map +1 -1
- package/umd/plugins/export.umd.js +1 -1
- package/umd/plugins/export.umd.js.map +1 -1
- package/umd/plugins/filtering.umd.js +1 -1
- package/umd/plugins/filtering.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/grouping-rows.umd.js +1 -1
- package/umd/plugins/grouping-rows.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/multi-sort.umd.js +1 -1
- package/umd/plugins/multi-sort.umd.js.map +1 -1
- package/umd/plugins/pinned-columns.umd.js +1 -1
- package/umd/plugins/pinned-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
- package/umd/plugins/undo-redo.umd.js +1 -1
- package/umd/plugins/undo-redo.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,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const L = {
|
|
2
2
|
expand: "▶",
|
|
3
3
|
collapse: "▼",
|
|
4
4
|
sortAsc: "▲",
|
|
@@ -9,8 +9,27 @@ const E = {
|
|
|
9
9
|
toolPanel: "☰"
|
|
10
10
|
};
|
|
11
11
|
class P {
|
|
12
|
-
/**
|
|
13
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Plugin dependencies - declare other plugins this one requires.
|
|
14
|
+
*
|
|
15
|
+
* Dependencies are validated when the plugin is attached.
|
|
16
|
+
* Required dependencies throw an error if missing.
|
|
17
|
+
* Optional dependencies log an info message if missing.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* static readonly dependencies: PluginDependency[] = [
|
|
22
|
+
* { name: 'editing', required: true, reason: 'Tracks cell edits for undo/redo' },
|
|
23
|
+
* { name: 'selection', required: false, reason: 'Enables selection-based undo' },
|
|
24
|
+
* ];
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
static dependencies;
|
|
28
|
+
/**
|
|
29
|
+
* Plugin version - defaults to grid version for built-in plugins.
|
|
30
|
+
* Third-party plugins can override with their own semver.
|
|
31
|
+
*/
|
|
32
|
+
version = typeof __GRID_VERSION__ < "u" ? __GRID_VERSION__ : "dev";
|
|
14
33
|
/** CSS styles to inject into the grid's shadow DOM */
|
|
15
34
|
styles;
|
|
16
35
|
/** Custom cell renderers keyed by type name */
|
|
@@ -97,12 +116,28 @@ class P {
|
|
|
97
116
|
emit(e, t) {
|
|
98
117
|
this.grid?.dispatchEvent?.(new CustomEvent(e, { detail: t, bubbles: !0 }));
|
|
99
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Emit a cancelable custom event from the grid.
|
|
121
|
+
* @returns `true` if the event was cancelled (preventDefault called), `false` otherwise
|
|
122
|
+
*/
|
|
123
|
+
emitCancelable(e, t) {
|
|
124
|
+
const i = new CustomEvent(e, { detail: t, bubbles: !0, cancelable: !0 });
|
|
125
|
+
return this.grid?.dispatchEvent?.(i), i.defaultPrevented;
|
|
126
|
+
}
|
|
100
127
|
/**
|
|
101
128
|
* Request a re-render of the grid.
|
|
102
129
|
*/
|
|
103
130
|
requestRender() {
|
|
104
131
|
this.grid?.requestRender?.();
|
|
105
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Request a re-render and restore focus styling afterward.
|
|
135
|
+
* Use this when a plugin action (like expand/collapse) triggers a render
|
|
136
|
+
* but needs to maintain keyboard navigation focus.
|
|
137
|
+
*/
|
|
138
|
+
requestRenderWithFocus() {
|
|
139
|
+
this.grid?.requestRenderWithFocus?.();
|
|
140
|
+
}
|
|
106
141
|
/**
|
|
107
142
|
* Request a lightweight style update without rebuilding DOM.
|
|
108
143
|
* Use this instead of requestRender() when only CSS classes need updating.
|
|
@@ -136,6 +171,19 @@ class P {
|
|
|
136
171
|
get visibleColumns() {
|
|
137
172
|
return this.grid?._visibleColumns ?? [];
|
|
138
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Get the grid as an HTMLElement for direct DOM operations.
|
|
176
|
+
* Use sparingly - prefer the typed GridElementRef API when possible.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* const width = this.gridElement.clientWidth;
|
|
181
|
+
* this.gridElement.classList.add('my-plugin-active');
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
get gridElement() {
|
|
185
|
+
return this.grid;
|
|
186
|
+
}
|
|
139
187
|
/**
|
|
140
188
|
* Get the shadow root of the grid.
|
|
141
189
|
*/
|
|
@@ -168,8 +216,53 @@ class P {
|
|
|
168
216
|
*/
|
|
169
217
|
get gridIcons() {
|
|
170
218
|
const e = this.grid?.gridConfig?.icons ?? {};
|
|
171
|
-
return { ...
|
|
219
|
+
return { ...L, ...e };
|
|
172
220
|
}
|
|
221
|
+
// #region Animation Helpers
|
|
222
|
+
/**
|
|
223
|
+
* Check if animations are enabled at the grid level.
|
|
224
|
+
* Respects gridConfig.animation.mode and the CSS variable set by the grid.
|
|
225
|
+
*
|
|
226
|
+
* Plugins should use this to skip animations when:
|
|
227
|
+
* - Animation mode is 'off' or `false`
|
|
228
|
+
* - User prefers reduced motion and mode is 'reduced-motion' (default)
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* private get animationStyle(): 'slide' | 'fade' | false {
|
|
233
|
+
* if (!this.isAnimationEnabled) return false;
|
|
234
|
+
* return this.config.animation ?? 'slide';
|
|
235
|
+
* }
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
get isAnimationEnabled() {
|
|
239
|
+
const e = this.grid?.effectiveConfig?.animation?.mode ?? "reduced-motion";
|
|
240
|
+
if (e === !1 || e === "off") return !1;
|
|
241
|
+
if (e === !0 || e === "on") return !0;
|
|
242
|
+
const t = this.shadowRoot?.host;
|
|
243
|
+
return t ? getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim() !== "0" : !0;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Get the animation duration in milliseconds from CSS variable.
|
|
247
|
+
* Falls back to 200ms if not set.
|
|
248
|
+
*
|
|
249
|
+
* Plugins can use this for their animation timing to stay consistent
|
|
250
|
+
* with the grid-level animation.duration setting.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* element.animate(keyframes, { duration: this.animationDuration });
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
get animationDuration() {
|
|
258
|
+
const e = this.shadowRoot?.host;
|
|
259
|
+
if (e) {
|
|
260
|
+
const t = getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(), i = parseInt(t, 10);
|
|
261
|
+
if (!isNaN(i)) return i;
|
|
262
|
+
}
|
|
263
|
+
return 200;
|
|
264
|
+
}
|
|
265
|
+
// #endregion
|
|
173
266
|
/**
|
|
174
267
|
* Resolve an icon value to string or HTMLElement.
|
|
175
268
|
* Checks plugin config first, then grid-level icons, then defaults.
|
|
@@ -200,237 +293,237 @@ class P {
|
|
|
200
293
|
// #endregion
|
|
201
294
|
}
|
|
202
295
|
const m = {
|
|
203
|
-
sum: (
|
|
204
|
-
avg: (
|
|
205
|
-
const t =
|
|
206
|
-
return
|
|
296
|
+
sum: (o, e) => o.reduce((t, i) => t + (Number(i[e]) || 0), 0),
|
|
297
|
+
avg: (o, e) => {
|
|
298
|
+
const t = o.reduce((i, n) => i + (Number(n[e]) || 0), 0);
|
|
299
|
+
return o.length ? t / o.length : 0;
|
|
207
300
|
},
|
|
208
|
-
count: (
|
|
209
|
-
min: (
|
|
210
|
-
max: (
|
|
211
|
-
first: (
|
|
212
|
-
last: (
|
|
213
|
-
},
|
|
301
|
+
count: (o) => o.length,
|
|
302
|
+
min: (o, e) => Math.min(...o.map((t) => Number(t[e]) || 1 / 0)),
|
|
303
|
+
max: (o, e) => Math.max(...o.map((t) => Number(t[e]) || -1 / 0)),
|
|
304
|
+
first: (o, e) => o[0]?.[e],
|
|
305
|
+
last: (o, e) => o[o.length - 1]?.[e]
|
|
306
|
+
}, f = /* @__PURE__ */ new Map(), h = {
|
|
214
307
|
/**
|
|
215
308
|
* Register a custom aggregator function.
|
|
216
309
|
*/
|
|
217
|
-
register(
|
|
218
|
-
|
|
310
|
+
register(o, e) {
|
|
311
|
+
f.set(o, e);
|
|
219
312
|
},
|
|
220
313
|
/**
|
|
221
314
|
* Unregister a custom aggregator function.
|
|
222
315
|
*/
|
|
223
|
-
unregister(
|
|
224
|
-
|
|
316
|
+
unregister(o) {
|
|
317
|
+
f.delete(o);
|
|
225
318
|
},
|
|
226
319
|
/**
|
|
227
320
|
* Get an aggregator function by reference.
|
|
228
321
|
*/
|
|
229
|
-
get(
|
|
230
|
-
if (
|
|
231
|
-
return typeof
|
|
322
|
+
get(o) {
|
|
323
|
+
if (o !== void 0)
|
|
324
|
+
return typeof o == "function" ? o : f.get(o) ?? m[o];
|
|
232
325
|
},
|
|
233
326
|
/**
|
|
234
327
|
* Run an aggregator on a set of rows.
|
|
235
328
|
*/
|
|
236
|
-
run(
|
|
237
|
-
const n = this.get(
|
|
238
|
-
return n ? n(e, t,
|
|
329
|
+
run(o, e, t, i) {
|
|
330
|
+
const n = this.get(o);
|
|
331
|
+
return n ? n(e, t, i) : void 0;
|
|
239
332
|
},
|
|
240
333
|
/**
|
|
241
334
|
* Check if an aggregator exists.
|
|
242
335
|
*/
|
|
243
|
-
has(
|
|
244
|
-
return
|
|
336
|
+
has(o) {
|
|
337
|
+
return f.has(o) || o in m;
|
|
245
338
|
},
|
|
246
339
|
/**
|
|
247
340
|
* List all available aggregator names.
|
|
248
341
|
*/
|
|
249
342
|
list() {
|
|
250
|
-
return [...Object.keys(m), ...
|
|
251
|
-
}
|
|
252
|
-
},
|
|
253
|
-
sum: (
|
|
254
|
-
avg: (
|
|
255
|
-
count: (
|
|
256
|
-
min: (
|
|
257
|
-
max: (
|
|
258
|
-
first: (
|
|
259
|
-
last: (
|
|
343
|
+
return [...Object.keys(m), ...f.keys()];
|
|
344
|
+
}
|
|
345
|
+
}, A = {
|
|
346
|
+
sum: (o) => o.reduce((e, t) => e + t, 0),
|
|
347
|
+
avg: (o) => o.length ? o.reduce((e, t) => e + t, 0) / o.length : 0,
|
|
348
|
+
count: (o) => o.length,
|
|
349
|
+
min: (o) => o.length ? Math.min(...o) : 0,
|
|
350
|
+
max: (o) => o.length ? Math.max(...o) : 0,
|
|
351
|
+
first: (o) => o[0] ?? 0,
|
|
352
|
+
last: (o) => o[o.length - 1] ?? 0
|
|
260
353
|
};
|
|
261
|
-
function
|
|
262
|
-
return
|
|
354
|
+
function k(o) {
|
|
355
|
+
return A[o] ?? A.sum;
|
|
263
356
|
}
|
|
264
357
|
h.register.bind(h);
|
|
265
358
|
h.unregister.bind(h);
|
|
266
359
|
h.get.bind(h);
|
|
267
360
|
h.run.bind(h);
|
|
268
361
|
h.list.bind(h);
|
|
269
|
-
const
|
|
270
|
-
function S(
|
|
362
|
+
const N = k;
|
|
363
|
+
function S(o) {
|
|
271
364
|
const e = [];
|
|
272
|
-
return !
|
|
365
|
+
return !o.rowGroupFields?.length && !o.columnGroupFields?.length && e.push("At least one row or column group field is required"), o.valueFields?.length || e.push("At least one value field is required"), e;
|
|
273
366
|
}
|
|
274
|
-
function
|
|
275
|
-
return [...
|
|
367
|
+
function x(o, e) {
|
|
368
|
+
return [...o, e].join("|");
|
|
276
369
|
}
|
|
277
|
-
function
|
|
278
|
-
const t = e.rowGroupFields ?? [],
|
|
279
|
-
i,
|
|
280
|
-
t,
|
|
370
|
+
function K(o, e) {
|
|
371
|
+
const t = e.rowGroupFields ?? [], i = e.columnGroupFields ?? [], n = e.valueFields ?? [], r = I(o, i), a = G(
|
|
281
372
|
o,
|
|
373
|
+
t,
|
|
374
|
+
i,
|
|
282
375
|
r,
|
|
283
376
|
n,
|
|
284
377
|
0,
|
|
285
378
|
// starting depth
|
|
286
379
|
""
|
|
287
380
|
// parent key prefix
|
|
288
|
-
),
|
|
381
|
+
), s = D(a, r, n), l = Object.values(s).reduce((d, c) => d + c, 0);
|
|
289
382
|
return {
|
|
290
|
-
rows:
|
|
383
|
+
rows: a,
|
|
291
384
|
columnKeys: r,
|
|
292
|
-
totals:
|
|
385
|
+
totals: s,
|
|
293
386
|
grandTotal: l
|
|
294
387
|
};
|
|
295
388
|
}
|
|
296
|
-
function
|
|
389
|
+
function I(o, e) {
|
|
297
390
|
if (e.length === 0) return ["value"];
|
|
298
391
|
const t = /* @__PURE__ */ new Set();
|
|
299
|
-
for (const
|
|
300
|
-
const n = e.map((r) => String(
|
|
392
|
+
for (const i of o) {
|
|
393
|
+
const n = e.map((r) => String(i[r] ?? "")).join("|");
|
|
301
394
|
t.add(n);
|
|
302
395
|
}
|
|
303
396
|
return [...t].sort();
|
|
304
397
|
}
|
|
305
|
-
function
|
|
398
|
+
function V(o, e) {
|
|
306
399
|
const t = /* @__PURE__ */ new Map();
|
|
307
|
-
for (const
|
|
308
|
-
const n = String(
|
|
309
|
-
r ? r.push(
|
|
400
|
+
for (const i of o) {
|
|
401
|
+
const n = String(i[e] ?? ""), r = t.get(n);
|
|
402
|
+
r ? r.push(i) : t.set(n, [i]);
|
|
310
403
|
}
|
|
311
404
|
return t;
|
|
312
405
|
}
|
|
313
|
-
function
|
|
314
|
-
const
|
|
406
|
+
function G(o, e, t, i, n, r, a) {
|
|
407
|
+
const s = [];
|
|
315
408
|
if (e.length === 0) {
|
|
316
|
-
const u =
|
|
317
|
-
return
|
|
318
|
-
rowKey:
|
|
319
|
-
rowLabel:
|
|
409
|
+
const u = R(o, t, i, n), g = _(u);
|
|
410
|
+
return s.push({
|
|
411
|
+
rowKey: a || "all",
|
|
412
|
+
rowLabel: a || "All",
|
|
320
413
|
depth: r,
|
|
321
414
|
values: u,
|
|
322
415
|
total: g,
|
|
323
416
|
isGroup: !1,
|
|
324
|
-
rowCount:
|
|
325
|
-
}),
|
|
417
|
+
rowCount: o.length
|
|
418
|
+
}), s;
|
|
326
419
|
}
|
|
327
|
-
const l = e[0], d = e.slice(1), c = d.length > 0, p =
|
|
420
|
+
const l = e[0], d = e.slice(1), c = d.length > 0, p = V(o, l);
|
|
328
421
|
for (const [u, g] of p) {
|
|
329
|
-
const
|
|
330
|
-
let
|
|
331
|
-
c && (
|
|
422
|
+
const C = a ? `${a}|${u}` : u, y = R(g, t, i, n), E = _(y);
|
|
423
|
+
let F;
|
|
424
|
+
c && (F = G(
|
|
332
425
|
g,
|
|
333
426
|
d,
|
|
334
427
|
t,
|
|
335
|
-
|
|
428
|
+
i,
|
|
336
429
|
n,
|
|
337
430
|
r + 1,
|
|
338
|
-
|
|
339
|
-
)),
|
|
340
|
-
rowKey:
|
|
431
|
+
C
|
|
432
|
+
)), s.push({
|
|
433
|
+
rowKey: C,
|
|
341
434
|
rowLabel: u || "(blank)",
|
|
342
435
|
depth: r,
|
|
343
|
-
values:
|
|
344
|
-
total:
|
|
436
|
+
values: y,
|
|
437
|
+
total: E,
|
|
345
438
|
isGroup: c,
|
|
346
|
-
children:
|
|
439
|
+
children: F,
|
|
347
440
|
rowCount: g.length
|
|
348
441
|
});
|
|
349
442
|
}
|
|
350
|
-
return
|
|
443
|
+
return s;
|
|
351
444
|
}
|
|
352
|
-
function
|
|
445
|
+
function R(o, e, t, i) {
|
|
353
446
|
const n = {};
|
|
354
447
|
for (const r of t)
|
|
355
|
-
for (const
|
|
356
|
-
const l = (e.length > 0 ?
|
|
448
|
+
for (const a of i) {
|
|
449
|
+
const l = (e.length > 0 ? o.filter((u) => e.map((g) => String(u[g] ?? "")).join("|") === r) : o).map((u) => Number(u[a.field]) || 0), d = N(a.aggFunc), c = l.length > 0 ? d(l) : null, p = x([r], a.field);
|
|
357
450
|
n[p] = c;
|
|
358
451
|
}
|
|
359
452
|
return n;
|
|
360
453
|
}
|
|
361
|
-
function _(
|
|
454
|
+
function _(o) {
|
|
362
455
|
let e = 0;
|
|
363
|
-
for (const t of Object.values(
|
|
456
|
+
for (const t of Object.values(o))
|
|
364
457
|
e += t ?? 0;
|
|
365
458
|
return e;
|
|
366
459
|
}
|
|
367
|
-
function D(
|
|
368
|
-
const
|
|
460
|
+
function D(o, e, t) {
|
|
461
|
+
const i = {};
|
|
369
462
|
function n(r) {
|
|
370
|
-
for (const
|
|
371
|
-
if (!
|
|
372
|
-
for (const
|
|
463
|
+
for (const a of r)
|
|
464
|
+
if (!a.isGroup || !a.children?.length)
|
|
465
|
+
for (const s of e)
|
|
373
466
|
for (const l of t) {
|
|
374
|
-
const d =
|
|
375
|
-
|
|
467
|
+
const d = x([s], l.field);
|
|
468
|
+
i[d] = (i[d] ?? 0) + (a.values[d] ?? 0);
|
|
376
469
|
}
|
|
377
|
-
else
|
|
470
|
+
else a.children && n(a.children);
|
|
378
471
|
}
|
|
379
|
-
return n(
|
|
472
|
+
return n(o), i;
|
|
380
473
|
}
|
|
381
|
-
function
|
|
382
|
-
const
|
|
474
|
+
function q(o, e, t = !0) {
|
|
475
|
+
const i = [];
|
|
383
476
|
function n(r) {
|
|
384
|
-
|
|
385
|
-
const
|
|
386
|
-
if (r.children &&
|
|
387
|
-
for (const
|
|
388
|
-
n(
|
|
477
|
+
i.push(r);
|
|
478
|
+
const a = e ? e.has(r.rowKey) : t;
|
|
479
|
+
if (r.children && a)
|
|
480
|
+
for (const s of r.children)
|
|
481
|
+
n(s);
|
|
389
482
|
}
|
|
390
|
-
for (const r of
|
|
483
|
+
for (const r of o)
|
|
391
484
|
n(r);
|
|
392
|
-
return
|
|
485
|
+
return i;
|
|
393
486
|
}
|
|
394
|
-
function
|
|
487
|
+
function H(o) {
|
|
395
488
|
const e = [];
|
|
396
|
-
function t(
|
|
397
|
-
if (
|
|
398
|
-
for (const n of
|
|
489
|
+
function t(i) {
|
|
490
|
+
if (i.isGroup && e.push(i.rowKey), i.children)
|
|
491
|
+
for (const n of i.children)
|
|
399
492
|
t(n);
|
|
400
493
|
}
|
|
401
|
-
for (const
|
|
402
|
-
t(
|
|
494
|
+
for (const i of o)
|
|
495
|
+
t(i);
|
|
403
496
|
return e;
|
|
404
497
|
}
|
|
405
|
-
const
|
|
406
|
-
function z(
|
|
407
|
-
const n = new AbortController(), r = { config: e, callbacks:
|
|
408
|
-
return
|
|
409
|
-
n.abort(),
|
|
498
|
+
const M = ["sum", "avg", "count", "min", "max", "first", "last"];
|
|
499
|
+
function z(o, e, t, i) {
|
|
500
|
+
const n = new AbortController(), r = { config: e, callbacks: i, signal: n.signal }, a = document.createElement("div");
|
|
501
|
+
return a.className = "tbw-pivot-panel", a.appendChild(b("Options", () => W(t, r))), a.appendChild(b("Row Groups", () => T("rowGroups", r))), a.appendChild(b("Column Groups", () => T("columnGroups", r))), a.appendChild(b("Values", () => Z(r))), a.appendChild(b("Available Fields", () => j(r))), o.appendChild(a), () => {
|
|
502
|
+
n.abort(), a.remove();
|
|
410
503
|
};
|
|
411
504
|
}
|
|
412
|
-
function
|
|
505
|
+
function b(o, e) {
|
|
413
506
|
const t = document.createElement("div");
|
|
414
507
|
t.className = "tbw-pivot-section";
|
|
415
|
-
const
|
|
416
|
-
|
|
508
|
+
const i = document.createElement("div");
|
|
509
|
+
i.className = "tbw-pivot-section-header", i.textContent = o;
|
|
417
510
|
const n = document.createElement("div");
|
|
418
|
-
return n.className = "tbw-pivot-section-content", n.appendChild(e()), t.appendChild(
|
|
511
|
+
return n.className = "tbw-pivot-section-content", n.appendChild(e()), t.appendChild(i), t.appendChild(n), t;
|
|
419
512
|
}
|
|
420
|
-
function
|
|
421
|
-
const { config: t, callbacks:
|
|
422
|
-
r.className = "tbw-pivot-drop-zone", r.setAttribute("data-zone",
|
|
423
|
-
const
|
|
424
|
-
if (
|
|
425
|
-
const
|
|
426
|
-
|
|
513
|
+
function T(o, e) {
|
|
514
|
+
const { config: t, callbacks: i, signal: n } = e, r = document.createElement("div");
|
|
515
|
+
r.className = "tbw-pivot-drop-zone", r.setAttribute("data-zone", o);
|
|
516
|
+
const a = o === "rowGroups" ? t.rowGroupFields ?? [] : t.columnGroupFields ?? [];
|
|
517
|
+
if (a.length === 0) {
|
|
518
|
+
const s = document.createElement("div");
|
|
519
|
+
s.className = "tbw-pivot-placeholder", s.textContent = "Drag fields here or click to add", r.appendChild(s);
|
|
427
520
|
} else
|
|
428
|
-
for (const
|
|
429
|
-
r.appendChild(O(
|
|
521
|
+
for (const s of a)
|
|
522
|
+
r.appendChild(O(s, o, e));
|
|
430
523
|
return r.addEventListener(
|
|
431
524
|
"dragover",
|
|
432
|
-
(
|
|
433
|
-
|
|
525
|
+
(s) => {
|
|
526
|
+
s.preventDefault(), r.classList.add("drag-over");
|
|
434
527
|
},
|
|
435
528
|
{ signal: n }
|
|
436
529
|
), r.addEventListener(
|
|
@@ -441,30 +534,30 @@ function G(i, e) {
|
|
|
441
534
|
{ signal: n }
|
|
442
535
|
), r.addEventListener(
|
|
443
536
|
"drop",
|
|
444
|
-
(
|
|
445
|
-
|
|
446
|
-
const l =
|
|
447
|
-
l &&
|
|
537
|
+
(s) => {
|
|
538
|
+
s.preventDefault(), r.classList.remove("drag-over");
|
|
539
|
+
const l = s.dataTransfer?.getData("text/plain");
|
|
540
|
+
l && i.onAddFieldToZone(l, o);
|
|
448
541
|
},
|
|
449
542
|
{ signal: n }
|
|
450
543
|
), r;
|
|
451
544
|
}
|
|
452
|
-
function O(
|
|
453
|
-
const { callbacks:
|
|
545
|
+
function O(o, e, t) {
|
|
546
|
+
const { callbacks: i, signal: n } = t, r = document.createElement("div");
|
|
454
547
|
r.className = "tbw-pivot-field-chip", r.draggable = !0;
|
|
455
|
-
const
|
|
456
|
-
|
|
548
|
+
const a = i.getAvailableFields().find((d) => d.field === o), s = document.createElement("span");
|
|
549
|
+
s.className = "tbw-pivot-chip-label", s.textContent = a?.header ?? o;
|
|
457
550
|
const l = document.createElement("button");
|
|
458
551
|
return l.className = "tbw-pivot-chip-remove", l.innerHTML = "×", l.title = "Remove field", l.addEventListener(
|
|
459
552
|
"click",
|
|
460
553
|
(d) => {
|
|
461
|
-
d.stopPropagation(),
|
|
554
|
+
d.stopPropagation(), i.onRemoveFieldFromZone(o, e);
|
|
462
555
|
},
|
|
463
556
|
{ signal: n }
|
|
464
|
-
), r.appendChild(
|
|
557
|
+
), r.appendChild(s), r.appendChild(l), r.addEventListener(
|
|
465
558
|
"dragstart",
|
|
466
559
|
(d) => {
|
|
467
|
-
d.dataTransfer?.setData("text/plain",
|
|
560
|
+
d.dataTransfer?.setData("text/plain", o), d.dataTransfer?.setData("source-zone", e), r.classList.add("dragging");
|
|
468
561
|
},
|
|
469
562
|
{ signal: n }
|
|
470
563
|
), r.addEventListener(
|
|
@@ -475,189 +568,189 @@ function O(i, e, t) {
|
|
|
475
568
|
{ signal: n }
|
|
476
569
|
), r;
|
|
477
570
|
}
|
|
478
|
-
function Z(
|
|
479
|
-
const { config: e, callbacks: t, signal:
|
|
571
|
+
function Z(o) {
|
|
572
|
+
const { config: e, callbacks: t, signal: i } = o, n = document.createElement("div");
|
|
480
573
|
n.className = "tbw-pivot-drop-zone tbw-pivot-values-zone", n.setAttribute("data-zone", "values");
|
|
481
574
|
const r = e.valueFields ?? [];
|
|
482
575
|
if (r.length === 0) {
|
|
483
|
-
const
|
|
484
|
-
|
|
576
|
+
const a = document.createElement("div");
|
|
577
|
+
a.className = "tbw-pivot-placeholder", a.textContent = "Drag numeric fields here for aggregation", n.appendChild(a);
|
|
485
578
|
} else
|
|
486
|
-
for (const
|
|
487
|
-
n.appendChild($(
|
|
579
|
+
for (const a of r)
|
|
580
|
+
n.appendChild($(a, o));
|
|
488
581
|
return n.addEventListener(
|
|
489
582
|
"dragover",
|
|
490
|
-
(
|
|
491
|
-
|
|
583
|
+
(a) => {
|
|
584
|
+
a.preventDefault(), n.classList.add("drag-over");
|
|
492
585
|
},
|
|
493
|
-
{ signal:
|
|
586
|
+
{ signal: i }
|
|
494
587
|
), n.addEventListener(
|
|
495
588
|
"dragleave",
|
|
496
589
|
() => {
|
|
497
590
|
n.classList.remove("drag-over");
|
|
498
591
|
},
|
|
499
|
-
{ signal:
|
|
592
|
+
{ signal: i }
|
|
500
593
|
), n.addEventListener(
|
|
501
594
|
"drop",
|
|
502
|
-
(
|
|
503
|
-
|
|
504
|
-
const
|
|
505
|
-
|
|
595
|
+
(a) => {
|
|
596
|
+
a.preventDefault(), n.classList.remove("drag-over");
|
|
597
|
+
const s = a.dataTransfer?.getData("text/plain");
|
|
598
|
+
s && t.onAddValueField(s, "sum");
|
|
506
599
|
},
|
|
507
|
-
{ signal:
|
|
600
|
+
{ signal: i }
|
|
508
601
|
), n;
|
|
509
602
|
}
|
|
510
|
-
function $(
|
|
511
|
-
const { callbacks: t, signal:
|
|
603
|
+
function $(o, e) {
|
|
604
|
+
const { callbacks: t, signal: i } = e, n = document.createElement("div");
|
|
512
605
|
n.className = "tbw-pivot-field-chip tbw-pivot-value-chip";
|
|
513
|
-
const r = t.getAvailableFields().find((c) => c.field ===
|
|
514
|
-
|
|
515
|
-
const
|
|
516
|
-
|
|
606
|
+
const r = t.getAvailableFields().find((c) => c.field === o.field), a = document.createElement("div");
|
|
607
|
+
a.className = "tbw-pivot-value-label-wrapper";
|
|
608
|
+
const s = document.createElement("span");
|
|
609
|
+
s.className = "tbw-pivot-chip-label", s.textContent = r?.header ?? o.field;
|
|
517
610
|
const l = document.createElement("select");
|
|
518
611
|
l.className = "tbw-pivot-agg-select", l.title = "Aggregation function";
|
|
519
|
-
for (const c of
|
|
612
|
+
for (const c of M) {
|
|
520
613
|
const p = document.createElement("option");
|
|
521
|
-
p.value = c, p.textContent = c.toUpperCase(), p.selected = c ===
|
|
614
|
+
p.value = c, p.textContent = c.toUpperCase(), p.selected = c === o.aggFunc, l.appendChild(p);
|
|
522
615
|
}
|
|
523
616
|
l.addEventListener(
|
|
524
617
|
"change",
|
|
525
618
|
() => {
|
|
526
|
-
t.onUpdateValueAggFunc(
|
|
619
|
+
t.onUpdateValueAggFunc(o.field, l.value);
|
|
527
620
|
},
|
|
528
|
-
{ signal:
|
|
621
|
+
{ signal: i }
|
|
529
622
|
);
|
|
530
623
|
const d = document.createElement("button");
|
|
531
624
|
return d.className = "tbw-pivot-chip-remove", d.innerHTML = "×", d.title = "Remove value field", d.addEventListener(
|
|
532
625
|
"click",
|
|
533
626
|
(c) => {
|
|
534
|
-
c.stopPropagation(), t.onRemoveValueField(
|
|
627
|
+
c.stopPropagation(), t.onRemoveValueField(o.field);
|
|
535
628
|
},
|
|
536
|
-
{ signal:
|
|
537
|
-
),
|
|
629
|
+
{ signal: i }
|
|
630
|
+
), a.appendChild(s), a.appendChild(l), n.appendChild(a), n.appendChild(d), n;
|
|
538
631
|
}
|
|
539
|
-
function j(
|
|
540
|
-
const { config: e, callbacks: t, signal:
|
|
632
|
+
function j(o) {
|
|
633
|
+
const { config: e, callbacks: t, signal: i } = o, n = document.createElement("div");
|
|
541
634
|
n.className = "tbw-pivot-available-fields";
|
|
542
|
-
const r = t.getAvailableFields(),
|
|
635
|
+
const r = t.getAvailableFields(), a = /* @__PURE__ */ new Set([
|
|
543
636
|
...e.rowGroupFields ?? [],
|
|
544
637
|
...e.columnGroupFields ?? [],
|
|
545
638
|
...e.valueFields?.map((l) => l.field) ?? []
|
|
546
|
-
]),
|
|
547
|
-
if (
|
|
639
|
+
]), s = r.filter((l) => !a.has(l.field));
|
|
640
|
+
if (s.length === 0) {
|
|
548
641
|
const l = document.createElement("div");
|
|
549
642
|
l.className = "tbw-pivot-placeholder", l.textContent = "All fields are in use", n.appendChild(l);
|
|
550
643
|
} else
|
|
551
|
-
for (const l of
|
|
644
|
+
for (const l of s) {
|
|
552
645
|
const d = document.createElement("div");
|
|
553
646
|
d.className = "tbw-pivot-field-chip available", d.textContent = l.header, d.draggable = !0, d.title = `Drag to add "${l.field}" to a zone`, d.addEventListener(
|
|
554
647
|
"dragstart",
|
|
555
648
|
(c) => {
|
|
556
649
|
c.dataTransfer?.setData("text/plain", l.field), d.classList.add("dragging");
|
|
557
650
|
},
|
|
558
|
-
{ signal:
|
|
651
|
+
{ signal: i }
|
|
559
652
|
), d.addEventListener(
|
|
560
653
|
"dragend",
|
|
561
654
|
() => {
|
|
562
655
|
d.classList.remove("dragging");
|
|
563
656
|
},
|
|
564
|
-
{ signal:
|
|
657
|
+
{ signal: i }
|
|
565
658
|
), n.appendChild(d);
|
|
566
659
|
}
|
|
567
660
|
return n;
|
|
568
661
|
}
|
|
569
|
-
function
|
|
570
|
-
const { config: t, callbacks:
|
|
662
|
+
function W(o, e) {
|
|
663
|
+
const { config: t, callbacks: i, signal: n } = e, r = document.createElement("div");
|
|
571
664
|
return r.className = "tbw-pivot-options", r.appendChild(
|
|
572
|
-
|
|
665
|
+
w(
|
|
573
666
|
"Enable Pivot View",
|
|
574
|
-
|
|
575
|
-
(
|
|
576
|
-
|
|
667
|
+
o,
|
|
668
|
+
(a) => {
|
|
669
|
+
i.onTogglePivot(a);
|
|
577
670
|
},
|
|
578
671
|
n
|
|
579
672
|
)
|
|
580
673
|
), r.appendChild(
|
|
581
|
-
|
|
674
|
+
w(
|
|
582
675
|
"Show Row Totals",
|
|
583
676
|
t.showTotals ?? !0,
|
|
584
|
-
(
|
|
585
|
-
|
|
677
|
+
(a) => {
|
|
678
|
+
i.onOptionChange("showTotals", a);
|
|
586
679
|
},
|
|
587
680
|
n
|
|
588
681
|
)
|
|
589
682
|
), r.appendChild(
|
|
590
|
-
|
|
683
|
+
w(
|
|
591
684
|
"Show Grand Total",
|
|
592
685
|
t.showGrandTotal ?? !0,
|
|
593
|
-
(
|
|
594
|
-
|
|
686
|
+
(a) => {
|
|
687
|
+
i.onOptionChange("showGrandTotal", a);
|
|
595
688
|
},
|
|
596
689
|
n
|
|
597
690
|
)
|
|
598
691
|
), r;
|
|
599
692
|
}
|
|
600
|
-
function
|
|
693
|
+
function w(o, e, t, i) {
|
|
601
694
|
const n = document.createElement("label");
|
|
602
695
|
n.className = "tbw-pivot-checkbox";
|
|
603
696
|
const r = document.createElement("input");
|
|
604
|
-
r.type = "checkbox", r.checked = e, r.addEventListener("change", () => t(r.checked), { signal:
|
|
605
|
-
const
|
|
606
|
-
return
|
|
697
|
+
r.type = "checkbox", r.checked = e, r.addEventListener("change", () => t(r.checked), { signal: i });
|
|
698
|
+
const a = document.createElement("span");
|
|
699
|
+
return a.textContent = o, n.appendChild(r), n.appendChild(a), n;
|
|
607
700
|
}
|
|
608
|
-
function
|
|
609
|
-
return e.className = "pivot-group-row", e.setAttribute("data-pivot-depth", String(
|
|
701
|
+
function U(o, e, t) {
|
|
702
|
+
return e.className = "data-grid-row pivot-group-row", e.setAttribute("data-pivot-depth", String(o.__pivotDepth ?? 0)), e.setAttribute("data-pivot-key", String(o.__pivotRowKey ?? "")), e.setAttribute("role", "row"), e.innerHTML = "", t.columns.forEach((i, n) => {
|
|
610
703
|
const r = document.createElement("div");
|
|
611
|
-
if (r.className = "cell", r.setAttribute("data-col", String(n)), r.setAttribute("role", "gridcell"), n === 0) {
|
|
612
|
-
const
|
|
613
|
-
r.style.paddingLeft = `${
|
|
614
|
-
const
|
|
615
|
-
l.type = "button", l.className = "pivot-toggle", l.setAttribute("aria-label",
|
|
616
|
-
p.stopPropagation(), t.onToggle(
|
|
704
|
+
if (r.className = "cell", r.setAttribute("data-col", String(n)), r.setAttribute("data-row", String(t.rowIndex)), r.setAttribute("role", "gridcell"), n === 0) {
|
|
705
|
+
const a = Number(o.__pivotIndent) || 0;
|
|
706
|
+
r.style.paddingLeft = `${a}px`;
|
|
707
|
+
const s = String(o.__pivotRowKey), l = document.createElement("button");
|
|
708
|
+
l.type = "button", l.className = "pivot-toggle", l.setAttribute("aria-label", o.__pivotExpanded ? "Collapse group" : "Expand group"), t.setIcon(l, t.resolveIcon(o.__pivotExpanded ? "collapse" : "expand")), l.addEventListener("click", (p) => {
|
|
709
|
+
p.stopPropagation(), t.onToggle(s);
|
|
617
710
|
}), r.appendChild(l);
|
|
618
711
|
const d = document.createElement("span");
|
|
619
|
-
d.className = "pivot-label", d.textContent = String(
|
|
712
|
+
d.className = "pivot-label", d.textContent = String(o.__pivotLabel ?? ""), r.appendChild(d);
|
|
620
713
|
const c = document.createElement("span");
|
|
621
|
-
c.className = "pivot-count", c.textContent = ` (${Number(
|
|
714
|
+
c.className = "pivot-count", c.textContent = ` (${Number(o.__pivotRowCount) || 0})`, r.appendChild(c);
|
|
622
715
|
} else {
|
|
623
|
-
const
|
|
624
|
-
r.textContent =
|
|
716
|
+
const a = o[i.field];
|
|
717
|
+
r.textContent = a != null ? String(a) : "";
|
|
625
718
|
}
|
|
626
719
|
e.appendChild(r);
|
|
627
720
|
}), !0;
|
|
628
721
|
}
|
|
629
|
-
function
|
|
630
|
-
return e.className = "pivot-leaf-row", e.setAttribute("data-pivot-depth", String(
|
|
631
|
-
const
|
|
632
|
-
if (
|
|
633
|
-
const s = Number(
|
|
634
|
-
|
|
635
|
-
const
|
|
636
|
-
|
|
722
|
+
function B(o, e, t, i) {
|
|
723
|
+
return e.className = "data-grid-row pivot-leaf-row", e.setAttribute("data-pivot-depth", String(o.__pivotDepth ?? 0)), e.setAttribute("data-pivot-key", String(o.__pivotRowKey ?? "")), e.innerHTML = "", t.forEach((n, r) => {
|
|
724
|
+
const a = document.createElement("div");
|
|
725
|
+
if (a.className = "cell", a.setAttribute("data-col", String(r)), a.setAttribute("data-row", String(i)), a.setAttribute("role", "gridcell"), r === 0) {
|
|
726
|
+
const s = Number(o.__pivotIndent) || 0;
|
|
727
|
+
a.style.paddingLeft = `${s + 20}px`;
|
|
728
|
+
const l = document.createElement("span");
|
|
729
|
+
l.className = "pivot-label", l.textContent = String(o.__pivotLabel ?? ""), a.appendChild(l);
|
|
637
730
|
} else {
|
|
638
|
-
const s =
|
|
639
|
-
|
|
731
|
+
const s = o[n.field];
|
|
732
|
+
a.textContent = s != null ? String(s) : "";
|
|
640
733
|
}
|
|
641
|
-
e.appendChild(
|
|
734
|
+
e.appendChild(a);
|
|
642
735
|
}), !0;
|
|
643
736
|
}
|
|
644
|
-
function J(
|
|
645
|
-
return e.className = "pivot-grand-total-row", e.setAttribute("role", "presentation"), e.innerHTML = "", t.forEach((
|
|
737
|
+
function J(o, e, t) {
|
|
738
|
+
return e.className = "pivot-grand-total-row", e.setAttribute("role", "presentation"), e.innerHTML = "", t.forEach((i, n) => {
|
|
646
739
|
const r = document.createElement("div");
|
|
647
740
|
if (r.className = "cell", r.setAttribute("data-col", String(n)), n === 0) {
|
|
648
|
-
const
|
|
649
|
-
|
|
741
|
+
const a = document.createElement("span");
|
|
742
|
+
a.className = "pivot-label", a.textContent = "Grand Total", r.appendChild(a);
|
|
650
743
|
} else {
|
|
651
|
-
const
|
|
652
|
-
r.textContent =
|
|
744
|
+
const a = o[i.field];
|
|
745
|
+
r.textContent = a != null ? String(a) : "";
|
|
653
746
|
}
|
|
654
747
|
e.appendChild(r);
|
|
655
748
|
}), !0;
|
|
656
749
|
}
|
|
657
750
|
const Q = '.pivot-group-row{display:grid;grid-template-columns:var(--tbw-column-template);font-weight:600;background:var(--tbw-pivot-group-bg, var(--tbw-color-row-alt));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider)}.pivot-group-row:hover{background:var(--tbw-pivot-group-hover, var(--tbw-color-row-hover))}.pivot-leaf-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-pivot-leaf-bg, var(--tbw-color-bg));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider)}.pivot-grand-total-row{display:grid;grid-template-columns:var(--tbw-column-template);font-weight:700;background:var(--tbw-pivot-grand-total-bg, var(--tbw-color-header-bg));min-height:var(--tbw-row-height);border-top:2px solid var(--tbw-color-border-strong)}.pivot-grand-total-row>.cell{display:flex;align-items:center;padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}.pivot-grand-total-row>.cell:last-child{border-right:0}.pivot-grand-total-footer{position:sticky;bottom:0;z-index:var(--tbw-z-layer-pinned-rows, 20);background:var(--tbw-pivot-grand-total-bg, var(--tbw-color-header-bg));min-width:fit-content}.pivot-group-row>.cell,.pivot-leaf-row>.cell{display:flex;align-items:center;padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}.pivot-group-row>.cell:last-child,.pivot-leaf-row>.cell:last-child{border-right:0}.pivot-toggle{display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;margin-right:6px;border:none;background:transparent;cursor:pointer;color:var(--tbw-pivot-toggle-color, var(--tbw-color-fg-muted));border-radius:var(--tbw-border-radius);transition:background .15s,color .15s}.pivot-toggle:hover{background:var(--tbw-pivot-toggle-hover-bg, var(--tbw-color-row-hover));color:var(--tbw-pivot-toggle-hover-color, var(--tbw-color-fg))}.pivot-toggle:focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}.pivot-label{font-weight:inherit}.pivot-count{color:var(--tbw-pivot-count-color, var(--tbw-color-fg-muted));font-size:.9em;font-weight:400}.pivot-total-row{font-weight:700;border-top:2px solid var(--tbw-pivot-border, var(--tbw-color-border-strong))}[data-pivot-depth="1"]{--tbw-pivot-depth: 1}[data-pivot-depth="2"]{--tbw-pivot-depth: 2}[data-pivot-depth="3"]{--tbw-pivot-depth: 3}[data-pivot-depth="4"]{--tbw-pivot-depth: 4}.tbw-pivot-panel{display:flex;flex-direction:column;gap:12px;padding:12px;height:100%;overflow-y:auto;font-size:13px}.tbw-pivot-section{border:1px solid var(--tbw-pivot-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);background:var(--tbw-pivot-section-bg, var(--tbw-color-bg))}.tbw-pivot-section-header{padding:8px 12px;font-weight:600;background:var(--tbw-pivot-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-pivot-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius) var(--tbw-border-radius) 0 0}.tbw-pivot-section-content{padding:8px}.tbw-pivot-toggle-wrapper{display:flex;align-items:center}.tbw-pivot-toggle-label{display:flex;align-items:center;gap:8px;cursor:pointer}.tbw-pivot-toggle-label input{width:16px;height:16px;cursor:pointer}.tbw-pivot-drop-zone{min-height:60px;padding:8px;border:2px dashed var(--tbw-pivot-drop-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);background:var(--tbw-pivot-drop-bg, var(--tbw-color-row-alt));display:flex;flex-wrap:wrap;gap:6px;align-content:flex-start;transition:all .15s ease}.tbw-pivot-drop-zone.drag-over{border-color:var(--tbw-color-accent);background:var(--tbw-pivot-drop-active, var(--tbw-focus-background))}.tbw-pivot-placeholder{color:var(--tbw-color-fg-muted);font-style:italic;padding:8px;text-align:center;width:100%}.tbw-pivot-field-chip{display:inline-flex;align-items:center;gap:6px;padding:4px 8px;background:var(--tbw-pivot-chip-bg, var(--tbw-color-header-bg));border:1px solid var(--tbw-pivot-chip-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);cursor:grab;font-size:12px;transition:all .15s ease}.tbw-pivot-field-chip:hover{background:var(--tbw-pivot-chip-hover, var(--tbw-color-row-hover));border-color:var(--tbw-color-accent)}.tbw-pivot-field-chip.available{background:var(--tbw-color-bg)}.tbw-pivot-field-chip.dragging{opacity:.5;cursor:grabbing}.tbw-pivot-chip-label{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:120px}.tbw-pivot-chip-remove{display:flex;align-items:center;justify-content:center;width:16px;height:16px;padding:0;border:none;background:transparent;color:var(--tbw-color-fg-muted);font-size:14px;font-weight:700;cursor:pointer;border-radius:50%;transition:all .15s ease}.tbw-pivot-chip-remove:hover{background:var(--tbw-pivot-chip-remove-hover-bg, var(--tbw-color-accent));color:var(--tbw-pivot-chip-remove-hover-fg, var(--tbw-color-accent-fg))}.tbw-pivot-value-chip{padding:4px 8px}.tbw-pivot-value-label-wrapper{display:flex;align-items:center;gap:8px;flex:1;min-width:0}.tbw-pivot-agg-select{padding:2px 4px;font-size:11px;border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);cursor:pointer}.tbw-pivot-available-fields{display:flex;flex-wrap:wrap;gap:6px;min-height:40px}.tbw-pivot-options{display:flex;flex-direction:column;gap:8px}.tbw-pivot-checkbox{display:flex;align-items:center;gap:8px;cursor:pointer}.tbw-pivot-checkbox input{width:14px;height:14px;cursor:pointer}.pivot-group-row.tbw-pivot-slide-in,.pivot-leaf-row.tbw-pivot-slide-in{animation:tbw-pivot-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-pivot-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.pivot-group-row.tbw-pivot-fade-in,.pivot-leaf-row.tbw-pivot-fade-in{animation:tbw-pivot-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-pivot-fade-in{0%{opacity:0}to{opacity:1}}';
|
|
658
|
-
class
|
|
751
|
+
class v extends P {
|
|
659
752
|
name = "pivot";
|
|
660
|
-
|
|
753
|
+
styles = Q;
|
|
661
754
|
/** Tool panel ID for shell integration */
|
|
662
755
|
static PANEL_ID = "pivot";
|
|
663
756
|
get defaultConfig() {
|
|
@@ -688,17 +781,11 @@ class b extends P {
|
|
|
688
781
|
return (this.config.valueFields?.length ?? 0) > 0;
|
|
689
782
|
}
|
|
690
783
|
/**
|
|
691
|
-
* Get animation style
|
|
784
|
+
* Get expand/collapse animation style from plugin config.
|
|
785
|
+
* Uses base class isAnimationEnabled to respect grid-level settings.
|
|
692
786
|
*/
|
|
693
787
|
get animationStyle() {
|
|
694
|
-
|
|
695
|
-
if (t === !1 || t === "off") return !1;
|
|
696
|
-
if (t !== !0 && t !== "on") {
|
|
697
|
-
const o = this.shadowRoot?.host;
|
|
698
|
-
if (o && getComputedStyle(o).getPropertyValue("--tbw-animation-enabled").trim() === "0")
|
|
699
|
-
return !1;
|
|
700
|
-
}
|
|
701
|
-
return this.config.animation ?? "slide";
|
|
788
|
+
return this.isAnimationEnabled ? this.config.animation ?? "slide" : !1;
|
|
702
789
|
}
|
|
703
790
|
// #endregion
|
|
704
791
|
// #region Lifecycle
|
|
@@ -710,7 +797,7 @@ class b extends P {
|
|
|
710
797
|
getToolPanel() {
|
|
711
798
|
if ((this.config?.showToolPanel ?? this.userConfig?.showToolPanel ?? !0) !== !1)
|
|
712
799
|
return {
|
|
713
|
-
id:
|
|
800
|
+
id: v.PANEL_ID,
|
|
714
801
|
title: "Pivot",
|
|
715
802
|
icon: "⊞",
|
|
716
803
|
tooltip: "Configure pivot table",
|
|
@@ -726,55 +813,46 @@ class b extends P {
|
|
|
726
813
|
const t = S(this.config);
|
|
727
814
|
if (t.length > 0)
|
|
728
815
|
return this.warn(`Config errors: ${t.join(", ")}`), [...e];
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
for (const a of s)
|
|
732
|
-
this.expandedKeys.add(a);
|
|
733
|
-
}
|
|
734
|
-
if (this.pivotResult = I(e, this.config), this.expandedKeys.size === 0 && this.defaultExpanded) {
|
|
735
|
-
const s = w(this.pivotResult.rows);
|
|
736
|
-
for (const a of s)
|
|
737
|
-
this.expandedKeys.add(a);
|
|
738
|
-
}
|
|
739
|
-
const o = this.config.indentWidth ?? 20, n = H(
|
|
816
|
+
this.buildFieldHeaderMap(), this.defaultExpanded = this.config.defaultExpanded ?? !0, this.expandedKeys.size === 0 && this.defaultExpanded && this.pivotResult && this.expandAllKeys(), this.pivotResult = K(e, this.config), this.expandedKeys.size === 0 && this.defaultExpanded && this.expandAllKeys();
|
|
817
|
+
const i = this.config.indentWidth ?? 20, n = q(
|
|
740
818
|
this.pivotResult.rows,
|
|
741
819
|
this.expandedKeys,
|
|
742
820
|
this.defaultExpanded
|
|
743
|
-
).map((
|
|
744
|
-
__pivotRowKey:
|
|
745
|
-
__pivotLabel:
|
|
746
|
-
__pivotDepth:
|
|
747
|
-
__pivotIsGroup:
|
|
748
|
-
__pivotHasChildren: !!
|
|
749
|
-
__pivotExpanded: this.expandedKeys.has(
|
|
750
|
-
__pivotRowCount:
|
|
751
|
-
__pivotIndent:
|
|
752
|
-
__pivotTotal:
|
|
753
|
-
...
|
|
821
|
+
).map((a) => ({
|
|
822
|
+
__pivotRowKey: a.rowKey,
|
|
823
|
+
__pivotLabel: a.rowLabel,
|
|
824
|
+
__pivotDepth: a.depth,
|
|
825
|
+
__pivotIsGroup: a.isGroup,
|
|
826
|
+
__pivotHasChildren: !!a.children?.length,
|
|
827
|
+
__pivotExpanded: this.expandedKeys.has(a.rowKey),
|
|
828
|
+
__pivotRowCount: a.rowCount ?? 0,
|
|
829
|
+
__pivotIndent: a.depth * i,
|
|
830
|
+
__pivotTotal: a.total,
|
|
831
|
+
...a.values
|
|
754
832
|
}));
|
|
755
833
|
this.keysToAnimate.clear();
|
|
756
834
|
const r = /* @__PURE__ */ new Set();
|
|
757
|
-
for (const
|
|
758
|
-
const
|
|
759
|
-
r.add(
|
|
835
|
+
for (const a of n) {
|
|
836
|
+
const s = a.__pivotRowKey;
|
|
837
|
+
r.add(s), !this.previousVisibleKeys.has(s) && a.__pivotDepth > 0 && this.keysToAnimate.add(s);
|
|
760
838
|
}
|
|
761
839
|
return this.previousVisibleKeys = r, n;
|
|
762
840
|
}
|
|
763
841
|
processColumns(e) {
|
|
764
842
|
if (!this.isActive || !this.pivotResult)
|
|
765
843
|
return [...e];
|
|
766
|
-
const t = [],
|
|
844
|
+
const t = [], i = (this.config.rowGroupFields ?? []).map((n) => this.fieldHeaderMap.get(n) ?? n).join(" / ");
|
|
767
845
|
t.push({
|
|
768
846
|
field: "__pivotLabel",
|
|
769
|
-
header:
|
|
847
|
+
header: i || "Group",
|
|
770
848
|
width: 200
|
|
771
849
|
});
|
|
772
850
|
for (const n of this.pivotResult.columnKeys)
|
|
773
851
|
for (const r of this.config.valueFields ?? []) {
|
|
774
|
-
const
|
|
852
|
+
const a = x([n], r.field), s = r.header || this.fieldHeaderMap.get(r.field) || r.field;
|
|
775
853
|
t.push({
|
|
776
|
-
field:
|
|
777
|
-
header: `${n} - ${
|
|
854
|
+
field: a,
|
|
855
|
+
header: `${n} - ${s} (${r.aggFunc})`,
|
|
778
856
|
width: 120,
|
|
779
857
|
type: "number"
|
|
780
858
|
});
|
|
@@ -786,14 +864,15 @@ class b extends P {
|
|
|
786
864
|
type: "number"
|
|
787
865
|
}), t;
|
|
788
866
|
}
|
|
789
|
-
renderRow(e, t) {
|
|
790
|
-
const
|
|
791
|
-
return
|
|
867
|
+
renderRow(e, t, i) {
|
|
868
|
+
const n = e;
|
|
869
|
+
return n.__pivotRowKey && n.__pivotHasChildren ? U(n, t, {
|
|
792
870
|
columns: this.gridColumns,
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
871
|
+
rowIndex: i,
|
|
872
|
+
onToggle: (r) => this.toggle(r),
|
|
873
|
+
resolveIcon: (r) => this.resolveIcon(r),
|
|
874
|
+
setIcon: (r, a) => this.setIcon(r, a)
|
|
875
|
+
}) : n.__pivotRowKey !== void 0 && this.isActive ? B(n, t, this.gridColumns, i) : (this.cleanupPivotStyling(t), !1);
|
|
797
876
|
}
|
|
798
877
|
/**
|
|
799
878
|
* Remove pivot-specific classes, attributes, and inline styles from a row element.
|
|
@@ -803,16 +882,22 @@ class b extends P {
|
|
|
803
882
|
cleanupPivotStyling(e) {
|
|
804
883
|
(e.classList.contains("pivot-group-row") || e.classList.contains("pivot-leaf-row") || e.classList.contains("pivot-grand-total-row")) && (e.classList.remove("pivot-group-row", "pivot-leaf-row", "pivot-grand-total-row"), e.classList.add("data-grid-row"), e.removeAttribute("data-pivot-depth"), e.innerHTML = "");
|
|
805
884
|
}
|
|
885
|
+
onKeyDown(e) {
|
|
886
|
+
if (e.key !== " " || !this.isActive) return;
|
|
887
|
+
const t = this.grid._focusRow, i = this.rows[t];
|
|
888
|
+
if (!(!i?.__pivotIsGroup || !i.__pivotHasChildren))
|
|
889
|
+
return e.preventDefault(), this.toggle(i.__pivotRowKey), this.requestRenderWithFocus(), !0;
|
|
890
|
+
}
|
|
806
891
|
afterRender() {
|
|
807
892
|
this.isActive && this.config.showGrandTotal && this.pivotResult ? this.renderGrandTotalFooter() : this.cleanupGrandTotalFooter();
|
|
808
893
|
const e = this.animationStyle;
|
|
809
894
|
if (e === !1 || this.keysToAnimate.size === 0) return;
|
|
810
895
|
const t = this.shadowRoot?.querySelector(".rows");
|
|
811
896
|
if (!t) return;
|
|
812
|
-
const
|
|
897
|
+
const i = e === "fade" ? "tbw-pivot-fade-in" : "tbw-pivot-slide-in";
|
|
813
898
|
for (const n of t.querySelectorAll(".pivot-group-row, .pivot-leaf-row")) {
|
|
814
899
|
const r = n.dataset.pivotKey;
|
|
815
|
-
r && this.keysToAnimate.has(r) && (n.classList.add(
|
|
900
|
+
r && this.keysToAnimate.has(r) && (n.classList.add(i), n.addEventListener("animationend", () => n.classList.remove(i), { once: !0 }));
|
|
816
901
|
}
|
|
817
902
|
this.keysToAnimate.clear();
|
|
818
903
|
}
|
|
@@ -826,14 +911,14 @@ class b extends P {
|
|
|
826
911
|
const t = e.querySelector(".tbw-scroll-area") ?? e.querySelector(".tbw-grid-content") ?? e.children[0];
|
|
827
912
|
if (!t) return;
|
|
828
913
|
this.grandTotalFooter || (this.grandTotalFooter = document.createElement("div"), this.grandTotalFooter.className = "pivot-grand-total-footer", t.appendChild(this.grandTotalFooter));
|
|
829
|
-
const
|
|
914
|
+
const i = {
|
|
830
915
|
__pivotRowKey: "__grandTotal",
|
|
831
916
|
__pivotLabel: "Grand Total",
|
|
832
917
|
__pivotIsGrandTotal: !0,
|
|
833
918
|
__pivotTotal: this.pivotResult.grandTotal,
|
|
834
919
|
...this.pivotResult.totals
|
|
835
920
|
};
|
|
836
|
-
J(
|
|
921
|
+
J(i, this.grandTotalFooter, this.gridColumns);
|
|
837
922
|
}
|
|
838
923
|
/**
|
|
839
924
|
* Remove the grand total footer element.
|
|
@@ -853,16 +938,20 @@ class b extends P {
|
|
|
853
938
|
this.expandedKeys.delete(e), this.requestRender();
|
|
854
939
|
}
|
|
855
940
|
expandAll() {
|
|
856
|
-
|
|
857
|
-
const e = w(this.pivotResult.rows);
|
|
858
|
-
for (const t of e)
|
|
859
|
-
this.expandedKeys.add(t);
|
|
860
|
-
this.requestRender();
|
|
861
|
-
}
|
|
941
|
+
this.expandAllKeys(), this.requestRender();
|
|
862
942
|
}
|
|
863
943
|
collapseAll() {
|
|
864
944
|
this.expandedKeys.clear(), this.requestRender();
|
|
865
945
|
}
|
|
946
|
+
/**
|
|
947
|
+
* Add all group keys from the current pivot result to expandedKeys.
|
|
948
|
+
*/
|
|
949
|
+
expandAllKeys() {
|
|
950
|
+
if (!this.pivotResult) return;
|
|
951
|
+
const e = H(this.pivotResult.rows);
|
|
952
|
+
for (const t of e)
|
|
953
|
+
this.expandedKeys.add(t);
|
|
954
|
+
}
|
|
866
955
|
isExpanded(e) {
|
|
867
956
|
return this.expandedKeys.has(e);
|
|
868
957
|
}
|
|
@@ -894,23 +983,42 @@ class b extends P {
|
|
|
894
983
|
}
|
|
895
984
|
// #endregion
|
|
896
985
|
// #region Tool Panel API
|
|
986
|
+
/**
|
|
987
|
+
* Show the pivot tool panel.
|
|
988
|
+
* Opens the tool panel and ensures this section is expanded.
|
|
989
|
+
*/
|
|
897
990
|
showPanel() {
|
|
898
|
-
this.grid.openToolPanel(
|
|
991
|
+
this.grid.openToolPanel(), this.grid.expandedToolPanelSections.includes(v.PANEL_ID) || this.grid.toggleToolPanelSection(v.PANEL_ID);
|
|
899
992
|
}
|
|
993
|
+
/**
|
|
994
|
+
* Hide the tool panel.
|
|
995
|
+
*/
|
|
900
996
|
hidePanel() {
|
|
901
997
|
this.grid.closeToolPanel();
|
|
902
998
|
}
|
|
999
|
+
/**
|
|
1000
|
+
* Toggle the pivot tool panel section.
|
|
1001
|
+
*/
|
|
903
1002
|
togglePanel() {
|
|
904
|
-
this.grid.
|
|
1003
|
+
this.grid.isToolPanelOpen || this.grid.openToolPanel(), this.grid.toggleToolPanelSection(v.PANEL_ID);
|
|
905
1004
|
}
|
|
1005
|
+
/**
|
|
1006
|
+
* Check if the pivot panel section is currently expanded.
|
|
1007
|
+
*/
|
|
906
1008
|
isPanelVisible() {
|
|
907
|
-
return this.grid.
|
|
1009
|
+
return this.grid.isToolPanelOpen && this.grid.expandedToolPanelSections.includes(v.PANEL_ID);
|
|
908
1010
|
}
|
|
909
1011
|
// #endregion
|
|
910
1012
|
// #region Private Helpers
|
|
911
1013
|
get gridColumns() {
|
|
912
1014
|
return this.grid.columns ?? [];
|
|
913
1015
|
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Refresh pivot and update tool panel if active.
|
|
1018
|
+
*/
|
|
1019
|
+
refreshIfActive() {
|
|
1020
|
+
this.isActive && this.refresh(), this.refreshPanel();
|
|
1021
|
+
}
|
|
914
1022
|
buildFieldHeaderMap() {
|
|
915
1023
|
const e = this.getAvailableFields();
|
|
916
1024
|
this.fieldHeaderMap.clear();
|
|
@@ -921,12 +1029,11 @@ class b extends P {
|
|
|
921
1029
|
return this.originalColumns.length > 0 ? this.originalColumns : this.captureOriginalColumns();
|
|
922
1030
|
}
|
|
923
1031
|
captureOriginalColumns() {
|
|
924
|
-
const e = this.grid;
|
|
925
1032
|
try {
|
|
926
|
-
const
|
|
927
|
-
return this.originalColumns =
|
|
928
|
-
field:
|
|
929
|
-
header:
|
|
1033
|
+
const e = this.grid.getAllColumns?.() ?? this.grid.columns ?? [];
|
|
1034
|
+
return this.originalColumns = e.filter((t) => !t.field.startsWith("__pivot")).map((t) => ({
|
|
1035
|
+
field: t.field,
|
|
1036
|
+
header: t.header ?? t.field
|
|
930
1037
|
})), this.originalColumns;
|
|
931
1038
|
} catch {
|
|
932
1039
|
return [];
|
|
@@ -935,16 +1042,16 @@ class b extends P {
|
|
|
935
1042
|
renderPanel(e) {
|
|
936
1043
|
this.panelContainer = e, this.originalColumns.length === 0 && this.captureOriginalColumns();
|
|
937
1044
|
const t = {
|
|
938
|
-
onTogglePivot: (
|
|
939
|
-
|
|
1045
|
+
onTogglePivot: (i) => {
|
|
1046
|
+
i ? this.enablePivot() : this.disablePivot(), this.refreshPanel();
|
|
940
1047
|
},
|
|
941
|
-
onAddFieldToZone: (
|
|
942
|
-
onRemoveFieldFromZone: (
|
|
943
|
-
onAddValueField: (
|
|
944
|
-
onRemoveValueField: (
|
|
945
|
-
onUpdateValueAggFunc: (
|
|
946
|
-
onOptionChange: (
|
|
947
|
-
this.config[
|
|
1048
|
+
onAddFieldToZone: (i, n) => this.addFieldToZone(i, n),
|
|
1049
|
+
onRemoveFieldFromZone: (i, n) => this.removeFieldFromZone(i, n),
|
|
1050
|
+
onAddValueField: (i, n) => this.addValueField(i, n),
|
|
1051
|
+
onRemoveValueField: (i) => this.removeValueField(i),
|
|
1052
|
+
onUpdateValueAggFunc: (i, n) => this.updateValueAggFunc(i, n),
|
|
1053
|
+
onOptionChange: (i, n) => {
|
|
1054
|
+
this.config[i] = n, this.isActive && this.refresh();
|
|
948
1055
|
},
|
|
949
1056
|
getAvailableFields: () => this.getAvailableFields()
|
|
950
1057
|
};
|
|
@@ -955,37 +1062,34 @@ class b extends P {
|
|
|
955
1062
|
}
|
|
956
1063
|
addFieldToZone(e, t) {
|
|
957
1064
|
if (t === "rowGroups") {
|
|
958
|
-
const
|
|
959
|
-
|
|
1065
|
+
const i = this.config.rowGroupFields ?? [];
|
|
1066
|
+
i.includes(e) || (this.config.rowGroupFields = [...i, e]);
|
|
960
1067
|
} else {
|
|
961
|
-
const
|
|
962
|
-
|
|
1068
|
+
const i = this.config.columnGroupFields ?? [];
|
|
1069
|
+
i.includes(e) || (this.config.columnGroupFields = [...i, e]);
|
|
963
1070
|
}
|
|
964
|
-
this.removeFromOtherZones(e, t), this.
|
|
1071
|
+
this.removeFromOtherZones(e, t), this.refreshIfActive();
|
|
965
1072
|
}
|
|
966
1073
|
removeFieldFromZone(e, t) {
|
|
967
|
-
t === "rowGroups" ? this.config.rowGroupFields = (this.config.rowGroupFields ?? []).filter((
|
|
1074
|
+
t === "rowGroups" ? this.config.rowGroupFields = (this.config.rowGroupFields ?? []).filter((i) => i !== e) : this.config.columnGroupFields = (this.config.columnGroupFields ?? []).filter((i) => i !== e), this.refreshIfActive();
|
|
968
1075
|
}
|
|
969
1076
|
removeFromOtherZones(e, t) {
|
|
970
|
-
t !== "rowGroups" && (this.config.rowGroupFields = (this.config.rowGroupFields ?? []).filter((
|
|
1077
|
+
t !== "rowGroups" && (this.config.rowGroupFields = (this.config.rowGroupFields ?? []).filter((i) => i !== e)), t !== "columnGroups" && (this.config.columnGroupFields = (this.config.columnGroupFields ?? []).filter((i) => i !== e)), t !== "values" && (this.config.valueFields = (this.config.valueFields ?? []).filter((i) => i.field !== e));
|
|
971
1078
|
}
|
|
972
1079
|
addValueField(e, t) {
|
|
973
|
-
const
|
|
974
|
-
|
|
1080
|
+
const i = this.config.valueFields ?? [];
|
|
1081
|
+
i.some((n) => n.field === e) || (this.config.valueFields = [...i, { field: e, aggFunc: t }]), this.removeFromOtherZones(e, "values"), this.refreshIfActive();
|
|
975
1082
|
}
|
|
976
1083
|
removeValueField(e) {
|
|
977
|
-
this.config.valueFields = (this.config.valueFields ?? []).filter((t) => t.field !== e), this.
|
|
1084
|
+
this.config.valueFields = (this.config.valueFields ?? []).filter((t) => t.field !== e), this.refreshIfActive();
|
|
978
1085
|
}
|
|
979
1086
|
updateValueAggFunc(e, t) {
|
|
980
|
-
const
|
|
981
|
-
n >= 0 && (
|
|
1087
|
+
const i = this.config.valueFields ?? [], n = i.findIndex((r) => r.field === e);
|
|
1088
|
+
n >= 0 && (i[n] = { ...i[n], aggFunc: t }, this.config.valueFields = [...i]), this.isActive && this.refresh();
|
|
982
1089
|
}
|
|
983
1090
|
// #endregion
|
|
984
|
-
// #region Styles
|
|
985
|
-
styles = Q;
|
|
986
|
-
// #endregion
|
|
987
1091
|
}
|
|
988
1092
|
export {
|
|
989
|
-
|
|
1093
|
+
v as PivotPlugin
|
|
990
1094
|
};
|
|
991
1095
|
//# sourceMappingURL=index.js.map
|