@toolbox-web/grid 2.17.0 → 2.17.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/all.js +1 -1
- package/all.js.map +1 -1
- package/index.js +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/export/index.js +1 -1
- package/lib/plugins/filtering/index.js +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/reorder-columns/index.js +1 -1
- package/lib/plugins/reorder-rows/index.js +1 -1
- package/lib/plugins/responsive/index.js +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/StickyRowsPlugin.d.ts +23 -0
- package/lib/plugins/sticky-rows/index.js +1 -1
- package/lib/plugins/sticky-rows/index.js.map +1 -1
- package/lib/plugins/tooltip/index.js +1 -1
- package/lib/plugins/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/plugins/selection.umd.js +1 -1
- package/umd/plugins/selection.umd.js.map +1 -1
- package/umd/plugins/sticky-rows.umd.js +1 -1
- package/umd/plugins/sticky-rows.umd.js.map +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,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 r(e,t){if(!e)return;const r="effectiveConfig"in e?e.effectiveConfig:void 0;if(!1===r?.a11y?.announcements)return;const o=e.querySelector?.(".tbw-sr-only");o&&(o.textContent="",requestAnimationFrame(()=>{o.textContent=t}))}function o(t,r,...o){const n=t&&"effectiveConfig"in t?t.effectiveConfig:void 0,i=n?.a11y?.messages?.[r];return i?i(...o):e[r](...o)}function n(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function i(e,t,r,o){return`${n(r,o)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}const 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(""));new RegExp(`__(proto|defineGetter|defineSetter)|${s.slice(3).join("|")}|this\\b`);const l=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("|")),a=/^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=[],r=e.querySelectorAll("*");for(const o of r){const e=o.tagName.toLowerCase();if(l.has(e)){t.push(o);continue}if("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI){if(Array.from(o.attributes).some(e=>a.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(o);continue}}const r=[];for(const t of o.attributes){const e=t.name.toLowerCase();a.test(e)?r.push(t.name):(d.has(e)&&c.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name)}r.forEach(e=>o.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}class h{static dependencies;static manifest;aliases;version="2.17.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 o of Object.keys(t))r[o]=this;for(const o of e){const e=o.userConfig;for(const[n,s]of Object.entries(e)){if(void 0===s)continue;if(!(n in t)){t[n]=s,r[n]=o;continue}if(t[n]===s)continue;const e=r[n]?.constructor.name??this.constructor.name,l=o.constructor.name,a=i("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${e} and ${l}. 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;for(const r of Object.keys(t))delete t[r];Object.assign(t,e.userConfig)}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{...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;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),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 o=this.#t(t,r);void 0!==o?"string"==typeof o?e.innerHTML=u(o):o instanceof HTMLElement&&(e.innerHTML="",e.appendChild(o.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 o=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return o?e.insertBefore(r,o):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(i(e,t,this.gridElement.id,this.name)):console.warn(`${n(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(i(e,t,this.gridElement.id,this.name))}}const f=/* @__PURE__ */new WeakMap;const g=new Intl.Collator(void 0,{sensitivity:"variant"});function m(e,t,r){if(!t.length)return;const o=t.map(e=>{const t=r.find(t=>t.field===e.field),o=t?.sortComparator??p,n=e.field,i=t?.valueAccessor?e=>function(e,t,r=-1){if(!t.valueAccessor)return e?.[t.field];if("object"!=typeof e||null===e)return t.valueAccessor({row:e,column:t,rowIndex:r});const o=e,n=t.field;let i=f.get(o);if(i){const e=i.get(n);if(void 0!==e)return e.v}else i=/* @__PURE__ */new Map,f.set(o,i);const s=t.valueAccessor({row:e,column:t,rowIndex:r});return i.set(n,{v:s}),s}(e,t):e=>e[n];return{field:n,asc:"asc"===e.direction,comparator:o,getValue:i,pinPlaceholders:!t?.sortComparator}}),n=o.some(e=>e.pinPlaceholders)&&function(e){for(let t=0;t<e.length;t++)if(!0===e[t]?.__loading)return!0;return!1}(e),i=e.length,s=o.length,l=new Array(i*s);for(let u=0;u<i;u++){const t=e[u],r=u*s;for(let e=0;e<s;e++)l[r+e]=o[e].getValue(t)}const a=i<=4294967295?new Uint32Array(i):new Array(i);for(let u=0;u<i;u++)a[u]=u;const d=(t,r)=>{if(n){const o=function(e,t){const r=!0===e?.__loading;return r===(t?.__loading===true)?0:r?1:-1}(e[t],e[r]);if(0!==o)return o}const i=t*s,a=r*s;for(let n=0;n<s;n++){const s=o[n],d=s.comparator(l[i+n],l[a+n],e[t],e[r]);if(0!==d)return s.asc?d:-d}return 0};Uint32Array,a.sort(d);const c=e.slice();for(let u=0;u<i;u++)e[u]=c[a[u]]}function p(e,t){return null==e&&null==t?0:null==e?1:null==t?-1:"number"==typeof e&&"number"==typeof t?e-t:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():"boolean"==typeof e&&"boolean"==typeof t?e===t?0:e?-1:1:g.compare("string"==typeof e?e:String(e),"string"==typeof t?t:String(t))}function b(e,t){const r=e.findIndex(e=>e.field===t);return r>=0?r+1:void 0}function C(e,t){return e.find(e=>e.field===t)?.direction}class S extends h{static manifest={queries:[{type:"sort:get-model",description:"Returns the current multi-sort model as SortModel[]"},{type:"sort:set-model",description:"Sets the multi-sort model from context (SortModel[])"}]};name="multiSort";styles='@layer tbw-plugins{.header-cell[data-sort=asc]:after{content:"↑";margin-left:var(--tbw-spacing-xs, .25em);opacity:.8}.header-cell[data-sort=desc]:after{content:"↓";margin-left:var(--tbw-spacing-xs, .25em);opacity:.8}.sort-indicator{margin-left:var(--tbw-spacing-xs, .25em);opacity:.8}.sort-index{font-size:var(--tbw-font-size-2xs, .7em);background:var(--tbw-multi-sort-badge-bg, var(--tbw-color-panel-bg));color:var(--tbw-multi-sort-badge-color, var(--tbw-color-fg));border-radius:50%;width:var(--tbw-multi-sort-badge-size, 1em);height:var(--tbw-multi-sort-badge-size, 1em);display:inline-flex;align-items:center;justify-content:center;margin-left:var(--tbw-spacing-xs, .125em);font-weight:600}}';get defaultConfig(){return{maxSortColumns:3,showSortIndex:!0}}sortModel=[];cachedSortResult=null;#r=!1;#o=[];get#n(){return this.grid}clearCoreSortState(){this.#n._sortState=null}#i(e){const t=this.grid?.query?.("grouping:get-grouped-fields",null);if(!Array.isArray(t)||0===t.length)return e;const r=t[0];if(!Array.isArray(r)||0===r.length)return e;const o=new Set(r),n=e.filter(e=>!o.has(e.field));return n.length===e.length?e:n}detach(){this.sortModel=[],this.cachedSortResult=null}handleQuery(e){switch(e.type){case"sort:get-model":return[...this.sortModel];case"sort:set-model":{const t=e.context;return!!Array.isArray(t)&&(this.sortModel=[...t],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),!0)}default:return}}processRows(e){if(0===this.sortModel.length)return this.cachedSortResult=null,[...e];const t=this.#n;if(!t._isGridEditMode&&"number"==typeof t._activeEditRows&&-1!==t._activeEditRows&&this.cachedSortResult&&this.cachedSortResult.length===e.length)return[...this.cachedSortResult];const r=this.#i(this.sortModel),o=e;return r.length>0&&m(o,r,this.columns),this.cachedSortResult=o,o}onHeaderClick(e){const t=this.columns.find(t=>t.field===e.field);if(!t?.sortable)return!1;const n=e.originalEvent.shiftKey,i=this.config.maxSortColumns??3;if(this.sortModel=function(e,t,r,o){const n=e.find(e=>e.field===t);return r?n?"asc"===n.direction?e.map(e=>e.field===t?{...e,direction:"desc"}:e):e.filter(e=>e.field!==t):e.length<o?[...e,{field:t,direction:"asc"}]:e:"asc"===n?.direction?[{field:t,direction:"desc"}]:"desc"===n?.direction?[]:[{field:t,direction:"asc"}]}(this.sortModel,e.field,n,i),this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),this.grid?.requestStateChange?.(),this.sortModel.length>0){const e=this.sortModel.map(e=>{const t=this.columns.find(t=>t.field===e.field);return`${t?.header??e.field} ${"asc"===e.direction?"ascending":"descending"}`});r(this.gridElement,o(this.gridElement,"sortApplied",e.join(", then "),""))}else r(this.gridElement,o(this.gridElement,"sortCleared"));return!0}afterRender(){const e=this.gridElement;if(!e)return;const t=!1!==this.config.showSortIndex;e.querySelectorAll(".header-row .cell[data-field]").forEach(e=>{const r=e.getAttribute("data-field");if(!r)return;const o=b(this.sortModel,r),n=C(this.sortModel,r);if(e.querySelector(".sort-index")?.remove(),n){const r=this.updateSortIndicator(e,n);if(t&&this.sortModel.length>1&&void 0!==o){const t=document.createElement("span");t.className="sort-index",t.textContent=String(o),r.nextSibling?e.insertBefore(t,r.nextSibling):e.appendChild(t)}}else e.classList.contains("sortable")&&this.updateSortIndicator(e,null)})}getSortModel(){return[...this.sortModel]}setSortModel(e){if(this.sortModel=[...e],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...e]}),this.requestRender(),this.grid?.requestStateChange?.(),e.length>0){const t=e.map(e=>{const t=this.columns.find(t=>t.field===e.field);return`${t?.header??e.field} ${"asc"===e.direction?"ascending":"descending"}`});r(this.gridElement,o(this.gridElement,"sortApplied",t.join(", then "),""))}}clearSort(){this.sortModel=[],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[]}),this.requestRender(),this.grid?.requestStateChange?.(),r(this.gridElement,o(this.gridElement,"sortCleared"))}getSortIndex(e){return b(this.sortModel,e)}getSortDirection(e){return C(this.sortModel,e)}getColumnState(e){const t=this.sortModel.findIndex(t=>t.field===e);if(-1===t)return;return{sort:{direction:this.sortModel[t].direction,priority:t}}}applyColumnState(e,t){if(this.#r||(this.#o=[...this.sortModel]),t.sort){const r=this.sortModel.findIndex(t=>t.field===e),o={field:e,direction:t.sort.direction};-1!==r?this.sortModel[r]=o:this.sortModel.splice(t.sort.priority,0,o)}else this.sortModel=this.sortModel.filter(t=>t.field!==e);this.clearCoreSortState(),this.#r||(this.#r=!0,queueMicrotask(()=>{this.#r=!1;const e=this.#o;this.#o=[],function(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r].field!==t[r].field||e[r].direction!==t[r].direction)return!1;return!0}(e,this.sortModel)||(this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender())}))}}export{S as MultiSortPlugin};
|
|
1
|
+
const e={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,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 r(e,t){if(!e)return;const r="effectiveConfig"in e?e.effectiveConfig:void 0;if(!1===r?.a11y?.announcements)return;const o=e.querySelector?.(".tbw-sr-only");o&&(o.textContent="",requestAnimationFrame(()=>{o.textContent=t}))}function o(t,r,...o){const n=t&&"effectiveConfig"in t?t.effectiveConfig:void 0,i=n?.a11y?.messages?.[r];return i?i(...o):e[r](...o)}function n(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function i(e,t,r,o){return`${n(r,o)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}const 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(""));new RegExp(`__(proto|defineGetter|defineSetter)|${s.slice(3).join("|")}|this\\b`);const l=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("|")),a=/^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=[],r=e.querySelectorAll("*");for(const o of r){const e=o.tagName.toLowerCase();if(l.has(e)){t.push(o);continue}if("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI){if(Array.from(o.attributes).some(e=>a.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(o);continue}}const r=[];for(const t of o.attributes){const e=t.name.toLowerCase();a.test(e)?r.push(t.name):(d.has(e)&&c.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name)}r.forEach(e=>o.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}class h{static dependencies;static manifest;aliases;version="2.17.2";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 o of Object.keys(t))r[o]=this;for(const o of e){const e=o.userConfig;for(const[n,s]of Object.entries(e)){if(void 0===s)continue;if(!(n in t)){t[n]=s,r[n]=o;continue}if(t[n]===s)continue;const e=r[n]?.constructor.name??this.constructor.name,l=o.constructor.name,a=i("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${e} and ${l}. 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;for(const r of Object.keys(t))delete t[r];Object.assign(t,e.userConfig)}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{...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;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),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 o=this.#t(t,r);void 0!==o?"string"==typeof o?e.innerHTML=u(o):o instanceof HTMLElement&&(e.innerHTML="",e.appendChild(o.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 o=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return o?e.insertBefore(r,o):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(i(e,t,this.gridElement.id,this.name)):console.warn(`${n(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(i(e,t,this.gridElement.id,this.name))}}const f=/* @__PURE__ */new WeakMap;const g=new Intl.Collator(void 0,{sensitivity:"variant"});function m(e,t,r){if(!t.length)return;const o=t.map(e=>{const t=r.find(t=>t.field===e.field),o=t?.sortComparator??p,n=e.field,i=t?.valueAccessor?e=>function(e,t,r=-1){if(!t.valueAccessor)return e?.[t.field];if("object"!=typeof e||null===e)return t.valueAccessor({row:e,column:t,rowIndex:r});const o=e,n=t.field;let i=f.get(o);if(i){const e=i.get(n);if(void 0!==e)return e.v}else i=/* @__PURE__ */new Map,f.set(o,i);const s=t.valueAccessor({row:e,column:t,rowIndex:r});return i.set(n,{v:s}),s}(e,t):e=>e[n];return{field:n,asc:"asc"===e.direction,comparator:o,getValue:i,pinPlaceholders:!t?.sortComparator}}),n=o.some(e=>e.pinPlaceholders)&&function(e){for(let t=0;t<e.length;t++)if(!0===e[t]?.__loading)return!0;return!1}(e),i=e.length,s=o.length,l=new Array(i*s);for(let u=0;u<i;u++){const t=e[u],r=u*s;for(let e=0;e<s;e++)l[r+e]=o[e].getValue(t)}const a=i<=4294967295?new Uint32Array(i):new Array(i);for(let u=0;u<i;u++)a[u]=u;const d=(t,r)=>{if(n){const o=function(e,t){const r=!0===e?.__loading;return r===(t?.__loading===true)?0:r?1:-1}(e[t],e[r]);if(0!==o)return o}const i=t*s,a=r*s;for(let n=0;n<s;n++){const s=o[n],d=s.comparator(l[i+n],l[a+n],e[t],e[r]);if(0!==d)return s.asc?d:-d}return 0};Uint32Array,a.sort(d);const c=e.slice();for(let u=0;u<i;u++)e[u]=c[a[u]]}function p(e,t){return null==e&&null==t?0:null==e?1:null==t?-1:"number"==typeof e&&"number"==typeof t?e-t:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():"boolean"==typeof e&&"boolean"==typeof t?e===t?0:e?-1:1:g.compare("string"==typeof e?e:String(e),"string"==typeof t?t:String(t))}function b(e,t){const r=e.findIndex(e=>e.field===t);return r>=0?r+1:void 0}function C(e,t){return e.find(e=>e.field===t)?.direction}class S extends h{static manifest={queries:[{type:"sort:get-model",description:"Returns the current multi-sort model as SortModel[]"},{type:"sort:set-model",description:"Sets the multi-sort model from context (SortModel[])"}]};name="multiSort";styles='@layer tbw-plugins{.header-cell[data-sort=asc]:after{content:"↑";margin-left:var(--tbw-spacing-xs, .25em);opacity:.8}.header-cell[data-sort=desc]:after{content:"↓";margin-left:var(--tbw-spacing-xs, .25em);opacity:.8}.sort-indicator{margin-left:var(--tbw-spacing-xs, .25em);opacity:.8}.sort-index{font-size:var(--tbw-font-size-2xs, .7em);background:var(--tbw-multi-sort-badge-bg, var(--tbw-color-panel-bg));color:var(--tbw-multi-sort-badge-color, var(--tbw-color-fg));border-radius:50%;width:var(--tbw-multi-sort-badge-size, 1em);height:var(--tbw-multi-sort-badge-size, 1em);display:inline-flex;align-items:center;justify-content:center;margin-left:var(--tbw-spacing-xs, .125em);font-weight:600}}';get defaultConfig(){return{maxSortColumns:3,showSortIndex:!0}}sortModel=[];cachedSortResult=null;#r=!1;#o=[];get#n(){return this.grid}clearCoreSortState(){this.#n._sortState=null}#i(e){const t=this.grid?.query?.("grouping:get-grouped-fields",null);if(!Array.isArray(t)||0===t.length)return e;const r=t[0];if(!Array.isArray(r)||0===r.length)return e;const o=new Set(r),n=e.filter(e=>!o.has(e.field));return n.length===e.length?e:n}detach(){this.sortModel=[],this.cachedSortResult=null}handleQuery(e){switch(e.type){case"sort:get-model":return[...this.sortModel];case"sort:set-model":{const t=e.context;return!!Array.isArray(t)&&(this.sortModel=[...t],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),!0)}default:return}}processRows(e){if(0===this.sortModel.length)return this.cachedSortResult=null,[...e];const t=this.#n;if(!t._isGridEditMode&&"number"==typeof t._activeEditRows&&-1!==t._activeEditRows&&this.cachedSortResult&&this.cachedSortResult.length===e.length)return[...this.cachedSortResult];const r=this.#i(this.sortModel),o=e;return r.length>0&&m(o,r,this.columns),this.cachedSortResult=o,o}onHeaderClick(e){const t=this.columns.find(t=>t.field===e.field);if(!t?.sortable)return!1;const n=e.originalEvent.shiftKey,i=this.config.maxSortColumns??3;if(this.sortModel=function(e,t,r,o){const n=e.find(e=>e.field===t);return r?n?"asc"===n.direction?e.map(e=>e.field===t?{...e,direction:"desc"}:e):e.filter(e=>e.field!==t):e.length<o?[...e,{field:t,direction:"asc"}]:e:"asc"===n?.direction?[{field:t,direction:"desc"}]:"desc"===n?.direction?[]:[{field:t,direction:"asc"}]}(this.sortModel,e.field,n,i),this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),this.grid?.requestStateChange?.(),this.sortModel.length>0){const e=this.sortModel.map(e=>{const t=this.columns.find(t=>t.field===e.field);return`${t?.header??e.field} ${"asc"===e.direction?"ascending":"descending"}`});r(this.gridElement,o(this.gridElement,"sortApplied",e.join(", then "),""))}else r(this.gridElement,o(this.gridElement,"sortCleared"));return!0}afterRender(){const e=this.gridElement;if(!e)return;const t=!1!==this.config.showSortIndex;e.querySelectorAll(".header-row .cell[data-field]").forEach(e=>{const r=e.getAttribute("data-field");if(!r)return;const o=b(this.sortModel,r),n=C(this.sortModel,r);if(e.querySelector(".sort-index")?.remove(),n){const r=this.updateSortIndicator(e,n);if(t&&this.sortModel.length>1&&void 0!==o){const t=document.createElement("span");t.className="sort-index",t.textContent=String(o),r.nextSibling?e.insertBefore(t,r.nextSibling):e.appendChild(t)}}else e.classList.contains("sortable")&&this.updateSortIndicator(e,null)})}getSortModel(){return[...this.sortModel]}setSortModel(e){if(this.sortModel=[...e],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...e]}),this.requestRender(),this.grid?.requestStateChange?.(),e.length>0){const t=e.map(e=>{const t=this.columns.find(t=>t.field===e.field);return`${t?.header??e.field} ${"asc"===e.direction?"ascending":"descending"}`});r(this.gridElement,o(this.gridElement,"sortApplied",t.join(", then "),""))}}clearSort(){this.sortModel=[],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[]}),this.requestRender(),this.grid?.requestStateChange?.(),r(this.gridElement,o(this.gridElement,"sortCleared"))}getSortIndex(e){return b(this.sortModel,e)}getSortDirection(e){return C(this.sortModel,e)}getColumnState(e){const t=this.sortModel.findIndex(t=>t.field===e);if(-1===t)return;return{sort:{direction:this.sortModel[t].direction,priority:t}}}applyColumnState(e,t){if(this.#r||(this.#o=[...this.sortModel]),t.sort){const r=this.sortModel.findIndex(t=>t.field===e),o={field:e,direction:t.sort.direction};-1!==r?this.sortModel[r]=o:this.sortModel.splice(t.sort.priority,0,o)}else this.sortModel=this.sortModel.filter(t=>t.field!==e);this.clearCoreSortState(),this.#r||(this.#r=!0,queueMicrotask(()=>{this.#r=!1;const e=this.#o;this.#o=[],function(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r].field!==t[r].field||e[r].direction!==t[r].direction)return!1;return!0}(e,this.sortModel)||(this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender())}))}}export{S as MultiSortPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const t="sticky-left",e="sticky-right";function n(t){try{if("rtl"===getComputedStyle(t).direction)return"rtl"}catch{}try{const e=t.closest?.("[dir]")?.getAttribute("dir");if("rtl"===e)return"rtl"}catch{}return"ltr"}function s(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function i(t,e,n,i){return`${s(n,i)} ${t}: ${e}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}const 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(""));new RegExp(`__(proto|defineGetter|defineSetter)|${r.slice(3).join("|")}|this\\b`);const o=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("|")),a=/^\s*(javascript|vbscript|data|blob):/i;function c(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=[],n=t.querySelectorAll("*");for(const s of n){const t=s.tagName.toLowerCase();if(o.has(t)){e.push(s);continue}if("svg"===t||"http://www.w3.org/2000/svg"===s.namespaceURI){if(Array.from(s.attributes).some(t=>l.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(s);continue}}const n=[];for(const e of s.attributes){const t=e.name.toLowerCase();l.test(t)?n.push(e.name):(d.has(t)&&a.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&n.push(e.name)}n.forEach(t=>s.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content),e.innerHTML}const f={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};class u{static dependencies;static manifest;aliases;version="2.17.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 e={...this.userConfig},n={};for(const s of Object.keys(e))n[s]=this;for(const s of t){const t=s.userConfig;for(const[r,o]of Object.entries(t)){if(void 0===o)continue;if(!(r in e)){e[r]=o,n[r]=s;continue}if(e[r]===o)continue;const t=n[r]?.constructor.name??this.constructor.name,l=s.constructor.name,d=i("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${r}" supplied by both ${t} and ${l}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(d)}}Object.assign(this.userConfig,e)}refreshUserConfigFrom(t){const e=this.userConfig;for(const n of Object.keys(e))delete e[n];Object.assign(e,t.userConfig)}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 n=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(n),n.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{...f,...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;if(e){return"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),n=parseInt(e,10);if(!isNaN(n))return n}return 200}setIcon(t,e,n){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const s=this.#e(e,n);void 0!==s?"string"==typeof s?t.innerHTML=c(s):s instanceof HTMLElement&&(t.innerHTML="",t.appendChild(s.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 n=document.createElement("span");n.setAttribute("part","sort-indicator"),n.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(n,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(n,"sortNone"));const s=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return s?t.insertBefore(n,s):t.appendChild(n),n}warn(t,e){void 0!==e?console.warn(i(t,e,this.gridElement.id,this.name)):console.warn(`${s(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(t,e){throw new Error(i(t,e,this.gridElement.id,this.name))}}function g(t){return t.pinned??t.meta?.pinned}function p(t,e){return function(t,e){return"left"===t||"right"===t?t:"rtl"===e?"start"===t?"right":"left":"start"===t?"left":"right"}(t,e)}function h(t,e){const n=g(t);return!!n&&"left"===p(n,e)}function m(t,e){const n=g(t);return!!n&&"right"===p(n,e)}function y(t){for(let e=0;e<t.length;e++)if(null!=t[e].pinned||null!=t[e].meta?.pinned)return!0;return!1}function b(s,i){const r={groupEndAdjustments:{addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set},leftOffsets:/* @__PURE__ */new Map,rightOffsets:/* @__PURE__ */new Map,splitGroups:[]},o=Array.from(s.querySelectorAll(".header-row .cell"));if(!o.length)return r;const l=n(s),d=/* @__PURE__ */new Map,a=/* @__PURE__ */new Map;let c=0;for(const e of i)if(h(e,l)){const n=o.find(t=>t.getAttribute("data-field")===e.field);n&&(d.set(e.field,c),n.classList.add(t),n.style.position="sticky",n.style.left=c+"px",s.querySelectorAll(`.data-grid-row .cell[data-field="${e.field}"]`).forEach(e=>{e.classList.add(t),e.style.position="sticky",e.style.left=c+"px"}),c+=n.offsetWidth)}let f=0;for(const t of[...i].reverse())if(m(t,l)){const n=o.find(e=>e.getAttribute("data-field")===t.field);n&&(a.set(t.field,f),n.classList.add(e),n.style.position="sticky",n.style.right=f+"px",s.querySelectorAll(`.data-grid-row .cell[data-field="${t.field}"]`).forEach(t=>{t.classList.add(e),t.style.position="sticky",t.style.right=f+"px"}),f+=n.offsetWidth)}const u=[],g=function(n,s,i,r,o){const l={addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set},d=Array.from(n.querySelectorAll(".header-group-row .header-group-cell"));if(!d.length)return l;for(const a of d){const n=a.style.gridColumn;if(!n)continue;const d=n.match(/^(\d+)\s*\/\s*span\s+(\d+)$/);if(!d)continue;const c=parseInt(d[1],10)-1,f=c+parseInt(d[2],10)-1,u=s.slice(c,f+1);if(!u.length)continue;const g=u.every(t=>h(t,r)),p=u.every(t=>m(t,r));if(g){const e=u[0].field,n=i.find(t=>t.getAttribute("data-field")===e);n&&(a.classList.add(t),a.style.position="sticky",a.style.left=n.style.left)}else if(p){const t=u[u.length-1].field,n=i.find(e=>e.getAttribute("data-field")===t);n&&(a.classList.add(e),a.style.position="sticky",a.style.right=n.style.right)}else if(a.classList.contains("implicit-group"))v(a,u,c,i,r,l);else{const t=u.some(t=>h(t,r)),e=u.some(t=>m(t,r));(t||e)&&w(a,u,c,i,r,l,o)}}return l}(s,i,o,l,u);if(g.addGroupEnd.size>0||g.removeGroupEnd.size>0){for(const t of g.addGroupEnd){const e=o.find(e=>e.getAttribute("data-field")===t);e&&e.classList.add("group-end"),s.querySelectorAll(`.data-grid-row .cell[data-field="${t}"]`).forEach(t=>{t.classList.add("group-end")})}for(const t of g.removeGroupEnd){const e=o.find(e=>e.getAttribute("data-field")===t);e&&e.classList.remove("group-end"),s.querySelectorAll(`.data-grid-row .cell[data-field="${t}"]`).forEach(t=>{t.classList.remove("group-end")})}}return{groupEndAdjustments:g,leftOffsets:d,rightOffsets:a,splitGroups:u}}function E(t,e){return h(t,e)?"left":m(t,e)?"right":"none"}function v(n,s,i,r,o,l){const d=[];for(let t=0;t<s.length;t++){const e=E(s[t],o),n=d[d.length-1];n&&n.state===e?n.cols.push(s[t]):d.push({state:e,cols:[s[t]],colStart:i+t})}if(d.length<=1)return;const a=n.parentElement;if(!a)return;const c=n.nextSibling;a.removeChild(n);for(const f of d){const s=document.createElement("div");if(s.className=n.className,s.setAttribute("data-group",n.getAttribute("data-group")||""),s.style.gridColumn=`${f.colStart+1} / span ${f.cols.length}`,"left"===f.state){const e=f.cols[0].field,n=r.find(t=>t.getAttribute("data-field")===e);n&&(s.classList.add(t),s.style.position="sticky",s.style.left=n.style.left)}else if("right"===f.state){const t=f.cols[f.cols.length-1].field,n=r.find(e=>e.getAttribute("data-field")===t);n&&(s.classList.add(e),s.style.position="sticky",s.style.right=n.style.right)}else if("none"===f.state){f.cols.every(t=>String(t.field||"").startsWith("__tbw_"))&&(s.style.borderRightStyle="none")}c?a.insertBefore(s,c):a.appendChild(s)}for(let t=0;t<d.length;t++){const e=d[t],n=d[t+1];if("none"!==e.state&&n&&"none"===n.state){const t=e.cols[e.cols.length-1].field;t&&l.addGroupEnd.add(t)}if("none"===e.state){if(e.cols.every(t=>String(t.field||"").startsWith("__tbw_"))){const t=e.cols[e.cols.length-1].field;t&&l.removeGroupEnd.add(t)}}}}function w(n,s,i,r,o,l,d){const a=[];for(let t=0;t<s.length;t++){const e=E(s[t],o),n=a[a.length-1];n&&n.state===e?n.cols.push(s[t]):a.push({state:e,cols:[s[t]],colStart:i+t})}if(a.length<=1)return;const c=n.parentElement;if(!c)return;const f=n.textContent||"",u=n.getAttribute("data-group")||"",g=n.nextSibling;c.removeChild(n);const p=a.findIndex(t=>"left"===t.state);let h=-1;for(let t=a.length-1;t>=0;t--)if("right"===a[t].state){h=t;break}const m=p>=0?p:h,y=p>=0&&p+1<a.length?p+1:h>=0&&h-1>=0?h-1:-1;let b,v,w,C="";for(let E=0;E<a.length;E++){const s=a[E],i=document.createElement("div");if(i.className=n.className,i.setAttribute("data-group",u),i.style.gridColumn=`${s.colStart+1} / span ${s.cols.length}`,"left"===s.state){const e=s.cols[0].field,n=r.find(t=>t.getAttribute("data-field")===e);n&&(i.classList.add(t),i.style.position="sticky",i.style.left=n.style.left),E===m&&(i.style.borderRightStyle="none",b=i,C=s.cols[s.cols.length-1].field)}else if("right"===s.state){const t=s.cols[s.cols.length-1].field,n=r.find(e=>e.getAttribute("data-field")===t);n&&(i.classList.add(e),i.style.position="sticky",i.style.right=n.style.right),E===m&&(i.style.borderLeftStyle="none",b=i,C=s.cols[0].field)}if(E===y){i.style.overflow="visible";const t=document.createElement("span");t.textContent=f,t.style.position="relative",t.style.zIndex="36",t.style.display="block",t.style.overflow="hidden",t.style.textOverflow="ellipsis",t.style.whiteSpace="nowrap",i.appendChild(t),v=i,w=t}g?c.insertBefore(i,g):c.appendChild(i)}b&&v&&w&&C&&d.push({groupId:u,label:f,pinnedFragment:b,scrollableFragment:v,floatLabel:w,pinnedField:C,isTransferred:!1,floatOffset:0})}function C(n){n.querySelectorAll(`.${t}, .${e}`).forEach(n=>{n.classList.remove(t,e),n.style.position="",n.style.left="",n.style.right=""})}const A="canMoveColumn";class S extends u{static manifest={hookPriority:{processColumns:-10},ownedProperties:[{property:"pinned",level:"column",description:'the "pinned" column property',isUsed:t=>"left"===t||"right"===t||"start"===t||"end"===t}],queries:[{type:A,description:"Prevents pinned columns from being moved/reordered"},{type:"getStickyOffsets",description:"Returns the offsets for left/right pinned columns"},{type:"getContextMenuItems",description:"Contributes pin/unpin items to the header context menu"}]};name="pinnedColumns";get defaultConfig(){return{}}isApplied=!1;leftOffsets=/* @__PURE__ */new Map;rightOffsets=/* @__PURE__ */new Map;#n={addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set};#s=[];#i=[];#r=/* @__PURE__ */new WeakSet;detach(){this.leftOffsets.clear(),this.rightOffsets.clear(),this.isApplied=!1,this.#n={addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set},this.#s=[],this.#i=[],this.#r=/* @__PURE__ */new WeakSet}static detect(t,e){const n=e?.columns;return!!Array.isArray(n)&&y(n)}processColumns(t){const e=[...t];for(const n of e){const t=n.__element;if(!t||this.#r.has(t))continue;if(this.#r.add(t),null!=n.pinned)continue;const e=t.getAttribute("pinned");"left"!==e&&"right"!==e&&"start"!==e&&"end"!==e||(n.pinned=e)}if(this.isApplied=y(e),!this.isApplied)return e;const s=this.gridElement;return function(t,e="ltr"){const n=[],s=[],i=[];for(const r of t){const t=g(r);t?"left"===p(t,e)?n.push(r):i.push(r):s.push(r)}return[...n,...s,...i]}(e,s?n(s):"ltr")}afterRender(){if(!this.isApplied)return;const t=this.gridElement,e=[...this.columns];if(!y(e))return C(t),void(this.isApplied=!1);queueMicrotask(()=>{const n=b(t,e);this.#n=n.groupEndAdjustments,this.leftOffsets=n.leftOffsets,this.rightOffsets=n.rightOffsets,this.#s=n.splitGroups,this.#o()})}afterCellRender(n){if(!this.isApplied)return;const s=n.column.field,i=n.cellElement,r=this.leftOffsets.get(s);if(void 0!==r)i.classList.contains(t)||i.classList.add(t),i.style.position="sticky",i.style.left=r+"px";else{const t=this.rightOffsets.get(s);void 0!==t&&(i.classList.contains(e)||i.classList.add(e),i.style.position="sticky",i.style.right=t+"px")}this.#n.addGroupEnd.has(s)?n.cellElement.classList.add("group-end"):this.#n.removeGroupEnd.has(s)&&n.cellElement.classList.remove("group-end")}onScroll(t){this.#o()}#o(){if(!this.isApplied||0===this.#s.length)return;const t=this.gridElement;for(const e of this.#s){const n=e.pinnedFragment.getBoundingClientRect(),s=e.scrollableFragment.getBoundingClientRect().right<=n.right;if(s&&!e.isTransferred?(e.pinnedFragment.textContent=e.label,e.pinnedFragment.style.overflow="hidden",e.pinnedFragment.style.textOverflow="ellipsis",e.pinnedFragment.style.whiteSpace="nowrap",e.pinnedFragment.style.borderRightStyle="",e.floatLabel.style.visibility="hidden",e.floatLabel.style.transform="",e.floatOffset=0,this.#n.addGroupEnd.add(e.pinnedField),t.querySelectorAll(`.header-row .cell[data-field="${e.pinnedField}"], .data-grid-row .cell[data-field="${e.pinnedField}"]`).forEach(t=>t.classList.add("group-end")),e.isTransferred=!0):!s&&e.isTransferred&&(e.pinnedFragment.textContent="",e.pinnedFragment.style.overflow="",e.pinnedFragment.style.textOverflow="",e.pinnedFragment.style.whiteSpace="",e.pinnedFragment.style.borderRightStyle="none",e.floatLabel.style.visibility="",e.floatLabel.style.transform="",e.floatOffset=0,this.#n.addGroupEnd.delete(e.pinnedField),t.querySelectorAll(`.header-row .cell[data-field="${e.pinnedField}"], .data-grid-row .cell[data-field="${e.pinnedField}"]`).forEach(t=>t.classList.remove("group-end")),e.isTransferred=!1),!e.isTransferred){const t=e.floatLabel.getBoundingClientRect().left-e.floatOffset,s=n.left;t<s?(e.floatOffset=s-t,e.floatLabel.style.transform=`translateX(${e.floatOffset}px)`):(e.floatOffset=0,e.floatLabel.style.transform="")}}}handleQuery(t){switch(t.type){case A:return null==g(t.context)&&void 0;case"getStickyOffsets":return{left:Object.fromEntries(this.leftOffsets),right:Object.fromEntries(this.rightOffsets)};case"getContextMenuItems":{const e=t.context;if(!e.isHeader)return;const n=e.column;if(!n?.field)return;if(n.lockPinning||n.meta?.lockPinning)return;const s=[];return null!=g(n)?s.push({id:"pinned/unpin",label:"Unpin Column",icon:"📌",order:40,action:()=>this.setPinPosition(n.field,void 0)}):(s.push({id:"pinned/pin-left",label:"Pin Left",icon:"⬅",order:40,action:()=>this.setPinPosition(n.field,"left")}),s.push({id:"pinned/pin-right",label:"Pin Right",icon:"➡",order:41,action:()=>this.setPinPosition(n.field,"right")})),s}default:return}}setPinPosition(t,e){const n=this.columns;if(!n?.length)return;const s=n.findIndex(e=>e.field===t);if(-1===s)return;const i=this.gridElement;if(e){0===this.#i.length&&(this.#i=n.map(t=>t.field));const s=n.map(n=>{if(n.field!==t)return n;const s={...n};return s.pinned=e,s});i.columns=s}else{const e={...n[s]};delete e.pinned;const r=[...n];r.splice(s,1);const o=this.#i.indexOf(t);if(o>=0){let t=r.length;for(let e=0;e<r.length;e++){if(g(r[e]))continue;if(this.#i.indexOf(r[e].field)>o){t=e;break}}r.splice(t,0,e)}else r.splice(Math.min(s,r.length),0,e);r.some(t=>null!=g(t))||(this.#i=[]),i.columns=r}}refreshStickyOffsets(){const t=[...this.columns],e=b(this.gridElement,t);this.#n=e.groupEndAdjustments,this.leftOffsets=e.leftOffsets,this.rightOffsets=e.rightOffsets,this.#s=e.splitGroups}getLeftPinnedColumns(){return function(t,e="ltr"){return t.filter(t=>h(t,e))}([...this.columns],n(this.gridElement))}getRightPinnedColumns(){return function(t,e="ltr"){return t.filter(t=>m(t,e))}([...this.columns],n(this.gridElement))}clearStickyPositions(){C(this.gridElement)}getHorizontalScrollOffsets(n,s){if(!this.isApplied)return;let i=0,r=0;if(n){const s=n.querySelectorAll(`.${t}`),o=n.querySelectorAll(`.${e}`);s.forEach(t=>{i+=t.offsetWidth}),o.forEach(t=>{r+=t.offsetWidth})}else{this.gridElement.querySelectorAll(".header-row .cell").forEach(n=>{n.classList.contains(t)?i+=n.offsetWidth:n.classList.contains(e)&&(r+=n.offsetWidth)})}const o=s?.classList.contains(t)||s?.classList.contains(e);return{left:i,right:r,skipScroll:o}}}export{S as PinnedColumnsPlugin};
|
|
1
|
+
const t="sticky-left",e="sticky-right";function n(t){try{if("rtl"===getComputedStyle(t).direction)return"rtl"}catch{}try{const e=t.closest?.("[dir]")?.getAttribute("dir");if("rtl"===e)return"rtl"}catch{}return"ltr"}function s(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function i(t,e,n,i){return`${s(n,i)} ${t}: ${e}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}const 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(""));new RegExp(`__(proto|defineGetter|defineSetter)|${r.slice(3).join("|")}|this\\b`);const o=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("|")),a=/^\s*(javascript|vbscript|data|blob):/i;function c(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=[],n=t.querySelectorAll("*");for(const s of n){const t=s.tagName.toLowerCase();if(o.has(t)){e.push(s);continue}if("svg"===t||"http://www.w3.org/2000/svg"===s.namespaceURI){if(Array.from(s.attributes).some(t=>l.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(s);continue}}const n=[];for(const e of s.attributes){const t=e.name.toLowerCase();l.test(t)?n.push(e.name):(d.has(t)&&a.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&n.push(e.name)}n.forEach(t=>s.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content),e.innerHTML}const f={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};class u{static dependencies;static manifest;aliases;version="2.17.2";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 e={...this.userConfig},n={};for(const s of Object.keys(e))n[s]=this;for(const s of t){const t=s.userConfig;for(const[r,o]of Object.entries(t)){if(void 0===o)continue;if(!(r in e)){e[r]=o,n[r]=s;continue}if(e[r]===o)continue;const t=n[r]?.constructor.name??this.constructor.name,l=s.constructor.name,d=i("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${r}" supplied by both ${t} and ${l}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(d)}}Object.assign(this.userConfig,e)}refreshUserConfigFrom(t){const e=this.userConfig;for(const n of Object.keys(e))delete e[n];Object.assign(e,t.userConfig)}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 n=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(n),n.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{...f,...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;if(e){return"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),n=parseInt(e,10);if(!isNaN(n))return n}return 200}setIcon(t,e,n){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const s=this.#e(e,n);void 0!==s?"string"==typeof s?t.innerHTML=c(s):s instanceof HTMLElement&&(t.innerHTML="",t.appendChild(s.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 n=document.createElement("span");n.setAttribute("part","sort-indicator"),n.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(n,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(n,"sortNone"));const s=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return s?t.insertBefore(n,s):t.appendChild(n),n}warn(t,e){void 0!==e?console.warn(i(t,e,this.gridElement.id,this.name)):console.warn(`${s(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(t,e){throw new Error(i(t,e,this.gridElement.id,this.name))}}function g(t){return t.pinned??t.meta?.pinned}function p(t,e){return function(t,e){return"left"===t||"right"===t?t:"rtl"===e?"start"===t?"right":"left":"start"===t?"left":"right"}(t,e)}function h(t,e){const n=g(t);return!!n&&"left"===p(n,e)}function m(t,e){const n=g(t);return!!n&&"right"===p(n,e)}function y(t){for(let e=0;e<t.length;e++)if(null!=t[e].pinned||null!=t[e].meta?.pinned)return!0;return!1}function b(s,i){const r={groupEndAdjustments:{addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set},leftOffsets:/* @__PURE__ */new Map,rightOffsets:/* @__PURE__ */new Map,splitGroups:[]},o=Array.from(s.querySelectorAll(".header-row .cell"));if(!o.length)return r;const l=n(s),d=/* @__PURE__ */new Map,a=/* @__PURE__ */new Map;let c=0;for(const e of i)if(h(e,l)){const n=o.find(t=>t.getAttribute("data-field")===e.field);n&&(d.set(e.field,c),n.classList.add(t),n.style.position="sticky",n.style.left=c+"px",s.querySelectorAll(`.data-grid-row .cell[data-field="${e.field}"]`).forEach(e=>{e.classList.add(t),e.style.position="sticky",e.style.left=c+"px"}),c+=n.offsetWidth)}let f=0;for(const t of[...i].reverse())if(m(t,l)){const n=o.find(e=>e.getAttribute("data-field")===t.field);n&&(a.set(t.field,f),n.classList.add(e),n.style.position="sticky",n.style.right=f+"px",s.querySelectorAll(`.data-grid-row .cell[data-field="${t.field}"]`).forEach(t=>{t.classList.add(e),t.style.position="sticky",t.style.right=f+"px"}),f+=n.offsetWidth)}const u=[],g=function(n,s,i,r,o){const l={addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set},d=Array.from(n.querySelectorAll(".header-group-row .header-group-cell"));if(!d.length)return l;for(const a of d){const n=a.style.gridColumn;if(!n)continue;const d=n.match(/^(\d+)\s*\/\s*span\s+(\d+)$/);if(!d)continue;const c=parseInt(d[1],10)-1,f=c+parseInt(d[2],10)-1,u=s.slice(c,f+1);if(!u.length)continue;const g=u.every(t=>h(t,r)),p=u.every(t=>m(t,r));if(g){const e=u[0].field,n=i.find(t=>t.getAttribute("data-field")===e);n&&(a.classList.add(t),a.style.position="sticky",a.style.left=n.style.left)}else if(p){const t=u[u.length-1].field,n=i.find(e=>e.getAttribute("data-field")===t);n&&(a.classList.add(e),a.style.position="sticky",a.style.right=n.style.right)}else if(a.classList.contains("implicit-group"))v(a,u,c,i,r,l);else{const t=u.some(t=>h(t,r)),e=u.some(t=>m(t,r));(t||e)&&w(a,u,c,i,r,l,o)}}return l}(s,i,o,l,u);if(g.addGroupEnd.size>0||g.removeGroupEnd.size>0){for(const t of g.addGroupEnd){const e=o.find(e=>e.getAttribute("data-field")===t);e&&e.classList.add("group-end"),s.querySelectorAll(`.data-grid-row .cell[data-field="${t}"]`).forEach(t=>{t.classList.add("group-end")})}for(const t of g.removeGroupEnd){const e=o.find(e=>e.getAttribute("data-field")===t);e&&e.classList.remove("group-end"),s.querySelectorAll(`.data-grid-row .cell[data-field="${t}"]`).forEach(t=>{t.classList.remove("group-end")})}}return{groupEndAdjustments:g,leftOffsets:d,rightOffsets:a,splitGroups:u}}function E(t,e){return h(t,e)?"left":m(t,e)?"right":"none"}function v(n,s,i,r,o,l){const d=[];for(let t=0;t<s.length;t++){const e=E(s[t],o),n=d[d.length-1];n&&n.state===e?n.cols.push(s[t]):d.push({state:e,cols:[s[t]],colStart:i+t})}if(d.length<=1)return;const a=n.parentElement;if(!a)return;const c=n.nextSibling;a.removeChild(n);for(const f of d){const s=document.createElement("div");if(s.className=n.className,s.setAttribute("data-group",n.getAttribute("data-group")||""),s.style.gridColumn=`${f.colStart+1} / span ${f.cols.length}`,"left"===f.state){const e=f.cols[0].field,n=r.find(t=>t.getAttribute("data-field")===e);n&&(s.classList.add(t),s.style.position="sticky",s.style.left=n.style.left)}else if("right"===f.state){const t=f.cols[f.cols.length-1].field,n=r.find(e=>e.getAttribute("data-field")===t);n&&(s.classList.add(e),s.style.position="sticky",s.style.right=n.style.right)}else if("none"===f.state){f.cols.every(t=>String(t.field||"").startsWith("__tbw_"))&&(s.style.borderRightStyle="none")}c?a.insertBefore(s,c):a.appendChild(s)}for(let t=0;t<d.length;t++){const e=d[t],n=d[t+1];if("none"!==e.state&&n&&"none"===n.state){const t=e.cols[e.cols.length-1].field;t&&l.addGroupEnd.add(t)}if("none"===e.state){if(e.cols.every(t=>String(t.field||"").startsWith("__tbw_"))){const t=e.cols[e.cols.length-1].field;t&&l.removeGroupEnd.add(t)}}}}function w(n,s,i,r,o,l,d){const a=[];for(let t=0;t<s.length;t++){const e=E(s[t],o),n=a[a.length-1];n&&n.state===e?n.cols.push(s[t]):a.push({state:e,cols:[s[t]],colStart:i+t})}if(a.length<=1)return;const c=n.parentElement;if(!c)return;const f=n.textContent||"",u=n.getAttribute("data-group")||"",g=n.nextSibling;c.removeChild(n);const p=a.findIndex(t=>"left"===t.state);let h=-1;for(let t=a.length-1;t>=0;t--)if("right"===a[t].state){h=t;break}const m=p>=0?p:h,y=p>=0&&p+1<a.length?p+1:h>=0&&h-1>=0?h-1:-1;let b,v,w,C="";for(let E=0;E<a.length;E++){const s=a[E],i=document.createElement("div");if(i.className=n.className,i.setAttribute("data-group",u),i.style.gridColumn=`${s.colStart+1} / span ${s.cols.length}`,"left"===s.state){const e=s.cols[0].field,n=r.find(t=>t.getAttribute("data-field")===e);n&&(i.classList.add(t),i.style.position="sticky",i.style.left=n.style.left),E===m&&(i.style.borderRightStyle="none",b=i,C=s.cols[s.cols.length-1].field)}else if("right"===s.state){const t=s.cols[s.cols.length-1].field,n=r.find(e=>e.getAttribute("data-field")===t);n&&(i.classList.add(e),i.style.position="sticky",i.style.right=n.style.right),E===m&&(i.style.borderLeftStyle="none",b=i,C=s.cols[0].field)}if(E===y){i.style.overflow="visible";const t=document.createElement("span");t.textContent=f,t.style.position="relative",t.style.zIndex="36",t.style.display="block",t.style.overflow="hidden",t.style.textOverflow="ellipsis",t.style.whiteSpace="nowrap",i.appendChild(t),v=i,w=t}g?c.insertBefore(i,g):c.appendChild(i)}b&&v&&w&&C&&d.push({groupId:u,label:f,pinnedFragment:b,scrollableFragment:v,floatLabel:w,pinnedField:C,isTransferred:!1,floatOffset:0})}function C(n){n.querySelectorAll(`.${t}, .${e}`).forEach(n=>{n.classList.remove(t,e),n.style.position="",n.style.left="",n.style.right=""})}const A="canMoveColumn";class S extends u{static manifest={hookPriority:{processColumns:-10},ownedProperties:[{property:"pinned",level:"column",description:'the "pinned" column property',isUsed:t=>"left"===t||"right"===t||"start"===t||"end"===t}],queries:[{type:A,description:"Prevents pinned columns from being moved/reordered"},{type:"getStickyOffsets",description:"Returns the offsets for left/right pinned columns"},{type:"getContextMenuItems",description:"Contributes pin/unpin items to the header context menu"}]};name="pinnedColumns";get defaultConfig(){return{}}isApplied=!1;leftOffsets=/* @__PURE__ */new Map;rightOffsets=/* @__PURE__ */new Map;#n={addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set};#s=[];#i=[];#r=/* @__PURE__ */new WeakSet;detach(){this.leftOffsets.clear(),this.rightOffsets.clear(),this.isApplied=!1,this.#n={addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set},this.#s=[],this.#i=[],this.#r=/* @__PURE__ */new WeakSet}static detect(t,e){const n=e?.columns;return!!Array.isArray(n)&&y(n)}processColumns(t){const e=[...t];for(const n of e){const t=n.__element;if(!t||this.#r.has(t))continue;if(this.#r.add(t),null!=n.pinned)continue;const e=t.getAttribute("pinned");"left"!==e&&"right"!==e&&"start"!==e&&"end"!==e||(n.pinned=e)}if(this.isApplied=y(e),!this.isApplied)return e;const s=this.gridElement;return function(t,e="ltr"){const n=[],s=[],i=[];for(const r of t){const t=g(r);t?"left"===p(t,e)?n.push(r):i.push(r):s.push(r)}return[...n,...s,...i]}(e,s?n(s):"ltr")}afterRender(){if(!this.isApplied)return;const t=this.gridElement,e=[...this.columns];if(!y(e))return C(t),void(this.isApplied=!1);queueMicrotask(()=>{const n=b(t,e);this.#n=n.groupEndAdjustments,this.leftOffsets=n.leftOffsets,this.rightOffsets=n.rightOffsets,this.#s=n.splitGroups,this.#o()})}afterCellRender(n){if(!this.isApplied)return;const s=n.column.field,i=n.cellElement,r=this.leftOffsets.get(s);if(void 0!==r)i.classList.contains(t)||i.classList.add(t),i.style.position="sticky",i.style.left=r+"px";else{const t=this.rightOffsets.get(s);void 0!==t&&(i.classList.contains(e)||i.classList.add(e),i.style.position="sticky",i.style.right=t+"px")}this.#n.addGroupEnd.has(s)?n.cellElement.classList.add("group-end"):this.#n.removeGroupEnd.has(s)&&n.cellElement.classList.remove("group-end")}onScroll(t){this.#o()}#o(){if(!this.isApplied||0===this.#s.length)return;const t=this.gridElement;for(const e of this.#s){const n=e.pinnedFragment.getBoundingClientRect(),s=e.scrollableFragment.getBoundingClientRect().right<=n.right;if(s&&!e.isTransferred?(e.pinnedFragment.textContent=e.label,e.pinnedFragment.style.overflow="hidden",e.pinnedFragment.style.textOverflow="ellipsis",e.pinnedFragment.style.whiteSpace="nowrap",e.pinnedFragment.style.borderRightStyle="",e.floatLabel.style.visibility="hidden",e.floatLabel.style.transform="",e.floatOffset=0,this.#n.addGroupEnd.add(e.pinnedField),t.querySelectorAll(`.header-row .cell[data-field="${e.pinnedField}"], .data-grid-row .cell[data-field="${e.pinnedField}"]`).forEach(t=>t.classList.add("group-end")),e.isTransferred=!0):!s&&e.isTransferred&&(e.pinnedFragment.textContent="",e.pinnedFragment.style.overflow="",e.pinnedFragment.style.textOverflow="",e.pinnedFragment.style.whiteSpace="",e.pinnedFragment.style.borderRightStyle="none",e.floatLabel.style.visibility="",e.floatLabel.style.transform="",e.floatOffset=0,this.#n.addGroupEnd.delete(e.pinnedField),t.querySelectorAll(`.header-row .cell[data-field="${e.pinnedField}"], .data-grid-row .cell[data-field="${e.pinnedField}"]`).forEach(t=>t.classList.remove("group-end")),e.isTransferred=!1),!e.isTransferred){const t=e.floatLabel.getBoundingClientRect().left-e.floatOffset,s=n.left;t<s?(e.floatOffset=s-t,e.floatLabel.style.transform=`translateX(${e.floatOffset}px)`):(e.floatOffset=0,e.floatLabel.style.transform="")}}}handleQuery(t){switch(t.type){case A:return null==g(t.context)&&void 0;case"getStickyOffsets":return{left:Object.fromEntries(this.leftOffsets),right:Object.fromEntries(this.rightOffsets)};case"getContextMenuItems":{const e=t.context;if(!e.isHeader)return;const n=e.column;if(!n?.field)return;if(n.lockPinning||n.meta?.lockPinning)return;const s=[];return null!=g(n)?s.push({id:"pinned/unpin",label:"Unpin Column",icon:"📌",order:40,action:()=>this.setPinPosition(n.field,void 0)}):(s.push({id:"pinned/pin-left",label:"Pin Left",icon:"⬅",order:40,action:()=>this.setPinPosition(n.field,"left")}),s.push({id:"pinned/pin-right",label:"Pin Right",icon:"➡",order:41,action:()=>this.setPinPosition(n.field,"right")})),s}default:return}}setPinPosition(t,e){const n=this.columns;if(!n?.length)return;const s=n.findIndex(e=>e.field===t);if(-1===s)return;const i=this.gridElement;if(e){0===this.#i.length&&(this.#i=n.map(t=>t.field));const s=n.map(n=>{if(n.field!==t)return n;const s={...n};return s.pinned=e,s});i.columns=s}else{const e={...n[s]};delete e.pinned;const r=[...n];r.splice(s,1);const o=this.#i.indexOf(t);if(o>=0){let t=r.length;for(let e=0;e<r.length;e++){if(g(r[e]))continue;if(this.#i.indexOf(r[e].field)>o){t=e;break}}r.splice(t,0,e)}else r.splice(Math.min(s,r.length),0,e);r.some(t=>null!=g(t))||(this.#i=[]),i.columns=r}}refreshStickyOffsets(){const t=[...this.columns],e=b(this.gridElement,t);this.#n=e.groupEndAdjustments,this.leftOffsets=e.leftOffsets,this.rightOffsets=e.rightOffsets,this.#s=e.splitGroups}getLeftPinnedColumns(){return function(t,e="ltr"){return t.filter(t=>h(t,e))}([...this.columns],n(this.gridElement))}getRightPinnedColumns(){return function(t,e="ltr"){return t.filter(t=>m(t,e))}([...this.columns],n(this.gridElement))}clearStickyPositions(){C(this.gridElement)}getHorizontalScrollOffsets(n,s){if(!this.isApplied)return;let i=0,r=0;if(n){const s=n.querySelectorAll(`.${t}`),o=n.querySelectorAll(`.${e}`);s.forEach(t=>{i+=t.offsetWidth}),o.forEach(t=>{r+=t.offsetWidth})}else{this.gridElement.querySelectorAll(".header-row .cell").forEach(n=>{n.classList.contains(t)?i+=n.offsetWidth:n.classList.contains(e)&&(r+=n.offsetWidth)})}const o=s?.classList.contains(t)||s?.classList.contains(e);return{left:i,right:r,skipScroll:o}}}export{S as PinnedColumnsPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const t=/* @__PURE__ */new WeakMap;function e(e,n,r){return r?.valueAccessor?function(e,n,r=-1){if(!n.valueAccessor)return e?.[n.field];if("object"!=typeof e||null===e)return n.valueAccessor({row:e,column:n,rowIndex:r});const o=e,i=n.field;let s=t.get(o);if(s){const t=s.get(i);if(void 0!==t)return t.v}else s=/* @__PURE__ */new Map,t.set(o,s);const a=n.valueAccessor({row:e,column:n,rowIndex:r});return s.set(i,{v:a}),a}(e,r):e?.[n]}function n(t){return null==t||""===t||"number"==typeof t&&isNaN(t)}const r={sum:(t,r,o)=>{let i=0;for(let s=0;s<t.length;s++){const a=e(t[s],r,o);if(n(a))continue;const l=Number(a);isNaN(l)||(i+=l)}return i},avg:(t,r,o)=>{if(!t.length)return 0;let i=0,s=0;for(let a=0;a<t.length;a++){const l=e(t[a],r,o);if(n(l))continue;const c=Number(l);isNaN(c)||(i+=c,s++)}return s>0?i/s:0},count:t=>t.length,min:(t,r,o)=>{if(!t.length)return 0;let i=1/0;for(let s=0;s<t.length;s++){const a=e(t[s],r,o);if(n(a))continue;const l=Number(a);isNaN(l)||l<i&&(i=l)}return i===1/0?0:i},max:(t,r,o)=>{if(!t.length)return 0;let i=-1/0;for(let s=0;s<t.length;s++){const a=e(t[s],r,o);if(n(a))continue;const l=Number(a);isNaN(l)||l>i&&(i=l)}return i===-1/0?0:i},first:(t,n,r)=>t[0]?e(t[0],n,r):void 0,last:(t,n,r)=>t.length?e(t[t.length-1],n,r):void 0},o=/* @__PURE__ */new Map,i={register(t,e){o.set(t,e)},unregister(t){o.delete(t)},get(t){if(void 0!==t)return"function"==typeof t?t:o.get(t)??r[t]},run(t,e,n,r){const o=this.get(t);return o?o(e,n,r):void 0},has:t=>o.has(t)||t in r,list:()=>[...Object.keys(r),...o.keys()]},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(t=>t.split("").reverse().join(""));new RegExp(`__(proto|defineGetter|defineSetter)|${s.slice(3).join("|")}|this\\b`);const a=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,c=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),g=/^\s*(javascript|vbscript|data|blob):/i;function d(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=[],n=t.querySelectorAll("*");for(const r of n){const t=r.tagName.toLowerCase();if(a.has(t)){e.push(r);continue}if("svg"===t||"http://www.w3.org/2000/svg"===r.namespaceURI){if(Array.from(r.attributes).some(t=>l.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(r);continue}}const n=[];for(const e of r.attributes){const t=e.name.toLowerCase();l.test(t)?n.push(e.name):(c.has(t)&&g.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&n.push(e.name)}n.forEach(t=>r.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content),e.innerHTML}function h(t,e){const n=document.createElement("div");n.className="tbw-pinned-rows",n.setAttribute("role","presentation"),n.setAttribute("aria-live","polite");const r=document.createElement("div");r.className="tbw-pinned-rows-left";const o=document.createElement("div");o.className="tbw-pinned-rows-center";const i=document.createElement("div");if(i.className="tbw-pinned-rows-right",!1!==t.showRowCount){const t=document.createElement("span");t.className="tbw-status-panel tbw-status-panel-row-count",t.textContent=`Total: ${e.totalRows} rows`,r.appendChild(t)}if(t.showFilteredCount&&e.filteredRows!==e.totalRows){const t=document.createElement("span");t.className="tbw-status-panel tbw-status-panel-filtered-count",t.textContent=`Filtered: ${e.filteredRows}`,r.appendChild(t)}if(t.showSelectedCount&&e.selectedRows>0){const t=document.createElement("span");t.className="tbw-status-panel tbw-status-panel-selected-count",t.textContent=`Selected: ${e.selectedRows}`,i.appendChild(t)}if(t.customPanels)for(const s of t.customPanels){const t=w(s,e);switch(s.position){case"left":r.appendChild(t);break;case"center":o.appendChild(t);break;case"right":i.appendChild(t)}}return n.appendChild(r),n.appendChild(o),n.appendChild(i),n}function u(t){const e=document.createElement("div");return e.className=`tbw-aggregation-rows tbw-aggregation-rows-${t}`,e.setAttribute("role","presentation"),e}function p(t,e,n,r,o=!1){t.innerHTML="";for(const i of e){const e=document.createElement("div");e.className="tbw-aggregation-row",e.setAttribute("role","presentation"),i.id&&e.setAttribute("data-aggregation-id",i.id);i.fullWidth??o?f(e,i,n,r):m(e,i,n,r),t.appendChild(e)}}function f(t,e,n,r){const o=document.createElement("div");o.className="tbw-aggregation-cell tbw-aggregation-cell-full",o.style.gridColumn="1 / -1";const i="function"==typeof e.label?e.label(r,n):e.label;if(i){const t=document.createElement("span");t.className="tbw-aggregation-label",t.textContent=i,o.appendChild(t)}const s=function(t,e,n){const r=t.aggregators&&Object.keys(t.aggregators).length>0,o=t.cells&&Object.keys(t.cells).length>0;if(!r&&!o)return null;const i=document.createElement("span");i.className="tbw-aggregation-aggregates";for(const s of e){const{value:e,formatter:r}=b(t,s,n);if(null!=e){const t=document.createElement("span");t.className="tbw-aggregation-aggregate",t.setAttribute("data-field",s.field);const n=s.header??s.field,o=r?r(e,s.field,s):String(e);t.textContent=`${n}: ${o}`,i.appendChild(t)}}return i.children.length>0?i:null}(e,n,r);s&&o.appendChild(s),t.appendChild(o)}function m(t,e,n,r){for(const i of n){const n=document.createElement("div");n.className="tbw-aggregation-cell",n.setAttribute("data-field",i.field);const{value:o,formatter:s}=b(e,i,r);n.textContent=null!=o?s?s(o,i.field,i):String(o):"",t.appendChild(n)}const o="function"==typeof e.label?e.label(r,n):e.label;if(o){const e=document.createElement("span");e.className="tbw-aggregation-label",e.textContent=o,t.appendChild(e)}}function b(t,e,n){let r,o;const s=t.aggregators?.[e.field];if(s)if("object"==typeof(a=s)&&null!==a&&"aggFunc"in a){const t=i.get(s.aggFunc);t&&(r=t(n,e.field,e)),o=s.formatter}else{const t=i.get(s);t&&(r=t(n,e.field,e))}else if(t.cells&&Object.prototype.hasOwnProperty.call(t.cells,e.field)){const o=t.cells[e.field];r="function"==typeof o?o(n,e.field,e):o}var a;return{value:r,formatter:o}}function w(t,e){const n=document.createElement("div");n.className="tbw-status-panel tbw-status-panel-custom",n.id=`status-panel-${t.id}`;const r=t.render(e);return"string"==typeof r?n.innerHTML=d(r):n.appendChild(r),n}function v(t,e,n,r,o){const i=n?.sourceRows,s=n?.rows,a=Array.isArray(i)?i.length:t.length,l=Array.isArray(s)?s.length:t.length,c=a>0?a:l;return{totalRows:c,filteredRows:o?.cachedResult?.length??(l<a?l:c),selectedRows:r?.selected?.size??0,columns:e,rows:t,grid:n}}function C(){return t=>{const e=document.createElement("span");return e.className="tbw-status-panel tbw-status-panel-row-count",e.textContent=`Total: ${t.totalRows} rows`,e}}function E(){return t=>{if(t.selectedRows<=0)return null;const e=document.createElement("span");return e.className="tbw-status-panel tbw-status-panel-selected-count",e.textContent=`Selected: ${t.selectedRows}`,e}}function A(){return t=>{if(t.filteredRows===t.totalRows)return null;const e=document.createElement("span");return e.className="tbw-status-panel tbw-status-panel-filtered-count",e.textContent=`Filtered: ${t.filteredRows}`,e}}function W(t){const e=document.createElement("div");return e.className="tbw-status-panel tbw-status-panel-custom",e.appendChild(t),e}const y=/* @__PURE__ */new WeakMap;function R(t,e,n){const r=Array.isArray(t.render)?t.render:[{zone:"left",render:t.render}],o=r.map(t=>t.render(e)??null);if(n){const t=y.get(n);if(t&&t.length===o.length&&t.every((t,e)=>t===o[e]))return n}const i=document.createElement("div");i.className="tbw-pinned-rows",i.setAttribute("role","presentation"),i.setAttribute("aria-live","polite"),t.id&&i.setAttribute("data-pinned-row-id",t.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 g=0;g<r.length;g++){const t=r[g],e=o[g];if(null==e)continue;const n=t.zone??"left",i=e.classList?.contains("tbw-status-panel");c[n].appendChild(i?e:W(e))}return 0===s.children.length&&0===a.children.length&&0===l.children.length?null:(i.appendChild(s),i.appendChild(a),i.appendChild(l),y.set(i,o),i)}function x(t,e,n,r,o=!1){const i=u(e);return p(i,[t],n,r,o),i}function S(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function N(t,e,n,r){return`${S(n,r)} ${t}: ${e}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}const B={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};class k{static dependencies;static manifest;aliases;version="2.17.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 e={...this.userConfig},n={};for(const r of Object.keys(e))n[r]=this;for(const r of t){const t=r.userConfig;for(const[o,i]of Object.entries(t)){if(void 0===i)continue;if(!(o in e)){e[o]=i,n[o]=r;continue}if(e[o]===i)continue;const t=n[o]?.constructor.name??this.constructor.name,s=r.constructor.name,a=N("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${t} 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,e)}refreshUserConfigFrom(t){const e=this.userConfig;for(const n of Object.keys(e))delete e[n];Object.assign(e,t.userConfig)}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 n=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(n),n.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{...B,...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;if(e){return"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),n=parseInt(e,10);if(!isNaN(n))return n}return 200}setIcon(t,e,n){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const r=this.#e(e,n);void 0!==r?"string"==typeof r?t.innerHTML=d(r):r instanceof HTMLElement&&(t.innerHTML="",t.appendChild(r.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 n=document.createElement("span");n.setAttribute("part","sort-indicator"),n.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(n,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(n,"sortNone"));const r=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return r?t.insertBefore(n,r):t.appendChild(n),n}warn(t,e){void 0!==e?console.warn(N(t,e,this.gridElement.id,this.name)):console.warn(`${S(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(t,e){throw new Error(N(t,e,this.gridElement.id,this.name))}}class M extends k{name="pinnedRows";styles="@layer tbw-plugins{.tbw-scroll-area{container-type:inline-size}.tbw-footer,.tbw-header-pinned{flex-shrink:0;z-index:var(--tbw-z-layer-pinned-rows, 20);background:var(--tbw-color-panel-bg);min-width:fit-content}.tbw-pinned-rows{display:flex;align-items:center;justify-content:space-between;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));min-height:32px;box-sizing:border-box;position:sticky;left:0;min-width:0;width:100cqi}.tbw-pinned-rows+.tbw-pinned-rows{border-top:0}.tbw-pinned-rows-left,.tbw-pinned-rows-center,.tbw-pinned-rows-right{display:flex;align-items:center;gap:var(--tbw-spacing-xl, 1rem)}.tbw-pinned-rows-left{justify-content:flex-start}.tbw-pinned-rows-center{justify-content:center;flex:1}.tbw-pinned-rows-right{justify-content:flex-end}.tbw-status-panel{white-space:nowrap}.tbw-aggregation-rows{min-width:fit-content;background:var(--tbw-aggregation-bg, var(--tbw-color-header-bg))}.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{display:grid;grid-template-columns:var(--tbw-column-template);font-size:var(--tbw-aggregation-font-size, .8em);font-weight:var(--tbw-aggregation-font-weight, 600);position:relative;background:inherit}.tbw-aggregation-row>.tbw-aggregation-label{position:sticky;left:0;grid-row:1;grid-column:1;display:flex;align-items:center;padding:var(--tbw-cell-padding, .125rem .5rem);background:inherit;z-index:1;pointer-events:none}.tbw-aggregation-row>.tbw-aggregation-cell:first-child{grid-column:1;grid-row:1}.tbw-aggregation-cell:not(:empty){position:relative;z-index:2;background:inherit}.tbw-aggregation-cell{padding:var(--tbw-cell-padding, .125rem .5rem);min-height:var(--tbw-row-height, 1.75rem);display:block;align-items:center;align-content:center;border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;text-overflow:ellipsis;white-space:var(--tbw-cell-white-space, nowrap)}.tbw-aggregation-cell:last-child{border-right:0}.tbw-aggregation-cell-full{grid-column:1 / -1;border-right:0;display:flex;align-items:center;gap:var(--tbw-spacing-lg, .75rem)}.tbw-aggregation-label{white-space:nowrap}.tbw-aggregation-aggregates{display:flex;align-items:center;gap:var(--tbw-spacing-lg, .75rem);font-weight:400;opacity:.85}.tbw-aggregation-aggregate{white-space:nowrap}}";get defaultConfig(){return{position:"bottom",showRowCount:!0,showSelectedCount:!0,showFilteredCount:!0}}infoBarElement=null;topAggregationContainer=null;bottomAggregationContainer=null;footerWrapper=null;headerWrapper=null;lastModeWasSlots=!1;detach(){this.cleanup()}afterRender(){const t=this.gridElement;if(!t)return;const e=t.querySelector(".tbw-scroll-area")??t.querySelector(".tbw-grid-content")??t.querySelector(".tbw-grid-root");if(!e)return;this.footerWrapper&&!e.contains(this.footerWrapper)&&(this.footerWrapper=null,this.bottomAggregationContainer=null,this.infoBarElement=null),this.topAggregationContainer&&!e.contains(this.topAggregationContainer)&&(this.topAggregationContainer=null),this.infoBarElement&&!e.contains(this.infoBarElement)&&(this.infoBarElement=null),this.headerWrapper&&!e.contains(this.headerWrapper)&&(this.headerWrapper=null);const n=this.getSelectionState(),r=this.getFilterState(),o=v(this.sourceRows,this.columns,this.gridElement,n,r);this.config.slots?this.renderSlotMode(e,t,o):this.renderLegacyMode(e,t,o)}renderSlotMode(t,e,n){this.lastModeWasSlots||this.detachLegacyOnly(),this.lastModeWasSlots=!0;const r=this.config.slots??[],o=r.filter(t=>"top"===t.position),i=r.filter(t=>"top"!==t.position);o.length>0?(this.headerWrapper||(this.headerWrapper=document.createElement("div"),this.headerWrapper.className="tbw-header-pinned",t.insertBefore(this.headerWrapper,t.firstChild)),this.populateSlotWrapper(this.headerWrapper,o,"top",n)):this.headerWrapper&&(this.headerWrapper.remove(),this.headerWrapper=null),i.length>0?(this.footerWrapper||(this.footerWrapper=document.createElement("div"),this.footerWrapper.className="tbw-footer",t.appendChild(this.footerWrapper)),this.populateSlotWrapper(this.footerWrapper,i,"bottom",n)):this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null)}populateSlotWrapper(t,e,n,r){const o=/* @__PURE__ */new Map;for(let a=0;a<t.children.length;a++){const e=t.children[a],n=e.getAttribute("data-pinned-row-id");n&&o.set(n,e)}const i=[];for(const a of e){const t="render"in a&&null!=a.render?R(a,r,a.id?o.get(a.id)??null:null):x(a,n,this.visibleColumns,this.sourceRows,this.config.fullWidth);t&&i.push(t)}const s=t.children;if(s.length===i.length){let t=!0;for(let e=0;e<i.length;e++)if(s[e]!==i[e]){t=!1;break}if(t)return}t.replaceChildren(...i)}renderLegacyMode(t,e,n){this.lastModeWasSlots&&(this.headerWrapper&&(this.headerWrapper.remove(),this.headerWrapper=null),this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null),this.bottomAggregationContainer=null,this.infoBarElement=null),this.lastModeWasSlots=!1;const r=this.config.aggregationRows||[],o=r.filter(t=>"top"===t.position),i=r.filter(t=>"top"!==t.position);o.length>0?(this.topAggregationContainer||(this.topAggregationContainer=u("top"),t.insertBefore(this.topAggregationContainer,t.firstChild)),p(this.topAggregationContainer,o,this.visibleColumns,this.sourceRows,this.config.fullWidth)):this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null);const s=!1!==this.config.showRowCount||this.config.showSelectedCount&&n.selectedRows>0||this.config.showFilteredCount&&n.filteredRows!==n.totalRows||this.config.customPanels&&this.config.customPanels.length>0,a=s&&"top"!==this.config.position,l=i.length>0||a;if(s&&"top"===this.config.position)if(this.infoBarElement){const t=h(this.config,n);this.infoBarElement.replaceWith(t),this.infoBarElement=t}else this.infoBarElement=h(this.config,n),t.insertBefore(this.infoBarElement,t.firstChild);else"top"===this.config.position&&this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null);l?(this.footerWrapper||(this.footerWrapper=document.createElement("div"),this.footerWrapper.className="tbw-footer",t.appendChild(this.footerWrapper)),this.footerWrapper.innerHTML="",i.length>0&&(this.bottomAggregationContainer||(this.bottomAggregationContainer=u("bottom")),this.footerWrapper.appendChild(this.bottomAggregationContainer),p(this.bottomAggregationContainer,i,this.visibleColumns,this.sourceRows,this.config.fullWidth)),a&&(this.infoBarElement=h(this.config,n),this.footerWrapper.appendChild(this.infoBarElement))):this.cleanupFooter()}cleanup(){this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null),this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null),this.headerWrapper&&(this.headerWrapper.remove(),this.headerWrapper=null)}detachLegacyOnly(){this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null),this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null)}cleanupFooter(){this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.infoBarElement&&"top"!==this.config.position&&(this.infoBarElement.remove(),this.infoBarElement=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 t=this.getSelectionState(),e=this.getFilterState();return v(this.rows,this.columns,this.gridElement,t,e)}addPanel(t){this.config.customPanels||(this.config.customPanels=[]),this.config.customPanels.push(t),this.requestRender()}removePanel(t){this.config.customPanels&&(this.config.customPanels=this.config.customPanels.filter(e=>e.id!==t),this.requestRender())}addAggregationRow(t){this.config.aggregationRows||(this.config.aggregationRows=[]),this.config.aggregationRows.push(t),this.requestRender()}removeAggregationRow(t){this.config.aggregationRows&&(this.config.aggregationRows=this.config.aggregationRows.filter(e=>e.id!==t),this.requestRender())}}export{M as PinnedRowsPlugin,A as filteredCountPanel,C as rowCountPanel,E as selectedCountPanel};
|
|
1
|
+
const t=/* @__PURE__ */new WeakMap;function e(e,n,r){return r?.valueAccessor?function(e,n,r=-1){if(!n.valueAccessor)return e?.[n.field];if("object"!=typeof e||null===e)return n.valueAccessor({row:e,column:n,rowIndex:r});const o=e,i=n.field;let s=t.get(o);if(s){const t=s.get(i);if(void 0!==t)return t.v}else s=/* @__PURE__ */new Map,t.set(o,s);const a=n.valueAccessor({row:e,column:n,rowIndex:r});return s.set(i,{v:a}),a}(e,r):e?.[n]}function n(t){return null==t||""===t||"number"==typeof t&&isNaN(t)}const r={sum:(t,r,o)=>{let i=0;for(let s=0;s<t.length;s++){const a=e(t[s],r,o);if(n(a))continue;const l=Number(a);isNaN(l)||(i+=l)}return i},avg:(t,r,o)=>{if(!t.length)return 0;let i=0,s=0;for(let a=0;a<t.length;a++){const l=e(t[a],r,o);if(n(l))continue;const c=Number(l);isNaN(c)||(i+=c,s++)}return s>0?i/s:0},count:t=>t.length,min:(t,r,o)=>{if(!t.length)return 0;let i=1/0;for(let s=0;s<t.length;s++){const a=e(t[s],r,o);if(n(a))continue;const l=Number(a);isNaN(l)||l<i&&(i=l)}return i===1/0?0:i},max:(t,r,o)=>{if(!t.length)return 0;let i=-1/0;for(let s=0;s<t.length;s++){const a=e(t[s],r,o);if(n(a))continue;const l=Number(a);isNaN(l)||l>i&&(i=l)}return i===-1/0?0:i},first:(t,n,r)=>t[0]?e(t[0],n,r):void 0,last:(t,n,r)=>t.length?e(t[t.length-1],n,r):void 0},o=/* @__PURE__ */new Map,i={register(t,e){o.set(t,e)},unregister(t){o.delete(t)},get(t){if(void 0!==t)return"function"==typeof t?t:o.get(t)??r[t]},run(t,e,n,r){const o=this.get(t);return o?o(e,n,r):void 0},has:t=>o.has(t)||t in r,list:()=>[...Object.keys(r),...o.keys()]},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(t=>t.split("").reverse().join(""));new RegExp(`__(proto|defineGetter|defineSetter)|${s.slice(3).join("|")}|this\\b`);const a=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,c=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),g=/^\s*(javascript|vbscript|data|blob):/i;function d(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=[],n=t.querySelectorAll("*");for(const r of n){const t=r.tagName.toLowerCase();if(a.has(t)){e.push(r);continue}if("svg"===t||"http://www.w3.org/2000/svg"===r.namespaceURI){if(Array.from(r.attributes).some(t=>l.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(r);continue}}const n=[];for(const e of r.attributes){const t=e.name.toLowerCase();l.test(t)?n.push(e.name):(c.has(t)&&g.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&n.push(e.name)}n.forEach(t=>r.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content),e.innerHTML}function h(t,e){const n=document.createElement("div");n.className="tbw-pinned-rows",n.setAttribute("role","presentation"),n.setAttribute("aria-live","polite");const r=document.createElement("div");r.className="tbw-pinned-rows-left";const o=document.createElement("div");o.className="tbw-pinned-rows-center";const i=document.createElement("div");if(i.className="tbw-pinned-rows-right",!1!==t.showRowCount){const t=document.createElement("span");t.className="tbw-status-panel tbw-status-panel-row-count",t.textContent=`Total: ${e.totalRows} rows`,r.appendChild(t)}if(t.showFilteredCount&&e.filteredRows!==e.totalRows){const t=document.createElement("span");t.className="tbw-status-panel tbw-status-panel-filtered-count",t.textContent=`Filtered: ${e.filteredRows}`,r.appendChild(t)}if(t.showSelectedCount&&e.selectedRows>0){const t=document.createElement("span");t.className="tbw-status-panel tbw-status-panel-selected-count",t.textContent=`Selected: ${e.selectedRows}`,i.appendChild(t)}if(t.customPanels)for(const s of t.customPanels){const t=w(s,e);switch(s.position){case"left":r.appendChild(t);break;case"center":o.appendChild(t);break;case"right":i.appendChild(t)}}return n.appendChild(r),n.appendChild(o),n.appendChild(i),n}function u(t){const e=document.createElement("div");return e.className=`tbw-aggregation-rows tbw-aggregation-rows-${t}`,e.setAttribute("role","presentation"),e}function p(t,e,n,r,o=!1){t.innerHTML="";for(const i of e){const e=document.createElement("div");e.className="tbw-aggregation-row",e.setAttribute("role","presentation"),i.id&&e.setAttribute("data-aggregation-id",i.id);i.fullWidth??o?f(e,i,n,r):m(e,i,n,r),t.appendChild(e)}}function f(t,e,n,r){const o=document.createElement("div");o.className="tbw-aggregation-cell tbw-aggregation-cell-full",o.style.gridColumn="1 / -1";const i="function"==typeof e.label?e.label(r,n):e.label;if(i){const t=document.createElement("span");t.className="tbw-aggregation-label",t.textContent=i,o.appendChild(t)}const s=function(t,e,n){const r=t.aggregators&&Object.keys(t.aggregators).length>0,o=t.cells&&Object.keys(t.cells).length>0;if(!r&&!o)return null;const i=document.createElement("span");i.className="tbw-aggregation-aggregates";for(const s of e){const{value:e,formatter:r}=b(t,s,n);if(null!=e){const t=document.createElement("span");t.className="tbw-aggregation-aggregate",t.setAttribute("data-field",s.field);const n=s.header??s.field,o=r?r(e,s.field,s):String(e);t.textContent=`${n}: ${o}`,i.appendChild(t)}}return i.children.length>0?i:null}(e,n,r);s&&o.appendChild(s),t.appendChild(o)}function m(t,e,n,r){for(const i of n){const n=document.createElement("div");n.className="tbw-aggregation-cell",n.setAttribute("data-field",i.field);const{value:o,formatter:s}=b(e,i,r);n.textContent=null!=o?s?s(o,i.field,i):String(o):"",t.appendChild(n)}const o="function"==typeof e.label?e.label(r,n):e.label;if(o){const e=document.createElement("span");e.className="tbw-aggregation-label",e.textContent=o,t.appendChild(e)}}function b(t,e,n){let r,o;const s=t.aggregators?.[e.field];if(s)if("object"==typeof(a=s)&&null!==a&&"aggFunc"in a){const t=i.get(s.aggFunc);t&&(r=t(n,e.field,e)),o=s.formatter}else{const t=i.get(s);t&&(r=t(n,e.field,e))}else if(t.cells&&Object.prototype.hasOwnProperty.call(t.cells,e.field)){const o=t.cells[e.field];r="function"==typeof o?o(n,e.field,e):o}var a;return{value:r,formatter:o}}function w(t,e){const n=document.createElement("div");n.className="tbw-status-panel tbw-status-panel-custom",n.id=`status-panel-${t.id}`;const r=t.render(e);return"string"==typeof r?n.innerHTML=d(r):n.appendChild(r),n}function v(t,e,n,r,o){const i=n?.sourceRows,s=n?.rows,a=Array.isArray(i)?i.length:t.length,l=Array.isArray(s)?s.length:t.length,c=a>0?a:l;return{totalRows:c,filteredRows:o?.cachedResult?.length??(l<a?l:c),selectedRows:r?.selected?.size??0,columns:e,rows:t,grid:n}}function C(){return t=>{const e=document.createElement("span");return e.className="tbw-status-panel tbw-status-panel-row-count",e.textContent=`Total: ${t.totalRows} rows`,e}}function E(){return t=>{if(t.selectedRows<=0)return null;const e=document.createElement("span");return e.className="tbw-status-panel tbw-status-panel-selected-count",e.textContent=`Selected: ${t.selectedRows}`,e}}function A(){return t=>{if(t.filteredRows===t.totalRows)return null;const e=document.createElement("span");return e.className="tbw-status-panel tbw-status-panel-filtered-count",e.textContent=`Filtered: ${t.filteredRows}`,e}}function W(t){const e=document.createElement("div");return e.className="tbw-status-panel tbw-status-panel-custom",e.appendChild(t),e}const y=/* @__PURE__ */new WeakMap;function R(t,e,n){const r=Array.isArray(t.render)?t.render:[{zone:"left",render:t.render}],o=r.map(t=>t.render(e)??null);if(n){const t=y.get(n);if(t&&t.length===o.length&&t.every((t,e)=>t===o[e]))return n}const i=document.createElement("div");i.className="tbw-pinned-rows",i.setAttribute("role","presentation"),i.setAttribute("aria-live","polite"),t.id&&i.setAttribute("data-pinned-row-id",t.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 g=0;g<r.length;g++){const t=r[g],e=o[g];if(null==e)continue;const n=t.zone??"left",i=e.classList?.contains("tbw-status-panel");c[n].appendChild(i?e:W(e))}return 0===s.children.length&&0===a.children.length&&0===l.children.length?null:(i.appendChild(s),i.appendChild(a),i.appendChild(l),y.set(i,o),i)}function x(t,e,n,r,o=!1){const i=u(e);return p(i,[t],n,r,o),i}function S(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function N(t,e,n,r){return`${S(n,r)} ${t}: ${e}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}const B={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};class k{static dependencies;static manifest;aliases;version="2.17.2";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 e={...this.userConfig},n={};for(const r of Object.keys(e))n[r]=this;for(const r of t){const t=r.userConfig;for(const[o,i]of Object.entries(t)){if(void 0===i)continue;if(!(o in e)){e[o]=i,n[o]=r;continue}if(e[o]===i)continue;const t=n[o]?.constructor.name??this.constructor.name,s=r.constructor.name,a=N("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${t} 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,e)}refreshUserConfigFrom(t){const e=this.userConfig;for(const n of Object.keys(e))delete e[n];Object.assign(e,t.userConfig)}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 n=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(n),n.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{...B,...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;if(e){return"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),n=parseInt(e,10);if(!isNaN(n))return n}return 200}setIcon(t,e,n){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const r=this.#e(e,n);void 0!==r?"string"==typeof r?t.innerHTML=d(r):r instanceof HTMLElement&&(t.innerHTML="",t.appendChild(r.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 n=document.createElement("span");n.setAttribute("part","sort-indicator"),n.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(n,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(n,"sortNone"));const r=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return r?t.insertBefore(n,r):t.appendChild(n),n}warn(t,e){void 0!==e?console.warn(N(t,e,this.gridElement.id,this.name)):console.warn(`${S(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(t,e){throw new Error(N(t,e,this.gridElement.id,this.name))}}class M extends k{name="pinnedRows";styles="@layer tbw-plugins{.tbw-scroll-area{container-type:inline-size}.tbw-footer,.tbw-header-pinned{flex-shrink:0;z-index:var(--tbw-z-layer-pinned-rows, 20);background:var(--tbw-color-panel-bg);min-width:fit-content}.tbw-pinned-rows{display:flex;align-items:center;justify-content:space-between;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));min-height:32px;box-sizing:border-box;position:sticky;left:0;min-width:0;width:100cqi}.tbw-pinned-rows+.tbw-pinned-rows{border-top:0}.tbw-pinned-rows-left,.tbw-pinned-rows-center,.tbw-pinned-rows-right{display:flex;align-items:center;gap:var(--tbw-spacing-xl, 1rem)}.tbw-pinned-rows-left{justify-content:flex-start}.tbw-pinned-rows-center{justify-content:center;flex:1}.tbw-pinned-rows-right{justify-content:flex-end}.tbw-status-panel{white-space:nowrap}.tbw-aggregation-rows{min-width:fit-content;background:var(--tbw-aggregation-bg, var(--tbw-color-header-bg))}.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{display:grid;grid-template-columns:var(--tbw-column-template);font-size:var(--tbw-aggregation-font-size, .8em);font-weight:var(--tbw-aggregation-font-weight, 600);position:relative;background:inherit}.tbw-aggregation-row>.tbw-aggregation-label{position:sticky;left:0;grid-row:1;grid-column:1;display:flex;align-items:center;padding:var(--tbw-cell-padding, .125rem .5rem);background:inherit;z-index:1;pointer-events:none}.tbw-aggregation-row>.tbw-aggregation-cell:first-child{grid-column:1;grid-row:1}.tbw-aggregation-cell:not(:empty){position:relative;z-index:2;background:inherit}.tbw-aggregation-cell{padding:var(--tbw-cell-padding, .125rem .5rem);min-height:var(--tbw-row-height, 1.75rem);display:block;align-items:center;align-content:center;border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;text-overflow:ellipsis;white-space:var(--tbw-cell-white-space, nowrap)}.tbw-aggregation-cell:last-child{border-right:0}.tbw-aggregation-cell-full{grid-column:1 / -1;border-right:0;display:flex;align-items:center;gap:var(--tbw-spacing-lg, .75rem)}.tbw-aggregation-label{white-space:nowrap}.tbw-aggregation-aggregates{display:flex;align-items:center;gap:var(--tbw-spacing-lg, .75rem);font-weight:400;opacity:.85}.tbw-aggregation-aggregate{white-space:nowrap}}";get defaultConfig(){return{position:"bottom",showRowCount:!0,showSelectedCount:!0,showFilteredCount:!0}}infoBarElement=null;topAggregationContainer=null;bottomAggregationContainer=null;footerWrapper=null;headerWrapper=null;lastModeWasSlots=!1;detach(){this.cleanup()}afterRender(){const t=this.gridElement;if(!t)return;const e=t.querySelector(".tbw-scroll-area")??t.querySelector(".tbw-grid-content")??t.querySelector(".tbw-grid-root");if(!e)return;this.footerWrapper&&!e.contains(this.footerWrapper)&&(this.footerWrapper=null,this.bottomAggregationContainer=null,this.infoBarElement=null),this.topAggregationContainer&&!e.contains(this.topAggregationContainer)&&(this.topAggregationContainer=null),this.infoBarElement&&!e.contains(this.infoBarElement)&&(this.infoBarElement=null),this.headerWrapper&&!e.contains(this.headerWrapper)&&(this.headerWrapper=null);const n=this.getSelectionState(),r=this.getFilterState(),o=v(this.sourceRows,this.columns,this.gridElement,n,r);this.config.slots?this.renderSlotMode(e,t,o):this.renderLegacyMode(e,t,o)}renderSlotMode(t,e,n){this.lastModeWasSlots||this.detachLegacyOnly(),this.lastModeWasSlots=!0;const r=this.config.slots??[],o=r.filter(t=>"top"===t.position),i=r.filter(t=>"top"!==t.position);o.length>0?(this.headerWrapper||(this.headerWrapper=document.createElement("div"),this.headerWrapper.className="tbw-header-pinned",t.insertBefore(this.headerWrapper,t.firstChild)),this.populateSlotWrapper(this.headerWrapper,o,"top",n)):this.headerWrapper&&(this.headerWrapper.remove(),this.headerWrapper=null),i.length>0?(this.footerWrapper||(this.footerWrapper=document.createElement("div"),this.footerWrapper.className="tbw-footer",t.appendChild(this.footerWrapper)),this.populateSlotWrapper(this.footerWrapper,i,"bottom",n)):this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null)}populateSlotWrapper(t,e,n,r){const o=/* @__PURE__ */new Map;for(let a=0;a<t.children.length;a++){const e=t.children[a],n=e.getAttribute("data-pinned-row-id");n&&o.set(n,e)}const i=[];for(const a of e){const t="render"in a&&null!=a.render?R(a,r,a.id?o.get(a.id)??null:null):x(a,n,this.visibleColumns,this.sourceRows,this.config.fullWidth);t&&i.push(t)}const s=t.children;if(s.length===i.length){let t=!0;for(let e=0;e<i.length;e++)if(s[e]!==i[e]){t=!1;break}if(t)return}t.replaceChildren(...i)}renderLegacyMode(t,e,n){this.lastModeWasSlots&&(this.headerWrapper&&(this.headerWrapper.remove(),this.headerWrapper=null),this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null),this.bottomAggregationContainer=null,this.infoBarElement=null),this.lastModeWasSlots=!1;const r=this.config.aggregationRows||[],o=r.filter(t=>"top"===t.position),i=r.filter(t=>"top"!==t.position);o.length>0?(this.topAggregationContainer||(this.topAggregationContainer=u("top"),t.insertBefore(this.topAggregationContainer,t.firstChild)),p(this.topAggregationContainer,o,this.visibleColumns,this.sourceRows,this.config.fullWidth)):this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null);const s=!1!==this.config.showRowCount||this.config.showSelectedCount&&n.selectedRows>0||this.config.showFilteredCount&&n.filteredRows!==n.totalRows||this.config.customPanels&&this.config.customPanels.length>0,a=s&&"top"!==this.config.position,l=i.length>0||a;if(s&&"top"===this.config.position)if(this.infoBarElement){const t=h(this.config,n);this.infoBarElement.replaceWith(t),this.infoBarElement=t}else this.infoBarElement=h(this.config,n),t.insertBefore(this.infoBarElement,t.firstChild);else"top"===this.config.position&&this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null);l?(this.footerWrapper||(this.footerWrapper=document.createElement("div"),this.footerWrapper.className="tbw-footer",t.appendChild(this.footerWrapper)),this.footerWrapper.innerHTML="",i.length>0&&(this.bottomAggregationContainer||(this.bottomAggregationContainer=u("bottom")),this.footerWrapper.appendChild(this.bottomAggregationContainer),p(this.bottomAggregationContainer,i,this.visibleColumns,this.sourceRows,this.config.fullWidth)),a&&(this.infoBarElement=h(this.config,n),this.footerWrapper.appendChild(this.infoBarElement))):this.cleanupFooter()}cleanup(){this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null),this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null),this.headerWrapper&&(this.headerWrapper.remove(),this.headerWrapper=null)}detachLegacyOnly(){this.topAggregationContainer&&(this.topAggregationContainer.remove(),this.topAggregationContainer=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null),this.infoBarElement&&(this.infoBarElement.remove(),this.infoBarElement=null)}cleanupFooter(){this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null),this.bottomAggregationContainer&&(this.bottomAggregationContainer.remove(),this.bottomAggregationContainer=null),this.infoBarElement&&"top"!==this.config.position&&(this.infoBarElement.remove(),this.infoBarElement=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 t=this.getSelectionState(),e=this.getFilterState();return v(this.rows,this.columns,this.gridElement,t,e)}addPanel(t){this.config.customPanels||(this.config.customPanels=[]),this.config.customPanels.push(t),this.requestRender()}removePanel(t){this.config.customPanels&&(this.config.customPanels=this.config.customPanels.filter(e=>e.id!==t),this.requestRender())}addAggregationRow(t){this.config.aggregationRows||(this.config.aggregationRows=[]),this.config.aggregationRows.push(t),this.requestRender()}removeAggregationRow(t){this.config.aggregationRows&&(this.config.aggregationRows=this.config.aggregationRows.filter(e=>e.id!==t),this.requestRender())}}export{M as PinnedRowsPlugin,A as filteredCountPanel,C as rowCountPanel,E as selectedCountPanel};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,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;const o="effectiveConfig"in e?e.effectiveConfig:void 0;if(!1===o?.a11y?.announcements)return;const i=e.querySelector?.(".tbw-sr-only");i&&(i.textContent="",requestAnimationFrame(()=>{i.textContent=t}))}function i(t,o,...i){const r=t&&"effectiveConfig"in t?t.effectiveConfig:void 0,n=r?.a11y?.messages?.[o];return n?n(...i):e[o](...i)}function 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)}`}const 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(""));new RegExp(`__(proto|defineGetter|defineSetter)|${s.slice(3).join("|")}|this\\b`);const a=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){if(Array.from(i.attributes).some(e=>l.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(i);continue}}const o=[];for(const t of i.attributes){const e=t.name.toLowerCase();l.test(e)?o.push(t.name):(d.has(e)&&c.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&o.push(t.name)}o.forEach(e=>i.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}class p{static dependencies;static manifest;aliases;version="2.17.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;for(const o of Object.keys(t))delete t[o];Object.assign(t,e.userConfig)}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;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),o=parseInt(t,10);if(!isNaN(o))return o}return 200}setIcon(e,t,o){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const i=this.#t(t,o);void 0!==i?"string"==typeof i?e.innerHTML=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))}}const g={sum:e=>{let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t},avg:e=>{if(!e.length)return 0;let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t/e.length},count:e=>e.length,min:e=>{if(!e.length)return 0;let t=e[0];for(let o=1;o<e.length;o++)e[o]<t&&(t=e[o]);return t},max:e=>{if(!e.length)return 0;let t=e[0];for(let o=1;o<e.length;o++)e[o]>t&&(t=e[o]);return t},first:e=>e[0]??0,last:e=>e[e.length-1]??0};function h(e){return"function"==typeof e?e:function(e){return g[e]??g.sum}(e)}function v(e,t){return[...e,t].join("|")}function f(e,t){const o=t.rowGroupFields??[],i=t.columnGroupFields??[],r=t.valueFields??[],n=function(e,t,o="asc"){if(0===t.length)return["value"];const i=/* @__PURE__ */new Set;for(const n of e){const e=t.map(e=>String(n[e]??"")).join("|");i.add(e)}const r=[...i].sort();return"desc"===o?r.reverse():r}(e,i,t.sortColumns),s=m(e,o,i,n,r,0,"");t.sortRows&&F(s,t.sortRows,r);const a=function(e,t,o){const i={};function r(e){for(const n of e)if(n.isGroup&&n.children?.length)n.children&&r(n.children);else for(const e of t)for(const t of o){const o=v([e],t.field);i[o]=(i[o]??0)+(n.values[o]??0)}}return r(e),i}(s,n,r);return{rows:s,columnKeys:n,totals:a,grandTotal:Object.values(a).reduce((e,t)=>e+t,0)}}function m(e,t,o,i,r,n,s){const a=[];if(0===t.length){const t=b(e,o,i,r),l=w(t);return a.push({rowKey:s||"all",rowLabel:s||"All",depth:n,values:t,total:l,isGroup:!1,rowCount:e.length}),a}const l=t[0],d=t.slice(1),c=d.length>0,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)=>{if("value"===t.by){if(t.valueField??o[0]?.field){return((e.total??0)-(r.total??0))*i}}return e.rowLabel.localeCompare(r.rowLabel)*i});for(const r of e)r.children?.length&&F(r.children,t,o)}function y(e,t,o){if(0===t.length)return;const i=new Set(o.map(e=>e.field)),r=t.map(e=>"value"===e.by?e.valueField?t=>((e,t)=>{if(null!=e.values[t])return"number"==typeof e.values[t]?e.values[t]:0;if(i.has(t)){const o=`|${t}`;let i=0,r=!1;for(const t of Object.keys(e.values))t.endsWith(o)&&(i+="number"==typeof e.values[t]?e.values[t]:0,r=!0);if(r)return i}return e.total??0})(t,e.valueField):e=>e.total??0:null);e.sort((e,o)=>{for(let i=0;i<t.length;i++){const n=t[i],s="desc"===n.direction?-1:1;let a=0;if("value"===n.by){const t=r[i];a=(t(e)-t(o))*s}else a=e.rowLabel.localeCompare(o.rowLabel)*s;if(0!==a)return a}return 0});for(const n of e)n.children?.length&&y(n.children,t,o)}const x="dragging",_=["sum","avg","count","min","max","first","last"];function A(e,t,o,i){const r=new AbortController,n={config:t,callbacks:i,signal:r.signal},s=document.createElement("div");return s.className="tbw-pivot-panel",s.appendChild(T("Options",()=>function(e,t){const{config:o,callbacks:i,signal:r}=t,n=document.createElement("div");return n.className="tbw-pivot-options",n.appendChild(R("Enable Pivot View",e,e=>{i.onTogglePivot(e)},r)),n.appendChild(R("Show Row Totals",o.showTotals??!0,e=>{i.onOptionChange("showTotals",e)},r)),n.appendChild(R("Show Grand Total",o.showGrandTotal??!0,e=>{i.onOptionChange("showGrandTotal",e)},r)),n}(o,n))),s.appendChild(T("Row Groups",()=>E("rowGroups",n))),s.appendChild(T("Column Groups",()=>E("columnGroups",n))),s.appendChild(T("Values",()=>function(e){const{config:t,callbacks:o,signal:i}=e,r=document.createElement("div");r.className="tbw-pivot-drop-zone tbw-pivot-values-zone",r.setAttribute("data-zone","values");const n=t.valueFields??[];if(0===n.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="Drag numeric fields here",r.appendChild(e)}else for(const s of n)r.appendChild(G(s,e));return r.addEventListener("dragover",e=>{e.preventDefault(),r.classList.add("drag-over")},{signal:i}),r.addEventListener("dragleave",()=>{r.classList.remove("drag-over")},{signal:i}),r.addEventListener("drop",e=>{e.preventDefault(),r.classList.remove("drag-over");const t=e.dataTransfer?.getData("text/plain");t&&o.onAddValueField(t,"sum")},{signal:i}),r}(n))),s.appendChild(T("Available Fields",()=>function(e){const{config:t,callbacks:o,signal:i}=e,r=document.createElement("div");r.className="tbw-pivot-available-fields";const n=o.getAvailableFields(),s=/* @__PURE__ */new Set([...t.rowGroupFields??[],...t.columnGroupFields??[],...t.valueFields?.map(e=>e.field)??[]]),a=n.filter(e=>!s.has(e.field));if(0===a.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="All fields are in use",r.appendChild(e)}else{const e=document.createElement("div");if(e.className="tbw-pivot-fields-list",a.length>=6){const t=document.createElement("input");t.type="text",t.placeholder="Filter fields…",t.className="tbw-pivot-field-search",t.addEventListener("input",()=>{const o=t.value.toLowerCase();for(const t of e.querySelectorAll(".tbw-pivot-field-chip")){const e=t;e.style.display=e.textContent?.toLowerCase().includes(o)?"":"none"}},{signal:i}),r.appendChild(t)}for(const t of a){const o=document.createElement("div");o.className="tbw-pivot-field-chip available",o.textContent=t.header,o.draggable=!0,o.title=`Drag to add "${t.field}" to a zone`,o.addEventListener("dragstart",e=>{e.dataTransfer?.setData("text/plain",t.field),o.classList.add(x)},{signal:i}),o.addEventListener("dragend",()=>{o.classList.remove(x)},{signal:i}),e.appendChild(o)}r.appendChild(e)}return r}(n))),e.appendChild(s),()=>{r.abort(),s.remove()}}function T(e,t){const o=document.createElement("div");o.className="tbw-pivot-section";const i=document.createElement("div");i.className="tbw-pivot-section-header",i.textContent=e;const r=document.createElement("div");return r.className="tbw-pivot-section-content",r.appendChild(t()),o.appendChild(i),o.appendChild(r),o}function E(e,t){const{config:o,callbacks:i,signal:r}=t,n=document.createElement("div");n.className="tbw-pivot-drop-zone",n.setAttribute("data-zone",e);const s="rowGroups"===e?o.rowGroupFields??[]:o.columnGroupFields??[];if(0===s.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="Drag fields here",n.appendChild(e)}else for(const a of s)n.appendChild(S(a,e,t));return n.addEventListener("dragover",e=>{e.preventDefault(),n.classList.add("drag-over")},{signal:r}),n.addEventListener("dragleave",()=>{n.classList.remove("drag-over")},{signal:r}),n.addEventListener("drop",t=>{t.preventDefault(),n.classList.remove("drag-over");const o=t.dataTransfer?.getData("text/plain"),r=t.dataTransfer?.getData("source-zone");if(!o)return;const s=n.querySelectorAll(".tbw-pivot-field-chip");let a=s.length;for(let e=0;e<s.length;e++){const o=s[e].getBoundingClientRect();if(t.clientY<o.top+o.height/2){a=e;break}}!r||r===e||"rowGroups"!==r&&"columnGroups"!==r?r===e?i.onReorderFieldInZone(o,e,a):i.onAddFieldToZone(o,e):i.onMoveFieldBetweenZones(o,r,e)},{signal:r}),n}function S(e,t,o){const{callbacks:i,signal:r}=o,n=document.createElement("div");n.className="tbw-pivot-field-chip",n.draggable=!0;const s=i.getAvailableFields().find(t=>t.field===e),a=document.createElement("span");a.className="tbw-pivot-chip-label",a.textContent=s?.header??e;const l=document.createElement("button");return l.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}class P 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{display:grid;grid-template-columns:var(--tbw-column-template);font-weight:600;background:var(--tbw-pivot-group-bg, var(--tbw-color-row-alt));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider)}@media(hover:hover){.pivot-group-row:hover{background:var(--tbw-pivot-group-hover, var(--tbw-color-row-hover))}}.pivot-leaf-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-pivot-leaf-bg, var(--tbw-color-bg));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider)}.pivot-grand-total-row{display:grid;grid-template-columns:var(--tbw-column-template);font-weight:700;background:var(--tbw-pivot-grand-total-bg, var(--tbw-color-header-bg));min-height:var(--tbw-row-height);border-top:2px solid var(--tbw-color-border-strong)}.pivot-grand-total-row>.cell{display:flex;align-items:center;padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}.pivot-grand-total-row>.cell:last-child{border-right:0}.pivot-grand-total-footer{position:sticky;bottom:0;z-index:var(--tbw-z-layer-pinned-rows, 20);background:var(--tbw-pivot-grand-total-bg, var(--tbw-color-header-bg));min-width:fit-content}.pivot-group-row>.cell,.pivot-leaf-row>.cell{display:flex;align-items:center;padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}.pivot-group-row>.cell:last-child,.pivot-leaf-row>.cell:last-child{border-right:0}.pivot-toggle{display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-pivot-toggle-size, var(--tbw-toggle-size, 1.25em));height:var(--tbw-pivot-toggle-size, var(--tbw-toggle-size, 1.25em));margin-right:var(--tbw-spacing-sm, .375em);border:none;background:transparent;cursor:pointer;color:var(--tbw-pivot-toggle-color, var(--tbw-color-fg-muted));border-radius:var(--tbw-border-radius);transition:background var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease),color var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease)}.pivot-toggle:hover{background:var(--tbw-pivot-toggle-hover-bg, var(--tbw-color-row-hover));color:var(--tbw-pivot-toggle-hover-color, var(--tbw-color-fg))}.pivot-toggle:focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}.pivot-label{font-weight:inherit}.pivot-count{color:var(--tbw-pivot-count-color, var(--tbw-color-fg-muted));font-size:.9em;font-weight:400}.pivot-total-row{font-weight:700;border-top:2px solid var(--tbw-pivot-border, var(--tbw-color-border-strong))}[data-pivot-depth="1"]{--tbw-pivot-depth: 1}[data-pivot-depth="2"]{--tbw-pivot-depth: 2}[data-pivot-depth="3"]{--tbw-pivot-depth: 3}[data-pivot-depth="4"]{--tbw-pivot-depth: 4}.tbw-pivot-panel{display:flex;flex-direction:column;gap:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));padding:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));height:100%;overflow-y:auto;font-size:var(--tbw-font-size-sm, .8125rem)}.tbw-pivot-section{border:1px solid var(--tbw-pivot-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);background:var(--tbw-pivot-section-bg, var(--tbw-color-bg))}.tbw-pivot-section-header{padding:var(--tbw-button-padding, var(--tbw-spacing-md, .5rem) var(--tbw-spacing-lg, .75rem));font-weight:600;background:var(--tbw-pivot-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-pivot-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius) var(--tbw-border-radius) 0 0}.tbw-pivot-section-content{padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-pivot-toggle-wrapper{display:flex;align-items:center}.tbw-pivot-toggle-label{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));cursor:pointer}.tbw-pivot-toggle-label input{width:var(--tbw-icon-size, 1rem);height:var(--tbw-icon-size, 1rem);cursor:pointer}.tbw-pivot-drop-zone{min-height:60px;padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border:2px dashed var(--tbw-pivot-drop-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);background:var(--tbw-pivot-drop-bg, var(--tbw-color-row-alt));display:flex;flex-wrap:wrap;gap:var(--tbw-spacing-sm, .375rem);align-content:flex-start;transition:all .15s ease}.tbw-pivot-drop-zone.drag-over{border-color:var(--tbw-color-accent);background:var(--tbw-pivot-drop-active, var(--tbw-focus-background))}.tbw-pivot-placeholder{color:var(--tbw-color-fg-muted);font-style:italic;padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));text-align:center;width:100%}.tbw-pivot-field-chip{display:inline-flex;align-items:center;gap:var(--tbw-spacing-sm, .375rem);padding:var(--tbw-button-padding-sm, var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-md, .5rem));background:var(--tbw-pivot-chip-bg, var(--tbw-color-header-bg));border:1px solid var(--tbw-pivot-chip-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);cursor:grab;font-size:var(--tbw-font-size-xs, .75rem);transition:all .15s ease}.tbw-pivot-field-chip:hover{background:var(--tbw-pivot-chip-hover, var(--tbw-color-row-hover));border-color:var(--tbw-color-accent)}.tbw-pivot-field-chip.available{background:var(--tbw-color-bg)}.tbw-pivot-field-chip.dragging{opacity:.5;cursor:grabbing}.tbw-pivot-chip-label{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:120px}.tbw-pivot-chip-remove{display:flex;align-items:center;justify-content:center;width:var(--tbw-icon-size, 1rem);height:var(--tbw-icon-size, 1rem);padding:0;border:none;background:transparent;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-sm, .875rem);font-weight:700;cursor:pointer;border-radius:50%;transition:all .15s ease}.tbw-pivot-chip-remove:hover{background:var(--tbw-pivot-chip-remove-hover-bg, var(--tbw-color-accent));color:var(--tbw-pivot-chip-remove-hover-fg, var(--tbw-color-accent-fg))}.tbw-pivot-value-chip{padding:var(--tbw-button-padding-sm, var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-md, .5rem))}.tbw-pivot-value-label-wrapper{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));flex:1;min-width:0}.tbw-pivot-agg-select{padding:var(--tbw-spacing-xs, .125rem) var(--tbw-spacing-xs, .25rem);font-size:var(--tbw-font-size-xs, .6875rem);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);cursor:pointer}.tbw-pivot-available-fields{display:flex;flex-direction:column;gap:var(--tbw-spacing-sm, .375rem);min-height:40px}.tbw-pivot-field-search{width:100%;padding:.25rem .5rem;border:1px solid var(--tbw-color-border, #d0d5dd);border-radius:var(--tbw-radius-sm, .25rem);font-size:var(--tbw-font-size-sm, .875rem);background:var(--tbw-color-bg, #fff);color:var(--tbw-color-fg, #1a1a2e);outline:none}.tbw-pivot-field-search:focus{border-color:var(--tbw-color-primary, #3b82f6)}.tbw-pivot-fields-list{display:flex;flex-wrap:wrap;gap:var(--tbw-spacing-sm, .375rem)}.tbw-pivot-options{display:flex;flex-direction:column;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-pivot-checkbox{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));cursor:pointer}.tbw-pivot-checkbox input{width:var(--tbw-icon-size-sm, .875rem);height:var(--tbw-icon-size-sm, .875rem);cursor:pointer}.pivot-group-row.tbw-pivot-slide-in,.pivot-leaf-row.tbw-pivot-slide-in{animation:tbw-pivot-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-pivot-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.pivot-group-row.tbw-pivot-fade-in,.pivot-leaf-row.tbw-pivot-fade-in{animation:tbw-pivot-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-pivot-fade-in{0%{opacity:0}to{opacity:1}}}';static PANEL_ID="pivot";get defaultConfig(){return{active:!0,showTotals:!0,showGrandTotal:!0,showToolPanel:!0,animation:"slide"}}isActive=!1;hasInitialized=!1;pivotResult=null;fieldHeaderMap=/* @__PURE__ */new Map;expandedKeys=/* @__PURE__ */new Set;defaultExpanded=!0;userHasToggledExpand=!1;originalColumns=[];panelContainer=null;grandTotalFooter=null;previousVisibleKeys=/* @__PURE__ */new Set;keysToAnimate=/* @__PURE__ */new Set;valueFormatters=/* @__PURE__ */new Map;columnTotals={};activeSortField=null;activeSortDir=null;hasValidPivotConfig(){return(this.config.valueFields?.length??0)>0}get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}detach(){this.isActive=!1,this.hasInitialized=!1,this.pivotResult=null,this.fieldHeaderMap.clear(),this.originalColumns=[],this.panelContainer=null,this.cleanupGrandTotalFooter(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.userHasToggledExpand=!1,this.valueFormatters.clear(),this.columnTotals={},this.activeSortField=null,this.activeSortDir=null,this.config.sortRows=void 0}getToolPanel(){if(!1!==(this.config?.showToolPanel??this.userConfig?.showToolPanel??!0))return{id:P.PANEL_ID,title:"Pivot",icon:"⊞",tooltip:"Configure pivot table",order:90,render:e=>this.renderPanel(e)}}processRows(e){if(!this.hasInitialized&&!1!==this.config.active&&this.hasValidPivotConfig()&&(this.hasInitialized=!0,this.isActive=!0),!this.isActive)return[...e];const t=function(e){const t=[];return e.rowGroupFields?.length||e.columnGroupFields?.length||t.push("At least one row or column group field is required"),e.valueFields?.length||t.push("At least one value field is required"),t}(this.config);if(t.length>0)return this.warn(`Config errors: ${t.join(", ")}`),[...e];this.buildFieldHeaderMap(),this.buildValueFormatters(),this.defaultExpanded=this.config.defaultExpanded??!0,this.pivotResult=f(e,this.config);const o=this.getMultiSortConfigs();if(o&&y(this.pivotResult.rows,o,this.config.valueFields??[]),0===this.expandedKeys.size&&!this.userHasToggledExpand){const e=C(this.pivotResult.rows);this.expandedKeys=function(e,t){if(!0===e||void 0===e)return new Set(t);if(!1===e)/* @__PURE__ */return new Set;if("number"==typeof e){const o=t[e];return o?/* @__PURE__ */new Set([o]):/* @__PURE__ */new Set}return"string"==typeof e?/* @__PURE__ */new Set([e]):Array.isArray(e)?new Set(e):/* @__PURE__ */new Set}(this.defaultExpanded,e)}this.config.valueDisplayMode&&"raw"!==this.config.valueDisplayMode&&(this.columnTotals=function(e,t,o){const i={};return function e(r){for(const n of r)if(n.isGroup&&n.children?.length)n.children&&e(n.children);else for(const e of t)for(const t of o){const o=v([e],t.field);i[o]=(i[o]??0)+(n.values[o]??0)}}(e),i}(this.pivotResult.rows,this.pivotResult.columnKeys,this.config.valueFields??[]));const i=this.config.indentWidth??20,r=!0===this.defaultExpanded||void 0===this.defaultExpanded,n=function(e,t,o=!0){const i=[];function r(e){i.push(e);const n=t?t.has(e.rowKey):o;if(e.children&&n)for(const t of e.children)r(t)}for(const n of e)r(n);return i}(this.pivotResult.rows,this.expandedKeys,r).map(e=>({__pivotRowKey:e.rowKey,__pivotLabel:e.rowLabel,__pivotDepth:e.depth,__pivotIsGroup:e.isGroup,__pivotHasChildren:Boolean(e.children?.length),__pivotExpanded:this.expandedKeys.has(e.rowKey),__pivotRowCount:e.rowCount??0,__pivotIndent:e.depth*i,__pivotTotal:e.total,...e.values}));this.keysToAnimate.clear();const s=/* @__PURE__ */new Set;for(const a of n){const e=a.__pivotRowKey;s.add(e),!this.previousVisibleKeys.has(e)&&a.__pivotDepth>0&&this.keysToAnimate.add(e)}return this.previousVisibleKeys=s,this.config.grandTotalInRowModel&&this.config.showGrandTotal&&this.pivotResult&&n.push({__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotDepth:0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals}),n}processColumns(e){if(!this.isActive||!this.pivotResult)return[...e];const t=[],o=(this.config.rowGroupFields??[]).map(e=>this.fieldHeaderMap.get(e)??e).join(" / ");t.push({field:"__pivotLabel",header:o||"Group",width:200,sortable:!0});for(const i of this.pivotResult.columnKeys)for(const e of this.config.valueFields??[]){const o=v([i],e.field),r=e.header||this.fieldHeaderMap.get(e.field)||e.field,n="function"==typeof e.aggFunc?"custom":e.aggFunc,s=this.valueFormatters.get(e.field);t.push({field:o,header:`${i} - ${r} (${n})`,width:120,type:"number",sortable:!0,...s?{format:e=>null!=e?s(Number(e)):""}:{}})}return this.config.showTotals&&t.push({field:"__pivotTotal",header:"Total",width:100,type:"number",sortable:!0}),t}renderRow(e,t,o){const i=e;return i.__pivotIsGrandTotal?L(i,t,this.gridColumns):i.__pivotRowKey&&i.__pivotHasChildren?function(e,t,o){return t.className="data-grid-row pivot-group-row",t.setAttribute("data-pivot-depth",String(e.__pivotDepth??0)),t.setAttribute("data-pivot-key",String(e.__pivotRowKey??"")),t.setAttribute("role","row"),t.innerHTML="",o.columns.forEach((i,r)=>{const n=document.createElement("div");if(n.className="cell",n.setAttribute("data-col",String(r)),n.setAttribute("data-row",String(o.rowIndex)),n.setAttribute("role","gridcell"),0===r){const t=Number(e.__pivotIndent)||0;n.style.paddingLeft=`${t}px`;const i=String(e.__pivotRowKey),r=document.createElement("button");r.type="button",r.className="pivot-toggle",r.setAttribute("aria-label",e.__pivotExpanded?"Collapse group":"Expand group"),o.setIcon(r,e.__pivotExpanded?"collapse":"expand"),r.addEventListener("click",e=>{e.stopPropagation(),o.onToggle(i)}),n.appendChild(r);const s=document.createElement("span");s.className="pivot-label",s.textContent=String(e.__pivotLabel??""),n.appendChild(s);const a=document.createElement("span");a.className="pivot-count",a.textContent=` (${Number(e.__pivotRowCount)||0})`,n.appendChild(a)}else{const t=e[i.field];n.textContent=null!=t?i.format?i.format(t,e):String(t):""}t.appendChild(n)}),!0}(i,t,{columns:this.gridColumns,rowIndex:o,onToggle:e=>this.toggle(e),setIcon:(e,t)=>this.setIcon(e,t)}):void 0!==i.__pivotRowKey&&this.isActive?function(e,t,o,i){return t.className="data-grid-row pivot-leaf-row",t.setAttribute("data-pivot-depth",String(e.__pivotDepth??0)),t.setAttribute("data-pivot-key",String(e.__pivotRowKey??"")),t.innerHTML="",o.forEach((o,r)=>{const n=document.createElement("div");if(n.className="cell",n.setAttribute("data-col",String(r)),n.setAttribute("data-row",String(i)),n.setAttribute("role","gridcell"),0===r){const t=Number(e.__pivotIndent)||0;n.style.paddingLeft=`${t+20}px`;const o=document.createElement("span");o.className="pivot-label",o.textContent=String(e.__pivotLabel??""),n.appendChild(o)}else{const t=e[o.field];n.textContent=null!=t?o.format?o.format(t,e):String(t):""}t.appendChild(n)}),!0}(i,t,this.gridColumns,o):(this.cleanupPivotStyling(t),!1)}cleanupPivotStyling(e){(e.classList.contains("pivot-group-row")||e.classList.contains("pivot-leaf-row")||e.classList.contains("pivot-grand-total-row"))&&(e.classList.remove("pivot-group-row","pivot-leaf-row","pivot-grand-total-row"),e.classList.add("data-grid-row"),e.removeAttribute("data-pivot-depth"),e.innerHTML="")}onKeyDown(e){if(" "!==e.key)return;if(!this.isActive)return;const t=this.grid._focusRow,o=this.rows[t];return o?.__pivotIsGroup&&o.__pivotHasChildren?(e.preventDefault(),this.toggle(o.__pivotRowKey),this.requestRenderWithFocus(),!0):void 0}handleQuery(e){if("sort:get-sort-config"===e.type){const e=this.getMultiSortConfigs();return e||(this.config.sortRows??null)}}onHeaderClick(e){if(!this.isActive)return!1;const t=e.field;if(!this.isPivotField(t))return!1;if(this.isMultiSortActive())return!1;const 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");if(!t)return;this.grandTotalFooter||(this.grandTotalFooter=document.createElement("div"),this.grandTotalFooter.className="pivot-grand-total-footer",t.appendChild(this.grandTotalFooter));L({__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals},this.grandTotalFooter,this.gridColumns),this.grandTotalFooter.setAttribute("role","presentation")}cleanupGrandTotalFooter(){this.grandTotalFooter&&(this.grandTotalFooter.remove(),this.grandTotalFooter=null)}toggle(e){this.userHasToggledExpand=!0;const t=this.expandedKeys.has(e);t?this.expandedKeys.delete(e):this.expandedKeys.add(e),this.emitToggle(e,!t),this.requestRender()}expand(e){this.userHasToggledExpand=!0,this.expandedKeys.add(e),this.emitToggle(e,!0),this.requestRender()}collapse(e){this.userHasToggledExpand=!0,this.expandedKeys.delete(e),this.emitToggle(e,!1),this.requestRender()}expandAll(){this.userHasToggledExpand=!0,this.expandAllKeys(),this.requestRender()}collapseAll(){this.userHasToggledExpand=!0,this.expandedKeys.clear(),this.requestRender()}expandAllKeys(){if(!this.pivotResult)return;const e=C(this.pivotResult.rows);for(const t of e)this.expandedKeys.add(t)}isExpanded(e){return this.expandedKeys.has(e)}getExpandedGroups(){return[...this.expandedKeys]}enablePivot(){0===this.originalColumns.length&&this.captureOriginalColumns(),this.isActive=!0,this.emit("pivot-state-change",{active:!0}),this.requestRender()}disablePivot(){this.isActive=!1,this.pivotResult=null,this.emit("pivot-state-change",{active:!1}),this.requestRender()}isPivotActive(){return this.isActive}getPivotResult(){return this.pivotResult}setRowGroupFields(e){this.config.rowGroupFields=e,this.emitConfigChange("rowGroupFields"),this.refresh()}setColumnGroupFields(e){this.config.columnGroupFields=e,this.emitConfigChange("columnGroupFields"),this.refresh()}setValueFields(e){this.config.valueFields=e,this.emitConfigChange("valueFields"),this.refresh()}refresh(){this.pivotResult=null,this.requestRender()}showPanel(){this.grid.openToolPanel(),this.grid.expandedToolPanelSections.includes(P.PANEL_ID)||this.grid.toggleToolPanelSection(P.PANEL_ID)}hidePanel(){this.grid.closeToolPanel()}togglePanel(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection(P.PANEL_ID)}isPanelVisible(){return this.grid.isToolPanelOpen&&this.grid.expandedToolPanelSections.includes(P.PANEL_ID)}get gridColumns(){return this.grid.columns??[]}refreshIfActive(){this.isActive&&this.refresh(),this.refreshPanel()}buildFieldHeaderMap(){const e=this.getAvailableFields();this.fieldHeaderMap.clear();for(const t of e)this.fieldHeaderMap.set(t.field,t.header)}getAvailableFields(){return this.originalColumns.length>0?this.originalColumns:this.captureOriginalColumns()}captureOriginalColumns(){try{const e=this.grid.getAllColumns?.()??this.grid.columns??[];return this.originalColumns=e.filter(e=>!e.field.startsWith("__pivot")).map(e=>({field:e.field,header:e.header??e.field})),this.originalColumns}catch{return[]}}renderPanel(e){this.panelContainer=e,0===this.originalColumns.length&&this.captureOriginalColumns();const t={onTogglePivot:e=>{e?this.enablePivot():this.disablePivot(),this.refreshPanel()},onAddFieldToZone:(e,t)=>{this.addFieldToZone(e,t),this.emitConfigChange("rowGroups"===t?"rowGroupFields":"columnGroupFields",e,t)},onRemoveFieldFromZone:(e,t)=>{this.removeFieldFromZone(e,t),this.emitConfigChange("rowGroups"===t?"rowGroupFields":"columnGroupFields",e,t)},onReorderFieldInZone:(e,t,o)=>{this.reorderFieldInZone(e,t,o),this.emitConfigChange("rowGroups"===t?"rowGroupFields":"columnGroupFields",e,t)},onMoveFieldBetweenZones:(e,t,o)=>{this.moveFieldBetweenZones(e,t,o),this.emitConfigChange("rowGroups"===o?"rowGroupFields":"columnGroupFields",e,o)},onAddValueField:(e,t)=>{this.addValueField(e,t),this.emitConfigChange("valueFields",e,"values")},onRemoveValueField:e=>{this.removeValueField(e),this.emitConfigChange("valueFields",e,"values")},onUpdateValueAggFunc:(e,t)=>{this.updateValueAggFunc(e,t),this.emitConfigChange("valueFields",e,"values")},onOptionChange:(e,t)=>{this.config[e]=t,this.emitConfigChange(e),this.isActive&&this.refresh()},getAvailableFields:()=>this.getAvailableFields()};return A(e,this.config,this.isActive,t)}refreshPanel(){this.panelContainer&&(this.panelContainer.innerHTML="",this.renderPanel(this.panelContainer))}addFieldToZone(e,t){if("rowGroups"===t){const t=this.config.rowGroupFields??[];t.includes(e)||(this.config.rowGroupFields=[...t,e])}else{const t=this.config.columnGroupFields??[];t.includes(e)||(this.config.columnGroupFields=[...t,e])}this.removeFromOtherZones(e,t),this.refreshIfActive()}removeFieldFromZone(e,t){"rowGroups"===t?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e),this.refreshIfActive()}reorderFieldInZone(e,t,o){const i="rowGroups"===t?[...this.config.rowGroupFields??[]]:[...this.config.columnGroupFields??[]],r=i.indexOf(e);-1!==r&&r!==o&&(i.splice(r,1),i.splice(o>r?o-1:o,0,e),"rowGroups"===t?this.config.rowGroupFields=i:this.config.columnGroupFields=i,this.refreshIfActive())}moveFieldBetweenZones(e,t,o){"rowGroups"===t?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e),"rowGroups"===o?this.config.rowGroupFields=[...this.config.rowGroupFields??[],e]:this.config.columnGroupFields=[...this.config.columnGroupFields??[],e],this.refreshIfActive()}removeFromOtherZones(e,t){"rowGroups"!==t&&(this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e)),"columnGroups"!==t&&(this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e)),"values"!==t&&(this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e))}addValueField(e,t){const o=this.config.valueFields??[];o.some(t=>t.field===e)||(this.config.valueFields=[...o,{field:e,aggFunc:t}]),this.removeFromOtherZones(e,"values"),this.refreshIfActive()}removeValueField(e){this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e),this.refreshIfActive()}updateValueAggFunc(e,t){const o=this.config.valueFields??[],i=o.findIndex(t=>t.field===e);i>=0&&(o[i]={...o[i],aggFunc:t},this.config.valueFields=[...o]),this.isActive&&this.refresh()}emitToggle(e,t){const o=this.rows.find(t=>t.__pivotRowKey===e);this.emit("pivot-toggle",{key:e,expanded:t,label:o?.__pivotLabel??e,depth:o?.__pivotDepth??0})}emitConfigChange(e,t,o){this.emit("pivot-config-change",{property:e,field:t,zone:o})}buildValueFormatters(){this.valueFormatters.clear();const e=this.config.valueFields??[];for(const t of e)if(t.format)this.valueFormatters.set(t.field,t.format);else{if(this.originalColumns.find(e=>e.field===t.field)){const e=(this.grid.getAllColumns?.()??this.grid.columns??[]).find(e=>e.field===t.field);if(e?.format){const o=e.format;this.valueFormatters.set(t.field,e=>o(e,{}))}}}}}export{P as PivotPlugin};
|
|
1
|
+
const e={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,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;const o="effectiveConfig"in e?e.effectiveConfig:void 0;if(!1===o?.a11y?.announcements)return;const i=e.querySelector?.(".tbw-sr-only");i&&(i.textContent="",requestAnimationFrame(()=>{i.textContent=t}))}function i(t,o,...i){const r=t&&"effectiveConfig"in t?t.effectiveConfig:void 0,n=r?.a11y?.messages?.[o];return n?n(...i):e[o](...i)}function 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)}`}const 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(""));new RegExp(`__(proto|defineGetter|defineSetter)|${s.slice(3).join("|")}|this\\b`);const a=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){if(Array.from(i.attributes).some(e=>l.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(i);continue}}const o=[];for(const t of i.attributes){const e=t.name.toLowerCase();l.test(e)?o.push(t.name):(d.has(e)&&c.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&o.push(t.name)}o.forEach(e=>i.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}class p{static dependencies;static manifest;aliases;version="2.17.2";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;for(const o of Object.keys(t))delete t[o];Object.assign(t,e.userConfig)}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;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),o=parseInt(t,10);if(!isNaN(o))return o}return 200}setIcon(e,t,o){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const i=this.#t(t,o);void 0!==i?"string"==typeof i?e.innerHTML=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))}}const g={sum:e=>{let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t},avg:e=>{if(!e.length)return 0;let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t/e.length},count:e=>e.length,min:e=>{if(!e.length)return 0;let t=e[0];for(let o=1;o<e.length;o++)e[o]<t&&(t=e[o]);return t},max:e=>{if(!e.length)return 0;let t=e[0];for(let o=1;o<e.length;o++)e[o]>t&&(t=e[o]);return t},first:e=>e[0]??0,last:e=>e[e.length-1]??0};function h(e){return"function"==typeof e?e:function(e){return g[e]??g.sum}(e)}function v(e,t){return[...e,t].join("|")}function f(e,t){const o=t.rowGroupFields??[],i=t.columnGroupFields??[],r=t.valueFields??[],n=function(e,t,o="asc"){if(0===t.length)return["value"];const i=/* @__PURE__ */new Set;for(const n of e){const e=t.map(e=>String(n[e]??"")).join("|");i.add(e)}const r=[...i].sort();return"desc"===o?r.reverse():r}(e,i,t.sortColumns),s=m(e,o,i,n,r,0,"");t.sortRows&&F(s,t.sortRows,r);const a=function(e,t,o){const i={};function r(e){for(const n of e)if(n.isGroup&&n.children?.length)n.children&&r(n.children);else for(const e of t)for(const t of o){const o=v([e],t.field);i[o]=(i[o]??0)+(n.values[o]??0)}}return r(e),i}(s,n,r);return{rows:s,columnKeys:n,totals:a,grandTotal:Object.values(a).reduce((e,t)=>e+t,0)}}function m(e,t,o,i,r,n,s){const a=[];if(0===t.length){const t=b(e,o,i,r),l=w(t);return a.push({rowKey:s||"all",rowLabel:s||"All",depth:n,values:t,total:l,isGroup:!1,rowCount:e.length}),a}const l=t[0],d=t.slice(1),c=d.length>0,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)=>{if("value"===t.by){if(t.valueField??o[0]?.field){return((e.total??0)-(r.total??0))*i}}return e.rowLabel.localeCompare(r.rowLabel)*i});for(const r of e)r.children?.length&&F(r.children,t,o)}function y(e,t,o){if(0===t.length)return;const i=new Set(o.map(e=>e.field)),r=t.map(e=>"value"===e.by?e.valueField?t=>((e,t)=>{if(null!=e.values[t])return"number"==typeof e.values[t]?e.values[t]:0;if(i.has(t)){const o=`|${t}`;let i=0,r=!1;for(const t of Object.keys(e.values))t.endsWith(o)&&(i+="number"==typeof e.values[t]?e.values[t]:0,r=!0);if(r)return i}return e.total??0})(t,e.valueField):e=>e.total??0:null);e.sort((e,o)=>{for(let i=0;i<t.length;i++){const n=t[i],s="desc"===n.direction?-1:1;let a=0;if("value"===n.by){const t=r[i];a=(t(e)-t(o))*s}else a=e.rowLabel.localeCompare(o.rowLabel)*s;if(0!==a)return a}return 0});for(const n of e)n.children?.length&&y(n.children,t,o)}const x="dragging",_=["sum","avg","count","min","max","first","last"];function A(e,t,o,i){const r=new AbortController,n={config:t,callbacks:i,signal:r.signal},s=document.createElement("div");return s.className="tbw-pivot-panel",s.appendChild(T("Options",()=>function(e,t){const{config:o,callbacks:i,signal:r}=t,n=document.createElement("div");return n.className="tbw-pivot-options",n.appendChild(R("Enable Pivot View",e,e=>{i.onTogglePivot(e)},r)),n.appendChild(R("Show Row Totals",o.showTotals??!0,e=>{i.onOptionChange("showTotals",e)},r)),n.appendChild(R("Show Grand Total",o.showGrandTotal??!0,e=>{i.onOptionChange("showGrandTotal",e)},r)),n}(o,n))),s.appendChild(T("Row Groups",()=>E("rowGroups",n))),s.appendChild(T("Column Groups",()=>E("columnGroups",n))),s.appendChild(T("Values",()=>function(e){const{config:t,callbacks:o,signal:i}=e,r=document.createElement("div");r.className="tbw-pivot-drop-zone tbw-pivot-values-zone",r.setAttribute("data-zone","values");const n=t.valueFields??[];if(0===n.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="Drag numeric fields here",r.appendChild(e)}else for(const s of n)r.appendChild(G(s,e));return r.addEventListener("dragover",e=>{e.preventDefault(),r.classList.add("drag-over")},{signal:i}),r.addEventListener("dragleave",()=>{r.classList.remove("drag-over")},{signal:i}),r.addEventListener("drop",e=>{e.preventDefault(),r.classList.remove("drag-over");const t=e.dataTransfer?.getData("text/plain");t&&o.onAddValueField(t,"sum")},{signal:i}),r}(n))),s.appendChild(T("Available Fields",()=>function(e){const{config:t,callbacks:o,signal:i}=e,r=document.createElement("div");r.className="tbw-pivot-available-fields";const n=o.getAvailableFields(),s=/* @__PURE__ */new Set([...t.rowGroupFields??[],...t.columnGroupFields??[],...t.valueFields?.map(e=>e.field)??[]]),a=n.filter(e=>!s.has(e.field));if(0===a.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="All fields are in use",r.appendChild(e)}else{const e=document.createElement("div");if(e.className="tbw-pivot-fields-list",a.length>=6){const t=document.createElement("input");t.type="text",t.placeholder="Filter fields…",t.className="tbw-pivot-field-search",t.addEventListener("input",()=>{const o=t.value.toLowerCase();for(const t of e.querySelectorAll(".tbw-pivot-field-chip")){const e=t;e.style.display=e.textContent?.toLowerCase().includes(o)?"":"none"}},{signal:i}),r.appendChild(t)}for(const t of a){const o=document.createElement("div");o.className="tbw-pivot-field-chip available",o.textContent=t.header,o.draggable=!0,o.title=`Drag to add "${t.field}" to a zone`,o.addEventListener("dragstart",e=>{e.dataTransfer?.setData("text/plain",t.field),o.classList.add(x)},{signal:i}),o.addEventListener("dragend",()=>{o.classList.remove(x)},{signal:i}),e.appendChild(o)}r.appendChild(e)}return r}(n))),e.appendChild(s),()=>{r.abort(),s.remove()}}function T(e,t){const o=document.createElement("div");o.className="tbw-pivot-section";const i=document.createElement("div");i.className="tbw-pivot-section-header",i.textContent=e;const r=document.createElement("div");return r.className="tbw-pivot-section-content",r.appendChild(t()),o.appendChild(i),o.appendChild(r),o}function E(e,t){const{config:o,callbacks:i,signal:r}=t,n=document.createElement("div");n.className="tbw-pivot-drop-zone",n.setAttribute("data-zone",e);const s="rowGroups"===e?o.rowGroupFields??[]:o.columnGroupFields??[];if(0===s.length){const e=document.createElement("div");e.className="tbw-pivot-placeholder",e.textContent="Drag fields here",n.appendChild(e)}else for(const a of s)n.appendChild(S(a,e,t));return n.addEventListener("dragover",e=>{e.preventDefault(),n.classList.add("drag-over")},{signal:r}),n.addEventListener("dragleave",()=>{n.classList.remove("drag-over")},{signal:r}),n.addEventListener("drop",t=>{t.preventDefault(),n.classList.remove("drag-over");const o=t.dataTransfer?.getData("text/plain"),r=t.dataTransfer?.getData("source-zone");if(!o)return;const s=n.querySelectorAll(".tbw-pivot-field-chip");let a=s.length;for(let e=0;e<s.length;e++){const o=s[e].getBoundingClientRect();if(t.clientY<o.top+o.height/2){a=e;break}}!r||r===e||"rowGroups"!==r&&"columnGroups"!==r?r===e?i.onReorderFieldInZone(o,e,a):i.onAddFieldToZone(o,e):i.onMoveFieldBetweenZones(o,r,e)},{signal:r}),n}function S(e,t,o){const{callbacks:i,signal:r}=o,n=document.createElement("div");n.className="tbw-pivot-field-chip",n.draggable=!0;const s=i.getAvailableFields().find(t=>t.field===e),a=document.createElement("span");a.className="tbw-pivot-chip-label",a.textContent=s?.header??e;const l=document.createElement("button");return l.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}class P 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{display:grid;grid-template-columns:var(--tbw-column-template);font-weight:600;background:var(--tbw-pivot-group-bg, var(--tbw-color-row-alt));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider)}@media(hover:hover){.pivot-group-row:hover{background:var(--tbw-pivot-group-hover, var(--tbw-color-row-hover))}}.pivot-leaf-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-pivot-leaf-bg, var(--tbw-color-bg));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider)}.pivot-grand-total-row{display:grid;grid-template-columns:var(--tbw-column-template);font-weight:700;background:var(--tbw-pivot-grand-total-bg, var(--tbw-color-header-bg));min-height:var(--tbw-row-height);border-top:2px solid var(--tbw-color-border-strong)}.pivot-grand-total-row>.cell{display:flex;align-items:center;padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}.pivot-grand-total-row>.cell:last-child{border-right:0}.pivot-grand-total-footer{position:sticky;bottom:0;z-index:var(--tbw-z-layer-pinned-rows, 20);background:var(--tbw-pivot-grand-total-bg, var(--tbw-color-header-bg));min-width:fit-content}.pivot-group-row>.cell,.pivot-leaf-row>.cell{display:flex;align-items:center;padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0}.pivot-group-row>.cell:last-child,.pivot-leaf-row>.cell:last-child{border-right:0}.pivot-toggle{display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-pivot-toggle-size, var(--tbw-toggle-size, 1.25em));height:var(--tbw-pivot-toggle-size, var(--tbw-toggle-size, 1.25em));margin-right:var(--tbw-spacing-sm, .375em);border:none;background:transparent;cursor:pointer;color:var(--tbw-pivot-toggle-color, var(--tbw-color-fg-muted));border-radius:var(--tbw-border-radius);transition:background var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease),color var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease)}.pivot-toggle:hover{background:var(--tbw-pivot-toggle-hover-bg, var(--tbw-color-row-hover));color:var(--tbw-pivot-toggle-hover-color, var(--tbw-color-fg))}.pivot-toggle:focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}.pivot-label{font-weight:inherit}.pivot-count{color:var(--tbw-pivot-count-color, var(--tbw-color-fg-muted));font-size:.9em;font-weight:400}.pivot-total-row{font-weight:700;border-top:2px solid var(--tbw-pivot-border, var(--tbw-color-border-strong))}[data-pivot-depth="1"]{--tbw-pivot-depth: 1}[data-pivot-depth="2"]{--tbw-pivot-depth: 2}[data-pivot-depth="3"]{--tbw-pivot-depth: 3}[data-pivot-depth="4"]{--tbw-pivot-depth: 4}.tbw-pivot-panel{display:flex;flex-direction:column;gap:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));padding:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));height:100%;overflow-y:auto;font-size:var(--tbw-font-size-sm, .8125rem)}.tbw-pivot-section{border:1px solid var(--tbw-pivot-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);background:var(--tbw-pivot-section-bg, var(--tbw-color-bg))}.tbw-pivot-section-header{padding:var(--tbw-button-padding, var(--tbw-spacing-md, .5rem) var(--tbw-spacing-lg, .75rem));font-weight:600;background:var(--tbw-pivot-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-pivot-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius) var(--tbw-border-radius) 0 0}.tbw-pivot-section-content{padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-pivot-toggle-wrapper{display:flex;align-items:center}.tbw-pivot-toggle-label{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));cursor:pointer}.tbw-pivot-toggle-label input{width:var(--tbw-icon-size, 1rem);height:var(--tbw-icon-size, 1rem);cursor:pointer}.tbw-pivot-drop-zone{min-height:60px;padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border:2px dashed var(--tbw-pivot-drop-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);background:var(--tbw-pivot-drop-bg, var(--tbw-color-row-alt));display:flex;flex-wrap:wrap;gap:var(--tbw-spacing-sm, .375rem);align-content:flex-start;transition:all .15s ease}.tbw-pivot-drop-zone.drag-over{border-color:var(--tbw-color-accent);background:var(--tbw-pivot-drop-active, var(--tbw-focus-background))}.tbw-pivot-placeholder{color:var(--tbw-color-fg-muted);font-style:italic;padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));text-align:center;width:100%}.tbw-pivot-field-chip{display:inline-flex;align-items:center;gap:var(--tbw-spacing-sm, .375rem);padding:var(--tbw-button-padding-sm, var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-md, .5rem));background:var(--tbw-pivot-chip-bg, var(--tbw-color-header-bg));border:1px solid var(--tbw-pivot-chip-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius);cursor:grab;font-size:var(--tbw-font-size-xs, .75rem);transition:all .15s ease}.tbw-pivot-field-chip:hover{background:var(--tbw-pivot-chip-hover, var(--tbw-color-row-hover));border-color:var(--tbw-color-accent)}.tbw-pivot-field-chip.available{background:var(--tbw-color-bg)}.tbw-pivot-field-chip.dragging{opacity:.5;cursor:grabbing}.tbw-pivot-chip-label{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:120px}.tbw-pivot-chip-remove{display:flex;align-items:center;justify-content:center;width:var(--tbw-icon-size, 1rem);height:var(--tbw-icon-size, 1rem);padding:0;border:none;background:transparent;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-sm, .875rem);font-weight:700;cursor:pointer;border-radius:50%;transition:all .15s ease}.tbw-pivot-chip-remove:hover{background:var(--tbw-pivot-chip-remove-hover-bg, var(--tbw-color-accent));color:var(--tbw-pivot-chip-remove-hover-fg, var(--tbw-color-accent-fg))}.tbw-pivot-value-chip{padding:var(--tbw-button-padding-sm, var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-md, .5rem))}.tbw-pivot-value-label-wrapper{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));flex:1;min-width:0}.tbw-pivot-agg-select{padding:var(--tbw-spacing-xs, .125rem) var(--tbw-spacing-xs, .25rem);font-size:var(--tbw-font-size-xs, .6875rem);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);cursor:pointer}.tbw-pivot-available-fields{display:flex;flex-direction:column;gap:var(--tbw-spacing-sm, .375rem);min-height:40px}.tbw-pivot-field-search{width:100%;padding:.25rem .5rem;border:1px solid var(--tbw-color-border, #d0d5dd);border-radius:var(--tbw-radius-sm, .25rem);font-size:var(--tbw-font-size-sm, .875rem);background:var(--tbw-color-bg, #fff);color:var(--tbw-color-fg, #1a1a2e);outline:none}.tbw-pivot-field-search:focus{border-color:var(--tbw-color-primary, #3b82f6)}.tbw-pivot-fields-list{display:flex;flex-wrap:wrap;gap:var(--tbw-spacing-sm, .375rem)}.tbw-pivot-options{display:flex;flex-direction:column;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-pivot-checkbox{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));cursor:pointer}.tbw-pivot-checkbox input{width:var(--tbw-icon-size-sm, .875rem);height:var(--tbw-icon-size-sm, .875rem);cursor:pointer}.pivot-group-row.tbw-pivot-slide-in,.pivot-leaf-row.tbw-pivot-slide-in{animation:tbw-pivot-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-pivot-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.pivot-group-row.tbw-pivot-fade-in,.pivot-leaf-row.tbw-pivot-fade-in{animation:tbw-pivot-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-pivot-fade-in{0%{opacity:0}to{opacity:1}}}';static PANEL_ID="pivot";get defaultConfig(){return{active:!0,showTotals:!0,showGrandTotal:!0,showToolPanel:!0,animation:"slide"}}isActive=!1;hasInitialized=!1;pivotResult=null;fieldHeaderMap=/* @__PURE__ */new Map;expandedKeys=/* @__PURE__ */new Set;defaultExpanded=!0;userHasToggledExpand=!1;originalColumns=[];panelContainer=null;grandTotalFooter=null;previousVisibleKeys=/* @__PURE__ */new Set;keysToAnimate=/* @__PURE__ */new Set;valueFormatters=/* @__PURE__ */new Map;columnTotals={};activeSortField=null;activeSortDir=null;hasValidPivotConfig(){return(this.config.valueFields?.length??0)>0}get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}detach(){this.isActive=!1,this.hasInitialized=!1,this.pivotResult=null,this.fieldHeaderMap.clear(),this.originalColumns=[],this.panelContainer=null,this.cleanupGrandTotalFooter(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.userHasToggledExpand=!1,this.valueFormatters.clear(),this.columnTotals={},this.activeSortField=null,this.activeSortDir=null,this.config.sortRows=void 0}getToolPanel(){if(!1!==(this.config?.showToolPanel??this.userConfig?.showToolPanel??!0))return{id:P.PANEL_ID,title:"Pivot",icon:"⊞",tooltip:"Configure pivot table",order:90,render:e=>this.renderPanel(e)}}processRows(e){if(!this.hasInitialized&&!1!==this.config.active&&this.hasValidPivotConfig()&&(this.hasInitialized=!0,this.isActive=!0),!this.isActive)return[...e];const t=function(e){const t=[];return e.rowGroupFields?.length||e.columnGroupFields?.length||t.push("At least one row or column group field is required"),e.valueFields?.length||t.push("At least one value field is required"),t}(this.config);if(t.length>0)return this.warn(`Config errors: ${t.join(", ")}`),[...e];this.buildFieldHeaderMap(),this.buildValueFormatters(),this.defaultExpanded=this.config.defaultExpanded??!0,this.pivotResult=f(e,this.config);const o=this.getMultiSortConfigs();if(o&&y(this.pivotResult.rows,o,this.config.valueFields??[]),0===this.expandedKeys.size&&!this.userHasToggledExpand){const e=C(this.pivotResult.rows);this.expandedKeys=function(e,t){if(!0===e||void 0===e)return new Set(t);if(!1===e)/* @__PURE__ */return new Set;if("number"==typeof e){const o=t[e];return o?/* @__PURE__ */new Set([o]):/* @__PURE__ */new Set}return"string"==typeof e?/* @__PURE__ */new Set([e]):Array.isArray(e)?new Set(e):/* @__PURE__ */new Set}(this.defaultExpanded,e)}this.config.valueDisplayMode&&"raw"!==this.config.valueDisplayMode&&(this.columnTotals=function(e,t,o){const i={};return function e(r){for(const n of r)if(n.isGroup&&n.children?.length)n.children&&e(n.children);else for(const e of t)for(const t of o){const o=v([e],t.field);i[o]=(i[o]??0)+(n.values[o]??0)}}(e),i}(this.pivotResult.rows,this.pivotResult.columnKeys,this.config.valueFields??[]));const i=this.config.indentWidth??20,r=!0===this.defaultExpanded||void 0===this.defaultExpanded,n=function(e,t,o=!0){const i=[];function r(e){i.push(e);const n=t?t.has(e.rowKey):o;if(e.children&&n)for(const t of e.children)r(t)}for(const n of e)r(n);return i}(this.pivotResult.rows,this.expandedKeys,r).map(e=>({__pivotRowKey:e.rowKey,__pivotLabel:e.rowLabel,__pivotDepth:e.depth,__pivotIsGroup:e.isGroup,__pivotHasChildren:Boolean(e.children?.length),__pivotExpanded:this.expandedKeys.has(e.rowKey),__pivotRowCount:e.rowCount??0,__pivotIndent:e.depth*i,__pivotTotal:e.total,...e.values}));this.keysToAnimate.clear();const s=/* @__PURE__ */new Set;for(const a of n){const e=a.__pivotRowKey;s.add(e),!this.previousVisibleKeys.has(e)&&a.__pivotDepth>0&&this.keysToAnimate.add(e)}return this.previousVisibleKeys=s,this.config.grandTotalInRowModel&&this.config.showGrandTotal&&this.pivotResult&&n.push({__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotDepth:0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals}),n}processColumns(e){if(!this.isActive||!this.pivotResult)return[...e];const t=[],o=(this.config.rowGroupFields??[]).map(e=>this.fieldHeaderMap.get(e)??e).join(" / ");t.push({field:"__pivotLabel",header:o||"Group",width:200,sortable:!0});for(const i of this.pivotResult.columnKeys)for(const e of this.config.valueFields??[]){const o=v([i],e.field),r=e.header||this.fieldHeaderMap.get(e.field)||e.field,n="function"==typeof e.aggFunc?"custom":e.aggFunc,s=this.valueFormatters.get(e.field);t.push({field:o,header:`${i} - ${r} (${n})`,width:120,type:"number",sortable:!0,...s?{format:e=>null!=e?s(Number(e)):""}:{}})}return this.config.showTotals&&t.push({field:"__pivotTotal",header:"Total",width:100,type:"number",sortable:!0}),t}renderRow(e,t,o){const i=e;return i.__pivotIsGrandTotal?L(i,t,this.gridColumns):i.__pivotRowKey&&i.__pivotHasChildren?function(e,t,o){return t.className="data-grid-row pivot-group-row",t.setAttribute("data-pivot-depth",String(e.__pivotDepth??0)),t.setAttribute("data-pivot-key",String(e.__pivotRowKey??"")),t.setAttribute("role","row"),t.innerHTML="",o.columns.forEach((i,r)=>{const n=document.createElement("div");if(n.className="cell",n.setAttribute("data-col",String(r)),n.setAttribute("data-row",String(o.rowIndex)),n.setAttribute("role","gridcell"),0===r){const t=Number(e.__pivotIndent)||0;n.style.paddingLeft=`${t}px`;const i=String(e.__pivotRowKey),r=document.createElement("button");r.type="button",r.className="pivot-toggle",r.setAttribute("aria-label",e.__pivotExpanded?"Collapse group":"Expand group"),o.setIcon(r,e.__pivotExpanded?"collapse":"expand"),r.addEventListener("click",e=>{e.stopPropagation(),o.onToggle(i)}),n.appendChild(r);const s=document.createElement("span");s.className="pivot-label",s.textContent=String(e.__pivotLabel??""),n.appendChild(s);const a=document.createElement("span");a.className="pivot-count",a.textContent=` (${Number(e.__pivotRowCount)||0})`,n.appendChild(a)}else{const t=e[i.field];n.textContent=null!=t?i.format?i.format(t,e):String(t):""}t.appendChild(n)}),!0}(i,t,{columns:this.gridColumns,rowIndex:o,onToggle:e=>this.toggle(e),setIcon:(e,t)=>this.setIcon(e,t)}):void 0!==i.__pivotRowKey&&this.isActive?function(e,t,o,i){return t.className="data-grid-row pivot-leaf-row",t.setAttribute("data-pivot-depth",String(e.__pivotDepth??0)),t.setAttribute("data-pivot-key",String(e.__pivotRowKey??"")),t.innerHTML="",o.forEach((o,r)=>{const n=document.createElement("div");if(n.className="cell",n.setAttribute("data-col",String(r)),n.setAttribute("data-row",String(i)),n.setAttribute("role","gridcell"),0===r){const t=Number(e.__pivotIndent)||0;n.style.paddingLeft=`${t+20}px`;const o=document.createElement("span");o.className="pivot-label",o.textContent=String(e.__pivotLabel??""),n.appendChild(o)}else{const t=e[o.field];n.textContent=null!=t?o.format?o.format(t,e):String(t):""}t.appendChild(n)}),!0}(i,t,this.gridColumns,o):(this.cleanupPivotStyling(t),!1)}cleanupPivotStyling(e){(e.classList.contains("pivot-group-row")||e.classList.contains("pivot-leaf-row")||e.classList.contains("pivot-grand-total-row"))&&(e.classList.remove("pivot-group-row","pivot-leaf-row","pivot-grand-total-row"),e.classList.add("data-grid-row"),e.removeAttribute("data-pivot-depth"),e.innerHTML="")}onKeyDown(e){if(" "!==e.key)return;if(!this.isActive)return;const t=this.grid._focusRow,o=this.rows[t];return o?.__pivotIsGroup&&o.__pivotHasChildren?(e.preventDefault(),this.toggle(o.__pivotRowKey),this.requestRenderWithFocus(),!0):void 0}handleQuery(e){if("sort:get-sort-config"===e.type){const e=this.getMultiSortConfigs();return e||(this.config.sortRows??null)}}onHeaderClick(e){if(!this.isActive)return!1;const t=e.field;if(!this.isPivotField(t))return!1;if(this.isMultiSortActive())return!1;const 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");if(!t)return;this.grandTotalFooter||(this.grandTotalFooter=document.createElement("div"),this.grandTotalFooter.className="pivot-grand-total-footer",t.appendChild(this.grandTotalFooter));L({__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals},this.grandTotalFooter,this.gridColumns),this.grandTotalFooter.setAttribute("role","presentation")}cleanupGrandTotalFooter(){this.grandTotalFooter&&(this.grandTotalFooter.remove(),this.grandTotalFooter=null)}toggle(e){this.userHasToggledExpand=!0;const t=this.expandedKeys.has(e);t?this.expandedKeys.delete(e):this.expandedKeys.add(e),this.emitToggle(e,!t),this.requestRender()}expand(e){this.userHasToggledExpand=!0,this.expandedKeys.add(e),this.emitToggle(e,!0),this.requestRender()}collapse(e){this.userHasToggledExpand=!0,this.expandedKeys.delete(e),this.emitToggle(e,!1),this.requestRender()}expandAll(){this.userHasToggledExpand=!0,this.expandAllKeys(),this.requestRender()}collapseAll(){this.userHasToggledExpand=!0,this.expandedKeys.clear(),this.requestRender()}expandAllKeys(){if(!this.pivotResult)return;const e=C(this.pivotResult.rows);for(const t of e)this.expandedKeys.add(t)}isExpanded(e){return this.expandedKeys.has(e)}getExpandedGroups(){return[...this.expandedKeys]}enablePivot(){0===this.originalColumns.length&&this.captureOriginalColumns(),this.isActive=!0,this.emit("pivot-state-change",{active:!0}),this.requestRender()}disablePivot(){this.isActive=!1,this.pivotResult=null,this.emit("pivot-state-change",{active:!1}),this.requestRender()}isPivotActive(){return this.isActive}getPivotResult(){return this.pivotResult}setRowGroupFields(e){this.config.rowGroupFields=e,this.emitConfigChange("rowGroupFields"),this.refresh()}setColumnGroupFields(e){this.config.columnGroupFields=e,this.emitConfigChange("columnGroupFields"),this.refresh()}setValueFields(e){this.config.valueFields=e,this.emitConfigChange("valueFields"),this.refresh()}refresh(){this.pivotResult=null,this.requestRender()}showPanel(){this.grid.openToolPanel(),this.grid.expandedToolPanelSections.includes(P.PANEL_ID)||this.grid.toggleToolPanelSection(P.PANEL_ID)}hidePanel(){this.grid.closeToolPanel()}togglePanel(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection(P.PANEL_ID)}isPanelVisible(){return this.grid.isToolPanelOpen&&this.grid.expandedToolPanelSections.includes(P.PANEL_ID)}get gridColumns(){return this.grid.columns??[]}refreshIfActive(){this.isActive&&this.refresh(),this.refreshPanel()}buildFieldHeaderMap(){const e=this.getAvailableFields();this.fieldHeaderMap.clear();for(const t of e)this.fieldHeaderMap.set(t.field,t.header)}getAvailableFields(){return this.originalColumns.length>0?this.originalColumns:this.captureOriginalColumns()}captureOriginalColumns(){try{const e=this.grid.getAllColumns?.()??this.grid.columns??[];return this.originalColumns=e.filter(e=>!e.field.startsWith("__pivot")).map(e=>({field:e.field,header:e.header??e.field})),this.originalColumns}catch{return[]}}renderPanel(e){this.panelContainer=e,0===this.originalColumns.length&&this.captureOriginalColumns();const t={onTogglePivot:e=>{e?this.enablePivot():this.disablePivot(),this.refreshPanel()},onAddFieldToZone:(e,t)=>{this.addFieldToZone(e,t),this.emitConfigChange("rowGroups"===t?"rowGroupFields":"columnGroupFields",e,t)},onRemoveFieldFromZone:(e,t)=>{this.removeFieldFromZone(e,t),this.emitConfigChange("rowGroups"===t?"rowGroupFields":"columnGroupFields",e,t)},onReorderFieldInZone:(e,t,o)=>{this.reorderFieldInZone(e,t,o),this.emitConfigChange("rowGroups"===t?"rowGroupFields":"columnGroupFields",e,t)},onMoveFieldBetweenZones:(e,t,o)=>{this.moveFieldBetweenZones(e,t,o),this.emitConfigChange("rowGroups"===o?"rowGroupFields":"columnGroupFields",e,o)},onAddValueField:(e,t)=>{this.addValueField(e,t),this.emitConfigChange("valueFields",e,"values")},onRemoveValueField:e=>{this.removeValueField(e),this.emitConfigChange("valueFields",e,"values")},onUpdateValueAggFunc:(e,t)=>{this.updateValueAggFunc(e,t),this.emitConfigChange("valueFields",e,"values")},onOptionChange:(e,t)=>{this.config[e]=t,this.emitConfigChange(e),this.isActive&&this.refresh()},getAvailableFields:()=>this.getAvailableFields()};return A(e,this.config,this.isActive,t)}refreshPanel(){this.panelContainer&&(this.panelContainer.innerHTML="",this.renderPanel(this.panelContainer))}addFieldToZone(e,t){if("rowGroups"===t){const t=this.config.rowGroupFields??[];t.includes(e)||(this.config.rowGroupFields=[...t,e])}else{const t=this.config.columnGroupFields??[];t.includes(e)||(this.config.columnGroupFields=[...t,e])}this.removeFromOtherZones(e,t),this.refreshIfActive()}removeFieldFromZone(e,t){"rowGroups"===t?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e),this.refreshIfActive()}reorderFieldInZone(e,t,o){const i="rowGroups"===t?[...this.config.rowGroupFields??[]]:[...this.config.columnGroupFields??[]],r=i.indexOf(e);-1!==r&&r!==o&&(i.splice(r,1),i.splice(o>r?o-1:o,0,e),"rowGroups"===t?this.config.rowGroupFields=i:this.config.columnGroupFields=i,this.refreshIfActive())}moveFieldBetweenZones(e,t,o){"rowGroups"===t?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e),"rowGroups"===o?this.config.rowGroupFields=[...this.config.rowGroupFields??[],e]:this.config.columnGroupFields=[...this.config.columnGroupFields??[],e],this.refreshIfActive()}removeFromOtherZones(e,t){"rowGroups"!==t&&(this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e)),"columnGroups"!==t&&(this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e)),"values"!==t&&(this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e))}addValueField(e,t){const o=this.config.valueFields??[];o.some(t=>t.field===e)||(this.config.valueFields=[...o,{field:e,aggFunc:t}]),this.removeFromOtherZones(e,"values"),this.refreshIfActive()}removeValueField(e){this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e),this.refreshIfActive()}updateValueAggFunc(e,t){const o=this.config.valueFields??[],i=o.findIndex(t=>t.field===e);i>=0&&(o[i]={...o[i],aggFunc:t},this.config.valueFields=[...o]),this.isActive&&this.refresh()}emitToggle(e,t){const o=this.rows.find(t=>t.__pivotRowKey===e);this.emit("pivot-toggle",{key:e,expanded:t,label:o?.__pivotLabel??e,depth:o?.__pivotDepth??0})}emitConfigChange(e,t,o){this.emit("pivot-config-change",{property:e,field:t,zone:o})}buildValueFormatters(){this.valueFormatters.clear();const e=this.config.valueFields??[];for(const t of e)if(t.format)this.valueFormatters.set(t.field,t.format);else{if(this.originalColumns.find(e=>e.field===t.field)){const e=(this.grid.getAllColumns?.()??this.grid.columns??[]).find(e=>e.field===t.field);if(e?.format){const o=e.format;this.valueFormatters.set(t.field,e=>o(e,{}))}}}}}export{P as PivotPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|