@toolbox-web/grid 3.5.0 → 3.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/all.js +1 -1
  2. package/all.js.map +1 -1
  3. package/index.js +1 -1
  4. package/lib/features/registry.js +1 -1
  5. package/lib/plugins/clipboard/index.js +1 -1
  6. package/lib/plugins/clipboard/index.js.map +1 -1
  7. package/lib/plugins/column-virtualization/index.js +1 -1
  8. package/lib/plugins/context-menu/index.js +1 -1
  9. package/lib/plugins/editing/index.js +1 -1
  10. package/lib/plugins/export/index.js +1 -1
  11. package/lib/plugins/filtering/index.js +1 -1
  12. package/lib/plugins/grouping-columns/index.js +1 -1
  13. package/lib/plugins/grouping-rows/index.js +1 -1
  14. package/lib/plugins/master-detail/index.js +1 -1
  15. package/lib/plugins/multi-sort/index.js +1 -1
  16. package/lib/plugins/pinned-columns/index.js +1 -1
  17. package/lib/plugins/pinned-rows/index.js +1 -1
  18. package/lib/plugins/pivot/index.js +1 -1
  19. package/lib/plugins/print/index.js +1 -1
  20. package/lib/plugins/reorder-columns/index.js +1 -1
  21. package/lib/plugins/responsive/index.js +1 -1
  22. package/lib/plugins/row-drag-drop/index.js +1 -1
  23. package/lib/plugins/selection/index.js +1 -1
  24. package/lib/plugins/server-side/index.js +1 -1
  25. package/lib/plugins/shell/index.js +1 -1
  26. package/lib/plugins/sticky-rows/index.js +1 -1
  27. package/lib/plugins/tooltip/index.js +1 -1
  28. package/lib/plugins/tree/index.js +1 -1
  29. package/lib/plugins/undo-redo/index.js +1 -1
  30. package/lib/plugins/visibility/index.js +1 -1
  31. package/package.json +1 -1
  32. package/umd/grid.all.umd.js +1 -1
  33. package/umd/grid.all.umd.js.map +1 -1
  34. package/umd/grid.umd.js +1 -1
  35. package/umd/plugins/clipboard.umd.js +1 -1
  36. package/umd/plugins/clipboard.umd.js.map +1 -1
