@toolbox-web/grid 3.0.0 → 3.0.1
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.js +1 -1
- package/all.js.map +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/lib/features/registry.js +1 -1
- package/lib/plugins/clipboard/index.js +1 -1
- package/lib/plugins/column-virtualization/index.js +1 -1
- package/lib/plugins/context-menu/index.js +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/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-rows/index.js +1 -1
- package/lib/plugins/master-detail/index.js +1 -1
- package/lib/plugins/multi-sort/index.js +1 -1
- package/lib/plugins/pinned-columns/index.js +1 -1
- package/lib/plugins/pinned-rows/index.js +1 -1
- package/lib/plugins/pivot/index.js +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/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/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/shell/index.js +1 -1
- package/lib/plugins/sticky-rows/index.js +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/undo-redo/index.js +1 -1
- package/lib/plugins/visibility/index.js +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/editing.umd.js +1 -1
- package/umd/plugins/editing.umd.js.map +1 -1
- package/umd/plugins/filtering.umd.js +1 -1
- package/umd/plugins/filtering.umd.js.map +1 -1
- package/umd/plugins/print.umd.js +1 -1
- package/umd/plugins/print.umd.js.map +1 -1
- package/umd/plugins/responsive.umd.js +1 -1
- package/umd/plugins/responsive.umd.js.map +1 -1
- package/umd/plugins/selection.umd.js +1 -1
- package/umd/plugins/selection.umd.js.map +1 -1
- package/umd/plugins/tooltip.umd.js +1 -1
- package/umd/plugins/tooltip.umd.js.map +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=/* @__PURE__ */new WeakMap;function t(t,r,n){return n?.valueAccessor?function(t,r,n=-1){if(!r.valueAccessor)return t?.[r.field];if("object"!=typeof t||null===t)return r.valueAccessor({row:t,column:r,rowIndex:n});const o=t,i=r.field;let s=e.get(o);if(s){const e=s.get(i);if(void 0!==e)return e.v}else s=/* @__PURE__ */new Map,e.set(o,s);const a=r.valueAccessor({row:t,column:r,rowIndex:n});return s.set(i,{v:a}),a}(t,n):t?.[r]}function r(e){return null==e||""===e||"number"==typeof e&&isNaN(e)}var n={sum:(e,n,o)=>{let i=0;for(let s=0;s<e.length;s++){const a=t(e[s],n,o);if(r(a))continue;const l=Number(a);isNaN(l)||(i+=l)}return i},avg:(e,n,o)=>{if(!e.length)return 0;let i=0,s=0;for(let a=0;a<e.length;a++){const l=t(e[a],n,o);if(r(l))continue;const c=Number(l);isNaN(c)||(i+=c,s++)}return s>0?i/s:0},count:e=>e.length,min:(e,n,o)=>{if(!e.length)return 0;let i=1/0;for(let s=0;s<e.length;s++){const a=t(e[s],n,o);if(r(a))continue;const l=Number(a);isNaN(l)||l<i&&(i=l)}return i===1/0?0:i},max:(e,n,o)=>{if(!e.length)return 0;let i=-1/0;for(let s=0;s<e.length;s++){const a=t(e[s],n,o);if(r(a))continue;const l=Number(a);isNaN(l)||l>i&&(i=l)}return i===-1/0?0:i},first:(e,r,n)=>e[0]?t(e[0],r,n):void 0,last:(e,r,n)=>e.length?t(e[e.length-1],r,n):void 0},o=/* @__PURE__ */new Map,i={register(e,t){o.set(e,t)},unregister(e){o.delete(e)},get(e){if(void 0!==e)return"function"==typeof e?e:o.get(e)??n[e]},run(e,t,r,n){const o=this.get(e);return o?o(t,r,n):void 0},has:e=>o.has(e)||e in n,list:()=>[...Object.keys(n),...o.keys()]};function s(e,t,r,n){const o=document.createElement("div");o.className="tbw-aggregation-cell tbw-aggregation-cell-full",o.style.gridColumn="1 / -1";const i="function"==typeof t.label?t.label(n,r):t.label;if(i){const e=document.createElement("span");e.className="tbw-aggregation-label",e.textContent=i,o.appendChild(e)}const s=function(e,t,r){const n=e.aggregators&&Object.keys(e.aggregators).length>0,o=e.cells&&Object.keys(e.cells).length>0;if(!n&&!o)return null;const i=document.createElement("span");i.className="tbw-aggregation-aggregates";for(const s of t){const{value:t,formatter:n}=l(e,s,r);if(null!=t){const e=document.createElement("span");e.className="tbw-aggregation-aggregate",e.setAttribute("data-field",s.field),e.textContent=`${s.header??s.field}: ${n?n(t,s.field,s):String(t)}`,i.appendChild(e)}}return i.children.length>0?i:null}(t,r,n);s&&o.appendChild(s),e.appendChild(o)}function a(e,t,r,n){for(const i of r){const r=document.createElement("div");r.className="tbw-aggregation-cell",r.setAttribute("data-field",i.field);const{value:o,formatter:s}=l(t,i,n);r.textContent=null!=o?s?s(o,i.field,i):String(o):"",e.appendChild(r)}const o="function"==typeof t.label?t.label(n,r):t.label;if(o){const t=document.createElement("span");t.className="tbw-aggregation-label",t.textContent=o,e.appendChild(t)}}function l(e,t,r){let n,o;const s=e.aggregators?.[t.field];if(s)if("object"==typeof(a=s)&&null!==a&&"aggFunc"in a){const e=i.get(s.aggFunc);e&&(n=e(r,t.field,t)),o=s.formatter}else{const e=i.get(s);e&&(n=e(r,t.field,t))}else if(e.cells&&Object.prototype.hasOwnProperty.call(e.cells,t.field)){const o=e.cells[t.field];n="function"==typeof o?o(r,t.field,t):o}var a;return{value:n,formatter:o}}function c(e,t,r,n,o){const i=r?.sourceRows,s=r?.rows,a=Array.isArray(i)?i.length:e.length,l=Array.isArray(s)?s.length:e.length,c=a>0?a:l;return{totalRows:c,filteredRows:o?.cachedResult?.length??(l<a?l:c),selectedRows:n?.selected?.size??0,columns:t,rows:e,grid:r}}function d(){return e=>{const t=document.createElement("span");return t.className="tbw-status-panel tbw-status-panel-row-count",t.textContent=`Total: ${e.totalRows} rows`,t}}function g(){return e=>{if(e.selectedRows<=0)return null;const t=document.createElement("span");return t.className="tbw-status-panel tbw-status-panel-selected-count",t.textContent=`Selected: ${e.selectedRows}`,t}}function u(){return e=>{if(e.filteredRows===e.totalRows)return null;const t=document.createElement("span");return t.className="tbw-status-panel tbw-status-panel-filtered-count",t.textContent=`Filtered: ${e.filteredRows}`,t}}function p(e){const t=document.createElement("div");return t.className="tbw-status-panel tbw-status-panel-custom",t.appendChild(e),t}var f=/* @__PURE__ */new WeakMap;function h(e,t,r){const n=Array.isArray(e.render)?e.render:[{zone:"left",render:e.render}],o=n.map(e=>e.render(t)??null);if(r){const e=f.get(r);if(e&&e.length===o.length&&e.every((e,t)=>e===o[t]))return r}const i=document.createElement("div");i.className="tbw-pinned-rows",i.setAttribute("role","presentation"),i.setAttribute("aria-live","polite"),e.id&&i.setAttribute("data-pinned-row-id",e.id);const s=document.createElement("div");s.className="tbw-pinned-rows-left";const a=document.createElement("div");a.className="tbw-pinned-rows-center";const l=document.createElement("div");l.className="tbw-pinned-rows-right";const c={left:s,center:a,right:l};for(let d=0;d<n.length;d++){const e=n[d],t=o[d];if(null==t)continue;const r=e.zone??"left",i=t.classList?.contains("tbw-status-panel");c[r].appendChild(i?t:p(t))}return 0===s.children.length&&0===a.children.length&&0===l.children.length?null:(i.appendChild(s),i.appendChild(a),i.appendChild(l),f.set(i,o),i)}function b(e,t,r,n,o=!1){const i=function(e){const t=document.createElement("div");return t.className=`tbw-aggregation-rows tbw-aggregation-rows-${e}`,t.setAttribute("role","presentation"),t}(t);return function(e,t,r,n,o=!1){e.innerHTML="";for(const i of t){const t=document.createElement("div");t.className="tbw-aggregation-row",t.setAttribute("role","presentation"),i.id&&t.setAttribute("data-aggregation-id",i.id),i.fullWidth??o?s(t,i,r,n):a(t,i,r,n),e.appendChild(t)}}(i,[e],r,n,o),i}function m(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function w(e,t,r,n){return`${m(r,n)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var v="__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("")),C=(new RegExp(`__(proto|defineGetter|defineSetter)|${v.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".split("|"))),y=/^on\w+$/i,x=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),E=/^\s*(javascript|vbscript|data|blob):/i;function W(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const n of r){const e=n.tagName.toLowerCase();if(C.has(e)){t.push(n);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===n.namespaceURI)&&Array.from(n.attributes).some(e=>y.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(n);continue}const r=[];for(const t of n.attributes){const e=t.name.toLowerCase();y.test(e)?r.push(t.name):(x.has(e)&&E.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name)}r.forEach(e=>n.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}var S={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var N=class{static dependencies;static manifest;aliases;version="3.0.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},r={};for(const n of Object.keys(t))r[n]=this;for(const n of e){const e=n.userConfig;for(const[o,i]of Object.entries(e)){if(void 0===i)continue;if(!(o in t)){t[o]=i,r[o]=n;continue}if(t[o]===i)continue;const e=r[o]?.constructor.name??this.constructor.name,s=n.constructor.name,a=w("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${e} and ${s}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const n of Object.keys(t))delete t[n];Object.assign(t,r)}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 r=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(r),r.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...S,...e}}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;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(),r=parseInt(t,10);if(!isNaN(r))return r}return 200}setIcon(e,t,r){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const n=this.#t(t,r);void 0!==n?"string"==typeof n?e.innerHTML=W(n):n instanceof HTMLElement&&(e.innerHTML="",e.appendChild(n.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 r=document.createElement("span");r.setAttribute("part","sort-indicator"),r.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(r,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(r,"sortNone"));const n=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return n?e.insertBefore(r,n):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(w(e,t,this.gridElement.id,this.name)):console.warn(`${m(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(w(e,t,this.gridElement.id,this.name))}},A=class extends N{name="pinnedRows";styles="@layer tbw-plugins{.tbw-scroll-area{container-type:inline-size}.tbw-footer,.tbw-header-pinned{z-index:var(--tbw-z-layer-pinned-rows,20);background:var(--tbw-color-panel-bg);flex-shrink:0;min-width:fit-content}.tbw-pinned-rows{padding:var(--tbw-button-padding,var(--tbw-spacing-md,.5rem) var(--tbw-spacing-lg,.75rem));background:var(--tbw-pinned-rows-bg,var(--tbw-color-panel-bg));border-top:1px solid var(--tbw-pinned-rows-border,var(--tbw-color-border));font-size:var(--tbw-font-size-xs,.75rem);color:var(--tbw-pinned-rows-color,var(--tbw-color-fg-muted));box-sizing:border-box;justify-content:space-between;align-items:center;width:100cqi;min-width:0;min-height:32px;display:flex;position:sticky;left:0}.tbw-pinned-rows+.tbw-pinned-rows{border-top:0}.tbw-pinned-rows-left,.tbw-pinned-rows-center,.tbw-pinned-rows-right{align-items:center;gap:var(--tbw-spacing-xl,1rem);display:flex}.tbw-pinned-rows-left{justify-content:flex-start}.tbw-pinned-rows-center{flex:1;justify-content:center}.tbw-pinned-rows-right{justify-content:flex-end}.tbw-status-panel{white-space:nowrap}.tbw-aggregation-rows{background:var(--tbw-aggregation-bg,var(--tbw-color-header-bg));min-width:fit-content}.tbw-aggregation-rows-top{border-bottom:1px solid var(--tbw-aggregation-border,var(--tbw-color-border))}.tbw-aggregation-rows-bottom{border-top:1px solid var(--tbw-aggregation-border,var(--tbw-color-border))}.tbw-aggregation-row{grid-template-columns:var(--tbw-column-template);font-size:var(--tbw-aggregation-font-size,.8em);font-weight:var(--tbw-aggregation-font-weight,600);background:inherit;display:grid;position:relative}.tbw-aggregation-row>.tbw-aggregation-label{padding:var(--tbw-cell-padding,.125rem .5rem);background:inherit;z-index:1;pointer-events:none;grid-area:1/1;align-items:center;display:flex;position:sticky;left:0}.tbw-aggregation-row>.tbw-aggregation-cell:first-child{grid-area:1/1}.tbw-aggregation-cell:not(:empty){z-index:2;background:inherit;position:relative}.tbw-aggregation-cell{padding:var(--tbw-cell-padding,.125rem .5rem);min-height:var(--tbw-row-height,1.75rem);border-right:1px solid var(--tbw-color-border-cell);text-overflow:ellipsis;white-space:var(--tbw-cell-white-space,nowrap);align-content:center;align-items:center;display:block;overflow:hidden}.tbw-aggregation-cell:last-child{border-right:0}.tbw-aggregation-cell-full{align-items:center;gap:var(--tbw-spacing-lg,.75rem);border-right:0;grid-column:1/-1;display:flex}.tbw-aggregation-label{white-space:nowrap}.tbw-aggregation-aggregates{align-items:center;gap:var(--tbw-spacing-lg,.75rem);opacity:.85;font-weight:400;display:flex}.tbw-aggregation-aggregate{white-space:nowrap}}";get defaultConfig(){return{slots:[{position:"bottom",render:[{zone:"left",render:d()},{zone:"left",render:u()},{zone:"right",render:g()}]}]}}footerWrapper=null;headerWrapper=null;detach(){this.cleanup()}afterRender(){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.footerWrapper&&!t.contains(this.footerWrapper)&&(this.footerWrapper=null),this.headerWrapper&&!t.contains(this.headerWrapper)&&(this.headerWrapper=null);const r=this.getSelectionState(),n=this.getFilterState(),o=c(this.sourceRows,this.columns,this.gridElement,r,n);this.renderSlotMode(t,e,o)}renderSlotMode(e,t,r){const n=this.config.slots??[],o=n.filter(e=>"top"===e.position),i=n.filter(e=>"top"!==e.position);o.length>0?(this.headerWrapper||(this.headerWrapper=document.createElement("div"),this.headerWrapper.className="tbw-header-pinned",e.insertBefore(this.headerWrapper,e.firstChild)),this.populateSlotWrapper(this.headerWrapper,o,"top",r)):this.headerWrapper&&(this.headerWrapper.remove(),this.headerWrapper=null),i.length>0?(this.footerWrapper||(this.footerWrapper=document.createElement("div"),this.footerWrapper.className="tbw-footer",e.appendChild(this.footerWrapper)),this.populateSlotWrapper(this.footerWrapper,i,"bottom",r)):this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null)}populateSlotWrapper(e,t,r,n){const o=/* @__PURE__ */new Map;for(let a=0;a<e.children.length;a++){const t=e.children[a],r=t.getAttribute("data-pinned-row-id");r&&o.set(r,t)}const i=[];for(const a of t){const e="render"in a&&null!=a.render?h(a,n,a.id?o.get(a.id)??null:null):b(a,r,this.visibleColumns,this.sourceRows,this.config.fullWidth);e&&i.push(e)}const s=e.children;if(s.length===i.length){let e=!0;for(let t=0;t<i.length;t++)if(s[t]!==i[t]){e=!1;break}if(e)return}e.replaceChildren(...i)}cleanup(){this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null),this.headerWrapper&&(this.headerWrapper.remove(),this.headerWrapper=null)}getSelectionState(){try{return this.grid?.getPluginState?.("selection")??null}catch{return null}}getFilterState(){try{return this.grid?.getPluginState?.("filtering")??null}catch{return null}}refresh(){this.requestRender()}getContext(){const e=this.getSelectionState(),t=this.getFilterState();return c(this.rows,this.columns,this.gridElement,e,t)}};export{A as PinnedRowsPlugin,u as filteredCountPanel,d as rowCountPanel,g as selectedCountPanel};
|
|
1
|
+
var e=/* @__PURE__ */new WeakMap;function t(t,r,n){return n?.valueAccessor?function(t,r,n=-1){if(!r.valueAccessor)return t?.[r.field];if("object"!=typeof t||null===t)return r.valueAccessor({row:t,column:r,rowIndex:n});const o=t,i=r.field;let s=e.get(o);if(s){const e=s.get(i);if(void 0!==e)return e.v}else s=/* @__PURE__ */new Map,e.set(o,s);const a=r.valueAccessor({row:t,column:r,rowIndex:n});return s.set(i,{v:a}),a}(t,n):t?.[r]}function r(e){return null==e||""===e||"number"==typeof e&&isNaN(e)}var n={sum:(e,n,o)=>{let i=0;for(let s=0;s<e.length;s++){const a=t(e[s],n,o);if(r(a))continue;const l=Number(a);isNaN(l)||(i+=l)}return i},avg:(e,n,o)=>{if(!e.length)return 0;let i=0,s=0;for(let a=0;a<e.length;a++){const l=t(e[a],n,o);if(r(l))continue;const c=Number(l);isNaN(c)||(i+=c,s++)}return s>0?i/s:0},count:e=>e.length,min:(e,n,o)=>{if(!e.length)return 0;let i=1/0;for(let s=0;s<e.length;s++){const a=t(e[s],n,o);if(r(a))continue;const l=Number(a);isNaN(l)||l<i&&(i=l)}return i===1/0?0:i},max:(e,n,o)=>{if(!e.length)return 0;let i=-1/0;for(let s=0;s<e.length;s++){const a=t(e[s],n,o);if(r(a))continue;const l=Number(a);isNaN(l)||l>i&&(i=l)}return i===-1/0?0:i},first:(e,r,n)=>e[0]?t(e[0],r,n):void 0,last:(e,r,n)=>e.length?t(e[e.length-1],r,n):void 0},o=/* @__PURE__ */new Map,i={register(e,t){o.set(e,t)},unregister(e){o.delete(e)},get(e){if(void 0!==e)return"function"==typeof e?e:o.get(e)??n[e]},run(e,t,r,n){const o=this.get(e);return o?o(t,r,n):void 0},has:e=>o.has(e)||e in n,list:()=>[...Object.keys(n),...o.keys()]};function s(e,t,r,n){const o=document.createElement("div");o.className="tbw-aggregation-cell tbw-aggregation-cell-full",o.style.gridColumn="1 / -1";const i="function"==typeof t.label?t.label(n,r):t.label;if(i){const e=document.createElement("span");e.className="tbw-aggregation-label",e.textContent=i,o.appendChild(e)}const s=function(e,t,r){const n=e.aggregators&&Object.keys(e.aggregators).length>0,o=e.cells&&Object.keys(e.cells).length>0;if(!n&&!o)return null;const i=document.createElement("span");i.className="tbw-aggregation-aggregates";for(const s of t){const{value:t,formatter:n}=l(e,s,r);if(null!=t){const e=document.createElement("span");e.className="tbw-aggregation-aggregate",e.setAttribute("data-field",s.field),e.textContent=`${s.header??s.field}: ${n?n(t,s.field,s):String(t)}`,i.appendChild(e)}}return i.children.length>0?i:null}(t,r,n);s&&o.appendChild(s),e.appendChild(o)}function a(e,t,r,n){for(const i of r){const r=document.createElement("div");r.className="tbw-aggregation-cell",r.setAttribute("data-field",i.field);const{value:o,formatter:s}=l(t,i,n);r.textContent=null!=o?s?s(o,i.field,i):String(o):"",e.appendChild(r)}const o="function"==typeof t.label?t.label(n,r):t.label;if(o){const t=document.createElement("span");t.className="tbw-aggregation-label",t.textContent=o,e.appendChild(t)}}function l(e,t,r){let n,o;const s=e.aggregators?.[t.field];if(s)if("object"==typeof(a=s)&&null!==a&&"aggFunc"in a){const e=i.get(s.aggFunc);e&&(n=e(r,t.field,t)),o=s.formatter}else{const e=i.get(s);e&&(n=e(r,t.field,t))}else if(e.cells&&Object.prototype.hasOwnProperty.call(e.cells,t.field)){const o=e.cells[t.field];n="function"==typeof o?o(r,t.field,t):o}var a;return{value:n,formatter:o}}function c(e,t,r,n,o){const i=r?.sourceRows,s=r?.rows,a=Array.isArray(i)?i.length:e.length,l=Array.isArray(s)?s.length:e.length,c=a>0?a:l;return{totalRows:c,filteredRows:o?.cachedResult?.length??(l<a?l:c),selectedRows:n?.selected?.size??0,columns:t,rows:e,grid:r}}function d(){return e=>{const t=document.createElement("span");return t.className="tbw-status-panel tbw-status-panel-row-count",t.textContent=`Total: ${e.totalRows} rows`,t}}function g(){return e=>{if(e.selectedRows<=0)return null;const t=document.createElement("span");return t.className="tbw-status-panel tbw-status-panel-selected-count",t.textContent=`Selected: ${e.selectedRows}`,t}}function u(){return e=>{if(e.filteredRows===e.totalRows)return null;const t=document.createElement("span");return t.className="tbw-status-panel tbw-status-panel-filtered-count",t.textContent=`Filtered: ${e.filteredRows}`,t}}function p(e){const t=document.createElement("div");return t.className="tbw-status-panel tbw-status-panel-custom",t.appendChild(e),t}var f=/* @__PURE__ */new WeakMap;function h(e,t,r){const n=Array.isArray(e.render)?e.render:[{zone:"left",render:e.render}],o=n.map(e=>e.render(t)??null);if(r){const e=f.get(r);if(e&&e.length===o.length&&e.every((e,t)=>e===o[t]))return r}const i=document.createElement("div");i.className="tbw-pinned-rows",i.setAttribute("role","presentation"),i.setAttribute("aria-live","polite"),e.id&&i.setAttribute("data-pinned-row-id",e.id);const s=document.createElement("div");s.className="tbw-pinned-rows-left";const a=document.createElement("div");a.className="tbw-pinned-rows-center";const l=document.createElement("div");l.className="tbw-pinned-rows-right";const c={left:s,center:a,right:l};for(let d=0;d<n.length;d++){const e=n[d],t=o[d];if(null==t)continue;const r=e.zone??"left",i=t.classList?.contains("tbw-status-panel");c[r].appendChild(i?t:p(t))}return 0===s.children.length&&0===a.children.length&&0===l.children.length?null:(i.appendChild(s),i.appendChild(a),i.appendChild(l),f.set(i,o),i)}function b(e,t,r,n,o=!1){const i=function(e){const t=document.createElement("div");return t.className=`tbw-aggregation-rows tbw-aggregation-rows-${e}`,t.setAttribute("role","presentation"),t}(t);return function(e,t,r,n,o=!1){e.innerHTML="";for(const i of t){const t=document.createElement("div");t.className="tbw-aggregation-row",t.setAttribute("role","presentation"),i.id&&t.setAttribute("data-aggregation-id",i.id),i.fullWidth??o?s(t,i,r,n):a(t,i,r,n),e.appendChild(t)}}(i,[e],r,n,o),i}function m(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function w(e,t,r,n){return`${m(r,n)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var v="__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("")),C=(new RegExp(`__(proto|defineGetter|defineSetter)|${v.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".split("|"))),y=/^on\w+$/i,x=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),E=/^\s*(javascript|vbscript|data|blob):/i;function W(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const n of r){const e=n.tagName.toLowerCase();if(C.has(e)){t.push(n);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===n.namespaceURI)&&Array.from(n.attributes).some(e=>y.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(n);continue}const r=[];for(const t of n.attributes){const e=t.name.toLowerCase();y.test(e)?r.push(t.name):(x.has(e)&&E.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name)}r.forEach(e=>n.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}var S={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var N=class{static dependencies;static manifest;aliases;version="3.0.1";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},r={};for(const n of Object.keys(t))r[n]=this;for(const n of e){const e=n.userConfig;for(const[o,i]of Object.entries(e)){if(void 0===i)continue;if(!(o in t)){t[o]=i,r[o]=n;continue}if(t[o]===i)continue;const e=r[o]?.constructor.name??this.constructor.name,s=n.constructor.name,a=w("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${e} and ${s}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const n of Object.keys(t))delete t[n];Object.assign(t,r)}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 r=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(r),r.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...S,...e}}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;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(),r=parseInt(t,10);if(!isNaN(r))return r}return 200}setIcon(e,t,r){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const n=this.#t(t,r);void 0!==n?"string"==typeof n?e.innerHTML=W(n):n instanceof HTMLElement&&(e.innerHTML="",e.appendChild(n.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 r=document.createElement("span");r.setAttribute("part","sort-indicator"),r.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(r,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(r,"sortNone"));const n=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return n?e.insertBefore(r,n):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(w(e,t,this.gridElement.id,this.name)):console.warn(`${m(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(w(e,t,this.gridElement.id,this.name))}},A=class extends N{name="pinnedRows";styles="@layer tbw-plugins{.tbw-scroll-area{container-type:inline-size}.tbw-footer,.tbw-header-pinned{z-index:var(--tbw-z-layer-pinned-rows,20);background:var(--tbw-color-panel-bg);flex-shrink:0;min-width:fit-content}.tbw-pinned-rows{padding:var(--tbw-button-padding,var(--tbw-spacing-md,.5rem) var(--tbw-spacing-lg,.75rem));background:var(--tbw-pinned-rows-bg,var(--tbw-color-panel-bg));border-top:1px solid var(--tbw-pinned-rows-border,var(--tbw-color-border));font-size:var(--tbw-font-size-xs,.75rem);color:var(--tbw-pinned-rows-color,var(--tbw-color-fg-muted));box-sizing:border-box;justify-content:space-between;align-items:center;width:100cqi;min-width:0;min-height:32px;display:flex;position:sticky;left:0}.tbw-pinned-rows+.tbw-pinned-rows{border-top:0}.tbw-pinned-rows-left,.tbw-pinned-rows-center,.tbw-pinned-rows-right{align-items:center;gap:var(--tbw-spacing-xl,1rem);display:flex}.tbw-pinned-rows-left{justify-content:flex-start}.tbw-pinned-rows-center{flex:1;justify-content:center}.tbw-pinned-rows-right{justify-content:flex-end}.tbw-status-panel{white-space:nowrap}.tbw-aggregation-rows{background:var(--tbw-aggregation-bg,var(--tbw-color-header-bg));min-width:fit-content}.tbw-aggregation-rows-top{border-bottom:1px solid var(--tbw-aggregation-border,var(--tbw-color-border))}.tbw-aggregation-rows-bottom{border-top:1px solid var(--tbw-aggregation-border,var(--tbw-color-border))}.tbw-aggregation-row{grid-template-columns:var(--tbw-column-template);font-size:var(--tbw-aggregation-font-size,.8em);font-weight:var(--tbw-aggregation-font-weight,600);background:inherit;display:grid;position:relative}.tbw-aggregation-row>.tbw-aggregation-label{padding:var(--tbw-cell-padding,.125rem .5rem);background:inherit;z-index:1;pointer-events:none;grid-area:1/1;align-items:center;display:flex;position:sticky;left:0}.tbw-aggregation-row>.tbw-aggregation-cell:first-child{grid-area:1/1}.tbw-aggregation-cell:not(:empty){z-index:2;background:inherit;position:relative}.tbw-aggregation-cell{padding:var(--tbw-cell-padding,.125rem .5rem);min-height:var(--tbw-row-height,1.75rem);border-right:1px solid var(--tbw-color-border-cell);text-overflow:ellipsis;white-space:var(--tbw-cell-white-space,nowrap);align-content:center;align-items:center;display:block;overflow:hidden}.tbw-aggregation-cell:last-child{border-right:0}.tbw-aggregation-cell-full{align-items:center;gap:var(--tbw-spacing-lg,.75rem);border-right:0;grid-column:1/-1;display:flex}.tbw-aggregation-label{white-space:nowrap}.tbw-aggregation-aggregates{align-items:center;gap:var(--tbw-spacing-lg,.75rem);opacity:.85;font-weight:400;display:flex}.tbw-aggregation-aggregate{white-space:nowrap}}";get defaultConfig(){return{slots:[{position:"bottom",render:[{zone:"left",render:d()},{zone:"left",render:u()},{zone:"right",render:g()}]}]}}footerWrapper=null;headerWrapper=null;detach(){this.cleanup()}afterRender(){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.footerWrapper&&!t.contains(this.footerWrapper)&&(this.footerWrapper=null),this.headerWrapper&&!t.contains(this.headerWrapper)&&(this.headerWrapper=null);const r=this.getSelectionState(),n=this.getFilterState(),o=c(this.sourceRows,this.columns,this.gridElement,r,n);this.renderSlotMode(t,e,o)}renderSlotMode(e,t,r){const n=this.config.slots??[],o=n.filter(e=>"top"===e.position),i=n.filter(e=>"top"!==e.position);o.length>0?(this.headerWrapper||(this.headerWrapper=document.createElement("div"),this.headerWrapper.className="tbw-header-pinned",e.insertBefore(this.headerWrapper,e.firstChild)),this.populateSlotWrapper(this.headerWrapper,o,"top",r)):this.headerWrapper&&(this.headerWrapper.remove(),this.headerWrapper=null),i.length>0?(this.footerWrapper||(this.footerWrapper=document.createElement("div"),this.footerWrapper.className="tbw-footer",e.appendChild(this.footerWrapper)),this.populateSlotWrapper(this.footerWrapper,i,"bottom",r)):this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null)}populateSlotWrapper(e,t,r,n){const o=/* @__PURE__ */new Map;for(let a=0;a<e.children.length;a++){const t=e.children[a],r=t.getAttribute("data-pinned-row-id");r&&o.set(r,t)}const i=[];for(const a of t){const e="render"in a&&null!=a.render?h(a,n,a.id?o.get(a.id)??null:null):b(a,r,this.visibleColumns,this.sourceRows,this.config.fullWidth);e&&i.push(e)}const s=e.children;if(s.length===i.length){let e=!0;for(let t=0;t<i.length;t++)if(s[t]!==i[t]){e=!1;break}if(e)return}e.replaceChildren(...i)}cleanup(){this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null),this.headerWrapper&&(this.headerWrapper.remove(),this.headerWrapper=null)}getSelectionState(){try{return this.grid?.getPluginState?.("selection")??null}catch{return null}}getFilterState(){try{return this.grid?.getPluginState?.("filtering")??null}catch{return null}}refresh(){this.requestRender()}getContext(){const e=this.getSelectionState(),t=this.getFilterState();return c(this.rows,this.columns,this.gridElement,e,t)}};export{A as PinnedRowsPlugin,u as filteredCountPanel,d as rowCountPanel,g as selectedCountPanel};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -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`,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",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 r=(t&&"effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.messages?.[o];return r?r(...i):e[o](...i)}function r(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function n(e,t,o,i){return`${r(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".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){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],o=e.querySelectorAll("*");for(const i of o){const e=i.tagName.toLowerCase();if(a.has(e)){t.push(i);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===i.namespaceURI)&&Array.from(i.attributes).some(e=>l.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(i);continue}const o=[];for(const t of i.attributes){const e=t.name.toLowerCase();l.test(e)?o.push(t.name):(d.has(e)&&c.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&o.push(t.name)}o.forEach(e=>i.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}var p=class{static dependencies;static manifest;aliases;version="3.0.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[r,s]of Object.entries(e)){if(void 0===s)continue;if(!(r in t)){t[r]=s,o[r]=i;continue}if(t[r]===s)continue;const e=o[r]?.constructor.name??this.constructor.name,a=i.constructor.name,l=n("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${r}" 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)}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}}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);void 0!==i?"string"==typeof i?e.innerHTML=u(i):i instanceof HTMLElement&&(e.innerHTML="",e.appendChild(i.cloneNode(!0))):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const o=document.createElement("span");o.setAttribute("part","sort-indicator"),o.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(o,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(o,"sortNone"));const i=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return i?e.insertBefore(o,i):e.appendChild(o),o}warn(e,t){void 0!==t?console.warn(n(e,t,this.gridElement.id,this.name)):console.warn(`${r(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(n(e,t,this.gridElement.id,this.name))}},g={sum:e=>{let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t},avg:e=>{if(!e.length)return 0;let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t/e.length},count:e=>e.length,min:e=>{if(!e.length)return 0;let t=e[0];for(let o=1;o<e.length;o++)e[o]<t&&(t=e[o]);return t},max:e=>{if(!e.length)return 0;let t=e[0];for(let o=1;o<e.length;o++)e[o]>t&&(t=e[o]);return t},first:e=>e[0]??0,last:e=>e[e.length-1]??0};function h(e){return"function"==typeof e?e:function(e){return g[e]??g.sum}(e)}function v(e,t){return[...e,t].join("|")}function f(e,t){const o=t.rowGroupFields??[],i=t.columnGroupFields??[],r=t.valueFields??[],n=function(e,t,o="asc"){if(0===t.length)return["value"];const i=/* @__PURE__ */new Set;for(const n of e){const e=t.map(e=>String(n[e]??"")).join("|");i.add(e)}const r=[...i].sort();return"desc"===o?r.reverse():r}(e,i,t.sortColumns),s=m(e,o,i,n,r,0,"");t.sortRows&&F(s,t.sortRows,r);const a=function(e,t,o){const i={};function r(e){for(const n of e)if(n.isGroup&&n.children?.length)n.children&&r(n.children);else for(const e of t)for(const t of o){const o=v([e],t.field);i[o]=(i[o]??0)+(n.values[o]??0)}}return r(e),i}(s,n,r);return{rows:s,columnKeys:n,totals:a,grandTotal:Object.values(a).reduce((e,t)=>e+t,0)}}function m(e,t,o,i,r,n,s){const a=[];if(0===t.length){const t=b(e,o,i,r),l=w(t);return a.push({rowKey:s||"all",rowLabel:s||"All",depth:n,values:t,total:l,isGroup:!1,rowCount:e.length}),a}const l=t[0],d=t.slice(1),c=d.length>0,u=function(e,t){const o=/* @__PURE__ */new Map;for(const i of e){const e=String(i[t]??""),r=o.get(e);r?r.push(i):o.set(e,[i])}return o}(e,l);for(const[p,g]of u){const e=s?`${s}|${p}`:p,t=b(g,o,i,r),l=w(t);let u;c&&(u=m(g,d,o,i,r,n+1,e)),a.push({rowKey:e,rowLabel:p||"(blank)",depth:n,values:t,total:l,isGroup:c,children:u,rowCount:g.length})}return a}function b(e,t,o,i){const r={};if(0===t.length){for(const t of i){const o=[];for(let r=0;r<e.length;r++){const i=e[r][t.field];if(null==i||""===i)continue;const n=Number(i);isNaN(n)||o.push(n)}const i=h(t.aggFunc);r[v(["value"],t.field)]=o.length>0?i(o):null}return r}const n=/* @__PURE__ */new Map;for(let s=0;s<e.length;s++){const o=e[s];let i=String(o[t[0]]??"");for(let e=1;e<t.length;e++)i+="|",i+=String(o[t[e]]??"");const r=n.get(i);r?r.push(o):n.set(i,[o])}for(const s of o){const e=n.get(s);if(e&&0!==e.length)for(const t of i){const o=[];for(let r=0;r<e.length;r++){const i=e[r][t.field];if(null==i||""===i)continue;const n=Number(i);isNaN(n)||o.push(n)}const i=h(t.aggFunc);r[v([s],t.field)]=o.length>0?i(o):null}else for(const t of i)r[v([s],t.field)]=null}return r}function w(e){let t=0;for(const o of Object.values(e))t+=o??0;return t}function C(e){const t=[];function o(e){if(e.isGroup&&t.push(e.rowKey),e.children)for(const t of e.children)o(t)}for(const i of e)o(i);return t}function F(e,t,o){const i="desc"===t.direction?-1:1;e.sort((e,r)=>"value"===t.by&&(t.valueField??o[0]?.field)?((e.total??0)-(r.total??0))*i:e.rowLabel.localeCompare(r.rowLabel)*i);for(const r of e)r.children?.length&&F(r.children,t,o)}function y(e,t,o){if(0===t.length)return;const i=new Set(o.map(e=>e.field)),r=t.map(e=>"value"===e.by?e.valueField?t=>((e,t)=>{if(null!=e.values[t])return"number"==typeof e.values[t]?e.values[t]:0;if(i.has(t)){const o=`|${t}`;let i=0,r=!1;for(const t of Object.keys(e.values))t.endsWith(o)&&(i+="number"==typeof e.values[t]?e.values[t]:0,r=!0);if(r)return i}return e.total??0})(t,e.valueField):e=>e.total??0:null);e.sort((e,o)=>{for(let i=0;i<t.length;i++){const n=t[i],s="desc"===n.direction?-1:1;let a=0;if("value"===n.by){const t=r[i];a=(t(e)-t(o))*s}else a=e.rowLabel.localeCompare(o.rowLabel)*s;if(0!==a)return a}return 0});for(const n of e)n.children?.length&&y(n.children,t,o)}var x="dragging",_=["sum","avg","count","min","max","first","last"];function A(e,t,o,i){const r=new AbortController,n={config:t,callbacks:i,signal:r.signal},s=document.createElement("div");return s.className="tbw-pivot-panel",s.appendChild(T("Options",()=>function(e,t){const{config:o,callbacks:i,signal:r}=t,n=document.createElement("div");return n.className="tbw-pivot-options",n.appendChild(R("Enable Pivot View",e,e=>{i.onTogglePivot(e)},r)),n.appendChild(R("Show Row Totals",o.showTotals??!0,e=>{i.onOptionChange("showTotals",e)},r)),n.appendChild(R("Show Grand Total",o.showGrandTotal??!0,e=>{i.onOptionChange("showGrandTotal",e)},r)),n}(o,n))),s.appendChild(T("Row Groups",()=>E("rowGroups",n))),s.appendChild(T("Column Groups",()=>E("columnGroups",n))),s.appendChild(T("Values",()=>function(e){const{config:t,callbacks:o,signal:i}=e,r=document.createElement("div");r.className="tbw-pivot-drop-zone tbw-pivot-values-zone",r.setAttribute("data-zone","values");const n=t.valueFields??[];if(0===n.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="Drag numeric fields here",r.appendChild(e)}else for(const s of n)r.appendChild(G(s,e));return r.addEventListener("dragover",e=>{e.preventDefault(),r.classList.add("drag-over")},{signal:i}),r.addEventListener("dragleave",()=>{r.classList.remove("drag-over")},{signal:i}),r.addEventListener("drop",e=>{e.preventDefault(),r.classList.remove("drag-over");const t=e.dataTransfer?.getData("text/plain");t&&o.onAddValueField(t,"sum")},{signal:i}),r}(n))),s.appendChild(T("Available Fields",()=>function(e){const{config:t,callbacks:o,signal:i}=e,r=document.createElement("div");r.className="tbw-pivot-available-fields";const n=o.getAvailableFields(),s=/* @__PURE__ */new Set([...t.rowGroupFields??[],...t.columnGroupFields??[],...t.valueFields?.map(e=>e.field)??[]]),a=n.filter(e=>!s.has(e.field));if(0===a.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="All fields are in use",r.appendChild(e)}else{const e=document.createElement("div");if(e.className="tbw-pivot-fields-list",a.length>=6){const t=document.createElement("input");t.type="text",t.placeholder="Filter fields…",t.className="tbw-pivot-field-search",t.addEventListener("input",()=>{const o=t.value.toLowerCase();for(const t of e.querySelectorAll(".tbw-pivot-field-chip")){const e=t;e.style.display=e.textContent?.toLowerCase().includes(o)?"":"none"}},{signal:i}),r.appendChild(t)}for(const t of a){const o=document.createElement("div");o.className="tbw-pivot-field-chip available",o.textContent=t.header,o.draggable=!0,o.title=`Drag to add "${t.field}" to a zone`,o.addEventListener("dragstart",e=>{e.dataTransfer?.setData("text/plain",t.field),o.classList.add(x)},{signal:i}),o.addEventListener("dragend",()=>{o.classList.remove(x)},{signal:i}),e.appendChild(o)}r.appendChild(e)}return r}(n))),e.appendChild(s),()=>{r.abort(),s.remove()}}function T(e,t){const o=document.createElement("div");o.className="tbw-pivot-section";const i=document.createElement("div");i.className="tbw-pivot-section-header",i.textContent=e;const r=document.createElement("div");return r.className="tbw-pivot-section-content",r.appendChild(t()),o.appendChild(i),o.appendChild(r),o}function E(e,t){const{config:o,callbacks:i,signal:r}=t,n=document.createElement("div");n.className="tbw-pivot-drop-zone",n.setAttribute("data-zone",e);const s="rowGroups"===e?o.rowGroupFields??[]:o.columnGroupFields??[];if(0===s.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="Drag fields here",n.appendChild(e)}else for(const a of s)n.appendChild(S(a,e,t));return n.addEventListener("dragover",e=>{e.preventDefault(),n.classList.add("drag-over")},{signal:r}),n.addEventListener("dragleave",()=>{n.classList.remove("drag-over")},{signal:r}),n.addEventListener("drop",t=>{t.preventDefault(),n.classList.remove("drag-over");const o=t.dataTransfer?.getData("text/plain"),r=t.dataTransfer?.getData("source-zone");if(!o)return;const s=n.querySelectorAll(".tbw-pivot-field-chip");let a=s.length;for(let e=0;e<s.length;e++){const o=s[e].getBoundingClientRect();if(t.clientY<o.top+o.height/2){a=e;break}}!r||r===e||"rowGroups"!==r&&"columnGroups"!==r?r===e?i.onReorderFieldInZone(o,e,a):i.onAddFieldToZone(o,e):i.onMoveFieldBetweenZones(o,r,e)},{signal:r}),n}function S(e,t,o){const{callbacks:i,signal:r}=o,n=document.createElement("div");n.className="tbw-pivot-field-chip",n.draggable=!0;const s=i.getAvailableFields().find(t=>t.field===e),a=document.createElement("span");a.className="tbw-pivot-chip-label",a.textContent=s?.header??e;const l=document.createElement("button");return l.type="button",l.className="tbw-pivot-chip-remove",l.innerHTML="×",l.title="Remove field",l.addEventListener("click",o=>{o.stopPropagation(),i.onRemoveFieldFromZone(e,t)},{signal:r}),n.appendChild(a),n.appendChild(l),n.addEventListener("dragstart",o=>{o.dataTransfer?.setData("text/plain",e),o.dataTransfer?.setData("source-zone",t),n.classList.add(x)},{signal:r}),n.addEventListener("dragend",()=>{n.classList.remove(x)},{signal:r}),n}function G(e,t){const{callbacks:o,signal:i}=t,r=document.createElement("div");r.className="tbw-pivot-field-chip tbw-pivot-value-chip";const n=o.getAvailableFields().find(t=>t.field===e.field),s=document.createElement("div");s.className="tbw-pivot-value-label-wrapper";const a=document.createElement("span");a.className="tbw-pivot-chip-label",a.textContent=n?.header??e.field;const l="function"==typeof e.aggFunc,d=document.createElement("select");if(d.className="tbw-pivot-agg-select",d.title="Aggregation function",l){const e=document.createElement("option");e.value="__custom__",e.textContent="CUSTOM",e.selected=!0,d.appendChild(e),d.disabled=!0}for(const u of _){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="Remove value field",c.addEventListener("click",t=>{t.stopPropagation(),o.onRemoveValueField(e.field)},{signal:i}),s.appendChild(a),s.appendChild(d),r.appendChild(s),r.appendChild(c),r}function R(e,t,o,i){const r=document.createElement("label");r.className="tbw-pivot-checkbox";const n=document.createElement("input");n.type="checkbox",n.checked=t,n.addEventListener("change",()=>o(n.checked),{signal:i});const s=document.createElement("span");return s.textContent=e,r.appendChild(n),r.appendChild(s),r}function L(e,t,o){return t.className="data-grid-row pivot-grand-total-row",t.innerHTML="",o.forEach((o,i)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(i)),0===i){const e=document.createElement("span");e.className="pivot-label",e.textContent="Grand Total",r.appendChild(e)}else{const t=e[o.field];r.textContent=null!=t?o.format?o.format(t,e):String(t):""}t.appendChild(r)}),!0}var P=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: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-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:"Pivot",icon:"⊞",tooltip:"Configure pivot table",order:90,render:e=>this.renderPanel(e)}}processRows(e){if(!this.hasInitialized&&!1!==this.config.active&&this.hasValidPivotConfig()&&(this.hasInitialized=!0,this.isActive=!0),!this.isActive)return[...e];const t=function(e){const t=[];return e.rowGroupFields?.length||e.columnGroupFields?.length||t.push("At least one row or column group field is required"),e.valueFields?.length||t.push("At least one value field is required"),t}(this.config);if(t.length>0)return this.warn(`Config errors: ${t.join(", ")}`),[...e];this.buildFieldHeaderMap(),this.buildValueFormatters(),this.defaultExpanded=this.config.defaultExpanded??!0,this.pivotResult=f(e,this.config);const o=this.getMultiSortConfigs();if(o&&y(this.pivotResult.rows,o,this.config.valueFields??[]),0===this.expandedKeys.size&&!this.userHasToggledExpand){const e=C(this.pivotResult.rows);this.expandedKeys=function(e,t){if(!0===e||void 0===e)return new Set(t);if(!1===e)/* @__PURE__ */return new Set;if("number"==typeof e){const o=t[e];return o?/* @__PURE__ */new Set([o]):/* @__PURE__ */new Set}return"string"==typeof e?/* @__PURE__ */new Set([e]):Array.isArray(e)?new Set(e):/* @__PURE__ */new Set}(this.defaultExpanded,e)}this.config.valueDisplayMode&&"raw"!==this.config.valueDisplayMode&&(this.columnTotals=function(e,t,o){const i={};return function e(r){for(const n of r)if(n.isGroup&&n.children?.length)n.children&&e(n.children);else for(const e of t)for(const t of o){const o=v([e],t.field);i[o]=(i[o]??0)+(n.values[o]??0)}}(e),i}(this.pivotResult.rows,this.pivotResult.columnKeys,this.config.valueFields??[]));const i=this.config.indentWidth??20,r=!0===this.defaultExpanded||void 0===this.defaultExpanded,n=function(e,t,o=!0){const i=[];function r(e){i.push(e);const n=t?t.has(e.rowKey):o;if(e.children&&n)for(const t of e.children)r(t)}for(const n of e)r(n);return i}(this.pivotResult.rows,this.expandedKeys,r).map(e=>({__pivotRowKey:e.rowKey,__pivotLabel:e.rowLabel,__pivotDepth:e.depth,__pivotIsGroup:e.isGroup,__pivotHasChildren:Boolean(e.children?.length),__pivotExpanded:this.expandedKeys.has(e.rowKey),__pivotRowCount:e.rowCount??0,__pivotIndent:e.depth*i,__pivotTotal:e.total,...e.values}));this.keysToAnimate.clear();const s=/* @__PURE__ */new Set;for(const a of n){const e=a.__pivotRowKey;s.add(e),!this.previousVisibleKeys.has(e)&&a.__pivotDepth>0&&this.keysToAnimate.add(e)}return this.previousVisibleKeys=s,this.config.grandTotalInRowModel&&this.config.showGrandTotal&&this.pivotResult&&n.push({__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotDepth:0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals}),n}processColumns(e){if(!this.isActive||!this.pivotResult)return[...e];const t=[],o=(this.config.rowGroupFields??[]).map(e=>this.fieldHeaderMap.get(e)??e).join(" / ");t.push({field:"__pivotLabel",header:o||"Group",width:200,sortable:!0});for(const i of this.pivotResult.columnKeys)for(const e of this.config.valueFields??[]){const o=v([i],e.field),r=e.header||this.fieldHeaderMap.get(e.field)||e.field,n="function"==typeof e.aggFunc?"custom":e.aggFunc,s=this.valueFormatters.get(e.field);t.push({field:o,header:`${i} - ${r} (${n})`,width:120,type:"number",sortable:!0,...s?{format:e=>null!=e?s(Number(e)):""}:{}})}return this.config.showTotals&&t.push({field:"__pivotTotal",header:"Total",width:100,type:"number",sortable:!0}),t}renderRow(e,t,o){const i=e;return i.__pivotIsGrandTotal?L(i,t,this.gridColumns):i.__pivotRowKey&&i.__pivotHasChildren?function(e,t,o){return t.className="data-grid-row pivot-group-row",t.setAttribute("data-pivot-depth",String(e.__pivotDepth??0)),t.setAttribute("data-pivot-key",String(e.__pivotRowKey??"")),t.setAttribute("role","row"),t.innerHTML="",o.columns.forEach((i,r)=>{const n=document.createElement("div");if(n.className="cell",n.setAttribute("data-col",String(r)),n.setAttribute("data-row",String(o.rowIndex)),n.setAttribute("role","gridcell"),0===r){const t=Number(e.__pivotIndent)||0;n.style.paddingLeft=`${t}px`;const i=String(e.__pivotRowKey),r=document.createElement("button");r.type="button",r.className="pivot-toggle",r.setAttribute("aria-label",e.__pivotExpanded?"Collapse group":"Expand group"),o.setIcon(r,e.__pivotExpanded?"collapse":"expand"),r.addEventListener("click",e=>{e.stopPropagation(),o.onToggle(i)}),n.appendChild(r);const s=document.createElement("span");s.className="pivot-label",s.textContent=String(e.__pivotLabel??""),n.appendChild(s);const a=document.createElement("span");a.className="pivot-count",a.textContent=` (${Number(e.__pivotRowCount)||0})`,n.appendChild(a)}else{const t=e[i.field];n.textContent=null!=t?i.format?i.format(t,e):String(t):""}t.appendChild(n)}),!0}(i,t,{columns:this.gridColumns,rowIndex:o,onToggle:e=>this.toggle(e),setIcon:(e,t)=>this.setIcon(e,t)}):void 0!==i.__pivotRowKey&&this.isActive?function(e,t,o,i){return t.className="data-grid-row pivot-leaf-row",t.setAttribute("data-pivot-depth",String(e.__pivotDepth??0)),t.setAttribute("data-pivot-key",String(e.__pivotRowKey??"")),t.innerHTML="",o.forEach((o,r)=>{const n=document.createElement("div");if(n.className="cell",n.setAttribute("data-col",String(r)),n.setAttribute("data-row",String(i)),n.setAttribute("role","gridcell"),0===r){const t=Number(e.__pivotIndent)||0;n.style.paddingLeft=`${t+20}px`;const o=document.createElement("span");o.className="pivot-label",o.textContent=String(e.__pivotLabel??""),n.appendChild(o)}else{const t=e[o.field];n.textContent=null!=t?o.format?o.format(t,e):String(t):""}t.appendChild(n)}),!0}(i,t,this.gridColumns,o):(this.cleanupPivotStyling(t),!1)}cleanupPivotStyling(e){(e.classList.contains("pivot-group-row")||e.classList.contains("pivot-leaf-row")||e.classList.contains("pivot-grand-total-row"))&&(e.classList.remove("pivot-group-row","pivot-leaf-row","pivot-grand-total-row"),e.classList.add("data-grid-row"),e.removeAttribute("data-pivot-depth"),e.innerHTML="")}onKeyDown(e){if(" "!==e.key)return;if(!this.isActive)return;const t=this.grid._focusRow,o=this.rows[t];return o?.__pivotIsGroup&&o.__pivotHasChildren?(e.preventDefault(),this.toggle(o.__pivotRowKey),this.requestRenderWithFocus(),!0):void 0}handleQuery(e){if("sort:get-sort-config"===e.type){const e=this.getMultiSortConfigs();return e||(this.config.sortRows??null)}}onHeaderClick(e){if(!this.isActive)return!1;const t=e.field;if(!this.isPivotField(t))return!1;if(this.isMultiSortActive())return!1;const r=this.mapFieldToSortConfig(t);if(!r)return!1;const n=this.activeSortDir;let s;s=this.activeSortField!==t?"asc":"asc"===n?"desc":null,this.activeSortField=s?t:null,this.activeSortDir=s,this.config.sortRows=s?{...r,direction:s}:void 0,this.emit("pivot-config-change",{property:"sortRows"}),this.refresh();const a=this.gridElement;if(a){const r=e.column.header??t;o(a,s?i(a,"sortApplied",r,"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,r=e.querySelectorAll(".header-row .cell[data-field]");for(const n of r){const e=n.getAttribute("data-field");if(!e||!this.isPivotField(e))continue;let r=null;t===e?r=o:i&&("label"===i.by&&"__pivotLabel"===e?r=i.direction??"asc":"value"!==i.by||"__pivotTotal"!==e||i.valueField?"value"===i.by&&i.valueField&&e===i.valueField&&(r=i.direction??"asc"):r=i.direction??"asc"),this.updateSortIndicator(n,r)}}renderGrandTotalFooter(){if(!this.pivotResult)return;const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.querySelector(".tbw-grid-root");t&&(this.grandTotalFooter||(this.grandTotalFooter=document.createElement("div"),this.grandTotalFooter.className="pivot-grand-total-footer",t.appendChild(this.grandTotalFooter)),L({__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals},this.grandTotalFooter,this.gridColumns),this.grandTotalFooter.setAttribute("role","presentation"))}cleanupGrandTotalFooter(){this.grandTotalFooter&&(this.grandTotalFooter.remove(),this.grandTotalFooter=null)}toggle(e){this.userHasToggledExpand=!0;const t=this.expandedKeys.has(e);t?this.expandedKeys.delete(e):this.expandedKeys.add(e),this.emitToggle(e,!t),this.requestRender()}expand(e){this.userHasToggledExpand=!0,this.expandedKeys.add(e),this.emitToggle(e,!0),this.requestRender()}collapse(e){this.userHasToggledExpand=!0,this.expandedKeys.delete(e),this.emitToggle(e,!1),this.requestRender()}expandAll(){this.userHasToggledExpand=!0,this.expandAllKeys(),this.requestRender()}collapseAll(){this.userHasToggledExpand=!0,this.expandedKeys.clear(),this.requestRender()}expandAllKeys(){if(!this.pivotResult)return;const e=C(this.pivotResult.rows);for(const t of e)this.expandedKeys.add(t)}isExpanded(e){return this.expandedKeys.has(e)}getExpandedGroups(){return[...this.expandedKeys]}enablePivot(){0===this.originalColumns.length&&this.captureOriginalColumns(),this.isActive=!0,this.emit("pivot-state-change",{active:!0}),this.requestRender()}disablePivot(){this.isActive=!1,this.pivotResult=null,this.emit("pivot-state-change",{active:!1}),this.requestRender()}isPivotActive(){return this.isActive}getPivotResult(){return this.pivotResult}setRowGroupFields(e){this.config.rowGroupFields=e,this.emitConfigChange("rowGroupFields"),this.refresh()}setColumnGroupFields(e){this.config.columnGroupFields=e,this.emitConfigChange("columnGroupFields"),this.refresh()}setValueFields(e){this.config.valueFields=e,this.emitConfigChange("valueFields"),this.refresh()}refresh(){this.pivotResult=null,this.requestRender()}#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(),A(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()})}refreshPanel(){this.panelContainer&&(this.panelContainer.innerHTML="",this.renderPanel(this.panelContainer))}addFieldToZone(e,t){if("rowGroups"===t){const t=this.config.rowGroupFields??[];t.includes(e)||(this.config.rowGroupFields=[...t,e])}else{const t=this.config.columnGroupFields??[];t.includes(e)||(this.config.columnGroupFields=[...t,e])}this.removeFromOtherZones(e,t),this.refreshIfActive()}removeFieldFromZone(e,t){"rowGroups"===t?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e),this.refreshIfActive()}reorderFieldInZone(e,t,o){const i="rowGroups"===t?[...this.config.rowGroupFields??[]]:[...this.config.columnGroupFields??[]],r=i.indexOf(e);-1!==r&&r!==o&&(i.splice(r,1),i.splice(o>r?o-1:o,0,e),"rowGroups"===t?this.config.rowGroupFields=i:this.config.columnGroupFields=i,this.refreshIfActive())}moveFieldBetweenZones(e,t,o){"rowGroups"===t?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e),"rowGroups"===o?this.config.rowGroupFields=[...this.config.rowGroupFields??[],e]:this.config.columnGroupFields=[...this.config.columnGroupFields??[],e],this.refreshIfActive()}removeFromOtherZones(e,t){"rowGroups"!==t&&(this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e)),"columnGroups"!==t&&(this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e)),"values"!==t&&(this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e))}addValueField(e,t){const o=this.config.valueFields??[];o.some(t=>t.field===e)||(this.config.valueFields=[...o,{field:e,aggFunc:t}]),this.removeFromOtherZones(e,"values"),this.refreshIfActive()}removeValueField(e){this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e),this.refreshIfActive()}updateValueAggFunc(e,t){const o=this.config.valueFields??[],i=o.findIndex(t=>t.field===e);i>=0&&(o[i]={...o[i],aggFunc:t},this.config.valueFields=[...o]),this.isActive&&this.refresh()}emitToggle(e,t){const o=this.rows.find(t=>t.__pivotRowKey===e);this.emit("pivot-toggle",{key:e,expanded:t,label:o?.__pivotLabel??e,depth:o?.__pivotDepth??0})}emitConfigChange(e,t,o){this.emit("pivot-config-change",{property:e,field:t,zone:o})}buildValueFormatters(){this.valueFormatters.clear();const e=this.config.valueFields??[];for(const t of e)if(t.format)this.valueFormatters.set(t.field,t.format);else if(this.originalColumns.find(e=>e.field===t.field)){const e=(this.grid.getAllColumns?.()??this.grid.columns??[]).find(e=>e.field===t.field);if(e?.format){const o=e.format;this.valueFormatters.set(t.field,e=>o(e,{}))}}}};export{P as PivotPlugin};
|
|
1
|
+
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`,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",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 r=(t&&"effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.messages?.[o];return r?r(...i):e[o](...i)}function r(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function n(e,t,o,i){return`${r(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".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){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],o=e.querySelectorAll("*");for(const i of o){const e=i.tagName.toLowerCase();if(a.has(e)){t.push(i);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===i.namespaceURI)&&Array.from(i.attributes).some(e=>l.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(i);continue}const o=[];for(const t of i.attributes){const e=t.name.toLowerCase();l.test(e)?o.push(t.name):(d.has(e)&&c.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&o.push(t.name)}o.forEach(e=>i.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}var p=class{static dependencies;static manifest;aliases;version="3.0.1";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[r,s]of Object.entries(e)){if(void 0===s)continue;if(!(r in t)){t[r]=s,o[r]=i;continue}if(t[r]===s)continue;const e=o[r]?.constructor.name??this.constructor.name,a=i.constructor.name,l=n("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${r}" 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)}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}}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);void 0!==i?"string"==typeof i?e.innerHTML=u(i):i instanceof HTMLElement&&(e.innerHTML="",e.appendChild(i.cloneNode(!0))):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const o=document.createElement("span");o.setAttribute("part","sort-indicator"),o.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(o,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(o,"sortNone"));const i=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return i?e.insertBefore(o,i):e.appendChild(o),o}warn(e,t){void 0!==t?console.warn(n(e,t,this.gridElement.id,this.name)):console.warn(`${r(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(n(e,t,this.gridElement.id,this.name))}},g={sum:e=>{let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t},avg:e=>{if(!e.length)return 0;let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t/e.length},count:e=>e.length,min:e=>{if(!e.length)return 0;let t=e[0];for(let o=1;o<e.length;o++)e[o]<t&&(t=e[o]);return t},max:e=>{if(!e.length)return 0;let t=e[0];for(let o=1;o<e.length;o++)e[o]>t&&(t=e[o]);return t},first:e=>e[0]??0,last:e=>e[e.length-1]??0};function h(e){return"function"==typeof e?e:function(e){return g[e]??g.sum}(e)}function v(e,t){return[...e,t].join("|")}function f(e,t){const o=t.rowGroupFields??[],i=t.columnGroupFields??[],r=t.valueFields??[],n=function(e,t,o="asc"){if(0===t.length)return["value"];const i=/* @__PURE__ */new Set;for(const n of e){const e=t.map(e=>String(n[e]??"")).join("|");i.add(e)}const r=[...i].sort();return"desc"===o?r.reverse():r}(e,i,t.sortColumns),s=m(e,o,i,n,r,0,"");t.sortRows&&F(s,t.sortRows,r);const a=function(e,t,o){const i={};function r(e){for(const n of e)if(n.isGroup&&n.children?.length)n.children&&r(n.children);else for(const e of t)for(const t of o){const o=v([e],t.field);i[o]=(i[o]??0)+(n.values[o]??0)}}return r(e),i}(s,n,r);return{rows:s,columnKeys:n,totals:a,grandTotal:Object.values(a).reduce((e,t)=>e+t,0)}}function m(e,t,o,i,r,n,s){const a=[];if(0===t.length){const t=b(e,o,i,r),l=w(t);return a.push({rowKey:s||"all",rowLabel:s||"All",depth:n,values:t,total:l,isGroup:!1,rowCount:e.length}),a}const l=t[0],d=t.slice(1),c=d.length>0,u=function(e,t){const o=/* @__PURE__ */new Map;for(const i of e){const e=String(i[t]??""),r=o.get(e);r?r.push(i):o.set(e,[i])}return o}(e,l);for(const[p,g]of u){const e=s?`${s}|${p}`:p,t=b(g,o,i,r),l=w(t);let u;c&&(u=m(g,d,o,i,r,n+1,e)),a.push({rowKey:e,rowLabel:p||"(blank)",depth:n,values:t,total:l,isGroup:c,children:u,rowCount:g.length})}return a}function b(e,t,o,i){const r={};if(0===t.length){for(const t of i){const o=[];for(let r=0;r<e.length;r++){const i=e[r][t.field];if(null==i||""===i)continue;const n=Number(i);isNaN(n)||o.push(n)}const i=h(t.aggFunc);r[v(["value"],t.field)]=o.length>0?i(o):null}return r}const n=/* @__PURE__ */new Map;for(let s=0;s<e.length;s++){const o=e[s];let i=String(o[t[0]]??"");for(let e=1;e<t.length;e++)i+="|",i+=String(o[t[e]]??"");const r=n.get(i);r?r.push(o):n.set(i,[o])}for(const s of o){const e=n.get(s);if(e&&0!==e.length)for(const t of i){const o=[];for(let r=0;r<e.length;r++){const i=e[r][t.field];if(null==i||""===i)continue;const n=Number(i);isNaN(n)||o.push(n)}const i=h(t.aggFunc);r[v([s],t.field)]=o.length>0?i(o):null}else for(const t of i)r[v([s],t.field)]=null}return r}function w(e){let t=0;for(const o of Object.values(e))t+=o??0;return t}function C(e){const t=[];function o(e){if(e.isGroup&&t.push(e.rowKey),e.children)for(const t of e.children)o(t)}for(const i of e)o(i);return t}function F(e,t,o){const i="desc"===t.direction?-1:1;e.sort((e,r)=>"value"===t.by&&(t.valueField??o[0]?.field)?((e.total??0)-(r.total??0))*i:e.rowLabel.localeCompare(r.rowLabel)*i);for(const r of e)r.children?.length&&F(r.children,t,o)}function y(e,t,o){if(0===t.length)return;const i=new Set(o.map(e=>e.field)),r=t.map(e=>"value"===e.by?e.valueField?t=>((e,t)=>{if(null!=e.values[t])return"number"==typeof e.values[t]?e.values[t]:0;if(i.has(t)){const o=`|${t}`;let i=0,r=!1;for(const t of Object.keys(e.values))t.endsWith(o)&&(i+="number"==typeof e.values[t]?e.values[t]:0,r=!0);if(r)return i}return e.total??0})(t,e.valueField):e=>e.total??0:null);e.sort((e,o)=>{for(let i=0;i<t.length;i++){const n=t[i],s="desc"===n.direction?-1:1;let a=0;if("value"===n.by){const t=r[i];a=(t(e)-t(o))*s}else a=e.rowLabel.localeCompare(o.rowLabel)*s;if(0!==a)return a}return 0});for(const n of e)n.children?.length&&y(n.children,t,o)}var x="dragging",_=["sum","avg","count","min","max","first","last"];function A(e,t,o,i){const r=new AbortController,n={config:t,callbacks:i,signal:r.signal},s=document.createElement("div");return s.className="tbw-pivot-panel",s.appendChild(T("Options",()=>function(e,t){const{config:o,callbacks:i,signal:r}=t,n=document.createElement("div");return n.className="tbw-pivot-options",n.appendChild(R("Enable Pivot View",e,e=>{i.onTogglePivot(e)},r)),n.appendChild(R("Show Row Totals",o.showTotals??!0,e=>{i.onOptionChange("showTotals",e)},r)),n.appendChild(R("Show Grand Total",o.showGrandTotal??!0,e=>{i.onOptionChange("showGrandTotal",e)},r)),n}(o,n))),s.appendChild(T("Row Groups",()=>E("rowGroups",n))),s.appendChild(T("Column Groups",()=>E("columnGroups",n))),s.appendChild(T("Values",()=>function(e){const{config:t,callbacks:o,signal:i}=e,r=document.createElement("div");r.className="tbw-pivot-drop-zone tbw-pivot-values-zone",r.setAttribute("data-zone","values");const n=t.valueFields??[];if(0===n.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="Drag numeric fields here",r.appendChild(e)}else for(const s of n)r.appendChild(G(s,e));return r.addEventListener("dragover",e=>{e.preventDefault(),r.classList.add("drag-over")},{signal:i}),r.addEventListener("dragleave",()=>{r.classList.remove("drag-over")},{signal:i}),r.addEventListener("drop",e=>{e.preventDefault(),r.classList.remove("drag-over");const t=e.dataTransfer?.getData("text/plain");t&&o.onAddValueField(t,"sum")},{signal:i}),r}(n))),s.appendChild(T("Available Fields",()=>function(e){const{config:t,callbacks:o,signal:i}=e,r=document.createElement("div");r.className="tbw-pivot-available-fields";const n=o.getAvailableFields(),s=/* @__PURE__ */new Set([...t.rowGroupFields??[],...t.columnGroupFields??[],...t.valueFields?.map(e=>e.field)??[]]),a=n.filter(e=>!s.has(e.field));if(0===a.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="All fields are in use",r.appendChild(e)}else{const e=document.createElement("div");if(e.className="tbw-pivot-fields-list",a.length>=6){const t=document.createElement("input");t.type="text",t.placeholder="Filter fields…",t.className="tbw-pivot-field-search",t.addEventListener("input",()=>{const o=t.value.toLowerCase();for(const t of e.querySelectorAll(".tbw-pivot-field-chip")){const e=t;e.style.display=e.textContent?.toLowerCase().includes(o)?"":"none"}},{signal:i}),r.appendChild(t)}for(const t of a){const o=document.createElement("div");o.className="tbw-pivot-field-chip available",o.textContent=t.header,o.draggable=!0,o.title=`Drag to add "${t.field}" to a zone`,o.addEventListener("dragstart",e=>{e.dataTransfer?.setData("text/plain",t.field),o.classList.add(x)},{signal:i}),o.addEventListener("dragend",()=>{o.classList.remove(x)},{signal:i}),e.appendChild(o)}r.appendChild(e)}return r}(n))),e.appendChild(s),()=>{r.abort(),s.remove()}}function T(e,t){const o=document.createElement("div");o.className="tbw-pivot-section";const i=document.createElement("div");i.className="tbw-pivot-section-header",i.textContent=e;const r=document.createElement("div");return r.className="tbw-pivot-section-content",r.appendChild(t()),o.appendChild(i),o.appendChild(r),o}function E(e,t){const{config:o,callbacks:i,signal:r}=t,n=document.createElement("div");n.className="tbw-pivot-drop-zone",n.setAttribute("data-zone",e);const s="rowGroups"===e?o.rowGroupFields??[]:o.columnGroupFields??[];if(0===s.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="Drag fields here",n.appendChild(e)}else for(const a of s)n.appendChild(S(a,e,t));return n.addEventListener("dragover",e=>{e.preventDefault(),n.classList.add("drag-over")},{signal:r}),n.addEventListener("dragleave",()=>{n.classList.remove("drag-over")},{signal:r}),n.addEventListener("drop",t=>{t.preventDefault(),n.classList.remove("drag-over");const o=t.dataTransfer?.getData("text/plain"),r=t.dataTransfer?.getData("source-zone");if(!o)return;const s=n.querySelectorAll(".tbw-pivot-field-chip");let a=s.length;for(let e=0;e<s.length;e++){const o=s[e].getBoundingClientRect();if(t.clientY<o.top+o.height/2){a=e;break}}!r||r===e||"rowGroups"!==r&&"columnGroups"!==r?r===e?i.onReorderFieldInZone(o,e,a):i.onAddFieldToZone(o,e):i.onMoveFieldBetweenZones(o,r,e)},{signal:r}),n}function S(e,t,o){const{callbacks:i,signal:r}=o,n=document.createElement("div");n.className="tbw-pivot-field-chip",n.draggable=!0;const s=i.getAvailableFields().find(t=>t.field===e),a=document.createElement("span");a.className="tbw-pivot-chip-label",a.textContent=s?.header??e;const l=document.createElement("button");return l.type="button",l.className="tbw-pivot-chip-remove",l.innerHTML="×",l.title="Remove field",l.addEventListener("click",o=>{o.stopPropagation(),i.onRemoveFieldFromZone(e,t)},{signal:r}),n.appendChild(a),n.appendChild(l),n.addEventListener("dragstart",o=>{o.dataTransfer?.setData("text/plain",e),o.dataTransfer?.setData("source-zone",t),n.classList.add(x)},{signal:r}),n.addEventListener("dragend",()=>{n.classList.remove(x)},{signal:r}),n}function G(e,t){const{callbacks:o,signal:i}=t,r=document.createElement("div");r.className="tbw-pivot-field-chip tbw-pivot-value-chip";const n=o.getAvailableFields().find(t=>t.field===e.field),s=document.createElement("div");s.className="tbw-pivot-value-label-wrapper";const a=document.createElement("span");a.className="tbw-pivot-chip-label",a.textContent=n?.header??e.field;const l="function"==typeof e.aggFunc,d=document.createElement("select");if(d.className="tbw-pivot-agg-select",d.title="Aggregation function",l){const e=document.createElement("option");e.value="__custom__",e.textContent="CUSTOM",e.selected=!0,d.appendChild(e),d.disabled=!0}for(const u of _){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="Remove value field",c.addEventListener("click",t=>{t.stopPropagation(),o.onRemoveValueField(e.field)},{signal:i}),s.appendChild(a),s.appendChild(d),r.appendChild(s),r.appendChild(c),r}function R(e,t,o,i){const r=document.createElement("label");r.className="tbw-pivot-checkbox";const n=document.createElement("input");n.type="checkbox",n.checked=t,n.addEventListener("change",()=>o(n.checked),{signal:i});const s=document.createElement("span");return s.textContent=e,r.appendChild(n),r.appendChild(s),r}function L(e,t,o){return t.className="data-grid-row pivot-grand-total-row",t.innerHTML="",o.forEach((o,i)=>{const r=document.createElement("div");if(r.className="cell",r.setAttribute("data-col",String(i)),0===i){const e=document.createElement("span");e.className="pivot-label",e.textContent="Grand Total",r.appendChild(e)}else{const t=e[o.field];r.textContent=null!=t?o.format?o.format(t,e):String(t):""}t.appendChild(r)}),!0}var P=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: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-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:"Pivot",icon:"⊞",tooltip:"Configure pivot table",order:90,render:e=>this.renderPanel(e)}}processRows(e){if(!this.hasInitialized&&!1!==this.config.active&&this.hasValidPivotConfig()&&(this.hasInitialized=!0,this.isActive=!0),!this.isActive)return[...e];const t=function(e){const t=[];return e.rowGroupFields?.length||e.columnGroupFields?.length||t.push("At least one row or column group field is required"),e.valueFields?.length||t.push("At least one value field is required"),t}(this.config);if(t.length>0)return this.warn(`Config errors: ${t.join(", ")}`),[...e];this.buildFieldHeaderMap(),this.buildValueFormatters(),this.defaultExpanded=this.config.defaultExpanded??!0,this.pivotResult=f(e,this.config);const o=this.getMultiSortConfigs();if(o&&y(this.pivotResult.rows,o,this.config.valueFields??[]),0===this.expandedKeys.size&&!this.userHasToggledExpand){const e=C(this.pivotResult.rows);this.expandedKeys=function(e,t){if(!0===e||void 0===e)return new Set(t);if(!1===e)/* @__PURE__ */return new Set;if("number"==typeof e){const o=t[e];return o?/* @__PURE__ */new Set([o]):/* @__PURE__ */new Set}return"string"==typeof e?/* @__PURE__ */new Set([e]):Array.isArray(e)?new Set(e):/* @__PURE__ */new Set}(this.defaultExpanded,e)}this.config.valueDisplayMode&&"raw"!==this.config.valueDisplayMode&&(this.columnTotals=function(e,t,o){const i={};return function e(r){for(const n of r)if(n.isGroup&&n.children?.length)n.children&&e(n.children);else for(const e of t)for(const t of o){const o=v([e],t.field);i[o]=(i[o]??0)+(n.values[o]??0)}}(e),i}(this.pivotResult.rows,this.pivotResult.columnKeys,this.config.valueFields??[]));const i=this.config.indentWidth??20,r=!0===this.defaultExpanded||void 0===this.defaultExpanded,n=function(e,t,o=!0){const i=[];function r(e){i.push(e);const n=t?t.has(e.rowKey):o;if(e.children&&n)for(const t of e.children)r(t)}for(const n of e)r(n);return i}(this.pivotResult.rows,this.expandedKeys,r).map(e=>({__pivotRowKey:e.rowKey,__pivotLabel:e.rowLabel,__pivotDepth:e.depth,__pivotIsGroup:e.isGroup,__pivotHasChildren:Boolean(e.children?.length),__pivotExpanded:this.expandedKeys.has(e.rowKey),__pivotRowCount:e.rowCount??0,__pivotIndent:e.depth*i,__pivotTotal:e.total,...e.values}));this.keysToAnimate.clear();const s=/* @__PURE__ */new Set;for(const a of n){const e=a.__pivotRowKey;s.add(e),!this.previousVisibleKeys.has(e)&&a.__pivotDepth>0&&this.keysToAnimate.add(e)}return this.previousVisibleKeys=s,this.config.grandTotalInRowModel&&this.config.showGrandTotal&&this.pivotResult&&n.push({__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotDepth:0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals}),n}processColumns(e){if(!this.isActive||!this.pivotResult)return[...e];const t=[],o=(this.config.rowGroupFields??[]).map(e=>this.fieldHeaderMap.get(e)??e).join(" / ");t.push({field:"__pivotLabel",header:o||"Group",width:200,sortable:!0});for(const i of this.pivotResult.columnKeys)for(const e of this.config.valueFields??[]){const o=v([i],e.field),r=e.header||this.fieldHeaderMap.get(e.field)||e.field,n="function"==typeof e.aggFunc?"custom":e.aggFunc,s=this.valueFormatters.get(e.field);t.push({field:o,header:`${i} - ${r} (${n})`,width:120,type:"number",sortable:!0,...s?{format:e=>null!=e?s(Number(e)):""}:{}})}return this.config.showTotals&&t.push({field:"__pivotTotal",header:"Total",width:100,type:"number",sortable:!0}),t}renderRow(e,t,o){const i=e;return i.__pivotIsGrandTotal?L(i,t,this.gridColumns):i.__pivotRowKey&&i.__pivotHasChildren?function(e,t,o){return t.className="data-grid-row pivot-group-row",t.setAttribute("data-pivot-depth",String(e.__pivotDepth??0)),t.setAttribute("data-pivot-key",String(e.__pivotRowKey??"")),t.setAttribute("role","row"),t.innerHTML="",o.columns.forEach((i,r)=>{const n=document.createElement("div");if(n.className="cell",n.setAttribute("data-col",String(r)),n.setAttribute("data-row",String(o.rowIndex)),n.setAttribute("role","gridcell"),0===r){const t=Number(e.__pivotIndent)||0;n.style.paddingLeft=`${t}px`;const i=String(e.__pivotRowKey),r=document.createElement("button");r.type="button",r.className="pivot-toggle",r.setAttribute("aria-label",e.__pivotExpanded?"Collapse group":"Expand group"),o.setIcon(r,e.__pivotExpanded?"collapse":"expand"),r.addEventListener("click",e=>{e.stopPropagation(),o.onToggle(i)}),n.appendChild(r);const s=document.createElement("span");s.className="pivot-label",s.textContent=String(e.__pivotLabel??""),n.appendChild(s);const a=document.createElement("span");a.className="pivot-count",a.textContent=` (${Number(e.__pivotRowCount)||0})`,n.appendChild(a)}else{const t=e[i.field];n.textContent=null!=t?i.format?i.format(t,e):String(t):""}t.appendChild(n)}),!0}(i,t,{columns:this.gridColumns,rowIndex:o,onToggle:e=>this.toggle(e),setIcon:(e,t)=>this.setIcon(e,t)}):void 0!==i.__pivotRowKey&&this.isActive?function(e,t,o,i){return t.className="data-grid-row pivot-leaf-row",t.setAttribute("data-pivot-depth",String(e.__pivotDepth??0)),t.setAttribute("data-pivot-key",String(e.__pivotRowKey??"")),t.innerHTML="",o.forEach((o,r)=>{const n=document.createElement("div");if(n.className="cell",n.setAttribute("data-col",String(r)),n.setAttribute("data-row",String(i)),n.setAttribute("role","gridcell"),0===r){const t=Number(e.__pivotIndent)||0;n.style.paddingLeft=`${t+20}px`;const o=document.createElement("span");o.className="pivot-label",o.textContent=String(e.__pivotLabel??""),n.appendChild(o)}else{const t=e[o.field];n.textContent=null!=t?o.format?o.format(t,e):String(t):""}t.appendChild(n)}),!0}(i,t,this.gridColumns,o):(this.cleanupPivotStyling(t),!1)}cleanupPivotStyling(e){(e.classList.contains("pivot-group-row")||e.classList.contains("pivot-leaf-row")||e.classList.contains("pivot-grand-total-row"))&&(e.classList.remove("pivot-group-row","pivot-leaf-row","pivot-grand-total-row"),e.classList.add("data-grid-row"),e.removeAttribute("data-pivot-depth"),e.innerHTML="")}onKeyDown(e){if(" "!==e.key)return;if(!this.isActive)return;const t=this.grid._focusRow,o=this.rows[t];return o?.__pivotIsGroup&&o.__pivotHasChildren?(e.preventDefault(),this.toggle(o.__pivotRowKey),this.requestRenderWithFocus(),!0):void 0}handleQuery(e){if("sort:get-sort-config"===e.type){const e=this.getMultiSortConfigs();return e||(this.config.sortRows??null)}}onHeaderClick(e){if(!this.isActive)return!1;const t=e.field;if(!this.isPivotField(t))return!1;if(this.isMultiSortActive())return!1;const r=this.mapFieldToSortConfig(t);if(!r)return!1;const n=this.activeSortDir;let s;s=this.activeSortField!==t?"asc":"asc"===n?"desc":null,this.activeSortField=s?t:null,this.activeSortDir=s,this.config.sortRows=s?{...r,direction:s}:void 0,this.emit("pivot-config-change",{property:"sortRows"}),this.refresh();const a=this.gridElement;if(a){const r=e.column.header??t;o(a,s?i(a,"sortApplied",r,"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,r=e.querySelectorAll(".header-row .cell[data-field]");for(const n of r){const e=n.getAttribute("data-field");if(!e||!this.isPivotField(e))continue;let r=null;t===e?r=o:i&&("label"===i.by&&"__pivotLabel"===e?r=i.direction??"asc":"value"!==i.by||"__pivotTotal"!==e||i.valueField?"value"===i.by&&i.valueField&&e===i.valueField&&(r=i.direction??"asc"):r=i.direction??"asc"),this.updateSortIndicator(n,r)}}renderGrandTotalFooter(){if(!this.pivotResult)return;const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.querySelector(".tbw-grid-root");t&&(this.grandTotalFooter||(this.grandTotalFooter=document.createElement("div"),this.grandTotalFooter.className="pivot-grand-total-footer",t.appendChild(this.grandTotalFooter)),L({__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals},this.grandTotalFooter,this.gridColumns),this.grandTotalFooter.setAttribute("role","presentation"))}cleanupGrandTotalFooter(){this.grandTotalFooter&&(this.grandTotalFooter.remove(),this.grandTotalFooter=null)}toggle(e){this.userHasToggledExpand=!0;const t=this.expandedKeys.has(e);t?this.expandedKeys.delete(e):this.expandedKeys.add(e),this.emitToggle(e,!t),this.requestRender()}expand(e){this.userHasToggledExpand=!0,this.expandedKeys.add(e),this.emitToggle(e,!0),this.requestRender()}collapse(e){this.userHasToggledExpand=!0,this.expandedKeys.delete(e),this.emitToggle(e,!1),this.requestRender()}expandAll(){this.userHasToggledExpand=!0,this.expandAllKeys(),this.requestRender()}collapseAll(){this.userHasToggledExpand=!0,this.expandedKeys.clear(),this.requestRender()}expandAllKeys(){if(!this.pivotResult)return;const e=C(this.pivotResult.rows);for(const t of e)this.expandedKeys.add(t)}isExpanded(e){return this.expandedKeys.has(e)}getExpandedGroups(){return[...this.expandedKeys]}enablePivot(){0===this.originalColumns.length&&this.captureOriginalColumns(),this.isActive=!0,this.emit("pivot-state-change",{active:!0}),this.requestRender()}disablePivot(){this.isActive=!1,this.pivotResult=null,this.emit("pivot-state-change",{active:!1}),this.requestRender()}isPivotActive(){return this.isActive}getPivotResult(){return this.pivotResult}setRowGroupFields(e){this.config.rowGroupFields=e,this.emitConfigChange("rowGroupFields"),this.refresh()}setColumnGroupFields(e){this.config.columnGroupFields=e,this.emitConfigChange("columnGroupFields"),this.refresh()}setValueFields(e){this.config.valueFields=e,this.emitConfigChange("valueFields"),this.refresh()}refresh(){this.pivotResult=null,this.requestRender()}#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(),A(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()})}refreshPanel(){this.panelContainer&&(this.panelContainer.innerHTML="",this.renderPanel(this.panelContainer))}addFieldToZone(e,t){if("rowGroups"===t){const t=this.config.rowGroupFields??[];t.includes(e)||(this.config.rowGroupFields=[...t,e])}else{const t=this.config.columnGroupFields??[];t.includes(e)||(this.config.columnGroupFields=[...t,e])}this.removeFromOtherZones(e,t),this.refreshIfActive()}removeFieldFromZone(e,t){"rowGroups"===t?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e),this.refreshIfActive()}reorderFieldInZone(e,t,o){const i="rowGroups"===t?[...this.config.rowGroupFields??[]]:[...this.config.columnGroupFields??[]],r=i.indexOf(e);-1!==r&&r!==o&&(i.splice(r,1),i.splice(o>r?o-1:o,0,e),"rowGroups"===t?this.config.rowGroupFields=i:this.config.columnGroupFields=i,this.refreshIfActive())}moveFieldBetweenZones(e,t,o){"rowGroups"===t?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e),"rowGroups"===o?this.config.rowGroupFields=[...this.config.rowGroupFields??[],e]:this.config.columnGroupFields=[...this.config.columnGroupFields??[],e],this.refreshIfActive()}removeFromOtherZones(e,t){"rowGroups"!==t&&(this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e)),"columnGroups"!==t&&(this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e)),"values"!==t&&(this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e))}addValueField(e,t){const o=this.config.valueFields??[];o.some(t=>t.field===e)||(this.config.valueFields=[...o,{field:e,aggFunc:t}]),this.removeFromOtherZones(e,"values"),this.refreshIfActive()}removeValueField(e){this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e),this.refreshIfActive()}updateValueAggFunc(e,t){const o=this.config.valueFields??[],i=o.findIndex(t=>t.field===e);i>=0&&(o[i]={...o[i],aggFunc:t},this.config.valueFields=[...o]),this.isActive&&this.refresh()}emitToggle(e,t){const o=this.rows.find(t=>t.__pivotRowKey===e);this.emit("pivot-toggle",{key:e,expanded:t,label:o?.__pivotLabel??e,depth:o?.__pivotDepth??0})}emitConfigChange(e,t,o){this.emit("pivot-config-change",{property:e,field:t,zone:o})}buildValueFormatters(){this.valueFormatters.clear();const e=this.config.valueFields??[];for(const t of e)if(t.format)this.valueFormatters.set(t.field,t.format);else if(this.originalColumns.find(e=>e.field===t.field)){const e=(this.grid.getAllColumns?.()??this.grid.columns??[]).find(e=>e.field===t.field);if(e?.format){const o=e.format;this.valueFormatters.set(t.field,e=>o(e,{}))}}}};export{P as PivotPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function t(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function e(e,i,n,r){return`${t(n,r)} ${e}: ${i}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(e)}`}var i="tbw-print-isolation-style";async function n(t,n={}){const{orientation:r="landscape"}=n,o=t.id;document.querySelectorAll(`#${CSS.escape(o)}`).length>1&&function(t,i,n,r){console.warn(e(t,i,n,r))}("TBW093",`Multiple elements found with id="${o}". Print isolation may not work correctly. Ensure each grid has a unique ID.`,o,"print"),document.getElementById(i)?.remove();const s=function(t,e){const n=document.createElement("style");return n.id=i,n.textContent=`\n /* Print isolation: hide everything except the target grid */\n @media print {\n /* Hide all body children by default */\n body > *:not(#${t}) {\n display: none !important;\n }\n\n /* But show the grid and ensure it's not hidden by ancestor rules */\n #${t} {\n display: block !important;\n position: static !important;\n visibility: visible !important;\n opacity: 1 !important;\n overflow: visible !important;\n height: auto !important;\n width: 100% !important;\n max-height: none !important;\n margin: 0 !important;\n padding: 0 !important;\n transform: none !important;\n }\n\n /* If grid is nested, we need to show its ancestors too */\n #${t},\n #${t} * {\n visibility: visible !important;\n }\n\n /* Walk up the DOM and show all ancestors of the grid */\n body *:has(> #${t}),\n body *:has(#${t}) {\n display: block !important;\n visibility: visible !important;\n opacity: 1 !important;\n overflow: visible !important;\n height: auto !important;\n position: static !important;\n transform: none !important;\n background: transparent !important;\n border: none !important;\n padding: 0 !important;\n margin: 0 !important;\n }\n\n /* Hide siblings of ancestors (everything that's not in the path to the grid) */\n body *:has(#${t}) > *:not(:has(#${t})):not(#${t}) {\n display: none !important;\n }\n\n /* Page settings */\n @page {\n size: ${e};\n margin: 1cm;\n }\n\n /* Ensure proper print styling */\n body {\n margin: 0 !important;\n padding: 0 !important;\n background: white !important;\n color-scheme: light !important;\n }\n }\n\n /* Screen: also apply isolation for print preview */\n @media screen {\n /* When this stylesheet is active, we're about to print */\n /* No screen-specific rules needed - isolation only applies to print */\n }\n `,n}(o,r);return document.head.appendChild(s),new Promise(t=>{const e=()=>{window.removeEventListener("afterprint",e),document.getElementById(i)?.remove(),t()};window.addEventListener("afterprint",e),window.print(),setTimeout(()=>{window.removeEventListener("afterprint",e),document.getElementById(i)?.remove(),t()},5e3)})}var r="__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(t=>t.split("").reverse().join("")),o=(new RegExp(`__(proto|defineGetter|defineSetter)|${r.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".split("|"))),s=/^on\w+$/i,a=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),d=/^\s*(javascript|vbscript|data|blob):/i;function l(t){if(!t||"string"!=typeof t)return"";if(-1===t.indexOf("<"))return t;const e=document.createElement("template");return e.innerHTML=t,function(t){const e=[],i=t.querySelectorAll("*");for(const n of i){const t=n.tagName.toLowerCase();if(o.has(t)){e.push(n);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===n.namespaceURI)&&Array.from(n.attributes).some(t=>s.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(n);continue}const i=[];for(const e of n.attributes){const t=e.name.toLowerCase();s.test(t)?i.push(e.name):(a.has(t)&&d.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&i.push(e.name)}i.forEach(t=>n.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content),e.innerHTML}var c={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var p=class{static dependencies;static manifest;aliases;version="3.0.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}get resolvedConfig(){return this.#t?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(t){if(0===t.length)return;const i={...this.userConfig},n={};for(const e of Object.keys(i))n[e]=this;for(const r of t){const t=r.userConfig;for(const[o,s]of Object.entries(t)){if(void 0===s)continue;if(!(o in i)){i[o]=s,n[o]=r;continue}if(i[o]===s)continue;const t=n[o]?.constructor.name??this.constructor.name,a=r.constructor.name,d=e("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${t} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(d)}}Object.assign(this.userConfig,i)}refreshUserConfigFrom(t){const e=this.userConfig,i={...t.userConfig};for(const n of Object.keys(e))delete e[n];Object.assign(e,i)}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const i=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}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.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...c,...t}}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;return!e||"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(e,10);if(!isNaN(i))return i}return 200}setIcon(t,e,i){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const n=this.#e(e,i);void 0!==n?"string"==typeof n?t.innerHTML=l(n):n instanceof HTMLElement&&(t.innerHTML="",t.appendChild(n.cloneNode(!0))):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const i=document.createElement("span");i.setAttribute("part","sort-indicator"),i.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(i,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(i,"sortNone"));const n=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return n?t.insertBefore(i,n):t.appendChild(i),i}warn(i,n){void 0!==n?console.warn(e(i,n,this.gridElement.id,this.name)):console.warn(`${t(this.gridElement.id,this.name)} ${i}`)}throwDiagnostic(t,i){throw new Error(e(t,i,this.gridElement.id,this.name))}},h={button:!1,orientation:"landscape",warnThreshold:500,maxRows:0,includeTitle:!0,includeTimestamp:!0,title:"",isolate:!1},m=class extends p{name="print";version="1.0.0";styles=".tbw-print-header,.tbw-print-footer{display:none}@media print{tbw-grid{--lightningcss-light:initial;--lightningcss-dark: ;color-scheme:light only;-webkit-print-color-adjust:exact;print-color-adjust:exact;border:none!important;border-radius:0!important;height:auto!important;overflow:visible!important}tbw-grid .tbw-grid-content,tbw-grid .tbw-scroll-area,tbw-grid .rows-body{height:auto!important;max-height:none!important;overflow:visible!important}tbw-grid .rows-container,tbw-grid .rows-viewport,tbw-grid .rows{height:auto!important;max-height:none!important;overflow:visible!important;transform:none!important}tbw-grid .rows-viewport .rows{position:static!important}tbw-grid .resize-handle,tbw-grid [part=sort-indicator],tbw-grid .tbw-filter-btn,tbw-grid .tool-panel,tbw-grid .tool-panel-content,tbw-grid .tbw-shell-header,tbw-grid .shell-toolbar,tbw-grid .tool-panel-toggle,tbw-grid [data-print-hide],tbw-grid .expander-cell,tbw-grid .tree-toggle,tbw-grid .context-menu,tbw-grid .faux-vscroll{display:none!important}tbw-grid .tbw-print-header{padding:var(--tbw-spacing-md,.5em) 0;margin-bottom:var(--tbw-spacing-md,.5em);border-bottom:2px solid var(--tbw-print-border,var(--tbw-color-border-strong));justify-content:space-between;align-items:baseline;font-family:inherit;display:flex}.tbw-print-header-title{font-size:1.25em;font-weight:700}.tbw-print-header-timestamp{font-size:var(--tbw-font-size-sm,.875em);color:var(--tbw-print-muted,var(--tbw-color-fg-muted))}tbw-grid .tbw-print-footer{margin-top:var(--tbw-spacing-md,.5em);padding-top:var(--tbw-spacing-md,.5em);border-top:1px solid var(--tbw-print-border,var(--tbw-color-border));font-size:var(--tbw-font-size-xs,.75em);color:var(--tbw-print-muted,var(--tbw-color-fg-muted));text-align:end;display:block}tbw-grid .data-grid-row{break-inside:avoid;page-break-inside:avoid}tbw-grid .cell{border:1px solid var(--tbw-print-cell-border,var(--tbw-color-border))!important}tbw-grid .header-row,tbw-grid .data-grid-row{padding-inline-end:1px}tbw-grid .data-grid-row:hover,tbw-grid .cell:hover{background:inherit!important}@page{margin:1cm}}";#i=!1;#n=null;#r=null;#o=null;#s=null;#a=null;#d=null;get#l(){return this.grid}isPrinting(){return this.#i}async print(t){if(this.#i)return void this.warn("TBW090","Print already in progress");const i=this.gridElement;if(!i)return void this.warn("TBW091","Grid not available");const n={...h,...this.config,...t},r=this.rows.length;let o=r,s=!1;if(n.warnThreshold>0&&r>n.warnThreshold){const t=n.maxRows>0?`\n\nNote: Output will be limited to ${n.maxRows.toLocaleString()} rows.`:"";if(!confirm(`This grid has ${r.toLocaleString()} rows. Printing large datasets may cause performance issues or browser slowdowns.${t}\n\nClick OK to continue, or Cancel to abort.`))return}n.maxRows>0&&r>n.maxRows&&(o=n.maxRows,s=!0),this.#i=!0;const a=performance.now();this.emit("print-start",{rowCount:o,limitApplied:s,originalRowCount:r});try{const t=this.#l;this.#r={bypassThreshold:t._virtualization?.bypassThreshold??24},this.#c(),s&&(this.#o=this.sourceRows,this.grid.rows=this.sourceRows.slice(0,o),await new Promise(t=>setTimeout(t,50))),(n.includeTitle||n.includeTimestamp)&&this.#p(n),await this.#h(),await new Promise(t=>requestAnimationFrame(t)),await new Promise(t=>requestAnimationFrame(t)),i.classList.add(`print-${n.orientation}`),await new Promise(t=>requestAnimationFrame(t)),await new Promise(t=>requestAnimationFrame(t)),n.isolate?await this.#m(n):await this.#u(),this.emit("print-complete",{success:!0,rowCount:o,duration:Math.round(performance.now()-a)})}catch(m){d="TBW092",l=`Print failed: ${m}`,c=this.gridElement?.id,p=this.name,console.error(e(d,l,c,p)),this.emit("print-complete",{success:!1,rowCount:0,duration:Math.round(performance.now()-a)})}finally{this.#g(),this.#i=!1}var d,l,c,p}#p(t){const e=this.gridElement;if(e){if(this.#s=document.createElement("div"),this.#s.className="tbw-print-header",t.includeTitle){const e=t.title||this.grid.effectiveConfig?.shell?.header?.title||"Grid Data",i=document.createElement("div");i.className="tbw-print-header-title",i.textContent=e,this.#s.appendChild(i)}if(t.includeTimestamp){const t=document.createElement("div");t.className="tbw-print-header-timestamp",t.textContent=`Printed: ${/* @__PURE__ */(new Date).toLocaleString()}`,this.#s.appendChild(t)}e.insertBefore(this.#s,e.firstChild),this.#a=document.createElement("div"),this.#a.className="tbw-print-footer",this.#a.textContent=`Page generated from ${window.location.hostname}`,e.appendChild(this.#a)}}async#h(){const t=this.#l;if(!t._virtualization)return;const e=this.rows.length;t._virtualization.bypassThreshold=e+100,t.refreshVirtualWindow(!0),await new Promise(t=>setTimeout(t,100))}async#u(){return new Promise(t=>{const e=()=>{window.removeEventListener("afterprint",e),t()};window.addEventListener("afterprint",e),window.print(),setTimeout(()=>{"undefined"!=typeof window&&window.removeEventListener("afterprint",e),t()},1e3)})}async#m(t){const e=this.gridElement;e&&await n(e,{orientation:t.orientation})}#c(){const t=this.columns;if(t){this.#n=/* @__PURE__ */new Map;for(const e of t)e.field&&(!0===e.printHidden||!0===e.utility&&!1!==e.printHidden)&&(this.#n.set(e.field,!e.hidden),this.grid.setColumnVisible(e.field,!1))}}#w(){if(this.#n){for(const[t,e]of this.#n)this.grid.setColumnVisible(t,e);this.#n=null}}#g(){const t=this.gridElement;if(!t)return;this.#w(),t.classList.remove("print-portrait","print-landscape"),null!==this.#d&&(t.style.transform="",t.style.transformOrigin="",t.style.width="",this.#d=null),this.#s&&(this.#s.remove(),this.#s=null),this.#a&&(this.#a.remove(),this.#a=null);const e=this.#l;this.#r&&e._virtualization&&(e._virtualization.bypassThreshold=this.#r.bypassThreshold,e.refreshVirtualWindow(!0),this.#r=null),null!==this.#o&&(this.grid.rows=this.#o,this.#o=null)}afterRender(){this.config?.button&&!this.#b&&(this.#f(),this.#b=!0)}#b=!1;#f(){this.#l.registerToolbarContent?.({id:"print-button",order:900,render:t=>{const e=document.createElement("button");e.className="tbw-toolbar-btn tbw-print-btn",e.title="Print grid",e.type="button",this.setIcon(e,"print"),e.addEventListener("click",()=>{this.print()},{signal:this.disconnectSignal}),t.appendChild(e)}})}};export{m as PrintPlugin,n as printGridIsolated};
|
|
1
|
+
function t(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function e(e,i,n,r){return`${t(n,r)} ${e}: ${i}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(e)}`}var i="tbw-print-isolation-style";async function n(t,n={}){const{orientation:r="landscape"}=n,o=t.id;document.querySelectorAll(`#${CSS.escape(o)}`).length>1&&function(t,i,n,r){console.warn(e(t,i,n,r))}("TBW093",`Multiple elements found with id="${o}". Print isolation may not work correctly. Ensure each grid has a unique ID.`,o,"print"),document.getElementById(i)?.remove();const s=function(t,e){const n=document.createElement("style");return n.id=i,n.textContent=`\n /* Print isolation: hide everything except the target grid */\n @media print {\n /* Hide all body children by default */\n body > *:not(#${t}) {\n display: none !important;\n }\n\n /* But show the grid and ensure it's not hidden by ancestor rules */\n #${t} {\n display: block !important;\n position: static !important;\n visibility: visible !important;\n opacity: 1 !important;\n overflow: visible !important;\n height: auto !important;\n width: 100% !important;\n max-height: none !important;\n margin: 0 !important;\n padding: 0 !important;\n transform: none !important;\n }\n\n /* If grid is nested, we need to show its ancestors too */\n #${t},\n #${t} * {\n visibility: visible !important;\n }\n\n /* Walk up the DOM and show all ancestors of the grid */\n body *:has(> #${t}),\n body *:has(#${t}) {\n display: block !important;\n visibility: visible !important;\n opacity: 1 !important;\n overflow: visible !important;\n height: auto !important;\n position: static !important;\n transform: none !important;\n background: transparent !important;\n border: none !important;\n padding: 0 !important;\n margin: 0 !important;\n }\n\n /* Hide siblings of ancestors (everything that's not in the path to the grid) */\n body *:has(#${t}) > *:not(:has(#${t})):not(#${t}) {\n display: none !important;\n }\n\n /* Page settings */\n @page {\n size: ${e};\n margin: 1cm;\n }\n\n /* Ensure proper print styling */\n body {\n margin: 0 !important;\n padding: 0 !important;\n background: white !important;\n color-scheme: light !important;\n }\n }\n\n /* Screen: also apply isolation for print preview */\n @media screen {\n /* When this stylesheet is active, we're about to print */\n /* No screen-specific rules needed - isolation only applies to print */\n }\n `,n}(o,r);return document.head.appendChild(s),new Promise(t=>{const e=()=>{window.removeEventListener("afterprint",e),document.getElementById(i)?.remove(),t()};window.addEventListener("afterprint",e),window.print(),setTimeout(()=>{window.removeEventListener("afterprint",e),document.getElementById(i)?.remove(),t()},5e3)})}var r="__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(t=>t.split("").reverse().join("")),o=(new RegExp(`__(proto|defineGetter|defineSetter)|${r.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".split("|"))),s=/^on\w+$/i,a=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),d=/^\s*(javascript|vbscript|data|blob):/i;function l(t){if(!t||"string"!=typeof t)return"";if(-1===t.indexOf("<"))return t;const e=document.createElement("template");return e.innerHTML=t,function(t){const e=[],i=t.querySelectorAll("*");for(const n of i){const t=n.tagName.toLowerCase();if(o.has(t)){e.push(n);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===n.namespaceURI)&&Array.from(n.attributes).some(t=>s.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(n);continue}const i=[];for(const e of n.attributes){const t=e.name.toLowerCase();s.test(t)?i.push(e.name):(a.has(t)&&d.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&i.push(e.name)}i.forEach(t=>n.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content),e.innerHTML}var c={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var p=class{static dependencies;static manifest;aliases;version="3.0.1";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}get resolvedConfig(){return this.#t?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(t){if(0===t.length)return;const i={...this.userConfig},n={};for(const e of Object.keys(i))n[e]=this;for(const r of t){const t=r.userConfig;for(const[o,s]of Object.entries(t)){if(void 0===s)continue;if(!(o in i)){i[o]=s,n[o]=r;continue}if(i[o]===s)continue;const t=n[o]?.constructor.name??this.constructor.name,a=r.constructor.name,d=e("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${t} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(d)}}Object.assign(this.userConfig,i)}refreshUserConfigFrom(t){const e=this.userConfig,i={...t.userConfig};for(const n of Object.keys(e))delete e[n];Object.assign(e,i)}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const i=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}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.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...c,...t}}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;return!e||"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(e,10);if(!isNaN(i))return i}return 200}setIcon(t,e,i){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const n=this.#e(e,i);void 0!==n?"string"==typeof n?t.innerHTML=l(n):n instanceof HTMLElement&&(t.innerHTML="",t.appendChild(n.cloneNode(!0))):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const i=document.createElement("span");i.setAttribute("part","sort-indicator"),i.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(i,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(i,"sortNone"));const n=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return n?t.insertBefore(i,n):t.appendChild(i),i}warn(i,n){void 0!==n?console.warn(e(i,n,this.gridElement.id,this.name)):console.warn(`${t(this.gridElement.id,this.name)} ${i}`)}throwDiagnostic(t,i){throw new Error(e(t,i,this.gridElement.id,this.name))}},m={button:!1,orientation:"landscape",warnThreshold:500,maxRows:0,includeTitle:!0,includeTimestamp:!0,title:"",isolate:!1},h=class extends p{name="print";version="1.0.0";styles=".tbw-print-header,.tbw-print-footer{display:none}@media print{tbw-grid{color-scheme:light only;-webkit-print-color-adjust:exact;print-color-adjust:exact;border:none!important;border-radius:0!important;height:auto!important;overflow:visible!important}tbw-grid .tbw-grid-content,tbw-grid .tbw-scroll-area,tbw-grid .rows-body{height:auto!important;max-height:none!important;overflow:visible!important}tbw-grid .rows-container,tbw-grid .rows-viewport,tbw-grid .rows{height:auto!important;max-height:none!important;overflow:visible!important;transform:none!important}tbw-grid .rows-viewport .rows{position:static!important}tbw-grid .resize-handle,tbw-grid [part=sort-indicator],tbw-grid .tbw-filter-btn,tbw-grid .tool-panel,tbw-grid .tool-panel-content,tbw-grid .tbw-shell-header,tbw-grid .shell-toolbar,tbw-grid .tool-panel-toggle,tbw-grid [data-print-hide],tbw-grid .expander-cell,tbw-grid .tree-toggle,tbw-grid .context-menu,tbw-grid .faux-vscroll{display:none!important}tbw-grid .tbw-print-header{padding:var(--tbw-spacing-md,.5em) 0;margin-bottom:var(--tbw-spacing-md,.5em);border-bottom:2px solid var(--tbw-print-border,var(--tbw-color-border-strong));justify-content:space-between;align-items:baseline;font-family:inherit;display:flex}.tbw-print-header-title{font-size:1.25em;font-weight:700}.tbw-print-header-timestamp{font-size:var(--tbw-font-size-sm,.875em);color:var(--tbw-print-muted,var(--tbw-color-fg-muted))}tbw-grid .tbw-print-footer{margin-top:var(--tbw-spacing-md,.5em);padding-top:var(--tbw-spacing-md,.5em);border-top:1px solid var(--tbw-print-border,var(--tbw-color-border));font-size:var(--tbw-font-size-xs,.75em);color:var(--tbw-print-muted,var(--tbw-color-fg-muted));text-align:end;display:block}tbw-grid .data-grid-row{break-inside:avoid;page-break-inside:avoid}tbw-grid .cell{border:1px solid var(--tbw-print-cell-border,var(--tbw-color-border))!important}tbw-grid .header-row,tbw-grid .data-grid-row{padding-inline-end:1px}tbw-grid .data-grid-row:hover,tbw-grid .cell:hover{background:inherit!important}@page{margin:1cm}}";#i=!1;#n=null;#r=null;#o=null;#s=null;#a=null;#d=null;get#l(){return this.grid}isPrinting(){return this.#i}async print(t){if(this.#i)return void this.warn("TBW090","Print already in progress");const i=this.gridElement;if(!i)return void this.warn("TBW091","Grid not available");const n={...m,...this.config,...t},r=this.rows.length;let o=r,s=!1;if(n.warnThreshold>0&&r>n.warnThreshold){const t=n.maxRows>0?`\n\nNote: Output will be limited to ${n.maxRows.toLocaleString()} rows.`:"";if(!confirm(`This grid has ${r.toLocaleString()} rows. Printing large datasets may cause performance issues or browser slowdowns.${t}\n\nClick OK to continue, or Cancel to abort.`))return}n.maxRows>0&&r>n.maxRows&&(o=n.maxRows,s=!0),this.#i=!0;const a=performance.now();this.emit("print-start",{rowCount:o,limitApplied:s,originalRowCount:r});try{const t=this.#l;this.#r={bypassThreshold:t._virtualization?.bypassThreshold??24},this.#c(),s&&(this.#o=this.sourceRows,this.grid.rows=this.sourceRows.slice(0,o),await new Promise(t=>setTimeout(t,50))),(n.includeTitle||n.includeTimestamp)&&this.#p(n),await this.#m(),await new Promise(t=>requestAnimationFrame(t)),await new Promise(t=>requestAnimationFrame(t)),i.classList.add(`print-${n.orientation}`),await new Promise(t=>requestAnimationFrame(t)),await new Promise(t=>requestAnimationFrame(t)),n.isolate?await this.#h(n):await this.#u(),this.emit("print-complete",{success:!0,rowCount:o,duration:Math.round(performance.now()-a)})}catch(h){d="TBW092",l=`Print failed: ${h}`,c=this.gridElement?.id,p=this.name,console.error(e(d,l,c,p)),this.emit("print-complete",{success:!1,rowCount:0,duration:Math.round(performance.now()-a)})}finally{this.#g(),this.#i=!1}var d,l,c,p}#p(t){const e=this.gridElement;if(e){if(this.#s=document.createElement("div"),this.#s.className="tbw-print-header",t.includeTitle){const e=t.title||this.grid.effectiveConfig?.shell?.header?.title||"Grid Data",i=document.createElement("div");i.className="tbw-print-header-title",i.textContent=e,this.#s.appendChild(i)}if(t.includeTimestamp){const t=document.createElement("div");t.className="tbw-print-header-timestamp",t.textContent=`Printed: ${/* @__PURE__ */(new Date).toLocaleString()}`,this.#s.appendChild(t)}e.insertBefore(this.#s,e.firstChild),this.#a=document.createElement("div"),this.#a.className="tbw-print-footer",this.#a.textContent=`Page generated from ${window.location.hostname}`,e.appendChild(this.#a)}}async#m(){const t=this.#l;if(!t._virtualization)return;const e=this.rows.length;t._virtualization.bypassThreshold=e+100,t.refreshVirtualWindow(!0),await new Promise(t=>setTimeout(t,100))}async#u(){return new Promise(t=>{const e=()=>{window.removeEventListener("afterprint",e),t()};window.addEventListener("afterprint",e),window.print(),setTimeout(()=>{"undefined"!=typeof window&&window.removeEventListener("afterprint",e),t()},1e3)})}async#h(t){const e=this.gridElement;e&&await n(e,{orientation:t.orientation})}#c(){const t=this.columns;if(t){this.#n=/* @__PURE__ */new Map;for(const e of t)e.field&&(!0===e.printHidden||!0===e.utility&&!1!==e.printHidden)&&(this.#n.set(e.field,!e.hidden),this.grid.setColumnVisible(e.field,!1))}}#w(){if(this.#n){for(const[t,e]of this.#n)this.grid.setColumnVisible(t,e);this.#n=null}}#g(){const t=this.gridElement;if(!t)return;this.#w(),t.classList.remove("print-portrait","print-landscape"),null!==this.#d&&(t.style.transform="",t.style.transformOrigin="",t.style.width="",this.#d=null),this.#s&&(this.#s.remove(),this.#s=null),this.#a&&(this.#a.remove(),this.#a=null);const e=this.#l;this.#r&&e._virtualization&&(e._virtualization.bypassThreshold=this.#r.bypassThreshold,e.refreshVirtualWindow(!0),this.#r=null),null!==this.#o&&(this.grid.rows=this.#o,this.#o=null)}afterRender(){this.config?.button&&!this.#b&&(this.#f(),this.#b=!0)}#b=!1;#f(){this.#l.registerToolbarContent?.({id:"print-button",order:900,render:t=>{const e=document.createElement("button");e.className="tbw-toolbar-btn tbw-print-btn",e.title="Print grid",e.type="button",this.setIcon(e,"print"),e.addEventListener("click",()=>{this.print()},{signal:this.disconnectSignal}),t.appendChild(e)}})}};export{h as PrintPlugin,n as printGridIsolated};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|