@toolbox-web/grid 1.30.2 → 1.31.0
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.js +2 -2
- package/all.js.map +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/lib/core/internal/dom-builder.d.ts +3 -3
- package/lib/core/plugin/base-plugin.d.ts +31 -8
- package/lib/core/plugin/plugin-manager.d.ts +2 -2
- package/lib/core/types.d.ts +16 -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/editing/index.js +1 -1
- package/lib/plugins/editing/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 +1 -1
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/index.js +2 -2
- 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/MultiSortPlugin.d.ts +8 -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 +1 -1
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/PivotPlugin.d.ts +43 -1
- package/lib/plugins/pivot/index.d.ts +1 -1
- package/lib/plugins/pivot/index.js +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/pivot/pivot-engine.d.ts +21 -2
- package/lib/plugins/pivot/pivot-model.d.ts +6 -3
- package/lib/plugins/pivot/pivot-panel.d.ts +8 -3
- package/lib/plugins/pivot/pivot-rows.d.ts +3 -3
- package/lib/plugins/pivot/types.d.ts +121 -8
- package/lib/plugins/print/index.js +1 -1
- package/lib/plugins/print/index.js.map +1 -1
- package/lib/plugins/reorder-columns/index.js +1 -1
- package/lib/plugins/reorder-columns/index.js.map +1 -1
- package/lib/plugins/reorder-rows/index.js +1 -1
- package/lib/plugins/reorder-rows/index.js.map +1 -1
- package/lib/plugins/responsive/index.js +1 -1
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/selection/index.js +1 -1
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/tooltip/index.js +1 -1
- package/lib/plugins/tooltip/index.js.map +1 -1
- package/lib/plugins/tree/index.js +1 -1
- 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/themes/dg-theme-bootstrap.css +8 -1
- package/themes/dg-theme-large.css +3 -1
- package/themes/dg-theme-material.css +3 -1
- package/themes/dg-theme-standard.css +5 -0
- package/themes/dg-theme-vibrant.css +5 -0
- package/umd/grid.all.umd.js +1 -1
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +1 -1
- package/umd/grid.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/filtering.umd.js +1 -1
- package/umd/plugins/filtering.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/pivot.umd.js +1 -1
- package/umd/plugins/pivot.umd.js.map +1 -1
- package/umd/plugins/print.umd.js +1 -1
- package/umd/plugins/print.umd.js.map +1 -1
- package/umd/plugins/reorder-rows.umd.js +1 -1
- package/umd/plugins/reorder-rows.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/visibility.umd.js +1 -1
- package/umd/plugins/visibility.umd.js.map +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseGridPlugin, PluginManifest } from '../../core/plugin/base-plugin';
|
|
1
|
+
import { BaseGridPlugin, HeaderClickEvent, PluginManifest, PluginQuery } from '../../core/plugin/base-plugin';
|
|
2
2
|
import { ColumnConfig, ToolPanelDefinition } from '../../core/types';
|
|
3
3
|
import { PivotDataRow } from './pivot-engine';
|
|
4
4
|
import { PivotConfig, PivotResult, PivotValueField } from './types';
|
|
@@ -84,6 +84,13 @@ export declare class PivotPlugin extends BaseGridPlugin<PivotConfig> {
|
|
|
84
84
|
private grandTotalFooter;
|
|
85
85
|
private previousVisibleKeys;
|
|
86
86
|
private keysToAnimate;
|
|
87
|
+
/** Cached value formatters keyed by value field name */
|
|
88
|
+
private valueFormatters;
|
|
89
|
+
/** Column totals for percentage mode */
|
|
90
|
+
private columnTotals;
|
|
91
|
+
/** Current interactive sort state for pivot columns (managed by onHeaderClick) */
|
|
92
|
+
private activeSortField;
|
|
93
|
+
private activeSortDir;
|
|
87
94
|
/**
|
|
88
95
|
* Check if the plugin has valid pivot configuration (at least value fields).
|
|
89
96
|
*/
|
|
@@ -112,7 +119,28 @@ export declare class PivotPlugin extends BaseGridPlugin<PivotConfig> {
|
|
|
112
119
|
/** @internal */
|
|
113
120
|
onKeyDown(event: KeyboardEvent): boolean | void;
|
|
114
121
|
/** @internal */
|
|
122
|
+
handleQuery(query: PluginQuery): unknown;
|
|
123
|
+
/** @internal */
|
|
124
|
+
onHeaderClick(event: HeaderClickEvent): boolean;
|
|
125
|
+
/** Check if a field belongs to a pivot-generated column. */
|
|
126
|
+
private isPivotField;
|
|
127
|
+
/** Check whether the MultiSort plugin is loaded alongside Pivot. */
|
|
128
|
+
private isMultiSortActive;
|
|
129
|
+
/**
|
|
130
|
+
* Read MultiSort's sort model and translate entries to PivotSortConfig[].
|
|
131
|
+
* Returns null when MultiSort is not present or has no active sorts.
|
|
132
|
+
*/
|
|
133
|
+
private getMultiSortConfigs;
|
|
134
|
+
/** Map a pivot column field to the appropriate PivotSortConfig (without direction). */
|
|
135
|
+
private mapFieldToSortConfig;
|
|
136
|
+
/** @internal */
|
|
115
137
|
afterRender(): void;
|
|
138
|
+
/**
|
|
139
|
+
* Update sort indicator icons on pivot header cells.
|
|
140
|
+
* Core's indicator rendering reads `_sortState`, which doesn't reflect pivot sort.
|
|
141
|
+
* We manage indicators directly, following the same pattern as MultiSortPlugin.
|
|
142
|
+
*/
|
|
143
|
+
private updateSortIndicators;
|
|
116
144
|
/**
|
|
117
145
|
* Render the grand total row as a sticky footer pinned to the bottom.
|
|
118
146
|
*/
|
|
@@ -153,6 +181,12 @@ export declare class PivotPlugin extends BaseGridPlugin<PivotConfig> {
|
|
|
153
181
|
* @returns `true` if the group is expanded
|
|
154
182
|
*/
|
|
155
183
|
isExpanded(key: string): boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Get all currently expanded group keys.
|
|
186
|
+
*
|
|
187
|
+
* @returns Array of expanded pivot row keys
|
|
188
|
+
*/
|
|
189
|
+
getExpandedGroups(): string[];
|
|
156
190
|
/**
|
|
157
191
|
* Enable pivot mode.
|
|
158
192
|
*
|
|
@@ -269,8 +303,16 @@ export declare class PivotPlugin extends BaseGridPlugin<PivotConfig> {
|
|
|
269
303
|
private refreshPanel;
|
|
270
304
|
private addFieldToZone;
|
|
271
305
|
private removeFieldFromZone;
|
|
306
|
+
private reorderFieldInZone;
|
|
307
|
+
private moveFieldBetweenZones;
|
|
272
308
|
private removeFromOtherZones;
|
|
273
309
|
private addValueField;
|
|
274
310
|
private removeValueField;
|
|
275
311
|
private updateValueAggFunc;
|
|
312
|
+
private emitToggle;
|
|
313
|
+
private emitConfigChange;
|
|
314
|
+
/**
|
|
315
|
+
* Build value formatters from PivotValueField.format or original column format.
|
|
316
|
+
*/
|
|
317
|
+
private buildValueFormatters;
|
|
276
318
|
}
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export type { PivotDataRow } from './pivot-engine';
|
|
8
8
|
export { PivotPlugin } from './PivotPlugin';
|
|
9
|
-
export type { AggFunc, PivotConfig, PivotResult, PivotRow, PivotValueField } from './types';
|
|
9
|
+
export type { AggFunc, CustomAggFunc, PivotConfig, PivotConfigChangeDetail, PivotDefaultExpandedValue, PivotResult, PivotRow, PivotSortConfig, PivotSortDir, PivotStateChangeDetail, PivotToggleDetail, PivotValueDisplayMode, PivotValueField, } from './types';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function t(t,i,o,r){return`${e(o,r)} ${t}: ${i}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(t)}`}const i=/* @__PURE__ */new Set(["script","iframe","object","embed","form","input","button","textarea","select","link","meta","base","style","template","slot","portal","frame","frameset","applet","noscript","noembed","plaintext","xmp","listing"]),o=/^on\w+$/i,r=/* @__PURE__ */new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),n=/^\s*(javascript|vbscript|data|blob):/i;function a(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],a=e.querySelectorAll("*");for(const s of a){const e=s.tagName.toLowerCase();if(i.has(e)){t.push(s);continue}if("svg"===e||"http://www.w3.org/2000/svg"===s.namespaceURI){if(Array.from(s.attributes).some(e=>o.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(s);continue}}const a=[];for(const t of s.attributes){const e=t.name.toLowerCase();o.test(e)?a.push(t.name):(r.has(e)&&n.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&a.push(t.name)}a.forEach(e=>s.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}const s='<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>',l={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:s,filterActive:s,print:"🖨️"};class d{static dependencies;static manifest;aliases;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const i=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...l,...e}}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(t,10);if(!isNaN(i))return i}return 200}resolveIcon(e,t){return void 0!==t?t:this.gridIcons[e]}setIcon(e,t){"string"==typeof t?e.innerHTML=a(t):t instanceof HTMLElement&&(e.innerHTML="",e.appendChild(t.cloneNode(!0)))}warn(i,o){void 0!==o?console.warn(t(i,o,this.gridElement.id,this.name)):console.warn(`${e(this.gridElement.id,this.name)} ${i}`)}throwDiagnostic(e,i){throw new Error(t(e,i,this.gridElement.id,this.name))}}const c={sum:(e,t)=>e.reduce((e,i)=>e+(Number(i[t])||0),0),avg:(e,t)=>{const i=e.reduce((e,i)=>e+(Number(i[t])||0),0);return e.length?i/e.length:0},count:e=>e.length,min:(e,t)=>e.length?Math.min(...e.map(e=>Number(e[t])||1/0)):0,max:(e,t)=>e.length?Math.max(...e.map(e=>Number(e[t])||-1/0)):0,first:(e,t)=>e[0]?.[t],last:(e,t)=>e[e.length-1]?.[t]},p=/* @__PURE__ */new Map,u={register(e,t){p.set(e,t)},unregister(e){p.delete(e)},get(e){if(void 0!==e)return"function"==typeof e?e:p.get(e)??c[e]},run(e,t,i,o){const r=this.get(e);return r?r(t,i,o):void 0},has:e=>p.has(e)||e in c,list:()=>[...Object.keys(c),...p.keys()]},g={sum:e=>e.reduce((e,t)=>e+t,0),avg:e=>e.length?e.reduce((e,t)=>e+t,0)/e.length:0,count:e=>e.length,min:e=>e.length?Math.min(...e):0,max:e=>e.length?Math.max(...e):0,first:e=>e[0]??0,last:e=>e[e.length-1]??0};u.register.bind(u),u.unregister.bind(u),u.get.bind(u),u.run.bind(u),u.list.bind(u);const h=function(e){return g[e]??g.sum};function v(e,t){return[...e,t].join("|")}function b(e,t){const i=t.rowGroupFields??[],o=t.columnGroupFields??[],r=t.valueFields??[],n=function(e,t){if(0===t.length)return["value"];const i=/* @__PURE__ */new Set;for(const o of e){const e=t.map(e=>String(o[e]??"")).join("|");i.add(e)}return[...i].sort()}(e,o),a=f(e,i,o,n,r,0,""),s=function(e,t,i){const o={};function r(e){for(const n of e)if(n.isGroup&&n.children?.length)n.children&&r(n.children);else for(const e of t)for(const t of i){const i=v([e],t.field);o[i]=(o[i]??0)+(n.values[i]??0)}}return r(e),o}(a,n,r);return{rows:a,columnKeys:n,totals:s,grandTotal:Object.values(s).reduce((e,t)=>e+t,0)}}function f(e,t,i,o,r,n,a){const s=[];if(0===t.length){const t=m(e,i,o,r),l=w(t);return s.push({rowKey:a||"all",rowLabel:a||"All",depth:n,values:t,total:l,isGroup:!1,rowCount:e.length}),s}const l=t[0],d=t.slice(1),c=d.length>0,p=function(e,t){const i=/* @__PURE__ */new Map;for(const o of e){const e=String(o[t]??""),r=i.get(e);r?r.push(o):i.set(e,[o])}return i}(e,l);for(const[u,g]of p){const e=a?`${a}|${u}`:u,t=m(g,i,o,r),l=w(t);let p;c&&(p=f(g,d,i,o,r,n+1,e)),s.push({rowKey:e,rowLabel:u||"(blank)",depth:n,values:t,total:l,isGroup:c,children:p,rowCount:g.length})}return s}function m(e,t,i,o){const r={};for(const n of i)for(const i of o){const o=(t.length>0?e.filter(e=>t.map(t=>String(e[t]??"")).join("|")===n):e).map(e=>Number(e[i.field])||0),a=h(i.aggFunc),s=o.length>0?a(o):null;r[v([n],i.field)]=s}return r}function w(e){let t=0;for(const i of Object.values(e))t+=i??0;return t}const x="dragging",C=["sum","avg","count","min","max","first","last"];function y(e,t,i,o){const r=new AbortController,n={config:t,callbacks:o,signal:r.signal},a=document.createElement("div");return a.className="tbw-pivot-panel",a.appendChild(E("Options",()=>function(e,t){const{config:i,callbacks:o,signal:r}=t,n=document.createElement("div");return n.className="tbw-pivot-options",n.appendChild(T("Enable Pivot View",e,e=>{o.onTogglePivot(e)},r)),n.appendChild(T("Show Row Totals",i.showTotals??!0,e=>{o.onOptionChange("showTotals",e)},r)),n.appendChild(T("Show Grand Total",i.showGrandTotal??!0,e=>{o.onOptionChange("showGrandTotal",e)},r)),n}(i,n))),a.appendChild(E("Row Groups",()=>F("rowGroups",n))),a.appendChild(E("Column Groups",()=>F("columnGroups",n))),a.appendChild(E("Values",()=>function(e){const{config:t,callbacks:i,signal:o}=e,r=document.createElement("div");r.className="tbw-pivot-drop-zone tbw-pivot-values-zone",r.setAttribute("data-zone","values");const n=t.valueFields??[];if(0===n.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="Drag numeric fields here for aggregation",r.appendChild(e)}else for(const a of n)r.appendChild(A(a,e));return r.addEventListener("dragover",e=>{e.preventDefault(),r.classList.add("drag-over")},{signal:o}),r.addEventListener("dragleave",()=>{r.classList.remove("drag-over")},{signal:o}),r.addEventListener("drop",e=>{e.preventDefault(),r.classList.remove("drag-over");const t=e.dataTransfer?.getData("text/plain");t&&i.onAddValueField(t,"sum")},{signal:o}),r}(n))),a.appendChild(E("Available Fields",()=>function(e){const{config:t,callbacks:i,signal:o}=e,r=document.createElement("div");r.className="tbw-pivot-available-fields";const n=i.getAvailableFields(),a=/* @__PURE__ */new Set([...t.rowGroupFields??[],...t.columnGroupFields??[],...t.valueFields?.map(e=>e.field)??[]]),s=n.filter(e=>!a.has(e.field));if(0===s.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="All fields are in use",r.appendChild(e)}else for(const l of s){const e=document.createElement("div");e.className="tbw-pivot-field-chip available",e.textContent=l.header,e.draggable=!0,e.title=`Drag to add "${l.field}" to a zone`,e.addEventListener("dragstart",t=>{t.dataTransfer?.setData("text/plain",l.field),e.classList.add(x)},{signal:o}),e.addEventListener("dragend",()=>{e.classList.remove(x)},{signal:o}),r.appendChild(e)}return r}(n))),e.appendChild(a),()=>{r.abort(),a.remove()}}function E(e,t){const i=document.createElement("div");i.className="tbw-pivot-section";const o=document.createElement("div");o.className="tbw-pivot-section-header",o.textContent=e;const r=document.createElement("div");return r.className="tbw-pivot-section-content",r.appendChild(t()),i.appendChild(o),i.appendChild(r),i}function F(e,t){const{config:i,callbacks:o,signal:r}=t,n=document.createElement("div");n.className="tbw-pivot-drop-zone",n.setAttribute("data-zone",e);const a="rowGroups"===e?i.rowGroupFields??[]:i.columnGroupFields??[];if(0===a.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="Drag fields here or click to add",n.appendChild(e)}else for(const s of a)n.appendChild(_(s,e,t));return n.addEventListener("dragover",e=>{e.preventDefault(),n.classList.add("drag-over")},{signal:r}),n.addEventListener("dragleave",()=>{n.classList.remove("drag-over")},{signal:r}),n.addEventListener("drop",t=>{t.preventDefault(),n.classList.remove("drag-over");const i=t.dataTransfer?.getData("text/plain");i&&o.onAddFieldToZone(i,e)},{signal:r}),n}function _(e,t,i){const{callbacks:o,signal:r}=i,n=document.createElement("div");n.className="tbw-pivot-field-chip",n.draggable=!0;const a=o.getAvailableFields().find(t=>t.field===e),s=document.createElement("span");s.className="tbw-pivot-chip-label",s.textContent=a?.header??e;const l=document.createElement("button");return l.className="tbw-pivot-chip-remove",l.innerHTML="×",l.title="Remove field",l.addEventListener("click",i=>{i.stopPropagation(),o.onRemoveFieldFromZone(e,t)},{signal:r}),n.appendChild(s),n.appendChild(l),n.addEventListener("dragstart",i=>{i.dataTransfer?.setData("text/plain",e),i.dataTransfer?.setData("source-zone",t),n.classList.add(x)},{signal:r}),n.addEventListener("dragend",()=>{n.classList.remove(x)},{signal:r}),n}function A(e,t){const{callbacks:i,signal:o}=t,r=document.createElement("div");r.className="tbw-pivot-field-chip tbw-pivot-value-chip";const n=i.getAvailableFields().find(t=>t.field===e.field),a=document.createElement("div");a.className="tbw-pivot-value-label-wrapper";const s=document.createElement("span");s.className="tbw-pivot-chip-label",s.textContent=n?.header??e.field;const l=document.createElement("select");l.className="tbw-pivot-agg-select",l.title="Aggregation function";for(const c of C){const t=document.createElement("option");t.value=c,t.textContent=c.toUpperCase(),t.selected=c===e.aggFunc,l.appendChild(t)}l.addEventListener("change",()=>{i.onUpdateValueAggFunc(e.field,l.value)},{signal:o});const d=document.createElement("button");return d.className="tbw-pivot-chip-remove",d.innerHTML="×",d.title="Remove value field",d.addEventListener("click",t=>{t.stopPropagation(),i.onRemoveValueField(e.field)},{signal:o}),a.appendChild(s),a.appendChild(l),r.appendChild(a),r.appendChild(d),r}function T(e,t,i,o){const r=document.createElement("label");r.className="tbw-pivot-checkbox";const n=document.createElement("input");n.type="checkbox",n.checked=t,n.addEventListener("change",()=>i(n.checked),{signal:o});const a=document.createElement("span");return a.textContent=e,r.appendChild(n),r.appendChild(a),r}class R extends d{static manifest={incompatibleWith:[{name:"groupingRows",reason:"PivotPlugin creates its own aggregated row and column structure. Row grouping cannot be applied on top of pivot-generated rows."},{name:"tree",reason:"PivotPlugin replaces the entire row and column structure with aggregated pivot data. Tree hierarchy cannot coexist with pivot aggregation."},{name:"serverSide",reason:"PivotPlugin requires the full dataset to compute aggregations. ServerSidePlugin lazy-loads rows in blocks, so pivot aggregation cannot be performed client-side."}]};name="pivot";styles='@layer tbw-plugins{.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)}@media(hover:hover){.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:var(--tbw-pivot-toggle-size, var(--tbw-toggle-size, 1.25em));height:var(--tbw-pivot-toggle-size, var(--tbw-toggle-size, 1.25em));margin-right:var(--tbw-spacing-sm, .375em);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 var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease),color var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease)}.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:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));padding:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));height:100%;overflow-y:auto;font-size:var(--tbw-font-size-sm, .8125rem)}.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:var(--tbw-button-padding, var(--tbw-spacing-md, .5rem) var(--tbw-spacing-lg, .75rem));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:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-pivot-toggle-wrapper{display:flex;align-items:center}.tbw-pivot-toggle-label{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));cursor:pointer}.tbw-pivot-toggle-label input{width:var(--tbw-icon-size, 1rem);height:var(--tbw-icon-size, 1rem);cursor:pointer}.tbw-pivot-drop-zone{min-height:60px;padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));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:var(--tbw-spacing-sm, .375rem);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:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));text-align:center;width:100%}.tbw-pivot-field-chip{display:inline-flex;align-items:center;gap:var(--tbw-spacing-sm, .375rem);padding:var(--tbw-button-padding-sm, var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-md, .5rem));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:var(--tbw-font-size-xs, .75rem);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:var(--tbw-icon-size, 1rem);height:var(--tbw-icon-size, 1rem);padding:0;border:none;background:transparent;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-sm, .875rem);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:var(--tbw-button-padding-sm, var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-md, .5rem))}.tbw-pivot-value-label-wrapper{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));flex:1;min-width:0}.tbw-pivot-agg-select{padding:var(--tbw-spacing-xs, .125rem) var(--tbw-spacing-xs, .25rem);font-size:var(--tbw-font-size-xs, .6875rem);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:var(--tbw-spacing-sm, .375rem);min-height:40px}.tbw-pivot-options{display:flex;flex-direction:column;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-pivot-checkbox{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));cursor:pointer}.tbw-pivot-checkbox input{width:var(--tbw-icon-size-sm, .875rem);height:var(--tbw-icon-size-sm, .875rem);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}}}';static PANEL_ID="pivot";get defaultConfig(){return{active:!0,showTotals:!0,showGrandTotal:!0,showToolPanel:!0,animation:"slide"}}isActive=!1;hasInitialized=!1;pivotResult=null;fieldHeaderMap=/* @__PURE__ */new Map;expandedKeys=/* @__PURE__ */new Set;defaultExpanded=!0;userHasToggledExpand=!1;originalColumns=[];panelContainer=null;grandTotalFooter=null;previousVisibleKeys=/* @__PURE__ */new Set;keysToAnimate=/* @__PURE__ */new Set;hasValidPivotConfig(){return(this.config.valueFields?.length??0)>0}get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}detach(){this.isActive=!1,this.hasInitialized=!1,this.pivotResult=null,this.fieldHeaderMap.clear(),this.originalColumns=[],this.panelContainer=null,this.cleanupGrandTotalFooter(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.userHasToggledExpand=!1}getToolPanel(){if(!1!==(this.config?.showToolPanel??this.userConfig?.showToolPanel??!0))return{id:R.PANEL_ID,title:"Pivot",icon:"⊞",tooltip:"Configure pivot table",order:90,render:e=>this.renderPanel(e)}}processRows(e){if(!this.hasInitialized&&!1!==this.config.active&&this.hasValidPivotConfig()&&(this.hasInitialized=!0,this.isActive=!0),!this.isActive)return[...e];const t=function(e){const t=[];return e.rowGroupFields?.length||e.columnGroupFields?.length||t.push("At least one row or column group field is required"),e.valueFields?.length||t.push("At least one value field is required"),t}(this.config);if(t.length>0)return this.warn(`Config errors: ${t.join(", ")}`),[...e];this.buildFieldHeaderMap(),this.defaultExpanded=this.config.defaultExpanded??!0,this.pivotResult=b(e,this.config),0===this.expandedKeys.size&&this.defaultExpanded&&!this.userHasToggledExpand&&this.expandAllKeys();const i=this.config.indentWidth??20,o=function(e,t,i=!0){const o=[];function r(e){o.push(e);const n=t?t.has(e.rowKey):i;if(e.children&&n)for(const t of e.children)r(t)}for(const n of e)r(n);return o}(this.pivotResult.rows,this.expandedKeys,this.defaultExpanded).map(e=>({__pivotRowKey:e.rowKey,__pivotLabel:e.rowLabel,__pivotDepth:e.depth,__pivotIsGroup:e.isGroup,__pivotHasChildren:Boolean(e.children?.length),__pivotExpanded:this.expandedKeys.has(e.rowKey),__pivotRowCount:e.rowCount??0,__pivotIndent:e.depth*i,__pivotTotal:e.total,...e.values}));this.keysToAnimate.clear();const r=/* @__PURE__ */new Set;for(const n of o){const e=n.__pivotRowKey;r.add(e),!this.previousVisibleKeys.has(e)&&n.__pivotDepth>0&&this.keysToAnimate.add(e)}return this.previousVisibleKeys=r,o}processColumns(e){if(!this.isActive||!this.pivotResult)return[...e];const t=[],i=(this.config.rowGroupFields??[]).map(e=>this.fieldHeaderMap.get(e)??e).join(" / ");t.push({field:"__pivotLabel",header:i||"Group",width:200});for(const o of this.pivotResult.columnKeys)for(const e of this.config.valueFields??[]){const i=v([o],e.field),r=e.header||this.fieldHeaderMap.get(e.field)||e.field;t.push({field:i,header:`${o} - ${r} (${e.aggFunc})`,width:120,type:"number"})}return this.config.showTotals&&t.push({field:"__pivotTotal",header:"Total",width:100,type:"number"}),t}renderRow(e,t,i){const o=e;return o.__pivotRowKey&&o.__pivotHasChildren?function(e,t,i){return t.className="data-grid-row pivot-group-row",t.setAttribute("data-pivot-depth",String(e.__pivotDepth??0)),t.setAttribute("data-pivot-key",String(e.__pivotRowKey??"")),t.setAttribute("role","row"),t.innerHTML="",i.columns.forEach((o,r)=>{const n=document.createElement("div");if(n.className="cell",n.setAttribute("data-col",String(r)),n.setAttribute("data-row",String(i.rowIndex)),n.setAttribute("role","gridcell"),0===r){const t=Number(e.__pivotIndent)||0;n.style.paddingLeft=`${t}px`;const o=String(e.__pivotRowKey),r=document.createElement("button");r.type="button",r.className="pivot-toggle",r.setAttribute("aria-label",e.__pivotExpanded?"Collapse group":"Expand group"),i.setIcon(r,i.resolveIcon(e.__pivotExpanded?"collapse":"expand")),r.addEventListener("click",e=>{e.stopPropagation(),i.onToggle(o)}),n.appendChild(r);const a=document.createElement("span");a.className="pivot-label",a.textContent=String(e.__pivotLabel??""),n.appendChild(a);const s=document.createElement("span");s.className="pivot-count",s.textContent=` (${Number(e.__pivotRowCount)||0})`,n.appendChild(s)}else{const t=e[o.field];n.textContent=null!=t?String(t):""}t.appendChild(n)}),!0}(o,t,{columns:this.gridColumns,rowIndex:i,onToggle:e=>this.toggle(e),resolveIcon:e=>this.resolveIcon(e),setIcon:(e,t)=>this.setIcon(e,t)}):void 0!==o.__pivotRowKey&&this.isActive?function(e,t,i,o){return t.className="data-grid-row pivot-leaf-row",t.setAttribute("data-pivot-depth",String(e.__pivotDepth??0)),t.setAttribute("data-pivot-key",String(e.__pivotRowKey??"")),t.innerHTML="",i.forEach((i,r)=>{const n=document.createElement("div");if(n.className="cell",n.setAttribute("data-col",String(r)),n.setAttribute("data-row",String(o)),n.setAttribute("role","gridcell"),0===r){const t=Number(e.__pivotIndent)||0;n.style.paddingLeft=`${t+20}px`;const i=document.createElement("span");i.className="pivot-label",i.textContent=String(e.__pivotLabel??""),n.appendChild(i)}else{const t=e[i.field];n.textContent=null!=t?String(t):""}t.appendChild(n)}),!0}(o,t,this.gridColumns,i):(this.cleanupPivotStyling(t),!1)}cleanupPivotStyling(e){(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="")}onKeyDown(e){if(" "!==e.key)return;if(!this.isActive)return;const t=this.grid._focusRow,i=this.rows[t];return i?.__pivotIsGroup&&i.__pivotHasChildren?(e.preventDefault(),this.toggle(i.__pivotRowKey),this.requestRenderWithFocus(),!0):void 0}afterRender(){this.isActive&&this.config.showGrandTotal&&this.pivotResult?this.renderGrandTotalFooter():this.cleanupGrandTotalFooter();const e=this.animationStyle;if(!1===e||0===this.keysToAnimate.size)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const i="fade"===e?"tbw-pivot-fade-in":"tbw-pivot-slide-in";for(const o of t.querySelectorAll(".pivot-group-row, .pivot-leaf-row")){const e=o.dataset.pivotKey;e&&this.keysToAnimate.has(e)&&(o.classList.add(i),o.addEventListener("animationend",()=>o.classList.remove(i),{once:!0}))}this.keysToAnimate.clear()}renderGrandTotalFooter(){if(!this.pivotResult)return;const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.querySelector(".tbw-grid-root");if(!t)return;this.grandTotalFooter||(this.grandTotalFooter=document.createElement("div"),this.grandTotalFooter.className="pivot-grand-total-footer",t.appendChild(this.grandTotalFooter));const i={__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals};var o,r,n;o=i,r=this.grandTotalFooter,n=this.gridColumns,r.className="pivot-grand-total-row",r.setAttribute("role","presentation"),r.innerHTML="",n.forEach((e,t)=>{const i=document.createElement("div");if(i.className="cell",i.setAttribute("data-col",String(t)),0===t){const e=document.createElement("span");e.className="pivot-label",e.textContent="Grand Total",i.appendChild(e)}else{const t=o[e.field];i.textContent=null!=t?String(t):""}r.appendChild(i)})}cleanupGrandTotalFooter(){this.grandTotalFooter&&(this.grandTotalFooter.remove(),this.grandTotalFooter=null)}toggle(e){this.userHasToggledExpand=!0,this.expandedKeys.has(e)?this.expandedKeys.delete(e):this.expandedKeys.add(e),this.requestRender()}expand(e){this.userHasToggledExpand=!0,this.expandedKeys.add(e),this.requestRender()}collapse(e){this.userHasToggledExpand=!0,this.expandedKeys.delete(e),this.requestRender()}expandAll(){this.userHasToggledExpand=!0,this.expandAllKeys(),this.requestRender()}collapseAll(){this.userHasToggledExpand=!0,this.expandedKeys.clear(),this.requestRender()}expandAllKeys(){if(!this.pivotResult)return;const e=function(e){const t=[];function i(e){if(e.isGroup&&t.push(e.rowKey),e.children)for(const t of e.children)i(t)}for(const o of e)i(o);return t}(this.pivotResult.rows);for(const t of e)this.expandedKeys.add(t)}isExpanded(e){return this.expandedKeys.has(e)}enablePivot(){0===this.originalColumns.length&&this.captureOriginalColumns(),this.isActive=!0,this.requestRender()}disablePivot(){this.isActive=!1,this.pivotResult=null,this.requestRender()}isPivotActive(){return this.isActive}getPivotResult(){return this.pivotResult}setRowGroupFields(e){this.config.rowGroupFields=e,this.requestRender()}setColumnGroupFields(e){this.config.columnGroupFields=e,this.requestRender()}setValueFields(e){this.config.valueFields=e,this.requestRender()}refresh(){this.pivotResult=null,this.requestRender()}showPanel(){this.grid.openToolPanel(),this.grid.expandedToolPanelSections.includes(R.PANEL_ID)||this.grid.toggleToolPanelSection(R.PANEL_ID)}hidePanel(){this.grid.closeToolPanel()}togglePanel(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection(R.PANEL_ID)}isPanelVisible(){return this.grid.isToolPanelOpen&&this.grid.expandedToolPanelSections.includes(R.PANEL_ID)}get gridColumns(){return this.grid.columns??[]}refreshIfActive(){this.isActive&&this.refresh(),this.refreshPanel()}buildFieldHeaderMap(){const e=this.getAvailableFields();this.fieldHeaderMap.clear();for(const t of e)this.fieldHeaderMap.set(t.field,t.header)}getAvailableFields(){return this.originalColumns.length>0?this.originalColumns:this.captureOriginalColumns()}captureOriginalColumns(){try{const e=this.grid.getAllColumns?.()??this.grid.columns??[];return this.originalColumns=e.filter(e=>!e.field.startsWith("__pivot")).map(e=>({field:e.field,header:e.header??e.field})),this.originalColumns}catch{return[]}}renderPanel(e){this.panelContainer=e,0===this.originalColumns.length&&this.captureOriginalColumns();const t={onTogglePivot:e=>{e?this.enablePivot():this.disablePivot(),this.refreshPanel()},onAddFieldToZone:(e,t)=>this.addFieldToZone(e,t),onRemoveFieldFromZone:(e,t)=>this.removeFieldFromZone(e,t),onAddValueField:(e,t)=>this.addValueField(e,t),onRemoveValueField:e=>this.removeValueField(e),onUpdateValueAggFunc:(e,t)=>this.updateValueAggFunc(e,t),onOptionChange:(e,t)=>{this.config[e]=t,this.isActive&&this.refresh()},getAvailableFields:()=>this.getAvailableFields()};return y(e,this.config,this.isActive,t)}refreshPanel(){this.panelContainer&&(this.panelContainer.innerHTML="",this.renderPanel(this.panelContainer))}addFieldToZone(e,t){if("rowGroups"===t){const t=this.config.rowGroupFields??[];t.includes(e)||(this.config.rowGroupFields=[...t,e])}else{const t=this.config.columnGroupFields??[];t.includes(e)||(this.config.columnGroupFields=[...t,e])}this.removeFromOtherZones(e,t),this.refreshIfActive()}removeFieldFromZone(e,t){"rowGroups"===t?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e),this.refreshIfActive()}removeFromOtherZones(e,t){"rowGroups"!==t&&(this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e)),"columnGroups"!==t&&(this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e)),"values"!==t&&(this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e))}addValueField(e,t){const i=this.config.valueFields??[];i.some(t=>t.field===e)||(this.config.valueFields=[...i,{field:e,aggFunc:t}]),this.removeFromOtherZones(e,"values"),this.refreshIfActive()}removeValueField(e){this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e),this.refreshIfActive()}updateValueAggFunc(e,t){const i=this.config.valueFields??[],o=i.findIndex(t=>t.field===e);o>=0&&(i[o]={...i[o],aggFunc:t},this.config.valueFields=[...i]),this.isActive&&this.refresh()}}export{R as PivotPlugin};
|
|
1
|
+
function e(e,t){const o=e.querySelector?.(".tbw-sr-only");o&&(o.textContent="",requestAnimationFrame(()=>{o.textContent=t}))}function t(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function o(e,o,i,r){return`${t(i,r)} ${e}: ${o}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}["__otorp__","__retteGenifed__","__retteSenifed__","rotcurtsnoc","wodniw","sihTlabolg","labolg","ssecorp","noitcnuF","tropmi","lave","tcelfeR","yxorP","rorrE","stnemugra","tnemucod","noitacol","eikooc","egarotSlacol","egarotSnoisses","BDdexedni","hctef","tseuqeRpttHLMX","tekcoSbeW","rekroW","rekroWderahS","rekroWecivreS","renepo","tnerap","pot","semarf","fles"].map(e=>e.split("").reverse().join(""));const i=/* @__PURE__ */new Set(["script","iframe","object","embed","form","input","button","textarea","select","link","meta","base","style","template","slot","portal","frame","frameset","applet","noscript","noembed","plaintext","xmp","listing"]),r=/^on\w+$/i,n=/* @__PURE__ */new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),s=/^\s*(javascript|vbscript|data|blob):/i;function a(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],o=e.querySelectorAll("*");for(const a of o){const e=a.tagName.toLowerCase();if(i.has(e)){t.push(a);continue}if("svg"===e||"http://www.w3.org/2000/svg"===a.namespaceURI){if(Array.from(a.attributes).some(e=>r.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(a);continue}}const o=[];for(const t of a.attributes){const e=t.name.toLowerCase();r.test(e)?o.push(t.name):(n.has(e)&&s.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&o.push(t.name)}o.forEach(e=>a.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}const l='<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>',d={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:l,filterActive:l,print:"🖨️"};class c{static dependencies;static manifest;aliases;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const o=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(o),o.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...d,...e}}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),o=parseInt(t,10);if(!isNaN(o))return o}return 200}resolveIcon(e,t){return void 0!==t?t:this.gridIcons[e]}setIcon(e,t,o){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const i=this.#t(t,o);void 0!==i?"string"==typeof i?e.innerHTML=a(i):i instanceof HTMLElement&&(e.innerHTML="",e.appendChild(i.cloneNode(!0))):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const o=document.createElement("span");o.setAttribute("part","sort-indicator"),o.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(o,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(o,"sortNone"));const i=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return i?e.insertBefore(o,i):e.appendChild(o),o}warn(e,i){void 0!==i?console.warn(o(e,i,this.gridElement.id,this.name)):console.warn(`${t(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(o(e,t,this.gridElement.id,this.name))}}const u={sum:(e,t)=>e.reduce((e,o)=>e+(Number(o[t])||0),0),avg:(e,t)=>{const o=e.reduce((e,o)=>e+(Number(o[t])||0),0);return e.length?o/e.length:0},count:e=>e.length,min:(e,t)=>e.length?Math.min(...e.map(e=>Number(e[t])||1/0)):0,max:(e,t)=>e.length?Math.max(...e.map(e=>Number(e[t])||-1/0)):0,first:(e,t)=>e[0]?.[t],last:(e,t)=>e[e.length-1]?.[t]},p=/* @__PURE__ */new Map,g={register(e,t){p.set(e,t)},unregister(e){p.delete(e)},get(e){if(void 0!==e)return"function"==typeof e?e:p.get(e)??u[e]},run(e,t,o,i){const r=this.get(e);return r?r(t,o,i):void 0},has:e=>p.has(e)||e in u,list:()=>[...Object.keys(u),...p.keys()]},h={sum:e=>e.reduce((e,t)=>e+t,0),avg:e=>e.length?e.reduce((e,t)=>e+t,0)/e.length:0,count:e=>e.length,min:e=>e.length?Math.min(...e):0,max:e=>e.length?Math.max(...e):0,first:e=>e[0]??0,last:e=>e[e.length-1]??0};function v(e){return"function"==typeof e?e:function(e){return h[e]??h.sum}(e)}function f(e,t){return[...e,t].join("|")}function m(e,t){const o=t.rowGroupFields??[],i=t.columnGroupFields??[],r=t.valueFields??[],n=function(e,t,o="asc"){if(0===t.length)return["value"];const i=/* @__PURE__ */new Set;for(const n of e){const e=t.map(e=>String(n[e]??"")).join("|");i.add(e)}const r=[...i].sort();return"desc"===o?r.reverse():r}(e,i,t.sortColumns),s=b(e,o,i,n,r,0,"");t.sortRows&&y(s,t.sortRows,r);const a=function(e,t,o){const i={};function r(e){for(const n of e)if(n.isGroup&&n.children?.length)n.children&&r(n.children);else for(const e of t)for(const t of o){const o=f([e],t.field);i[o]=(i[o]??0)+(n.values[o]??0)}}return r(e),i}(s,n,r);return{rows:s,columnKeys:n,totals:a,grandTotal:Object.values(a).reduce((e,t)=>e+t,0)}}function b(e,t,o,i,r,n,s){const a=[];if(0===t.length){const t=w(e,o,i,r),l=C(t);return a.push({rowKey:s||"all",rowLabel:s||"All",depth:n,values:t,total:l,isGroup:!1,rowCount:e.length}),a}const l=t[0],d=t.slice(1),c=d.length>0,u=function(e,t){const o=/* @__PURE__ */new Map;for(const i of e){const e=String(i[t]??""),r=o.get(e);r?r.push(i):o.set(e,[i])}return o}(e,l);for(const[p,g]of u){const e=s?`${s}|${p}`:p,t=w(g,o,i,r),l=C(t);let u;c&&(u=b(g,d,o,i,r,n+1,e)),a.push({rowKey:e,rowLabel:p||"(blank)",depth:n,values:t,total:l,isGroup:c,children:u,rowCount:g.length})}return a}function w(e,t,o,i){const r={};for(const n of o)for(const o of i){const i=(t.length>0?e.filter(e=>t.map(t=>String(e[t]??"")).join("|")===n):e).map(e=>Number(e[o.field])||0),s=v(o.aggFunc),a=i.length>0?s(i):null;r[f([n],o.field)]=a}return r}function C(e){let t=0;for(const o of Object.values(e))t+=o??0;return t}function F(e){const t=[];function o(e){if(e.isGroup&&t.push(e.rowKey),e.children)for(const t of e.children)o(t)}for(const i of e)o(i);return t}function y(e,t,o){const i="desc"===t.direction?-1:1;e.sort((e,r)=>{if("value"===t.by){if(t.valueField??o[0]?.field){return((e.total??0)-(r.total??0))*i}}return e.rowLabel.localeCompare(r.rowLabel)*i});for(const r of e)r.children?.length&&y(r.children,t,o)}function x(e,t,o){if(0===t.length)return;const i=new Set(o.map(e=>e.field)),r=t.map(e=>"value"===e.by?e.valueField?t=>((e,t)=>{if(null!=e.values[t])return"number"==typeof e.values[t]?e.values[t]:0;if(i.has(t)){const o=`|${t}`;let i=0,r=!1;for(const t of Object.keys(e.values))t.endsWith(o)&&(i+="number"==typeof e.values[t]?e.values[t]:0,r=!0);if(r)return i}return e.total??0})(t,e.valueField):e=>e.total??0:null);e.sort((e,o)=>{for(let i=0;i<t.length;i++){const n=t[i],s="desc"===n.direction?-1:1;let a=0;if("value"===n.by){const t=r[i];a=(t(e)-t(o))*s}else a=e.rowLabel.localeCompare(o.rowLabel)*s;if(0!==a)return a}return 0});for(const n of e)n.children?.length&&x(n.children,t,o)}g.register.bind(g),g.unregister.bind(g),g.get.bind(g),g.run.bind(g),g.list.bind(g);const _="dragging",A=["sum","avg","count","min","max","first","last"];function T(e,t,o,i){const r=new AbortController,n={config:t,callbacks:i,signal:r.signal},s=document.createElement("div");return s.className="tbw-pivot-panel",s.appendChild(E("Options",()=>function(e,t){const{config:o,callbacks:i,signal:r}=t,n=document.createElement("div");return n.className="tbw-pivot-options",n.appendChild(L("Enable Pivot View",e,e=>{i.onTogglePivot(e)},r)),n.appendChild(L("Show Row Totals",o.showTotals??!0,e=>{i.onOptionChange("showTotals",e)},r)),n.appendChild(L("Show Grand Total",o.showGrandTotal??!0,e=>{i.onOptionChange("showGrandTotal",e)},r)),n}(o,n))),s.appendChild(E("Row Groups",()=>S("rowGroups",n))),s.appendChild(E("Column Groups",()=>S("columnGroups",n))),s.appendChild(E("Values",()=>function(e){const{config:t,callbacks:o,signal:i}=e,r=document.createElement("div");r.className="tbw-pivot-drop-zone tbw-pivot-values-zone",r.setAttribute("data-zone","values");const n=t.valueFields??[];if(0===n.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="Drag numeric fields here",r.appendChild(e)}else for(const s of n)r.appendChild(R(s,e));return r.addEventListener("dragover",e=>{e.preventDefault(),r.classList.add("drag-over")},{signal:i}),r.addEventListener("dragleave",()=>{r.classList.remove("drag-over")},{signal:i}),r.addEventListener("drop",e=>{e.preventDefault(),r.classList.remove("drag-over");const t=e.dataTransfer?.getData("text/plain");t&&o.onAddValueField(t,"sum")},{signal:i}),r}(n))),s.appendChild(E("Available Fields",()=>function(e){const{config:t,callbacks:o,signal:i}=e,r=document.createElement("div");r.className="tbw-pivot-available-fields";const n=o.getAvailableFields(),s=/* @__PURE__ */new Set([...t.rowGroupFields??[],...t.columnGroupFields??[],...t.valueFields?.map(e=>e.field)??[]]),a=n.filter(e=>!s.has(e.field));if(0===a.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="All fields are in use",r.appendChild(e)}else{const e=document.createElement("div");if(e.className="tbw-pivot-fields-list",a.length>=6){const t=document.createElement("input");t.type="text",t.placeholder="Filter fields…",t.className="tbw-pivot-field-search",t.addEventListener("input",()=>{const o=t.value.toLowerCase();for(const t of e.querySelectorAll(".tbw-pivot-field-chip")){const e=t;e.style.display=e.textContent?.toLowerCase().includes(o)?"":"none"}},{signal:i}),r.appendChild(t)}for(const t of a){const o=document.createElement("div");o.className="tbw-pivot-field-chip available",o.textContent=t.header,o.draggable=!0,o.title=`Drag to add "${t.field}" to a zone`,o.addEventListener("dragstart",e=>{e.dataTransfer?.setData("text/plain",t.field),o.classList.add(_)},{signal:i}),o.addEventListener("dragend",()=>{o.classList.remove(_)},{signal:i}),e.appendChild(o)}r.appendChild(e)}return r}(n))),e.appendChild(s),()=>{r.abort(),s.remove()}}function E(e,t){const o=document.createElement("div");o.className="tbw-pivot-section";const i=document.createElement("div");i.className="tbw-pivot-section-header",i.textContent=e;const r=document.createElement("div");return r.className="tbw-pivot-section-content",r.appendChild(t()),o.appendChild(i),o.appendChild(r),o}function S(e,t){const{config:o,callbacks:i,signal:r}=t,n=document.createElement("div");n.className="tbw-pivot-drop-zone",n.setAttribute("data-zone",e);const s="rowGroups"===e?o.rowGroupFields??[]:o.columnGroupFields??[];if(0===s.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="Drag fields here",n.appendChild(e)}else for(const a of s)n.appendChild(G(a,e,t));return n.addEventListener("dragover",e=>{e.preventDefault(),n.classList.add("drag-over")},{signal:r}),n.addEventListener("dragleave",()=>{n.classList.remove("drag-over")},{signal:r}),n.addEventListener("drop",t=>{t.preventDefault(),n.classList.remove("drag-over");const o=t.dataTransfer?.getData("text/plain"),r=t.dataTransfer?.getData("source-zone");if(!o)return;const s=n.querySelectorAll(".tbw-pivot-field-chip");let a=s.length;for(let e=0;e<s.length;e++){const o=s[e].getBoundingClientRect();if(t.clientY<o.top+o.height/2){a=e;break}}!r||r===e||"rowGroups"!==r&&"columnGroups"!==r?r===e?i.onReorderFieldInZone(o,e,a):i.onAddFieldToZone(o,e):i.onMoveFieldBetweenZones(o,r,e)},{signal:r}),n}function G(e,t,o){const{callbacks:i,signal:r}=o,n=document.createElement("div");n.className="tbw-pivot-field-chip",n.draggable=!0;const s=i.getAvailableFields().find(t=>t.field===e),a=document.createElement("span");a.className="tbw-pivot-chip-label",a.textContent=s?.header??e;const l=document.createElement("button");return l.className="tbw-pivot-chip-remove",l.innerHTML="×",l.title="Remove field",l.addEventListener("click",o=>{o.stopPropagation(),i.onRemoveFieldFromZone(e,t)},{signal:r}),n.appendChild(a),n.appendChild(l),n.addEventListener("dragstart",o=>{o.dataTransfer?.setData("text/plain",e),o.dataTransfer?.setData("source-zone",t),n.classList.add(_)},{signal:r}),n.addEventListener("dragend",()=>{n.classList.remove(_)},{signal:r}),n}function R(e,t){const{callbacks:o,signal:i}=t,r=document.createElement("div");r.className="tbw-pivot-field-chip tbw-pivot-value-chip";const n=o.getAvailableFields().find(t=>t.field===e.field),s=document.createElement("div");s.className="tbw-pivot-value-label-wrapper";const a=document.createElement("span");a.className="tbw-pivot-chip-label",a.textContent=n?.header??e.field;const l="function"==typeof e.aggFunc,d=document.createElement("select");if(d.className="tbw-pivot-agg-select",d.title="Aggregation function",l){const e=document.createElement("option");e.value="__custom__",e.textContent="CUSTOM",e.selected=!0,d.appendChild(e),d.disabled=!0}for(const u of A){const t=document.createElement("option");t.value=u,t.textContent=u.toUpperCase(),l||(t.selected=u===e.aggFunc),d.appendChild(t)}d.addEventListener("change",()=>{o.onUpdateValueAggFunc(e.field,d.value)},{signal:i});const c=document.createElement("button");return c.className="tbw-pivot-chip-remove",c.innerHTML="×",c.title="Remove value field",c.addEventListener("click",t=>{t.stopPropagation(),o.onRemoveValueField(e.field)},{signal:i}),s.appendChild(a),s.appendChild(d),r.appendChild(s),r.appendChild(c),r}function L(e,t,o,i){const r=document.createElement("label");r.className="tbw-pivot-checkbox";const n=document.createElement("input");n.type="checkbox",n.checked=t,n.addEventListener("change",()=>o(n.checked),{signal:i});const s=document.createElement("span");return s.textContent=e,r.appendChild(n),r.appendChild(s),r}function P(e,t,o){return t.className="data-grid-row pivot-grand-total-row",t.innerHTML="",o.forEach((o,i)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(i)),0===i){const e=document.createElement("span");e.className="pivot-label",e.textContent="Grand Total",r.appendChild(e)}else{const t=e[o.field];r.textContent=null!=t?o.format?o.format(t,e):String(t):""}t.appendChild(r)}),!0}class k extends c{static manifest={hookPriority:{onHeaderClick:-10,processRows:100},incompatibleWith:[{name:"groupingRows",reason:"PivotPlugin creates its own aggregated row and column structure. Row grouping cannot be applied on top of pivot-generated rows."},{name:"tree",reason:"PivotPlugin replaces the entire row and column structure with aggregated pivot data. Tree hierarchy cannot coexist with pivot aggregation."},{name:"serverSide",reason:"PivotPlugin requires the full dataset to compute aggregations. ServerSidePlugin lazy-loads rows in blocks, so pivot aggregation cannot be performed client-side."}],queries:[{type:"sort:get-sort-config",description:"Returns the current pivot sort configuration"}]};name="pivot";styles='@layer tbw-plugins{.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)}@media(hover:hover){.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:var(--tbw-pivot-toggle-size, var(--tbw-toggle-size, 1.25em));height:var(--tbw-pivot-toggle-size, var(--tbw-toggle-size, 1.25em));margin-right:var(--tbw-spacing-sm, .375em);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 var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease),color var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease)}.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:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));padding:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));height:100%;overflow-y:auto;font-size:var(--tbw-font-size-sm, .8125rem)}.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:var(--tbw-button-padding, var(--tbw-spacing-md, .5rem) var(--tbw-spacing-lg, .75rem));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:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-pivot-toggle-wrapper{display:flex;align-items:center}.tbw-pivot-toggle-label{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));cursor:pointer}.tbw-pivot-toggle-label input{width:var(--tbw-icon-size, 1rem);height:var(--tbw-icon-size, 1rem);cursor:pointer}.tbw-pivot-drop-zone{min-height:60px;padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));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:var(--tbw-spacing-sm, .375rem);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:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));text-align:center;width:100%}.tbw-pivot-field-chip{display:inline-flex;align-items:center;gap:var(--tbw-spacing-sm, .375rem);padding:var(--tbw-button-padding-sm, var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-md, .5rem));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:var(--tbw-font-size-xs, .75rem);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:var(--tbw-icon-size, 1rem);height:var(--tbw-icon-size, 1rem);padding:0;border:none;background:transparent;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-sm, .875rem);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:var(--tbw-button-padding-sm, var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-md, .5rem))}.tbw-pivot-value-label-wrapper{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));flex:1;min-width:0}.tbw-pivot-agg-select{padding:var(--tbw-spacing-xs, .125rem) var(--tbw-spacing-xs, .25rem);font-size:var(--tbw-font-size-xs, .6875rem);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-direction:column;gap:var(--tbw-spacing-sm, .375rem);min-height:40px}.tbw-pivot-field-search{width:100%;padding:.25rem .5rem;border:1px solid var(--tbw-color-border, #d0d5dd);border-radius:var(--tbw-radius-sm, .25rem);font-size:var(--tbw-font-size-sm, .875rem);background:var(--tbw-color-bg, #fff);color:var(--tbw-color-fg, #1a1a2e);outline:none}.tbw-pivot-field-search:focus{border-color:var(--tbw-color-primary, #3b82f6)}.tbw-pivot-fields-list{display:flex;flex-wrap:wrap;gap:var(--tbw-spacing-sm, .375rem)}.tbw-pivot-options{display:flex;flex-direction:column;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-pivot-checkbox{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));cursor:pointer}.tbw-pivot-checkbox input{width:var(--tbw-icon-size-sm, .875rem);height:var(--tbw-icon-size-sm, .875rem);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}}}';static PANEL_ID="pivot";get defaultConfig(){return{active:!0,showTotals:!0,showGrandTotal:!0,showToolPanel:!0,animation:"slide"}}isActive=!1;hasInitialized=!1;pivotResult=null;fieldHeaderMap=/* @__PURE__ */new Map;expandedKeys=/* @__PURE__ */new Set;defaultExpanded=!0;userHasToggledExpand=!1;originalColumns=[];panelContainer=null;grandTotalFooter=null;previousVisibleKeys=/* @__PURE__ */new Set;keysToAnimate=/* @__PURE__ */new Set;valueFormatters=/* @__PURE__ */new Map;columnTotals={};activeSortField=null;activeSortDir=null;hasValidPivotConfig(){return(this.config.valueFields?.length??0)>0}get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}detach(){this.isActive=!1,this.hasInitialized=!1,this.pivotResult=null,this.fieldHeaderMap.clear(),this.originalColumns=[],this.panelContainer=null,this.cleanupGrandTotalFooter(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.userHasToggledExpand=!1,this.valueFormatters.clear(),this.columnTotals={},this.activeSortField=null,this.activeSortDir=null,this.config.sortRows=void 0}getToolPanel(){if(!1!==(this.config?.showToolPanel??this.userConfig?.showToolPanel??!0))return{id:k.PANEL_ID,title:"Pivot",icon:"⊞",tooltip:"Configure pivot table",order:90,render:e=>this.renderPanel(e)}}processRows(e){if(!this.hasInitialized&&!1!==this.config.active&&this.hasValidPivotConfig()&&(this.hasInitialized=!0,this.isActive=!0),!this.isActive)return[...e];const t=function(e){const t=[];return e.rowGroupFields?.length||e.columnGroupFields?.length||t.push("At least one row or column group field is required"),e.valueFields?.length||t.push("At least one value field is required"),t}(this.config);if(t.length>0)return this.warn(`Config errors: ${t.join(", ")}`),[...e];this.buildFieldHeaderMap(),this.buildValueFormatters(),this.defaultExpanded=this.config.defaultExpanded??!0,this.pivotResult=m(e,this.config);const o=this.getMultiSortConfigs();if(o&&x(this.pivotResult.rows,o,this.config.valueFields??[]),0===this.expandedKeys.size&&!this.userHasToggledExpand){const e=F(this.pivotResult.rows);this.expandedKeys=function(e,t){if(!0===e||void 0===e)return new Set(t);if(!1===e)/* @__PURE__ */return new Set;if("number"==typeof e){const o=t[e];return o?/* @__PURE__ */new Set([o]):/* @__PURE__ */new Set}return"string"==typeof e?/* @__PURE__ */new Set([e]):Array.isArray(e)?new Set(e):/* @__PURE__ */new Set}(this.defaultExpanded,e)}this.config.valueDisplayMode&&"raw"!==this.config.valueDisplayMode&&(this.columnTotals=function(e,t,o){const i={};return function e(r){for(const n of r)if(n.isGroup&&n.children?.length)n.children&&e(n.children);else for(const e of t)for(const t of o){const o=f([e],t.field);i[o]=(i[o]??0)+(n.values[o]??0)}}(e),i}(this.pivotResult.rows,this.pivotResult.columnKeys,this.config.valueFields??[]));const i=this.config.indentWidth??20,r=!0===this.defaultExpanded||void 0===this.defaultExpanded,n=function(e,t,o=!0){const i=[];function r(e){i.push(e);const n=t?t.has(e.rowKey):o;if(e.children&&n)for(const t of e.children)r(t)}for(const n of e)r(n);return i}(this.pivotResult.rows,this.expandedKeys,r).map(e=>({__pivotRowKey:e.rowKey,__pivotLabel:e.rowLabel,__pivotDepth:e.depth,__pivotIsGroup:e.isGroup,__pivotHasChildren:Boolean(e.children?.length),__pivotExpanded:this.expandedKeys.has(e.rowKey),__pivotRowCount:e.rowCount??0,__pivotIndent:e.depth*i,__pivotTotal:e.total,...e.values}));this.keysToAnimate.clear();const s=/* @__PURE__ */new Set;for(const a of n){const e=a.__pivotRowKey;s.add(e),!this.previousVisibleKeys.has(e)&&a.__pivotDepth>0&&this.keysToAnimate.add(e)}return this.previousVisibleKeys=s,this.config.grandTotalInRowModel&&this.config.showGrandTotal&&this.pivotResult&&n.push({__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotDepth:0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals}),n}processColumns(e){if(!this.isActive||!this.pivotResult)return[...e];const t=[],o=(this.config.rowGroupFields??[]).map(e=>this.fieldHeaderMap.get(e)??e).join(" / ");t.push({field:"__pivotLabel",header:o||"Group",width:200,sortable:!0});for(const i of this.pivotResult.columnKeys)for(const e of this.config.valueFields??[]){const o=f([i],e.field),r=e.header||this.fieldHeaderMap.get(e.field)||e.field,n="function"==typeof e.aggFunc?"custom":e.aggFunc,s=this.valueFormatters.get(e.field);t.push({field:o,header:`${i} - ${r} (${n})`,width:120,type:"number",sortable:!0,...s?{format:e=>null!=e?s(Number(e)):""}:{}})}return this.config.showTotals&&t.push({field:"__pivotTotal",header:"Total",width:100,type:"number",sortable:!0}),t}renderRow(e,t,o){const i=e;return i.__pivotIsGrandTotal?P(i,t,this.gridColumns):i.__pivotRowKey&&i.__pivotHasChildren?function(e,t,o){return t.className="data-grid-row pivot-group-row",t.setAttribute("data-pivot-depth",String(e.__pivotDepth??0)),t.setAttribute("data-pivot-key",String(e.__pivotRowKey??"")),t.setAttribute("role","row"),t.innerHTML="",o.columns.forEach((i,r)=>{const n=document.createElement("div");if(n.className="cell",n.setAttribute("data-col",String(r)),n.setAttribute("data-row",String(o.rowIndex)),n.setAttribute("role","gridcell"),0===r){const t=Number(e.__pivotIndent)||0;n.style.paddingLeft=`${t}px`;const i=String(e.__pivotRowKey),r=document.createElement("button");r.type="button",r.className="pivot-toggle",r.setAttribute("aria-label",e.__pivotExpanded?"Collapse group":"Expand group"),o.setIcon(r,e.__pivotExpanded?"collapse":"expand"),r.addEventListener("click",e=>{e.stopPropagation(),o.onToggle(i)}),n.appendChild(r);const s=document.createElement("span");s.className="pivot-label",s.textContent=String(e.__pivotLabel??""),n.appendChild(s);const a=document.createElement("span");a.className="pivot-count",a.textContent=` (${Number(e.__pivotRowCount)||0})`,n.appendChild(a)}else{const t=e[i.field];n.textContent=null!=t?i.format?i.format(t,e):String(t):""}t.appendChild(n)}),!0}(i,t,{columns:this.gridColumns,rowIndex:o,onToggle:e=>this.toggle(e),setIcon:(e,t)=>this.setIcon(e,t)}):void 0!==i.__pivotRowKey&&this.isActive?function(e,t,o,i){return t.className="data-grid-row pivot-leaf-row",t.setAttribute("data-pivot-depth",String(e.__pivotDepth??0)),t.setAttribute("data-pivot-key",String(e.__pivotRowKey??"")),t.innerHTML="",o.forEach((o,r)=>{const n=document.createElement("div");if(n.className="cell",n.setAttribute("data-col",String(r)),n.setAttribute("data-row",String(i)),n.setAttribute("role","gridcell"),0===r){const t=Number(e.__pivotIndent)||0;n.style.paddingLeft=`${t+20}px`;const o=document.createElement("span");o.className="pivot-label",o.textContent=String(e.__pivotLabel??""),n.appendChild(o)}else{const t=e[o.field];n.textContent=null!=t?o.format?o.format(t,e):String(t):""}t.appendChild(n)}),!0}(i,t,this.gridColumns,o):(this.cleanupPivotStyling(t),!1)}cleanupPivotStyling(e){(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="")}onKeyDown(e){if(" "!==e.key)return;if(!this.isActive)return;const t=this.grid._focusRow,o=this.rows[t];return o?.__pivotIsGroup&&o.__pivotHasChildren?(e.preventDefault(),this.toggle(o.__pivotRowKey),this.requestRenderWithFocus(),!0):void 0}handleQuery(e){if("sort:get-sort-config"===e.type){const e=this.getMultiSortConfigs();return e||(this.config.sortRows??null)}}onHeaderClick(t){if(!this.isActive)return!1;const o=t.field;if(!this.isPivotField(o))return!1;if(this.isMultiSortActive())return!1;const i=this.mapFieldToSortConfig(o);if(!i)return!1;const r=this.activeSortDir;let n;n=this.activeSortField!==o?"asc":"asc"===r?"desc":null,this.activeSortField=n?o:null,this.activeSortDir=n,this.config.sortRows=n?{...i,direction:n}:void 0,this.emit("pivot-config-change",{property:"sortRows"}),this.refresh();const s=this.gridElement;if(s){const i=t.column.header??o;e(s,n?`Sorted by ${i}, ${"asc"===n?"ascending":"descending"}`:"Sort cleared")}return!0}isPivotField(e){return"__pivotLabel"===e||"__pivotTotal"===e||e.includes("|")}isMultiSortActive(){const e=this.grid?.queryPlugins?.({type:"sort:get-model",context:null});return Array.isArray(e)&&e.length>0}getMultiSortConfigs(){const e=this.grid?.queryPlugins?.({type:"sort:get-model",context:null});if(!e||0===e.length)return null;const t=e[0];if(!Array.isArray(t)||0===t.length)return null;const o=[];for(const i of t){if(!this.isPivotField(i.field))continue;const e=this.mapFieldToSortConfig(i.field);e&&o.push({...e,direction:i.direction})}return o.length>0?o:null}mapFieldToSortConfig(e){return"__pivotLabel"===e?{by:"label"}:"__pivotTotal"===e?{by:"value"}:e.includes("|")?{by:"value",valueField:e}:null}afterRender(){this.isActive&&this.config.showGrandTotal&&this.pivotResult&&!this.config.grandTotalInRowModel?this.renderGrandTotalFooter():this.cleanupGrandTotalFooter(),this.isActive&&!this.isMultiSortActive()&&this.updateSortIndicators();const e=this.animationStyle;if(!1===e||0===this.keysToAnimate.size)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const o="fade"===e?"tbw-pivot-fade-in":"tbw-pivot-slide-in";for(const i of t.querySelectorAll(".pivot-group-row, .pivot-leaf-row")){const e=i.dataset.pivotKey;e&&this.keysToAnimate.has(e)&&(i.classList.add(o),i.addEventListener("animationend",()=>i.classList.remove(o),{once:!0}))}this.keysToAnimate.clear()}updateSortIndicators(){const e=this.gridElement;if(!e)return;const t=this.activeSortField,o=this.activeSortDir,i=t?null:this.config.sortRows,r=e.querySelectorAll(".header-row .cell[data-field]");for(const n of r){const e=n.getAttribute("data-field");if(!e||!this.isPivotField(e))continue;let r=null;t===e?r=o:i&&("label"===i.by&&"__pivotLabel"===e?r=i.direction??"asc":"value"!==i.by||"__pivotTotal"!==e||i.valueField?"value"===i.by&&i.valueField&&e===i.valueField&&(r=i.direction??"asc"):r=i.direction??"asc"),this.updateSortIndicator(n,r)}}renderGrandTotalFooter(){if(!this.pivotResult)return;const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.querySelector(".tbw-grid-root");if(!t)return;this.grandTotalFooter||(this.grandTotalFooter=document.createElement("div"),this.grandTotalFooter.className="pivot-grand-total-footer",t.appendChild(this.grandTotalFooter));P({__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals},this.grandTotalFooter,this.gridColumns),this.grandTotalFooter.setAttribute("role","presentation")}cleanupGrandTotalFooter(){this.grandTotalFooter&&(this.grandTotalFooter.remove(),this.grandTotalFooter=null)}toggle(e){this.userHasToggledExpand=!0;const t=this.expandedKeys.has(e);t?this.expandedKeys.delete(e):this.expandedKeys.add(e),this.emitToggle(e,!t),this.requestRender()}expand(e){this.userHasToggledExpand=!0,this.expandedKeys.add(e),this.emitToggle(e,!0),this.requestRender()}collapse(e){this.userHasToggledExpand=!0,this.expandedKeys.delete(e),this.emitToggle(e,!1),this.requestRender()}expandAll(){this.userHasToggledExpand=!0,this.expandAllKeys(),this.requestRender()}collapseAll(){this.userHasToggledExpand=!0,this.expandedKeys.clear(),this.requestRender()}expandAllKeys(){if(!this.pivotResult)return;const e=F(this.pivotResult.rows);for(const t of e)this.expandedKeys.add(t)}isExpanded(e){return this.expandedKeys.has(e)}getExpandedGroups(){return[...this.expandedKeys]}enablePivot(){0===this.originalColumns.length&&this.captureOriginalColumns(),this.isActive=!0,this.emit("pivot-state-change",{active:!0}),this.requestRender()}disablePivot(){this.isActive=!1,this.pivotResult=null,this.emit("pivot-state-change",{active:!1}),this.requestRender()}isPivotActive(){return this.isActive}getPivotResult(){return this.pivotResult}setRowGroupFields(e){this.config.rowGroupFields=e,this.emitConfigChange("rowGroupFields"),this.refresh()}setColumnGroupFields(e){this.config.columnGroupFields=e,this.emitConfigChange("columnGroupFields"),this.refresh()}setValueFields(e){this.config.valueFields=e,this.emitConfigChange("valueFields"),this.refresh()}refresh(){this.pivotResult=null,this.requestRender()}showPanel(){this.grid.openToolPanel(),this.grid.expandedToolPanelSections.includes(k.PANEL_ID)||this.grid.toggleToolPanelSection(k.PANEL_ID)}hidePanel(){this.grid.closeToolPanel()}togglePanel(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection(k.PANEL_ID)}isPanelVisible(){return this.grid.isToolPanelOpen&&this.grid.expandedToolPanelSections.includes(k.PANEL_ID)}get gridColumns(){return this.grid.columns??[]}refreshIfActive(){this.isActive&&this.refresh(),this.refreshPanel()}buildFieldHeaderMap(){const e=this.getAvailableFields();this.fieldHeaderMap.clear();for(const t of e)this.fieldHeaderMap.set(t.field,t.header)}getAvailableFields(){return this.originalColumns.length>0?this.originalColumns:this.captureOriginalColumns()}captureOriginalColumns(){try{const e=this.grid.getAllColumns?.()??this.grid.columns??[];return this.originalColumns=e.filter(e=>!e.field.startsWith("__pivot")).map(e=>({field:e.field,header:e.header??e.field})),this.originalColumns}catch{return[]}}renderPanel(e){this.panelContainer=e,0===this.originalColumns.length&&this.captureOriginalColumns();const t={onTogglePivot:e=>{e?this.enablePivot():this.disablePivot(),this.refreshPanel()},onAddFieldToZone:(e,t)=>{this.addFieldToZone(e,t),this.emitConfigChange("rowGroups"===t?"rowGroupFields":"columnGroupFields",e,t)},onRemoveFieldFromZone:(e,t)=>{this.removeFieldFromZone(e,t),this.emitConfigChange("rowGroups"===t?"rowGroupFields":"columnGroupFields",e,t)},onReorderFieldInZone:(e,t,o)=>{this.reorderFieldInZone(e,t,o),this.emitConfigChange("rowGroups"===t?"rowGroupFields":"columnGroupFields",e,t)},onMoveFieldBetweenZones:(e,t,o)=>{this.moveFieldBetweenZones(e,t,o),this.emitConfigChange("rowGroups"===o?"rowGroupFields":"columnGroupFields",e,o)},onAddValueField:(e,t)=>{this.addValueField(e,t),this.emitConfigChange("valueFields",e,"values")},onRemoveValueField:e=>{this.removeValueField(e),this.emitConfigChange("valueFields",e,"values")},onUpdateValueAggFunc:(e,t)=>{this.updateValueAggFunc(e,t),this.emitConfigChange("valueFields",e,"values")},onOptionChange:(e,t)=>{this.config[e]=t,this.emitConfigChange(e),this.isActive&&this.refresh()},getAvailableFields:()=>this.getAvailableFields()};return T(e,this.config,this.isActive,t)}refreshPanel(){this.panelContainer&&(this.panelContainer.innerHTML="",this.renderPanel(this.panelContainer))}addFieldToZone(e,t){if("rowGroups"===t){const t=this.config.rowGroupFields??[];t.includes(e)||(this.config.rowGroupFields=[...t,e])}else{const t=this.config.columnGroupFields??[];t.includes(e)||(this.config.columnGroupFields=[...t,e])}this.removeFromOtherZones(e,t),this.refreshIfActive()}removeFieldFromZone(e,t){"rowGroups"===t?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e),this.refreshIfActive()}reorderFieldInZone(e,t,o){const i="rowGroups"===t?[...this.config.rowGroupFields??[]]:[...this.config.columnGroupFields??[]],r=i.indexOf(e);-1!==r&&r!==o&&(i.splice(r,1),i.splice(o>r?o-1:o,0,e),"rowGroups"===t?this.config.rowGroupFields=i:this.config.columnGroupFields=i,this.refreshIfActive())}moveFieldBetweenZones(e,t,o){"rowGroups"===t?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e),"rowGroups"===o?this.config.rowGroupFields=[...this.config.rowGroupFields??[],e]:this.config.columnGroupFields=[...this.config.columnGroupFields??[],e],this.refreshIfActive()}removeFromOtherZones(e,t){"rowGroups"!==t&&(this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e)),"columnGroups"!==t&&(this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e)),"values"!==t&&(this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e))}addValueField(e,t){const o=this.config.valueFields??[];o.some(t=>t.field===e)||(this.config.valueFields=[...o,{field:e,aggFunc:t}]),this.removeFromOtherZones(e,"values"),this.refreshIfActive()}removeValueField(e){this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e),this.refreshIfActive()}updateValueAggFunc(e,t){const o=this.config.valueFields??[],i=o.findIndex(t=>t.field===e);i>=0&&(o[i]={...o[i],aggFunc:t},this.config.valueFields=[...o]),this.isActive&&this.refresh()}emitToggle(e,t){const o=this.rows.find(t=>t.__pivotRowKey===e);this.emit("pivot-toggle",{key:e,expanded:t,label:o?.__pivotLabel??e,depth:o?.__pivotDepth??0})}emitConfigChange(e,t,o){this.emit("pivot-config-change",{property:e,field:t,zone:o})}buildValueFormatters(){this.valueFormatters.clear();const e=this.config.valueFields??[];for(const t of e)if(t.format)this.valueFormatters.set(t.field,t.format);else{if(this.originalColumns.find(e=>e.field===t.field)){const e=(this.grid.getAllColumns?.()??this.grid.columns??[]).find(e=>e.field===t.field);if(e?.format){const o=e.format;this.valueFormatters.set(t.field,e=>o(e,{}))}}}}}export{k as PivotPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|