@toolbox-web/grid 2.0.0-rc.1 → 2.0.0-rc.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 +23 -6
- 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/sorting.d.ts +4 -0
- package/lib/core/plugin/base-plugin.d.ts +31 -0
- package/lib/core/plugin/plugin-manager.d.ts +4 -1
- package/lib/core/plugin/types.d.ts +2 -0
- package/lib/core/types.d.ts +20 -1
- package/lib/plugins/clipboard/ClipboardPlugin.d.ts +8 -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/ExportPlugin.d.ts +8 -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/GroupingRowsPlugin.d.ts +33 -1
- package/lib/plugins/grouping-rows/grouping-rows.d.ts +15 -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/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 +10 -0
- package/lib/plugins/pivot/index.js +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- 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/RowReorderPlugin.d.ts +3 -0
- 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/TreePlugin.d.ts +16 -0
- package/lib/plugins/tree/index.js +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/tree/types.d.ts +6 -0
- package/lib/plugins/undo-redo/index.js +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +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/clipboard.umd.js +1 -1
- package/umd/plugins/clipboard.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/grouping-rows.umd.js +1 -1
- package/umd/plugins/grouping-rows.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/pivot.umd.js +1 -1
- package/umd/plugins/pivot.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/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/tooltip.umd.js +1 -1
- package/umd/plugins/tooltip.umd.js.map +1 -1
- package/umd/plugins/tree.umd.js +1 -1
- package/umd/plugins/tree.umd.js.map +1 -1
|
@@ -63,6 +63,16 @@ export declare class PivotPlugin extends BaseGridPlugin<PivotConfig> {
|
|
|
63
63
|
* @internal
|
|
64
64
|
*/
|
|
65
65
|
static readonly manifest: PluginManifest;
|
|
66
|
+
/**
|
|
67
|
+
* Optional dependency on MultiSort for coordinated sorting.
|
|
68
|
+
* When MultiSort is loaded, Pivot queries its sort model to apply sorting
|
|
69
|
+
* to pivot columns.
|
|
70
|
+
*/
|
|
71
|
+
static readonly dependencies: {
|
|
72
|
+
name: string;
|
|
73
|
+
required: boolean;
|
|
74
|
+
reason: string;
|
|
75
|
+
}[];
|
|
66
76
|
/** @internal */
|
|
67
77
|
readonly name = "pivot";
|
|
68
78
|
/** @internal */
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,editingStarted:e=>`Editing row ${e+1}`,editingCommitted:e=>`Row ${e+1} saved`,dataLoaded:e=>`${e} rows loaded`},t='<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>',o={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:t,filterActive:t,print:"🖨️"};function i(e,t){if(!e)return;const o="effectiveConfig"in e?e.effectiveConfig:void 0;if(!1===o?.a11y?.announcements)return;const i=e.querySelector?.(".tbw-sr-only");i&&(i.textContent="",requestAnimationFrame(()=>{i.textContent=t}))}function r(t,o,...i){const r=t&&"effectiveConfig"in t?t.effectiveConfig:void 0,n=r?.a11y?.messages?.[o];return n?n(...i):e[o](...i)}function n(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function s(e,t,o,i){return`${n(o,i)} ${e}: ${t}\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 a=/* @__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"]),l=/^on\w+$/i,d=/* @__PURE__ */new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),c=/^\s*(javascript|vbscript|data|blob):/i;function p(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 i of o){const e=i.tagName.toLowerCase();if(a.has(e)){t.push(i);continue}if("svg"===e||"http://www.w3.org/2000/svg"===i.namespaceURI){if(Array.from(i.attributes).some(e=>l.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(i);continue}}const o=[];for(const t of i.attributes){const e=t.name.toLowerCase();l.test(e)?o.push(t.name):(d.has(e)&&c.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&o.push(t.name)}o.forEach(e=>i.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}class u{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{...o,...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}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=p(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,t){void 0!==t?console.warn(s(e,t,this.gridElement.id,this.name)):console.warn(`${n(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(s(e,t,this.gridElement.id,this.name))}}const g={sum:e=>{let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t},avg:e=>{if(!e.length)return 0;let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t/e.length},count:e=>e.length,min:e=>{if(!e.length)return 0;let t=e[0];for(let o=1;o<e.length;o++)e[o]<t&&(t=e[o]);return t},max:e=>{if(!e.length)return 0;let t=e[0];for(let o=1;o<e.length;o++)e[o]>t&&(t=e[o]);return t},first:e=>e[0]??0,last:e=>e[e.length-1]??0};function h(e){return"function"==typeof e?e:function(e){return g[e]??g.sum}(e)}function v(e,t){return[...e,t].join("|")}function f(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=m(e,o,i,n,r,0,"");t.sortRows&&F(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=v([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 m(e,t,o,i,r,n,s){const a=[];if(0===t.length){const t=b(e,o,i,r),l=w(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,p=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[u,g]of p){const e=s?`${s}|${u}`:u,t=b(g,o,i,r),l=w(t);let p;c&&(p=m(g,d,o,i,r,n+1,e)),a.push({rowKey:e,rowLabel:u||"(blank)",depth:n,values:t,total:l,isGroup:c,children:p,rowCount:g.length})}return a}function b(e,t,o,i){const r={};if(0===t.length){for(const t of i){const o=new Array(e.length);for(let r=0;r<e.length;r++)o[r]=Number(e[r][t.field])||0;const i=h(t.aggFunc);r[v(["value"],t.field)]=o.length>0?i(o):null}return r}const n=/* @__PURE__ */new Map;for(let s=0;s<e.length;s++){const o=e[s];let i=String(o[t[0]]??"");for(let e=1;e<t.length;e++)i+="|",i+=String(o[t[e]]??"");const r=n.get(i);r?r.push(o):n.set(i,[o])}for(const s of o){const e=n.get(s);if(e&&0!==e.length)for(const t of i){const o=new Array(e.length);for(let r=0;r<e.length;r++)o[r]=Number(e[r][t.field])||0;const i=h(t.aggFunc);r[v([s],t.field)]=i(o)}else for(const t of i)r[v([s],t.field)]=null}return r}function w(e){let t=0;for(const o of Object.values(e))t+=o??0;return t}function C(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 F(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&&F(r.children,t,o)}function y(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&&y(n.children,t,o)}const x="dragging",_=["sum","avg","count","min","max","first","last"];function A(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(T("Options",()=>function(e,t){const{config:o,callbacks:i,signal:r}=t,n=document.createElement("div");return n.className="tbw-pivot-options",n.appendChild(R("Enable Pivot View",e,e=>{i.onTogglePivot(e)},r)),n.appendChild(R("Show Row Totals",o.showTotals??!0,e=>{i.onOptionChange("showTotals",e)},r)),n.appendChild(R("Show Grand Total",o.showGrandTotal??!0,e=>{i.onOptionChange("showGrandTotal",e)},r)),n}(o,n))),s.appendChild(T("Row Groups",()=>E("rowGroups",n))),s.appendChild(T("Column Groups",()=>E("columnGroups",n))),s.appendChild(T("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(G(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(T("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(x)},{signal:i}),o.addEventListener("dragend",()=>{o.classList.remove(x)},{signal:i}),e.appendChild(o)}r.appendChild(e)}return r}(n))),e.appendChild(s),()=>{r.abort(),s.remove()}}function T(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 E(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(S(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 S(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(x)},{signal:r}),n.addEventListener("dragend",()=>{n.classList.remove(x)},{signal:r}),n}function G(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 p of _){const t=document.createElement("option");t.value=p,t.textContent=p.toUpperCase(),l||(t.selected=p===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 R(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 L(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 P extends u{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:P.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=f(e,this.config);const o=this.getMultiSortConfigs();if(o&&y(this.pivotResult.rows,o,this.config.valueFields??[]),0===this.expandedKeys.size&&!this.userHasToggledExpand){const e=C(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=v([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=v([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?L(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(e){if(!this.isActive)return!1;const t=e.field;if(!this.isPivotField(t))return!1;if(this.isMultiSortActive())return!1;const o=this.mapFieldToSortConfig(t);if(!o)return!1;const n=this.activeSortDir;let s;s=this.activeSortField!==t?"asc":"asc"===n?"desc":null,this.activeSortField=s?t:null,this.activeSortDir=s,this.config.sortRows=s?{...o,direction:s}:void 0,this.emit("pivot-config-change",{property:"sortRows"}),this.refresh();const a=this.gridElement;if(a){const o=e.column.header??t;i(a,s?r(a,"sortApplied",o,"asc"===s?"ascending":"descending"):r(a,"sortCleared"))}return!0}isPivotField(e){return"__pivotLabel"===e||"__pivotTotal"===e||e.includes("|")}isMultiSortActive(){const e=this.grid?.query?.("sort:get-model",null);return Array.isArray(e)&&e.length>0}getMultiSortConfigs(){const e=this.grid?.query?.("sort:get-model",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));L({__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=C(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(P.PANEL_ID)||this.grid.toggleToolPanelSection(P.PANEL_ID)}hidePanel(){this.grid.closeToolPanel()}togglePanel(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection(P.PANEL_ID)}isPanelVisible(){return this.grid.isToolPanelOpen&&this.grid.expandedToolPanelSections.includes(P.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 A(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{P as PivotPlugin};
|
|
1
|
+
const e={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,editingStarted:e=>`Editing row ${e+1}`,editingCommitted:e=>`Row ${e+1} saved`,dataLoaded:e=>`${e} rows loaded`},t='<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>',o={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:t,filterActive:t,print:"🖨️"};function i(e,t){if(!e)return;const o="effectiveConfig"in e?e.effectiveConfig:void 0;if(!1===o?.a11y?.announcements)return;const i=e.querySelector?.(".tbw-sr-only");i&&(i.textContent="",requestAnimationFrame(()=>{i.textContent=t}))}function r(t,o,...i){const r=t&&"effectiveConfig"in t?t.effectiveConfig:void 0,n=r?.a11y?.messages?.[o];return n?n(...i):e[o](...i)}function n(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function s(e,t,o,i){return`${n(o,i)} ${e}: ${t}\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 a=/* @__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"]),l=/^on\w+$/i,d=/* @__PURE__ */new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),c=/^\s*(javascript|vbscript|data|blob):/i;function p(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 i of o){const e=i.tagName.toLowerCase();if(a.has(e)){t.push(i);continue}if("svg"===e||"http://www.w3.org/2000/svg"===i.namespaceURI){if(Array.from(i.attributes).some(e=>l.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(i);continue}}const o=[];for(const t of i.attributes){const e=t.name.toLowerCase();l.test(e)?o.push(t.name):(d.has(e)&&c.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&o.push(t.name)}o.forEach(e=>i.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}class u{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)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(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{...o,...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}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=p(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,t){void 0!==t?console.warn(s(e,t,this.gridElement.id,this.name)):console.warn(`${n(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(s(e,t,this.gridElement.id,this.name))}}const g={sum:e=>{let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t},avg:e=>{if(!e.length)return 0;let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t/e.length},count:e=>e.length,min:e=>{if(!e.length)return 0;let t=e[0];for(let o=1;o<e.length;o++)e[o]<t&&(t=e[o]);return t},max:e=>{if(!e.length)return 0;let t=e[0];for(let o=1;o<e.length;o++)e[o]>t&&(t=e[o]);return t},first:e=>e[0]??0,last:e=>e[e.length-1]??0};function h(e){return"function"==typeof e?e:function(e){return g[e]??g.sum}(e)}function v(e,t){return[...e,t].join("|")}function f(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=m(e,o,i,n,r,0,"");t.sortRows&&F(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=v([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 m(e,t,o,i,r,n,s){const a=[];if(0===t.length){const t=b(e,o,i,r),l=w(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,p=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[u,g]of p){const e=s?`${s}|${u}`:u,t=b(g,o,i,r),l=w(t);let p;c&&(p=m(g,d,o,i,r,n+1,e)),a.push({rowKey:e,rowLabel:u||"(blank)",depth:n,values:t,total:l,isGroup:c,children:p,rowCount:g.length})}return a}function b(e,t,o,i){const r={};if(0===t.length){for(const t of i){const o=new Array(e.length);for(let r=0;r<e.length;r++)o[r]=Number(e[r][t.field])||0;const i=h(t.aggFunc);r[v(["value"],t.field)]=o.length>0?i(o):null}return r}const n=/* @__PURE__ */new Map;for(let s=0;s<e.length;s++){const o=e[s];let i=String(o[t[0]]??"");for(let e=1;e<t.length;e++)i+="|",i+=String(o[t[e]]??"");const r=n.get(i);r?r.push(o):n.set(i,[o])}for(const s of o){const e=n.get(s);if(e&&0!==e.length)for(const t of i){const o=new Array(e.length);for(let r=0;r<e.length;r++)o[r]=Number(e[r][t.field])||0;const i=h(t.aggFunc);r[v([s],t.field)]=i(o)}else for(const t of i)r[v([s],t.field)]=null}return r}function w(e){let t=0;for(const o of Object.values(e))t+=o??0;return t}function C(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 F(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&&F(r.children,t,o)}function y(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&&y(n.children,t,o)}const x="dragging",_=["sum","avg","count","min","max","first","last"];function A(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(R("Enable Pivot View",e,e=>{i.onTogglePivot(e)},r)),n.appendChild(R("Show Row Totals",o.showTotals??!0,e=>{i.onOptionChange("showTotals",e)},r)),n.appendChild(R("Show Grand Total",o.showGrandTotal??!0,e=>{i.onOptionChange("showGrandTotal",e)},r)),n}(o,n))),s.appendChild(E("Row Groups",()=>T("rowGroups",n))),s.appendChild(E("Column Groups",()=>T("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(G(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(x)},{signal:i}),o.addEventListener("dragend",()=>{o.classList.remove(x)},{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 T(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(S(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 S(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(x)},{signal:r}),n.addEventListener("dragend",()=>{n.classList.remove(x)},{signal:r}),n}function G(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 p of _){const t=document.createElement("option");t.value=p,t.textContent=p.toUpperCase(),l||(t.selected=p===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 R(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 L(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 P extends u{static manifest={modifiesRowStructure:!0,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"}]};static dependencies=[{name:"multiSort",required:!1,reason:"Queries sort model for pivot column sorting"}];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:P.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=f(e,this.config);const o=this.getMultiSortConfigs();if(o&&y(this.pivotResult.rows,o,this.config.valueFields??[]),0===this.expandedKeys.size&&!this.userHasToggledExpand){const e=C(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=v([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=v([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?L(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(e){if(!this.isActive)return!1;const t=e.field;if(!this.isPivotField(t))return!1;if(this.isMultiSortActive())return!1;const o=this.mapFieldToSortConfig(t);if(!o)return!1;const n=this.activeSortDir;let s;s=this.activeSortField!==t?"asc":"asc"===n?"desc":null,this.activeSortField=s?t:null,this.activeSortDir=s,this.config.sortRows=s?{...o,direction:s}:void 0,this.emit("pivot-config-change",{property:"sortRows"}),this.refresh();const a=this.gridElement;if(a){const o=e.column.header??t;i(a,s?r(a,"sortApplied",o,"asc"===s?"ascending":"descending"):r(a,"sortCleared"))}return!0}isPivotField(e){return"__pivotLabel"===e||"__pivotTotal"===e||e.includes("|")}isMultiSortActive(){const e=this.grid?.query?.("sort:get-model",null);return Array.isArray(e)&&e.length>0}getMultiSortConfigs(){const e=this.grid?.query?.("sort:get-model",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));L({__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=C(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(P.PANEL_ID)||this.grid.toggleToolPanelSection(P.PANEL_ID)}hidePanel(){this.grid.closeToolPanel()}togglePanel(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection(P.PANEL_ID)}isPanelVisible(){return this.grid.isToolPanelOpen&&this.grid.expandedToolPanelSections.includes(P.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 A(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{P as PivotPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|