@toolbox-web/grid 3.8.3 → 3.9.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/all.d.ts +1 -0
- package/all.js +1 -1
- package/all.js.map +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/lib/core/plugin/base-plugin.d.ts +14 -0
- package/lib/core/plugin/plugin-manager.d.ts +5 -1
- package/lib/core/plugin/types.d.ts +2 -0
- package/lib/features/registry.js +1 -1
- package/lib/plugins/clipboard/index.js +1 -1
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js +1 -1
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/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/grouping-rows-plugin.d.ts +20 -24
- package/lib/plugins/grouping-rows/grouping-rows.d.ts +9 -4
- package/lib/plugins/grouping-rows/index.d.ts +1 -1
- package/lib/plugins/grouping-rows/index.js +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/grouping-rows/types.d.ts +32 -4
- package/lib/plugins/hierarchy/hierarchy-plugin.d.ts +79 -0
- package/lib/plugins/hierarchy/hierarchy.d.ts +28 -0
- package/lib/plugins/hierarchy/index.d.ts +9 -0
- package/lib/plugins/hierarchy/index.js +2 -0
- package/lib/plugins/hierarchy/index.js.map +1 -0
- package/lib/plugins/hierarchy/types.d.ts +92 -0
- 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/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/responsive/index.js +1 -1
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/row-drag-drop/index.js +1 -1
- package/lib/plugins/row-drag-drop/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/shell/index.js +1 -1
- package/lib/plugins/shell/index.js.map +1 -1
- package/lib/plugins/sticky-rows/index.js +1 -1
- package/lib/plugins/sticky-rows/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/tree/tree-datasource.d.ts +7 -10
- package/lib/plugins/tree/tree-plugin.d.ts +23 -3
- 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/grouping-rows.umd.js +1 -1
- package/umd/plugins/grouping-rows.umd.js.map +1 -1
- package/umd/plugins/hierarchy.umd.js +2 -0
- package/umd/plugins/hierarchy.umd.js.map +1 -0
- package/umd/plugins/selection.umd.js +1 -1
- package/umd/plugins/selection.umd.js.map +1 -1
- package/umd/plugins/tree.umd.js +1 -1
- package/umd/plugins/tree.umd.js.map +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var 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`,selectAllRows:()=>"Select all rows",selectRow:e=>`Select row ${e+1}`,columnSelected:e=>`Column ${e} selected`,columnSelectionChanged:e=>`${e} columns selected`,columnSelectionCleared:()=>"Column selection cleared",selectionAxisChanged:e=>"column"===e?"Row selection cleared, column selection active":"Column selection cleared, row selection active",rangeSpanSelected:(e,t)=>1===t?("row"===e?"Row":"Column")+" selected":`${t} ${e}s selected`,editingStarted:e=>`Editing row ${e+1}`,editingCommitted:e=>`Row ${e+1} saved`,dataLoaded:e=>`${e} rows loaded`},t={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function o(e,t){if(!e)return;if(!1===("effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.announcements)return;const o=e.querySelector?.(".tbw-sr-only");o&&(o.textContent="","function"==typeof requestAnimationFrame?requestAnimationFrame(()=>{o.textContent=t}):o.textContent=t)}function i(t,o,...i){const n=(t&&"effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.messages?.[o];return n?n(...i):e[o](...i)}function n(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function r(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)}`}var s="__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".split("|").map(e=>e.split("").reverse().join("")),a=(new RegExp(`__(proto|defineGetter|defineSetter)|${s.slice(3).join("|")}|this\\b`),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|math".split("|"))),l=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),c=/^\s*(javascript|vbscript|data|blob):/i;function u(e){const t=document.createElement("template");return e&&"string"==typeof e&&(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)&&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):"is"!==e?(d.has(e)&&c.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&o.push(t.name):o.push(t.name)}o.forEach(e=>i.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}var p=class{static dependencies;static manifest;aliases;version="3.8.3";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},o={};for(const i of Object.keys(t))o[i]=this;for(const i of e){const e=i.userConfig;for(const[n,s]of Object.entries(e)){if(void 0===s)continue;if(!(n in t)){t[n]=s,o[n]=i;continue}if(t[n]===s)continue;const e=o[n]?.constructor.name??this.constructor.name,a=i.constructor.name,l=r("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${e} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,o={...e.userConfig};for(const i of Object.keys(t))delete t[i];Object.assign(t,o)}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)}queryBoolean(e,t=null){const o=this.grid?.query?.(e,t);return Array.isArray(o)?o.some(Boolean):!!o}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{...t,...e}}t(e,t){return this.grid?.effectiveConfig?.locale?.[e]??t}get translate(){return(e,t)=>this.t(e,t)}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;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}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);var n,r;void 0!==i?"string"==typeof i?(n=e,(r=i)&&"string"==typeof r?-1!==r.indexOf("<")||-1!==r.indexOf("&")?n.replaceChildren(u(r)):n.textContent=r:n.replaceChildren()):i instanceof HTMLElement&&e.replaceChildren(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(r(e,t,this.gridElement.id,this.name)):console.warn(`${n(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(r(e,t,this.gridElement.id,this.name))}};function g(e,t){const o=/* @__PURE__ */new Map;for(const n of t)o.set(n.field,(o.get(n.field)??0)+1);const i=/* @__PURE__ */new Set;return t.map((t,n)=>{const r=function(e,t){return[...e,t].join("|")}(e,t.field);if((o.get(t.field)??0)<2)return r;const s="string"==typeof t.aggFunc?t.aggFunc:"custom",a=`${r}|${s}`,l=`${t.field}\0${s}`;return i.has(l)?`${a}|${n+1}`:(i.add(l),a)})}function h(e,t){const o=t.rowGroupFields??[],i=t.columnGroupFields??[],n=t.valueFields??[],r=function(e,t,o="asc"){if(0===t.length)return["value"];const i=/* @__PURE__ */new Set;for(const r of e){const e=t.map(e=>String(r[e]??"")).join("|");i.add(e)}const n=[...i].sort();return"desc"===o?n.reverse():n}(e,i,t.sortColumns),s=b(e,o,i,r,n,0,"");t.sortRows&&y(s,t.sortRows,n);const a=function(e,t,o){const i={},n=t.flatMap(e=>g([e],o));function r(e){for(const t of e)if(t.isGroup&&t.children?.length)t.children&&r(t.children);else for(const e of n)i[e]=(i[e]??0)+(t.values[e]??0)}return r(e),i}(s,r,n);return{rows:s,columnKeys:r,totals:a,grandTotal:Object.values(a).reduce((e,t)=>e+t,0)}}function v(e,t){const{aggFunc:o,field:i}=t;if("function"==typeof o){const t=[];for(let o=0;o<e.length;o++){const n=e[o][i];if(null==n||""===n)continue;const r=Number(n);isNaN(r)||t.push(r)}return t.length>0?o(t):null}if("first"===o){for(let t=0;t<e.length;t++){const o=e[t][i];if(null==o||""===o)continue;const n=Number(o);if(!isNaN(n))return n}return null}if("last"===o){for(let t=e.length-1;t>=0;t--){const o=e[t][i];if(null==o||""===o)continue;const n=Number(o);if(!isNaN(n))return n}return null}let n="min"===o?1/0:"max"===o?-1/0:0,r=0;for(let s=0;s<e.length;s++){const t=e[s][i];if(null==t||""===t)continue;const a=Number(t);isNaN(a)||(r++,"min"===o?a<n&&(n=a):"max"===o?a>n&&(n=a):"count"!==o&&(n+=a))}return 0===r?null:"avg"===o?n/r:"count"===o?r:n}function f(e,t,o,i,n){let r=0,s=0,a=1/0,l=-1/0,d=null,c=null;for(let u=0;u<e.length;u++){const o=e[u][t];if(null==o||""===o)continue;const i=Number(o);isNaN(i)||(0===s&&(d=i),c=i,r+=i,s++,i<a&&(a=i),i>l&&(l=i))}for(let u=0;u<o.length;u++){const e=o[u];if(e.field!==t||"function"==typeof e.aggFunc)continue;let p;p=0===s?null:"avg"===e.aggFunc?r/s:"count"===e.aggFunc?s:"min"===e.aggFunc?a:"max"===e.aggFunc?l:"first"===e.aggFunc?d:"last"===e.aggFunc?c:r,n[i[u]]=p}}function m(e,t,o,i){for(let n=0;n<t.length;n++){const r=t[n];let s=!1,a=0;for(let e=0;e<t.length;e++)t[e].field===r.field&&(e<n&&(s=!0),"function"!=typeof t[e].aggFunc&&a++);if(!s){a>1&&f(e,r.field,t,o,i);for(let s=n;s<t.length;s++){const n=t[s];n.field===r.field&&(a>1&&"function"!=typeof n.aggFunc||(i[o[s]]=v(e,n)))}}}}function b(e,t,o,i,n,r,s){const a=[];if(0===t.length){const t=w(e,o,i,n),l=C(t);return a.push({rowKey:s||"all",rowLabel:s||"All",depth:r,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]??""),n=o.get(e);n?n.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,n),l=C(t);let u;c&&(u=b(g,d,o,i,n,r+1,e)),a.push({rowKey:e,rowLabel:p||"(blank)",depth:r,values:t,total:l,isGroup:c,children:u,rowCount:g.length})}return a}function w(e,t,o,i){const n={};if(0===t.length)return m(e,i,g(["value"],i),n),n;const r=/* @__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 n=r.get(i);n?n.push(o):r.set(i,[o])}for(const s of o){const e=g([s],i),t=r.get(s);if(t&&0!==t.length)m(t,i,e,n);else for(const o of e)n[o]=null}return n}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,n)=>"value"===t.by&&(t.valueField??o[0]?.field)?((e.total??0)-(n.total??0))*i:e.rowLabel.localeCompare(n.rowLabel)*i);for(const n of e)n.children?.length&&y(n.children,t,o)}function x(e,t,o){if(0===t.length)return;const i=new Set(o.map(e=>e.field)),n=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,n=!1;for(const t of Object.keys(e.values))t.endsWith(o)&&(i+="number"==typeof e.values[t]?e.values[t]:0,n=!0);if(n)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 r=t[i],s="desc"===r.direction?-1:1;let a=0;if("value"===r.by){const t=n[i];a=(t(e)-t(o))*s}else a=e.rowLabel.localeCompare(o.rowLabel)*s;if(0!==a)return a}return 0});for(const r of e)r.children?.length&&x(r.children,t,o)}var A="dragging";function _(){return"function"==typeof HTMLElement.prototype?.showPopover}function T(e,t){let o=null,i=!1,n=!1;const r=new AbortController;function s(){i&&o&&(i=!1,_()&&o.hidePopover(),o.hidden=!0)}return document.addEventListener("pointerdown",e=>{i&&o&&!e.composedPath().includes(o)&&s()},{capture:!0,signal:r.signal}),document.addEventListener("keydown",e=>{"Escape"===e.key&&s()},{capture:!0,signal:r.signal}),{get element(){return o},open(a,l,d){if(n||0===d.length)return;o||(o=function(){const o=document.createElement("div");return o.id=e,o.className=t,o.setAttribute("popover","manual"),o.setAttribute("role","group"),o.hidden=!0,o.addEventListener("focusout",e=>{const t=e.relatedTarget;t instanceof Node&&!o.contains(t)&&s()},{signal:r.signal}),o}());const c=a.closest("tbw-grid, [data-tbw-grid]")??document.body;o.parentNode!==c&&c.appendChild(o),o.setAttribute("aria-label",l),o.replaceChildren();for(const e of d){const i=document.createElement("button");i.type="button",i.className=`${t}-item`,i.textContent=e.label,i.disabled=!0===e.disabled,i.addEventListener("click",()=>{s(),e.run()}),o.appendChild(i)}o.hidden=!1,!i&&_()&&o.showPopover(),i=!0,function(e){if(!o)return;const t=e.getBoundingClientRect(),i=o.getBoundingClientRect(),n=Math.max(4,Math.min(t.left,window.innerWidth-i.width-4)),r=t.bottom+6,s=r+i.height<=window.innerHeight?r:Math.max(4,t.top-6-i.height);o.style.left=`${Math.round(n)}px`,o.style.top=`${Math.round(s)}px`}(a),o.querySelector("button:not([disabled])")?.focus()},close:s,dispose(){n=!0,s(),r.abort(),o?.remove(),o=null}}}var E=null,G=["sum","avg","count","min","max","first","last"];function S(e,t,o,i,n=(e,t)=>t){const r=new AbortController,s={config:t,callbacks:i,signal:r.signal,t:n},a=document.createElement("div");return a.className="tbw-pivot-panel",a.appendChild(P(n("pivot.options","Options"),()=>function(e,t){const{config:o,callbacks:i,signal:n,t:r}=t,s=document.createElement("div");return s.className="tbw-pivot-options",s.appendChild(I(r("pivot.enable","Enable Pivot View"),e,e=>{i.onTogglePivot(e)},n)),s.appendChild(I(r("pivot.showRowTotals","Show Row Totals"),o.showTotals??!0,e=>{i.onOptionChange("showTotals",e)},n)),s.appendChild(I(r("pivot.showGrandTotal","Show Grand Total"),o.showGrandTotal??!0,e=>{i.onOptionChange("showGrandTotal",e)},n)),s}(o,s))),a.appendChild(P(n("pivot.rowGroups","Row Groups"),()=>N("rowGroups",s))),a.appendChild(P(n("pivot.columnGroups","Column Groups"),()=>N("columnGroups",s))),a.appendChild(P(n("pivot.values","Values"),()=>function(e){const{config:t,callbacks:o,signal:i}=e,n=document.createElement("div");n.className="tbw-pivot-drop-zone tbw-pivot-values-zone",n.setAttribute("data-zone","values");const r=t.valueFields??[];if(0===r.length){const t=document.createElement("div");t.className="tbw-pivot-placeholder",t.textContent=e.t("pivot.dropNumericFields","Drag numeric fields here"),n.appendChild(t)}else for(const s of r)n.appendChild($(s,e));return n.addEventListener("dragover",e=>{e.preventDefault(),n.classList.add("drag-over")},{signal:i}),n.addEventListener("dragleave",()=>{n.classList.remove("drag-over")},{signal:i}),n.addEventListener("drop",e=>{e.preventDefault(),n.classList.remove("drag-over");const t=e.dataTransfer?.getData("text/plain");t&&o.onAddValueField(t,"sum")},{signal:i}),n}(s))),a.appendChild(P(n("pivot.availableFields","Available Fields"),()=>function(e){const{config:t,callbacks:o,signal:i}=e,n=document.createElement("div");n.className="tbw-pivot-available-fields";const r=o.getAvailableFields(),s=/* @__PURE__ */new Set([...t.rowGroupFields??[],...t.columnGroupFields??[],...t.valueFields?.map(e=>e.field)??[]]),a=r.filter(e=>!s.has(e.field));if(0===a.length){const t=document.createElement("div");t.className="tbw-pivot-placeholder",t.textContent=e.t("pivot.allFieldsUsed","All fields are in use"),n.appendChild(t)}else{const t=document.createElement("div");if(t.className="tbw-pivot-fields-list",a.length>=6){const o=document.createElement("input");o.type="text",o.placeholder=e.t("pivot.filterFields","Filter fields…"),o.className="tbw-pivot-field-search",o.addEventListener("input",()=>{const e=o.value.toLowerCase();for(const o of t.querySelectorAll(".tbw-pivot-field-chip")){const t=o;t.style.display=t.textContent?.toLowerCase().includes(e)?"":"none"}},{signal:i}),n.appendChild(o)}for(const o of a){const n=document.createElement("div");n.className="tbw-pivot-field-chip available",n.textContent=o.header,n.draggable=!0,n.title=e.t("pivot.availableChipHint","Drag into a zone, or click to choose one"),k(n,o.header,e.t),n.addEventListener("dragstart",e=>{e.dataTransfer?.setData("text/plain",o.field),n.classList.add(A)},{signal:i}),n.addEventListener("dragend",()=>{n.classList.remove(A)},{signal:i}),n.addEventListener("click",()=>R(n,o.header,L(o.field,e)),{signal:i}),t.appendChild(n)}n.appendChild(t)}return n}(s))),e.appendChild(a),()=>{r.abort(),E?.dispose(),E=null,a.remove()}}function R(e,t,o){E??=T("tbw-pivot-chip-menu","tbw-pivot-chip-menu"),E.open(e,t,o)}function k(e,t,o){e.setAttribute("role","button"),e.tabIndex=-1,e.setAttribute("aria-label",`${t} — ${o("pivot.chipHint","drag, or activate for move options")}`)}function L(e,t){const{callbacks:o,t:i}=t;return[{label:i("pivot.addToRowGroups","Add to Row Groups"),run:()=>o.onAddFieldToZone(e,"rowGroups")},{label:i("pivot.addToColumnGroups","Add to Column Groups"),run:()=>o.onAddFieldToZone(e,"columnGroups")},{label:i("pivot.addToValues","Add to Values"),run:()=>o.onAddValueField(e,"sum")}]}function P(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 n=document.createElement("div");return n.className="tbw-pivot-section-content",n.appendChild(t()),o.appendChild(i),o.appendChild(n),o}function N(e,t){const{config:o,callbacks:i,signal:n}=t,r=document.createElement("div");r.className="tbw-pivot-drop-zone",r.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=t.t("pivot.dropFields","Drag fields here"),r.appendChild(e)}else for(const a of s)r.appendChild(M(a,e,t));return r.addEventListener("dragover",e=>{e.preventDefault(),r.classList.add("drag-over")},{signal:n}),r.addEventListener("dragleave",()=>{r.classList.remove("drag-over")},{signal:n}),r.addEventListener("drop",t=>{t.preventDefault(),r.classList.remove("drag-over");const o=t.dataTransfer?.getData("text/plain"),n=t.dataTransfer?.getData("source-zone");if(!o)return;const s=r.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}}!n||n===e||"rowGroups"!==n&&"columnGroups"!==n?n===e?i.onReorderFieldInZone(o,e,a):i.onAddFieldToZone(o,e):i.onMoveFieldBetweenZones(o,n,e)},{signal:n}),r}function M(e,t,o){const{callbacks:i,signal:n}=o,r=document.createElement("div");r.className="tbw-pivot-field-chip",r.draggable=!0;const s=i.getAvailableFields().find(t=>t.field===e)?.header??e,a=document.createElement("span");a.className="tbw-pivot-chip-label",a.textContent=s,k(a,s,o.t);const l=document.createElement("button");return l.type="button",l.className="tbw-pivot-chip-remove",l.innerHTML="×",l.title=o.t("pivot.removeField","Remove field"),l.addEventListener("click",o=>{o.stopPropagation(),i.onRemoveFieldFromZone(e,t)},{signal:n}),r.appendChild(a),r.appendChild(l),r.addEventListener("dragstart",o=>{o.dataTransfer?.setData("text/plain",e),o.dataTransfer?.setData("source-zone",t),r.classList.add(A)},{signal:n}),r.addEventListener("dragend",()=>{r.classList.remove(A)},{signal:n}),r.addEventListener("click",()=>R(r,s,function(e,t,o){const{config:i,callbacks:n,t:r}=o,s="rowGroups"===t?i.rowGroupFields??[]:i.columnGroupFields??[],a=s.indexOf(e),l="rowGroups"===t?"columnGroups":"rowGroups";return[{label:r("pivot.moveUp","Move up"),disabled:a<=0,run:()=>n.onReorderFieldInZone(e,t,a-1)},{label:r("pivot.moveDown","Move down"),disabled:a<0||a>=s.length-1,run:()=>n.onReorderFieldInZone(e,t,a+2)},{label:"columnGroups"===l?r("pivot.moveToColumnGroups","Move to Column Groups"):r("pivot.moveToRowGroups","Move to Row Groups"),run:()=>n.onMoveFieldBetweenZones(e,t,l)},{label:r("pivot.moveToValues","Move to Values"),run:()=>n.onAddValueField(e,"sum")},{label:r("pivot.removeField","Remove field"),run:()=>n.onRemoveFieldFromZone(e,t)}]}(e,t,o)),{signal:n}),r}function $(e,t){const{callbacks:o,signal:i}=t,n=document.createElement("div");n.className="tbw-pivot-field-chip tbw-pivot-value-chip";const r=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=r?.header??e.field;const l="function"==typeof e.aggFunc,d=document.createElement("select");if(d.className="tbw-pivot-agg-select",d.title=t.t("pivot.aggFunction","Aggregation function"),l){const e=document.createElement("option");e.value="__custom__",e.textContent=t.t("pivot.customAgg","CUSTOM"),e.selected=!0,d.appendChild(e),d.disabled=!0}for(const u of G){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.type="button",c.className="tbw-pivot-chip-remove",c.innerHTML="×",c.title=t.t("pivot.removeValueField","Remove value field"),c.addEventListener("click",t=>{t.stopPropagation(),o.onRemoveValueField(e.field)},{signal:i}),s.appendChild(a),s.appendChild(d),n.appendChild(s),n.appendChild(c),n}function I(e,t,o,i){const n=document.createElement("label");n.className="tbw-pivot-checkbox";const r=document.createElement("input");r.type="checkbox",r.checked=t,r.addEventListener("change",()=>o(r.checked),{signal:i});const s=document.createElement("span");return s.textContent=e,n.appendChild(r),n.appendChild(s),n}function q(e,t,o,i=(e,t)=>t){return t.className="data-grid-row pivot-grand-total-row",t.innerHTML="",o.forEach((o,n)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(n)),0===n){const e=document.createElement("span");e.className="pivot-label",e.textContent=i("pivot.grandTotal","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}var z=class e extends p{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:"shell",required:!1,severity:"warn",when:e=>!0===e.showToolPanel,reason:"PivotPlugin renders its tool panel in a shell host when showToolPanel is enabled"}];name="pivot";styles='@layer tbw-plugins{.pivot-group-row{grid-template-columns:var(--tbw-column-template);background:var(--tbw-pivot-group-bg,var(--tbw-color-row-alt));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider);font-weight:600;display:grid}@media (hover:hover){.pivot-group-row:hover{background:var(--tbw-pivot-group-hover,var(--tbw-color-row-hover))}}.pivot-leaf-row{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);display:grid}.pivot-grand-total-row{grid-template-columns:var(--tbw-column-template);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);font-weight:700;display:grid}.pivot-grand-total-row>.cell{padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);align-items:center;min-width:0;display:flex;overflow:hidden}.pivot-grand-total-row>.cell:last-child{border-right:0}.pivot-grand-total-footer{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;position:sticky;bottom:0}.pivot-group-row>.cell,.pivot-leaf-row>.cell{padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);align-items:center;min-width:0;display:flex;overflow:hidden}.pivot-group-row>.cell:last-child,.pivot-leaf-row>.cell:last-child{border-right:0}.pivot-toggle{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);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);background:0 0;border:none;justify-content:center;align-items:center;display:inline-flex}.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{position:relative}.pivot-toggle:after{content:"";inline-size:var(--tbw-touch-target-min,24px);block-size:var(--tbw-touch-target-min,24px);position:absolute;inset-block-start:50%;inset-inline-start:50%;translate:-50% -50%}@media (pointer:coarse){.pivot-toggle{min-width:var(--tbw-touch-target-min,24px);min-height:var(--tbw-touch-target-min,24px)}}.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{border-top:2px solid var(--tbw-pivot-border,var(--tbw-color-border-strong));font-weight:700}[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{gap:var(--tbw-panel-padding,var(--tbw-spacing-lg,.75rem));padding:var(--tbw-panel-padding,var(--tbw-spacing-lg,.75rem));height:100%;font-size:var(--tbw-font-size-sm,.8125rem);flex-direction:column;display:flex;overflow-y:auto}.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));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;font-weight:600}.tbw-pivot-section-content{padding:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem))}.tbw-pivot-toggle-wrapper{align-items:center;display:flex}.tbw-pivot-toggle-label{align-items:center;gap:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));cursor:pointer;display:flex}.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));gap:var(--tbw-spacing-sm,.375rem);flex-wrap:wrap;align-content:flex-start;transition:all .15s;display:flex}.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);padding:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));text-align:center;width:100%;font-style:italic}.tbw-pivot-field-chip{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;display:inline-flex}.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;text-overflow:ellipsis;max-width:120px;overflow:hidden}.tbw-pivot-chip-remove{width:var(--tbw-icon-size,1rem);height:var(--tbw-icon-size,1rem);color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-sm,.875rem);cursor:pointer;background:0 0;border:none;border-radius:50%;justify-content:center;align-items:center;padding:0;font-weight:700;transition:all .15s;display:flex}.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-chip-menu{min-width:12rem;padding:var(--tbw-spacing-xs,.25rem);background:var(--tbw-color-panel-bg,light-dark(#fff,#1f1f1f));color:var(--tbw-color-fg,light-dark(#1a1a1a,#f0f0f0));border:1px solid var(--tbw-color-border,light-dark(#d0d0d0,#3a3a3a));border-radius:var(--tbw-border-radius,.25rem);box-shadow:var(--tbw-shadow-md,0 4px 12px #00000040);font:inherit;z-index:10001;flex-direction:column;margin:0;display:flex;position:fixed}.tbw-pivot-chip-menu[hidden]{display:none}.tbw-pivot-chip-menu-item{min-height:var(--tbw-touch-target-min,24px);padding:var(--tbw-spacing-xs,.25rem) var(--tbw-spacing-sm,.5rem);text-align:start;border-radius:min(var(--tbw-border-radius,.25rem), 6px);color:inherit;font:inherit;cursor:pointer;background:0 0;border:none}.tbw-pivot-chip-menu-item:hover:not(:disabled){background:var(--tbw-color-row-hover,light-dark(#f0f0f0,#2a2a2a))}.tbw-pivot-chip-menu-item:disabled{opacity:.5;cursor:default}.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{align-items:center;gap:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));flex:1;min-width:0;display:flex}.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{gap:var(--tbw-spacing-sm,.375rem);flex-direction:column;min-height:40px;display:flex}.tbw-pivot-field-search{border:1px solid var(--tbw-color-border,#d0d5dd);border-radius:var(--tbw-radius-sm,.25rem);width:100%;font-size:var(--tbw-font-size-sm,.875rem);background:var(--tbw-color-bg,#fff);color:var(--tbw-color-fg,#1a1a2e);outline:none;padding:.25rem .5rem}.tbw-pivot-field-search:focus{border-color:var(--tbw-color-primary,#3b82f6)}.tbw-pivot-fields-list{gap:var(--tbw-spacing-sm,.375rem);flex-wrap:wrap;display:flex}.tbw-pivot-options{gap:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));flex-direction:column;display:flex}.tbw-pivot-checkbox{align-items:center;gap:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));cursor:pointer;display:flex}.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:e.PANEL_ID,title:this.t("pivot.panelTitle","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=h(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={},n=t.flatMap(e=>g([e],o));return function e(t){for(const o of t)if(o.isGroup&&o.children?.length)o.children&&e(o.children);else for(const e of n)i[e]=(i[e]??0)+(o.values[e]??0)}(e),i}(this.pivotResult.rows,this.pivotResult.columnKeys,this.config.valueFields??[]));const i=this.config.indentWidth??20,n=!0===this.defaultExpanded||void 0===this.defaultExpanded,r=function(e,t,o=!0){const i=[];function n(e){i.push(e);const r=t?t.has(e.rowKey):o;if(e.children&&r)for(const t of e.children)n(t)}for(const r of e)n(r);return i}(this.pivotResult.rows,this.expandedKeys,n).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 r){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&&r.push({__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotDepth:0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals}),r}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});const i=this.config.valueFields??[];for(const n of this.pivotResult.columnKeys){const e=g([n],i);for(let o=0;o<i.length;o++){const r=i[o],s=e[o],a=r.header||this.fieldHeaderMap.get(r.field)||r.field,l="function"==typeof r.aggFunc?"custom":r.aggFunc,d=this.valueFormatters.get(o);t.push({field:s,header:`${n} - ${a} (${l})`,width:120,type:"number",sortable:!0,...d?{format:e=>null!=e?d(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?q(i,t,this.gridColumns,this.translate):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,n)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(n)),r.setAttribute("data-row",String(o.rowIndex)),r.setAttribute("role","gridcell"),0===n){const t=Number(e.__pivotIndent)||0;r.style.paddingLeft=`${t}px`;const i=String(e.__pivotRowKey),n=document.createElement("button");n.type="button",n.className="pivot-toggle",n.setAttribute("aria-label",e.__pivotExpanded?"Collapse group":"Expand group"),o.setIcon(n,e.__pivotExpanded?"collapse":"expand"),n.addEventListener("click",e=>{e.stopPropagation(),o.onToggle(i)}),r.appendChild(n);const s=document.createElement("span");s.className="pivot-label",s.textContent=String(e.__pivotLabel??""),r.appendChild(s);const a=document.createElement("span");a.className="pivot-count",a.textContent=` (${Number(e.__pivotRowCount)||0})`,r.appendChild(a)}else{const t=e[i.field];r.textContent=null!=t?i.format?i.format(t,e):String(t):""}t.appendChild(r)}),!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,n)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(n)),r.setAttribute("data-row",String(i)),r.setAttribute("role","gridcell"),0===n){const t=Number(e.__pivotIndent)||0;r.style.paddingLeft=`${t+20}px`;const o=document.createElement("span");o.className="pivot-label",o.textContent=String(e.__pivotLabel??""),r.appendChild(o)}else{const t=e[o.field];r.textContent=null!=t?o.format?o.format(t,e):String(t):""}t.appendChild(r)}),!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 n=this.mapFieldToSortConfig(t);if(!n)return!1;const r=this.activeSortDir;let s;s=this.activeSortField!==t?"asc":"asc"===r?"desc":null,this.activeSortField=s?t:null,this.activeSortDir=s,this.config.sortRows=s?{...n,direction:s}:void 0,this.emit("pivot-config-change",{property:"sortRows"}),this.refresh();const a=this.gridElement;if(a){const n=e.column.header??t;o(a,s?i(a,"sortApplied",n,"asc"===s?"ascending":"descending"):i(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,n=e.querySelectorAll(".header-row .cell[data-field]");for(const r of n){const e=r.getAttribute("data-field");if(!e||!this.isPivotField(e))continue;let n=null;t===e?n=o:i&&("label"===i.by&&"__pivotLabel"===e?n=i.direction??"asc":"value"!==i.by||"__pivotTotal"!==e||i.valueField?"value"===i.by&&i.valueField&&e===i.valueField&&(n=i.direction??"asc"):n=i.direction??"asc"),this.updateSortIndicator(r,n)}}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));q({__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals},this.grandTotalFooter,this.gridColumns,this.translate),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()}#o(){return this.grid.getPluginByName("shell")}showPanel(){const t=this.#o();t?.openToolPanel(),t?.expandedToolPanelSections.includes(e.PANEL_ID)||t?.toggleToolPanelSection(e.PANEL_ID)}hidePanel(){this.#o()?.closeToolPanel()}togglePanel(){const t=this.#o();t?.isToolPanelOpen||t?.openToolPanel(),t?.toggleToolPanelSection(e.PANEL_ID)}isPanelVisible(){const t=this.#o();return!!t?.isToolPanelOpen&&t.expandedToolPanelSections.includes(e.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){return this.panelContainer=e,0===this.originalColumns.length&&this.captureOriginalColumns(),S(e,this.config,this.isActive,{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()},this.translate)}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??[]],n=i.indexOf(e);-1!==n&&n!==o&&(i.splice(n,1),i.splice(o>n?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(let t=0;t<e.length;t++){const o=e[t];if(o.format)this.valueFormatters.set(t,o.format);else if(this.originalColumns.find(e=>e.field===o.field)){const e=(this.grid.getAllColumns?.()??this.grid.columns??[]).find(e=>e.field===o.field);if(e?.format){const o=e.format;this.valueFormatters.set(t,e=>o(e,{}))}}}}};export{z as PivotPlugin};
|
|
1
|
+
var 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`,selectAllRows:()=>"Select all rows",selectRow:e=>`Select row ${e+1}`,columnSelected:e=>`Column ${e} selected`,columnSelectionChanged:e=>`${e} columns selected`,columnSelectionCleared:()=>"Column selection cleared",selectionAxisChanged:e=>"column"===e?"Row selection cleared, column selection active":"Column selection cleared, row selection active",rangeSpanSelected:(e,t)=>1===t?("row"===e?"Row":"Column")+" selected":`${t} ${e}s selected`,editingStarted:e=>`Editing row ${e+1}`,editingCommitted:e=>`Row ${e+1} saved`,dataLoaded:e=>`${e} rows loaded`},t={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function o(e,t){if(!e)return;if(!1===("effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.announcements)return;const o=e.querySelector?.(".tbw-sr-only");o&&(o.textContent="","function"==typeof requestAnimationFrame?requestAnimationFrame(()=>{o.textContent=t}):o.textContent=t)}function i(t,o,...i){const n=(t&&"effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.messages?.[o];return n?n(...i):e[o](...i)}function n(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function r(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)}`}var s="__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".split("|").map(e=>e.split("").reverse().join("")),a=(new RegExp(`__(proto|defineGetter|defineSetter)|${s.slice(3).join("|")}|this\\b`),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|math".split("|"))),l=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),c=/^\s*(javascript|vbscript|data|blob):/i;function u(e){const t=document.createElement("template");return e&&"string"==typeof e&&(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)&&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):"is"!==e?(d.has(e)&&c.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&o.push(t.name):o.push(t.name)}o.forEach(e=>i.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}var p=class{static dependencies;static manifest;aliases;version="3.9.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},o={};for(const i of Object.keys(t))o[i]=this;for(const i of e){const e=i.userConfig;for(const[n,s]of Object.entries(e)){if(void 0===s)continue;if(!(n in t)){t[n]=s,o[n]=i;continue}if(t[n]===s)continue;const e=o[n]?.constructor.name??this.constructor.name,a=i.constructor.name,l=r("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${e} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,o={...e.userConfig};for(const i of Object.keys(t))delete t[i];Object.assign(t,o)}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)}queryBoolean(e,t=null){const o=this.grid?.query?.(e,t);return Array.isArray(o)?o.some(Boolean):!!o}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{...t,...e}}t(e,t){return this.grid?.effectiveConfig?.locale?.[e]??t}get translate(){return(e,t)=>this.t(e,t)}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;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}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);var n,r;void 0!==i?"string"==typeof i?(n=e,(r=i)&&"string"==typeof r?-1!==r.indexOf("<")||-1!==r.indexOf("&")?n.replaceChildren(u(r)):n.textContent=r:n.replaceChildren()):i instanceof HTMLElement&&e.replaceChildren(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(r(e,t,this.gridElement.id,this.name)):console.warn(`${n(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(r(e,t,this.gridElement.id,this.name))}};function g(e,t){const o=/* @__PURE__ */new Map;for(const n of t)o.set(n.field,(o.get(n.field)??0)+1);const i=/* @__PURE__ */new Set;return t.map((t,n)=>{const r=function(e,t){return[...e,t].join("|")}(e,t.field);if((o.get(t.field)??0)<2)return r;const s="string"==typeof t.aggFunc?t.aggFunc:"custom",a=`${r}|${s}`,l=`${t.field}\0${s}`;return i.has(l)?`${a}|${n+1}`:(i.add(l),a)})}function h(e,t){const o=t.rowGroupFields??[],i=t.columnGroupFields??[],n=t.valueFields??[],r=function(e,t,o="asc"){if(0===t.length)return["value"];const i=/* @__PURE__ */new Set;for(const r of e){const e=t.map(e=>String(r[e]??"")).join("|");i.add(e)}const n=[...i].sort();return"desc"===o?n.reverse():n}(e,i,t.sortColumns),s=b(e,o,i,r,n,0,"");t.sortRows&&y(s,t.sortRows,n);const a=function(e,t,o){const i={},n=t.flatMap(e=>g([e],o));function r(e){for(const t of e)if(t.isGroup&&t.children?.length)t.children&&r(t.children);else for(const e of n)i[e]=(i[e]??0)+(t.values[e]??0)}return r(e),i}(s,r,n);return{rows:s,columnKeys:r,totals:a,grandTotal:Object.values(a).reduce((e,t)=>e+t,0)}}function v(e,t){const{aggFunc:o,field:i}=t;if("function"==typeof o){const t=[];for(let o=0;o<e.length;o++){const n=e[o][i];if(null==n||""===n)continue;const r=Number(n);isNaN(r)||t.push(r)}return t.length>0?o(t):null}if("first"===o){for(let t=0;t<e.length;t++){const o=e[t][i];if(null==o||""===o)continue;const n=Number(o);if(!isNaN(n))return n}return null}if("last"===o){for(let t=e.length-1;t>=0;t--){const o=e[t][i];if(null==o||""===o)continue;const n=Number(o);if(!isNaN(n))return n}return null}let n="min"===o?1/0:"max"===o?-1/0:0,r=0;for(let s=0;s<e.length;s++){const t=e[s][i];if(null==t||""===t)continue;const a=Number(t);isNaN(a)||(r++,"min"===o?a<n&&(n=a):"max"===o?a>n&&(n=a):"count"!==o&&(n+=a))}return 0===r?null:"avg"===o?n/r:"count"===o?r:n}function f(e,t,o,i,n){let r=0,s=0,a=1/0,l=-1/0,d=null,c=null;for(let u=0;u<e.length;u++){const o=e[u][t];if(null==o||""===o)continue;const i=Number(o);isNaN(i)||(0===s&&(d=i),c=i,r+=i,s++,i<a&&(a=i),i>l&&(l=i))}for(let u=0;u<o.length;u++){const e=o[u];if(e.field!==t||"function"==typeof e.aggFunc)continue;let p;p=0===s?null:"avg"===e.aggFunc?r/s:"count"===e.aggFunc?s:"min"===e.aggFunc?a:"max"===e.aggFunc?l:"first"===e.aggFunc?d:"last"===e.aggFunc?c:r,n[i[u]]=p}}function m(e,t,o,i){for(let n=0;n<t.length;n++){const r=t[n];let s=!1,a=0;for(let e=0;e<t.length;e++)t[e].field===r.field&&(e<n&&(s=!0),"function"!=typeof t[e].aggFunc&&a++);if(!s){a>1&&f(e,r.field,t,o,i);for(let s=n;s<t.length;s++){const n=t[s];n.field===r.field&&(a>1&&"function"!=typeof n.aggFunc||(i[o[s]]=v(e,n)))}}}}function b(e,t,o,i,n,r,s){const a=[];if(0===t.length){const t=w(e,o,i,n),l=C(t);return a.push({rowKey:s||"all",rowLabel:s||"All",depth:r,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]??""),n=o.get(e);n?n.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,n),l=C(t);let u;c&&(u=b(g,d,o,i,n,r+1,e)),a.push({rowKey:e,rowLabel:p||"(blank)",depth:r,values:t,total:l,isGroup:c,children:u,rowCount:g.length})}return a}function w(e,t,o,i){const n={};if(0===t.length)return m(e,i,g(["value"],i),n),n;const r=/* @__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 n=r.get(i);n?n.push(o):r.set(i,[o])}for(const s of o){const e=g([s],i),t=r.get(s);if(t&&0!==t.length)m(t,i,e,n);else for(const o of e)n[o]=null}return n}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,n)=>"value"===t.by&&(t.valueField??o[0]?.field)?((e.total??0)-(n.total??0))*i:e.rowLabel.localeCompare(n.rowLabel)*i);for(const n of e)n.children?.length&&y(n.children,t,o)}function x(e,t,o){if(0===t.length)return;const i=new Set(o.map(e=>e.field)),n=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,n=!1;for(const t of Object.keys(e.values))t.endsWith(o)&&(i+="number"==typeof e.values[t]?e.values[t]:0,n=!0);if(n)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 r=t[i],s="desc"===r.direction?-1:1;let a=0;if("value"===r.by){const t=n[i];a=(t(e)-t(o))*s}else a=e.rowLabel.localeCompare(o.rowLabel)*s;if(0!==a)return a}return 0});for(const r of e)r.children?.length&&x(r.children,t,o)}var A="dragging";function _(){return"function"==typeof HTMLElement.prototype?.showPopover}function T(e,t){let o=null,i=!1,n=!1;const r=new AbortController;function s(){i&&o&&(i=!1,_()&&o.hidePopover(),o.hidden=!0)}return document.addEventListener("pointerdown",e=>{i&&o&&!e.composedPath().includes(o)&&s()},{capture:!0,signal:r.signal}),document.addEventListener("keydown",e=>{"Escape"===e.key&&s()},{capture:!0,signal:r.signal}),{get element(){return o},open(a,l,d){if(n||0===d.length)return;o||(o=function(){const o=document.createElement("div");return o.id=e,o.className=t,o.setAttribute("popover","manual"),o.setAttribute("role","group"),o.hidden=!0,o.addEventListener("focusout",e=>{const t=e.relatedTarget;t instanceof Node&&!o.contains(t)&&s()},{signal:r.signal}),o}());const c=a.closest("tbw-grid, [data-tbw-grid]")??document.body;o.parentNode!==c&&c.appendChild(o),o.setAttribute("aria-label",l),o.replaceChildren();for(const e of d){const i=document.createElement("button");i.type="button",i.className=`${t}-item`,i.textContent=e.label,i.disabled=!0===e.disabled,i.addEventListener("click",()=>{s(),e.run()}),o.appendChild(i)}o.hidden=!1,!i&&_()&&o.showPopover(),i=!0,function(e){if(!o)return;const t=e.getBoundingClientRect(),i=o.getBoundingClientRect(),n=Math.max(4,Math.min(t.left,window.innerWidth-i.width-4)),r=t.bottom+6,s=r+i.height<=window.innerHeight?r:Math.max(4,t.top-6-i.height);o.style.left=`${Math.round(n)}px`,o.style.top=`${Math.round(s)}px`}(a),o.querySelector("button:not([disabled])")?.focus()},close:s,dispose(){n=!0,s(),r.abort(),o?.remove(),o=null}}}var E=null,G=["sum","avg","count","min","max","first","last"];function S(e,t,o,i,n=(e,t)=>t){const r=new AbortController,s={config:t,callbacks:i,signal:r.signal,t:n},a=document.createElement("div");return a.className="tbw-pivot-panel",a.appendChild(P(n("pivot.options","Options"),()=>function(e,t){const{config:o,callbacks:i,signal:n,t:r}=t,s=document.createElement("div");return s.className="tbw-pivot-options",s.appendChild(I(r("pivot.enable","Enable Pivot View"),e,e=>{i.onTogglePivot(e)},n)),s.appendChild(I(r("pivot.showRowTotals","Show Row Totals"),o.showTotals??!0,e=>{i.onOptionChange("showTotals",e)},n)),s.appendChild(I(r("pivot.showGrandTotal","Show Grand Total"),o.showGrandTotal??!0,e=>{i.onOptionChange("showGrandTotal",e)},n)),s}(o,s))),a.appendChild(P(n("pivot.rowGroups","Row Groups"),()=>N("rowGroups",s))),a.appendChild(P(n("pivot.columnGroups","Column Groups"),()=>N("columnGroups",s))),a.appendChild(P(n("pivot.values","Values"),()=>function(e){const{config:t,callbacks:o,signal:i}=e,n=document.createElement("div");n.className="tbw-pivot-drop-zone tbw-pivot-values-zone",n.setAttribute("data-zone","values");const r=t.valueFields??[];if(0===r.length){const t=document.createElement("div");t.className="tbw-pivot-placeholder",t.textContent=e.t("pivot.dropNumericFields","Drag numeric fields here"),n.appendChild(t)}else for(const s of r)n.appendChild($(s,e));return n.addEventListener("dragover",e=>{e.preventDefault(),n.classList.add("drag-over")},{signal:i}),n.addEventListener("dragleave",()=>{n.classList.remove("drag-over")},{signal:i}),n.addEventListener("drop",e=>{e.preventDefault(),n.classList.remove("drag-over");const t=e.dataTransfer?.getData("text/plain");t&&o.onAddValueField(t,"sum")},{signal:i}),n}(s))),a.appendChild(P(n("pivot.availableFields","Available Fields"),()=>function(e){const{config:t,callbacks:o,signal:i}=e,n=document.createElement("div");n.className="tbw-pivot-available-fields";const r=o.getAvailableFields(),s=/* @__PURE__ */new Set([...t.rowGroupFields??[],...t.columnGroupFields??[],...t.valueFields?.map(e=>e.field)??[]]),a=r.filter(e=>!s.has(e.field));if(0===a.length){const t=document.createElement("div");t.className="tbw-pivot-placeholder",t.textContent=e.t("pivot.allFieldsUsed","All fields are in use"),n.appendChild(t)}else{const t=document.createElement("div");if(t.className="tbw-pivot-fields-list",a.length>=6){const o=document.createElement("input");o.type="text",o.placeholder=e.t("pivot.filterFields","Filter fields…"),o.className="tbw-pivot-field-search",o.addEventListener("input",()=>{const e=o.value.toLowerCase();for(const o of t.querySelectorAll(".tbw-pivot-field-chip")){const t=o;t.style.display=t.textContent?.toLowerCase().includes(e)?"":"none"}},{signal:i}),n.appendChild(o)}for(const o of a){const n=document.createElement("div");n.className="tbw-pivot-field-chip available",n.textContent=o.header,n.draggable=!0,n.title=e.t("pivot.availableChipHint","Drag into a zone, or click to choose one"),k(n,o.header,e.t),n.addEventListener("dragstart",e=>{e.dataTransfer?.setData("text/plain",o.field),n.classList.add(A)},{signal:i}),n.addEventListener("dragend",()=>{n.classList.remove(A)},{signal:i}),n.addEventListener("click",()=>R(n,o.header,L(o.field,e)),{signal:i}),t.appendChild(n)}n.appendChild(t)}return n}(s))),e.appendChild(a),()=>{r.abort(),E?.dispose(),E=null,a.remove()}}function R(e,t,o){E??=T("tbw-pivot-chip-menu","tbw-pivot-chip-menu"),E.open(e,t,o)}function k(e,t,o){e.setAttribute("role","button"),e.tabIndex=-1,e.setAttribute("aria-label",`${t} — ${o("pivot.chipHint","drag, or activate for move options")}`)}function L(e,t){const{callbacks:o,t:i}=t;return[{label:i("pivot.addToRowGroups","Add to Row Groups"),run:()=>o.onAddFieldToZone(e,"rowGroups")},{label:i("pivot.addToColumnGroups","Add to Column Groups"),run:()=>o.onAddFieldToZone(e,"columnGroups")},{label:i("pivot.addToValues","Add to Values"),run:()=>o.onAddValueField(e,"sum")}]}function P(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 n=document.createElement("div");return n.className="tbw-pivot-section-content",n.appendChild(t()),o.appendChild(i),o.appendChild(n),o}function N(e,t){const{config:o,callbacks:i,signal:n}=t,r=document.createElement("div");r.className="tbw-pivot-drop-zone",r.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=t.t("pivot.dropFields","Drag fields here"),r.appendChild(e)}else for(const a of s)r.appendChild(M(a,e,t));return r.addEventListener("dragover",e=>{e.preventDefault(),r.classList.add("drag-over")},{signal:n}),r.addEventListener("dragleave",()=>{r.classList.remove("drag-over")},{signal:n}),r.addEventListener("drop",t=>{t.preventDefault(),r.classList.remove("drag-over");const o=t.dataTransfer?.getData("text/plain"),n=t.dataTransfer?.getData("source-zone");if(!o)return;const s=r.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}}!n||n===e||"rowGroups"!==n&&"columnGroups"!==n?n===e?i.onReorderFieldInZone(o,e,a):i.onAddFieldToZone(o,e):i.onMoveFieldBetweenZones(o,n,e)},{signal:n}),r}function M(e,t,o){const{callbacks:i,signal:n}=o,r=document.createElement("div");r.className="tbw-pivot-field-chip",r.draggable=!0;const s=i.getAvailableFields().find(t=>t.field===e)?.header??e,a=document.createElement("span");a.className="tbw-pivot-chip-label",a.textContent=s,k(a,s,o.t);const l=document.createElement("button");return l.type="button",l.className="tbw-pivot-chip-remove",l.innerHTML="×",l.title=o.t("pivot.removeField","Remove field"),l.addEventListener("click",o=>{o.stopPropagation(),i.onRemoveFieldFromZone(e,t)},{signal:n}),r.appendChild(a),r.appendChild(l),r.addEventListener("dragstart",o=>{o.dataTransfer?.setData("text/plain",e),o.dataTransfer?.setData("source-zone",t),r.classList.add(A)},{signal:n}),r.addEventListener("dragend",()=>{r.classList.remove(A)},{signal:n}),r.addEventListener("click",()=>R(r,s,function(e,t,o){const{config:i,callbacks:n,t:r}=o,s="rowGroups"===t?i.rowGroupFields??[]:i.columnGroupFields??[],a=s.indexOf(e),l="rowGroups"===t?"columnGroups":"rowGroups";return[{label:r("pivot.moveUp","Move up"),disabled:a<=0,run:()=>n.onReorderFieldInZone(e,t,a-1)},{label:r("pivot.moveDown","Move down"),disabled:a<0||a>=s.length-1,run:()=>n.onReorderFieldInZone(e,t,a+2)},{label:"columnGroups"===l?r("pivot.moveToColumnGroups","Move to Column Groups"):r("pivot.moveToRowGroups","Move to Row Groups"),run:()=>n.onMoveFieldBetweenZones(e,t,l)},{label:r("pivot.moveToValues","Move to Values"),run:()=>n.onAddValueField(e,"sum")},{label:r("pivot.removeField","Remove field"),run:()=>n.onRemoveFieldFromZone(e,t)}]}(e,t,o)),{signal:n}),r}function $(e,t){const{callbacks:o,signal:i}=t,n=document.createElement("div");n.className="tbw-pivot-field-chip tbw-pivot-value-chip";const r=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=r?.header??e.field;const l="function"==typeof e.aggFunc,d=document.createElement("select");if(d.className="tbw-pivot-agg-select",d.title=t.t("pivot.aggFunction","Aggregation function"),l){const e=document.createElement("option");e.value="__custom__",e.textContent=t.t("pivot.customAgg","CUSTOM"),e.selected=!0,d.appendChild(e),d.disabled=!0}for(const u of G){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.type="button",c.className="tbw-pivot-chip-remove",c.innerHTML="×",c.title=t.t("pivot.removeValueField","Remove value field"),c.addEventListener("click",t=>{t.stopPropagation(),o.onRemoveValueField(e.field)},{signal:i}),s.appendChild(a),s.appendChild(d),n.appendChild(s),n.appendChild(c),n}function I(e,t,o,i){const n=document.createElement("label");n.className="tbw-pivot-checkbox";const r=document.createElement("input");r.type="checkbox",r.checked=t,r.addEventListener("change",()=>o(r.checked),{signal:i});const s=document.createElement("span");return s.textContent=e,n.appendChild(r),n.appendChild(s),n}function q(e,t,o,i=(e,t)=>t){return t.className="data-grid-row pivot-grand-total-row",t.innerHTML="",o.forEach((o,n)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(n)),0===n){const e=document.createElement("span");e.className="pivot-label",e.textContent=i("pivot.grandTotal","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}var z=class e extends p{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:"shell",required:!1,severity:"warn",when:e=>!0===e.showToolPanel,reason:"PivotPlugin renders its tool panel in a shell host when showToolPanel is enabled"}];name="pivot";styles='@layer tbw-plugins{.pivot-group-row{grid-template-columns:var(--tbw-column-template);background:var(--tbw-pivot-group-bg,var(--tbw-color-row-alt));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider);font-weight:600;display:grid}@media (hover:hover){.pivot-group-row:hover{background:var(--tbw-pivot-group-hover,var(--tbw-color-row-hover))}}.pivot-leaf-row{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);display:grid}.pivot-grand-total-row{grid-template-columns:var(--tbw-column-template);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);font-weight:700;display:grid}.pivot-grand-total-row>.cell{padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);align-items:center;min-width:0;display:flex;overflow:hidden}.pivot-grand-total-row>.cell:last-child{border-right:0}.pivot-grand-total-footer{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;position:sticky;bottom:0}.pivot-group-row>.cell,.pivot-leaf-row>.cell{padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);align-items:center;min-width:0;display:flex;overflow:hidden}.pivot-group-row>.cell:last-child,.pivot-leaf-row>.cell:last-child{border-right:0}.pivot-toggle{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);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);background:0 0;border:none;justify-content:center;align-items:center;display:inline-flex}.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{position:relative}.pivot-toggle:after{content:"";inline-size:var(--tbw-touch-target-min,24px);block-size:var(--tbw-touch-target-min,24px);position:absolute;inset-block-start:50%;inset-inline-start:50%;translate:-50% -50%}@media (pointer:coarse){.pivot-toggle{min-width:var(--tbw-touch-target-min,24px);min-height:var(--tbw-touch-target-min,24px)}}.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{border-top:2px solid var(--tbw-pivot-border,var(--tbw-color-border-strong));font-weight:700}[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{gap:var(--tbw-panel-padding,var(--tbw-spacing-lg,.75rem));padding:var(--tbw-panel-padding,var(--tbw-spacing-lg,.75rem));height:100%;font-size:var(--tbw-font-size-sm,.8125rem);flex-direction:column;display:flex;overflow-y:auto}.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));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;font-weight:600}.tbw-pivot-section-content{padding:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem))}.tbw-pivot-toggle-wrapper{align-items:center;display:flex}.tbw-pivot-toggle-label{align-items:center;gap:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));cursor:pointer;display:flex}.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));gap:var(--tbw-spacing-sm,.375rem);flex-wrap:wrap;align-content:flex-start;transition:all .15s;display:flex}.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);padding:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));text-align:center;width:100%;font-style:italic}.tbw-pivot-field-chip{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;display:inline-flex}.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;text-overflow:ellipsis;max-width:120px;overflow:hidden}.tbw-pivot-chip-remove{width:var(--tbw-icon-size,1rem);height:var(--tbw-icon-size,1rem);color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-sm,.875rem);cursor:pointer;background:0 0;border:none;border-radius:50%;justify-content:center;align-items:center;padding:0;font-weight:700;transition:all .15s;display:flex}.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-chip-menu{min-width:12rem;padding:var(--tbw-spacing-xs,.25rem);background:var(--tbw-color-panel-bg,light-dark(#fff,#1f1f1f));color:var(--tbw-color-fg,light-dark(#1a1a1a,#f0f0f0));border:1px solid var(--tbw-color-border,light-dark(#d0d0d0,#3a3a3a));border-radius:var(--tbw-border-radius,.25rem);box-shadow:var(--tbw-shadow-md,0 4px 12px #00000040);font:inherit;z-index:10001;flex-direction:column;margin:0;display:flex;position:fixed}.tbw-pivot-chip-menu[hidden]{display:none}.tbw-pivot-chip-menu-item{min-height:var(--tbw-touch-target-min,24px);padding:var(--tbw-spacing-xs,.25rem) var(--tbw-spacing-sm,.5rem);text-align:start;border-radius:min(var(--tbw-border-radius,.25rem), 6px);color:inherit;font:inherit;cursor:pointer;background:0 0;border:none}.tbw-pivot-chip-menu-item:hover:not(:disabled){background:var(--tbw-color-row-hover,light-dark(#f0f0f0,#2a2a2a))}.tbw-pivot-chip-menu-item:disabled{opacity:.5;cursor:default}.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{align-items:center;gap:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));flex:1;min-width:0;display:flex}.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{gap:var(--tbw-spacing-sm,.375rem);flex-direction:column;min-height:40px;display:flex}.tbw-pivot-field-search{border:1px solid var(--tbw-color-border,#d0d5dd);border-radius:var(--tbw-radius-sm,.25rem);width:100%;font-size:var(--tbw-font-size-sm,.875rem);background:var(--tbw-color-bg,#fff);color:var(--tbw-color-fg,#1a1a2e);outline:none;padding:.25rem .5rem}.tbw-pivot-field-search:focus{border-color:var(--tbw-color-primary,#3b82f6)}.tbw-pivot-fields-list{gap:var(--tbw-spacing-sm,.375rem);flex-wrap:wrap;display:flex}.tbw-pivot-options{gap:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));flex-direction:column;display:flex}.tbw-pivot-checkbox{align-items:center;gap:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));cursor:pointer;display:flex}.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:e.PANEL_ID,title:this.t("pivot.panelTitle","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=h(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={},n=t.flatMap(e=>g([e],o));return function e(t){for(const o of t)if(o.isGroup&&o.children?.length)o.children&&e(o.children);else for(const e of n)i[e]=(i[e]??0)+(o.values[e]??0)}(e),i}(this.pivotResult.rows,this.pivotResult.columnKeys,this.config.valueFields??[]));const i=this.config.indentWidth??20,n=!0===this.defaultExpanded||void 0===this.defaultExpanded,r=function(e,t,o=!0){const i=[];function n(e){i.push(e);const r=t?t.has(e.rowKey):o;if(e.children&&r)for(const t of e.children)n(t)}for(const r of e)n(r);return i}(this.pivotResult.rows,this.expandedKeys,n).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 r){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&&r.push({__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotDepth:0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals}),r}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});const i=this.config.valueFields??[];for(const n of this.pivotResult.columnKeys){const e=g([n],i);for(let o=0;o<i.length;o++){const r=i[o],s=e[o],a=r.header||this.fieldHeaderMap.get(r.field)||r.field,l="function"==typeof r.aggFunc?"custom":r.aggFunc,d=this.valueFormatters.get(o);t.push({field:s,header:`${n} - ${a} (${l})`,width:120,type:"number",sortable:!0,...d?{format:e=>null!=e?d(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?q(i,t,this.gridColumns,this.translate):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,n)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(n)),r.setAttribute("data-row",String(o.rowIndex)),r.setAttribute("role","gridcell"),0===n){const t=Number(e.__pivotIndent)||0;r.style.paddingLeft=`${t}px`;const i=String(e.__pivotRowKey),n=document.createElement("button");n.type="button",n.className="pivot-toggle",n.setAttribute("aria-label",e.__pivotExpanded?"Collapse group":"Expand group"),o.setIcon(n,e.__pivotExpanded?"collapse":"expand"),n.addEventListener("click",e=>{e.stopPropagation(),o.onToggle(i)}),r.appendChild(n);const s=document.createElement("span");s.className="pivot-label",s.textContent=String(e.__pivotLabel??""),r.appendChild(s);const a=document.createElement("span");a.className="pivot-count",a.textContent=` (${Number(e.__pivotRowCount)||0})`,r.appendChild(a)}else{const t=e[i.field];r.textContent=null!=t?i.format?i.format(t,e):String(t):""}t.appendChild(r)}),!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,n)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(n)),r.setAttribute("data-row",String(i)),r.setAttribute("role","gridcell"),0===n){const t=Number(e.__pivotIndent)||0;r.style.paddingLeft=`${t+20}px`;const o=document.createElement("span");o.className="pivot-label",o.textContent=String(e.__pivotLabel??""),r.appendChild(o)}else{const t=e[o.field];r.textContent=null!=t?o.format?o.format(t,e):String(t):""}t.appendChild(r)}),!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 n=this.mapFieldToSortConfig(t);if(!n)return!1;const r=this.activeSortDir;let s;s=this.activeSortField!==t?"asc":"asc"===r?"desc":null,this.activeSortField=s?t:null,this.activeSortDir=s,this.config.sortRows=s?{...n,direction:s}:void 0,this.emit("pivot-config-change",{property:"sortRows"}),this.refresh();const a=this.gridElement;if(a){const n=e.column.header??t;o(a,s?i(a,"sortApplied",n,"asc"===s?"ascending":"descending"):i(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,n=e.querySelectorAll(".header-row .cell[data-field]");for(const r of n){const e=r.getAttribute("data-field");if(!e||!this.isPivotField(e))continue;let n=null;t===e?n=o:i&&("label"===i.by&&"__pivotLabel"===e?n=i.direction??"asc":"value"!==i.by||"__pivotTotal"!==e||i.valueField?"value"===i.by&&i.valueField&&e===i.valueField&&(n=i.direction??"asc"):n=i.direction??"asc"),this.updateSortIndicator(r,n)}}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));q({__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals},this.grandTotalFooter,this.gridColumns,this.translate),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()}#o(){return this.grid.getPluginByName("shell")}showPanel(){const t=this.#o();t?.openToolPanel(),t?.expandedToolPanelSections.includes(e.PANEL_ID)||t?.toggleToolPanelSection(e.PANEL_ID)}hidePanel(){this.#o()?.closeToolPanel()}togglePanel(){const t=this.#o();t?.isToolPanelOpen||t?.openToolPanel(),t?.toggleToolPanelSection(e.PANEL_ID)}isPanelVisible(){const t=this.#o();return!!t?.isToolPanelOpen&&t.expandedToolPanelSections.includes(e.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){return this.panelContainer=e,0===this.originalColumns.length&&this.captureOriginalColumns(),S(e,this.config,this.isActive,{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()},this.translate)}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??[]],n=i.indexOf(e);-1!==n&&n!==o&&(i.splice(n,1),i.splice(o>n?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(let t=0;t<e.length;t++){const o=e[t];if(o.format)this.valueFormatters.set(t,o.format);else if(this.originalColumns.find(e=>e.field===o.field)){const e=(this.grid.getAllColumns?.()??this.grid.columns??[]).find(e=>e.field===o.field);if(e?.format){const o=e.format;this.valueFormatters.set(t,e=>o(e,{}))}}}}};export{z as PivotPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|