@@ -1,2 +1,2 @@
1
- var e={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,columnSelected:e=>`Column ${e} selected`,columnSelectionChanged:e=>`${e} columns selected`,columnSelectionCleared:()=>"Column selection cleared",selectionAxisChanged:e=>"column"===e?"Row selection cleared, column selection active":"Column selection cleared, row selection active",editingStarted:e=>`Editing row ${e+1}`,editingCommitted:e=>`Row ${e+1} saved`,dataLoaded:e=>`${e} rows loaded`},t={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function o(e,t){if(!e)return;if(!1===("effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.announcements)return;const o=e.querySelector?.(".tbw-sr-only");o&&(o.textContent="","function"==typeof requestAnimationFrame?requestAnimationFrame(()=>{o.textContent=t}):o.textContent=t)}function i(t,o,...i){const r=(t&&"effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.messages?.[o];return r?r(...i):e[o](...i)}function r(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function n(e,t,o,i){return`${r(o,i)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var s="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(e=>e.split("").reverse().join("")),a=(new RegExp(`__(proto|defineGetter|defineSetter)|${s.slice(3).join("|")}|this\\b`),new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing|math".split("|"))),l=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),c=/^\s*(javascript|vbscript|data|blob):/i;function u(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],o=e.querySelectorAll("*");for(const i of o){const e=i.tagName.toLowerCase();if(a.has(e)){t.push(i);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===i.namespaceURI)&&Array.from(i.attributes).some(e=>l.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(i);continue}const o=[];for(const t of i.attributes){const e=t.name.toLowerCase();l.test(e)?o.push(t.name):"is"!==e?(d.has(e)&&c.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&o.push(t.name):o.push(t.name)}o.forEach(e=>i.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}var p=class{static dependencies;static manifest;aliases;version="3.5.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},o={};for(const i of Object.keys(t))o[i]=this;for(const i of e){const e=i.userConfig;for(const[r,s]of Object.entries(e)){if(void 0===s)continue;if(!(r in t)){t[r]=s,o[r]=i;continue}if(t[r]===s)continue;const e=o[r]?.constructor.name??this.constructor.name,a=i.constructor.name,l=n("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${r}" supplied by both ${e} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,o={...e.userConfig};for(const i of Object.keys(t))delete t[i];Object.assign(t,o)}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const o=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(o),o.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}queryBoolean(e,t=null){const o=this.grid?.query?.(e,t);return Array.isArray(o)?o.some(Boolean):!!o}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...t,...e}}t(e,t){return this.grid?.effectiveConfig?.locale?.[e]??t}get translate(){return(e,t)=>this.t(e,t)}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),o=parseInt(t,10);if(!isNaN(o))return o}return 200}setIcon(e,t,o){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const i=this.#t(t,o);var r,n;void 0!==i?"string"==typeof i?(r=e,(n=i)&&"string"==typeof n?-1!==n.indexOf("<")||-1!==n.indexOf("&")?r.replaceChildren(u(n)):r.textContent=n:r.replaceChildren()):i instanceof HTMLElement&&e.replaceChildren(i.cloneNode(!0)):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const o=document.createElement("span");o.setAttribute("part","sort-indicator"),o.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(o,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(o,"sortNone"));const i=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return i?e.insertBefore(o,i):e.appendChild(o),o}warn(e,t){void 0!==t?console.warn(n(e,t,this.gridElement.id,this.name)):console.warn(`${r(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(n(e,t,this.gridElement.id,this.name))}},g={sum:e=>{let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t},avg:e=>{if(!e.length)return 0;let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t/e.length},count:e=>e.length,min:e=>{if(!e.length)return 0;let t=e[0];for(let o=1;o<e.length;o++)e[o]<t&&(t=e[o]);return t},max:e=>{if(!e.length)return 0;let t=e[0];for(let o=1;o<e.length;o++)e[o]>t&&(t=e[o]);return t},first:e=>e[0]??0,last:e=>e[e.length-1]??0};function h(e){return"function"==typeof e?e:function(e){return g[e]??g.sum}(e)}function v(e,t){return[...e,t].join("|")}function f(e,t){const o=t.rowGroupFields??[],i=t.columnGroupFields??[],r=t.valueFields??[],n=function(e,t,o="asc"){if(0===t.length)return["value"];const i=/* @__PURE__ */new Set;for(const n of e){const e=t.map(e=>String(n[e]??"")).join("|");i.add(e)}const r=[...i].sort();return"desc"===o?r.reverse():r}(e,i,t.sortColumns),s=m(e,o,i,n,r,0,"");t.sortRows&&F(s,t.sortRows,r);const a=function(e,t,o){const i={};function r(e){for(const n of e)if(n.isGroup&&n.children?.length)n.children&&r(n.children);else for(const e of t)for(const t of o){const o=v([e],t.field);i[o]=(i[o]??0)+(n.values[o]??0)}}return r(e),i}(s,n,r);return{rows:s,columnKeys:n,totals:a,grandTotal:Object.values(a).reduce((e,t)=>e+t,0)}}function m(e,t,o,i,r,n,s){const a=[];if(0===t.length){const t=b(e,o,i,r),l=w(t);return a.push({rowKey:s||"all",rowLabel:s||"All",depth:n,values:t,total:l,isGroup:!1,rowCount:e.length}),a}const l=t[0],d=t.slice(1),c=d.length>0,u=function(e,t){const o=/* @__PURE__ */new Map;for(const i of e){const e=String(i[t]??""),r=o.get(e);r?r.push(i):o.set(e,[i])}return o}(e,l);for(const[p,g]of u){const e=s?`${s}|${p}`:p,t=b(g,o,i,r),l=w(t);let u;c&&(u=m(g,d,o,i,r,n+1,e)),a.push({rowKey:e,rowLabel:p||"(blank)",depth:n,values:t,total:l,isGroup:c,children:u,rowCount:g.length})}return a}function b(e,t,o,i){const r={};if(0===t.length){for(const t of i){const o=[];for(let r=0;r<e.length;r++){const i=e[r][t.field];if(null==i||""===i)continue;const n=Number(i);isNaN(n)||o.push(n)}const i=h(t.aggFunc);r[v(["value"],t.field)]=o.length>0?i(o):null}return r}const n=/* @__PURE__ */new Map;for(let s=0;s<e.length;s++){const o=e[s];let i=String(o[t[0]]??"");for(let e=1;e<t.length;e++)i+="|",i+=String(o[t[e]]??"");const r=n.get(i);r?r.push(o):n.set(i,[o])}for(const s of o){const e=n.get(s);if(e&&0!==e.length)for(const t of i){const o=[];for(let r=0;r<e.length;r++){const i=e[r][t.field];if(null==i||""===i)continue;const n=Number(i);isNaN(n)||o.push(n)}const i=h(t.aggFunc);r[v([s],t.field)]=o.length>0?i(o):null}else for(const t of i)r[v([s],t.field)]=null}return r}function w(e){let t=0;for(const o of Object.values(e))t+=o??0;return t}function C(e){const t=[];function o(e){if(e.isGroup&&t.push(e.rowKey),e.children)for(const t of e.children)o(t)}for(const i of e)o(i);return t}function F(e,t,o){const i="desc"===t.direction?-1:1;e.sort((e,r)=>"value"===t.by&&(t.valueField??o[0]?.field)?((e.total??0)-(r.total??0))*i:e.rowLabel.localeCompare(r.rowLabel)*i);for(const r of e)r.children?.length&&F(r.children,t,o)}function y(e,t,o){if(0===t.length)return;const i=new Set(o.map(e=>e.field)),r=t.map(e=>"value"===e.by?e.valueField?t=>((e,t)=>{if(null!=e.values[t])return"number"==typeof e.values[t]?e.values[t]:0;if(i.has(t)){const o=`|${t}`;let i=0,r=!1;for(const t of Object.keys(e.values))t.endsWith(o)&&(i+="number"==typeof e.values[t]?e.values[t]:0,r=!0);if(r)return i}return e.total??0})(t,e.valueField):e=>e.total??0:null);e.sort((e,o)=>{for(let i=0;i<t.length;i++){const n=t[i],s="desc"===n.direction?-1:1;let a=0;if("value"===n.by){const t=r[i];a=(t(e)-t(o))*s}else a=e.rowLabel.localeCompare(o.rowLabel)*s;if(0!==a)return a}return 0});for(const n of e)n.children?.length&&y(n.children,t,o)}var x="dragging",_=["sum","avg","count","min","max","first","last"];function A(e,t,o,i,r=(e,t)=>t){const n=new AbortController,s={config:t,callbacks:i,signal:n.signal,t:r},a=document.createElement("div");return a.className="tbw-pivot-panel",a.appendChild(T(r("pivot.options","Options"),()=>function(e,t){const{config:o,callbacks:i,signal:r,t:n}=t,s=document.createElement("div");return s.className="tbw-pivot-options",s.appendChild(R(n("pivot.enable","Enable Pivot View"),e,e=>{i.onTogglePivot(e)},r)),s.appendChild(R(n("pivot.showRowTotals","Show Row Totals"),o.showTotals??!0,e=>{i.onOptionChange("showTotals",e)},r)),s.appendChild(R(n("pivot.showGrandTotal","Show Grand Total"),o.showGrandTotal??!0,e=>{i.onOptionChange("showGrandTotal",e)},r)),s}(o,s))),a.appendChild(T(r("pivot.rowGroups","Row Groups"),()=>E("rowGroups",s))),a.appendChild(T(r("pivot.columnGroups","Column Groups"),()=>E("columnGroups",s))),a.appendChild(T(r("pivot.values","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 t=document.createElement("div");t.className="tbw-pivot-placeholder",t.textContent=e.t("pivot.dropNumericFields","Drag numeric fields here"),r.appendChild(t)}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}(s))),a.appendChild(T(r("pivot.availableFields","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 t=document.createElement("div");t.className="tbw-pivot-placeholder",t.textContent=e.t("pivot.allFieldsUsed","All fields are in use"),r.appendChild(t)}else{const t=document.createElement("div");if(t.className="tbw-pivot-fields-list",a.length>=6){const o=document.createElement("input");o.type="text",o.placeholder=e.t("pivot.filterFields","Filter fields…"),o.className="tbw-pivot-field-search",o.addEventListener("input",()=>{const e=o.value.toLowerCase();for(const o of t.querySelectorAll(".tbw-pivot-field-chip")){const t=o;t.style.display=t.textContent?.toLowerCase().includes(e)?"":"none"}},{signal:i}),r.appendChild(o)}for(const e of a){const o=document.createElement("div");o.className="tbw-pivot-field-chip available",o.textContent=e.header,o.draggable=!0,o.title=`Drag to add "${e.field}" to a zone`,o.addEventListener("dragstart",t=>{t.dataTransfer?.setData("text/plain",e.field),o.classList.add(x)},{signal:i}),o.addEventListener("dragend",()=>{o.classList.remove(x)},{signal:i}),t.appendChild(o)}r.appendChild(t)}return r}(s))),e.appendChild(a),()=>{n.abort(),a.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=t.t("pivot.dropFields","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=o.t("pivot.removeField","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=t.t("pivot.aggFunction","Aggregation function"),l){const e=document.createElement("option");e.value="__custom__",e.textContent=t.t("pivot.customAgg","CUSTOM"),e.selected=!0,d.appendChild(e),d.disabled=!0}for(const u of _){const t=document.createElement("option");t.value=u,t.textContent=u.toUpperCase(),l||(t.selected=u===e.aggFunc),d.appendChild(t)}d.addEventListener("change",()=>{o.onUpdateValueAggFunc(e.field,d.value)},{signal:i});const c=document.createElement("button");return c.type="button",c.className="tbw-pivot-chip-remove",c.innerHTML="×",c.title=t.t("pivot.removeValueField","Remove value field"),c.addEventListener("click",t=>{t.stopPropagation(),o.onRemoveValueField(e.field)},{signal:i}),s.appendChild(a),s.appendChild(d),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,i=(e,t)=>t){return t.className="data-grid-row pivot-grand-total-row",t.innerHTML="",o.forEach((o,r)=>{const n=document.createElement("div");if(n.className="cell",n.setAttribute("data-col",String(r)),0===r){const e=document.createElement("span");e.className="pivot-label",e.textContent=i("pivot.grandTotal","Grand Total"),n.appendChild(e)}else{const t=e[o.field];n.textContent=null!=t?o.format?o.format(t,e):String(t):""}t.appendChild(n)}),!0}var P=class e extends p{static manifest={modifiesRowStructure:!0,hookPriority:{onHeaderClick:-10,processRows:100},incompatibleWith:[{name:"groupingRows",reason:"PivotPlugin creates its own aggregated row and column structure. Row grouping cannot be applied on top of pivot-generated rows."},{name:"tree",reason:"PivotPlugin replaces the entire row and column structure with aggregated pivot data. Tree hierarchy cannot coexist with pivot aggregation."},{name:"serverSide",reason:"PivotPlugin requires the full dataset to compute aggregations. ServerSidePlugin lazy-loads rows in blocks, so pivot aggregation cannot be performed client-side."}],queries:[{type:"sort:get-sort-config",description:"Returns the current pivot sort configuration"}]};static dependencies=[{name:"multiSort",required:!1,reason:"Queries sort model for pivot column sorting"},{name:"shell",required:!1,severity:"warn",when:e=>!0===e.showToolPanel,reason:"PivotPlugin renders its tool panel in a shell host when showToolPanel is enabled"}];name="pivot";styles='@layer tbw-plugins{.pivot-group-row{grid-template-columns:var(--tbw-column-template);background:var(--tbw-pivot-group-bg,var(--tbw-color-row-alt));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider);font-weight:600;display:grid}@media (hover:hover){.pivot-group-row:hover{background:var(--tbw-pivot-group-hover,var(--tbw-color-row-hover))}}.pivot-leaf-row{grid-template-columns:var(--tbw-column-template);background:var(--tbw-pivot-leaf-bg,var(--tbw-color-bg));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider);display:grid}.pivot-grand-total-row{grid-template-columns:var(--tbw-column-template);background:var(--tbw-pivot-grand-total-bg,var(--tbw-color-header-bg));min-height:var(--tbw-row-height);border-top:2px solid var(--tbw-color-border-strong);font-weight:700;display:grid}.pivot-grand-total-row>.cell{padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);align-items:center;min-width:0;display:flex;overflow:hidden}.pivot-grand-total-row>.cell:last-child{border-right:0}.pivot-grand-total-footer{z-index:var(--tbw-z-layer-pinned-rows,20);background:var(--tbw-pivot-grand-total-bg,var(--tbw-color-header-bg));min-width:fit-content;position:sticky;bottom:0}.pivot-group-row>.cell,.pivot-leaf-row>.cell{padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);align-items:center;min-width:0;display:flex;overflow:hidden}.pivot-group-row>.cell:last-child,.pivot-leaf-row>.cell:last-child{border-right:0}.pivot-toggle{width:var(--tbw-pivot-toggle-size,var(--tbw-toggle-size,1.25em));height:var(--tbw-pivot-toggle-size,var(--tbw-toggle-size,1.25em));margin-right:var(--tbw-spacing-sm,.375em);cursor:pointer;color:var(--tbw-pivot-toggle-color,var(--tbw-color-fg-muted));border-radius:var(--tbw-border-radius);transition:background var(--tbw-transition-duration,.12s) var(--tbw-transition-ease,ease), color var(--tbw-transition-duration,.12s) var(--tbw-transition-ease,ease);background:0 0;border:none;justify-content:center;align-items:center;display:inline-flex}.pivot-toggle:hover{background:var(--tbw-pivot-toggle-hover-bg,var(--tbw-color-row-hover));color:var(--tbw-pivot-toggle-hover-color,var(--tbw-color-fg))}@media (pointer:coarse){.pivot-toggle{min-width:var(--tbw-touch-target-min,24px);min-height:var(--tbw-touch-target-min,24px)}}.pivot-toggle:focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}.pivot-label{font-weight:inherit}.pivot-count{color:var(--tbw-pivot-count-color,var(--tbw-color-fg-muted));font-size:.9em;font-weight:400}.pivot-total-row{border-top:2px solid var(--tbw-pivot-border,var(--tbw-color-border-strong));font-weight:700}[data-pivot-depth="1"]{--tbw-pivot-depth:1}[data-pivot-depth="2"]{--tbw-pivot-depth:2}[data-pivot-depth="3"]{--tbw-pivot-depth:3}[data-pivot-depth="4"]{--tbw-pivot-depth:4}.tbw-pivot-panel{gap:var(--tbw-panel-padding,var(--tbw-spacing-lg,.75rem));padding:var(--tbw-panel-padding,var(--tbw-spacing-lg,.75rem));height:100%;font-size:var(--tbw-font-size-sm,.8125rem);flex-direction:column;display:flex;overflow-y:auto}.tbw-pivot-section{border:1px solid var(--tbw-pivot-border,var(--tbw-color-border));border-radius:var(--tbw-border-radius);background:var(--tbw-pivot-section-bg,var(--tbw-color-bg))}.tbw-pivot-section-header{padding:var(--tbw-button-padding,var(--tbw-spacing-md,.5rem) var(--tbw-spacing-lg,.75rem));background:var(--tbw-pivot-header-bg,var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-pivot-border,var(--tbw-color-border));border-radius:var(--tbw-border-radius) var(--tbw-border-radius) 0 0;font-weight:600}.tbw-pivot-section-content{padding:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem))}.tbw-pivot-toggle-wrapper{align-items:center;display:flex}.tbw-pivot-toggle-label{align-items:center;gap:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));cursor:pointer;display:flex}.tbw-pivot-toggle-label input{width:var(--tbw-icon-size,1rem);height:var(--tbw-icon-size,1rem);cursor:pointer}.tbw-pivot-drop-zone{min-height:60px;padding:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));border:2px dashed var(--tbw-pivot-drop-border,var(--tbw-color-border));border-radius:var(--tbw-border-radius);background:var(--tbw-pivot-drop-bg,var(--tbw-color-row-alt));gap:var(--tbw-spacing-sm,.375rem);flex-wrap:wrap;align-content:flex-start;transition:all .15s;display:flex}.tbw-pivot-drop-zone.drag-over{border-color:var(--tbw-color-accent);background:var(--tbw-pivot-drop-active,var(--tbw-focus-background))}.tbw-pivot-placeholder{color:var(--tbw-color-fg-muted);padding:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));text-align:center;width:100%;font-style:italic}.tbw-pivot-field-chip{align-items:center;gap:var(--tbw-spacing-sm,.375rem);padding:var(--tbw-button-padding-sm,var(--tbw-spacing-xs,.25rem) var(--tbw-spacing-md,.5rem));background:var(--tbw-pivot-chip-bg,var(--tbw-color-header-bg));border:1px solid var(--tbw-pivot-chip-border,var(--tbw-color-border));border-radius:var(--tbw-border-radius);cursor:grab;font-size:var(--tbw-font-size-xs,.75rem);transition:all .15s;display:inline-flex}.tbw-pivot-field-chip:hover{background:var(--tbw-pivot-chip-hover,var(--tbw-color-row-hover));border-color:var(--tbw-color-accent)}.tbw-pivot-field-chip.available{background:var(--tbw-color-bg)}.tbw-pivot-field-chip.dragging{opacity:.5;cursor:grabbing}.tbw-pivot-chip-label{white-space:nowrap;text-overflow:ellipsis;max-width:120px;overflow:hidden}.tbw-pivot-chip-remove{width:var(--tbw-icon-size,1rem);height:var(--tbw-icon-size,1rem);color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-sm,.875rem);cursor:pointer;background:0 0;border:none;border-radius:50%;justify-content:center;align-items:center;padding:0;font-weight:700;transition:all .15s;display:flex}.tbw-pivot-chip-remove:hover{background:var(--tbw-pivot-chip-remove-hover-bg,var(--tbw-color-accent));color:var(--tbw-pivot-chip-remove-hover-fg,var(--tbw-color-accent-fg))}.tbw-pivot-value-chip{padding:var(--tbw-button-padding-sm,var(--tbw-spacing-xs,.25rem) var(--tbw-spacing-md,.5rem))}.tbw-pivot-value-label-wrapper{align-items:center;gap:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));flex:1;min-width:0;display:flex}.tbw-pivot-agg-select{padding:var(--tbw-spacing-xs,.125rem) var(--tbw-spacing-xs,.25rem);font-size:var(--tbw-font-size-xs,.6875rem);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);cursor:pointer}.tbw-pivot-available-fields{gap:var(--tbw-spacing-sm,.375rem);flex-direction:column;min-height:40px;display:flex}.tbw-pivot-field-search{border:1px solid var(--tbw-color-border,#d0d5dd);border-radius:var(--tbw-radius-sm,.25rem);width:100%;font-size:var(--tbw-font-size-sm,.875rem);background:var(--tbw-color-bg,#fff);color:var(--tbw-color-fg,#1a1a2e);outline:none;padding:.25rem .5rem}.tbw-pivot-field-search:focus{border-color:var(--tbw-color-primary,#3b82f6)}.tbw-pivot-fields-list{gap:var(--tbw-spacing-sm,.375rem);flex-wrap:wrap;display:flex}.tbw-pivot-options{gap:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));flex-direction:column;display:flex}.tbw-pivot-checkbox{align-items:center;gap:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));cursor:pointer;display:flex}.tbw-pivot-checkbox input{width:var(--tbw-icon-size-sm,.875rem);height:var(--tbw-icon-size-sm,.875rem);cursor:pointer}.pivot-group-row.tbw-pivot-slide-in,.pivot-leaf-row.tbw-pivot-slide-in{animation:tbw-pivot-slide-in var(--tbw-animation-duration,.2s) var(--tbw-animation-easing,ease-out) forwards}@keyframes tbw-pivot-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.pivot-group-row.tbw-pivot-fade-in,.pivot-leaf-row.tbw-pivot-fade-in{animation:tbw-pivot-fade-in var(--tbw-animation-duration,.2s) var(--tbw-animation-easing,ease-out) forwards}@keyframes tbw-pivot-fade-in{0%{opacity:0}to{opacity:1}}}';static PANEL_ID="pivot";get defaultConfig(){return{active:!0,showTotals:!0,showGrandTotal:!0,showToolPanel:!0,animation:"slide"}}isActive=!1;hasInitialized=!1;pivotResult=null;fieldHeaderMap=/* @__PURE__ */new Map;expandedKeys=/* @__PURE__ */new Set;defaultExpanded=!0;userHasToggledExpand=!1;originalColumns=[];panelContainer=null;grandTotalFooter=null;previousVisibleKeys=/* @__PURE__ */new Set;keysToAnimate=/* @__PURE__ */new Set;valueFormatters=/* @__PURE__ */new Map;columnTotals={};activeSortField=null;activeSortDir=null;hasValidPivotConfig(){return(this.config.valueFields?.length??0)>0}get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}detach(){this.isActive=!1,this.hasInitialized=!1,this.pivotResult=null,this.fieldHeaderMap.clear(),this.originalColumns=[],this.panelContainer=null,this.cleanupGrandTotalFooter(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.userHasToggledExpand=!1,this.valueFormatters.clear(),this.columnTotals={},this.activeSortField=null,this.activeSortDir=null,this.config.sortRows=void 0}getToolPanel(){if(!1!==(this.config?.showToolPanel??this.userConfig?.showToolPanel??!0))return{id:e.PANEL_ID,title:this.t("pivot.panelTitle","Pivot"),icon:"⊞",tooltip:"Configure pivot table",order:90,render:e=>this.renderPanel(e)}}processRows(e){if(!this.hasInitialized&&!1!==this.config.active&&this.hasValidPivotConfig()&&(this.hasInitialized=!0,this.isActive=!0),!this.isActive)return[...e];const t=function(e){const t=[];return e.rowGroupFields?.length||e.columnGroupFields?.length||t.push("At least one row or column group field is required"),e.valueFields?.length||t.push("At least one value field is required"),t}(this.config);if(t.length>0)return this.warn(`Config errors: ${t.join(", ")}`),[...e];this.buildFieldHeaderMap(),this.buildValueFormatters(),this.defaultExpanded=this.config.defaultExpanded??!0,this.pivotResult=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,this.translate):i.__pivotRowKey&&i.__pivotHasChildren?function(e,t,o){return t.className="data-grid-row pivot-group-row",t.setAttribute("data-pivot-depth",String(e.__pivotDepth??0)),t.setAttribute("data-pivot-key",String(e.__pivotRowKey??"")),t.setAttribute("role","row"),t.innerHTML="",o.columns.forEach((i,r)=>{const n=document.createElement("div");if(n.className="cell",n.setAttribute("data-col",String(r)),n.setAttribute("data-row",String(o.rowIndex)),n.setAttribute("role","gridcell"),0===r){const t=Number(e.__pivotIndent)||0;n.style.paddingLeft=`${t}px`;const i=String(e.__pivotRowKey),r=document.createElement("button");r.type="button",r.className="pivot-toggle",r.setAttribute("aria-label",e.__pivotExpanded?"Collapse group":"Expand group"),o.setIcon(r,e.__pivotExpanded?"collapse":"expand"),r.addEventListener("click",e=>{e.stopPropagation(),o.onToggle(i)}),n.appendChild(r);const s=document.createElement("span");s.className="pivot-label",s.textContent=String(e.__pivotLabel??""),n.appendChild(s);const a=document.createElement("span");a.className="pivot-count",a.textContent=` (${Number(e.__pivotRowCount)||0})`,n.appendChild(a)}else{const t=e[i.field];n.textContent=null!=t?i.format?i.format(t,e):String(t):""}t.appendChild(n)}),!0}(i,t,{columns:this.gridColumns,rowIndex:o,onToggle:e=>this.toggle(e),setIcon:(e,t)=>this.setIcon(e,t)}):void 0!==i.__pivotRowKey&&this.isActive?function(e,t,o,i){return t.className="data-grid-row pivot-leaf-row",t.setAttribute("data-pivot-depth",String(e.__pivotDepth??0)),t.setAttribute("data-pivot-key",String(e.__pivotRowKey??"")),t.innerHTML="",o.forEach((o,r)=>{const n=document.createElement("div");if(n.className="cell",n.setAttribute("data-col",String(r)),n.setAttribute("data-row",String(i)),n.setAttribute("role","gridcell"),0===r){const t=Number(e.__pivotIndent)||0;n.style.paddingLeft=`${t+20}px`;const o=document.createElement("span");o.className="pivot-label",o.textContent=String(e.__pivotLabel??""),n.appendChild(o)}else{const t=e[o.field];n.textContent=null!=t?o.format?o.format(t,e):String(t):""}t.appendChild(n)}),!0}(i,t,this.gridColumns,o):(this.cleanupPivotStyling(t),!1)}cleanupPivotStyling(e){(e.classList.contains("pivot-group-row")||e.classList.contains("pivot-leaf-row")||e.classList.contains("pivot-grand-total-row"))&&(e.classList.remove("pivot-group-row","pivot-leaf-row","pivot-grand-total-row"),e.classList.add("data-grid-row"),e.removeAttribute("data-pivot-depth"),e.innerHTML="")}onKeyDown(e){if(" "!==e.key)return;if(!this.isActive)return;const t=this.grid._focusRow,o=this.rows[t];return o?.__pivotIsGroup&&o.__pivotHasChildren?(e.preventDefault(),this.toggle(o.__pivotRowKey),this.requestRenderWithFocus(),!0):void 0}handleQuery(e){if("sort:get-sort-config"===e.type){const e=this.getMultiSortConfigs();return e||(this.config.sortRows??null)}}onHeaderClick(e){if(!this.isActive)return!1;const t=e.field;if(!this.isPivotField(t))return!1;if(this.isMultiSortActive())return!1;const r=this.mapFieldToSortConfig(t);if(!r)return!1;const n=this.activeSortDir;let s;s=this.activeSortField!==t?"asc":"asc"===n?"desc":null,this.activeSortField=s?t:null,this.activeSortDir=s,this.config.sortRows=s?{...r,direction:s}:void 0,this.emit("pivot-config-change",{property:"sortRows"}),this.refresh();const a=this.gridElement;if(a){const r=e.column.header??t;o(a,s?i(a,"sortApplied",r,"asc"===s?"ascending":"descending"):i(a,"sortCleared"))}return!0}isPivotField(e){return"__pivotLabel"===e||"__pivotTotal"===e||e.includes("|")}isMultiSortActive(){const e=this.grid?.query?.("sort:get-model",null);return Array.isArray(e)&&e.length>0}getMultiSortConfigs(){const e=this.grid?.query?.("sort:get-model",null);if(!e||0===e.length)return null;const t=e[0];if(!Array.isArray(t)||0===t.length)return null;const o=[];for(const i of t){if(!this.isPivotField(i.field))continue;const e=this.mapFieldToSortConfig(i.field);e&&o.push({...e,direction:i.direction})}return o.length>0?o:null}mapFieldToSortConfig(e){return"__pivotLabel"===e?{by:"label"}:"__pivotTotal"===e?{by:"value"}:e.includes("|")?{by:"value",valueField:e}:null}afterRender(){this.isActive&&this.config.showGrandTotal&&this.pivotResult&&!this.config.grandTotalInRowModel?this.renderGrandTotalFooter():this.cleanupGrandTotalFooter(),this.isActive&&!this.isMultiSortActive()&&this.updateSortIndicators();const e=this.animationStyle;if(!1===e||0===this.keysToAnimate.size)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const o="fade"===e?"tbw-pivot-fade-in":"tbw-pivot-slide-in";for(const i of t.querySelectorAll(".pivot-group-row, .pivot-leaf-row")){const e=i.dataset.pivotKey;e&&this.keysToAnimate.has(e)&&(i.classList.add(o),i.addEventListener("animationend",()=>i.classList.remove(o),{once:!0}))}this.keysToAnimate.clear()}updateSortIndicators(){const e=this.gridElement;if(!e)return;const t=this.activeSortField,o=this.activeSortDir,i=t?null:this.config.sortRows,r=e.querySelectorAll(".header-row .cell[data-field]");for(const n of r){const e=n.getAttribute("data-field");if(!e||!this.isPivotField(e))continue;let r=null;t===e?r=o:i&&("label"===i.by&&"__pivotLabel"===e?r=i.direction??"asc":"value"!==i.by||"__pivotTotal"!==e||i.valueField?"value"===i.by&&i.valueField&&e===i.valueField&&(r=i.direction??"asc"):r=i.direction??"asc"),this.updateSortIndicator(n,r)}}renderGrandTotalFooter(){if(!this.pivotResult)return;const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.querySelector(".tbw-grid-root");t&&(this.grandTotalFooter||(this.grandTotalFooter=document.createElement("div"),this.grandTotalFooter.className="pivot-grand-total-footer",t.appendChild(this.grandTotalFooter)),L({__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals},this.grandTotalFooter,this.gridColumns,this.translate),this.grandTotalFooter.setAttribute("role","presentation"))}cleanupGrandTotalFooter(){this.grandTotalFooter&&(this.grandTotalFooter.remove(),this.grandTotalFooter=null)}toggle(e){this.userHasToggledExpand=!0;const t=this.expandedKeys.has(e);t?this.expandedKeys.delete(e):this.expandedKeys.add(e),this.emitToggle(e,!t),this.requestRender()}expand(e){this.userHasToggledExpand=!0,this.expandedKeys.add(e),this.emitToggle(e,!0),this.requestRender()}collapse(e){this.userHasToggledExpand=!0,this.expandedKeys.delete(e),this.emitToggle(e,!1),this.requestRender()}expandAll(){this.userHasToggledExpand=!0,this.expandAllKeys(),this.requestRender()}collapseAll(){this.userHasToggledExpand=!0,this.expandedKeys.clear(),this.requestRender()}expandAllKeys(){if(!this.pivotResult)return;const e=C(this.pivotResult.rows);for(const t of e)this.expandedKeys.add(t)}isExpanded(e){return this.expandedKeys.has(e)}getExpandedGroups(){return[...this.expandedKeys]}enablePivot(){0===this.originalColumns.length&&this.captureOriginalColumns(),this.isActive=!0,this.emit("pivot-state-change",{active:!0}),this.requestRender()}disablePivot(){this.isActive=!1,this.pivotResult=null,this.emit("pivot-state-change",{active:!1}),this.requestRender()}isPivotActive(){return this.isActive}getPivotResult(){return this.pivotResult}setRowGroupFields(e){this.config.rowGroupFields=e,this.emitConfigChange("rowGroupFields"),this.refresh()}setColumnGroupFields(e){this.config.columnGroupFields=e,this.emitConfigChange("columnGroupFields"),this.refresh()}setValueFields(e){this.config.valueFields=e,this.emitConfigChange("valueFields"),this.refresh()}refresh(){this.pivotResult=null,this.requestRender()}#o(){return this.grid.getPluginByName("shell")}showPanel(){const t=this.#o();t?.openToolPanel(),t?.expandedToolPanelSections.includes(e.PANEL_ID)||t?.toggleToolPanelSection(e.PANEL_ID)}hidePanel(){this.#o()?.closeToolPanel()}togglePanel(){const t=this.#o();t?.isToolPanelOpen||t?.openToolPanel(),t?.toggleToolPanelSection(e.PANEL_ID)}isPanelVisible(){const t=this.#o();return!!t?.isToolPanelOpen&&t.expandedToolPanelSections.includes(e.PANEL_ID)}get gridColumns(){return this.grid.columns??[]}refreshIfActive(){this.isActive&&this.refresh(),this.refreshPanel()}buildFieldHeaderMap(){const e=this.getAvailableFields();this.fieldHeaderMap.clear();for(const t of e)this.fieldHeaderMap.set(t.field,t.header)}getAvailableFields(){return this.originalColumns.length>0?this.originalColumns:this.captureOriginalColumns()}captureOriginalColumns(){try{const e=this.grid.getAllColumns?.()??this.grid.columns??[];return this.originalColumns=e.filter(e=>!e.field.startsWith("__pivot")).map(e=>({field:e.field,header:e.header??e.field})),this.originalColumns}catch{return[]}}renderPanel(e){return this.panelContainer=e,0===this.originalColumns.length&&this.captureOriginalColumns(),A(e,this.config,this.isActive,{onTogglePivot:e=>{e?this.enablePivot():this.disablePivot(),this.refreshPanel()},onAddFieldToZone:(e,t)=>{this.addFieldToZone(e,t),this.emitConfigChange("rowGroups"===t?"rowGroupFields":"columnGroupFields",e,t)},onRemoveFieldFromZone:(e,t)=>{this.removeFieldFromZone(e,t),this.emitConfigChange("rowGroups"===t?"rowGroupFields":"columnGroupFields",e,t)},onReorderFieldInZone:(e,t,o)=>{this.reorderFieldInZone(e,t,o),this.emitConfigChange("rowGroups"===t?"rowGroupFields":"columnGroupFields",e,t)},onMoveFieldBetweenZones:(e,t,o)=>{this.moveFieldBetweenZones(e,t,o),this.emitConfigChange("rowGroups"===o?"rowGroupFields":"columnGroupFields",e,o)},onAddValueField:(e,t)=>{this.addValueField(e,t),this.emitConfigChange("valueFields",e,"values")},onRemoveValueField:e=>{this.removeValueField(e),this.emitConfigChange("valueFields",e,"values")},onUpdateValueAggFunc:(e,t)=>{this.updateValueAggFunc(e,t),this.emitConfigChange("valueFields",e,"values")},onOptionChange:(e,t)=>{this.config[e]=t,this.emitConfigChange(e),this.isActive&&this.refresh()},getAvailableFields:()=>this.getAvailableFields()},this.translate)}refreshPanel(){this.panelContainer&&(this.panelContainer.innerHTML="",this.renderPanel(this.panelContainer))}addFieldToZone(e,t){if("rowGroups"===t){const t=this.config.rowGroupFields??[];t.includes(e)||(this.config.rowGroupFields=[...t,e])}else{const t=this.config.columnGroupFields??[];t.includes(e)||(this.config.columnGroupFields=[...t,e])}this.removeFromOtherZones(e,t),this.refreshIfActive()}removeFieldFromZone(e,t){"rowGroups"===t?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e),this.refreshIfActive()}reorderFieldInZone(e,t,o){const i="rowGroups"===t?[...this.config.rowGroupFields??[]]:[...this.config.columnGroupFields??[]],r=i.indexOf(e);-1!==r&&r!==o&&(i.splice(r,1),i.splice(o>r?o-1:o,0,e),"rowGroups"===t?this.config.rowGroupFields=i:this.config.columnGroupFields=i,this.refreshIfActive())}moveFieldBetweenZones(e,t,o){"rowGroups"===t?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e),"rowGroups"===o?this.config.rowGroupFields=[...this.config.rowGroupFields??[],e]:this.config.columnGroupFields=[...this.config.columnGroupFields??[],e],this.refreshIfActive()}removeFromOtherZones(e,t){"rowGroups"!==t&&(this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e)),"columnGroups"!==t&&(this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e)),"values"!==t&&(this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e))}addValueField(e,t){const o=this.config.valueFields??[];o.some(t=>t.field===e)||(this.config.valueFields=[...o,{field:e,aggFunc:t}]),this.removeFromOtherZones(e,"values"),this.refreshIfActive()}removeValueField(e){this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e),this.refreshIfActive()}updateValueAggFunc(e,t){const o=this.config.valueFields??[],i=o.findIndex(t=>t.field===e);i>=0&&(o[i]={...o[i],aggFunc:t},this.config.valueFields=[...o]),this.isActive&&this.refresh()}emitToggle(e,t){const o=this.rows.find(t=>t.__pivotRowKey===e);this.emit("pivot-toggle",{key:e,expanded:t,label:o?.__pivotLabel??e,depth:o?.__pivotDepth??0})}emitConfigChange(e,t,o){this.emit("pivot-config-change",{property:e,field:t,zone:o})}buildValueFormatters(){this.valueFormatters.clear();const e=this.config.valueFields??[];for(const t of e)if(t.format)this.valueFormatters.set(t.field,t.format);else if(this.originalColumns.find(e=>e.field===t.field)){const e=(this.grid.getAllColumns?.()??this.grid.columns??[]).find(e=>e.field===t.field);if(e?.format){const o=e.format;this.valueFormatters.set(t.field,e=>o(e,{}))}}}};export{P as PivotPlugin};
1
+ var e={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,columnSelected:e=>`Column ${e} selected`,columnSelectionChanged:e=>`${e} columns selected`,columnSelectionCleared:()=>"Column selection cleared",selectionAxisChanged:e=>"column"===e?"Row selection cleared, column selection active":"Column selection cleared, row selection active",editingStarted:e=>`Editing row ${e+1}`,editingCommitted:e=>`Row ${e+1} saved`,dataLoaded:e=>`${e} rows loaded`},t={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function o(e,t){if(!e)return;if(!1===("effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.announcements)return;const o=e.querySelector?.(".tbw-sr-only");o&&(o.textContent="","function"==typeof requestAnimationFrame?requestAnimationFrame(()=>{o.textContent=t}):o.textContent=t)}function i(t,o,...i){const r=(t&&"effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.messages?.[o];return r?r(...i):e[o](...i)}function r(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function n(e,t,o,i){return`${r(o,i)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var s="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(e=>e.split("").reverse().join("")),a=(new RegExp(`__(proto|defineGetter|defineSetter)|${s.slice(3).join("|")}|this\\b`),new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing|math".split("|"))),l=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),c=/^\s*(javascript|vbscript|data|blob):/i;function u(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],o=e.querySelectorAll("*");for(const i of o){const e=i.tagName.toLowerCase();if(a.has(e)){t.push(i);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===i.namespaceURI)&&Array.from(i.attributes).some(e=>l.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(i);continue}const o=[];for(const t of i.attributes){const e=t.name.toLowerCase();l.test(e)?o.push(t.name):"is"!==e?(d.has(e)&&c.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&o.push(t.name):o.push(t.name)}o.forEach(e=>i.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}var p=class{static dependencies;static manifest;aliases;version="3.5.1";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},o={};for(const i of Object.keys(t))o[i]=this;for(const i of e){const e=i.userConfig;for(const[r,s]of Object.entries(e)){if(void 0===s)continue;if(!(r in t)){t[r]=s,o[r]=i;continue}if(t[r]===s)continue;const e=o[r]?.constructor.name??this.constructor.name,a=i.constructor.name,l=n("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${r}" supplied by both ${e} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,o={...e.userConfig};for(const i of Object.keys(t))delete t[i];Object.assign(t,o)}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const o=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(o),o.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}queryBoolean(e,t=null){const o=this.grid?.query?.(e,t);return Array.isArray(o)?o.some(Boolean):!!o}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...t,...e}}t(e,t){return this.grid?.effectiveConfig?.locale?.[e]??t}get translate(){return(e,t)=>this.t(e,t)}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),o=parseInt(t,10);if(!isNaN(o))return o}return 200}setIcon(e,t,o){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const i=this.#t(t,o);var r,n;void 0!==i?"string"==typeof i?(r=e,(n=i)&&"string"==typeof n?-1!==n.indexOf("<")||-1!==n.indexOf("&")?r.replaceChildren(u(n)):r.textContent=n:r.replaceChildren()):i instanceof HTMLElement&&e.replaceChildren(i.cloneNode(!0)):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const o=document.createElement("span");o.setAttribute("part","sort-indicator"),o.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(o,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(o,"sortNone"));const i=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return i?e.insertBefore(o,i):e.appendChild(o),o}warn(e,t){void 0!==t?console.warn(n(e,t,this.gridElement.id,this.name)):console.warn(`${r(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(n(e,t,this.gridElement.id,this.name))}},g={sum:e=>{let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t},avg:e=>{if(!e.length)return 0;let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t/e.length},count:e=>e.length,min:e=>{if(!e.length)return 0;let t=e[0];for(let o=1;o<e.length;o++)e[o]<t&&(t=e[o]);return t},max:e=>{if(!e.length)return 0;let t=e[0];for(let o=1;o<e.length;o++)e[o]>t&&(t=e[o]);return t},first:e=>e[0]??0,last:e=>e[e.length-1]??0};function h(e){return"function"==typeof e?e:function(e){return g[e]??g.sum}(e)}function v(e,t){return[...e,t].join("|")}function f(e,t){const o=t.rowGroupFields??[],i=t.columnGroupFields??[],r=t.valueFields??[],n=function(e,t,o="asc"){if(0===t.length)return["value"];const i=/* @__PURE__ */new Set;for(const n of e){const e=t.map(e=>String(n[e]??"")).join("|");i.add(e)}const r=[...i].sort();return"desc"===o?r.reverse():r}(e,i,t.sortColumns),s=m(e,o,i,n,r,0,"");t.sortRows&&F(s,t.sortRows,r);const a=function(e,t,o){const i={};function r(e){for(const n of e)if(n.isGroup&&n.children?.length)n.children&&r(n.children);else for(const e of t)for(const t of o){const o=v([e],t.field);i[o]=(i[o]??0)+(n.values[o]??0)}}return r(e),i}(s,n,r);return{rows:s,columnKeys:n,totals:a,grandTotal:Object.values(a).reduce((e,t)=>e+t,0)}}function m(e,t,o,i,r,n,s){const a=[];if(0===t.length){const t=b(e,o,i,r),l=w(t);return a.push({rowKey:s||"all",rowLabel:s||"All",depth:n,values:t,total:l,isGroup:!1,rowCount:e.length}),a}const l=t[0],d=t.slice(1),c=d.length>0,u=function(e,t){const o=/* @__PURE__ */new Map;for(const i of e){const e=String(i[t]??""),r=o.get(e);r?r.push(i):o.set(e,[i])}return o}(e,l);for(const[p,g]of u){const e=s?`${s}|${p}`:p,t=b(g,o,i,r),l=w(t);let u;c&&(u=m(g,d,o,i,r,n+1,e)),a.push({rowKey:e,rowLabel:p||"(blank)",depth:n,values:t,total:l,isGroup:c,children:u,rowCount:g.length})}return a}function b(e,t,o,i){const r={};if(0===t.length){for(const t of i){const o=[];for(let r=0;r<e.length;r++){const i=e[r][t.field];if(null==i||""===i)continue;const n=Number(i);isNaN(n)||o.push(n)}const i=h(t.aggFunc);r[v(["value"],t.field)]=o.length>0?i(o):null}return r}const n=/* @__PURE__ */new Map;for(let s=0;s<e.length;s++){const o=e[s];let i=String(o[t[0]]??"");for(let e=1;e<t.length;e++)i+="|",i+=String(o[t[e]]??"");const r=n.get(i);r?r.push(o):n.set(i,[o])}for(const s of o){const e=n.get(s);if(e&&0!==e.length)for(const t of i){const o=[];for(let r=0;r<e.length;r++){const i=e[r][t.field];if(null==i||""===i)continue;const n=Number(i);isNaN(n)||o.push(n)}const i=h(t.aggFunc);r[v([s],t.field)]=o.length>0?i(o):null}else for(const t of i)r[v([s],t.field)]=null}return r}function w(e){let t=0;for(const o of Object.values(e))t+=o??0;return t}function C(e){const t=[];function o(e){if(e.isGroup&&t.push(e.rowKey),e.children)for(const t of e.children)o(t)}for(const i of e)o(i);return t}function F(e,t,o){const i="desc"===t.direction?-1:1;e.sort((e,r)=>"value"===t.by&&(t.valueField??o[0]?.field)?((e.total??0)-(r.total??0))*i:e.rowLabel.localeCompare(r.rowLabel)*i);for(const r of e)r.children?.length&&F(r.children,t,o)}function y(e,t,o){if(0===t.length)return;const i=new Set(o.map(e=>e.field)),r=t.map(e=>"value"===e.by?e.valueField?t=>((e,t)=>{if(null!=e.values[t])return"number"==typeof e.values[t]?e.values[t]:0;if(i.has(t)){const o=`|${t}`;let i=0,r=!1;for(const t of Object.keys(e.values))t.endsWith(o)&&(i+="number"==typeof e.values[t]?e.values[t]:0,r=!0);if(r)return i}return e.total??0})(t,e.valueField):e=>e.total??0:null);e.sort((e,o)=>{for(let i=0;i<t.length;i++){const n=t[i],s="desc"===n.direction?-1:1;let a=0;if("value"===n.by){const t=r[i];a=(t(e)-t(o))*s}else a=e.rowLabel.localeCompare(o.rowLabel)*s;if(0!==a)return a}return 0});for(const n of e)n.children?.length&&y(n.children,t,o)}var x="dragging",_=["sum","avg","count","min","max","first","last"];function A(e,t,o,i,r=(e,t)=>t){const n=new AbortController,s={config:t,callbacks:i,signal:n.signal,t:r},a=document.createElement("div");return a.className="tbw-pivot-panel",a.appendChild(T(r("pivot.options","Options"),()=>function(e,t){const{config:o,callbacks:i,signal:r,t:n}=t,s=document.createElement("div");return s.className="tbw-pivot-options",s.appendChild(R(n("pivot.enable","Enable Pivot View"),e,e=>{i.onTogglePivot(e)},r)),s.appendChild(R(n("pivot.showRowTotals","Show Row Totals"),o.showTotals??!0,e=>{i.onOptionChange("showTotals",e)},r)),s.appendChild(R(n("pivot.showGrandTotal","Show Grand Total"),o.showGrandTotal??!0,e=>{i.onOptionChange("showGrandTotal",e)},r)),s}(o,s))),a.appendChild(T(r("pivot.rowGroups","Row Groups"),()=>E("rowGroups",s))),a.appendChild(T(r("pivot.columnGroups","Column Groups"),()=>E("columnGroups",s))),a.appendChild(T(r("pivot.values","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 t=document.createElement("div");t.className="tbw-pivot-placeholder",t.textContent=e.t("pivot.dropNumericFields","Drag numeric fields here"),r.appendChild(t)}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}(s))),a.appendChild(T(r("pivot.availableFields","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 t=document.createElement("div");t.className="tbw-pivot-placeholder",t.textContent=e.t("pivot.allFieldsUsed","All fields are in use"),r.appendChild(t)}else{const t=document.createElement("div");if(t.className="tbw-pivot-fields-list",a.length>=6){const o=document.createElement("input");o.type="text",o.placeholder=e.t("pivot.filterFields","Filter fields…"),o.className="tbw-pivot-field-search",o.addEventListener("input",()=>{const e=o.value.toLowerCase();for(const o of t.querySelectorAll(".tbw-pivot-field-chip")){const t=o;t.style.display=t.textContent?.toLowerCase().includes(e)?"":"none"}},{signal:i}),r.appendChild(o)}for(const e of a){const o=document.createElement("div");o.className="tbw-pivot-field-chip available",o.textContent=e.header,o.draggable=!0,o.title=`Drag to add "${e.field}" to a zone`,o.addEventListener("dragstart",t=>{t.dataTransfer?.setData("text/plain",e.field),o.classList.add(x)},{signal:i}),o.addEventListener("dragend",()=>{o.classList.remove(x)},{signal:i}),t.appendChild(o)}r.appendChild(t)}return r}(s))),e.appendChild(a),()=>{n.abort(),a.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=t.t("pivot.dropFields","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=o.t("pivot.removeField","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=t.t("pivot.aggFunction","Aggregation function"),l){const e=document.createElement("option");e.value="__custom__",e.textContent=t.t("pivot.customAgg","CUSTOM"),e.selected=!0,d.appendChild(e),d.disabled=!0}for(const u of _){const t=document.createElement("option");t.value=u,t.textContent=u.toUpperCase(),l||(t.selected=u===e.aggFunc),d.appendChild(t)}d.addEventListener("change",()=>{o.onUpdateValueAggFunc(e.field,d.value)},{signal:i});const c=document.createElement("button");return c.type="button",c.className="tbw-pivot-chip-remove",c.innerHTML="×",c.title=t.t("pivot.removeValueField","Remove value field"),c.addEventListener("click",t=>{t.stopPropagation(),o.onRemoveValueField(e.field)},{signal:i}),s.appendChild(a),s.appendChild(d),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,i=(e,t)=>t){return t.className="data-grid-row pivot-grand-total-row",t.innerHTML="",o.forEach((o,r)=>{const n=document.createElement("div");if(n.className="cell",n.setAttribute("data-col",String(r)),0===r){const e=document.createElement("span");e.className="pivot-label",e.textContent=i("pivot.grandTotal","Grand Total"),n.appendChild(e)}else{const t=e[o.field];n.textContent=null!=t?o.format?o.format(t,e):String(t):""}t.appendChild(n)}),!0}var P=class e extends p{static manifest={modifiesRowStructure:!0,hookPriority:{onHeaderClick:-10,processRows:100},incompatibleWith:[{name:"groupingRows",reason:"PivotPlugin creates its own aggregated row and column structure. Row grouping cannot be applied on top of pivot-generated rows."},{name:"tree",reason:"PivotPlugin replaces the entire row and column structure with aggregated pivot data. Tree hierarchy cannot coexist with pivot aggregation."},{name:"serverSide",reason:"PivotPlugin requires the full dataset to compute aggregations. ServerSidePlugin lazy-loads rows in blocks, so pivot aggregation cannot be performed client-side."}],queries:[{type:"sort:get-sort-config",description:"Returns the current pivot sort configuration"}]};static dependencies=[{name:"multiSort",required:!1,reason:"Queries sort model for pivot column sorting"},{name:"shell",required:!1,severity:"warn",when:e=>!0===e.showToolPanel,reason:"PivotPlugin renders its tool panel in a shell host when showToolPanel is enabled"}];name="pivot";styles='@layer tbw-plugins{.pivot-group-row{grid-template-columns:var(--tbw-column-template);background:var(--tbw-pivot-group-bg,var(--tbw-color-row-alt));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider);font-weight:600;display:grid}@media (hover:hover){.pivot-group-row:hover{background:var(--tbw-pivot-group-hover,var(--tbw-color-row-hover))}}.pivot-leaf-row{grid-template-columns:var(--tbw-column-template);background:var(--tbw-pivot-leaf-bg,var(--tbw-color-bg));min-height:var(--tbw-row-height);border-bottom:var(--tbw-row-divider);display:grid}.pivot-grand-total-row{grid-template-columns:var(--tbw-column-template);background:var(--tbw-pivot-grand-total-bg,var(--tbw-color-header-bg));min-height:var(--tbw-row-height);border-top:2px solid var(--tbw-color-border-strong);font-weight:700;display:grid}.pivot-grand-total-row>.cell{padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);align-items:center;min-width:0;display:flex;overflow:hidden}.pivot-grand-total-row>.cell:last-child{border-right:0}.pivot-grand-total-footer{z-index:var(--tbw-z-layer-pinned-rows,20);background:var(--tbw-pivot-grand-total-bg,var(--tbw-color-header-bg));min-width:fit-content;position:sticky;bottom:0}.pivot-group-row>.cell,.pivot-leaf-row>.cell{padding:var(--tbw-cell-padding);border-right:1px solid var(--tbw-color-border-cell);align-items:center;min-width:0;display:flex;overflow:hidden}.pivot-group-row>.cell:last-child,.pivot-leaf-row>.cell:last-child{border-right:0}.pivot-toggle{width:var(--tbw-pivot-toggle-size,var(--tbw-toggle-size,1.25em));height:var(--tbw-pivot-toggle-size,var(--tbw-toggle-size,1.25em));margin-right:var(--tbw-spacing-sm,.375em);cursor:pointer;color:var(--tbw-pivot-toggle-color,var(--tbw-color-fg-muted));border-radius:var(--tbw-border-radius);transition:background var(--tbw-transition-duration,.12s) var(--tbw-transition-ease,ease), color var(--tbw-transition-duration,.12s) var(--tbw-transition-ease,ease);background:0 0;border:none;justify-content:center;align-items:center;display:inline-flex}.pivot-toggle:hover{background:var(--tbw-pivot-toggle-hover-bg,var(--tbw-color-row-hover));color:var(--tbw-pivot-toggle-hover-color,var(--tbw-color-fg))}@media (pointer:coarse){.pivot-toggle{min-width:var(--tbw-touch-target-min,24px);min-height:var(--tbw-touch-target-min,24px)}}.pivot-toggle:focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}.pivot-label{font-weight:inherit}.pivot-count{color:var(--tbw-pivot-count-color,var(--tbw-color-fg-muted));font-size:.9em;font-weight:400}.pivot-total-row{border-top:2px solid var(--tbw-pivot-border,var(--tbw-color-border-strong));font-weight:700}[data-pivot-depth="1"]{--tbw-pivot-depth:1}[data-pivot-depth="2"]{--tbw-pivot-depth:2}[data-pivot-depth="3"]{--tbw-pivot-depth:3}[data-pivot-depth="4"]{--tbw-pivot-depth:4}.tbw-pivot-panel{gap:var(--tbw-panel-padding,var(--tbw-spacing-lg,.75rem));padding:var(--tbw-panel-padding,var(--tbw-spacing-lg,.75rem));height:100%;font-size:var(--tbw-font-size-sm,.8125rem);flex-direction:column;display:flex;overflow-y:auto}.tbw-pivot-section{border:1px solid var(--tbw-pivot-border,var(--tbw-color-border));border-radius:var(--tbw-border-radius);background:var(--tbw-pivot-section-bg,var(--tbw-color-bg))}.tbw-pivot-section-header{padding:var(--tbw-button-padding,var(--tbw-spacing-md,.5rem) var(--tbw-spacing-lg,.75rem));background:var(--tbw-pivot-header-bg,var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-pivot-border,var(--tbw-color-border));border-radius:var(--tbw-border-radius) var(--tbw-border-radius) 0 0;font-weight:600}.tbw-pivot-section-content{padding:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem))}.tbw-pivot-toggle-wrapper{align-items:center;display:flex}.tbw-pivot-toggle-label{align-items:center;gap:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));cursor:pointer;display:flex}.tbw-pivot-toggle-label input{width:var(--tbw-icon-size,1rem);height:var(--tbw-icon-size,1rem);cursor:pointer}.tbw-pivot-drop-zone{min-height:60px;padding:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));border:2px dashed var(--tbw-pivot-drop-border,var(--tbw-color-border));border-radius:var(--tbw-border-radius);background:var(--tbw-pivot-drop-bg,var(--tbw-color-row-alt));gap:var(--tbw-spacing-sm,.375rem);flex-wrap:wrap;align-content:flex-start;transition:all .15s;display:flex}.tbw-pivot-drop-zone.drag-over{border-color:var(--tbw-color-accent);background:var(--tbw-pivot-drop-active,var(--tbw-focus-background))}.tbw-pivot-placeholder{color:var(--tbw-color-fg-muted);padding:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));text-align:center;width:100%;font-style:italic}.tbw-pivot-field-chip{align-items:center;gap:var(--tbw-spacing-sm,.375rem);padding:var(--tbw-button-padding-sm,var(--tbw-spacing-xs,.25rem) var(--tbw-spacing-md,.5rem));background:var(--tbw-pivot-chip-bg,var(--tbw-color-header-bg));border:1px solid var(--tbw-pivot-chip-border,var(--tbw-color-border));border-radius:var(--tbw-border-radius);cursor:grab;font-size:var(--tbw-font-size-xs,.75rem);transition:all .15s;display:inline-flex}.tbw-pivot-field-chip:hover{background:var(--tbw-pivot-chip-hover,var(--tbw-color-row-hover));border-color:var(--tbw-color-accent)}.tbw-pivot-field-chip.available{background:var(--tbw-color-bg)}.tbw-pivot-field-chip.dragging{opacity:.5;cursor:grabbing}.tbw-pivot-chip-label{white-space:nowrap;text-overflow:ellipsis;max-width:120px;overflow:hidden}.tbw-pivot-chip-remove{width:var(--tbw-icon-size,1rem);height:var(--tbw-icon-size,1rem);color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-sm,.875rem);cursor:pointer;background:0 0;border:none;border-radius:50%;justify-content:center;align-items:center;padding:0;font-weight:700;transition:all .15s;display:flex}.tbw-pivot-chip-remove:hover{background:var(--tbw-pivot-chip-remove-hover-bg,var(--tbw-color-accent));color:var(--tbw-pivot-chip-remove-hover-fg,var(--tbw-color-accent-fg))}.tbw-pivot-value-chip{padding:var(--tbw-button-padding-sm,var(--tbw-spacing-xs,.25rem) var(--tbw-spacing-md,.5rem))}.tbw-pivot-value-label-wrapper{align-items:center;gap:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));flex:1;min-width:0;display:flex}.tbw-pivot-agg-select{padding:var(--tbw-spacing-xs,.125rem) var(--tbw-spacing-xs,.25rem);font-size:var(--tbw-font-size-xs,.6875rem);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);cursor:pointer}.tbw-pivot-available-fields{gap:var(--tbw-spacing-sm,.375rem);flex-direction:column;min-height:40px;display:flex}.tbw-pivot-field-search{border:1px solid var(--tbw-color-border,#d0d5dd);border-radius:var(--tbw-radius-sm,.25rem);width:100%;font-size:var(--tbw-font-size-sm,.875rem);background:var(--tbw-color-bg,#fff);color:var(--tbw-color-fg,#1a1a2e);outline:none;padding:.25rem .5rem}.tbw-pivot-field-search:focus{border-color:var(--tbw-color-primary,#3b82f6)}.tbw-pivot-fields-list{gap:var(--tbw-spacing-sm,.375rem);flex-wrap:wrap;display:flex}.tbw-pivot-options{gap:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));flex-direction:column;display:flex}.tbw-pivot-checkbox{align-items:center;gap:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));cursor:pointer;display:flex}.tbw-pivot-checkbox input{width:var(--tbw-icon-size-sm,.875rem);height:var(--tbw-icon-size-sm,.875rem);cursor:pointer}.pivot-group-row.tbw-pivot-slide-in,.pivot-leaf-row.tbw-pivot-slide-in{animation:tbw-pivot-slide-in var(--tbw-animation-duration,.2s) var(--tbw-animation-easing,ease-out) forwards}@keyframes tbw-pivot-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.pivot-group-row.tbw-pivot-fade-in,.pivot-leaf-row.tbw-pivot-fade-in{animation:tbw-pivot-fade-in var(--tbw-animation-duration,.2s) var(--tbw-animation-easing,ease-out) forwards}@keyframes tbw-pivot-fade-in{0%{opacity:0}to{opacity:1}}}';static PANEL_ID="pivot";get defaultConfig(){return{active:!0,showTotals:!0,showGrandTotal:!0,showToolPanel:!0,animation:"slide"}}isActive=!1;hasInitialized=!1;pivotResult=null;fieldHeaderMap=/* @__PURE__ */new Map;expandedKeys=/* @__PURE__ */new Set;defaultExpanded=!0;userHasToggledExpand=!1;originalColumns=[];panelContainer=null;grandTotalFooter=null;previousVisibleKeys=/* @__PURE__ */new Set;keysToAnimate=/* @__PURE__ */new Set;valueFormatters=/* @__PURE__ */new Map;columnTotals={};activeSortField=null;activeSortDir=null;hasValidPivotConfig(){return(this.config.valueFields?.length??0)>0}get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}detach(){this.isActive=!1,this.hasInitialized=!1,this.pivotResult=null,this.fieldHeaderMap.clear(),this.originalColumns=[],this.panelContainer=null,this.cleanupGrandTotalFooter(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.userHasToggledExpand=!1,this.valueFormatters.clear(),this.columnTotals={},this.activeSortField=null,this.activeSortDir=null,this.config.sortRows=void 0}getToolPanel(){if(!1!==(this.config?.showToolPanel??this.userConfig?.showToolPanel??!0))return{id:e.PANEL_ID,title:this.t("pivot.panelTitle","Pivot"),icon:"⊞",tooltip:"Configure pivot table",order:90,render:e=>this.renderPanel(e)}}processRows(e){if(!this.hasInitialized&&!1!==this.config.active&&this.hasValidPivotConfig()&&(this.hasInitialized=!0,this.isActive=!0),!this.isActive)return[...e];const t=function(e){const t=[];return e.rowGroupFields?.length||e.columnGroupFields?.length||t.push("At least one row or column group field is required"),e.valueFields?.length||t.push("At least one value field is required"),t}(this.config);if(t.length>0)return this.warn(`Config errors: ${t.join(", ")}`),[...e];this.buildFieldHeaderMap(),this.buildValueFormatters(),this.defaultExpanded=this.config.defaultExpanded??!0,this.pivotResult=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,this.translate):i.__pivotRowKey&&i.__pivotHasChildren?function(e,t,o){return t.className="data-grid-row pivot-group-row",t.setAttribute("data-pivot-depth",String(e.__pivotDepth??0)),t.setAttribute("data-pivot-key",String(e.__pivotRowKey??"")),t.setAttribute("role","row"),t.innerHTML="",o.columns.forEach((i,r)=>{const n=document.createElement("div");if(n.className="cell",n.setAttribute("data-col",String(r)),n.setAttribute("data-row",String(o.rowIndex)),n.setAttribute("role","gridcell"),0===r){const t=Number(e.__pivotIndent)||0;n.style.paddingLeft=`${t}px`;const i=String(e.__pivotRowKey),r=document.createElement("button");r.type="button",r.className="pivot-toggle",r.setAttribute("aria-label",e.__pivotExpanded?"Collapse group":"Expand group"),o.setIcon(r,e.__pivotExpanded?"collapse":"expand"),r.addEventListener("click",e=>{e.stopPropagation(),o.onToggle(i)}),n.appendChild(r);const s=document.createElement("span");s.className="pivot-label",s.textContent=String(e.__pivotLabel??""),n.appendChild(s);const a=document.createElement("span");a.className="pivot-count",a.textContent=` (${Number(e.__pivotRowCount)||0})`,n.appendChild(a)}else{const t=e[i.field];n.textContent=null!=t?i.format?i.format(t,e):String(t):""}t.appendChild(n)}),!0}(i,t,{columns:this.gridColumns,rowIndex:o,onToggle:e=>this.toggle(e),setIcon:(e,t)=>this.setIcon(e,t)}):void 0!==i.__pivotRowKey&&this.isActive?function(e,t,o,i){return t.className="data-grid-row pivot-leaf-row",t.setAttribute("data-pivot-depth",String(e.__pivotDepth??0)),t.setAttribute("data-pivot-key",String(e.__pivotRowKey??"")),t.innerHTML="",o.forEach((o,r)=>{const n=document.createElement("div");if(n.className="cell",n.setAttribute("data-col",String(r)),n.setAttribute("data-row",String(i)),n.setAttribute("role","gridcell"),0===r){const t=Number(e.__pivotIndent)||0;n.style.paddingLeft=`${t+20}px`;const o=document.createElement("span");o.className="pivot-label",o.textContent=String(e.__pivotLabel??""),n.appendChild(o)}else{const t=e[o.field];n.textContent=null!=t?o.format?o.format(t,e):String(t):""}t.appendChild(n)}),!0}(i,t,this.gridColumns,o):(this.cleanupPivotStyling(t),!1)}cleanupPivotStyling(e){(e.classList.contains("pivot-group-row")||e.classList.contains("pivot-leaf-row")||e.classList.contains("pivot-grand-total-row"))&&(e.classList.remove("pivot-group-row","pivot-leaf-row","pivot-grand-total-row"),e.classList.add("data-grid-row"),e.removeAttribute("data-pivot-depth"),e.innerHTML="")}onKeyDown(e){if(" "!==e.key)return;if(!this.isActive)return;const t=this.grid._focusRow,o=this.rows[t];return o?.__pivotIsGroup&&o.__pivotHasChildren?(e.preventDefault(),this.toggle(o.__pivotRowKey),this.requestRenderWithFocus(),!0):void 0}handleQuery(e){if("sort:get-sort-config"===e.type){const e=this.getMultiSortConfigs();return e||(this.config.sortRows??null)}}onHeaderClick(e){if(!this.isActive)return!1;const t=e.field;if(!this.isPivotField(t))return!1;if(this.isMultiSortActive())return!1;const r=this.mapFieldToSortConfig(t);if(!r)return!1;const n=this.activeSortDir;let s;s=this.activeSortField!==t?"asc":"asc"===n?"desc":null,this.activeSortField=s?t:null,this.activeSortDir=s,this.config.sortRows=s?{...r,direction:s}:void 0,this.emit("pivot-config-change",{property:"sortRows"}),this.refresh();const a=this.gridElement;if(a){const r=e.column.header??t;o(a,s?i(a,"sortApplied",r,"asc"===s?"ascending":"descending"):i(a,"sortCleared"))}return!0}isPivotField(e){return"__pivotLabel"===e||"__pivotTotal"===e||e.includes("|")}isMultiSortActive(){const e=this.grid?.query?.("sort:get-model",null);return Array.isArray(e)&&e.length>0}getMultiSortConfigs(){const e=this.grid?.query?.("sort:get-model",null);if(!e||0===e.length)return null;const t=e[0];if(!Array.isArray(t)||0===t.length)return null;const o=[];for(const i of t){if(!this.isPivotField(i.field))continue;const e=this.mapFieldToSortConfig(i.field);e&&o.push({...e,direction:i.direction})}return o.length>0?o:null}mapFieldToSortConfig(e){return"__pivotLabel"===e?{by:"label"}:"__pivotTotal"===e?{by:"value"}:e.includes("|")?{by:"value",valueField:e}:null}afterRender(){this.isActive&&this.config.showGrandTotal&&this.pivotResult&&!this.config.grandTotalInRowModel?this.renderGrandTotalFooter():this.cleanupGrandTotalFooter(),this.isActive&&!this.isMultiSortActive()&&this.updateSortIndicators();const e=this.animationStyle;if(!1===e||0===this.keysToAnimate.size)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const o="fade"===e?"tbw-pivot-fade-in":"tbw-pivot-slide-in";for(const i of t.querySelectorAll(".pivot-group-row, .pivot-leaf-row")){const e=i.dataset.pivotKey;e&&this.keysToAnimate.has(e)&&(i.classList.add(o),i.addEventListener("animationend",()=>i.classList.remove(o),{once:!0}))}this.keysToAnimate.clear()}updateSortIndicators(){const e=this.gridElement;if(!e)return;const t=this.activeSortField,o=this.activeSortDir,i=t?null:this.config.sortRows,r=e.querySelectorAll(".header-row .cell[data-field]");for(const n of r){const e=n.getAttribute("data-field");if(!e||!this.isPivotField(e))continue;let r=null;t===e?r=o:i&&("label"===i.by&&"__pivotLabel"===e?r=i.direction??"asc":"value"!==i.by||"__pivotTotal"!==e||i.valueField?"value"===i.by&&i.valueField&&e===i.valueField&&(r=i.direction??"asc"):r=i.direction??"asc"),this.updateSortIndicator(n,r)}}renderGrandTotalFooter(){if(!this.pivotResult)return;const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.querySelector(".tbw-grid-root");t&&(this.grandTotalFooter||(this.grandTotalFooter=document.createElement("div"),this.grandTotalFooter.className="pivot-grand-total-footer",t.appendChild(this.grandTotalFooter)),L({__pivotRowKey:"__grandTotal",__pivotLabel:"Grand Total",__pivotIsGrandTotal:!0,__pivotTotal:this.pivotResult.grandTotal,...this.pivotResult.totals},this.grandTotalFooter,this.gridColumns,this.translate),this.grandTotalFooter.setAttribute("role","presentation"))}cleanupGrandTotalFooter(){this.grandTotalFooter&&(this.grandTotalFooter.remove(),this.grandTotalFooter=null)}toggle(e){this.userHasToggledExpand=!0;const t=this.expandedKeys.has(e);t?this.expandedKeys.delete(e):this.expandedKeys.add(e),this.emitToggle(e,!t),this.requestRender()}expand(e){this.userHasToggledExpand=!0,this.expandedKeys.add(e),this.emitToggle(e,!0),this.requestRender()}collapse(e){this.userHasToggledExpand=!0,this.expandedKeys.delete(e),this.emitToggle(e,!1),this.requestRender()}expandAll(){this.userHasToggledExpand=!0,this.expandAllKeys(),this.requestRender()}collapseAll(){this.userHasToggledExpand=!0,this.expandedKeys.clear(),this.requestRender()}expandAllKeys(){if(!this.pivotResult)return;const e=C(this.pivotResult.rows);for(const t of e)this.expandedKeys.add(t)}isExpanded(e){return this.expandedKeys.has(e)}getExpandedGroups(){return[...this.expandedKeys]}enablePivot(){0===this.originalColumns.length&&this.captureOriginalColumns(),this.isActive=!0,this.emit("pivot-state-change",{active:!0}),this.requestRender()}disablePivot(){this.isActive=!1,this.pivotResult=null,this.emit("pivot-state-change",{active:!1}),this.requestRender()}isPivotActive(){return this.isActive}getPivotResult(){return this.pivotResult}setRowGroupFields(e){this.config.rowGroupFields=e,this.emitConfigChange("rowGroupFields"),this.refresh()}setColumnGroupFields(e){this.config.columnGroupFields=e,this.emitConfigChange("columnGroupFields"),this.refresh()}setValueFields(e){this.config.valueFields=e,this.emitConfigChange("valueFields"),this.refresh()}refresh(){this.pivotResult=null,this.requestRender()}#o(){return this.grid.getPluginByName("shell")}showPanel(){const t=this.#o();t?.openToolPanel(),t?.expandedToolPanelSections.includes(e.PANEL_ID)||t?.toggleToolPanelSection(e.PANEL_ID)}hidePanel(){this.#o()?.closeToolPanel()}togglePanel(){const t=this.#o();t?.isToolPanelOpen||t?.openToolPanel(),t?.toggleToolPanelSection(e.PANEL_ID)}isPanelVisible(){const t=this.#o();return!!t?.isToolPanelOpen&&t.expandedToolPanelSections.includes(e.PANEL_ID)}get gridColumns(){return this.grid.columns??[]}refreshIfActive(){this.isActive&&this.refresh(),this.refreshPanel()}buildFieldHeaderMap(){const e=this.getAvailableFields();this.fieldHeaderMap.clear();for(const t of e)this.fieldHeaderMap.set(t.field,t.header)}getAvailableFields(){return this.originalColumns.length>0?this.originalColumns:this.captureOriginalColumns()}captureOriginalColumns(){try{const e=this.grid.getAllColumns?.()??this.grid.columns??[];return this.originalColumns=e.filter(e=>!e.field.startsWith("__pivot")).map(e=>({field:e.field,header:e.header??e.field})),this.originalColumns}catch{return[]}}renderPanel(e){return this.panelContainer=e,0===this.originalColumns.length&&this.captureOriginalColumns(),A(e,this.config,this.isActive,{onTogglePivot:e=>{e?this.enablePivot():this.disablePivot(),this.refreshPanel()},onAddFieldToZone:(e,t)=>{this.addFieldToZone(e,t),this.emitConfigChange("rowGroups"===t?"rowGroupFields":"columnGroupFields",e,t)},onRemoveFieldFromZone:(e,t)=>{this.removeFieldFromZone(e,t),this.emitConfigChange("rowGroups"===t?"rowGroupFields":"columnGroupFields",e,t)},onReorderFieldInZone:(e,t,o)=>{this.reorderFieldInZone(e,t,o),this.emitConfigChange("rowGroups"===t?"rowGroupFields":"columnGroupFields",e,t)},onMoveFieldBetweenZones:(e,t,o)=>{this.moveFieldBetweenZones(e,t,o),this.emitConfigChange("rowGroups"===o?"rowGroupFields":"columnGroupFields",e,o)},onAddValueField:(e,t)=>{this.addValueField(e,t),this.emitConfigChange("valueFields",e,"values")},onRemoveValueField:e=>{this.removeValueField(e),this.emitConfigChange("valueFields",e,"values")},onUpdateValueAggFunc:(e,t)=>{this.updateValueAggFunc(e,t),this.emitConfigChange("valueFields",e,"values")},onOptionChange:(e,t)=>{this.config[e]=t,this.emitConfigChange(e),this.isActive&&this.refresh()},getAvailableFields:()=>this.getAvailableFields()},this.translate)}refreshPanel(){this.panelContainer&&(this.panelContainer.innerHTML="",this.renderPanel(this.panelContainer))}addFieldToZone(e,t){if("rowGroups"===t){const t=this.config.rowGroupFields??[];t.includes(e)||(this.config.rowGroupFields=[...t,e])}else{const t=this.config.columnGroupFields??[];t.includes(e)||(this.config.columnGroupFields=[...t,e])}this.removeFromOtherZones(e,t),this.refreshIfActive()}removeFieldFromZone(e,t){"rowGroups"===t?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e),this.refreshIfActive()}reorderFieldInZone(e,t,o){const i="rowGroups"===t?[...this.config.rowGroupFields??[]]:[...this.config.columnGroupFields??[]],r=i.indexOf(e);-1!==r&&r!==o&&(i.splice(r,1),i.splice(o>r?o-1:o,0,e),"rowGroups"===t?this.config.rowGroupFields=i:this.config.columnGroupFields=i,this.refreshIfActive())}moveFieldBetweenZones(e,t,o){"rowGroups"===t?this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e):this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e),"rowGroups"===o?this.config.rowGroupFields=[...this.config.rowGroupFields??[],e]:this.config.columnGroupFields=[...this.config.columnGroupFields??[],e],this.refreshIfActive()}removeFromOtherZones(e,t){"rowGroups"!==t&&(this.config.rowGroupFields=(this.config.rowGroupFields??[]).filter(t=>t!==e)),"columnGroups"!==t&&(this.config.columnGroupFields=(this.config.columnGroupFields??[]).filter(t=>t!==e)),"values"!==t&&(this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e))}addValueField(e,t){const o=this.config.valueFields??[];o.some(t=>t.field===e)||(this.config.valueFields=[...o,{field:e,aggFunc:t}]),this.removeFromOtherZones(e,"values"),this.refreshIfActive()}removeValueField(e){this.config.valueFields=(this.config.valueFields??[]).filter(t=>t.field!==e),this.refreshIfActive()}updateValueAggFunc(e,t){const o=this.config.valueFields??[],i=o.findIndex(t=>t.field===e);i>=0&&(o[i]={...o[i],aggFunc:t},this.config.valueFields=[...o]),this.isActive&&this.refresh()}emitToggle(e,t){const o=this.rows.find(t=>t.__pivotRowKey===e);this.emit("pivot-toggle",{key:e,expanded:t,label:o?.__pivotLabel??e,depth:o?.__pivotDepth??0})}emitConfigChange(e,t,o){this.emit("pivot-config-change",{property:e,field:t,zone:o})}buildValueFormatters(){this.valueFormatters.clear();const e=this.config.valueFields??[];for(const t of e)if(t.format)this.valueFormatters.set(t.field,t.format);else if(this.originalColumns.find(e=>e.field===t.field)){const e=(this.grid.getAllColumns?.()??this.grid.columns??[]).find(e=>e.field===t.field);if(e?.format){const o=e.format;this.valueFormatters.set(t.field,e=>o(e,{}))}}}};export{P as PivotPlugin};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- function t(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function e(e,i,n,r){return`${t(n,r)} ${e}: ${i}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(e)}`}var i="tbw-print-isolation-style";async function n(t,n={}){const{orientation:r="landscape"}=n,o=t.id;document.querySelectorAll(`#${CSS.escape(o)}`).length>1&&function(t,i,n,r){console.warn(e(t,i,n,r))}("TBW093",`Multiple elements found with id="${o}". Print isolation may not work correctly. Ensure each grid has a unique ID.`,o,"print"),document.getElementById(i)?.remove();const s=function(t,e){const n=document.createElement("style");return n.id=i,n.textContent=`\n /* Print isolation: hide everything except the target grid */\n @media print {\n /* Hide all body children by default */\n body > *:not(#${t}) {\n display: none !important;\n }\n\n /* But show the grid and ensure it's not hidden by ancestor rules */\n #${t} {\n display: block !important;\n position: static !important;\n visibility: visible !important;\n opacity: 1 !important;\n overflow: visible !important;\n height: auto !important;\n width: 100% !important;\n max-height: none !important;\n margin: 0 !important;\n padding: 0 !important;\n transform: none !important;\n }\n\n /* If grid is nested, we need to show its ancestors too */\n #${t},\n #${t} * {\n visibility: visible !important;\n }\n\n /* Walk up the DOM and show all ancestors of the grid */\n body *:has(> #${t}),\n body *:has(#${t}) {\n display: block !important;\n visibility: visible !important;\n opacity: 1 !important;\n overflow: visible !important;\n height: auto !important;\n position: static !important;\n transform: none !important;\n background: transparent !important;\n border: none !important;\n padding: 0 !important;\n margin: 0 !important;\n }\n\n /* Hide siblings of ancestors (everything that's not in the path to the grid) */\n body *:has(#${t}) > *:not(:has(#${t})):not(#${t}) {\n display: none !important;\n }\n\n /* Page settings */\n @page {\n size: ${e};\n margin: 1cm;\n }\n\n /* Ensure proper print styling */\n body {\n margin: 0 !important;\n padding: 0 !important;\n background: white !important;\n color-scheme: light !important;\n }\n }\n\n /* Screen: also apply isolation for print preview */\n @media screen {\n /* When this stylesheet is active, we're about to print */\n /* No screen-specific rules needed - isolation only applies to print */\n }\n `,n}(o,r);return document.head.appendChild(s),new Promise(t=>{const e=()=>{window.removeEventListener("afterprint",e),document.getElementById(i)?.remove(),t()};window.addEventListener("afterprint",e),window.print(),setTimeout(()=>{window.removeEventListener("afterprint",e),document.getElementById(i)?.remove(),t()},5e3)})}var r="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(t=>t.split("").reverse().join("")),o=(new RegExp(`__(proto|defineGetter|defineSetter)|${r.slice(3).join("|")}|this\\b`),new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing|math".split("|"))),s=/^on\w+$/i,a=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),d=/^\s*(javascript|vbscript|data|blob):/i;function l(t){const e=document.createElement("template");return t&&"string"==typeof t&&(e.innerHTML=t,function(t){const e=[],i=t.querySelectorAll("*");for(const n of i){const t=n.tagName.toLowerCase();if(o.has(t)){e.push(n);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===n.namespaceURI)&&Array.from(n.attributes).some(t=>s.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(n);continue}const i=[];for(const e of n.attributes){const t=e.name.toLowerCase();s.test(t)?i.push(e.name):"is"!==t?(a.has(t)&&d.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&i.push(e.name):i.push(e.name)}i.forEach(t=>n.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content)),e.content}var c={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var p=class{static dependencies;static manifest;aliases;version="3.5.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}get resolvedConfig(){return this.#t?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(t){if(0===t.length)return;const i={...this.userConfig},n={};for(const e of Object.keys(i))n[e]=this;for(const r of t){const t=r.userConfig;for(const[o,s]of Object.entries(t)){if(void 0===s)continue;if(!(o in i)){i[o]=s,n[o]=r;continue}if(i[o]===s)continue;const t=n[o]?.constructor.name??this.constructor.name,a=r.constructor.name,d=e("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${t} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(d)}}Object.assign(this.userConfig,i)}refreshUserConfigFrom(t){const e=this.userConfig,i={...t.userConfig};for(const n of Object.keys(e))delete e[n];Object.assign(e,i)}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const i=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}queryBoolean(t,e=null){const i=this.grid?.query?.(t,e);return Array.isArray(i)?i.some(Boolean):!!i}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...c,...t}}t(t,e){return this.grid?.effectiveConfig?.locale?.[t]??e}get translate(){return(t,e)=>this.t(t,e)}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;return!e||"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(e,10);if(!isNaN(i))return i}return 200}setIcon(t,e,i){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const n=this.#e(e,i);var r,o;void 0!==n?"string"==typeof n?(r=t,(o=n)&&"string"==typeof o?-1!==o.indexOf("<")||-1!==o.indexOf("&")?r.replaceChildren(l(o)):r.textContent=o:r.replaceChildren()):n instanceof HTMLElement&&t.replaceChildren(n.cloneNode(!0)):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const i=document.createElement("span");i.setAttribute("part","sort-indicator"),i.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(i,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(i,"sortNone"));const n=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return n?t.insertBefore(i,n):t.appendChild(i),i}warn(i,n){void 0!==n?console.warn(e(i,n,this.gridElement.id,this.name)):console.warn(`${t(this.gridElement.id,this.name)} ${i}`)}throwDiagnostic(t,i){throw new Error(e(t,i,this.gridElement.id,this.name))}},h={button:!1,orientation:"landscape",warnThreshold:500,maxRows:0,includeTitle:!0,includeTimestamp:!0,title:"",isolate:!1},m=class extends p{name="print";version="1.0.0";styles=".tbw-print-header,.tbw-print-footer{display:none}@media print{tbw-grid{color-scheme:light only;-webkit-print-color-adjust:exact;print-color-adjust:exact;border:none!important;border-radius:0!important;height:auto!important;overflow:visible!important}tbw-grid .tbw-grid-content,tbw-grid .tbw-scroll-area,tbw-grid .rows-body{height:auto!important;max-height:none!important;overflow:visible!important}tbw-grid .rows-container,tbw-grid .rows-viewport,tbw-grid .rows{height:auto!important;max-height:none!important;overflow:visible!important;transform:none!important}tbw-grid .rows-viewport .rows{position:static!important}tbw-grid .resize-handle,tbw-grid [part=sort-indicator],tbw-grid .tbw-filter-btn,tbw-grid .tool-panel,tbw-grid .tool-panel-content,tbw-grid .tbw-shell-header,tbw-grid .shell-toolbar,tbw-grid .tool-panel-toggle,tbw-grid [data-print-hide],tbw-grid .expander-cell,tbw-grid .tree-toggle,tbw-grid .context-menu,tbw-grid .faux-vscroll{display:none!important}tbw-grid .tbw-print-header{padding:var(--tbw-spacing-md,.5em) 0;margin-bottom:var(--tbw-spacing-md,.5em);border-bottom:2px solid var(--tbw-print-border,var(--tbw-color-border-strong));justify-content:space-between;align-items:baseline;font-family:inherit;display:flex}.tbw-print-header-title{font-size:1.25em;font-weight:700}.tbw-print-header-timestamp{font-size:var(--tbw-font-size-sm,.875em);color:var(--tbw-print-muted,var(--tbw-color-fg-muted))}tbw-grid .tbw-print-footer{margin-top:var(--tbw-spacing-md,.5em);padding-top:var(--tbw-spacing-md,.5em);border-top:1px solid var(--tbw-print-border,var(--tbw-color-border));font-size:var(--tbw-font-size-xs,.75em);color:var(--tbw-print-muted,var(--tbw-color-fg-muted));text-align:end;display:block}tbw-grid .data-grid-row{break-inside:avoid;page-break-inside:avoid}tbw-grid .cell{border:1px solid var(--tbw-print-cell-border,var(--tbw-color-border))!important}tbw-grid .header-row,tbw-grid .data-grid-row{padding-inline-end:1px}tbw-grid .data-grid-row:hover,tbw-grid .cell:hover{background:inherit!important}@page{margin:1cm}}";#i=!1;#n=null;#r=null;#o=null;#s=null;#a=null;#d=null;get#l(){return this.grid}isPrinting(){return this.#i}async print(t){if(this.#i)return void this.warn("TBW090","Print already in progress");const i=this.gridElement;if(!i)return void this.warn("TBW091","Grid not available");const n={...h,...this.config,...t},r=this.rows.length;let o=r,s=!1;if(n.warnThreshold>0&&r>n.warnThreshold){const t=n.maxRows>0?`\n\nNote: Output will be limited to ${n.maxRows.toLocaleString()} rows.`:"";if(!confirm(`This grid has ${r.toLocaleString()} rows. Printing large datasets may cause performance issues or browser slowdowns.${t}\n\nClick OK to continue, or Cancel to abort.`))return}n.maxRows>0&&r>n.maxRows&&(o=n.maxRows,s=!0),this.#i=!0;const a=performance.now();this.emit("print-start",{rowCount:o,limitApplied:s,originalRowCount:r});try{const t=this.#l;this.#r={bypassThreshold:t._virtualization?.bypassThreshold??24},this.#c(),s&&(this.#o=this.sourceRows,this.grid.rows=this.sourceRows.slice(0,o),await new Promise(t=>setTimeout(t,50))),(n.includeTitle||n.includeTimestamp)&&this.#p(n),await this.#h(),await new Promise(t=>requestAnimationFrame(t)),await new Promise(t=>requestAnimationFrame(t)),i.classList.add(`print-${n.orientation}`),await new Promise(t=>requestAnimationFrame(t)),await new Promise(t=>requestAnimationFrame(t)),n.isolate?await this.#m(n):await this.#u(),this.emit("print-complete",{success:!0,rowCount:o,duration:Math.round(performance.now()-a)})}catch(m){d="TBW092",l=`Print failed: ${m}`,c=this.gridElement?.id,p=this.name,console.error(e(d,l,c,p)),this.emit("print-complete",{success:!1,rowCount:0,duration:Math.round(performance.now()-a)})}finally{this.#g(),this.#i=!1}var d,l,c,p}#p(t){const e=this.gridElement;if(e){if(this.#s=document.createElement("div"),this.#s.className="tbw-print-header",t.includeTitle){const e=t.title||this.grid.effectiveConfig?.shell?.header?.title||"Grid Data",i=document.createElement("div");i.className="tbw-print-header-title",i.textContent=e,this.#s.appendChild(i)}if(t.includeTimestamp){const t=document.createElement("div");t.className="tbw-print-header-timestamp",t.textContent=`Printed: ${/* @__PURE__ */(new Date).toLocaleString()}`,this.#s.appendChild(t)}e.insertBefore(this.#s,e.firstChild),this.#a=document.createElement("div"),this.#a.className="tbw-print-footer",this.#a.textContent=`Page generated from ${window.location.hostname}`,e.appendChild(this.#a)}}async#h(){const t=this.#l;if(!t._virtualization)return;const e=this.rows.length;t._virtualization.bypassThreshold=e+100,t.refreshVirtualWindow(!0),await new Promise(t=>setTimeout(t,100))}async#u(){return new Promise(t=>{const e=()=>{window.removeEventListener("afterprint",e),t()};window.addEventListener("afterprint",e),window.print(),setTimeout(()=>{"undefined"!=typeof window&&window.removeEventListener("afterprint",e),t()},1e3)})}async#m(t){const e=this.gridElement;e&&await n(e,{orientation:t.orientation})}#c(){const t=this.columns;if(t){this.#n=/* @__PURE__ */new Map;for(const e of t)e.field&&(!0===e.printHidden||!0===e.utility&&!1!==e.printHidden)&&(this.#n.set(e.field,!e.hidden),this.grid.setColumnVisible(e.field,!1))}}#w(){if(this.#n){for(const[t,e]of this.#n)this.grid.setColumnVisible(t,e);this.#n=null}}#g(){const t=this.gridElement;if(!t)return;this.#w(),t.classList.remove("print-portrait","print-landscape"),null!==this.#d&&(t.style.transform="",t.style.transformOrigin="",t.style.width="",this.#d=null),this.#s&&(this.#s.remove(),this.#s=null),this.#a&&(this.#a.remove(),this.#a=null);const e=this.#l;this.#r&&e._virtualization&&(e._virtualization.bypassThreshold=this.#r.bypassThreshold,e.refreshVirtualWindow(!0),this.#r=null),null!==this.#o&&(this.grid.rows=this.#o,this.#o=null)}afterRender(){this.config?.button&&!this.#b&&(this.#f(),this.#b=!0)}#b=!1;#f(){this.#l.registerToolbarContent?.({id:"print-button",order:900,render:t=>{const e=document.createElement("button");e.className="tbw-toolbar-btn tbw-print-btn",e.title=this.t("print.buttonTitle","Print grid"),e.type="button",this.setIcon(e,"print"),e.addEventListener("click",()=>{this.print()},{signal:this.disconnectSignal}),t.appendChild(e)}})}};export{m as PrintPlugin,n as printGridIsolated};
1
+ function t(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function e(e,i,n,r){return`${t(n,r)} ${e}: ${i}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(e)}`}var i="tbw-print-isolation-style";async function n(t,n={}){const{orientation:r="landscape"}=n,o=t.id;document.querySelectorAll(`#${CSS.escape(o)}`).length>1&&function(t,i,n,r){console.warn(e(t,i,n,r))}("TBW093",`Multiple elements found with id="${o}". Print isolation may not work correctly. Ensure each grid has a unique ID.`,o,"print"),document.getElementById(i)?.remove();const s=function(t,e){const n=document.createElement("style");return n.id=i,n.textContent=`\n /* Print isolation: hide everything except the target grid */\n @media print {\n /* Hide all body children by default */\n body > *:not(#${t}) {\n display: none !important;\n }\n\n /* But show the grid and ensure it's not hidden by ancestor rules */\n #${t} {\n display: block !important;\n position: static !important;\n visibility: visible !important;\n opacity: 1 !important;\n overflow: visible !important;\n height: auto !important;\n width: 100% !important;\n max-height: none !important;\n margin: 0 !important;\n padding: 0 !important;\n transform: none !important;\n }\n\n /* If grid is nested, we need to show its ancestors too */\n #${t},\n #${t} * {\n visibility: visible !important;\n }\n\n /* Walk up the DOM and show all ancestors of the grid */\n body *:has(> #${t}),\n body *:has(#${t}) {\n display: block !important;\n visibility: visible !important;\n opacity: 1 !important;\n overflow: visible !important;\n height: auto !important;\n position: static !important;\n transform: none !important;\n background: transparent !important;\n border: none !important;\n padding: 0 !important;\n margin: 0 !important;\n }\n\n /* Hide siblings of ancestors (everything that's not in the path to the grid) */\n body *:has(#${t}) > *:not(:has(#${t})):not(#${t}) {\n display: none !important;\n }\n\n /* Page settings */\n @page {\n size: ${e};\n margin: 1cm;\n }\n\n /* Ensure proper print styling */\n body {\n margin: 0 !important;\n padding: 0 !important;\n background: white !important;\n color-scheme: light !important;\n }\n }\n\n /* Screen: also apply isolation for print preview */\n @media screen {\n /* When this stylesheet is active, we're about to print */\n /* No screen-specific rules needed - isolation only applies to print */\n }\n `,n}(o,r);return document.head.appendChild(s),new Promise(t=>{const e=()=>{window.removeEventListener("afterprint",e),document.getElementById(i)?.remove(),t()};window.addEventListener("afterprint",e),window.print(),setTimeout(()=>{window.removeEventListener("afterprint",e),document.getElementById(i)?.remove(),t()},5e3)})}var r="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(t=>t.split("").reverse().join("")),o=(new RegExp(`__(proto|defineGetter|defineSetter)|${r.slice(3).join("|")}|this\\b`),new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing|math".split("|"))),s=/^on\w+$/i,a=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),d=/^\s*(javascript|vbscript|data|blob):/i;function l(t){const e=document.createElement("template");return t&&"string"==typeof t&&(e.innerHTML=t,function(t){const e=[],i=t.querySelectorAll("*");for(const n of i){const t=n.tagName.toLowerCase();if(o.has(t)){e.push(n);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===n.namespaceURI)&&Array.from(n.attributes).some(t=>s.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(n);continue}const i=[];for(const e of n.attributes){const t=e.name.toLowerCase();s.test(t)?i.push(e.name):"is"!==t?(a.has(t)&&d.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&i.push(e.name):i.push(e.name)}i.forEach(t=>n.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content)),e.content}var c={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var p=class{static dependencies;static manifest;aliases;version="3.5.1";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}get resolvedConfig(){return this.#t?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(t){if(0===t.length)return;const i={...this.userConfig},n={};for(const e of Object.keys(i))n[e]=this;for(const r of t){const t=r.userConfig;for(const[o,s]of Object.entries(t)){if(void 0===s)continue;if(!(o in i)){i[o]=s,n[o]=r;continue}if(i[o]===s)continue;const t=n[o]?.constructor.name??this.constructor.name,a=r.constructor.name,d=e("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${t} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(d)}}Object.assign(this.userConfig,i)}refreshUserConfigFrom(t){const e=this.userConfig,i={...t.userConfig};for(const n of Object.keys(e))delete e[n];Object.assign(e,i)}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const i=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}queryBoolean(t,e=null){const i=this.grid?.query?.(t,e);return Array.isArray(i)?i.some(Boolean):!!i}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...c,...t}}t(t,e){return this.grid?.effectiveConfig?.locale?.[t]??e}get translate(){return(t,e)=>this.t(t,e)}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;return!e||"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(e,10);if(!isNaN(i))return i}return 200}setIcon(t,e,i){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const n=this.#e(e,i);var r,o;void 0!==n?"string"==typeof n?(r=t,(o=n)&&"string"==typeof o?-1!==o.indexOf("<")||-1!==o.indexOf("&")?r.replaceChildren(l(o)):r.textContent=o:r.replaceChildren()):n instanceof HTMLElement&&t.replaceChildren(n.cloneNode(!0)):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const i=document.createElement("span");i.setAttribute("part","sort-indicator"),i.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(i,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(i,"sortNone"));const n=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return n?t.insertBefore(i,n):t.appendChild(i),i}warn(i,n){void 0!==n?console.warn(e(i,n,this.gridElement.id,this.name)):console.warn(`${t(this.gridElement.id,this.name)} ${i}`)}throwDiagnostic(t,i){throw new Error(e(t,i,this.gridElement.id,this.name))}},h={button:!1,orientation:"landscape",warnThreshold:500,maxRows:0,includeTitle:!0,includeTimestamp:!0,title:"",isolate:!1},m=class extends p{name="print";version="1.0.0";styles=".tbw-print-header,.tbw-print-footer{display:none}@media print{tbw-grid{color-scheme:light only;-webkit-print-color-adjust:exact;print-color-adjust:exact;border:none!important;border-radius:0!important;height:auto!important;overflow:visible!important}tbw-grid .tbw-grid-content,tbw-grid .tbw-scroll-area,tbw-grid .rows-body{height:auto!important;max-height:none!important;overflow:visible!important}tbw-grid .rows-container,tbw-grid .rows-viewport,tbw-grid .rows{height:auto!important;max-height:none!important;overflow:visible!important;transform:none!important}tbw-grid .rows-viewport .rows{position:static!important}tbw-grid .resize-handle,tbw-grid [part=sort-indicator],tbw-grid .tbw-filter-btn,tbw-grid .tool-panel,tbw-grid .tool-panel-content,tbw-grid .tbw-shell-header,tbw-grid .shell-toolbar,tbw-grid .tool-panel-toggle,tbw-grid [data-print-hide],tbw-grid .expander-cell,tbw-grid .tree-toggle,tbw-grid .context-menu,tbw-grid .faux-vscroll{display:none!important}tbw-grid .tbw-print-header{padding:var(--tbw-spacing-md,.5em) 0;margin-bottom:var(--tbw-spacing-md,.5em);border-bottom:2px solid var(--tbw-print-border,var(--tbw-color-border-strong));justify-content:space-between;align-items:baseline;font-family:inherit;display:flex}.tbw-print-header-title{font-size:1.25em;font-weight:700}.tbw-print-header-timestamp{font-size:var(--tbw-font-size-sm,.875em);color:var(--tbw-print-muted,var(--tbw-color-fg-muted))}tbw-grid .tbw-print-footer{margin-top:var(--tbw-spacing-md,.5em);padding-top:var(--tbw-spacing-md,.5em);border-top:1px solid var(--tbw-print-border,var(--tbw-color-border));font-size:var(--tbw-font-size-xs,.75em);color:var(--tbw-print-muted,var(--tbw-color-fg-muted));text-align:end;display:block}tbw-grid .data-grid-row{break-inside:avoid;page-break-inside:avoid}tbw-grid .cell{border:1px solid var(--tbw-print-cell-border,var(--tbw-color-border))!important}tbw-grid .header-row,tbw-grid .data-grid-row{padding-inline-end:1px}tbw-grid .data-grid-row:hover,tbw-grid .cell:hover{background:inherit!important}@page{margin:1cm}}";#i=!1;#n=null;#r=null;#o=null;#s=null;#a=null;#d=null;get#l(){return this.grid}isPrinting(){return this.#i}async print(t){if(this.#i)return void this.warn("TBW090","Print already in progress");const i=this.gridElement;if(!i)return void this.warn("TBW091","Grid not available");const n={...h,...this.config,...t},r=this.rows.length;let o=r,s=!1;if(n.warnThreshold>0&&r>n.warnThreshold){const t=n.maxRows>0?`\n\nNote: Output will be limited to ${n.maxRows.toLocaleString()} rows.`:"";if(!confirm(`This grid has ${r.toLocaleString()} rows. Printing large datasets may cause performance issues or browser slowdowns.${t}\n\nClick OK to continue, or Cancel to abort.`))return}n.maxRows>0&&r>n.maxRows&&(o=n.maxRows,s=!0),this.#i=!0;const a=performance.now();this.emit("print-start",{rowCount:o,limitApplied:s,originalRowCount:r});try{const t=this.#l;this.#r={bypassThreshold:t._virtualization?.bypassThreshold??24},this.#c(),s&&(this.#o=this.sourceRows,this.grid.rows=this.sourceRows.slice(0,o),await new Promise(t=>setTimeout(t,50))),(n.includeTitle||n.includeTimestamp)&&this.#p(n),await this.#h(),await new Promise(t=>requestAnimationFrame(t)),await new Promise(t=>requestAnimationFrame(t)),i.classList.add(`print-${n.orientation}`),await new Promise(t=>requestAnimationFrame(t)),await new Promise(t=>requestAnimationFrame(t)),n.isolate?await this.#m(n):await this.#u(),this.emit("print-complete",{success:!0,rowCount:o,duration:Math.round(performance.now()-a)})}catch(m){d="TBW092",l=`Print failed: ${m}`,c=this.gridElement?.id,p=this.name,console.error(e(d,l,c,p)),this.emit("print-complete",{success:!1,rowCount:0,duration:Math.round(performance.now()-a)})}finally{this.#g(),this.#i=!1}var d,l,c,p}#p(t){const e=this.gridElement;if(e){if(this.#s=document.createElement("div"),this.#s.className="tbw-print-header",t.includeTitle){const e=t.title||this.grid.effectiveConfig?.shell?.header?.title||"Grid Data",i=document.createElement("div");i.className="tbw-print-header-title",i.textContent=e,this.#s.appendChild(i)}if(t.includeTimestamp){const t=document.createElement("div");t.className="tbw-print-header-timestamp",t.textContent=`Printed: ${/* @__PURE__ */(new Date).toLocaleString()}`,this.#s.appendChild(t)}e.insertBefore(this.#s,e.firstChild),this.#a=document.createElement("div"),this.#a.className="tbw-print-footer",this.#a.textContent=`Page generated from ${window.location.hostname}`,e.appendChild(this.#a)}}async#h(){const t=this.#l;if(!t._virtualization)return;const e=this.rows.length;t._virtualization.bypassThreshold=e+100,t.refreshVirtualWindow(!0),await new Promise(t=>setTimeout(t,100))}async#u(){return new Promise(t=>{const e=()=>{window.removeEventListener("afterprint",e),t()};window.addEventListener("afterprint",e),window.print(),setTimeout(()=>{"undefined"!=typeof window&&window.removeEventListener("afterprint",e),t()},1e3)})}async#m(t){const e=this.gridElement;e&&await n(e,{orientation:t.orientation})}#c(){const t=this.columns;if(t){this.#n=/* @__PURE__ */new Map;for(const e of t)e.field&&(!0===e.printHidden||!0===e.utility&&!1!==e.printHidden)&&(this.#n.set(e.field,!e.hidden),this.grid.setColumnVisible(e.field,!1))}}#w(){if(this.#n){for(const[t,e]of this.#n)this.grid.setColumnVisible(t,e);this.#n=null}}#g(){const t=this.gridElement;if(!t)return;this.#w(),t.classList.remove("print-portrait","print-landscape"),null!==this.#d&&(t.style.transform="",t.style.transformOrigin="",t.style.width="",this.#d=null),this.#s&&(this.#s.remove(),this.#s=null),this.#a&&(this.#a.remove(),this.#a=null);const e=this.#l;this.#r&&e._virtualization&&(e._virtualization.bypassThreshold=this.#r.bypassThreshold,e.refreshVirtualWindow(!0),this.#r=null),null!==this.#o&&(this.grid.rows=this.#o,this.#o=null)}afterRender(){this.config?.button&&!this.#b&&(this.#f(),this.#b=!0)}#b=!1;#f(){this.#l.registerToolbarContent?.({id:"print-button",order:900,render:t=>{const e=document.createElement("button");e.className="tbw-toolbar-btn tbw-print-btn",e.title=this.t("print.buttonTitle","Print grid"),e.type="button",this.setIcon(e,"print"),e.addEventListener("click",()=>{this.print()},{signal:this.disconnectSignal}),t.appendChild(e)}})}};export{m as PrintPlugin,n as printGridIsolated};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- var e="editing",t="dragging";function r(e,t){if(!t.capped)return e;const r=t.spacerHeight-t.viewportHeight,i=t.rawContentHeight-t.viewportHeight;return r<=0||i<=0?e:e*r/i}function i(t,i){!function(e){if(!e._virtualization?.enabled)return;const{rowHeight:t,container:i,viewportEl:n,scrollMapping:o}=e._virtualization,s=i,a=n?.clientHeight??s?.clientHeight??0;if(!s||a<=0)return;const l=e._focusRow*t,d=o?function(e,t){if(!t.capped)return e;const r=t.spacerHeight-t.viewportHeight,i=t.rawContentHeight-t.viewportHeight;if(r<=0||i<=0)return e;const n=e*i/r;return n<0?0:n>i?i:n}(s.scrollTop,o):s.scrollTop;if(l<d)s.scrollTop=o?r(l,o):l;else if(l+t>d+a){const e=l-a+t;s.scrollTop=o?r(e,o):e}}(t);const n=function(e){return void 0!==e._activeEditRows&&-1!==e._activeEditRows}(t)||!!t._isGridEditMode;var o;n||t.refreshVirtualWindow(!1),(o=t._bodyEl)&&o.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus")),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(e=>{e.setAttribute("aria-selected","false")});const s=function(e){const t=e._focusRow,r=e._virtualization.start??0,i=e._virtualization.end??e._rows.length;if(t<r||t>=i)return;const n=e._bodyEl.querySelectorAll(".data-grid-row")[t-r];let o=n?.children[e._focusCol];return o&&o.classList?.contains("cell")||(o=n?.querySelector(`.cell[data-col="${e._focusCol}"]`)??n?.querySelector(".cell[data-col]")),o?{rowEl:n??null,cell:o}:void 0}(t);if(!s)return;const{rowEl:a,cell:l}=s;l.classList.add("cell-focus"),l.setAttribute("aria-selected","true"),n&&!i?.forceHorizontalScroll||function(e,t,r,i){const n=e.querySelector(".tbw-scroll-area");if(!n)return;if(i?.forceScrollLeft)return void(n.scrollLeft=0);if(i?.forceScrollRight)return void(n.scrollLeft=n.scrollWidth-n.clientWidth);const o=e._getHorizontalScrollOffsets?.(t??void 0,r)??{left:0,right:0};if(o.skipScroll)return;const s=r.getBoundingClientRect(),a=n.getBoundingClientRect(),l=s.left-a.left+n.scrollLeft,d=l+s.width,c=n.scrollLeft+o.left,u=n.scrollLeft+n.clientWidth-o.right;l<c?n.scrollLeft=l-o.left:d>u&&(n.scrollLeft=d-n.clientWidth+o.right)}(t,a,l,i),function(t,r,i){if(i&&r.classList.contains(e)){const e=r.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(e&&document.activeElement!==e)try{e.focus({preventScroll:!0})}catch{}return}if(i){if(r.contains(document.activeElement))return;r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1");try{r.focus({preventScroll:!0})}catch{}return}const n=document.activeElement;n instanceof HTMLElement&&n!==t&&"function"==typeof t.contains&&t.contains(n)&&!n.classList.contains("cell")&&!n.closest(".cell")||n===t||t.focus({preventScroll:!0})}(t,l,n)}function n(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function o(e,t,r,i){return`${n(r,i)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var s="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(e=>e.split("").reverse().join("")),a=(new RegExp(`__(proto|defineGetter|defineSetter)|${s.slice(3).join("|")}|this\\b`),new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing|math".split("|"))),l=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),c=/^\s*(javascript|vbscript|data|blob):/i;function u(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const i of r){const e=i.tagName.toLowerCase();if(a.has(e)){t.push(i);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===i.namespaceURI)&&Array.from(i.attributes).some(e=>l.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(i);continue}const r=[];for(const t of i.attributes){const e=t.name.toLowerCase();l.test(e)?r.push(t.name):"is"!==e?(d.has(e)&&c.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name):r.push(t.name)}r.forEach(e=>i.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}var g={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var f=class{static dependencies;static manifest;aliases;version="3.5.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 i of Object.keys(t))r[i]=this;for(const i of e){const e=i.userConfig;for(const[n,s]of Object.entries(e)){if(void 0===s)continue;if(!(n in t)){t[n]=s,r[n]=i;continue}if(t[n]===s)continue;const e=r[n]?.constructor.name??this.constructor.name,a=i.constructor.name,l=o("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${e} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const i of Object.keys(t))delete t[i];Object.assign(t,r)}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const r=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(r),r.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}queryBoolean(e,t=null){const r=this.grid?.query?.(e,t);return Array.isArray(r)?r.some(Boolean):!!r}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{...g,...e}}t(e,t){return this.grid?.effectiveConfig?.locale?.[e]??t}get translate(){return(e,t)=>this.t(e,t)}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),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 i=this.#t(t,r);var n,o;void 0!==i?"string"==typeof i?(n=e,(o=i)&&"string"==typeof o?-1!==o.indexOf("<")||-1!==o.indexOf("&")?n.replaceChildren(u(o)):n.textContent=o:n.replaceChildren()):i instanceof HTMLElement&&e.replaceChildren(i.cloneNode(!0)):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const 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 i=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return i?e.insertBefore(r,i):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(o(e,t,this.gridElement.id,this.name)):console.warn(`${n(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(o(e,t,this.gridElement.id,this.name))}};function h(e){if(!0===e.lockPosition)return!1;if(!0===e.utility)return!1;const t=e.meta??{};return!0!==t.lockPosition&&!0!==t.suppressMovable}function m(e,t,r){if(t===r)return e;if(t<0||t>=e.length)return e;if(r<0||r>e.length)return e;const i=[...e],[n]=i.splice(t,1);return i.splice(r,0,n),i}var p="canMoveColumn",v=class extends f{name="reorderColumns";aliases=["reorder"];styles='@layer tbw-plugins{.header-row>.cell[draggable=true]{cursor:grab;position:relative}.header-row>.cell.dragging{opacity:.5;cursor:grabbing}.header-row>.cell.drop-before:before{content:"";background:var(--tbw-reorder-indicator,var(--tbw-color-accent));z-index:1;width:2px;position:absolute;top:0;bottom:0;left:0}.header-row>.cell.drop-after:after{content:"";background:var(--tbw-reorder-indicator,var(--tbw-color-accent));z-index:1;width:2px;position:absolute;top:0;bottom:0;right:0}.cell.flip-animating{transition:transform var(--tbw-animation-duration,.2s) ease-out;will-change:transform;z-index:1}@keyframes reorder-fade-in{0%{opacity:0}to{opacity:1}}.cell.fade-animating{animation:reorder-fade-in var(--tbw-animation-duration,.2s) ease-out backwards}}';static manifest={queries:[{type:p,description:"Authoritative check for whether a column may be reordered (honors lockPosition)."}]};handleQuery(e){if(e.type===p){const t=e.context;return t?h(t):void 0}}get defaultConfig(){return{animation:"flip"}}get animationType(){return!!this.isAnimationEnabled&&(void 0!==this.config.animation?this.config.animation:"flip")}get animationDuration(){return void 0!==this.config.animationDuration?this.config.animationDuration:super.animationDuration}isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;draggedGroupFields=[];originalColumnOrder=null;get#r(){return this.grid}canMoveColumnWithPlugins(e){return!(!e||!h(e))&&!this.grid.query(p,e).includes(!1)}clearDragClasses(){this.gridElement?.querySelectorAll(".header-row > .cell, .header-group-row > .cell").forEach(e=>{e.classList.remove(t,"drop-target","drop-before","drop-after")})}attach(e){super.attach(e),this.gridElement.addEventListener("column-reorder-request",e=>{const t=e.detail;t?.field&&"number"==typeof t.toIndex&&this.moveColumn(t.field,t.toIndex)},{signal:this.disconnectSignal})}detach(){this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.draggedGroupFields=[]}afterRender(){const e=this.gridElement;e&&(this.originalColumnOrder||(this.originalColumnOrder=this.columns.map(e=>e.field)),e.querySelectorAll(".header-row > .cell").forEach(e=>{const r=e,i=r.getAttribute("data-field");if(!i)return;const n=this.columns.find(e=>e.field===i);this.canMoveColumnWithPlugins(n)?(r.draggable=!0,r.getAttribute("data-dragstart-bound")||(r.setAttribute("data-dragstart-bound","true"),r.addEventListener("dragstart",e=>{const n=this.getColumnOrder().indexOf(i);this.isDragging=!0,this.draggedField=i,this.draggedIndex=n,this.draggedGroupFields=[],e.dataTransfer&&(e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",i)),r.classList.add(t)}),r.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.draggedGroupFields=[],this.clearDragClasses()}),r.addEventListener("dragover",e=>{if(e.preventDefault(),!this.isDragging)return;if(this.draggedField===i&&0===this.draggedGroupFields.length)return;if(this.draggedGroupFields.includes(i))return;const n=r.getBoundingClientRect(),o=n.left+n.width/2,s=this.getColumnOrder().indexOf(i);if(this.dropIndex=e.clientX<o?s:s+1,this.clearDragClasses(),this.draggedGroupFields.length>0)for(const r of this.draggedGroupFields)this.gridElement?.querySelector(`.header-row > .cell[data-field="${r}"]`)?.classList.add(t);else this.draggedField&&this.gridElement?.querySelector(`.header-row > .cell[data-field="${this.draggedField}"]`)?.classList.add(t);r.classList.add("drop-target"),r.classList.toggle("drop-before",e.clientX<o),r.classList.toggle("drop-after",e.clientX>=o)}),r.addEventListener("dragleave",()=>{r.classList.remove("drop-target","drop-before","drop-after")}),r.addEventListener("drop",e=>{if(e.preventDefault(),!this.isDragging)return;if(this.draggedGroupFields.length>0){if(this.draggedGroupFields.includes(i))return;const t=r.getBoundingClientRect(),n=e.clientX<t.left+t.width/2;return void this.executeGroupBlockMove(this.draggedGroupFields,[i],n)}const t=this.draggedField,n=this.draggedIndex,o=this.dropIndex;if(!this.isDragging||null===t||null===n||null===o)return;const s=o>n?o-1:o,a=m(this.getColumnOrder(),n,s),l={field:t,fromIndex:n,toIndex:s,columnOrder:a};this.emitCancelable("column-move",l)||this.updateColumnOrder(a)}))):r.draggable=!1}),queueMicrotask(()=>this.setupGroupHeaderDrag(e)))}setupGroupHeaderDrag(e){e.querySelectorAll(".header-group-row > .cell[data-group]").forEach(r=>{const i=r,n=i.getAttribute("data-group");if(!n||n.startsWith("__implicit__"))return;if(i.getAttribute("data-group-drag-bound"))return;i.setAttribute("data-group-drag-bound","true");const o=this.getGroupFragmentFields(i,n);0!==o.length&&o.every(e=>{const t=this.columns.find(t=>t.field===e);return this.canMoveColumnWithPlugins(t)})&&(i.draggable=!0,i.style.cursor="grab",i.addEventListener("dragstart",r=>{this.isDragging=!0,this.draggedField=null,this.draggedIndex=null,this.draggedGroupFields=[...o],r.dataTransfer&&(r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",`group:${n}`)),i.classList.add(t);for(const i of o)e.querySelector(`.header-row > .cell[data-field="${i}"]`)?.classList.add(t)}),i.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.draggedGroupFields=[],this.clearDragClasses()}),i.addEventListener("dragover",e=>{if(e.preventDefault(),!this.isDragging)return;if(this.draggedGroupFields.length>0&&this.draggedGroupFields.length===o.length&&this.draggedGroupFields.every(e=>o.includes(e)))return;const t=i.getBoundingClientRect(),r=t.left+t.width/2,n=e.clientX<r;this.clearDragClasses(),i.classList.add("drop-target"),i.classList.toggle("drop-before",n),i.classList.toggle("drop-after",!n)}),i.addEventListener("dragleave",()=>{i.classList.remove("drop-target","drop-before","drop-after")}),i.addEventListener("drop",e=>{if(e.preventDefault(),!this.isDragging)return;const t=i.getBoundingClientRect(),r=e.clientX<t.left+t.width/2;if(this.draggedGroupFields.length>0){if(this.draggedGroupFields.length===o.length&&this.draggedGroupFields.every(e=>o.includes(e)))return;this.executeGroupBlockMove(this.draggedGroupFields,o,r)}else if(this.draggedField){const e=this.getColumnOrder(),t=r?o[0]:o[o.length-1],i=e.indexOf(this.draggedField),n=r?e.indexOf(t):e.indexOf(t)+1;if(-1===i||-1===n)return;const s=n>i?n-1:n,a=m(e,i,s);this.emitCancelable("column-move",{field:this.draggedField,fromIndex:i,toIndex:s,columnOrder:a})||this.updateColumnOrder(a)}}))})}getGroupFragmentFields(e,t){const r=e.style.gridColumn,i=/(\d+)\s*\/\s*span\s+(\d+)/.exec(r);if(!i)return[];const n=parseInt(i[1],10),o=parseInt(i[2],10),s=this.visibleColumns,a=[];for(let l=n-1;l<n-1+o&&l<s.length;l++){const e=s[l];e&&a.push(e.field)}return a}executeGroupBlockMove(e,t,r){const i=this.getColumnOrder(),n=i.filter(t=>!e.includes(t)),o=r?t[0]:t[t.length-1],s=n.indexOf(o);if(-1===s)return;const a=r?s:s+1,l=i.filter(t=>e.includes(t));n.splice(a,0,...l),this.emitCancelable("column-move",{field:e[0],fromIndex:i.indexOf(e[0]),toIndex:a,columnOrder:n})||this.updateColumnOrder(n)}onKeyDown(e){if(!e.altKey||"ArrowLeft"!==e.key&&"ArrowRight"!==e.key)return;const t=this.#r,r=t._focusCol,n=t._visibleColumns;if(r<0||r>=n.length)return;const o=n[r];if(!this.canMoveColumnWithPlugins(o))return;const s=this.getColumnOrder(),a=s.indexOf(o.field);if(-1===a)return;const l="ArrowLeft"===e.key?a-1:a+1;if(l<0||l>=s.length)return;const d=n.find(e=>e.field===s[l]);return this.canMoveColumnWithPlugins(d)?(this.moveColumn(o.field,l),t._focusCol=l,i(this.#r),e.preventDefault(),e.stopPropagation(),!0):void 0}getColumnOrder(){return this.grid.getColumnOrder()}moveColumn(e,t){const r=this.getColumnOrder(),i=r.indexOf(e);if(-1===i)return;const n=m(r,i,t);this.emitCancelable("column-move",{field:e,fromIndex:i,toIndex:t,columnOrder:n})||this.updateColumnOrder(n)}setColumnOrder(e){this.updateColumnOrder(e)}resetColumnOrder(){const e=this.originalColumnOrder??this.columns.map(e=>e.field);this.updateColumnOrder(e)}captureHeaderPositions(){const e=/* @__PURE__ */new Map;return this.gridElement?.querySelectorAll(".header-row > .cell[data-field]").forEach(t=>{const r=t.getAttribute("data-field");r&&e.set(r,t.getBoundingClientRect().left)}),e}animateFLIP(e){const t=this.gridElement;if(!t||0===e.size)return;const r=/* @__PURE__ */new Map;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(t=>{const i=t.getAttribute("data-field");if(!i)return;const n=e.get(i);if(void 0===n)return;const o=n-t.getBoundingClientRect().left;Math.abs(o)>1&&r.set(i,o)}),0===r.size)return;const i=[];if(t.querySelectorAll(".cell[data-field]").forEach(e=>{const t=r.get(e.getAttribute("data-field")??"");if(void 0!==t){const r=e;r.style.transform=`translateX(${t}px)`,i.push(r)}}),0===i.length)return;t.offsetHeight;const n=this.animationDuration;requestAnimationFrame(()=>{i.forEach(e=>{e.classList.add("flip-animating"),e.style.transform=""}),setTimeout(()=>{i.forEach(e=>{e.style.transform="",e.classList.remove("flip-animating")})},n+50)})}animateFade(e){const t=this.gridElement;if(!t)return void e();const r=this.captureHeaderPositions();e();const i=/* @__PURE__ */new Set;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(e=>{const t=e.getAttribute("data-field");if(!t)return;const n=r.get(t);if(void 0===n)return;const o=e.getBoundingClientRect().left;Math.abs(n-o)>1&&i.add(t)}),0===i.size)return;const n=[];if(t.querySelectorAll(".cell[data-field]").forEach(e=>{const t=e.getAttribute("data-field");if(t&&i.has(t)){const t=e;t.classList.add("fade-animating"),n.push(t)}}),0===n.length)return;const o=this.animationDuration;setTimeout(()=>{n.forEach(e=>e.classList.remove("fade-animating"))},o+50)}updateColumnOrder(e){const t=this.animationType;if("flip"===t&&this.gridElement){const t=this.captureHeaderPositions();this.grid.setColumnOrder(e),"function"==typeof this.grid.forceLayout?this.grid.forceLayout().then(()=>{this.animateFLIP(t)}):requestAnimationFrame(()=>{this.animateFLIP(t)})}else"fade"===t?this.animateFade(()=>this.grid.setColumnOrder(e)):this.grid.setColumnOrder(e);this.grid.requestStateChange?.()}};export{v as ReorderPlugin};
1
+ var e="editing",t="dragging";function r(e,t){if(!t.capped)return e;const r=t.spacerHeight-t.viewportHeight,i=t.rawContentHeight-t.viewportHeight;return r<=0||i<=0?e:e*r/i}function i(t,i){!function(e){if(!e._virtualization?.enabled)return;const{rowHeight:t,container:i,viewportEl:n,scrollMapping:o}=e._virtualization,s=i,a=n?.clientHeight??s?.clientHeight??0;if(!s||a<=0)return;const l=e._focusRow*t,d=o?function(e,t){if(!t.capped)return e;const r=t.spacerHeight-t.viewportHeight,i=t.rawContentHeight-t.viewportHeight;if(r<=0||i<=0)return e;const n=e*i/r;return n<0?0:n>i?i:n}(s.scrollTop,o):s.scrollTop;if(l<d)s.scrollTop=o?r(l,o):l;else if(l+t>d+a){const e=l-a+t;s.scrollTop=o?r(e,o):e}}(t);const n=function(e){return void 0!==e._activeEditRows&&-1!==e._activeEditRows}(t)||!!t._isGridEditMode;var o;n||t.refreshVirtualWindow(!1),(o=t._bodyEl)&&o.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus")),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(e=>{e.setAttribute("aria-selected","false")});const s=function(e){const t=e._focusRow,r=e._virtualization.start??0,i=e._virtualization.end??e._rows.length;if(t<r||t>=i)return;const n=e._bodyEl.querySelectorAll(".data-grid-row")[t-r];let o=n?.children[e._focusCol];return o&&o.classList?.contains("cell")||(o=n?.querySelector(`.cell[data-col="${e._focusCol}"]`)??n?.querySelector(".cell[data-col]")),o?{rowEl:n??null,cell:o}:void 0}(t);if(!s)return;const{rowEl:a,cell:l}=s;l.classList.add("cell-focus"),l.setAttribute("aria-selected","true"),n&&!i?.forceHorizontalScroll||function(e,t,r,i){const n=e.querySelector(".tbw-scroll-area");if(!n)return;if(i?.forceScrollLeft)return void(n.scrollLeft=0);if(i?.forceScrollRight)return void(n.scrollLeft=n.scrollWidth-n.clientWidth);const o=e._getHorizontalScrollOffsets?.(t??void 0,r)??{left:0,right:0};if(o.skipScroll)return;const s=r.getBoundingClientRect(),a=n.getBoundingClientRect(),l=s.left-a.left+n.scrollLeft,d=l+s.width,c=n.scrollLeft+o.left,u=n.scrollLeft+n.clientWidth-o.right;l<c?n.scrollLeft=l-o.left:d>u&&(n.scrollLeft=d-n.clientWidth+o.right)}(t,a,l,i),function(t,r,i){if(i&&r.classList.contains(e)){const e=r.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(e&&document.activeElement!==e)try{e.focus({preventScroll:!0})}catch{}return}if(i){if(r.contains(document.activeElement))return;r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1");try{r.focus({preventScroll:!0})}catch{}return}const n=document.activeElement;n instanceof HTMLElement&&n!==t&&"function"==typeof t.contains&&t.contains(n)&&!n.classList.contains("cell")&&!n.closest(".cell")||n===t||t.focus({preventScroll:!0})}(t,l,n)}function n(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function o(e,t,r,i){return`${n(r,i)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var s="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(e=>e.split("").reverse().join("")),a=(new RegExp(`__(proto|defineGetter|defineSetter)|${s.slice(3).join("|")}|this\\b`),new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing|math".split("|"))),l=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),c=/^\s*(javascript|vbscript|data|blob):/i;function u(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const i of r){const e=i.tagName.toLowerCase();if(a.has(e)){t.push(i);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===i.namespaceURI)&&Array.from(i.attributes).some(e=>l.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(i);continue}const r=[];for(const t of i.attributes){const e=t.name.toLowerCase();l.test(e)?r.push(t.name):"is"!==e?(d.has(e)&&c.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name):r.push(t.name)}r.forEach(e=>i.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}var g={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var f=class{static dependencies;static manifest;aliases;version="3.5.1";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},r={};for(const i of Object.keys(t))r[i]=this;for(const i of e){const e=i.userConfig;for(const[n,s]of Object.entries(e)){if(void 0===s)continue;if(!(n in t)){t[n]=s,r[n]=i;continue}if(t[n]===s)continue;const e=r[n]?.constructor.name??this.constructor.name,a=i.constructor.name,l=o("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${e} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const i of Object.keys(t))delete t[i];Object.assign(t,r)}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const r=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(r),r.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}queryBoolean(e,t=null){const r=this.grid?.query?.(e,t);return Array.isArray(r)?r.some(Boolean):!!r}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{...g,...e}}t(e,t){return this.grid?.effectiveConfig?.locale?.[e]??t}get translate(){return(e,t)=>this.t(e,t)}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),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 i=this.#t(t,r);var n,o;void 0!==i?"string"==typeof i?(n=e,(o=i)&&"string"==typeof o?-1!==o.indexOf("<")||-1!==o.indexOf("&")?n.replaceChildren(u(o)):n.textContent=o:n.replaceChildren()):i instanceof HTMLElement&&e.replaceChildren(i.cloneNode(!0)):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const 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 i=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return i?e.insertBefore(r,i):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(o(e,t,this.gridElement.id,this.name)):console.warn(`${n(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(o(e,t,this.gridElement.id,this.name))}};function h(e){if(!0===e.lockPosition)return!1;if(!0===e.utility)return!1;const t=e.meta??{};return!0!==t.lockPosition&&!0!==t.suppressMovable}function m(e,t,r){if(t===r)return e;if(t<0||t>=e.length)return e;if(r<0||r>e.length)return e;const i=[...e],[n]=i.splice(t,1);return i.splice(r,0,n),i}var p="canMoveColumn",v=class extends f{name="reorderColumns";aliases=["reorder"];styles='@layer tbw-plugins{.header-row>.cell[draggable=true]{cursor:grab;position:relative}.header-row>.cell.dragging{opacity:.5;cursor:grabbing}.header-row>.cell.drop-before:before{content:"";background:var(--tbw-reorder-indicator,var(--tbw-color-accent));z-index:1;width:2px;position:absolute;top:0;bottom:0;left:0}.header-row>.cell.drop-after:after{content:"";background:var(--tbw-reorder-indicator,var(--tbw-color-accent));z-index:1;width:2px;position:absolute;top:0;bottom:0;right:0}.cell.flip-animating{transition:transform var(--tbw-animation-duration,.2s) ease-out;will-change:transform;z-index:1}@keyframes reorder-fade-in{0%{opacity:0}to{opacity:1}}.cell.fade-animating{animation:reorder-fade-in var(--tbw-animation-duration,.2s) ease-out backwards}}';static manifest={queries:[{type:p,description:"Authoritative check for whether a column may be reordered (honors lockPosition)."}]};handleQuery(e){if(e.type===p){const t=e.context;return t?h(t):void 0}}get defaultConfig(){return{animation:"flip"}}get animationType(){return!!this.isAnimationEnabled&&(void 0!==this.config.animation?this.config.animation:"flip")}get animationDuration(){return void 0!==this.config.animationDuration?this.config.animationDuration:super.animationDuration}isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;draggedGroupFields=[];originalColumnOrder=null;get#r(){return this.grid}canMoveColumnWithPlugins(e){return!(!e||!h(e))&&!this.grid.query(p,e).includes(!1)}clearDragClasses(){this.gridElement?.querySelectorAll(".header-row > .cell, .header-group-row > .cell").forEach(e=>{e.classList.remove(t,"drop-target","drop-before","drop-after")})}attach(e){super.attach(e),this.gridElement.addEventListener("column-reorder-request",e=>{const t=e.detail;t?.field&&"number"==typeof t.toIndex&&this.moveColumn(t.field,t.toIndex)},{signal:this.disconnectSignal})}detach(){this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.draggedGroupFields=[]}afterRender(){const e=this.gridElement;e&&(this.originalColumnOrder||(this.originalColumnOrder=this.columns.map(e=>e.field)),e.querySelectorAll(".header-row > .cell").forEach(e=>{const r=e,i=r.getAttribute("data-field");if(!i)return;const n=this.columns.find(e=>e.field===i);this.canMoveColumnWithPlugins(n)?(r.draggable=!0,r.getAttribute("data-dragstart-bound")||(r.setAttribute("data-dragstart-bound","true"),r.addEventListener("dragstart",e=>{const n=this.getColumnOrder().indexOf(i);this.isDragging=!0,this.draggedField=i,this.draggedIndex=n,this.draggedGroupFields=[],e.dataTransfer&&(e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",i)),r.classList.add(t)}),r.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.draggedGroupFields=[],this.clearDragClasses()}),r.addEventListener("dragover",e=>{if(e.preventDefault(),!this.isDragging)return;if(this.draggedField===i&&0===this.draggedGroupFields.length)return;if(this.draggedGroupFields.includes(i))return;const n=r.getBoundingClientRect(),o=n.left+n.width/2,s=this.getColumnOrder().indexOf(i);if(this.dropIndex=e.clientX<o?s:s+1,this.clearDragClasses(),this.draggedGroupFields.length>0)for(const r of this.draggedGroupFields)this.gridElement?.querySelector(`.header-row > .cell[data-field="${r}"]`)?.classList.add(t);else this.draggedField&&this.gridElement?.querySelector(`.header-row > .cell[data-field="${this.draggedField}"]`)?.classList.add(t);r.classList.add("drop-target"),r.classList.toggle("drop-before",e.clientX<o),r.classList.toggle("drop-after",e.clientX>=o)}),r.addEventListener("dragleave",()=>{r.classList.remove("drop-target","drop-before","drop-after")}),r.addEventListener("drop",e=>{if(e.preventDefault(),!this.isDragging)return;if(this.draggedGroupFields.length>0){if(this.draggedGroupFields.includes(i))return;const t=r.getBoundingClientRect(),n=e.clientX<t.left+t.width/2;return void this.executeGroupBlockMove(this.draggedGroupFields,[i],n)}const t=this.draggedField,n=this.draggedIndex,o=this.dropIndex;if(!this.isDragging||null===t||null===n||null===o)return;const s=o>n?o-1:o,a=m(this.getColumnOrder(),n,s),l={field:t,fromIndex:n,toIndex:s,columnOrder:a};this.emitCancelable("column-move",l)||this.updateColumnOrder(a)}))):r.draggable=!1}),queueMicrotask(()=>this.setupGroupHeaderDrag(e)))}setupGroupHeaderDrag(e){e.querySelectorAll(".header-group-row > .cell[data-group]").forEach(r=>{const i=r,n=i.getAttribute("data-group");if(!n||n.startsWith("__implicit__"))return;if(i.getAttribute("data-group-drag-bound"))return;i.setAttribute("data-group-drag-bound","true");const o=this.getGroupFragmentFields(i,n);0!==o.length&&o.every(e=>{const t=this.columns.find(t=>t.field===e);return this.canMoveColumnWithPlugins(t)})&&(i.draggable=!0,i.style.cursor="grab",i.addEventListener("dragstart",r=>{this.isDragging=!0,this.draggedField=null,this.draggedIndex=null,this.draggedGroupFields=[...o],r.dataTransfer&&(r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",`group:${n}`)),i.classList.add(t);for(const i of o)e.querySelector(`.header-row > .cell[data-field="${i}"]`)?.classList.add(t)}),i.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.draggedGroupFields=[],this.clearDragClasses()}),i.addEventListener("dragover",e=>{if(e.preventDefault(),!this.isDragging)return;if(this.draggedGroupFields.length>0&&this.draggedGroupFields.length===o.length&&this.draggedGroupFields.every(e=>o.includes(e)))return;const t=i.getBoundingClientRect(),r=t.left+t.width/2,n=e.clientX<r;this.clearDragClasses(),i.classList.add("drop-target"),i.classList.toggle("drop-before",n),i.classList.toggle("drop-after",!n)}),i.addEventListener("dragleave",()=>{i.classList.remove("drop-target","drop-before","drop-after")}),i.addEventListener("drop",e=>{if(e.preventDefault(),!this.isDragging)return;const t=i.getBoundingClientRect(),r=e.clientX<t.left+t.width/2;if(this.draggedGroupFields.length>0){if(this.draggedGroupFields.length===o.length&&this.draggedGroupFields.every(e=>o.includes(e)))return;this.executeGroupBlockMove(this.draggedGroupFields,o,r)}else if(this.draggedField){const e=this.getColumnOrder(),t=r?o[0]:o[o.length-1],i=e.indexOf(this.draggedField),n=r?e.indexOf(t):e.indexOf(t)+1;if(-1===i||-1===n)return;const s=n>i?n-1:n,a=m(e,i,s);this.emitCancelable("column-move",{field:this.draggedField,fromIndex:i,toIndex:s,columnOrder:a})||this.updateColumnOrder(a)}}))})}getGroupFragmentFields(e,t){const r=e.style.gridColumn,i=/(\d+)\s*\/\s*span\s+(\d+)/.exec(r);if(!i)return[];const n=parseInt(i[1],10),o=parseInt(i[2],10),s=this.visibleColumns,a=[];for(let l=n-1;l<n-1+o&&l<s.length;l++){const e=s[l];e&&a.push(e.field)}return a}executeGroupBlockMove(e,t,r){const i=this.getColumnOrder(),n=i.filter(t=>!e.includes(t)),o=r?t[0]:t[t.length-1],s=n.indexOf(o);if(-1===s)return;const a=r?s:s+1,l=i.filter(t=>e.includes(t));n.splice(a,0,...l),this.emitCancelable("column-move",{field:e[0],fromIndex:i.indexOf(e[0]),toIndex:a,columnOrder:n})||this.updateColumnOrder(n)}onKeyDown(e){if(!e.altKey||"ArrowLeft"!==e.key&&"ArrowRight"!==e.key)return;const t=this.#r,r=t._focusCol,n=t._visibleColumns;if(r<0||r>=n.length)return;const o=n[r];if(!this.canMoveColumnWithPlugins(o))return;const s=this.getColumnOrder(),a=s.indexOf(o.field);if(-1===a)return;const l="ArrowLeft"===e.key?a-1:a+1;if(l<0||l>=s.length)return;const d=n.find(e=>e.field===s[l]);return this.canMoveColumnWithPlugins(d)?(this.moveColumn(o.field,l),t._focusCol=l,i(this.#r),e.preventDefault(),e.stopPropagation(),!0):void 0}getColumnOrder(){return this.grid.getColumnOrder()}moveColumn(e,t){const r=this.getColumnOrder(),i=r.indexOf(e);if(-1===i)return;const n=m(r,i,t);this.emitCancelable("column-move",{field:e,fromIndex:i,toIndex:t,columnOrder:n})||this.updateColumnOrder(n)}setColumnOrder(e){this.updateColumnOrder(e)}resetColumnOrder(){const e=this.originalColumnOrder??this.columns.map(e=>e.field);this.updateColumnOrder(e)}captureHeaderPositions(){const e=/* @__PURE__ */new Map;return this.gridElement?.querySelectorAll(".header-row > .cell[data-field]").forEach(t=>{const r=t.getAttribute("data-field");r&&e.set(r,t.getBoundingClientRect().left)}),e}animateFLIP(e){const t=this.gridElement;if(!t||0===e.size)return;const r=/* @__PURE__ */new Map;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(t=>{const i=t.getAttribute("data-field");if(!i)return;const n=e.get(i);if(void 0===n)return;const o=n-t.getBoundingClientRect().left;Math.abs(o)>1&&r.set(i,o)}),0===r.size)return;const i=[];if(t.querySelectorAll(".cell[data-field]").forEach(e=>{const t=r.get(e.getAttribute("data-field")??"");if(void 0!==t){const r=e;r.style.transform=`translateX(${t}px)`,i.push(r)}}),0===i.length)return;t.offsetHeight;const n=this.animationDuration;requestAnimationFrame(()=>{i.forEach(e=>{e.classList.add("flip-animating"),e.style.transform=""}),setTimeout(()=>{i.forEach(e=>{e.style.transform="",e.classList.remove("flip-animating")})},n+50)})}animateFade(e){const t=this.gridElement;if(!t)return void e();const r=this.captureHeaderPositions();e();const i=/* @__PURE__ */new Set;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(e=>{const t=e.getAttribute("data-field");if(!t)return;const n=r.get(t);if(void 0===n)return;const o=e.getBoundingClientRect().left;Math.abs(n-o)>1&&i.add(t)}),0===i.size)return;const n=[];if(t.querySelectorAll(".cell[data-field]").forEach(e=>{const t=e.getAttribute("data-field");if(t&&i.has(t)){const t=e;t.classList.add("fade-animating"),n.push(t)}}),0===n.length)return;const o=this.animationDuration;setTimeout(()=>{n.forEach(e=>e.classList.remove("fade-animating"))},o+50)}updateColumnOrder(e){const t=this.animationType;if("flip"===t&&this.gridElement){const t=this.captureHeaderPositions();this.grid.setColumnOrder(e),"function"==typeof this.grid.forceLayout?this.grid.forceLayout().then(()=>{this.animateFLIP(t)}):requestAnimationFrame(()=>{this.animateFLIP(t)})}else"fade"===t?this.animateFade(()=>this.grid.setColumnOrder(e)):this.grid.setColumnOrder(e);this.grid.requestStateChange?.()}};export{v as ReorderPlugin};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- function e(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function t(t,i,r,n){return`${e(r,n)} ${t}: ${i}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(t)}`}var i="editing";function r(e,t){if(!t.capped)return e;const i=t.spacerHeight-t.viewportHeight,r=t.rawContentHeight-t.viewportHeight;return i<=0||r<=0?e:e*i/r}function n(e,t){!function(e){if(!e._virtualization?.enabled)return;const{rowHeight:t,container:i,viewportEl:n,scrollMapping:o}=e._virtualization,s=i,a=n?.clientHeight??s?.clientHeight??0;if(!s||a<=0)return;const d=e._focusRow*t,l=o?function(e,t){if(!t.capped)return e;const i=t.spacerHeight-t.viewportHeight,r=t.rawContentHeight-t.viewportHeight;if(i<=0||r<=0)return e;const n=e*r/i;return n<0?0:n>r?r:n}(s.scrollTop,o):s.scrollTop;if(d<l)s.scrollTop=o?r(d,o):d;else if(d+t>l+a){const e=d-a+t;s.scrollTop=o?r(e,o):e}}(e);const n=function(e){return void 0!==e._activeEditRows&&-1!==e._activeEditRows}(e)||!!e._isGridEditMode;var o;n||e.refreshVirtualWindow(!1),(o=e._bodyEl)&&o.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus")),Array.from(e._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(e=>{e.setAttribute("aria-selected","false")});const s=function(e){const t=e._focusRow,i=e._virtualization.start??0,r=e._virtualization.end??e._rows.length;if(t<i||t>=r)return;const n=e._bodyEl.querySelectorAll(".data-grid-row")[t-i];let o=n?.children[e._focusCol];return o&&o.classList?.contains("cell")||(o=n?.querySelector(`.cell[data-col="${e._focusCol}"]`)??n?.querySelector(".cell[data-col]")),o?{rowEl:n??null,cell:o}:void 0}(e);if(!s)return;const{rowEl:a,cell:d}=s;d.classList.add("cell-focus"),d.setAttribute("aria-selected","true"),n&&!t?.forceHorizontalScroll||function(e,t,i,r){const n=e.querySelector(".tbw-scroll-area");if(!n)return;if(r?.forceScrollLeft)return void(n.scrollLeft=0);if(r?.forceScrollRight)return void(n.scrollLeft=n.scrollWidth-n.clientWidth);const o=e._getHorizontalScrollOffsets?.(t??void 0,i)??{left:0,right:0};if(o.skipScroll)return;const s=i.getBoundingClientRect(),a=n.getBoundingClientRect(),d=s.left-a.left+n.scrollLeft,l=d+s.width,c=n.scrollLeft+o.left,u=n.scrollLeft+n.clientWidth-o.right;d<c?n.scrollLeft=d-o.left:l>u&&(n.scrollLeft=l-n.clientWidth+o.right)}(e,a,d,t),function(e,t,r){if(r&&t.classList.contains(i)){const e=t.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(e&&document.activeElement!==e)try{e.focus({preventScroll:!0})}catch{}return}if(r){if(t.contains(document.activeElement))return;t.hasAttribute("tabindex")||t.setAttribute("tabindex","-1");try{t.focus({preventScroll:!0})}catch{}return}const n=document.activeElement;n instanceof HTMLElement&&n!==e&&"function"==typeof e.contains&&e.contains(n)&&!n.classList.contains("cell")&&!n.closest(".cell")||n===e||e.focus({preventScroll:!0})}(e,d,n)}var o=/{{\s*([^}]+)\s*}}/g,s="__DG_EMPTY__",a=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,d="__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("")),l=new RegExp(`__(proto|defineGetter|defineSetter)|${d.slice(3).join("|")}|this\\b`);var c=new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing|math".split("|")),u=/^on\w+$/i,h=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),g=/^\s*(javascript|vbscript|data|blob):/i;function p(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],i=e.querySelectorAll("*");for(const r of i){const e=r.tagName.toLowerCase();if(c.has(e)){t.push(r);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===r.namespaceURI)&&Array.from(r.attributes).some(e=>u.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(r);continue}const i=[];for(const t of r.attributes){const e=t.name.toLowerCase();u.test(e)?i.push(t.name):"is"!==e?(h.has(e)&&g.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&i.push(t.name):i.push(t.name)}i.forEach(e=>r.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}function f(e,t){t&&"string"==typeof t?-1!==t.indexOf("<")||-1!==t.indexOf("&")?e.replaceChildren(p(t)):e.textContent=t:e.replaceChildren()}function v(e,t){const i=function(e){const t=[];let i=0;for(;i<e.length;){const r=e[i];if(" "!==r){if(r>="0"&&r<="9"||"."===r&&i+1<e.length&&e[i+1]>="0"&&e[i+1]<="9"){const r=i;for(;i<e.length&&(e[i]>="0"&&e[i]<="9"||"."===e[i]);)i++;t.push({type:"num",v:Number(e.slice(r,i))});continue}if("'"===r){let r="";for(i++;i<e.length&&"'"!==e[i];)r+=e[i++];if(i>=e.length)return null;i++,t.push({type:"str",v:r});continue}if(r>="a"&&r<="z"||r>="A"&&r<="Z"||"_"===r||"$"===r){const r=i;for(;i<e.length&&/[\w$.]/.test(e[i]);)i++;t.push({type:"id",v:e.slice(r,i)});continue}if(i+2<e.length){const r=e.slice(i,i+3);if("==="===r||"!=="===r){t.push({type:"op",v:r}),i+=3;continue}}if(i+1<e.length){const r=e.slice(i,i+2);if("=="===r||"!="===r||"<="===r||">="===r||"&&"===r||"||"===r){t.push({type:"op",v:r}),i+=2;continue}}if(!"+-*/%<>!?:(),".includes(r))return null;t.push({type:"op",v:r}),i++}else i++}return t}(e);if(!i)return;const r=i;let n=0;function o(){return r[n]}function s(){return r[n++]}function a(e,t){const i=o();return!!i&&(i.type===e&&(void 0===t||i.v===t))}function d(){const e=function(){let e=l();for(;a("op","||");)s(),e=e||l();return e}();if(a("op","?")){s();const t=d();if(!a("op",":"))return;s();const i=d();return e?t:i}return e}function l(){let e=c();for(;a("op","&&");)s(),e=e&&c();return e}function c(){let e=u();for(;;){const t=o();if(!t||"op"!==t.type)break;if("==="===t.v)s(),e=e===u();else if("!=="===t.v)s(),e=e!==u();else if("=="===t.v)s(),e=e==u();else{if("!="!==t.v)break;s(),e=e!=u()}}return e}function u(){let e=h();for(;;){const t=o();if(!t||"op"!==t.type)break;if("<"===t.v)s(),e=e<h();else if(">"===t.v)s(),e=e>h();else if("<="===t.v)s(),e=e<=h();else{if(">="!==t.v)break;s(),e=e>=h()}}return e}function h(){let e=g();for(;;){const t=o();if(!t||"op"!==t.type)break;if("+"===t.v)s(),e+=g();else{if("-"!==t.v)break;s(),e-=g()}}return e}function g(){let e=p();for(;;){const t=o();if(!t||"op"!==t.type)break;if("*"===t.v)s(),e*=p();else if("/"===t.v)s(),e/=p();else{if("%"!==t.v)break;s(),e%=p()}}return e}function p(){return a("op","!")?(s(),!p()):f()}function f(){const e=o();if(e){if("num"===e.type)return s(),e.v;if("str"===e.type)return s(),e.v;if("id"===e.type)return s(),function(e){if("value"===e)return t.value;if(e.startsWith("row.")){const i=e.slice(4);return t.row?t.row[i]:void 0}if(e.startsWith("typeDefault.")){const i=e.slice(12);return t.typeDefault?t.typeDefault[i]:void 0}return"row"===e?t.row:"typeDefault"===e?t.typeDefault:void 0}(e.v);if("op"===e.type&&"("===e.v){s();const e=d();return a("op",")")&&s(),e}return"op"===e.type&&"-"===e.v?(s(),-f()):void 0}}const v=d();return n<r.length?void 0:v}function w(e,t){if(!e||-1===e.indexOf("{{"))return e;const i=[],r=(n=e.replace(o,(e,r)=>{const n=function(e,t){if(!(e=(e||"").trim()))return s;if(m.test(e))return s;if("value"===e)return null==t.value?s:String(t.value);if(e.startsWith("row.")&&!/[()?]/.test(e)&&!e.includes(":")){const i=e.slice(4),r=t.row?t.row[i]:void 0;return null==r?s:String(r)}if(e.startsWith("typeDefault.")&&!/[()?]/.test(e)&&!e.includes(":")){const i=e.slice(12),r=t.typeDefault?t.typeDefault[i]:void 0;return null==r?s:String(r)}if(e.length>80)return s;if(!a.test(e)||l.test(e))return s;const i=e.match(/\./g);if(i&&i.length>1)return s;try{const i=v(e,t),r=null==i?"":String(i);return m.test(r)?s:r||s}catch{return s}}(r,t);return i.push({expr:r.trim(),result:n}),n===s?n:(o=n)&&"string"==typeof o?o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"):"";var o}),n?n.replace(new RegExp(s,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):n);var n;const d=i.length&&i.every(e=>""===e.result||e.result===s);return m.test(e)||d?"":r}var m=/Reflect|Proxy|ownKeys/;var b={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var R=class{static dependencies;static manifest;aliases;version="3.5.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 i={...this.userConfig},r={};for(const t of Object.keys(i))r[t]=this;for(const n of e){const e=n.userConfig;for(const[o,s]of Object.entries(e)){if(void 0===s)continue;if(!(o in i)){i[o]=s,r[o]=n;continue}if(i[o]===s)continue;const e=r[o]?.constructor.name??this.constructor.name,a=n.constructor.name,d=t("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${e} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(d)}}Object.assign(this.userConfig,i)}refreshUserConfigFrom(e){const t=this.userConfig,i={...e.userConfig};for(const r of Object.keys(t))delete t[r];Object.assign(t,i)}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const i=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}queryBoolean(e,t=null){const i=this.grid?.query?.(e,t);return Array.isArray(i)?i.some(Boolean):!!i}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{...b,...e}}t(e,t){return this.grid?.effectiveConfig?.locale?.[e]??t}get translate(){return(e,t)=>this.t(e,t)}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(t,10);if(!isNaN(i))return i}return 200}setIcon(e,t,i){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const r=this.#t(t,i);void 0!==r?"string"==typeof r?f(e,r):r instanceof HTMLElement&&e.replaceChildren(r.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 i=document.createElement("span");i.setAttribute("part","sort-indicator"),i.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(i,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(i,"sortNone"));const r=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return r?e.insertBefore(i,r):e.appendChild(i),i}warn(i,r){void 0!==r?console.warn(t(i,r,this.gridElement.id,this.name)):console.warn(`${e(this.gridElement.id,this.name)} ${i}`)}throwDiagnostic(e,i){throw new Error(t(e,i,this.gridElement.id,this.name))}},y=class extends R{name="responsive";version="1.0.0";styles='tbw-grid[data-responsive-animate] .data-grid-row,tbw-grid[data-responsive-animate] .data-grid-row>.cell{transition:opacity var(--tbw-responsive-duration,.2s) ease-out, transform var(--tbw-responsive-duration,.2s) ease-out}tbw-grid[data-responsive][data-responsive-animate] .data-grid-row{animation:responsive-card-enter var(--tbw-responsive-duration,.2s) ease-out}@keyframes responsive-card-enter{0%{opacity:0;transform:translateY(-10px)}to{opacity:1;transform:translateY(0)}}tbw-grid[data-responsive] .header{display:none!important}tbw-grid[data-responsive] .footer-row{display:none}tbw-grid[data-responsive] .tbw-scroll-area{overflow-x:hidden;min-width:0!important}tbw-grid[data-responsive] .rows-body-wrapper{min-width:0!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row){padding:var(--tbw-cell-padding);border-bottom:1px solid var(--tbw-color-border);background:var(--tbw-color-bg);padding-inline-start:var(--tbw-spacing-xl);position:relative;contain:none!important;content-visibility:visible!important;grid-template-columns:none!important;height:auto!important;min-height:auto!important;display:block!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row):nth-child(2n){background:var(--tbw-color-row-alt)}tbw-grid[data-responsive] .data-grid-row:not(.group-row):hover{background:var(--tbw-color-row-hover)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)[aria-selected=true]{background:var(--tbw-color-selection)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)[aria-selected=true]:before{content:"";background:var(--tbw-color-accent);inset-inline-start:0;width:4px;position:absolute;top:0;bottom:0}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell{padding:var(--tbw-spacing-xs) var(--tbw-spacing-md);justify-content:space-between;align-items:center;white-space:normal!important;border:none!important;background:0 0!important;border-inline-end:none!important;width:100%!important;min-width:0!important;height:auto!important;min-height:auto!important;line-height:1.5!important;display:flex!important;position:static!important;left:auto!important;right:auto!important;overflow:visible!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell:before{content:attr(data-header) ": ";color:var(--tbw-color-header-fg);min-width:100px;flex-shrink:0;margin-inline-end:var(--tbw-spacing-md);font-weight:600}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell:after{content:none}tbw-grid[data-responsive] .cell[data-utility],tbw-grid[data-responsive] .data-grid-row>.cell[data-responsive-hidden],tbw-grid[data-responsive] .data-grid-row>.cell[data-responsive-value-only]:before{display:none!important}tbw-grid[data-responsive] .data-grid-row>.cell[data-responsive-value-only]{font-weight:500;justify-content:flex-start!important}tbw-grid[data-responsive][data-responsive-hide-header] .data-grid-row:not(.group-row)>.cell:before,tbw-grid:not([data-responsive]) .cell[data-responsive-hidden],tbw-grid[data-responsive] .tbw-footer,tbw-grid[data-responsive] .tbw-header-pinned,tbw-grid[data-responsive] .tbw-pinned-rows,tbw-grid[data-responsive] .tbw-aggregation-rows{display:none!important}tbw-grid[data-responsive] .tbw-pinned-rows,tbw-grid[data-responsive] .tbw-aggregation-rows,tbw-grid[data-responsive] .tbw-aggregation-row{min-width:0!important}tbw-grid[data-responsive] .data-grid-row.responsive-card{padding:var(--tbw-cell-padding);border-bottom:1px solid var(--tbw-color-border);display:block!important}tbw-grid[data-responsive] .data-grid-row.responsive-card>*{width:100%}tbw-grid[data-responsive] .data-grid-row.responsive-card .cell:before{display:none}';static manifest={queries:[{type:"isCardMode",description:"Returns whether the grid is currently in responsive card mode"}]};#i;#r=!1;#n;#o=!1;#s=0;#a=/* @__PURE__ */new Set;#d=/* @__PURE__ */new Set;#l=null;#c=[];get#u(){return this.grid}isResponsive(){return this.#r}setResponsive(e){e!==this.#r&&(this.#r=e,this.#h(),this.emit("responsive-change",{isResponsive:e,width:this.#s,breakpoint:this.config.breakpoint??0}),this.requestRender())}setBreakpoint(e){this.config.breakpoint=e,this.#g(this.#s)}setCardRenderer(e){this.config.cardRenderer=e,this.#r&&this.requestRender()}getWidth(){return this.#s}getActiveBreakpoint(){return this.#l}attach(e){super.attach(e),this.#p(),this.#f(this.config.hiddenColumns),this.config.breakpoints?.length&&(this.#c=[...this.config.breakpoints].sort((e,t)=>t.maxWidth-e.maxWidth)),this.#i=new ResizeObserver(e=>{const t=e[0]?.contentRect.width??0;this.#s=t,clearTimeout(this.#n),this.#n=setTimeout(()=>{this.#g(t)},this.config.debounceMs??100)}),this.#i.observe(this.gridElement)}#p(){const e=this.gridElement;if(!e)return;const t=e.querySelector("tbw-grid-responsive-card");if(!t)return;const i=this.#u.__frameworkAdapter;if(i?.parseResponsiveCardElement){const e=i.parseResponsiveCardElement(t);e&&(this.config={...this.config,cardRenderer:e})}const r=t.getAttribute("breakpoint"),n=t.getAttribute("card-row-height"),o=t.getAttribute("hidden-columns"),s=t.getAttribute("hide-header"),a=t.getAttribute("debounce-ms"),d={};if(null!==r){const e=parseInt(r,10);isNaN(e)||(d.breakpoint=e)}if(null!==n&&(d.cardRowHeight="auto"===n?"auto":parseInt(n,10)),null!==o&&(d.hiddenColumns=o.split(",").map(e=>e.trim()).filter(e=>e.length>0)),null!==s&&(d.hideHeader="false"!==s),null!==a){const e=parseInt(a,10);isNaN(e)||(d.debounceMs=e)}const l=t.innerHTML.trim();!l||this.config.cardRenderer||i?.parseResponsiveCardElement||(d.cardRenderer=e=>{const t=w(l,{value:e,row:e}),i=document.createElement("div");return i.className="tbw-responsive-card-content",f(i,t),i}),Object.keys(d).length>0&&(this.config={...this.config,...d})}#f(e){if(this.#a.clear(),this.#d.clear(),e)for(const t of e)"string"==typeof t?this.#a.add(t):t.showValue?this.#d.add(t.field):this.#a.add(t.field)}detach(){this.#i?.disconnect(),this.#i=void 0,clearTimeout(this.#n),this.#n=void 0,this.gridElement&&this.gridElement.removeAttribute("data-responsive"),super.detach()}handleQuery(e){if("isCardMode"===e.type)return this.#r}afterRender(){if(this.#v(),!(this.#c.length>0?null!==this.#l:this.#r))return;const e=this.#a.size>0,t=this.#d.size>0;if(!e&&!t)return;const i=this.gridElement.querySelectorAll(".cell[data-field]");for(const r of i){const e=r.getAttribute("data-field");e&&(this.#a.has(e)?(r.setAttribute("data-responsive-hidden",""),r.removeAttribute("data-responsive-value-only")):this.#d.has(e)?(r.setAttribute("data-responsive-value-only",""),r.removeAttribute("data-responsive-hidden")):(r.removeAttribute("data-responsive-hidden"),r.removeAttribute("data-responsive-value-only")))}}#g(e){if(this.#c.length>0)return void this.#w(e);const t=this.config.breakpoint??0;0!==t||this.#o||(this.#o=!0,this.warn("TBW110","No breakpoint configured. Responsive mode is disabled. Set a breakpoint based on your grid's column count."));const i=t>0&&e<t;i!==this.#r&&(this.#r=i,this.#h(),this.emit("responsive-change",{isResponsive:i,width:e,breakpoint:t}),this.requestRender())}#w(e){let t=null;for(const i of this.#c)e<=i.maxWidth&&(t=i);if(t!==this.#l){this.#l=t,t?.hiddenColumns?this.#f(t.hiddenColumns):this.#f(this.config.hiddenColumns);const i=!0===t?.cardLayout;i!==this.#r&&(this.#r=i,this.#h()),this.emit("responsive-change",{isResponsive:this.#r,width:e,breakpoint:t?.maxWidth??0}),this.requestRender()}}#m;#h(){this.gridElement.toggleAttribute("data-responsive",this.#r);const e=!1!==this.config.animate;this.gridElement.toggleAttribute("data-responsive-animate",e),this.gridElement.toggleAttribute("data-responsive-hide-header",this.#r&&!0===this.config.hideHeader),this.config.animationDuration&&this.gridElement.style.setProperty("--tbw-responsive-duration",`${this.config.animationDuration}ms`);const t=this.#u;if(this.#r){t._virtualization&&(this.#m=t._virtualization.rowHeight);const e=this.gridElement.querySelector(".tbw-scroll-area");e&&(e.scrollLeft=0)}else{const e=this.gridElement.querySelectorAll(".data-grid-row");for(const t of e)t.style.height="",t.classList.remove("responsive-card");this.#m&&this.#m>0&&t._virtualization&&(t._virtualization.rowHeight=this.#m,this.#m=void 0),this.#b=void 0,this.#R=void 0,this.#y=void 0}}renderRow(e,t,i){if(!this.#r||!this.config.cardRenderer)return;if(e.__isGroupRow)return;t.replaceChildren();const r=this.config.cardRenderer(e,i);t.className="data-grid-row responsive-card";const n=this.config.cardRowHeight;return t.style.height="auto"===n||void 0===n?"auto":`${this.#C()}px`,t.appendChild(r),!0}onKeyDown(e){if(!this.#r)return!1;if(this.config.cardRenderer&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e.key))return!1;const t=this.rows.length-1,i=this.visibleColumns.length-1;switch(e.key){case"ArrowDown":if(this.grid._focusCol<i)return this.grid._focusCol+=1,e.preventDefault(),n(this.#u),!0;if(this.grid._focusRow<t)return this.grid._focusRow+=1,this.grid._focusCol=0,e.preventDefault(),n(this.#u),!0;break;case"ArrowUp":if(this.grid._focusCol>0)return this.grid._focusCol-=1,e.preventDefault(),n(this.#u),!0;if(this.grid._focusRow>0)return this.grid._focusRow-=1,this.grid._focusCol=i,e.preventDefault(),n(this.#u),!0;break;case"ArrowRight":if(this.grid._focusRow<t)return this.grid._focusRow+=1,e.preventDefault(),n(this.#u),!0;break;case"ArrowLeft":if(this.grid._focusRow>0)return this.grid._focusRow-=1,e.preventDefault(),n(this.#u),!0}return!1}#b;#R;#y;#C(){if(this.#b&&this.#b>0)return this.#b;const e=this.config.cardRowHeight;return"number"==typeof e&&e>0?e:80}#k(){return this.#R&&this.#R>0?this.#R:this.#m??28}#_(){for(const e of this.rows)if(e.__isGroupRow)return!0;return!1}getRowHeight(e,t){if(this.#r&&this.config.cardRenderer)return e.__isGroupRow?this.#k():this.#C()}#S(){let e=0;for(const t of this.rows)t.__isGroupRow||e++;return e}#H=!1;#v(){if(!this.#r)return;let e=!1;const t=this.#u,i=this.#_(),r=this.#S();if(r!==this.#y&&(this.#y=r,e=!0),i){const t=this.gridElement.querySelector(".data-grid-row.group-row");if(t){const i=t.getBoundingClientRect().height;i>0&&i!==this.#R&&(this.#R=i,e=!0)}}const n=this.config.cardRenderer?".data-grid-row.responsive-card":".data-grid-row:not(.group-row)",o=this.gridElement.querySelector(n);if(o){const r=o.getBoundingClientRect().height;r>0&&r!==this.#b&&(this.#b=r,e=!0,!i&&t._virtualization&&(t._virtualization.rowHeight=r))}e&&!this.#H&&(this.#H=!0,queueMicrotask(()=>{this.#H=!1,this.grid&&this.#r&&this.#u.refreshVirtualWindow?.(!0,!0)}))}};export{y as ResponsivePlugin};
1
+ function e(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function t(t,i,r,n){return`${e(r,n)} ${t}: ${i}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(t)}`}var i="editing";function r(e,t){if(!t.capped)return e;const i=t.spacerHeight-t.viewportHeight,r=t.rawContentHeight-t.viewportHeight;return i<=0||r<=0?e:e*i/r}function n(e,t){!function(e){if(!e._virtualization?.enabled)return;const{rowHeight:t,container:i,viewportEl:n,scrollMapping:o}=e._virtualization,s=i,a=n?.clientHeight??s?.clientHeight??0;if(!s||a<=0)return;const d=e._focusRow*t,l=o?function(e,t){if(!t.capped)return e;const i=t.spacerHeight-t.viewportHeight,r=t.rawContentHeight-t.viewportHeight;if(i<=0||r<=0)return e;const n=e*r/i;return n<0?0:n>r?r:n}(s.scrollTop,o):s.scrollTop;if(d<l)s.scrollTop=o?r(d,o):d;else if(d+t>l+a){const e=d-a+t;s.scrollTop=o?r(e,o):e}}(e);const n=function(e){return void 0!==e._activeEditRows&&-1!==e._activeEditRows}(e)||!!e._isGridEditMode;var o;n||e.refreshVirtualWindow(!1),(o=e._bodyEl)&&o.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus")),Array.from(e._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(e=>{e.setAttribute("aria-selected","false")});const s=function(e){const t=e._focusRow,i=e._virtualization.start??0,r=e._virtualization.end??e._rows.length;if(t<i||t>=r)return;const n=e._bodyEl.querySelectorAll(".data-grid-row")[t-i];let o=n?.children[e._focusCol];return o&&o.classList?.contains("cell")||(o=n?.querySelector(`.cell[data-col="${e._focusCol}"]`)??n?.querySelector(".cell[data-col]")),o?{rowEl:n??null,cell:o}:void 0}(e);if(!s)return;const{rowEl:a,cell:d}=s;d.classList.add("cell-focus"),d.setAttribute("aria-selected","true"),n&&!t?.forceHorizontalScroll||function(e,t,i,r){const n=e.querySelector(".tbw-scroll-area");if(!n)return;if(r?.forceScrollLeft)return void(n.scrollLeft=0);if(r?.forceScrollRight)return void(n.scrollLeft=n.scrollWidth-n.clientWidth);const o=e._getHorizontalScrollOffsets?.(t??void 0,i)??{left:0,right:0};if(o.skipScroll)return;const s=i.getBoundingClientRect(),a=n.getBoundingClientRect(),d=s.left-a.left+n.scrollLeft,l=d+s.width,c=n.scrollLeft+o.left,u=n.scrollLeft+n.clientWidth-o.right;d<c?n.scrollLeft=d-o.left:l>u&&(n.scrollLeft=l-n.clientWidth+o.right)}(e,a,d,t),function(e,t,r){if(r&&t.classList.contains(i)){const e=t.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(e&&document.activeElement!==e)try{e.focus({preventScroll:!0})}catch{}return}if(r){if(t.contains(document.activeElement))return;t.hasAttribute("tabindex")||t.setAttribute("tabindex","-1");try{t.focus({preventScroll:!0})}catch{}return}const n=document.activeElement;n instanceof HTMLElement&&n!==e&&"function"==typeof e.contains&&e.contains(n)&&!n.classList.contains("cell")&&!n.closest(".cell")||n===e||e.focus({preventScroll:!0})}(e,d,n)}var o=/{{\s*([^}]+)\s*}}/g,s="__DG_EMPTY__",a=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,d="__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("")),l=new RegExp(`__(proto|defineGetter|defineSetter)|${d.slice(3).join("|")}|this\\b`);var c=new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing|math".split("|")),u=/^on\w+$/i,h=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),g=/^\s*(javascript|vbscript|data|blob):/i;function p(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],i=e.querySelectorAll("*");for(const r of i){const e=r.tagName.toLowerCase();if(c.has(e)){t.push(r);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===r.namespaceURI)&&Array.from(r.attributes).some(e=>u.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(r);continue}const i=[];for(const t of r.attributes){const e=t.name.toLowerCase();u.test(e)?i.push(t.name):"is"!==e?(h.has(e)&&g.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&i.push(t.name):i.push(t.name)}i.forEach(e=>r.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}function f(e,t){t&&"string"==typeof t?-1!==t.indexOf("<")||-1!==t.indexOf("&")?e.replaceChildren(p(t)):e.textContent=t:e.replaceChildren()}function v(e,t){const i=function(e){const t=[];let i=0;for(;i<e.length;){const r=e[i];if(" "!==r){if(r>="0"&&r<="9"||"."===r&&i+1<e.length&&e[i+1]>="0"&&e[i+1]<="9"){const r=i;for(;i<e.length&&(e[i]>="0"&&e[i]<="9"||"."===e[i]);)i++;t.push({type:"num",v:Number(e.slice(r,i))});continue}if("'"===r){let r="";for(i++;i<e.length&&"'"!==e[i];)r+=e[i++];if(i>=e.length)return null;i++,t.push({type:"str",v:r});continue}if(r>="a"&&r<="z"||r>="A"&&r<="Z"||"_"===r||"$"===r){const r=i;for(;i<e.length&&/[\w$.]/.test(e[i]);)i++;t.push({type:"id",v:e.slice(r,i)});continue}if(i+2<e.length){const r=e.slice(i,i+3);if("==="===r||"!=="===r){t.push({type:"op",v:r}),i+=3;continue}}if(i+1<e.length){const r=e.slice(i,i+2);if("=="===r||"!="===r||"<="===r||">="===r||"&&"===r||"||"===r){t.push({type:"op",v:r}),i+=2;continue}}if(!"+-*/%<>!?:(),".includes(r))return null;t.push({type:"op",v:r}),i++}else i++}return t}(e);if(!i)return;const r=i;let n=0;function o(){return r[n]}function s(){return r[n++]}function a(e,t){const i=o();return!!i&&(i.type===e&&(void 0===t||i.v===t))}function d(){const e=function(){let e=l();for(;a("op","||");)s(),e=e||l();return e}();if(a("op","?")){s();const t=d();if(!a("op",":"))return;s();const i=d();return e?t:i}return e}function l(){let e=c();for(;a("op","&&");)s(),e=e&&c();return e}function c(){let e=u();for(;;){const t=o();if(!t||"op"!==t.type)break;if("==="===t.v)s(),e=e===u();else if("!=="===t.v)s(),e=e!==u();else if("=="===t.v)s(),e=e==u();else{if("!="!==t.v)break;s(),e=e!=u()}}return e}function u(){let e=h();for(;;){const t=o();if(!t||"op"!==t.type)break;if("<"===t.v)s(),e=e<h();else if(">"===t.v)s(),e=e>h();else if("<="===t.v)s(),e=e<=h();else{if(">="!==t.v)break;s(),e=e>=h()}}return e}function h(){let e=g();for(;;){const t=o();if(!t||"op"!==t.type)break;if("+"===t.v)s(),e+=g();else{if("-"!==t.v)break;s(),e-=g()}}return e}function g(){let e=p();for(;;){const t=o();if(!t||"op"!==t.type)break;if("*"===t.v)s(),e*=p();else if("/"===t.v)s(),e/=p();else{if("%"!==t.v)break;s(),e%=p()}}return e}function p(){return a("op","!")?(s(),!p()):f()}function f(){const e=o();if(e){if("num"===e.type)return s(),e.v;if("str"===e.type)return s(),e.v;if("id"===e.type)return s(),function(e){if("value"===e)return t.value;if(e.startsWith("row.")){const i=e.slice(4);return t.row?t.row[i]:void 0}if(e.startsWith("typeDefault.")){const i=e.slice(12);return t.typeDefault?t.typeDefault[i]:void 0}return"row"===e?t.row:"typeDefault"===e?t.typeDefault:void 0}(e.v);if("op"===e.type&&"("===e.v){s();const e=d();return a("op",")")&&s(),e}return"op"===e.type&&"-"===e.v?(s(),-f()):void 0}}const v=d();return n<r.length?void 0:v}function w(e,t){if(!e||-1===e.indexOf("{{"))return e;const i=[],r=(n=e.replace(o,(e,r)=>{const n=function(e,t){if(!(e=(e||"").trim()))return s;if(m.test(e))return s;if("value"===e)return null==t.value?s:String(t.value);if(e.startsWith("row.")&&!/[()?]/.test(e)&&!e.includes(":")){const i=e.slice(4),r=t.row?t.row[i]:void 0;return null==r?s:String(r)}if(e.startsWith("typeDefault.")&&!/[()?]/.test(e)&&!e.includes(":")){const i=e.slice(12),r=t.typeDefault?t.typeDefault[i]:void 0;return null==r?s:String(r)}if(e.length>80)return s;if(!a.test(e)||l.test(e))return s;const i=e.match(/\./g);if(i&&i.length>1)return s;try{const i=v(e,t),r=null==i?"":String(i);return m.test(r)?s:r||s}catch{return s}}(r,t);return i.push({expr:r.trim(),result:n}),n===s?n:(o=n)&&"string"==typeof o?o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"):"";var o}),n?n.replace(new RegExp(s,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):n);var n;const d=i.length&&i.every(e=>""===e.result||e.result===s);return m.test(e)||d?"":r}var m=/Reflect|Proxy|ownKeys/;var b={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var R=class{static dependencies;static manifest;aliases;version="3.5.1";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const i={...this.userConfig},r={};for(const t of Object.keys(i))r[t]=this;for(const n of e){const e=n.userConfig;for(const[o,s]of Object.entries(e)){if(void 0===s)continue;if(!(o in i)){i[o]=s,r[o]=n;continue}if(i[o]===s)continue;const e=r[o]?.constructor.name??this.constructor.name,a=n.constructor.name,d=t("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${e} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(d)}}Object.assign(this.userConfig,i)}refreshUserConfigFrom(e){const t=this.userConfig,i={...e.userConfig};for(const r of Object.keys(t))delete t[r];Object.assign(t,i)}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const i=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}queryBoolean(e,t=null){const i=this.grid?.query?.(e,t);return Array.isArray(i)?i.some(Boolean):!!i}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{...b,...e}}t(e,t){return this.grid?.effectiveConfig?.locale?.[e]??t}get translate(){return(e,t)=>this.t(e,t)}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(t,10);if(!isNaN(i))return i}return 200}setIcon(e,t,i){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const r=this.#t(t,i);void 0!==r?"string"==typeof r?f(e,r):r instanceof HTMLElement&&e.replaceChildren(r.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 i=document.createElement("span");i.setAttribute("part","sort-indicator"),i.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(i,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(i,"sortNone"));const r=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return r?e.insertBefore(i,r):e.appendChild(i),i}warn(i,r){void 0!==r?console.warn(t(i,r,this.gridElement.id,this.name)):console.warn(`${e(this.gridElement.id,this.name)} ${i}`)}throwDiagnostic(e,i){throw new Error(t(e,i,this.gridElement.id,this.name))}},y=class extends R{name="responsive";version="1.0.0";styles='tbw-grid[data-responsive-animate] .data-grid-row,tbw-grid[data-responsive-animate] .data-grid-row>.cell{transition:opacity var(--tbw-responsive-duration,.2s) ease-out, transform var(--tbw-responsive-duration,.2s) ease-out}tbw-grid[data-responsive][data-responsive-animate] .data-grid-row{animation:responsive-card-enter var(--tbw-responsive-duration,.2s) ease-out}@keyframes responsive-card-enter{0%{opacity:0;transform:translateY(-10px)}to{opacity:1;transform:translateY(0)}}tbw-grid[data-responsive] .header{display:none!important}tbw-grid[data-responsive] .footer-row{display:none}tbw-grid[data-responsive] .tbw-scroll-area{overflow-x:hidden;min-width:0!important}tbw-grid[data-responsive] .rows-body-wrapper{min-width:0!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row){padding:var(--tbw-cell-padding);border-bottom:1px solid var(--tbw-color-border);background:var(--tbw-color-bg);padding-inline-start:var(--tbw-spacing-xl);position:relative;contain:none!important;content-visibility:visible!important;grid-template-columns:none!important;height:auto!important;min-height:auto!important;display:block!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row):nth-child(2n){background:var(--tbw-color-row-alt)}tbw-grid[data-responsive] .data-grid-row:not(.group-row):hover{background:var(--tbw-color-row-hover)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)[aria-selected=true]{background:var(--tbw-color-selection)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)[aria-selected=true]:before{content:"";background:var(--tbw-color-accent);inset-inline-start:0;width:4px;position:absolute;top:0;bottom:0}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell{padding:var(--tbw-spacing-xs) var(--tbw-spacing-md);justify-content:space-between;align-items:center;white-space:normal!important;border:none!important;background:0 0!important;border-inline-end:none!important;width:100%!important;min-width:0!important;height:auto!important;min-height:auto!important;line-height:1.5!important;display:flex!important;position:static!important;left:auto!important;right:auto!important;overflow:visible!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell:before{content:attr(data-header) ": ";color:var(--tbw-color-header-fg);min-width:100px;flex-shrink:0;margin-inline-end:var(--tbw-spacing-md);font-weight:600}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell:after{content:none}tbw-grid[data-responsive] .cell[data-utility],tbw-grid[data-responsive] .data-grid-row>.cell[data-responsive-hidden],tbw-grid[data-responsive] .data-grid-row>.cell[data-responsive-value-only]:before{display:none!important}tbw-grid[data-responsive] .data-grid-row>.cell[data-responsive-value-only]{font-weight:500;justify-content:flex-start!important}tbw-grid[data-responsive][data-responsive-hide-header] .data-grid-row:not(.group-row)>.cell:before,tbw-grid:not([data-responsive]) .cell[data-responsive-hidden],tbw-grid[data-responsive] .tbw-footer,tbw-grid[data-responsive] .tbw-header-pinned,tbw-grid[data-responsive] .tbw-pinned-rows,tbw-grid[data-responsive] .tbw-aggregation-rows{display:none!important}tbw-grid[data-responsive] .tbw-pinned-rows,tbw-grid[data-responsive] .tbw-aggregation-rows,tbw-grid[data-responsive] .tbw-aggregation-row{min-width:0!important}tbw-grid[data-responsive] .data-grid-row.responsive-card{padding:var(--tbw-cell-padding);border-bottom:1px solid var(--tbw-color-border);display:block!important}tbw-grid[data-responsive] .data-grid-row.responsive-card>*{width:100%}tbw-grid[data-responsive] .data-grid-row.responsive-card .cell:before{display:none}';static manifest={queries:[{type:"isCardMode",description:"Returns whether the grid is currently in responsive card mode"}]};#i;#r=!1;#n;#o=!1;#s=0;#a=/* @__PURE__ */new Set;#d=/* @__PURE__ */new Set;#l=null;#c=[];get#u(){return this.grid}isResponsive(){return this.#r}setResponsive(e){e!==this.#r&&(this.#r=e,this.#h(),this.emit("responsive-change",{isResponsive:e,width:this.#s,breakpoint:this.config.breakpoint??0}),this.requestRender())}setBreakpoint(e){this.config.breakpoint=e,this.#g(this.#s)}setCardRenderer(e){this.config.cardRenderer=e,this.#r&&this.requestRender()}getWidth(){return this.#s}getActiveBreakpoint(){return this.#l}attach(e){super.attach(e),this.#p(),this.#f(this.config.hiddenColumns),this.config.breakpoints?.length&&(this.#c=[...this.config.breakpoints].sort((e,t)=>t.maxWidth-e.maxWidth)),this.#i=new ResizeObserver(e=>{const t=e[0]?.contentRect.width??0;this.#s=t,clearTimeout(this.#n),this.#n=setTimeout(()=>{this.#g(t)},this.config.debounceMs??100)}),this.#i.observe(this.gridElement)}#p(){const e=this.gridElement;if(!e)return;const t=e.querySelector("tbw-grid-responsive-card");if(!t)return;const i=this.#u.__frameworkAdapter;if(i?.parseResponsiveCardElement){const e=i.parseResponsiveCardElement(t);e&&(this.config={...this.config,cardRenderer:e})}const r=t.getAttribute("breakpoint"),n=t.getAttribute("card-row-height"),o=t.getAttribute("hidden-columns"),s=t.getAttribute("hide-header"),a=t.getAttribute("debounce-ms"),d={};if(null!==r){const e=parseInt(r,10);isNaN(e)||(d.breakpoint=e)}if(null!==n&&(d.cardRowHeight="auto"===n?"auto":parseInt(n,10)),null!==o&&(d.hiddenColumns=o.split(",").map(e=>e.trim()).filter(e=>e.length>0)),null!==s&&(d.hideHeader="false"!==s),null!==a){const e=parseInt(a,10);isNaN(e)||(d.debounceMs=e)}const l=t.innerHTML.trim();!l||this.config.cardRenderer||i?.parseResponsiveCardElement||(d.cardRenderer=e=>{const t=w(l,{value:e,row:e}),i=document.createElement("div");return i.className="tbw-responsive-card-content",f(i,t),i}),Object.keys(d).length>0&&(this.config={...this.config,...d})}#f(e){if(this.#a.clear(),this.#d.clear(),e)for(const t of e)"string"==typeof t?this.#a.add(t):t.showValue?this.#d.add(t.field):this.#a.add(t.field)}detach(){this.#i?.disconnect(),this.#i=void 0,clearTimeout(this.#n),this.#n=void 0,this.gridElement&&this.gridElement.removeAttribute("data-responsive"),super.detach()}handleQuery(e){if("isCardMode"===e.type)return this.#r}afterRender(){if(this.#v(),!(this.#c.length>0?null!==this.#l:this.#r))return;const e=this.#a.size>0,t=this.#d.size>0;if(!e&&!t)return;const i=this.gridElement.querySelectorAll(".cell[data-field]");for(const r of i){const e=r.getAttribute("data-field");e&&(this.#a.has(e)?(r.setAttribute("data-responsive-hidden",""),r.removeAttribute("data-responsive-value-only")):this.#d.has(e)?(r.setAttribute("data-responsive-value-only",""),r.removeAttribute("data-responsive-hidden")):(r.removeAttribute("data-responsive-hidden"),r.removeAttribute("data-responsive-value-only")))}}#g(e){if(this.#c.length>0)return void this.#w(e);const t=this.config.breakpoint??0;0!==t||this.#o||(this.#o=!0,this.warn("TBW110","No breakpoint configured. Responsive mode is disabled. Set a breakpoint based on your grid's column count."));const i=t>0&&e<t;i!==this.#r&&(this.#r=i,this.#h(),this.emit("responsive-change",{isResponsive:i,width:e,breakpoint:t}),this.requestRender())}#w(e){let t=null;for(const i of this.#c)e<=i.maxWidth&&(t=i);if(t!==this.#l){this.#l=t,t?.hiddenColumns?this.#f(t.hiddenColumns):this.#f(this.config.hiddenColumns);const i=!0===t?.cardLayout;i!==this.#r&&(this.#r=i,this.#h()),this.emit("responsive-change",{isResponsive:this.#r,width:e,breakpoint:t?.maxWidth??0}),this.requestRender()}}#m;#h(){this.gridElement.toggleAttribute("data-responsive",this.#r);const e=!1!==this.config.animate;this.gridElement.toggleAttribute("data-responsive-animate",e),this.gridElement.toggleAttribute("data-responsive-hide-header",this.#r&&!0===this.config.hideHeader),this.config.animationDuration&&this.gridElement.style.setProperty("--tbw-responsive-duration",`${this.config.animationDuration}ms`);const t=this.#u;if(this.#r){t._virtualization&&(this.#m=t._virtualization.rowHeight);const e=this.gridElement.querySelector(".tbw-scroll-area");e&&(e.scrollLeft=0)}else{const e=this.gridElement.querySelectorAll(".data-grid-row");for(const t of e)t.style.height="",t.classList.remove("responsive-card");this.#m&&this.#m>0&&t._virtualization&&(t._virtualization.rowHeight=this.#m,this.#m=void 0),this.#b=void 0,this.#R=void 0,this.#y=void 0}}renderRow(e,t,i){if(!this.#r||!this.config.cardRenderer)return;if(e.__isGroupRow)return;t.replaceChildren();const r=this.config.cardRenderer(e,i);t.className="data-grid-row responsive-card";const n=this.config.cardRowHeight;return t.style.height="auto"===n||void 0===n?"auto":`${this.#C()}px`,t.appendChild(r),!0}onKeyDown(e){if(!this.#r)return!1;if(this.config.cardRenderer&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e.key))return!1;const t=this.rows.length-1,i=this.visibleColumns.length-1;switch(e.key){case"ArrowDown":if(this.grid._focusCol<i)return this.grid._focusCol+=1,e.preventDefault(),n(this.#u),!0;if(this.grid._focusRow<t)return this.grid._focusRow+=1,this.grid._focusCol=0,e.preventDefault(),n(this.#u),!0;break;case"ArrowUp":if(this.grid._focusCol>0)return this.grid._focusCol-=1,e.preventDefault(),n(this.#u),!0;if(this.grid._focusRow>0)return this.grid._focusRow-=1,this.grid._focusCol=i,e.preventDefault(),n(this.#u),!0;break;case"ArrowRight":if(this.grid._focusRow<t)return this.grid._focusRow+=1,e.preventDefault(),n(this.#u),!0;break;case"ArrowLeft":if(this.grid._focusRow>0)return this.grid._focusRow-=1,e.preventDefault(),n(this.#u),!0}return!1}#b;#R;#y;#C(){if(this.#b&&this.#b>0)return this.#b;const e=this.config.cardRowHeight;return"number"==typeof e&&e>0?e:80}#k(){return this.#R&&this.#R>0?this.#R:this.#m??28}#_(){for(const e of this.rows)if(e.__isGroupRow)return!0;return!1}getRowHeight(e,t){if(this.#r&&this.config.cardRenderer)return e.__isGroupRow?this.#k():this.#C()}#S(){let e=0;for(const t of this.rows)t.__isGroupRow||e++;return e}#H=!1;#v(){if(!this.#r)return;let e=!1;const t=this.#u,i=this.#_(),r=this.#S();if(r!==this.#y&&(this.#y=r,e=!0),i){const t=this.gridElement.querySelector(".data-grid-row.group-row");if(t){const i=t.getBoundingClientRect().height;i>0&&i!==this.#R&&(this.#R=i,e=!0)}}const n=this.config.cardRenderer?".data-grid-row.responsive-card":".data-grid-row:not(.group-row)",o=this.gridElement.querySelector(n);if(o){const r=o.getBoundingClientRect().height;r>0&&r!==this.#b&&(this.#b=r,e=!0,!i&&t._virtualization&&(t._virtualization.rowHeight=r))}e&&!this.#H&&(this.#H=!0,queueMicrotask(()=>{this.#H=!1,this.grid&&this.#r&&this.#u.refreshVirtualWindow?.(!0,!0)}))}};export{y as ResponsivePlugin};
2
2
  //# sourceMappingURL=index.js.map