@toolbox-web/grid 3.5.2 → 3.5.3

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/README.md +17 -17
  2. package/all.js +1 -1
  3. package/all.js.map +1 -1
  4. package/index.js +1 -1
  5. package/index.js.map +1 -1
  6. package/lib/features/registry.js +1 -1
  7. package/lib/plugins/clipboard/index.js +1 -1
  8. package/lib/plugins/column-virtualization/index.js +1 -1
  9. package/lib/plugins/context-menu/index.js +1 -1
  10. package/lib/plugins/editing/index.js +1 -1
  11. package/lib/plugins/export/index.js +1 -1
  12. package/lib/plugins/filtering/index.js +1 -1
  13. package/lib/plugins/grouping-columns/index.js +1 -1
  14. package/lib/plugins/grouping-rows/index.js +1 -1
  15. package/lib/plugins/master-detail/index.js +1 -1
  16. package/lib/plugins/multi-sort/index.js +1 -1
  17. package/lib/plugins/pinned-columns/index.js +1 -1
  18. package/lib/plugins/pinned-rows/index.js +1 -1
  19. package/lib/plugins/pivot/index.js +1 -1
  20. package/lib/plugins/print/index.js +1 -1
  21. package/lib/plugins/reorder-columns/index.js +1 -1
  22. package/lib/plugins/responsive/index.js +1 -1
  23. package/lib/plugins/row-drag-drop/index.js +1 -1
  24. package/lib/plugins/selection/index.js +1 -1
  25. package/lib/plugins/server-side/index.js +1 -1
  26. package/lib/plugins/shell/index.js +1 -1
  27. package/lib/plugins/sticky-rows/index.js +1 -1
  28. package/lib/plugins/tooltip/index.js +1 -1
  29. package/lib/plugins/tree/index.js +1 -1
  30. package/lib/plugins/undo-redo/index.js +1 -1
  31. package/lib/plugins/visibility/index.js +1 -1
  32. package/package.json +1 -1
  33. package/umd/grid.all.umd.js +1 -1
  34. package/umd/grid.all.umd.js.map +1 -1
  35. package/umd/grid.umd.js +1 -1
  36. package/umd/grid.umd.js.map +1 -1
@@ -1,2 +1,2 @@
1
- var e="expanded",t="group-toggle",r="group-label",o="group-count",n=/* @__PURE__ */new WeakMap;function i(e){return"__proto__"===e||"constructor"===e||"prototype"===e}var s=/* @__PURE__ */new Map;function a(e,t){if(null==e)return;const r=function(e){if(-1===e.indexOf("."))return null;let t=s.get(e);return void 0===t&&(t=Object.freeze(e.split(".")),s.set(e,t)),t}(t),o=e;return null===r?i(t)?void 0:o[t]:Object.prototype.hasOwnProperty.call(o,t)?o[t]:function(e,t){let r=e;for(let o=0;o<t.length;o++){if(null==r||"object"!=typeof r)return;const e=t[o];if(i(e))return;r=r[e]}return r}(o,r)}function d(e,t,r){return r?.valueAccessor?function(e,t,r=-1){if(!t.valueAccessor)return a(e,t.field);if("object"!=typeof e||null===e)return t.valueAccessor({row:e,column:t,rowIndex:r});const o=e,i=t.field;let s=n.get(o);if(s){const e=s.get(i);if(void 0!==e)return e.v}else s=/* @__PURE__ */new Map,n.set(o,s);const d=t.valueAccessor({row:e,column:t,rowIndex:r});return s.set(i,{v:d}),d}(e,r):a(e,t)}function l(e){return null==e||""===e||"number"==typeof e&&isNaN(e)}var u={sum:(e,t,r)=>{let o=0;for(let n=0;n<e.length;n++){const i=d(e[n],t,r);if(l(i))continue;const s=Number(i);isNaN(s)||(o+=s)}return o},avg:(e,t,r)=>{if(!e.length)return 0;let o=0,n=0;for(let i=0;i<e.length;i++){const s=d(e[i],t,r);if(l(s))continue;const a=Number(s);isNaN(a)||(o+=a,n++)}return n>0?o/n:0},count:e=>e.length,min:(e,t,r)=>{if(!e.length)return 0;let o=1/0;for(let n=0;n<e.length;n++){const i=d(e[n],t,r);if(l(i))continue;const s=Number(i);isNaN(s)||s<o&&(o=s)}return o===1/0?0:o},max:(e,t,r)=>{if(!e.length)return 0;let o=-1/0;for(let n=0;n<e.length;n++){const i=d(e[n],t,r);if(l(i))continue;const s=Number(i);isNaN(s)||s>o&&(o=s)}return o===-1/0?0:o},first:(e,t,r)=>e[0]?d(e[0],t,r):void 0,last:(e,t,r)=>e.length?d(e[e.length-1],t,r):void 0},p=/* @__PURE__ */new Map,c={register(e,t){p.set(e,t)},unregister(e){p.delete(e)},get(e){if(void 0!==e)return"function"==typeof e?e:p.get(e)??u[e]},run(e,t,r,o){const n=this.get(e);return n?n(t,r,o):void 0},has:e=>p.has(e)||e in u,list:()=>[...Object.keys(u),...p.keys()]},g={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`},h={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function f(e,t){if(!e)return;if(!1===("effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.announcements)return;const r=e.querySelector?.(".tbw-sr-only");r&&(r.textContent="","function"==typeof requestAnimationFrame?requestAnimationFrame(()=>{r.textContent=t}):r.textContent=t)}function w(e,t,...r){const o=(e&&"effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.messages?.[t];return o?o(...r):g[t](...r)}var m="__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("")),y=(new RegExp(`__(proto|defineGetter|defineSetter)|${m.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("|"))),v=/^on\w+$/i,b=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),x=/^\s*(javascript|vbscript|data|blob):/i;function _(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const o of r){const e=o.tagName.toLowerCase();if(y.has(e)){t.push(o);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(e=>v.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(o);continue}const r=[];for(const t of o.attributes){const e=t.name.toLowerCase();v.test(e)?r.push(t.name):"is"!==e?(b.has(e)&&x.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=>o.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}function C(e,t){t&&"string"==typeof t?-1!==t.indexOf("<")||-1!==t.indexOf("&")?e.replaceChildren(_(t)):e.textContent=t:e.replaceChildren()}function R(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function A(e,t,r,o){return`${R(r,o)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var E=class{static dependencies;static manifest;aliases;version="3.5.2";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},r={};for(const o of Object.keys(t))r[o]=this;for(const o of e){const e=o.userConfig;for(const[n,i]of Object.entries(e)){if(void 0===i)continue;if(!(n in t)){t[n]=i,r[n]=o;continue}if(t[n]===i)continue;const e=r[n]?.constructor.name??this.constructor.name,s=o.constructor.name,a=A("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${e} and ${s}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const o of Object.keys(t))delete t[o];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{...h,...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 o=this.#t(t,r);void 0!==o?"string"==typeof o?C(e,o):o instanceof HTMLElement&&e.replaceChildren(o.cloneNode(!0)):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const r=document.createElement("span");r.setAttribute("part","sort-indicator"),r.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(r,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(r,"sortNone"));const o=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return o?e.insertBefore(r,o):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(A(e,t,this.gridElement.id,this.name)):console.warn(`${R(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(A(e,t,this.gridElement.id,this.name))}};function S({rows:e,config:t,expanded:r,initialExpanded:o,groupSortDirections:n}){const i=t.groupOn;if("function"!=typeof i)return[];const s={key:"__root__",value:null,depth:-1,rows:[],children:/* @__PURE__ */new Map};if(e.forEach(e=>{let t=i(e);null==t||!1===t?t=["__ungrouped__"]:Array.isArray(t)||(t=[t]);let r=s;t.forEach((t,o)=>{const n=null==t?"∅":String(t),i="__root__"===r.key?n:r.key+"||"+n;let s=r.children.get(n);s||(s={key:i,value:t,depth:o,rows:[],children:/* @__PURE__ */new Map,parent:r},r.children.set(n,s)),s.rows.push(e),r=s})}),1===s.children.size&&s.children.has("__ungrouped__")&&s.children.get("__ungrouped__").rows.length===e.length)return[];const a=/* @__PURE__ */new Map;for(let c=0;c<e.length;c++)a.set(e[c],c);const d=/* @__PURE__ */new Set([...r,...o??[]]),l=e=>{const t=[...e.children.values()],r=e===s?0:e.depth+1,o=n?.get(r)??1;return t.sort((e,t)=>{const r=e.value,n=t.value;return null==r&&null==n?0:null==r?o:null==n?-o:r>n?o:r<n?-o:0}),t},u=[],p=e=>{if(e===s){for(const t of l(e))p(t);return}const t=d.has(e.key);if(u.push({kind:"group",key:e.key,value:e.value,depth:e.depth,rows:e.rows,expanded:t}),t)if(e.children.size)for(const r of l(e))p(r);else e.rows.forEach(e=>u.push({kind:"data",row:e,rowIndex:a.get(e)??-1}))};return p(s),u}function k(e,t){if(!0===e)return new Set(t);if(!1===e||null==e)/* @__PURE__ */return new Set;if("number"==typeof e){const r=t[e];return r?/* @__PURE__ */new Set([r]):/* @__PURE__ */new Set}return"string"==typeof e?/* @__PURE__ */new Set([e]):Array.isArray(e)?new Set(e):/* @__PURE__ */new Set}function G({groups:e,expanded:t,groupRows:r,loadingGroups:o,parentPath:n=[]}){const i=[],s=n.length;for(const a of e){const e=[...n,a.key],d=t.has(a.key),l=r.get(a.key)??[],u=o.has(a.key);if(i.push({kind:"group",key:a.key,value:a.value,depth:s,rows:l,expanded:d}),d)if(a.children?.length){const n=G({groups:a.children,expanded:t,groupRows:r,loadingGroups:o,parentPath:e});i.push(...n)}else u?i.push({kind:"data",row:{__loading:!0,__groupKey:a.key},rowIndex:-1}):l.forEach((e,t)=>{i.push({kind:"data",row:e,rowIndex:t})})}return i}function K(e,t,r=[]){for(const o of e){const e=[...r,o.key];if(o.key===t)return e;if(o.children?.length){const r=K(o.children,t,e);if(r.length>0)return r}}return[]}var D=class extends E{static manifest={modifiesRowStructure:!0,hookPriority:{processRows:10,onHeaderClick:-1},incompatibleWith:[{name:"tree",reason:"Both plugins transform the entire row model. TreePlugin flattens nested hierarchies while GroupingRowsPlugin groups flat rows with synthetic headers. Use one approach per grid."},{name:"pivot",reason:"PivotPlugin creates its own aggregated row and column structure. Row grouping cannot be applied on top of pivot-generated rows."}],events:[{type:"group-toggle",description:"Emitted when groups are expanded/collapsed. Broadcast to both DOM consumers and plugin bus."},{type:"group-expand",description:"Emitted when a pre-defined group is expanded."},{type:"group-collapse",description:"Emitted when a pre-defined group is collapsed."}],queries:[{type:"canMoveRow",description:"Returns false for group header rows (cannot be reordered)"},{type:"grouping:get-grouped-fields",description:"Returns the column field names that match group depth levels (string[])"},{type:"datasource:viewport-mapping",description:"Translates flat viewport row indices to top-level group indices for ServerSide pagination."}],configRules:[{id:"groupingRows/accordion-defaultExpanded",severity:"warn",message:'"accordion: true" and "defaultExpanded" (non-false) are used together.\n → In accordion mode, only one group can be open at a time.\n → Using defaultExpanded with multiple groups will collapse to one on first toggle.\n → Consider using "defaultExpanded: false" or a single group key/index with accordion mode.',check:e=>!0===e.accordion&&!1!==e.defaultExpanded&&void 0!==e.defaultExpanded&&!("number"==typeof e.defaultExpanded)&&!("string"==typeof e.defaultExpanded)&&(!0===e.defaultExpanded||Array.isArray(e.defaultExpanded)&&e.defaultExpanded.length>1)}]};static dependencies=[{name:"multiSort",required:!1,reason:"Queries sort model for coordinated group sorting"},{name:"serverSide",required:!1,reason:"Consumes datasource events for lazy-loaded grouped data"}];name="groupingRows";styles="@layer tbw-plugins{.group-row{grid-template-columns:var(--tbw-column-template);background:var(--tbw-grouping-rows-bg,var(--tbw-color-panel-bg));border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height);font-weight:500;display:grid}.group-row .cell{padding:var(--tbw-cell-padding,.125rem .5rem);align-items:center;display:flex}@media (hover:hover){.group-row:hover{background:var(--tbw-grouping-rows-bg-hover,var(--tbw-color-row-hover))}}.group-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;width:var(--tbw-toggle-size,1.25rem);height:var(--tbw-toggle-size,1.25rem);font:inherit;background:0 0;border:0;justify-content:center;align-items:center;margin-right:.25rem;display:inline-flex}.group-toggle:hover{background:var(--tbw-grouping-rows-toggle-hover,var(--tbw-color-row-hover));border-radius:var(--tbw-border-radius,.125rem)}@media (pointer:coarse){.group-toggle{min-width:var(--tbw-touch-target-min,24px);min-height:var(--tbw-touch-target-min,24px)}}.group-label{align-items:center;gap:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));display:inline-flex}.group-count{color:var(--tbw-grouping-rows-count-color,var(--tbw-color-fg-muted));font-size:var(--tbw-font-size-xs,.85em);font-weight:400}.group-aggregates{align-items:center;gap:var(--tbw-spacing-lg,1rem);margin-left:var(--tbw-spacing-lg,1rem);font-weight:400;font-size:var(--tbw-font-size-sm,.875em);color:var(--tbw-grouping-rows-aggregate-color,var(--tbw-color-fg-muted));display:inline-flex}.group-aggregate{white-space:nowrap}.group-row{padding-left:calc(var(--tbw-group-depth,0) * var(--tbw-group-indent-width,1.25em))}.data-grid-row.tbw-group-slide-in{animation:tbw-group-slide-in var(--tbw-animation-duration,.2s) var(--tbw-animation-easing,ease-out) forwards}@keyframes tbw-group-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.data-grid-row.tbw-group-fade-in{animation:tbw-group-fade-in var(--tbw-animation-duration,.2s) var(--tbw-animation-easing,ease-out) forwards}@keyframes tbw-group-fade-in{0%{opacity:0}to{opacity:1}}}";get defaultConfig(){return{defaultExpanded:!1,showRowCount:!0,indentWidth:20,aggregators:{},animation:"slide",accordion:!1}}expandedKeys=/* @__PURE__ */new Set;flattenedRows=[];isActive=!1;previousVisibleKeys=/* @__PURE__ */new Set;keysToAnimate=/* @__PURE__ */new Set;hasAppliedDefaultExpanded=!1;pendingExpansion;groupConfigDirty=!1;preDefinedGroups=[];groupRowsMap=/* @__PURE__ */new Map;loadingGroups=/* @__PURE__ */new Set;groupedFields=[];userGroupSortDirections=/* @__PURE__ */new Map;flatMeta=[];get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}detach(){(this.gridElement?.querySelector(".rows-body"))?.setAttribute("role","grid"),this.expandedKeys.clear(),this.flattenedRows=[],this.flatMeta=[],this.isActive=!1,this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.hasAppliedDefaultExpanded=!1,this.pendingExpansion=void 0,this.groupConfigDirty=!1,this.preDefinedGroups=[],this.groupRowsMap.clear(),this.loadingGroups.clear(),this.groupedFields=[],this.userGroupSortDirections.clear()}getRowHeight(e,t){if(null!=this.config.groupRowHeight)return!0===e.__isGroupRow?this.config.groupRowHeight:void 0}handleQuery(e){if("canMoveRow"===e.type&&!0===e.context?.__isGroupRow)return!1;if("grouping:get-grouped-fields"===e.type)return[...this.groupedFields];if("datasource:viewport-mapping"===e.type){const{viewportStart:t,viewportEnd:r}=e.context;if(0===this.flattenedRows.length)return;if(0===this.preDefinedGroups.length&&!Array.isArray(this.config.groups))return;const o=this.getActiveGroups();return{startNode:this.getTopLevelGroupIndex(t),endNode:this.getTopLevelGroupIndex(r)+1,totalLoadedNodes:o.length}}}getTopLevelGroupIndex(e){let t=-1;const r=Math.min(e,this.flattenedRows.length-1);for(let o=0;o<=r;o++){const e=this.flattenedRows[o];"group"===e.kind&&0===e.depth&&t++}return Math.max(0,t)}attach(e){super.attach(e),this.on("datasource:data",e=>{const t=e;t.claimed||(t.claimed=!0,this.preDefinedGroups=t.rows,this.groupRowsMap.clear(),this.loadingGroups.clear(),this.hasAppliedDefaultExpanded=!1,this.requestRender())}),this.on("datasource:children",e=>{const t=e;if("grouping-rows"!==t.context?.source)return;t.claimed=!0;const r=t.context.groupKey;r&&(this.groupRowsMap.set(r,t.rows),this.loadingGroups.delete(r),this.requestRender())})}onHeaderClick(e){const t=this.groupedFields.indexOf(e.field);if(-1===t)return;if(!e.column.sortable)return;const r=t,o=this.userGroupSortDirections.get(r)??1;return this.userGroupSortDirections.set(r,1===o?-1:1),this.requestRender(),!0}resolveGroupSortDirections(e){const t=this.config;if("function"!=typeof t.groupOn||0===e.length)return void(this.groupedFields=[]);const r=this.columns.map(e=>e.field),o=function(e,t,r){const o=/* @__PURE__ */new Map;if(0===e.length)return o;const n=e[0];let i=t(n);if(null==i||!1===i)return o;Array.isArray(i)||(i=[i]);for(let s=0;s<i.length;s++){const e=i[s];for(const t of r)if(n[t]===e){o.set(s,t);break}}return o}([...e],t.groupOn,r);if(this.groupedFields=[...o.values()],0===o.size)return;const n=new Map(this.userGroupSortDirections);if(n.size<o.size){const e=/* @__PURE__ */new Map,t=this.grid?.query?.("sort:get-model",null);if(Array.isArray(t)&&t.length>0){const r=t[0];if(Array.isArray(r))for(const t of r)e.set(t.field,"desc"===t.direction?-1:1)}if(0===e.size){const t=this.grid;t._sortState&&e.set(t._sortState.field,t._sortState.direction)}for(const[r,i]of o)if(!n.has(r)){const t=e.get(i);void 0!==t&&n.set(r,t)}}return n.size>0?n:void 0}static detect(e,t){return"function"==typeof t?.groupOn||"boolean"==typeof t?.enableRowGrouping||Array.isArray(t?.groups)}processRows(e){const t=this.pendingExpansion;if(this.pendingExpansion=void 0,this.groupConfigDirty=!1,this.preDefinedGroups.length>0||Array.isArray(this.config.groups))return this.preDefinedGroups.length>0||Array.isArray(this.config.groups)&&this.config.groups.length>0?this.processPreDefinedGroups():(this.isActive=!1,this.flattenedRows=[],[]);const r=this.config;if("function"!=typeof r.groupOn)return this.isActive=!1,this.flattenedRows=[],[...e];const o=this.resolveGroupSortDirections(e),n=S({rows:[...e],config:r,expanded:/* @__PURE__ */new Set,groupSortDirections:o});if(0===n.length)return this.isActive=!1,this.flattenedRows=[],[...e];let i;const s=void 0!==t;let a;if(s?i=t:this.hasAppliedDefaultExpanded||0!==this.expandedKeys.size||!1===r.defaultExpanded||(i=r.defaultExpanded??!1),void 0!==i){const e=function(e){return e.filter(e=>"group"===e.kind).map(e=>e.key)}(n);a=k(i,e),(s||a.size>0)&&(this.expandedKeys=new Set(a),this.hasAppliedDefaultExpanded=!0)}const d=S({rows:[...e],config:r,expanded:this.expandedKeys,initialExpanded:a,groupSortDirections:o});this.isActive=!0,this.flattenedRows=d,this.computeFlatMeta(),s&&this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.keysToAnimate.clear();const l=/* @__PURE__ */new Set;return d.forEach((e,t)=>{if("data"===e.kind){const e=`data-${t}`;l.add(e),this.previousVisibleKeys.has(e)||this.keysToAnimate.add(e)}}),this.previousVisibleKeys=l,d.map(e=>{return"group"===e.kind?{__isGroupRow:!0,__groupKey:e.key,__groupValue:e.value,__groupDepth:e.depth,__groupRows:e.rows,__groupExpanded:e.expanded,__groupRowCount:(t=e,"group"!==t.kind?0:t.rows.length),__rowCacheKey:`group:${e.key}`}:e.row;var t})}onCellClick(e){const r=e.row;if(r?.__isGroupRow&&e.originalEvent.target?.closest(`.${t}`))return this.toggle(r.__groupKey),!0}onKeyDown(e){if(" "!==e.key)return;const t=this.grid._focusRow,r=this.rows[t];return r?.__isGroupRow?(e.preventDefault(),this.toggle(r.__groupKey),this.requestRenderWithFocus(),!0):void 0}renderRow(e,t,r){if(!0===e?.__loading&&e?.__groupKey){t.className="data-grid-row",t.__isCustomRow=!0,t.innerHTML="";const e=document.createElement("div");return e.className="cell",e.style.gridColumn="1 / -1",e.setAttribute("role","gridcell"),e.textContent=" ",t.appendChild(e),function(e,t){if(t){if(e.classList.add("tbw-row-loading"),e.setAttribute("aria-busy","true"),!e.querySelector(".tbw-row-loading-overlay")){const t=document.createElement("div");t.className="tbw-row-loading-overlay",t.setAttribute("aria-hidden","true");const r=document.createElement("div");r.className="tbw-row-loading-spinner",t.appendChild(r),e.appendChild(t)}}else e.classList.remove("tbw-row-loading"),e.removeAttribute("aria-busy"),e.querySelector(".tbw-row-loading-overlay")?.remove()}(t,!0),!0}if(!e?.__isGroupRow)return!1;const o=this.config;if(o.groupRowRenderer){const r=()=>{this.toggle(e.__groupKey)},n=o.groupRowRenderer({key:e.__groupKey,value:e.__groupValue,depth:e.__groupDepth,rows:e.__groupRows,expanded:e.__groupExpanded,toggleExpand:r});if(n)return t.className="data-grid-row group-row",t.__isCustomRow=!0,t.setAttribute("data-group-depth",String(e.__groupDepth)),"string"==typeof n?C(t,n):t.replaceChildren(n),!0}const n=()=>{this.toggle(e.__groupKey)};t.className="data-grid-row group-row",t.__isCustomRow=!0,t.setAttribute("data-group-depth",String(e.__groupDepth)),t.setAttribute("role","row"),t.setAttribute("aria-expanded",String(e.__groupExpanded)),t.classList.toggle("tbw-row-expanded",!!e.__groupExpanded);const i=this.flatMeta[r];return i&&(t.setAttribute("aria-level",String(i.level)),t.setAttribute("aria-setsize",String(i.setSize)),t.setAttribute("aria-posinset",String(i.posInSet))),t.style.setProperty("--tbw-group-depth",String(e.__groupDepth||0)),void 0!==o.indentWidth&&t.style.setProperty("--tbw-group-indent-width",`${o.indentWidth}px`),t.style.height="",t.innerHTML="",!1!==o.fullWidth?this.renderFullWidthGroupRow(e,t,n):this.renderPerColumnGroupRow(e,t,n),!0}afterRender(){const e=this.gridElement?.querySelector(".rows");if(!e)return;const t=this.gridElement?.querySelector(".rows-body");t&&"treegrid"!==t.getAttribute("role")&&t.setAttribute("role","treegrid");for(const n of e.querySelectorAll(".data-grid-row:not(.group-row)")){const e=n.querySelector(".cell[data-row]"),t=e?parseInt(e.getAttribute("data-row")??"-1",10):-1,r=this.flatMeta[t];r&&(n.setAttribute("aria-level",String(r.level)),n.setAttribute("aria-setsize",String(r.setSize)),n.setAttribute("aria-posinset",String(r.posInSet)))}const r=this.animationStyle;if(!1===r||0===this.keysToAnimate.size)return;const o="fade"===r?"tbw-group-fade-in":"tbw-group-slide-in";for(const n of e.querySelectorAll(".data-grid-row:not(.group-row)")){const e=n.querySelector(".cell[data-row]"),t=e?parseInt(e.getAttribute("data-row")??"-1",10):-1,r="data"===this.flattenedRows[t]?.kind?`data-${t}`:void 0;r&&this.keysToAnimate.has(r)&&(n.classList.add(o),n.addEventListener("animationend",()=>n.classList.remove(o),{once:!0}))}this.keysToAnimate.clear()}computeFlatMeta(){const e=this.flattenedRows,t=new Array(e.length),r=/* @__PURE__ */new Map,o=/* @__PURE__ */new Map;let n=null,i=0;for(const l of e)if("group"===l.kind){n&&o.set(n.key,i),n=l,i=0;const e=`${l.key.split("||").slice(0,-1).join("||")}@${l.depth}`;r.set(e,(r.get(e)??0)+1)}else i++;n&&o.set(n.key,i);const s=/* @__PURE__ */new Map;let a=null,d=0;for(let l=0;l<e.length;l++){const n=e[l];if("group"===n.kind){const e=`${n.key.split("||").slice(0,-1).join("||")}@${n.depth}`,o=(s.get(e)??0)+1;s.set(e,o),t[l]={level:n.depth+1,setSize:r.get(e)??1,posInSet:o},a=n,d=0}else{d++;const r=a?.depth??-1,n=a?o.get(a.key)??1:e.length;t[l]={level:r+2,setSize:n,posInSet:d}}}this.flatMeta=t}processPreDefinedGroups(){const e=this.preDefinedGroups.length>0?this.preDefinedGroups:Array.isArray(this.config.groups)?this.config.groups:[];if(0===e.length)return this.isActive=!1,this.flattenedRows=[],[];if(!this.hasAppliedDefaultExpanded&&0===this.expandedKeys.size&&!1!==this.config.defaultExpanded){const t=this.collectGroupKeys(e),r=k(this.config.defaultExpanded??!1,t);r.size>0&&(this.expandedKeys=new Set(r),this.hasAppliedDefaultExpanded=!0)}const t=G({groups:e,expanded:this.expandedKeys,groupRows:this.groupRowsMap,loadingGroups:this.loadingGroups});this.isActive=!0,this.flattenedRows=t,this.computeFlatMeta(),this.keysToAnimate.clear();const r=/* @__PURE__ */new Set;return t.forEach((e,t)=>{if("data"===e.kind){const e=`data-${t}`;r.add(e),this.previousVisibleKeys.has(e)||this.keysToAnimate.add(e)}}),this.previousVisibleKeys=r,t.map(t=>{if("group"===t.kind){const r=this.findGroupDefinition(e,t.key)?.rowCount??t.rows.length;return{__isGroupRow:!0,__groupKey:t.key,__groupValue:t.value,__groupDepth:t.depth,__groupRows:t.rows,__groupExpanded:t.expanded,__groupRowCount:r,__rowCacheKey:`group:${t.key}`}}return t.row})}collectGroupKeys(e){const t=[];for(const r of e)t.push(r.key),r.children?.length&&t.push(...this.collectGroupKeys(r.children));return t}getActiveGroups(){return this.preDefinedGroups.length>0?this.preDefinedGroups:Array.isArray(this.config.groups)?this.config.groups:[]}findGroupDefinition(e,t){for(const r of e){if(r.key===t)return r;if(r.children?.length){const e=this.findGroupDefinition(r.children,t);if(e)return e}}}createToggleButton(r,o){const n=document.createElement("button");return n.type="button",n.className=`${t}${r?` ${e}`:""}`,n.setAttribute("aria-label",r?"Collapse group":"Expand group"),this.setIcon(n,r?"collapse":"expand"),n.addEventListener("click",e=>{e.stopPropagation(),o()}),n}getGroupLabelText(e,t,r){const o=this.config;return o.formatLabel?o.formatLabel(e,t,r):String(e)}renderFullWidthGroupRow(e,t,n){const i=this.config,s=i.aggregators??{},a=e.__groupRows??[],d=document.createElement("div");d.className="cell group-full",d.style.gridColumn="1 / -1",d.setAttribute("role","gridcell"),d.setAttribute("data-col","0"),d.appendChild(this.createToggleButton(e.__groupExpanded,n));const l=document.createElement("span");if(l.className=r,l.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey),d.appendChild(l),!1!==i.showRowCount){const t=document.createElement("span");t.className=o,t.textContent=`(${e.__groupRowCount??e.__groupRows?.length??0})`,d.appendChild(t)}const u=Object.entries(s);if(u.length>0){const e=document.createElement("span");e.className="group-aggregates";for(const[t,r]of u){const o=this.columns.find(e=>e.field===t),n=c.run(r,a,t,o);if(null!=n){const r=document.createElement("span");r.className="group-aggregate",r.setAttribute("data-field",t),r.textContent=`${o?.header??t}: ${n}`,e.appendChild(r)}}e.children.length>0&&d.appendChild(e)}t.appendChild(d)}renderPerColumnGroupRow(e,t,r){const n=this.config,i=n.aggregators??{},s=this.columns,a=e.__groupRows??[],d=(this.gridElement?.querySelector(".body"))?.style.gridTemplateColumns||"";d&&(t.style.display="grid",t.style.gridTemplateColumns=d);let l=!1;s.forEach((s,d)=>{const u=document.createElement("div");if(u.className="cell group-cell",u.setAttribute("data-col",String(d)),u.setAttribute("role","gridcell"),"__tbw_expander"===s.field)return u.setAttribute("data-field",s.field),void t.appendChild(u);if(l){const e=i[s.field];if(e){const t=c.run(e,a,s.field,s);u.textContent=null!=t?String(t):""}else u.textContent=""}else{l=!0,u.appendChild(this.createToggleButton(e.__groupExpanded,r));const t=document.createElement("span"),d=i[s.field];if(d){const r=c.run(d,a,s.field,s);t.textContent=String(null!=r?r:e.__groupValue)}else t.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey);if(u.appendChild(t),!1!==n.showRowCount){const e=document.createElement("span");e.className=o,e.textContent=` (${a.length})`,u.appendChild(e)}}t.appendChild(u)})}expandAll(){if(this.groupConfigDirty)return this.pendingExpansion=!0,this.expandedKeys=/* @__PURE__ */new Set,void this.requestRender();this.expandedKeys=function(e){const t=/* @__PURE__ */new Set;for(const r of e)"group"===r.kind&&t.add(r.key);return t}(this.flattenedRows),this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}collapseAll(){if(this.groupConfigDirty)return this.pendingExpansion=!1,this.expandedKeys=/* @__PURE__ */new Set,void this.requestRender();this.expandedKeys=/* @__PURE__ */new Set,this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}toggle(e){const t=!this.expandedKeys.has(e),r=this.config,o=this.flattenedRows.find(t=>"group"===t.kind&&t.key===e);if(r.accordion&&t&&o){const t=/* @__PURE__ */new Set;for(const r of this.expandedKeys)if(e.startsWith(r+"||")||r.startsWith(e+"||"))e.startsWith(r+"||")&&t.add(r);else{const e=this.flattenedRows.find(e=>"group"===e.kind&&e.key===r);e&&e.depth!==o.depth&&t.add(r)}t.add(e),this.expandedKeys=t}else this.expandedKeys=function(e,t){const r=new Set(e);return r.has(t)?r.delete(t):r.add(t),r}(this.expandedKeys,e);this.broadcast("group-toggle",{key:e,expanded:this.expandedKeys.has(e),value:o?.value,depth:o?.depth??0,expandedKeys:[...this.expandedKeys]});const n=this.getActiveGroups();if(n.length>0){const r=K(n,e);if(t){if(this.emit("group-expand",{groupKey:e,groupPath:r}),!this.groupRowsMap.has(e)){const t=this.findGroupDefinition(n,e);t&&(this.loadingGroups.add(e),this.grid?.query?.("datasource:fetch-children",{context:{source:"grouping-rows",groupKey:e,group:t,groupPath:r}}))}}else this.emit("group-collapse",{groupKey:e,groupPath:r})}const i=this.expandedKeys.has(e),s=null!=o?.value?String(o.value):e;if(i){const e=o?.rows?.length??0;f(this.gridElement,w(this.gridElement,"groupExpanded",s,e))}else f(this.gridElement,w(this.gridElement,"groupCollapsed",s));this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}expand(e){this.expandedKeys.has(e)||(this.expandedKeys=/* @__PURE__ */new Set([...this.expandedKeys,e]),this.requestRender())}collapse(e){if(this.expandedKeys.has(e)){const t=new Set(this.expandedKeys);t.delete(e),this.expandedKeys=t,this.requestRender()}}getGroupState(){const e=this.flattenedRows.filter(e=>"group"===e.kind);return{isActive:this.isActive,expandedCount:this.expandedKeys.size,totalGroups:e.length,expandedKeys:[...this.expandedKeys]}}getRowCount(){return this.flattenedRows.length}refreshGroups(){this.requestRender()}getExpandedGroups(){return[...this.expandedKeys]}getFlattenedRows(){return this.flattenedRows}isGroupingActive(){return this.isActive}setGroupOn(e,t){this.config.groupOn=e,this.groupConfigDirty=!0,void 0!==t&&(this.pendingExpansion=t,this.expandedKeys=/* @__PURE__ */new Set,this.hasAppliedDefaultExpanded=!1),this.requestRender()}setGroups(e){this.preDefinedGroups=e,this.groupRowsMap.clear(),this.loadingGroups.clear(),this.expandedKeys.clear(),this.hasAppliedDefaultExpanded=!1,this.requestRender()}getGroups(){return this.preDefinedGroups.length>0?[...this.preDefinedGroups]:Array.isArray(this.config.groups)?[...this.config.groups]:[]}setGroupRows(e,t){this.groupRowsMap.set(e,t),this.loadingGroups.delete(e),this.requestRender()}setGroupLoading(e,t){t?this.loadingGroups.add(e):this.loadingGroups.delete(e),this.requestRender()}clearGroupRows(e){null!=e?this.groupRowsMap.delete(e):this.groupRowsMap.clear(),this.requestRender()}};export{D as GroupingRowsPlugin};
1
+ var e="expanded",t="group-toggle",r="group-label",o="group-count",n=/* @__PURE__ */new WeakMap;function i(e){return"__proto__"===e||"constructor"===e||"prototype"===e}var s=/* @__PURE__ */new Map;function a(e,t){if(null==e)return;const r=function(e){if(-1===e.indexOf("."))return null;let t=s.get(e);return void 0===t&&(t=Object.freeze(e.split(".")),s.set(e,t)),t}(t),o=e;return null===r?i(t)?void 0:o[t]:Object.prototype.hasOwnProperty.call(o,t)?o[t]:function(e,t){let r=e;for(let o=0;o<t.length;o++){if(null==r||"object"!=typeof r)return;const e=t[o];if(i(e))return;r=r[e]}return r}(o,r)}function d(e,t,r){return r?.valueAccessor?function(e,t,r=-1){if(!t.valueAccessor)return a(e,t.field);if("object"!=typeof e||null===e)return t.valueAccessor({row:e,column:t,rowIndex:r});const o=e,i=t.field;let s=n.get(o);if(s){const e=s.get(i);if(void 0!==e)return e.v}else s=/* @__PURE__ */new Map,n.set(o,s);const d=t.valueAccessor({row:e,column:t,rowIndex:r});return s.set(i,{v:d}),d}(e,r):a(e,t)}function l(e){return null==e||""===e||"number"==typeof e&&isNaN(e)}var u={sum:(e,t,r)=>{let o=0;for(let n=0;n<e.length;n++){const i=d(e[n],t,r);if(l(i))continue;const s=Number(i);isNaN(s)||(o+=s)}return o},avg:(e,t,r)=>{if(!e.length)return 0;let o=0,n=0;for(let i=0;i<e.length;i++){const s=d(e[i],t,r);if(l(s))continue;const a=Number(s);isNaN(a)||(o+=a,n++)}return n>0?o/n:0},count:e=>e.length,min:(e,t,r)=>{if(!e.length)return 0;let o=1/0;for(let n=0;n<e.length;n++){const i=d(e[n],t,r);if(l(i))continue;const s=Number(i);isNaN(s)||s<o&&(o=s)}return o===1/0?0:o},max:(e,t,r)=>{if(!e.length)return 0;let o=-1/0;for(let n=0;n<e.length;n++){const i=d(e[n],t,r);if(l(i))continue;const s=Number(i);isNaN(s)||s>o&&(o=s)}return o===-1/0?0:o},first:(e,t,r)=>e[0]?d(e[0],t,r):void 0,last:(e,t,r)=>e.length?d(e[e.length-1],t,r):void 0},p=/* @__PURE__ */new Map,c={register(e,t){p.set(e,t)},unregister(e){p.delete(e)},get(e){if(void 0!==e)return"function"==typeof e?e:p.get(e)??u[e]},run(e,t,r,o){const n=this.get(e);return n?n(t,r,o):void 0},has:e=>p.has(e)||e in u,list:()=>[...Object.keys(u),...p.keys()]},g={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`},h={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function f(e,t){if(!e)return;if(!1===("effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.announcements)return;const r=e.querySelector?.(".tbw-sr-only");r&&(r.textContent="","function"==typeof requestAnimationFrame?requestAnimationFrame(()=>{r.textContent=t}):r.textContent=t)}function w(e,t,...r){const o=(e&&"effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.messages?.[t];return o?o(...r):g[t](...r)}var m="__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("")),y=(new RegExp(`__(proto|defineGetter|defineSetter)|${m.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("|"))),v=/^on\w+$/i,b=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),x=/^\s*(javascript|vbscript|data|blob):/i;function _(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const o of r){const e=o.tagName.toLowerCase();if(y.has(e)){t.push(o);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(e=>v.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(o);continue}const r=[];for(const t of o.attributes){const e=t.name.toLowerCase();v.test(e)?r.push(t.name):"is"!==e?(b.has(e)&&x.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=>o.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}function C(e,t){t&&"string"==typeof t?-1!==t.indexOf("<")||-1!==t.indexOf("&")?e.replaceChildren(_(t)):e.textContent=t:e.replaceChildren()}function R(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function A(e,t,r,o){return`${R(r,o)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var E=class{static dependencies;static manifest;aliases;version="3.5.3";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},r={};for(const o of Object.keys(t))r[o]=this;for(const o of e){const e=o.userConfig;for(const[n,i]of Object.entries(e)){if(void 0===i)continue;if(!(n in t)){t[n]=i,r[n]=o;continue}if(t[n]===i)continue;const e=r[n]?.constructor.name??this.constructor.name,s=o.constructor.name,a=A("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${e} and ${s}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const o of Object.keys(t))delete t[o];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{...h,...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 o=this.#t(t,r);void 0!==o?"string"==typeof o?C(e,o):o instanceof HTMLElement&&e.replaceChildren(o.cloneNode(!0)):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const r=document.createElement("span");r.setAttribute("part","sort-indicator"),r.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(r,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(r,"sortNone"));const o=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return o?e.insertBefore(r,o):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(A(e,t,this.gridElement.id,this.name)):console.warn(`${R(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(A(e,t,this.gridElement.id,this.name))}};function S({rows:e,config:t,expanded:r,initialExpanded:o,groupSortDirections:n}){const i=t.groupOn;if("function"!=typeof i)return[];const s={key:"__root__",value:null,depth:-1,rows:[],children:/* @__PURE__ */new Map};if(e.forEach(e=>{let t=i(e);null==t||!1===t?t=["__ungrouped__"]:Array.isArray(t)||(t=[t]);let r=s;t.forEach((t,o)=>{const n=null==t?"∅":String(t),i="__root__"===r.key?n:r.key+"||"+n;let s=r.children.get(n);s||(s={key:i,value:t,depth:o,rows:[],children:/* @__PURE__ */new Map,parent:r},r.children.set(n,s)),s.rows.push(e),r=s})}),1===s.children.size&&s.children.has("__ungrouped__")&&s.children.get("__ungrouped__").rows.length===e.length)return[];const a=/* @__PURE__ */new Map;for(let c=0;c<e.length;c++)a.set(e[c],c);const d=/* @__PURE__ */new Set([...r,...o??[]]),l=e=>{const t=[...e.children.values()],r=e===s?0:e.depth+1,o=n?.get(r)??1;return t.sort((e,t)=>{const r=e.value,n=t.value;return null==r&&null==n?0:null==r?o:null==n?-o:r>n?o:r<n?-o:0}),t},u=[],p=e=>{if(e===s){for(const t of l(e))p(t);return}const t=d.has(e.key);if(u.push({kind:"group",key:e.key,value:e.value,depth:e.depth,rows:e.rows,expanded:t}),t)if(e.children.size)for(const r of l(e))p(r);else e.rows.forEach(e=>u.push({kind:"data",row:e,rowIndex:a.get(e)??-1}))};return p(s),u}function k(e,t){if(!0===e)return new Set(t);if(!1===e||null==e)/* @__PURE__ */return new Set;if("number"==typeof e){const r=t[e];return r?/* @__PURE__ */new Set([r]):/* @__PURE__ */new Set}return"string"==typeof e?/* @__PURE__ */new Set([e]):Array.isArray(e)?new Set(e):/* @__PURE__ */new Set}function G({groups:e,expanded:t,groupRows:r,loadingGroups:o,parentPath:n=[]}){const i=[],s=n.length;for(const a of e){const e=[...n,a.key],d=t.has(a.key),l=r.get(a.key)??[],u=o.has(a.key);if(i.push({kind:"group",key:a.key,value:a.value,depth:s,rows:l,expanded:d}),d)if(a.children?.length){const n=G({groups:a.children,expanded:t,groupRows:r,loadingGroups:o,parentPath:e});i.push(...n)}else u?i.push({kind:"data",row:{__loading:!0,__groupKey:a.key},rowIndex:-1}):l.forEach((e,t)=>{i.push({kind:"data",row:e,rowIndex:t})})}return i}function K(e,t,r=[]){for(const o of e){const e=[...r,o.key];if(o.key===t)return e;if(o.children?.length){const r=K(o.children,t,e);if(r.length>0)return r}}return[]}var D=class extends E{static manifest={modifiesRowStructure:!0,hookPriority:{processRows:10,onHeaderClick:-1},incompatibleWith:[{name:"tree",reason:"Both plugins transform the entire row model. TreePlugin flattens nested hierarchies while GroupingRowsPlugin groups flat rows with synthetic headers. Use one approach per grid."},{name:"pivot",reason:"PivotPlugin creates its own aggregated row and column structure. Row grouping cannot be applied on top of pivot-generated rows."}],events:[{type:"group-toggle",description:"Emitted when groups are expanded/collapsed. Broadcast to both DOM consumers and plugin bus."},{type:"group-expand",description:"Emitted when a pre-defined group is expanded."},{type:"group-collapse",description:"Emitted when a pre-defined group is collapsed."}],queries:[{type:"canMoveRow",description:"Returns false for group header rows (cannot be reordered)"},{type:"grouping:get-grouped-fields",description:"Returns the column field names that match group depth levels (string[])"},{type:"datasource:viewport-mapping",description:"Translates flat viewport row indices to top-level group indices for ServerSide pagination."}],configRules:[{id:"groupingRows/accordion-defaultExpanded",severity:"warn",message:'"accordion: true" and "defaultExpanded" (non-false) are used together.\n → In accordion mode, only one group can be open at a time.\n → Using defaultExpanded with multiple groups will collapse to one on first toggle.\n → Consider using "defaultExpanded: false" or a single group key/index with accordion mode.',check:e=>!0===e.accordion&&!1!==e.defaultExpanded&&void 0!==e.defaultExpanded&&!("number"==typeof e.defaultExpanded)&&!("string"==typeof e.defaultExpanded)&&(!0===e.defaultExpanded||Array.isArray(e.defaultExpanded)&&e.defaultExpanded.length>1)}]};static dependencies=[{name:"multiSort",required:!1,reason:"Queries sort model for coordinated group sorting"},{name:"serverSide",required:!1,reason:"Consumes datasource events for lazy-loaded grouped data"}];name="groupingRows";styles="@layer tbw-plugins{.group-row{grid-template-columns:var(--tbw-column-template);background:var(--tbw-grouping-rows-bg,var(--tbw-color-panel-bg));border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height);font-weight:500;display:grid}.group-row .cell{padding:var(--tbw-cell-padding,.125rem .5rem);align-items:center;display:flex}@media (hover:hover){.group-row:hover{background:var(--tbw-grouping-rows-bg-hover,var(--tbw-color-row-hover))}}.group-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;width:var(--tbw-toggle-size,1.25rem);height:var(--tbw-toggle-size,1.25rem);font:inherit;background:0 0;border:0;justify-content:center;align-items:center;margin-right:.25rem;display:inline-flex}.group-toggle:hover{background:var(--tbw-grouping-rows-toggle-hover,var(--tbw-color-row-hover));border-radius:var(--tbw-border-radius,.125rem)}@media (pointer:coarse){.group-toggle{min-width:var(--tbw-touch-target-min,24px);min-height:var(--tbw-touch-target-min,24px)}}.group-label{align-items:center;gap:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));display:inline-flex}.group-count{color:var(--tbw-grouping-rows-count-color,var(--tbw-color-fg-muted));font-size:var(--tbw-font-size-xs,.85em);font-weight:400}.group-aggregates{align-items:center;gap:var(--tbw-spacing-lg,1rem);margin-left:var(--tbw-spacing-lg,1rem);font-weight:400;font-size:var(--tbw-font-size-sm,.875em);color:var(--tbw-grouping-rows-aggregate-color,var(--tbw-color-fg-muted));display:inline-flex}.group-aggregate{white-space:nowrap}.group-row{padding-left:calc(var(--tbw-group-depth,0) * var(--tbw-group-indent-width,1.25em))}.data-grid-row.tbw-group-slide-in{animation:tbw-group-slide-in var(--tbw-animation-duration,.2s) var(--tbw-animation-easing,ease-out) forwards}@keyframes tbw-group-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.data-grid-row.tbw-group-fade-in{animation:tbw-group-fade-in var(--tbw-animation-duration,.2s) var(--tbw-animation-easing,ease-out) forwards}@keyframes tbw-group-fade-in{0%{opacity:0}to{opacity:1}}}";get defaultConfig(){return{defaultExpanded:!1,showRowCount:!0,indentWidth:20,aggregators:{},animation:"slide",accordion:!1}}expandedKeys=/* @__PURE__ */new Set;flattenedRows=[];isActive=!1;previousVisibleKeys=/* @__PURE__ */new Set;keysToAnimate=/* @__PURE__ */new Set;hasAppliedDefaultExpanded=!1;pendingExpansion;groupConfigDirty=!1;preDefinedGroups=[];groupRowsMap=/* @__PURE__ */new Map;loadingGroups=/* @__PURE__ */new Set;groupedFields=[];userGroupSortDirections=/* @__PURE__ */new Map;flatMeta=[];get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}detach(){(this.gridElement?.querySelector(".rows-body"))?.setAttribute("role","grid"),this.expandedKeys.clear(),this.flattenedRows=[],this.flatMeta=[],this.isActive=!1,this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.hasAppliedDefaultExpanded=!1,this.pendingExpansion=void 0,this.groupConfigDirty=!1,this.preDefinedGroups=[],this.groupRowsMap.clear(),this.loadingGroups.clear(),this.groupedFields=[],this.userGroupSortDirections.clear()}getRowHeight(e,t){if(null!=this.config.groupRowHeight)return!0===e.__isGroupRow?this.config.groupRowHeight:void 0}handleQuery(e){if("canMoveRow"===e.type&&!0===e.context?.__isGroupRow)return!1;if("grouping:get-grouped-fields"===e.type)return[...this.groupedFields];if("datasource:viewport-mapping"===e.type){const{viewportStart:t,viewportEnd:r}=e.context;if(0===this.flattenedRows.length)return;if(0===this.preDefinedGroups.length&&!Array.isArray(this.config.groups))return;const o=this.getActiveGroups();return{startNode:this.getTopLevelGroupIndex(t),endNode:this.getTopLevelGroupIndex(r)+1,totalLoadedNodes:o.length}}}getTopLevelGroupIndex(e){let t=-1;const r=Math.min(e,this.flattenedRows.length-1);for(let o=0;o<=r;o++){const e=this.flattenedRows[o];"group"===e.kind&&0===e.depth&&t++}return Math.max(0,t)}attach(e){super.attach(e),this.on("datasource:data",e=>{const t=e;t.claimed||(t.claimed=!0,this.preDefinedGroups=t.rows,this.groupRowsMap.clear(),this.loadingGroups.clear(),this.hasAppliedDefaultExpanded=!1,this.requestRender())}),this.on("datasource:children",e=>{const t=e;if("grouping-rows"!==t.context?.source)return;t.claimed=!0;const r=t.context.groupKey;r&&(this.groupRowsMap.set(r,t.rows),this.loadingGroups.delete(r),this.requestRender())})}onHeaderClick(e){const t=this.groupedFields.indexOf(e.field);if(-1===t)return;if(!e.column.sortable)return;const r=t,o=this.userGroupSortDirections.get(r)??1;return this.userGroupSortDirections.set(r,1===o?-1:1),this.requestRender(),!0}resolveGroupSortDirections(e){const t=this.config;if("function"!=typeof t.groupOn||0===e.length)return void(this.groupedFields=[]);const r=this.columns.map(e=>e.field),o=function(e,t,r){const o=/* @__PURE__ */new Map;if(0===e.length)return o;const n=e[0];let i=t(n);if(null==i||!1===i)return o;Array.isArray(i)||(i=[i]);for(let s=0;s<i.length;s++){const e=i[s];for(const t of r)if(n[t]===e){o.set(s,t);break}}return o}([...e],t.groupOn,r);if(this.groupedFields=[...o.values()],0===o.size)return;const n=new Map(this.userGroupSortDirections);if(n.size<o.size){const e=/* @__PURE__ */new Map,t=this.grid?.query?.("sort:get-model",null);if(Array.isArray(t)&&t.length>0){const r=t[0];if(Array.isArray(r))for(const t of r)e.set(t.field,"desc"===t.direction?-1:1)}if(0===e.size){const t=this.grid;t._sortState&&e.set(t._sortState.field,t._sortState.direction)}for(const[r,i]of o)if(!n.has(r)){const t=e.get(i);void 0!==t&&n.set(r,t)}}return n.size>0?n:void 0}static detect(e,t){return"function"==typeof t?.groupOn||"boolean"==typeof t?.enableRowGrouping||Array.isArray(t?.groups)}processRows(e){const t=this.pendingExpansion;if(this.pendingExpansion=void 0,this.groupConfigDirty=!1,this.preDefinedGroups.length>0||Array.isArray(this.config.groups))return this.preDefinedGroups.length>0||Array.isArray(this.config.groups)&&this.config.groups.length>0?this.processPreDefinedGroups():(this.isActive=!1,this.flattenedRows=[],[]);const r=this.config;if("function"!=typeof r.groupOn)return this.isActive=!1,this.flattenedRows=[],[...e];const o=this.resolveGroupSortDirections(e),n=S({rows:[...e],config:r,expanded:/* @__PURE__ */new Set,groupSortDirections:o});if(0===n.length)return this.isActive=!1,this.flattenedRows=[],[...e];let i;const s=void 0!==t;let a;if(s?i=t:this.hasAppliedDefaultExpanded||0!==this.expandedKeys.size||!1===r.defaultExpanded||(i=r.defaultExpanded??!1),void 0!==i){const e=function(e){return e.filter(e=>"group"===e.kind).map(e=>e.key)}(n);a=k(i,e),(s||a.size>0)&&(this.expandedKeys=new Set(a),this.hasAppliedDefaultExpanded=!0)}const d=S({rows:[...e],config:r,expanded:this.expandedKeys,initialExpanded:a,groupSortDirections:o});this.isActive=!0,this.flattenedRows=d,this.computeFlatMeta(),s&&this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.keysToAnimate.clear();const l=/* @__PURE__ */new Set;return d.forEach((e,t)=>{if("data"===e.kind){const e=`data-${t}`;l.add(e),this.previousVisibleKeys.has(e)||this.keysToAnimate.add(e)}}),this.previousVisibleKeys=l,d.map(e=>{return"group"===e.kind?{__isGroupRow:!0,__groupKey:e.key,__groupValue:e.value,__groupDepth:e.depth,__groupRows:e.rows,__groupExpanded:e.expanded,__groupRowCount:(t=e,"group"!==t.kind?0:t.rows.length),__rowCacheKey:`group:${e.key}`}:e.row;var t})}onCellClick(e){const r=e.row;if(r?.__isGroupRow&&e.originalEvent.target?.closest(`.${t}`))return this.toggle(r.__groupKey),!0}onKeyDown(e){if(" "!==e.key)return;const t=this.grid._focusRow,r=this.rows[t];return r?.__isGroupRow?(e.preventDefault(),this.toggle(r.__groupKey),this.requestRenderWithFocus(),!0):void 0}renderRow(e,t,r){if(!0===e?.__loading&&e?.__groupKey){t.className="data-grid-row",t.__isCustomRow=!0,t.innerHTML="";const e=document.createElement("div");return e.className="cell",e.style.gridColumn="1 / -1",e.setAttribute("role","gridcell"),e.textContent=" ",t.appendChild(e),function(e,t){if(t){if(e.classList.add("tbw-row-loading"),e.setAttribute("aria-busy","true"),!e.querySelector(".tbw-row-loading-overlay")){const t=document.createElement("div");t.className="tbw-row-loading-overlay",t.setAttribute("aria-hidden","true");const r=document.createElement("div");r.className="tbw-row-loading-spinner",t.appendChild(r),e.appendChild(t)}}else e.classList.remove("tbw-row-loading"),e.removeAttribute("aria-busy"),e.querySelector(".tbw-row-loading-overlay")?.remove()}(t,!0),!0}if(!e?.__isGroupRow)return!1;const o=this.config;if(o.groupRowRenderer){const r=()=>{this.toggle(e.__groupKey)},n=o.groupRowRenderer({key:e.__groupKey,value:e.__groupValue,depth:e.__groupDepth,rows:e.__groupRows,expanded:e.__groupExpanded,toggleExpand:r});if(n)return t.className="data-grid-row group-row",t.__isCustomRow=!0,t.setAttribute("data-group-depth",String(e.__groupDepth)),"string"==typeof n?C(t,n):t.replaceChildren(n),!0}const n=()=>{this.toggle(e.__groupKey)};t.className="data-grid-row group-row",t.__isCustomRow=!0,t.setAttribute("data-group-depth",String(e.__groupDepth)),t.setAttribute("role","row"),t.setAttribute("aria-expanded",String(e.__groupExpanded)),t.classList.toggle("tbw-row-expanded",!!e.__groupExpanded);const i=this.flatMeta[r];return i&&(t.setAttribute("aria-level",String(i.level)),t.setAttribute("aria-setsize",String(i.setSize)),t.setAttribute("aria-posinset",String(i.posInSet))),t.style.setProperty("--tbw-group-depth",String(e.__groupDepth||0)),void 0!==o.indentWidth&&t.style.setProperty("--tbw-group-indent-width",`${o.indentWidth}px`),t.style.height="",t.innerHTML="",!1!==o.fullWidth?this.renderFullWidthGroupRow(e,t,n):this.renderPerColumnGroupRow(e,t,n),!0}afterRender(){const e=this.gridElement?.querySelector(".rows");if(!e)return;const t=this.gridElement?.querySelector(".rows-body");t&&"treegrid"!==t.getAttribute("role")&&t.setAttribute("role","treegrid");for(const n of e.querySelectorAll(".data-grid-row:not(.group-row)")){const e=n.querySelector(".cell[data-row]"),t=e?parseInt(e.getAttribute("data-row")??"-1",10):-1,r=this.flatMeta[t];r&&(n.setAttribute("aria-level",String(r.level)),n.setAttribute("aria-setsize",String(r.setSize)),n.setAttribute("aria-posinset",String(r.posInSet)))}const r=this.animationStyle;if(!1===r||0===this.keysToAnimate.size)return;const o="fade"===r?"tbw-group-fade-in":"tbw-group-slide-in";for(const n of e.querySelectorAll(".data-grid-row:not(.group-row)")){const e=n.querySelector(".cell[data-row]"),t=e?parseInt(e.getAttribute("data-row")??"-1",10):-1,r="data"===this.flattenedRows[t]?.kind?`data-${t}`:void 0;r&&this.keysToAnimate.has(r)&&(n.classList.add(o),n.addEventListener("animationend",()=>n.classList.remove(o),{once:!0}))}this.keysToAnimate.clear()}computeFlatMeta(){const e=this.flattenedRows,t=new Array(e.length),r=/* @__PURE__ */new Map,o=/* @__PURE__ */new Map;let n=null,i=0;for(const l of e)if("group"===l.kind){n&&o.set(n.key,i),n=l,i=0;const e=`${l.key.split("||").slice(0,-1).join("||")}@${l.depth}`;r.set(e,(r.get(e)??0)+1)}else i++;n&&o.set(n.key,i);const s=/* @__PURE__ */new Map;let a=null,d=0;for(let l=0;l<e.length;l++){const n=e[l];if("group"===n.kind){const e=`${n.key.split("||").slice(0,-1).join("||")}@${n.depth}`,o=(s.get(e)??0)+1;s.set(e,o),t[l]={level:n.depth+1,setSize:r.get(e)??1,posInSet:o},a=n,d=0}else{d++;const r=a?.depth??-1,n=a?o.get(a.key)??1:e.length;t[l]={level:r+2,setSize:n,posInSet:d}}}this.flatMeta=t}processPreDefinedGroups(){const e=this.preDefinedGroups.length>0?this.preDefinedGroups:Array.isArray(this.config.groups)?this.config.groups:[];if(0===e.length)return this.isActive=!1,this.flattenedRows=[],[];if(!this.hasAppliedDefaultExpanded&&0===this.expandedKeys.size&&!1!==this.config.defaultExpanded){const t=this.collectGroupKeys(e),r=k(this.config.defaultExpanded??!1,t);r.size>0&&(this.expandedKeys=new Set(r),this.hasAppliedDefaultExpanded=!0)}const t=G({groups:e,expanded:this.expandedKeys,groupRows:this.groupRowsMap,loadingGroups:this.loadingGroups});this.isActive=!0,this.flattenedRows=t,this.computeFlatMeta(),this.keysToAnimate.clear();const r=/* @__PURE__ */new Set;return t.forEach((e,t)=>{if("data"===e.kind){const e=`data-${t}`;r.add(e),this.previousVisibleKeys.has(e)||this.keysToAnimate.add(e)}}),this.previousVisibleKeys=r,t.map(t=>{if("group"===t.kind){const r=this.findGroupDefinition(e,t.key)?.rowCount??t.rows.length;return{__isGroupRow:!0,__groupKey:t.key,__groupValue:t.value,__groupDepth:t.depth,__groupRows:t.rows,__groupExpanded:t.expanded,__groupRowCount:r,__rowCacheKey:`group:${t.key}`}}return t.row})}collectGroupKeys(e){const t=[];for(const r of e)t.push(r.key),r.children?.length&&t.push(...this.collectGroupKeys(r.children));return t}getActiveGroups(){return this.preDefinedGroups.length>0?this.preDefinedGroups:Array.isArray(this.config.groups)?this.config.groups:[]}findGroupDefinition(e,t){for(const r of e){if(r.key===t)return r;if(r.children?.length){const e=this.findGroupDefinition(r.children,t);if(e)return e}}}createToggleButton(r,o){const n=document.createElement("button");return n.type="button",n.className=`${t}${r?` ${e}`:""}`,n.setAttribute("aria-label",r?"Collapse group":"Expand group"),this.setIcon(n,r?"collapse":"expand"),n.addEventListener("click",e=>{e.stopPropagation(),o()}),n}getGroupLabelText(e,t,r){const o=this.config;return o.formatLabel?o.formatLabel(e,t,r):String(e)}renderFullWidthGroupRow(e,t,n){const i=this.config,s=i.aggregators??{},a=e.__groupRows??[],d=document.createElement("div");d.className="cell group-full",d.style.gridColumn="1 / -1",d.setAttribute("role","gridcell"),d.setAttribute("data-col","0"),d.appendChild(this.createToggleButton(e.__groupExpanded,n));const l=document.createElement("span");if(l.className=r,l.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey),d.appendChild(l),!1!==i.showRowCount){const t=document.createElement("span");t.className=o,t.textContent=`(${e.__groupRowCount??e.__groupRows?.length??0})`,d.appendChild(t)}const u=Object.entries(s);if(u.length>0){const e=document.createElement("span");e.className="group-aggregates";for(const[t,r]of u){const o=this.columns.find(e=>e.field===t),n=c.run(r,a,t,o);if(null!=n){const r=document.createElement("span");r.className="group-aggregate",r.setAttribute("data-field",t),r.textContent=`${o?.header??t}: ${n}`,e.appendChild(r)}}e.children.length>0&&d.appendChild(e)}t.appendChild(d)}renderPerColumnGroupRow(e,t,r){const n=this.config,i=n.aggregators??{},s=this.columns,a=e.__groupRows??[],d=(this.gridElement?.querySelector(".body"))?.style.gridTemplateColumns||"";d&&(t.style.display="grid",t.style.gridTemplateColumns=d);let l=!1;s.forEach((s,d)=>{const u=document.createElement("div");if(u.className="cell group-cell",u.setAttribute("data-col",String(d)),u.setAttribute("role","gridcell"),"__tbw_expander"===s.field)return u.setAttribute("data-field",s.field),void t.appendChild(u);if(l){const e=i[s.field];if(e){const t=c.run(e,a,s.field,s);u.textContent=null!=t?String(t):""}else u.textContent=""}else{l=!0,u.appendChild(this.createToggleButton(e.__groupExpanded,r));const t=document.createElement("span"),d=i[s.field];if(d){const r=c.run(d,a,s.field,s);t.textContent=String(null!=r?r:e.__groupValue)}else t.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey);if(u.appendChild(t),!1!==n.showRowCount){const e=document.createElement("span");e.className=o,e.textContent=` (${a.length})`,u.appendChild(e)}}t.appendChild(u)})}expandAll(){if(this.groupConfigDirty)return this.pendingExpansion=!0,this.expandedKeys=/* @__PURE__ */new Set,void this.requestRender();this.expandedKeys=function(e){const t=/* @__PURE__ */new Set;for(const r of e)"group"===r.kind&&t.add(r.key);return t}(this.flattenedRows),this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}collapseAll(){if(this.groupConfigDirty)return this.pendingExpansion=!1,this.expandedKeys=/* @__PURE__ */new Set,void this.requestRender();this.expandedKeys=/* @__PURE__ */new Set,this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}toggle(e){const t=!this.expandedKeys.has(e),r=this.config,o=this.flattenedRows.find(t=>"group"===t.kind&&t.key===e);if(r.accordion&&t&&o){const t=/* @__PURE__ */new Set;for(const r of this.expandedKeys)if(e.startsWith(r+"||")||r.startsWith(e+"||"))e.startsWith(r+"||")&&t.add(r);else{const e=this.flattenedRows.find(e=>"group"===e.kind&&e.key===r);e&&e.depth!==o.depth&&t.add(r)}t.add(e),this.expandedKeys=t}else this.expandedKeys=function(e,t){const r=new Set(e);return r.has(t)?r.delete(t):r.add(t),r}(this.expandedKeys,e);this.broadcast("group-toggle",{key:e,expanded:this.expandedKeys.has(e),value:o?.value,depth:o?.depth??0,expandedKeys:[...this.expandedKeys]});const n=this.getActiveGroups();if(n.length>0){const r=K(n,e);if(t){if(this.emit("group-expand",{groupKey:e,groupPath:r}),!this.groupRowsMap.has(e)){const t=this.findGroupDefinition(n,e);t&&(this.loadingGroups.add(e),this.grid?.query?.("datasource:fetch-children",{context:{source:"grouping-rows",groupKey:e,group:t,groupPath:r}}))}}else this.emit("group-collapse",{groupKey:e,groupPath:r})}const i=this.expandedKeys.has(e),s=null!=o?.value?String(o.value):e;if(i){const e=o?.rows?.length??0;f(this.gridElement,w(this.gridElement,"groupExpanded",s,e))}else f(this.gridElement,w(this.gridElement,"groupCollapsed",s));this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}expand(e){this.expandedKeys.has(e)||(this.expandedKeys=/* @__PURE__ */new Set([...this.expandedKeys,e]),this.requestRender())}collapse(e){if(this.expandedKeys.has(e)){const t=new Set(this.expandedKeys);t.delete(e),this.expandedKeys=t,this.requestRender()}}getGroupState(){const e=this.flattenedRows.filter(e=>"group"===e.kind);return{isActive:this.isActive,expandedCount:this.expandedKeys.size,totalGroups:e.length,expandedKeys:[...this.expandedKeys]}}getRowCount(){return this.flattenedRows.length}refreshGroups(){this.requestRender()}getExpandedGroups(){return[...this.expandedKeys]}getFlattenedRows(){return this.flattenedRows}isGroupingActive(){return this.isActive}setGroupOn(e,t){this.config.groupOn=e,this.groupConfigDirty=!0,void 0!==t&&(this.pendingExpansion=t,this.expandedKeys=/* @__PURE__ */new Set,this.hasAppliedDefaultExpanded=!1),this.requestRender()}setGroups(e){this.preDefinedGroups=e,this.groupRowsMap.clear(),this.loadingGroups.clear(),this.expandedKeys.clear(),this.hasAppliedDefaultExpanded=!1,this.requestRender()}getGroups(){return this.preDefinedGroups.length>0?[...this.preDefinedGroups]:Array.isArray(this.config.groups)?[...this.config.groups]:[]}setGroupRows(e,t){this.groupRowsMap.set(e,t),this.loadingGroups.delete(e),this.requestRender()}setGroupLoading(e,t){t?this.loadingGroups.add(e):this.loadingGroups.delete(e),this.requestRender()}clearGroupRows(e){null!=e?this.groupRowsMap.delete(e):this.groupRowsMap.clear(),this.requestRender()}};export{D as GroupingRowsPlugin};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- var e=/{{\s*([^}]+)\s*}}/g,t="__DG_EMPTY__",i=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,n="__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("")),r=new RegExp(`__(proto|defineGetter|defineSetter)|${n.slice(3).join("|")}|this\\b`);var s=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("|")),o=/^on\w+$/i,a=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),l=/^\s*(javascript|vbscript|data|blob):/i;function d(e,t){t&&"string"==typeof t?-1!==t.indexOf("<")||-1!==t.indexOf("&")?e.replaceChildren(function(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,c(t.content)),t.content}(t)):e.textContent=t:e.replaceChildren()}function c(e){const t=[],i=e.querySelectorAll("*");for(const n of i){const e=n.tagName.toLowerCase();if(s.has(e)){t.push(n);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===n.namespaceURI)&&Array.from(n.attributes).some(e=>o.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(n);continue}const i=[];for(const t of n.attributes){const e=t.name.toLowerCase();o.test(e)?i.push(t.name):"is"!==e?(a.has(e)&&l.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=>n.removeAttribute(e))}t.forEach(e=>e.remove())}function u(e,t){const i=function(e){const t=[];let i=0;for(;i<e.length;){const n=e[i];if(" "!==n){if(n>="0"&&n<="9"||"."===n&&i+1<e.length&&e[i+1]>="0"&&e[i+1]<="9"){const n=i;for(;i<e.length&&(e[i]>="0"&&e[i]<="9"||"."===e[i]);)i++;t.push({type:"num",v:Number(e.slice(n,i))});continue}if("'"===n){let n="";for(i++;i<e.length&&"'"!==e[i];)n+=e[i++];if(i>=e.length)return null;i++,t.push({type:"str",v:n});continue}if(n>="a"&&n<="z"||n>="A"&&n<="Z"||"_"===n||"$"===n){const n=i;for(;i<e.length&&/[\w$.]/.test(e[i]);)i++;t.push({type:"id",v:e.slice(n,i)});continue}if(i+2<e.length){const n=e.slice(i,i+3);if("==="===n||"!=="===n){t.push({type:"op",v:n}),i+=3;continue}}if(i+1<e.length){const n=e.slice(i,i+2);if("=="===n||"!="===n||"<="===n||">="===n||"&&"===n||"||"===n){t.push({type:"op",v:n}),i+=2;continue}}if(!"+-*/%<>!?:(),".includes(n))return null;t.push({type:"op",v:n}),i++}else i++}return t}(e);if(!i)return;const n=i;let r=0;function s(){return n[r]}function o(){return n[r++]}function a(e,t){const i=s();return!!i&&(i.type===e&&(void 0===t||i.v===t))}function l(){const e=function(){let e=d();for(;a("op","||");)o(),e=e||d();return e}();if(a("op","?")){o();const t=l();if(!a("op",":"))return;o();const i=l();return e?t:i}return e}function d(){let e=c();for(;a("op","&&");)o(),e=e&&c();return e}function c(){let e=u();for(;;){const t=s();if(!t||"op"!==t.type)break;if("==="===t.v)o(),e=e===u();else if("!=="===t.v)o(),e=e!==u();else if("=="===t.v)o(),e=e==u();else{if("!="!==t.v)break;o(),e=e!=u()}}return e}function u(){let e=h();for(;;){const t=s();if(!t||"op"!==t.type)break;if("<"===t.v)o(),e=e<h();else if(">"===t.v)o(),e=e>h();else if("<="===t.v)o(),e=e<=h();else{if(">="!==t.v)break;o(),e=e>=h()}}return e}function h(){let e=g();for(;;){const t=s();if(!t||"op"!==t.type)break;if("+"===t.v)o(),e+=g();else{if("-"!==t.v)break;o(),e-=g()}}return e}function g(){let e=f();for(;;){const t=s();if(!t||"op"!==t.type)break;if("*"===t.v)o(),e*=f();else if("/"===t.v)o(),e/=f();else{if("%"!==t.v)break;o(),e%=f()}}return e}function f(){return a("op","!")?(o(),!f()):p()}function p(){const e=s();if(e){if("num"===e.type)return o(),e.v;if("str"===e.type)return o(),e.v;if("id"===e.type)return o(),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){o();const e=l();return a("op",")")&&o(),e}return"op"===e.type&&"-"===e.v?(o(),-p()):void 0}}const m=l();return r<n.length?void 0:m}function h(n,s){if(!n||-1===n.indexOf("{{"))return n;const o=[],a=(l=n.replace(e,(e,n)=>{const a=function(e,n){if(!(e=(e||"").trim()))return t;if(g.test(e))return t;if("value"===e)return null==n.value?t:String(n.value);if(e.startsWith("row.")&&!/[()?]/.test(e)&&!e.includes(":")){const i=e.slice(4),r=n.row?n.row[i]:void 0;return null==r?t:String(r)}if(e.startsWith("typeDefault.")&&!/[()?]/.test(e)&&!e.includes(":")){const i=e.slice(12),r=n.typeDefault?n.typeDefault[i]:void 0;return null==r?t:String(r)}if(e.length>80)return t;if(!i.test(e)||r.test(e))return t;const s=e.match(/\./g);if(s&&s.length>1)return t;try{const i=u(e,n),r=null==i?"":String(i);return g.test(r)?t:r||t}catch{return t}}(n,s);return o.push({expr:n.trim(),result:a}),a===t?a:(l=a)&&"string"==typeof l?l.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"):"";var l}),l?l.replace(new RegExp(t,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):l);var l;const d=o.length&&o.every(e=>""===e.result||e.result===t);return g.test(n)||d?"":a}var g=/Reflect|Proxy|ownKeys/;function f(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function p(e,t,i,n){return`${f(i,n)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var m={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var w=class{static dependencies;static manifest;aliases;version="3.5.2";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},i={};for(const n of Object.keys(t))i[n]=this;for(const n of e){const e=n.userConfig;for(const[r,s]of Object.entries(e)){if(void 0===s)continue;if(!(r in t)){t[r]=s,i[r]=n;continue}if(t[r]===s)continue;const e=i[r]?.constructor.name??this.constructor.name,o=n.constructor.name,a=p("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${r}" supplied by both ${e} and ${o}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,i={...e.userConfig};for(const n of Object.keys(t))delete t[n];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{...m,...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 n=this.#t(t,i);void 0!==n?"string"==typeof n?d(e,n):n instanceof HTMLElement&&e.replaceChildren(n.cloneNode(!0)):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const 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 n=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return n?e.insertBefore(i,n):e.appendChild(i),i}warn(e,t){void 0!==t?console.warn(p(e,t,this.gridElement.id,this.name)):console.warn(`${f(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(p(e,t,this.gridElement.id,this.name))}},b="__tbw_expander";function v(e){return e.field===b}function x(e,t){return e.has(t)?e.delete(t):e.add(t),e}var y=class e extends w{name="masterDetail";styles="@layer tbw-plugins{tbw-grid .cell[data-field=__tbw_expander]{justify-content:center;align-items:center;padding:0;display:flex;border-right:none!important}tbw-grid .header-row .cell[data-field=__tbw_expander]{display:none}tbw-grid .master-detail-expander{justify-content:center;align-items:center;width:100%;height:100%;display:flex}tbw-grid .master-detail-toggle{cursor:pointer;opacity:.7;-webkit-user-select:none;user-select:none;justify-content:center;align-items:center;display:inline-flex}tbw-grid .master-detail-toggle:hover{opacity:1}@media (pointer:coarse){tbw-grid .master-detail-toggle{min-width:var(--tbw-touch-target-min,24px);min-height:var(--tbw-touch-target-min,24px)}}tbw-grid .master-detail-row{background:var(--tbw-master-detail-bg,var(--tbw-color-row-alt));border-bottom:1px solid var(--tbw-master-detail-border,var(--tbw-color-border));grid-column:1/-1;display:grid;overflow:hidden}tbw-grid .master-detail-cell{padding:var(--tbw-detail-padding,var(--tbw-spacing-xl,1rem));overflow:auto}tbw-grid .master-detail-row.tbw-expanding{animation:tbw-detail-expand var(--tbw-animation-duration,.2s) var(--tbw-animation-easing,ease-out) forwards}tbw-grid .master-detail-row.tbw-collapsing{animation:tbw-detail-collapse var(--tbw-animation-duration,.2s) var(--tbw-animation-easing,ease-out) forwards}@keyframes tbw-detail-expand{0%{opacity:0;max-height:0;padding-top:0;padding-bottom:0}to{opacity:1;max-height:var(--tbw-detail-max-height,31.25rem);padding-top:var(--tbw-detail-padding,var(--tbw-spacing-xl,1rem));padding-bottom:var(--tbw-detail-padding,var(--tbw-spacing-xl,1rem))}}@keyframes tbw-detail-collapse{0%{opacity:1;max-height:var(--tbw-detail-max-height,31.25rem)}to{opacity:0;max-height:0}}}";static dependencies=[{name:"serverSide",required:!1,reason:"Fetches detail data via datasource:fetch-children on expand"}];get#i(){return this.grid}get defaultConfig(){return{detailHeight:"auto",expandOnRowClick:!1,animation:"slide"}}attach(e){super.attach(e),this.parseLightDomDetail(),this.on("datasource:children",e=>{const t=e;if("master-detail"!==t.context?.source)return;t.claimed=!0;const i=t.context.row;if(i&&this.expandedRows.has(i)){this.detailDataMap.set(i,t.rows),this.loadingDetails.delete(i);const e=this.detailElements.get(i);e&&(e.remove(),this.detailElements.delete(i),this.measuredDetailHeights.delete(i)),this.requestRender()}})}parseLightDomDetail(){const e=this.gridElement;if(!e)return;const t=e.querySelector("tbw-grid-detail");if(!t)return;const i=this.#i.__frameworkAdapter;if(i?.parseDetailElement){const e=i.parseDetailElement(t);if(e)return void(this.config={...this.config,detailRenderer:e})}const n=t.getAttribute("animation"),r=t.getAttribute("show-expand-column"),s=t.getAttribute("expand-on-row-click"),o=t.getAttribute("height"),a={};null!==n&&(a.animation="false"!==n&&n),null!==r&&(a.showExpandColumn="false"!==r),null!==s&&(a.expandOnRowClick="true"===s),null!==o&&(a.detailHeight="auto"===o?"auto":parseInt(o,10));const l=t.innerHTML.trim();l&&!this.config.detailRenderer&&(a.detailRenderer=(e,t)=>function(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,c(t.content),t.innerHTML}(h(l,{value:e,row:e}))),Object.keys(a).length>0&&(this.config={...this.config,...a})}get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}animateExpand(e,t,i){if(!this.isAnimationEnabled||!1===this.animationStyle)return!1;e.classList.add("tbw-expanding");let n=!1;const r=()=>{n||(n=!0,e.classList.remove("tbw-expanding"),void 0!==t&&void 0!==i&&this.#n(e,t,i))};return e.addEventListener("animationend",r,{once:!0}),setTimeout(r,this.animationDuration+50),!0}animateCollapse(e,t){if(!this.isAnimationEnabled||!1===this.animationStyle)return void t();e.classList.add("tbw-collapsing");const i=()=>{e.classList.remove("tbw-collapsing"),t()};e.addEventListener("animationend",i,{once:!0}),setTimeout(i,this.animationDuration+50)}#n(e,t,i){if(!e.isConnected)return;const n=e.offsetHeight;if(n>0){const e=this.measuredDetailHeights.get(t);this.measuredDetailHeights.set(t,n),e!==n&&this.grid.invalidateRowHeight(i)}}expandedRows=/* @__PURE__ */new Set;detailElements=/* @__PURE__ */new Map;measuredDetailHeights=/* @__PURE__ */new Map;rowsToAnimate=/* @__PURE__ */new Set;loadingDetails=/* @__PURE__ */new Set;detailDataMap=/* @__PURE__ */new Map;static DEFAULT_DETAIL_HEIGHT=150;getDetailHeight(t){const i=this.detailElements.get(t);if(i&&!i.classList.contains("tbw-expanding")&&!i.classList.contains("tbw-collapsing")){const e=i.offsetHeight;if(e>0)return this.measuredDetailHeights.set(t,e),e}const n=this.measuredDetailHeights.get(t);return n&&n>0?n:"number"==typeof this.config?.detailHeight?this.config.detailHeight:e.DEFAULT_DETAIL_HEIGHT}toggleAndEmit(e,t){if(e?.__isGroupRow)return;this.expandedRows=x(this.expandedRows,e);const i=this.expandedRows.has(e);i?(this.rowsToAnimate.add(e),this.detailDataMap.has(e)||this.queryBoolean("datasource:is-active")&&(this.loadingDetails.add(e),this.grid.query("datasource:fetch-children",{context:{source:"master-detail",row:e,rowIndex:t}}))):this.loadingDetails.delete(e),this.emit("detail-expand",{rowIndex:t,row:e,expanded:i}),this.requestRender()}detach(){this.expandedRows.clear(),this.detailElements.clear(),this.measuredDetailHeights.clear(),this.rowsToAnimate.clear(),this.loadingDetails.clear(),this.detailDataMap.clear()}processColumns(e){if(!(!0===this.config.showExpandColumn||!1!==this.config.showExpandColumn&&this.config.detailRenderer))return[...e];const t=[...e];if(function(e){return e.find(v)}(t))return t;const i=(n=this.name,{field:b,header:"",width:32,resizable:!1,sortable:!1,filterable:!1,lockPosition:!0,utility:!0,meta:{expanderColumn:!0,expanderPlugin:n}});var n;return i.viewRenderer=e=>{const{row:t}=e,i=this.expandedRows.has(t),n=document.createElement("span");n.className="master-detail-expander expander-cell";const r=document.createElement("span");return r.className="master-detail-toggle"+(i?" expanded":""),this.setIcon(r,i?"collapse":"expand"),r.setAttribute("role","button"),r.setAttribute("tabindex","0"),r.setAttribute("aria-expanded",String(i)),r.setAttribute("aria-label",i?"Collapse details":"Expand details"),n.appendChild(r),n},[i,...t]}onRowClick(e){if(this.config.expandOnRowClick&&this.config.detailRenderer)return this.toggleAndEmit(e.row,e.rowIndex),!1}onCellClick(e){if((e.originalEvent?.target)?.classList.contains("master-detail-toggle"))return this.toggleAndEmit(e.row,e.rowIndex),!0;this.expandedRows.size>0&&queueMicrotask(()=>this.#r())}onKeyDown(e){if(" "!==e.key)return;const t=this.grid._focusCol,i=this.grid._focusRow,n=this.visibleColumns[t];if(!n||!v(n))return;const r=this.rows[i];return r?(e.preventDefault(),this.toggleAndEmit(r,i),this.requestRenderWithFocus(),!0):void 0}afterRender(){this.#s(),this.#r()}#s(){const e=this.gridElement?.querySelector('.header-row .cell[data-field="__tbw_expander"]');if(!e)return;const t=parseInt(e.getAttribute("data-col")||"0",10),i=e.nextElementSibling;i&&(i.style.gridColumn=`${t+1} / ${t+3}`)}onScrollRender(){this.config.detailRenderer&&0!==this.expandedRows.size&&this.#r()}#r(){const e=this.config.detailRenderer;if(!e)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const i=this.#o(t);this.#a(i);const n=this.columns.length;for(const[r,s]of i){const t=this.rows[r];if(!t)continue;const i=this.expandedRows.has(t);if(s.classList.toggle("tbw-row-expanded",i),!i)continue;const o=this.detailElements.get(t);o?o.previousElementSibling!==s&&s.after(o):this.#l(t,r,s,n,e)}}#o(e){const t=this.grid,i=t._rowPool,n=t._virtualization?.start??0,r=t._virtualization?.end??0,s=/* @__PURE__ */new Map;if(i){const t=Math.min(i.length,r-n);for(let r=0;r<t;r++){const t=i[r];t.parentNode===e&&s.set(n+r,t)}return s}for(const o of e.querySelectorAll(".data-grid-row")){const e=o.querySelector(".cell[data-row]"),t=e?parseInt(e.getAttribute("data-row")??"-1",10):-1;t>=0&&s.set(t,o)}return s}#a(e){for(const[t,i]of this.detailElements){const n=this.rows.indexOf(t),r=n>=0&&e.has(n);if(this.expandedRows.has(t)&&r)continue;const s=this.#i.__frameworkAdapter;if(s?.unmount){const e=i.querySelector(".master-detail-cell")?.firstElementChild;e&&s.unmount(e)}i.parentNode&&i.remove(),this.detailElements.delete(t)}}#l(e,t,i,n,r){const s=function(e,t,i,n){const r=document.createElement("div");r.className="master-detail-row",r.setAttribute("data-detail-for",String(t)),r.setAttribute("role","row");const s=document.createElement("div");s.className="master-detail-cell",s.setAttribute("role","cell"),s.style.gridColumn=`1 / ${n+1}`;const o=i(e,t);return"string"==typeof o?d(s,o):o instanceof HTMLElement&&s.appendChild(o),r.appendChild(s),r}(e,t,r,n);"number"==typeof this.config.detailHeight&&(s.style.height=`${this.config.detailHeight}px`),i.after(s),this.detailElements.set(e,s);const o=this.rowsToAnimate.has(e);o&&this.rowsToAnimate.delete(e),o&&this.animateExpand(s,e,t)||requestAnimationFrame(()=>{this.#n(s,e,t)})}getRowHeight(e,t){if(this.expandedRows.has(e))return(this.grid.defaultRowHeight??28)+this.getDetailHeight(e)}adjustVirtualStart(e,t,i){if(0===this.expandedRows.size)return e;const n=this.grid?._virtualization?.positionCache;let r=e;if(n&&n.length>0)for(const s of this.expandedRows){const i=this.rows.indexOf(s);i<0||i>=e||n[i].offset+n[i].height>t&&i<r&&(r=i)}else{const n=[];for(const e of this.expandedRows){const t=this.rows.indexOf(e);t>=0&&n.push({index:t,row:e})}n.sort((e,t)=>e.index-t.index);let s=0;for(const{index:o,row:a}of n){const n=o*i+s,l=this.getDetailHeight(a);s+=l,o>=e||n+i+l>t&&o<r&&(r=o)}}return r}expand(e){const t=this.rows[e];t&&!t.__isGroupRow&&(this.rowsToAnimate.add(t),this.expandedRows=function(e,t){return e.add(t),e}(this.expandedRows,t),this.requestRender())}collapse(e){const t=this.rows[e];t&&(this.expandedRows=function(e,t){return e.delete(t),e}(this.expandedRows,t),this.requestRender())}toggle(e){const t=this.rows[e];t&&!t.__isGroupRow&&(this.expandedRows=x(this.expandedRows,t),this.expandedRows.has(t)&&this.rowsToAnimate.add(t),this.requestRender())}isExpanded(e){const t=this.rows[e];return!!t&&function(e,t){return e.has(t)}(this.expandedRows,t)}expandAll(){for(const e of this.rows)e?.__isGroupRow||(this.rowsToAnimate.add(e),this.expandedRows.add(e));this.requestRender()}collapseAll(){this.expandedRows.clear(),this.requestRender()}getExpandedRows(){const e=[];for(const t of this.expandedRows){const i=this.rows.indexOf(t);i>=0&&e.push(i)}return e}getDetailElement(e){const t=this.rows[e];return t?this.detailElements.get(t):void 0}getDetailData(e){const t=this.rows[e];return t?this.detailDataMap.get(t):void 0}isDetailLoading(e){const t=this.rows[e];return!!t&&this.loadingDetails.has(t)}refreshDetailRenderer(){const e=this.config.detailRenderer;if(this.config={...this.config,detailRenderer:void 0},this.parseLightDomDetail(),!this.config.detailRenderer&&e&&(this.config={...this.config,detailRenderer:e}),this.config.detailRenderer){const e=this.#i;"function"==typeof e.refreshColumns?e.refreshColumns():this.requestRender()}}};export{y as MasterDetailPlugin};
1
+ var e=/{{\s*([^}]+)\s*}}/g,t="__DG_EMPTY__",i=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,n="__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("")),r=new RegExp(`__(proto|defineGetter|defineSetter)|${n.slice(3).join("|")}|this\\b`);var s=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("|")),o=/^on\w+$/i,a=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),l=/^\s*(javascript|vbscript|data|blob):/i;function d(e,t){t&&"string"==typeof t?-1!==t.indexOf("<")||-1!==t.indexOf("&")?e.replaceChildren(function(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,c(t.content)),t.content}(t)):e.textContent=t:e.replaceChildren()}function c(e){const t=[],i=e.querySelectorAll("*");for(const n of i){const e=n.tagName.toLowerCase();if(s.has(e)){t.push(n);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===n.namespaceURI)&&Array.from(n.attributes).some(e=>o.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(n);continue}const i=[];for(const t of n.attributes){const e=t.name.toLowerCase();o.test(e)?i.push(t.name):"is"!==e?(a.has(e)&&l.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=>n.removeAttribute(e))}t.forEach(e=>e.remove())}function u(e,t){const i=function(e){const t=[];let i=0;for(;i<e.length;){const n=e[i];if(" "!==n){if(n>="0"&&n<="9"||"."===n&&i+1<e.length&&e[i+1]>="0"&&e[i+1]<="9"){const n=i;for(;i<e.length&&(e[i]>="0"&&e[i]<="9"||"."===e[i]);)i++;t.push({type:"num",v:Number(e.slice(n,i))});continue}if("'"===n){let n="";for(i++;i<e.length&&"'"!==e[i];)n+=e[i++];if(i>=e.length)return null;i++,t.push({type:"str",v:n});continue}if(n>="a"&&n<="z"||n>="A"&&n<="Z"||"_"===n||"$"===n){const n=i;for(;i<e.length&&/[\w$.]/.test(e[i]);)i++;t.push({type:"id",v:e.slice(n,i)});continue}if(i+2<e.length){const n=e.slice(i,i+3);if("==="===n||"!=="===n){t.push({type:"op",v:n}),i+=3;continue}}if(i+1<e.length){const n=e.slice(i,i+2);if("=="===n||"!="===n||"<="===n||">="===n||"&&"===n||"||"===n){t.push({type:"op",v:n}),i+=2;continue}}if(!"+-*/%<>!?:(),".includes(n))return null;t.push({type:"op",v:n}),i++}else i++}return t}(e);if(!i)return;const n=i;let r=0;function s(){return n[r]}function o(){return n[r++]}function a(e,t){const i=s();return!!i&&(i.type===e&&(void 0===t||i.v===t))}function l(){const e=function(){let e=d();for(;a("op","||");)o(),e=e||d();return e}();if(a("op","?")){o();const t=l();if(!a("op",":"))return;o();const i=l();return e?t:i}return e}function d(){let e=c();for(;a("op","&&");)o(),e=e&&c();return e}function c(){let e=u();for(;;){const t=s();if(!t||"op"!==t.type)break;if("==="===t.v)o(),e=e===u();else if("!=="===t.v)o(),e=e!==u();else if("=="===t.v)o(),e=e==u();else{if("!="!==t.v)break;o(),e=e!=u()}}return e}function u(){let e=h();for(;;){const t=s();if(!t||"op"!==t.type)break;if("<"===t.v)o(),e=e<h();else if(">"===t.v)o(),e=e>h();else if("<="===t.v)o(),e=e<=h();else{if(">="!==t.v)break;o(),e=e>=h()}}return e}function h(){let e=g();for(;;){const t=s();if(!t||"op"!==t.type)break;if("+"===t.v)o(),e+=g();else{if("-"!==t.v)break;o(),e-=g()}}return e}function g(){let e=f();for(;;){const t=s();if(!t||"op"!==t.type)break;if("*"===t.v)o(),e*=f();else if("/"===t.v)o(),e/=f();else{if("%"!==t.v)break;o(),e%=f()}}return e}function f(){return a("op","!")?(o(),!f()):p()}function p(){const e=s();if(e){if("num"===e.type)return o(),e.v;if("str"===e.type)return o(),e.v;if("id"===e.type)return o(),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){o();const e=l();return a("op",")")&&o(),e}return"op"===e.type&&"-"===e.v?(o(),-p()):void 0}}const m=l();return r<n.length?void 0:m}function h(n,s){if(!n||-1===n.indexOf("{{"))return n;const o=[],a=(l=n.replace(e,(e,n)=>{const a=function(e,n){if(!(e=(e||"").trim()))return t;if(g.test(e))return t;if("value"===e)return null==n.value?t:String(n.value);if(e.startsWith("row.")&&!/[()?]/.test(e)&&!e.includes(":")){const i=e.slice(4),r=n.row?n.row[i]:void 0;return null==r?t:String(r)}if(e.startsWith("typeDefault.")&&!/[()?]/.test(e)&&!e.includes(":")){const i=e.slice(12),r=n.typeDefault?n.typeDefault[i]:void 0;return null==r?t:String(r)}if(e.length>80)return t;if(!i.test(e)||r.test(e))return t;const s=e.match(/\./g);if(s&&s.length>1)return t;try{const i=u(e,n),r=null==i?"":String(i);return g.test(r)?t:r||t}catch{return t}}(n,s);return o.push({expr:n.trim(),result:a}),a===t?a:(l=a)&&"string"==typeof l?l.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"):"";var l}),l?l.replace(new RegExp(t,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):l);var l;const d=o.length&&o.every(e=>""===e.result||e.result===t);return g.test(n)||d?"":a}var g=/Reflect|Proxy|ownKeys/;function f(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function p(e,t,i,n){return`${f(i,n)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var m={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var w=class{static dependencies;static manifest;aliases;version="3.5.3";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},i={};for(const n of Object.keys(t))i[n]=this;for(const n of e){const e=n.userConfig;for(const[r,s]of Object.entries(e)){if(void 0===s)continue;if(!(r in t)){t[r]=s,i[r]=n;continue}if(t[r]===s)continue;const e=i[r]?.constructor.name??this.constructor.name,o=n.constructor.name,a=p("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${r}" supplied by both ${e} and ${o}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,i={...e.userConfig};for(const n of Object.keys(t))delete t[n];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{...m,...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 n=this.#t(t,i);void 0!==n?"string"==typeof n?d(e,n):n instanceof HTMLElement&&e.replaceChildren(n.cloneNode(!0)):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const 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 n=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return n?e.insertBefore(i,n):e.appendChild(i),i}warn(e,t){void 0!==t?console.warn(p(e,t,this.gridElement.id,this.name)):console.warn(`${f(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(p(e,t,this.gridElement.id,this.name))}},b="__tbw_expander";function v(e){return e.field===b}function x(e,t){return e.has(t)?e.delete(t):e.add(t),e}var y=class e extends w{name="masterDetail";styles="@layer tbw-plugins{tbw-grid .cell[data-field=__tbw_expander]{justify-content:center;align-items:center;padding:0;display:flex;border-right:none!important}tbw-grid .header-row .cell[data-field=__tbw_expander]{display:none}tbw-grid .master-detail-expander{justify-content:center;align-items:center;width:100%;height:100%;display:flex}tbw-grid .master-detail-toggle{cursor:pointer;opacity:.7;-webkit-user-select:none;user-select:none;justify-content:center;align-items:center;display:inline-flex}tbw-grid .master-detail-toggle:hover{opacity:1}@media (pointer:coarse){tbw-grid .master-detail-toggle{min-width:var(--tbw-touch-target-min,24px);min-height:var(--tbw-touch-target-min,24px)}}tbw-grid .master-detail-row{background:var(--tbw-master-detail-bg,var(--tbw-color-row-alt));border-bottom:1px solid var(--tbw-master-detail-border,var(--tbw-color-border));grid-column:1/-1;display:grid;overflow:hidden}tbw-grid .master-detail-cell{padding:var(--tbw-detail-padding,var(--tbw-spacing-xl,1rem));overflow:auto}tbw-grid .master-detail-row.tbw-expanding{animation:tbw-detail-expand var(--tbw-animation-duration,.2s) var(--tbw-animation-easing,ease-out) forwards}tbw-grid .master-detail-row.tbw-collapsing{animation:tbw-detail-collapse var(--tbw-animation-duration,.2s) var(--tbw-animation-easing,ease-out) forwards}@keyframes tbw-detail-expand{0%{opacity:0;max-height:0;padding-top:0;padding-bottom:0}to{opacity:1;max-height:var(--tbw-detail-max-height,31.25rem);padding-top:var(--tbw-detail-padding,var(--tbw-spacing-xl,1rem));padding-bottom:var(--tbw-detail-padding,var(--tbw-spacing-xl,1rem))}}@keyframes tbw-detail-collapse{0%{opacity:1;max-height:var(--tbw-detail-max-height,31.25rem)}to{opacity:0;max-height:0}}}";static dependencies=[{name:"serverSide",required:!1,reason:"Fetches detail data via datasource:fetch-children on expand"}];get#i(){return this.grid}get defaultConfig(){return{detailHeight:"auto",expandOnRowClick:!1,animation:"slide"}}attach(e){super.attach(e),this.parseLightDomDetail(),this.on("datasource:children",e=>{const t=e;if("master-detail"!==t.context?.source)return;t.claimed=!0;const i=t.context.row;if(i&&this.expandedRows.has(i)){this.detailDataMap.set(i,t.rows),this.loadingDetails.delete(i);const e=this.detailElements.get(i);e&&(e.remove(),this.detailElements.delete(i),this.measuredDetailHeights.delete(i)),this.requestRender()}})}parseLightDomDetail(){const e=this.gridElement;if(!e)return;const t=e.querySelector("tbw-grid-detail");if(!t)return;const i=this.#i.__frameworkAdapter;if(i?.parseDetailElement){const e=i.parseDetailElement(t);if(e)return void(this.config={...this.config,detailRenderer:e})}const n=t.getAttribute("animation"),r=t.getAttribute("show-expand-column"),s=t.getAttribute("expand-on-row-click"),o=t.getAttribute("height"),a={};null!==n&&(a.animation="false"!==n&&n),null!==r&&(a.showExpandColumn="false"!==r),null!==s&&(a.expandOnRowClick="true"===s),null!==o&&(a.detailHeight="auto"===o?"auto":parseInt(o,10));const l=t.innerHTML.trim();l&&!this.config.detailRenderer&&(a.detailRenderer=(e,t)=>function(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,c(t.content),t.innerHTML}(h(l,{value:e,row:e}))),Object.keys(a).length>0&&(this.config={...this.config,...a})}get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}animateExpand(e,t,i){if(!this.isAnimationEnabled||!1===this.animationStyle)return!1;e.classList.add("tbw-expanding");let n=!1;const r=()=>{n||(n=!0,e.classList.remove("tbw-expanding"),void 0!==t&&void 0!==i&&this.#n(e,t,i))};return e.addEventListener("animationend",r,{once:!0}),setTimeout(r,this.animationDuration+50),!0}animateCollapse(e,t){if(!this.isAnimationEnabled||!1===this.animationStyle)return void t();e.classList.add("tbw-collapsing");const i=()=>{e.classList.remove("tbw-collapsing"),t()};e.addEventListener("animationend",i,{once:!0}),setTimeout(i,this.animationDuration+50)}#n(e,t,i){if(!e.isConnected)return;const n=e.offsetHeight;if(n>0){const e=this.measuredDetailHeights.get(t);this.measuredDetailHeights.set(t,n),e!==n&&this.grid.invalidateRowHeight(i)}}expandedRows=/* @__PURE__ */new Set;detailElements=/* @__PURE__ */new Map;measuredDetailHeights=/* @__PURE__ */new Map;rowsToAnimate=/* @__PURE__ */new Set;loadingDetails=/* @__PURE__ */new Set;detailDataMap=/* @__PURE__ */new Map;static DEFAULT_DETAIL_HEIGHT=150;getDetailHeight(t){const i=this.detailElements.get(t);if(i&&!i.classList.contains("tbw-expanding")&&!i.classList.contains("tbw-collapsing")){const e=i.offsetHeight;if(e>0)return this.measuredDetailHeights.set(t,e),e}const n=this.measuredDetailHeights.get(t);return n&&n>0?n:"number"==typeof this.config?.detailHeight?this.config.detailHeight:e.DEFAULT_DETAIL_HEIGHT}toggleAndEmit(e,t){if(e?.__isGroupRow)return;this.expandedRows=x(this.expandedRows,e);const i=this.expandedRows.has(e);i?(this.rowsToAnimate.add(e),this.detailDataMap.has(e)||this.queryBoolean("datasource:is-active")&&(this.loadingDetails.add(e),this.grid.query("datasource:fetch-children",{context:{source:"master-detail",row:e,rowIndex:t}}))):this.loadingDetails.delete(e),this.emit("detail-expand",{rowIndex:t,row:e,expanded:i}),this.requestRender()}detach(){this.expandedRows.clear(),this.detailElements.clear(),this.measuredDetailHeights.clear(),this.rowsToAnimate.clear(),this.loadingDetails.clear(),this.detailDataMap.clear()}processColumns(e){if(!(!0===this.config.showExpandColumn||!1!==this.config.showExpandColumn&&this.config.detailRenderer))return[...e];const t=[...e];if(function(e){return e.find(v)}(t))return t;const i=(n=this.name,{field:b,header:"",width:32,resizable:!1,sortable:!1,filterable:!1,lockPosition:!0,utility:!0,meta:{expanderColumn:!0,expanderPlugin:n}});var n;return i.viewRenderer=e=>{const{row:t}=e,i=this.expandedRows.has(t),n=document.createElement("span");n.className="master-detail-expander expander-cell";const r=document.createElement("span");return r.className="master-detail-toggle"+(i?" expanded":""),this.setIcon(r,i?"collapse":"expand"),r.setAttribute("role","button"),r.setAttribute("tabindex","0"),r.setAttribute("aria-expanded",String(i)),r.setAttribute("aria-label",i?"Collapse details":"Expand details"),n.appendChild(r),n},[i,...t]}onRowClick(e){if(this.config.expandOnRowClick&&this.config.detailRenderer)return this.toggleAndEmit(e.row,e.rowIndex),!1}onCellClick(e){if((e.originalEvent?.target)?.classList.contains("master-detail-toggle"))return this.toggleAndEmit(e.row,e.rowIndex),!0;this.expandedRows.size>0&&queueMicrotask(()=>this.#r())}onKeyDown(e){if(" "!==e.key)return;const t=this.grid._focusCol,i=this.grid._focusRow,n=this.visibleColumns[t];if(!n||!v(n))return;const r=this.rows[i];return r?(e.preventDefault(),this.toggleAndEmit(r,i),this.requestRenderWithFocus(),!0):void 0}afterRender(){this.#s(),this.#r()}#s(){const e=this.gridElement?.querySelector('.header-row .cell[data-field="__tbw_expander"]');if(!e)return;const t=parseInt(e.getAttribute("data-col")||"0",10),i=e.nextElementSibling;i&&(i.style.gridColumn=`${t+1} / ${t+3}`)}onScrollRender(){this.config.detailRenderer&&0!==this.expandedRows.size&&this.#r()}#r(){const e=this.config.detailRenderer;if(!e)return;const t=this.gridElement?.querySelector(".rows");if(!t)return;const i=this.#o(t);this.#a(i);const n=this.columns.length;for(const[r,s]of i){const t=this.rows[r];if(!t)continue;const i=this.expandedRows.has(t);if(s.classList.toggle("tbw-row-expanded",i),!i)continue;const o=this.detailElements.get(t);o?o.previousElementSibling!==s&&s.after(o):this.#l(t,r,s,n,e)}}#o(e){const t=this.grid,i=t._rowPool,n=t._virtualization?.start??0,r=t._virtualization?.end??0,s=/* @__PURE__ */new Map;if(i){const t=Math.min(i.length,r-n);for(let r=0;r<t;r++){const t=i[r];t.parentNode===e&&s.set(n+r,t)}return s}for(const o of e.querySelectorAll(".data-grid-row")){const e=o.querySelector(".cell[data-row]"),t=e?parseInt(e.getAttribute("data-row")??"-1",10):-1;t>=0&&s.set(t,o)}return s}#a(e){for(const[t,i]of this.detailElements){const n=this.rows.indexOf(t),r=n>=0&&e.has(n);if(this.expandedRows.has(t)&&r)continue;const s=this.#i.__frameworkAdapter;if(s?.unmount){const e=i.querySelector(".master-detail-cell")?.firstElementChild;e&&s.unmount(e)}i.parentNode&&i.remove(),this.detailElements.delete(t)}}#l(e,t,i,n,r){const s=function(e,t,i,n){const r=document.createElement("div");r.className="master-detail-row",r.setAttribute("data-detail-for",String(t)),r.setAttribute("role","row");const s=document.createElement("div");s.className="master-detail-cell",s.setAttribute("role","cell"),s.style.gridColumn=`1 / ${n+1}`;const o=i(e,t);return"string"==typeof o?d(s,o):o instanceof HTMLElement&&s.appendChild(o),r.appendChild(s),r}(e,t,r,n);"number"==typeof this.config.detailHeight&&(s.style.height=`${this.config.detailHeight}px`),i.after(s),this.detailElements.set(e,s);const o=this.rowsToAnimate.has(e);o&&this.rowsToAnimate.delete(e),o&&this.animateExpand(s,e,t)||requestAnimationFrame(()=>{this.#n(s,e,t)})}getRowHeight(e,t){if(this.expandedRows.has(e))return(this.grid.defaultRowHeight??28)+this.getDetailHeight(e)}adjustVirtualStart(e,t,i){if(0===this.expandedRows.size)return e;const n=this.grid?._virtualization?.positionCache;let r=e;if(n&&n.length>0)for(const s of this.expandedRows){const i=this.rows.indexOf(s);i<0||i>=e||n[i].offset+n[i].height>t&&i<r&&(r=i)}else{const n=[];for(const e of this.expandedRows){const t=this.rows.indexOf(e);t>=0&&n.push({index:t,row:e})}n.sort((e,t)=>e.index-t.index);let s=0;for(const{index:o,row:a}of n){const n=o*i+s,l=this.getDetailHeight(a);s+=l,o>=e||n+i+l>t&&o<r&&(r=o)}}return r}expand(e){const t=this.rows[e];t&&!t.__isGroupRow&&(this.rowsToAnimate.add(t),this.expandedRows=function(e,t){return e.add(t),e}(this.expandedRows,t),this.requestRender())}collapse(e){const t=this.rows[e];t&&(this.expandedRows=function(e,t){return e.delete(t),e}(this.expandedRows,t),this.requestRender())}toggle(e){const t=this.rows[e];t&&!t.__isGroupRow&&(this.expandedRows=x(this.expandedRows,t),this.expandedRows.has(t)&&this.rowsToAnimate.add(t),this.requestRender())}isExpanded(e){const t=this.rows[e];return!!t&&function(e,t){return e.has(t)}(this.expandedRows,t)}expandAll(){for(const e of this.rows)e?.__isGroupRow||(this.rowsToAnimate.add(e),this.expandedRows.add(e));this.requestRender()}collapseAll(){this.expandedRows.clear(),this.requestRender()}getExpandedRows(){const e=[];for(const t of this.expandedRows){const i=this.rows.indexOf(t);i>=0&&e.push(i)}return e}getDetailElement(e){const t=this.rows[e];return t?this.detailElements.get(t):void 0}getDetailData(e){const t=this.rows[e];return t?this.detailDataMap.get(t):void 0}isDetailLoading(e){const t=this.rows[e];return!!t&&this.loadingDetails.has(t)}refreshDetailRenderer(){const e=this.config.detailRenderer;if(this.config={...this.config,detailRenderer:void 0},this.parseLightDomDetail(),!this.config.detailRenderer&&e&&(this.config={...this.config,detailRenderer:e}),this.config.detailRenderer){const e=this.#i;"function"==typeof e.refreshColumns?e.refreshColumns():this.requestRender()}}};export{y as MasterDetailPlugin};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- var e={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,columnSelected:e=>`Column ${e} selected`,columnSelectionChanged:e=>`${e} columns selected`,columnSelectionCleared:()=>"Column selection cleared",selectionAxisChanged:e=>"column"===e?"Row selection cleared, column selection active":"Column selection cleared, row selection active",editingStarted:e=>`Editing row ${e+1}`,editingCommitted:e=>`Row ${e+1} saved`,dataLoaded:e=>`${e} rows loaded`},t={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function r(e,t){if(!e)return;if(!1===("effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.announcements)return;const r=e.querySelector?.(".tbw-sr-only");r&&(r.textContent="","function"==typeof requestAnimationFrame?requestAnimationFrame(()=>{r.textContent=t}):r.textContent=t)}function o(t,r,...o){const n=(t&&"effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.messages?.[r];return n?n(...o):e[r](...o)}function n(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function i(e,t,r,o){return`${n(r,o)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}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("")),l=(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("|"))),a=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),c=/^\s*(javascript|vbscript|data|blob):/i;function u(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const o of r){const e=o.tagName.toLowerCase();if(l.has(e)){t.push(o);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(e=>a.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(o);continue}const r=[];for(const t of o.attributes){const e=t.name.toLowerCase();a.test(e)?r.push(t.name):"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=>o.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}var f=class{static dependencies;static manifest;aliases;version="3.5.2";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},r={};for(const o of Object.keys(t))r[o]=this;for(const o of e){const e=o.userConfig;for(const[n,s]of Object.entries(e)){if(void 0===s)continue;if(!(n in t)){t[n]=s,r[n]=o;continue}if(t[n]===s)continue;const e=r[n]?.constructor.name??this.constructor.name,l=o.constructor.name,a=i("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${e} and ${l}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const o of Object.keys(t))delete t[o];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{...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(),r=parseInt(t,10);if(!isNaN(r))return r}return 200}setIcon(e,t,r){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const o=this.#t(t,r);var n,i;void 0!==o?"string"==typeof o?(n=e,(i=o)&&"string"==typeof i?-1!==i.indexOf("<")||-1!==i.indexOf("&")?n.replaceChildren(u(i)):n.textContent=i:n.replaceChildren()):o instanceof HTMLElement&&e.replaceChildren(o.cloneNode(!0)):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const r=document.createElement("span");r.setAttribute("part","sort-indicator"),r.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(r,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(r,"sortNone"));const o=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return o?e.insertBefore(r,o):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(i(e,t,this.gridElement.id,this.name)):console.warn(`${n(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(i(e,t,this.gridElement.id,this.name))}},h=/* @__PURE__ */new WeakMap;function g(e){return"__proto__"===e||"constructor"===e||"prototype"===e}var m=/* @__PURE__ */new Map;function p(e,t){if(null==e)return;const r=function(e){if(-1===e.indexOf("."))return null;let t=m.get(e);return void 0===t&&(t=Object.freeze(e.split(".")),m.set(e,t)),t}(t),o=e;return null===r?g(t)?void 0:o[t]:Object.prototype.hasOwnProperty.call(o,t)?o[t]:function(e,t){let r=e;for(let o=0;o<t.length;o++){if(null==r||"object"!=typeof r)return;const e=t[o];if(g(e))return;r=r[e]}return r}(o,r)}var b=new Intl.Collator(void 0,{sensitivity:"variant"});function C(e,t,r){if(!t.length)return;const o=t.map(e=>{const t=r.find(t=>t.field===e.field),o=t?.sortComparator??v,n=e.field,i=t?.valueAccessor?e=>function(e,t,r=-1){if(!t.valueAccessor)return p(e,t.field);if("object"!=typeof e||null===e)return t.valueAccessor({row:e,column:t,rowIndex:r});const o=e,n=t.field;let i=h.get(o);if(i){const e=i.get(n);if(void 0!==e)return e.v}else i=/* @__PURE__ */new Map,h.set(o,i);const s=t.valueAccessor({row:e,column:t,rowIndex:r});return i.set(n,{v:s}),s}(e,t):e=>e[n];return{field:n,asc:"asc"===e.direction,comparator:o,getValue:i,pinPlaceholders:!t?.sortComparator}}),n=o.some(e=>e.pinPlaceholders)&&function(e){for(let t=0;t<e.length;t++)if(!0===e[t]?.__loading)return!0;return!1}(e),i=e.length,s=o.length,l=new Array(i*s);for(let u=0;u<i;u++){const t=e[u],r=u*s;for(let e=0;e<s;e++)l[r+e]=o[e].getValue(t)}const a=i<=4294967295?new Uint32Array(i):new Array(i);for(let u=0;u<i;u++)a[u]=u;const d=(t,r)=>{if(n){const o=function(e,t){const r=!0===e?.__loading;return r===(!0===t?.__loading)?0:r?1:-1}(e[t],e[r]);if(0!==o)return o}const i=t*s,a=r*s;for(let n=0;n<s;n++){const s=o[n],d=s.comparator(l[i+n],l[a+n],e[t],e[r]);if(0!==d)return s.asc?d:-d}return 0};Uint32Array,a.sort(d);const c=e.slice();for(let u=0;u<i;u++)e[u]=c[a[u]]}function v(e,t){return null==e&&null==t?0:null==e?1:null==t?-1:"number"==typeof e&&"number"==typeof t?e-t:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():"boolean"==typeof e&&"boolean"==typeof t?e===t?0:e?-1:1:b.compare("string"==typeof e?e:String(e),"string"==typeof t?t:String(t))}function S(e,t){const r=e.findIndex(e=>e.field===t);return r>=0?r+1:void 0}function w(e,t){return e.find(e=>e.field===t)?.direction}var y=class extends f{static manifest={queries:[{type:"sort:get-model",description:"Returns the current multi-sort model as SortModel[]"},{type:"sort:set-model",description:"Sets the multi-sort model from context (SortModel[])"}]};name="multiSort";styles='@layer tbw-plugins{.header-cell[data-sort=asc]:after{content:"↑";margin-left:var(--tbw-spacing-xs,.25em);opacity:.8}.header-cell[data-sort=desc]:after{content:"↓";margin-left:var(--tbw-spacing-xs,.25em);opacity:.8}.sort-indicator{margin-left:var(--tbw-spacing-xs,.25em);opacity:.8}.sort-index{font-size:var(--tbw-font-size-2xs,.7em);background:var(--tbw-multi-sort-badge-bg,var(--tbw-color-panel-bg));color:var(--tbw-multi-sort-badge-color,var(--tbw-color-fg));width:var(--tbw-multi-sort-badge-size,1em);height:var(--tbw-multi-sort-badge-size,1em);margin-left:var(--tbw-spacing-xs,.125em);border-radius:50%;justify-content:center;align-items:center;font-weight:600;display:inline-flex}}';get defaultConfig(){return{maxSortColumns:3,showSortIndex:!0}}sortModel=[];cachedSortResult=null;#r=!1;#o=[];get#n(){return this.grid}clearCoreSortState(){this.#n._sortState=null}#i(e){const t=this.grid?.query?.("grouping:get-grouped-fields",null);if(!Array.isArray(t)||0===t.length)return e;const r=t[0];if(!Array.isArray(r)||0===r.length)return e;const o=new Set(r),n=e.filter(e=>!o.has(e.field));return n.length===e.length?e:n}detach(){this.sortModel=[],this.cachedSortResult=null}handleQuery(e){switch(e.type){case"sort:get-model":return[...this.sortModel];case"sort:set-model":{const t=e.context;return!!Array.isArray(t)&&(this.sortModel=[...t],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),!0)}default:return}}processRows(e){if(0===this.sortModel.length)return this.cachedSortResult=null,[...e];const t=this.#n;if(!t._isGridEditMode&&"number"==typeof t._activeEditRows&&-1!==t._activeEditRows&&this.cachedSortResult&&this.cachedSortResult.length===e.length)return[...this.cachedSortResult];const r=this.#i(this.sortModel),o=e;return r.length>0&&C(o,r,this.columns),this.cachedSortResult=o,o}onHeaderClick(e){if(!this.columns.find(t=>t.field===e.field)?.sortable)return!1;const t=e.originalEvent.shiftKey,n=this.config.maxSortColumns??3;if(this.sortModel=function(e,t,r,o){const n=e.find(e=>e.field===t);return r?n?"asc"===n.direction?e.map(e=>e.field===t?{...e,direction:"desc"}:e):e.filter(e=>e.field!==t):e.length<o?[...e,{field:t,direction:"asc"}]:e:"asc"===n?.direction?[{field:t,direction:"desc"}]:"desc"===n?.direction?[]:[{field:t,direction:"asc"}]}(this.sortModel,e.field,t,n),this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),this.grid?.requestStateChange?.(),this.sortModel.length>0){const e=this.sortModel.map(e=>`${this.columns.find(t=>t.field===e.field)?.header??e.field} ${"asc"===e.direction?"ascending":"descending"}`);r(this.gridElement,o(this.gridElement,"sortApplied",e.join(", then "),""))}else r(this.gridElement,o(this.gridElement,"sortCleared"));return!0}afterRender(){const e=this.gridElement;if(!e)return;const t=!1!==this.config.showSortIndex;e.querySelectorAll(".header-row .cell[data-field]").forEach(e=>{const r=e.getAttribute("data-field");if(!r)return;const o=S(this.sortModel,r),n=w(this.sortModel,r);if(e.querySelector(".sort-index")?.remove(),n){const r=this.updateSortIndicator(e,n);if(t&&this.sortModel.length>1&&void 0!==o){const t=document.createElement("span");t.className="sort-index",t.textContent=String(o),r.nextSibling?e.insertBefore(t,r.nextSibling):e.appendChild(t)}}else e.classList.contains("sortable")&&this.updateSortIndicator(e,null)})}getSortModel(){return[...this.sortModel]}setSortModel(e){if(this.sortModel=[...e],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...e]}),this.requestRender(),this.grid?.requestStateChange?.(),e.length>0){const t=e.map(e=>`${this.columns.find(t=>t.field===e.field)?.header??e.field} ${"asc"===e.direction?"ascending":"descending"}`);r(this.gridElement,o(this.gridElement,"sortApplied",t.join(", then "),""))}}clearSort(){this.sortModel=[],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[]}),this.requestRender(),this.grid?.requestStateChange?.(),r(this.gridElement,o(this.gridElement,"sortCleared"))}getSortIndex(e){return S(this.sortModel,e)}getSortDirection(e){return w(this.sortModel,e)}getColumnState(e){const t=this.sortModel.findIndex(t=>t.field===e);if(-1!==t)return{sort:{direction:this.sortModel[t].direction,priority:t}}}applyColumnState(e,t){if(this.#r||(this.#o=[...this.sortModel]),t.sort){const r=this.sortModel.findIndex(t=>t.field===e),o={field:e,direction:t.sort.direction};-1!==r?this.sortModel[r]=o:this.sortModel.splice(t.sort.priority,0,o)}else this.sortModel=this.sortModel.filter(t=>t.field!==e);this.clearCoreSortState(),this.#r||(this.#r=!0,queueMicrotask(()=>{this.#r=!1;const e=this.#o;this.#o=[],function(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r].field!==t[r].field||e[r].direction!==t[r].direction)return!1;return!0}(e,this.sortModel)||(this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender())}))}};export{y as MultiSortPlugin};
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 r(e,t){if(!e)return;if(!1===("effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.announcements)return;const r=e.querySelector?.(".tbw-sr-only");r&&(r.textContent="","function"==typeof requestAnimationFrame?requestAnimationFrame(()=>{r.textContent=t}):r.textContent=t)}function o(t,r,...o){const n=(t&&"effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.messages?.[r];return n?n(...o):e[r](...o)}function n(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function i(e,t,r,o){return`${n(r,o)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}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("")),l=(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("|"))),a=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),c=/^\s*(javascript|vbscript|data|blob):/i;function u(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const o of r){const e=o.tagName.toLowerCase();if(l.has(e)){t.push(o);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(e=>a.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(o);continue}const r=[];for(const t of o.attributes){const e=t.name.toLowerCase();a.test(e)?r.push(t.name):"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=>o.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}var f=class{static dependencies;static manifest;aliases;version="3.5.3";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},r={};for(const o of Object.keys(t))r[o]=this;for(const o of e){const e=o.userConfig;for(const[n,s]of Object.entries(e)){if(void 0===s)continue;if(!(n in t)){t[n]=s,r[n]=o;continue}if(t[n]===s)continue;const e=r[n]?.constructor.name??this.constructor.name,l=o.constructor.name,a=i("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${e} and ${l}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const o of Object.keys(t))delete t[o];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{...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(),r=parseInt(t,10);if(!isNaN(r))return r}return 200}setIcon(e,t,r){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const o=this.#t(t,r);var n,i;void 0!==o?"string"==typeof o?(n=e,(i=o)&&"string"==typeof i?-1!==i.indexOf("<")||-1!==i.indexOf("&")?n.replaceChildren(u(i)):n.textContent=i:n.replaceChildren()):o instanceof HTMLElement&&e.replaceChildren(o.cloneNode(!0)):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const r=document.createElement("span");r.setAttribute("part","sort-indicator"),r.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(r,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(r,"sortNone"));const o=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return o?e.insertBefore(r,o):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(i(e,t,this.gridElement.id,this.name)):console.warn(`${n(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(i(e,t,this.gridElement.id,this.name))}},h=/* @__PURE__ */new WeakMap;function g(e){return"__proto__"===e||"constructor"===e||"prototype"===e}var m=/* @__PURE__ */new Map;function p(e,t){if(null==e)return;const r=function(e){if(-1===e.indexOf("."))return null;let t=m.get(e);return void 0===t&&(t=Object.freeze(e.split(".")),m.set(e,t)),t}(t),o=e;return null===r?g(t)?void 0:o[t]:Object.prototype.hasOwnProperty.call(o,t)?o[t]:function(e,t){let r=e;for(let o=0;o<t.length;o++){if(null==r||"object"!=typeof r)return;const e=t[o];if(g(e))return;r=r[e]}return r}(o,r)}var b=new Intl.Collator(void 0,{sensitivity:"variant"});function C(e,t,r){if(!t.length)return;const o=t.map(e=>{const t=r.find(t=>t.field===e.field),o=t?.sortComparator??v,n=e.field,i=t?.valueAccessor?e=>function(e,t,r=-1){if(!t.valueAccessor)return p(e,t.field);if("object"!=typeof e||null===e)return t.valueAccessor({row:e,column:t,rowIndex:r});const o=e,n=t.field;let i=h.get(o);if(i){const e=i.get(n);if(void 0!==e)return e.v}else i=/* @__PURE__ */new Map,h.set(o,i);const s=t.valueAccessor({row:e,column:t,rowIndex:r});return i.set(n,{v:s}),s}(e,t):e=>e[n];return{field:n,asc:"asc"===e.direction,comparator:o,getValue:i,pinPlaceholders:!t?.sortComparator}}),n=o.some(e=>e.pinPlaceholders)&&function(e){for(let t=0;t<e.length;t++)if(!0===e[t]?.__loading)return!0;return!1}(e),i=e.length,s=o.length,l=new Array(i*s);for(let u=0;u<i;u++){const t=e[u],r=u*s;for(let e=0;e<s;e++)l[r+e]=o[e].getValue(t)}const a=i<=4294967295?new Uint32Array(i):new Array(i);for(let u=0;u<i;u++)a[u]=u;const d=(t,r)=>{if(n){const o=function(e,t){const r=!0===e?.__loading;return r===(!0===t?.__loading)?0:r?1:-1}(e[t],e[r]);if(0!==o)return o}const i=t*s,a=r*s;for(let n=0;n<s;n++){const s=o[n],d=s.comparator(l[i+n],l[a+n],e[t],e[r]);if(0!==d)return s.asc?d:-d}return 0};Uint32Array,a.sort(d);const c=e.slice();for(let u=0;u<i;u++)e[u]=c[a[u]]}function v(e,t){return null==e&&null==t?0:null==e?1:null==t?-1:"number"==typeof e&&"number"==typeof t?e-t:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():"boolean"==typeof e&&"boolean"==typeof t?e===t?0:e?-1:1:b.compare("string"==typeof e?e:String(e),"string"==typeof t?t:String(t))}function S(e,t){const r=e.findIndex(e=>e.field===t);return r>=0?r+1:void 0}function w(e,t){return e.find(e=>e.field===t)?.direction}var y=class extends f{static manifest={queries:[{type:"sort:get-model",description:"Returns the current multi-sort model as SortModel[]"},{type:"sort:set-model",description:"Sets the multi-sort model from context (SortModel[])"}]};name="multiSort";styles='@layer tbw-plugins{.header-cell[data-sort=asc]:after{content:"↑";margin-left:var(--tbw-spacing-xs,.25em);opacity:.8}.header-cell[data-sort=desc]:after{content:"↓";margin-left:var(--tbw-spacing-xs,.25em);opacity:.8}.sort-indicator{margin-left:var(--tbw-spacing-xs,.25em);opacity:.8}.sort-index{font-size:var(--tbw-font-size-2xs,.7em);background:var(--tbw-multi-sort-badge-bg,var(--tbw-color-panel-bg));color:var(--tbw-multi-sort-badge-color,var(--tbw-color-fg));width:var(--tbw-multi-sort-badge-size,1em);height:var(--tbw-multi-sort-badge-size,1em);margin-left:var(--tbw-spacing-xs,.125em);border-radius:50%;justify-content:center;align-items:center;font-weight:600;display:inline-flex}}';get defaultConfig(){return{maxSortColumns:3,showSortIndex:!0}}sortModel=[];cachedSortResult=null;#r=!1;#o=[];get#n(){return this.grid}clearCoreSortState(){this.#n._sortState=null}#i(e){const t=this.grid?.query?.("grouping:get-grouped-fields",null);if(!Array.isArray(t)||0===t.length)return e;const r=t[0];if(!Array.isArray(r)||0===r.length)return e;const o=new Set(r),n=e.filter(e=>!o.has(e.field));return n.length===e.length?e:n}detach(){this.sortModel=[],this.cachedSortResult=null}handleQuery(e){switch(e.type){case"sort:get-model":return[...this.sortModel];case"sort:set-model":{const t=e.context;return!!Array.isArray(t)&&(this.sortModel=[...t],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),!0)}default:return}}processRows(e){if(0===this.sortModel.length)return this.cachedSortResult=null,[...e];const t=this.#n;if(!t._isGridEditMode&&"number"==typeof t._activeEditRows&&-1!==t._activeEditRows&&this.cachedSortResult&&this.cachedSortResult.length===e.length)return[...this.cachedSortResult];const r=this.#i(this.sortModel),o=e;return r.length>0&&C(o,r,this.columns),this.cachedSortResult=o,o}onHeaderClick(e){if(!this.columns.find(t=>t.field===e.field)?.sortable)return!1;const t=e.originalEvent.shiftKey,n=this.config.maxSortColumns??3;if(this.sortModel=function(e,t,r,o){const n=e.find(e=>e.field===t);return r?n?"asc"===n.direction?e.map(e=>e.field===t?{...e,direction:"desc"}:e):e.filter(e=>e.field!==t):e.length<o?[...e,{field:t,direction:"asc"}]:e:"asc"===n?.direction?[{field:t,direction:"desc"}]:"desc"===n?.direction?[]:[{field:t,direction:"asc"}]}(this.sortModel,e.field,t,n),this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),this.grid?.requestStateChange?.(),this.sortModel.length>0){const e=this.sortModel.map(e=>`${this.columns.find(t=>t.field===e.field)?.header??e.field} ${"asc"===e.direction?"ascending":"descending"}`);r(this.gridElement,o(this.gridElement,"sortApplied",e.join(", then "),""))}else r(this.gridElement,o(this.gridElement,"sortCleared"));return!0}afterRender(){const e=this.gridElement;if(!e)return;const t=!1!==this.config.showSortIndex;e.querySelectorAll(".header-row .cell[data-field]").forEach(e=>{const r=e.getAttribute("data-field");if(!r)return;const o=S(this.sortModel,r),n=w(this.sortModel,r);if(e.querySelector(".sort-index")?.remove(),n){const r=this.updateSortIndicator(e,n);if(t&&this.sortModel.length>1&&void 0!==o){const t=document.createElement("span");t.className="sort-index",t.textContent=String(o),r.nextSibling?e.insertBefore(t,r.nextSibling):e.appendChild(t)}}else e.classList.contains("sortable")&&this.updateSortIndicator(e,null)})}getSortModel(){return[...this.sortModel]}setSortModel(e){if(this.sortModel=[...e],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...e]}),this.requestRender(),this.grid?.requestStateChange?.(),e.length>0){const t=e.map(e=>`${this.columns.find(t=>t.field===e.field)?.header??e.field} ${"asc"===e.direction?"ascending":"descending"}`);r(this.gridElement,o(this.gridElement,"sortApplied",t.join(", then "),""))}}clearSort(){this.sortModel=[],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[]}),this.requestRender(),this.grid?.requestStateChange?.(),r(this.gridElement,o(this.gridElement,"sortCleared"))}getSortIndex(e){return S(this.sortModel,e)}getSortDirection(e){return w(this.sortModel,e)}getColumnState(e){const t=this.sortModel.findIndex(t=>t.field===e);if(-1!==t)return{sort:{direction:this.sortModel[t].direction,priority:t}}}applyColumnState(e,t){if(this.#r||(this.#o=[...this.sortModel]),t.sort){const r=this.sortModel.findIndex(t=>t.field===e),o={field:e,direction:t.sort.direction};-1!==r?this.sortModel[r]=o:this.sortModel.splice(t.sort.priority,0,o)}else this.sortModel=this.sortModel.filter(t=>t.field!==e);this.clearCoreSortState(),this.#r||(this.#r=!0,queueMicrotask(()=>{this.#r=!1;const e=this.#o;this.#o=[],function(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r].field!==t[r].field||e[r].direction!==t[r].direction)return!1;return!0}(e,this.sortModel)||(this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender())}))}};export{y as MultiSortPlugin};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- var t="sticky-left",e="sticky-right";function n(t){try{if("rtl"===getComputedStyle(t).direction)return"rtl"}catch{}try{if("rtl"===t.closest?.("[dir]")?.getAttribute("dir"))return"rtl"}catch{}return"ltr"}function s(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function i(t,e,n,i){return`${s(n,i)} ${t}: ${e}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}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("|"))),l=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),a=/^\s*(javascript|vbscript|data|blob):/i;function c(t){const e=document.createElement("template");return t&&"string"==typeof t&&(e.innerHTML=t,function(t){const e=[],n=t.querySelectorAll("*");for(const s of n){const t=s.tagName.toLowerCase();if(o.has(t)){e.push(s);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===s.namespaceURI)&&Array.from(s.attributes).some(t=>l.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(s);continue}const n=[];for(const e of s.attributes){const t=e.name.toLowerCase();l.test(t)?n.push(e.name):"is"!==t?(d.has(t)&&a.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&n.push(e.name):n.push(e.name)}n.forEach(t=>s.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content)),e.content}var f={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var u=class{static dependencies;static manifest;aliases;version="3.5.2";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}get resolvedConfig(){return this.#t?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(t){if(0===t.length)return;const e={...this.userConfig},n={};for(const s of Object.keys(e))n[s]=this;for(const s of t){const t=s.userConfig;for(const[r,o]of Object.entries(t)){if(void 0===o)continue;if(!(r in e)){e[r]=o,n[r]=s;continue}if(e[r]===o)continue;const t=n[r]?.constructor.name??this.constructor.name,l=s.constructor.name,d=i("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${r}" supplied by both ${t} and ${l}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(d)}}Object.assign(this.userConfig,e)}refreshUserConfigFrom(t){const e=this.userConfig,n={...t.userConfig};for(const s of Object.keys(e))delete e[s];Object.assign(e,n)}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const n=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(n),n.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}queryBoolean(t,e=null){const n=this.grid?.query?.(t,e);return Array.isArray(n)?n.some(Boolean):!!n}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...f,...t}}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(),n=parseInt(e,10);if(!isNaN(n))return n}return 200}setIcon(t,e,n){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const s=this.#e(e,n);var i,r;void 0!==s?"string"==typeof s?(i=t,(r=s)&&"string"==typeof r?-1!==r.indexOf("<")||-1!==r.indexOf("&")?i.replaceChildren(c(r)):i.textContent=r:i.replaceChildren()):s instanceof HTMLElement&&t.replaceChildren(s.cloneNode(!0)):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const n=document.createElement("span");n.setAttribute("part","sort-indicator"),n.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(n,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(n,"sortNone"));const s=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return s?t.insertBefore(n,s):t.appendChild(n),n}warn(t,e){void 0!==e?console.warn(i(t,e,this.gridElement.id,this.name)):console.warn(`${s(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(t,e){throw new Error(i(t,e,this.gridElement.id,this.name))}};function h(t){return t.pinned??t.meta?.pinned}function p(t,e){return function(t,e){return"left"===t||"right"===t?t:"rtl"===e?"start"===t?"right":"left":"start"===t?"left":"right"}(t,e)}function g(t,e){const n=h(t);return!!n&&"left"===p(n,e)}function m(t,e){const n=h(t);return!!n&&"right"===p(n,e)}function y(t){for(let e=0;e<t.length;e++)if(null!=t[e].pinned||null!=t[e].meta?.pinned)return!0;return!1}function b(s,i){const r={groupEndAdjustments:{addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set},leftOffsets:/* @__PURE__ */new Map,rightOffsets:/* @__PURE__ */new Map,splitGroups:[]},o=Array.from(s.querySelectorAll(".header-row .cell"));if(!o.length)return r;const l=n(s),d=/* @__PURE__ */new Map,a=/* @__PURE__ */new Map;let c=0;for(const e of i)if(g(e,l)){const n=o.find(t=>t.getAttribute("data-field")===e.field);n&&(d.set(e.field,c),n.classList.add(t),n.style.position="sticky",n.style.left=c+"px",s.querySelectorAll(`.data-grid-row .cell[data-field="${e.field}"]`).forEach(e=>{e.classList.add(t),e.style.position="sticky",e.style.left=c+"px"}),c+=n.offsetWidth)}let f=0;for(const t of[...i].reverse())if(m(t,l)){const n=o.find(e=>e.getAttribute("data-field")===t.field);n&&(a.set(t.field,f),n.classList.add(e),n.style.position="sticky",n.style.right=f+"px",s.querySelectorAll(`.data-grid-row .cell[data-field="${t.field}"]`).forEach(t=>{t.classList.add(e),t.style.position="sticky",t.style.right=f+"px"}),f+=n.offsetWidth)}const u=[],h=function(n,s,i,r,o){const l={addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set},d=Array.from(n.querySelectorAll(".header-group-row .header-group-cell"));if(!d.length)return l;for(const a of d){const n=a.style.gridColumn;if(!n)continue;const d=n.match(/^(\d+)\s*\/\s*span\s+(\d+)$/);if(!d)continue;const c=parseInt(d[1],10)-1,f=c+parseInt(d[2],10)-1,u=s.slice(c,f+1);if(!u.length)continue;const h=u.every(t=>g(t,r)),p=u.every(t=>m(t,r));if(h){const e=u[0].field,n=i.find(t=>t.getAttribute("data-field")===e);n&&(a.classList.add(t),a.style.position="sticky",a.style.left=n.style.left)}else if(p){const t=u[u.length-1].field,n=i.find(e=>e.getAttribute("data-field")===t);n&&(a.classList.add(e),a.style.position="sticky",a.style.right=n.style.right)}else if(a.classList.contains("implicit-group"))C(a,u,c,i,r,l);else{const t=u.some(t=>g(t,r)),e=u.some(t=>m(t,r));(t||e)&&E(a,u,c,i,r,l,o)}}return l}(s,i,o,l,u);if(h.addGroupEnd.size>0||h.removeGroupEnd.size>0){for(const t of h.addGroupEnd){const e=o.find(e=>e.getAttribute("data-field")===t);e&&e.classList.add("group-end"),s.querySelectorAll(`.data-grid-row .cell[data-field="${t}"]`).forEach(t=>{t.classList.add("group-end")})}for(const t of h.removeGroupEnd){const e=o.find(e=>e.getAttribute("data-field")===t);e&&e.classList.remove("group-end"),s.querySelectorAll(`.data-grid-row .cell[data-field="${t}"]`).forEach(t=>{t.classList.remove("group-end")})}}return{groupEndAdjustments:h,leftOffsets:d,rightOffsets:a,splitGroups:u}}function v(t,e){return g(t,e)?"left":m(t,e)?"right":"none"}function C(n,s,i,r,o,l){const d=[];for(let t=0;t<s.length;t++){const e=v(s[t],o),n=d[d.length-1];n&&n.state===e?n.cols.push(s[t]):d.push({state:e,cols:[s[t]],colStart:i+t})}if(d.length<=1)return;const a=n.parentElement;if(!a)return;const c=n.nextSibling;a.removeChild(n);for(const f of d){const s=document.createElement("div");if(s.className=n.className,s.setAttribute("data-group",n.getAttribute("data-group")||""),s.style.gridColumn=`${f.colStart+1} / span ${f.cols.length}`,"left"===f.state){const e=f.cols[0].field,n=r.find(t=>t.getAttribute("data-field")===e);n&&(s.classList.add(t),s.style.position="sticky",s.style.left=n.style.left)}else if("right"===f.state){const t=f.cols[f.cols.length-1].field,n=r.find(e=>e.getAttribute("data-field")===t);n&&(s.classList.add(e),s.style.position="sticky",s.style.right=n.style.right)}else"none"===f.state&&f.cols.every(t=>String(t.field||"").startsWith("__tbw_"))&&(s.style.borderRightStyle="none");c?a.insertBefore(s,c):a.appendChild(s)}for(let t=0;t<d.length;t++){const e=d[t],n=d[t+1];if("none"!==e.state&&n&&"none"===n.state){const t=e.cols[e.cols.length-1].field;t&&l.addGroupEnd.add(t)}if("none"===e.state&&e.cols.every(t=>String(t.field||"").startsWith("__tbw_"))){const t=e.cols[e.cols.length-1].field;t&&l.removeGroupEnd.add(t)}}}function E(n,s,i,r,o,l,d){const a=[];for(let t=0;t<s.length;t++){const e=v(s[t],o),n=a[a.length-1];n&&n.state===e?n.cols.push(s[t]):a.push({state:e,cols:[s[t]],colStart:i+t})}if(a.length<=1)return;const c=n.parentElement;if(!c)return;const f=n.textContent||"",u=n.getAttribute("data-group")||"",h=n.nextSibling;c.removeChild(n);const p=a.findIndex(t=>"left"===t.state);let g=-1;for(let t=a.length-1;t>=0;t--)if("right"===a[t].state){g=t;break}const m=p>=0?p:g,y=p>=0&&p+1<a.length?p+1:g>=0&&g-1>=0?g-1:-1;let b,C,E,w="";for(let v=0;v<a.length;v++){const s=a[v],i=document.createElement("div");if(i.className=n.className,i.setAttribute("data-group",u),i.style.gridColumn=`${s.colStart+1} / span ${s.cols.length}`,"left"===s.state){const e=s.cols[0].field,n=r.find(t=>t.getAttribute("data-field")===e);n&&(i.classList.add(t),i.style.position="sticky",i.style.left=n.style.left),v===m&&(i.style.borderRightStyle="none",b=i,w=s.cols[s.cols.length-1].field)}else if("right"===s.state){const t=s.cols[s.cols.length-1].field,n=r.find(e=>e.getAttribute("data-field")===t);n&&(i.classList.add(e),i.style.position="sticky",i.style.right=n.style.right),v===m&&(i.style.borderLeftStyle="none",b=i,w=s.cols[0].field)}if(v===y){i.style.overflow="visible";const t=document.createElement("span");t.textContent=f,t.style.position="relative",t.style.zIndex="36",t.style.display="block",t.style.overflow="hidden",t.style.textOverflow="ellipsis",t.style.whiteSpace="nowrap",i.appendChild(t),C=i,E=t}h?c.insertBefore(i,h):c.appendChild(i)}b&&C&&E&&w&&d.push({groupId:u,label:f,pinnedFragment:b,scrollableFragment:C,floatLabel:E,pinnedField:w,isTransferred:!1,floatOffset:0})}function w(n){n.querySelectorAll(`.${t}, .${e}`).forEach(n=>{n.classList.remove(t,e),n.style.position="",n.style.left="",n.style.right=""})}var A="canMoveColumn",S=class extends u{static manifest={hookPriority:{processColumns:-10},ownedProperties:[{property:"pinned",level:"column",description:'the "pinned" column property',isUsed:t=>"left"===t||"right"===t||"start"===t||"end"===t}],queries:[{type:A,description:"Prevents pinned columns from being moved/reordered"},{type:"getStickyOffsets",description:"Returns the offsets for left/right pinned columns"},{type:"getContextMenuItems",description:"Contributes pin/unpin items to the header context menu"}]};name="pinnedColumns";get defaultConfig(){return{}}isApplied=!1;leftOffsets=/* @__PURE__ */new Map;rightOffsets=/* @__PURE__ */new Map;#n={addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set};#s=[];#i=[];#r=/* @__PURE__ */new WeakSet;detach(){this.leftOffsets.clear(),this.rightOffsets.clear(),this.isApplied=!1,this.#n={addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set},this.#s=[],this.#i=[],this.#r=/* @__PURE__ */new WeakSet}static detect(t,e){const n=e?.columns;return!!Array.isArray(n)&&y(n)}processColumns(t){const e=[...t];for(const n of e){const t=n.__element;if(!t||this.#r.has(t))continue;if(this.#r.add(t),null!=n.pinned)continue;const e=t.getAttribute("pinned");"left"!==e&&"right"!==e&&"start"!==e&&"end"!==e||(n.pinned=e)}if(this.isApplied=y(e),!this.isApplied)return e;const s=this.gridElement;return function(t,e="ltr"){const n=[],s=[],i=[];for(const r of t){const t=h(r);t?"left"===p(t,e)?n.push(r):i.push(r):s.push(r)}return[...n,...s,...i]}(e,s?n(s):"ltr")}afterRender(){if(!this.isApplied)return;const t=this.gridElement,e=[...this.columns];if(!y(e))return w(t),void(this.isApplied=!1);queueMicrotask(()=>{const n=b(t,e);this.#n=n.groupEndAdjustments,this.leftOffsets=n.leftOffsets,this.rightOffsets=n.rightOffsets,this.#s=n.splitGroups,this.#o()})}afterCellRender(n){if(!this.isApplied)return;const s=n.column.field,i=n.cellElement,r=this.leftOffsets.get(s);if(void 0!==r)i.classList.contains(t)||i.classList.add(t),i.style.position="sticky",i.style.left=r+"px";else{const t=this.rightOffsets.get(s);void 0!==t&&(i.classList.contains(e)||i.classList.add(e),i.style.position="sticky",i.style.right=t+"px")}this.#n.addGroupEnd.has(s)?n.cellElement.classList.add("group-end"):this.#n.removeGroupEnd.has(s)&&n.cellElement.classList.remove("group-end")}onScroll(t){this.#o()}#o(){if(!this.isApplied||0===this.#s.length)return;const t=this.gridElement;for(const e of this.#s){const n=e.pinnedFragment.getBoundingClientRect(),s=e.scrollableFragment.getBoundingClientRect().right<=n.right;if(s&&!e.isTransferred?(e.pinnedFragment.textContent=e.label,e.pinnedFragment.style.overflow="hidden",e.pinnedFragment.style.textOverflow="ellipsis",e.pinnedFragment.style.whiteSpace="nowrap",e.pinnedFragment.style.borderRightStyle="",e.floatLabel.style.visibility="hidden",e.floatLabel.style.transform="",e.floatOffset=0,this.#n.addGroupEnd.add(e.pinnedField),t.querySelectorAll(`.header-row .cell[data-field="${e.pinnedField}"], .data-grid-row .cell[data-field="${e.pinnedField}"]`).forEach(t=>t.classList.add("group-end")),e.isTransferred=!0):!s&&e.isTransferred&&(e.pinnedFragment.textContent="",e.pinnedFragment.style.overflow="",e.pinnedFragment.style.textOverflow="",e.pinnedFragment.style.whiteSpace="",e.pinnedFragment.style.borderRightStyle="none",e.floatLabel.style.visibility="",e.floatLabel.style.transform="",e.floatOffset=0,this.#n.addGroupEnd.delete(e.pinnedField),t.querySelectorAll(`.header-row .cell[data-field="${e.pinnedField}"], .data-grid-row .cell[data-field="${e.pinnedField}"]`).forEach(t=>t.classList.remove("group-end")),e.isTransferred=!1),!e.isTransferred){const t=e.floatLabel.getBoundingClientRect().left-e.floatOffset,s=n.left;t<s?(e.floatOffset=s-t,e.floatLabel.style.transform=`translateX(${e.floatOffset}px)`):(e.floatOffset=0,e.floatLabel.style.transform="")}}}handleQuery(t){switch(t.type){case A:return null==h(t.context)&&void 0;case"getStickyOffsets":return{left:Object.fromEntries(this.leftOffsets),right:Object.fromEntries(this.rightOffsets)};case"getContextMenuItems":{const e=t.context;if(!e.isHeader)return;const n=e.column;if(!n?.field)return;if(n.lockPinning||n.meta?.lockPinning)return;const s=[];return null!=h(n)?s.push({id:"pinned/unpin",label:this.t("pinnedColumns.unpin","Unpin Column"),icon:"📌",order:40,action:()=>this.setPinPosition(n.field,void 0)}):(s.push({id:"pinned/pin-left",label:this.t("pinnedColumns.pinLeft","Pin Left"),icon:"⬅",order:40,action:()=>this.setPinPosition(n.field,"left")}),s.push({id:"pinned/pin-right",label:this.t("pinnedColumns.pinRight","Pin Right"),icon:"➡",order:41,action:()=>this.setPinPosition(n.field,"right")})),s}default:return}}setPinPosition(t,e){const n=this.columns;if(!n?.length)return;const s=n.findIndex(e=>e.field===t);if(-1===s)return;const i=this.gridElement;if(e)0===this.#i.length&&(this.#i=n.map(t=>t.field)),i.columns=n.map(n=>{if(n.field!==t)return n;const s={...n};return s.pinned=e,s});else{const e={...n[s]};delete e.pinned;const r=[...n];r.splice(s,1);const o=this.#i.indexOf(t);if(o>=0){let t=r.length;for(let e=0;e<r.length;e++)if(!h(r[e])&&this.#i.indexOf(r[e].field)>o){t=e;break}r.splice(t,0,e)}else r.splice(Math.min(s,r.length),0,e);r.some(t=>null!=h(t))||(this.#i=[]),i.columns=r}}refreshStickyOffsets(){const t=[...this.columns],e=b(this.gridElement,t);this.#n=e.groupEndAdjustments,this.leftOffsets=e.leftOffsets,this.rightOffsets=e.rightOffsets,this.#s=e.splitGroups}getLeftPinnedColumns(){return function(t,e="ltr"){return t.filter(t=>g(t,e))}([...this.columns],n(this.gridElement))}getRightPinnedColumns(){return function(t,e="ltr"){return t.filter(t=>m(t,e))}([...this.columns],n(this.gridElement))}clearStickyPositions(){w(this.gridElement)}getHorizontalScrollOffsets(n,s){if(!this.isApplied)return;let i=0,r=0;if(n){const s=n.querySelectorAll(`.${t}`),o=n.querySelectorAll(`.${e}`);s.forEach(t=>{i+=t.offsetWidth}),o.forEach(t=>{r+=t.offsetWidth})}else this.gridElement.querySelectorAll(".header-row .cell").forEach(n=>{n.classList.contains(t)?i+=n.offsetWidth:n.classList.contains(e)&&(r+=n.offsetWidth)});const o=s?.classList.contains(t)||s?.classList.contains(e);return{left:i,right:r,skipScroll:o}}};export{S as PinnedColumnsPlugin};
1
+ var t="sticky-left",e="sticky-right";function n(t){try{if("rtl"===getComputedStyle(t).direction)return"rtl"}catch{}try{if("rtl"===t.closest?.("[dir]")?.getAttribute("dir"))return"rtl"}catch{}return"ltr"}function s(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function i(t,e,n,i){return`${s(n,i)} ${t}: ${e}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}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("|"))),l=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),a=/^\s*(javascript|vbscript|data|blob):/i;function c(t){const e=document.createElement("template");return t&&"string"==typeof t&&(e.innerHTML=t,function(t){const e=[],n=t.querySelectorAll("*");for(const s of n){const t=s.tagName.toLowerCase();if(o.has(t)){e.push(s);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===s.namespaceURI)&&Array.from(s.attributes).some(t=>l.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(s);continue}const n=[];for(const e of s.attributes){const t=e.name.toLowerCase();l.test(t)?n.push(e.name):"is"!==t?(d.has(t)&&a.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&n.push(e.name):n.push(e.name)}n.forEach(t=>s.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content)),e.content}var f={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var u=class{static dependencies;static manifest;aliases;version="3.5.3";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}get resolvedConfig(){return this.#t?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(t){if(0===t.length)return;const e={...this.userConfig},n={};for(const s of Object.keys(e))n[s]=this;for(const s of t){const t=s.userConfig;for(const[r,o]of Object.entries(t)){if(void 0===o)continue;if(!(r in e)){e[r]=o,n[r]=s;continue}if(e[r]===o)continue;const t=n[r]?.constructor.name??this.constructor.name,l=s.constructor.name,d=i("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${r}" supplied by both ${t} and ${l}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(d)}}Object.assign(this.userConfig,e)}refreshUserConfigFrom(t){const e=this.userConfig,n={...t.userConfig};for(const s of Object.keys(e))delete e[s];Object.assign(e,n)}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const n=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(n),n.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}queryBoolean(t,e=null){const n=this.grid?.query?.(t,e);return Array.isArray(n)?n.some(Boolean):!!n}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...f,...t}}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(),n=parseInt(e,10);if(!isNaN(n))return n}return 200}setIcon(t,e,n){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const s=this.#e(e,n);var i,r;void 0!==s?"string"==typeof s?(i=t,(r=s)&&"string"==typeof r?-1!==r.indexOf("<")||-1!==r.indexOf("&")?i.replaceChildren(c(r)):i.textContent=r:i.replaceChildren()):s instanceof HTMLElement&&t.replaceChildren(s.cloneNode(!0)):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const n=document.createElement("span");n.setAttribute("part","sort-indicator"),n.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(n,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(n,"sortNone"));const s=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return s?t.insertBefore(n,s):t.appendChild(n),n}warn(t,e){void 0!==e?console.warn(i(t,e,this.gridElement.id,this.name)):console.warn(`${s(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(t,e){throw new Error(i(t,e,this.gridElement.id,this.name))}};function h(t){return t.pinned??t.meta?.pinned}function p(t,e){return function(t,e){return"left"===t||"right"===t?t:"rtl"===e?"start"===t?"right":"left":"start"===t?"left":"right"}(t,e)}function g(t,e){const n=h(t);return!!n&&"left"===p(n,e)}function m(t,e){const n=h(t);return!!n&&"right"===p(n,e)}function y(t){for(let e=0;e<t.length;e++)if(null!=t[e].pinned||null!=t[e].meta?.pinned)return!0;return!1}function b(s,i){const r={groupEndAdjustments:{addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set},leftOffsets:/* @__PURE__ */new Map,rightOffsets:/* @__PURE__ */new Map,splitGroups:[]},o=Array.from(s.querySelectorAll(".header-row .cell"));if(!o.length)return r;const l=n(s),d=/* @__PURE__ */new Map,a=/* @__PURE__ */new Map;let c=0;for(const e of i)if(g(e,l)){const n=o.find(t=>t.getAttribute("data-field")===e.field);n&&(d.set(e.field,c),n.classList.add(t),n.style.position="sticky",n.style.left=c+"px",s.querySelectorAll(`.data-grid-row .cell[data-field="${e.field}"]`).forEach(e=>{e.classList.add(t),e.style.position="sticky",e.style.left=c+"px"}),c+=n.offsetWidth)}let f=0;for(const t of[...i].reverse())if(m(t,l)){const n=o.find(e=>e.getAttribute("data-field")===t.field);n&&(a.set(t.field,f),n.classList.add(e),n.style.position="sticky",n.style.right=f+"px",s.querySelectorAll(`.data-grid-row .cell[data-field="${t.field}"]`).forEach(t=>{t.classList.add(e),t.style.position="sticky",t.style.right=f+"px"}),f+=n.offsetWidth)}const u=[],h=function(n,s,i,r,o){const l={addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set},d=Array.from(n.querySelectorAll(".header-group-row .header-group-cell"));if(!d.length)return l;for(const a of d){const n=a.style.gridColumn;if(!n)continue;const d=n.match(/^(\d+)\s*\/\s*span\s+(\d+)$/);if(!d)continue;const c=parseInt(d[1],10)-1,f=c+parseInt(d[2],10)-1,u=s.slice(c,f+1);if(!u.length)continue;const h=u.every(t=>g(t,r)),p=u.every(t=>m(t,r));if(h){const e=u[0].field,n=i.find(t=>t.getAttribute("data-field")===e);n&&(a.classList.add(t),a.style.position="sticky",a.style.left=n.style.left)}else if(p){const t=u[u.length-1].field,n=i.find(e=>e.getAttribute("data-field")===t);n&&(a.classList.add(e),a.style.position="sticky",a.style.right=n.style.right)}else if(a.classList.contains("implicit-group"))C(a,u,c,i,r,l);else{const t=u.some(t=>g(t,r)),e=u.some(t=>m(t,r));(t||e)&&E(a,u,c,i,r,l,o)}}return l}(s,i,o,l,u);if(h.addGroupEnd.size>0||h.removeGroupEnd.size>0){for(const t of h.addGroupEnd){const e=o.find(e=>e.getAttribute("data-field")===t);e&&e.classList.add("group-end"),s.querySelectorAll(`.data-grid-row .cell[data-field="${t}"]`).forEach(t=>{t.classList.add("group-end")})}for(const t of h.removeGroupEnd){const e=o.find(e=>e.getAttribute("data-field")===t);e&&e.classList.remove("group-end"),s.querySelectorAll(`.data-grid-row .cell[data-field="${t}"]`).forEach(t=>{t.classList.remove("group-end")})}}return{groupEndAdjustments:h,leftOffsets:d,rightOffsets:a,splitGroups:u}}function v(t,e){return g(t,e)?"left":m(t,e)?"right":"none"}function C(n,s,i,r,o,l){const d=[];for(let t=0;t<s.length;t++){const e=v(s[t],o),n=d[d.length-1];n&&n.state===e?n.cols.push(s[t]):d.push({state:e,cols:[s[t]],colStart:i+t})}if(d.length<=1)return;const a=n.parentElement;if(!a)return;const c=n.nextSibling;a.removeChild(n);for(const f of d){const s=document.createElement("div");if(s.className=n.className,s.setAttribute("data-group",n.getAttribute("data-group")||""),s.style.gridColumn=`${f.colStart+1} / span ${f.cols.length}`,"left"===f.state){const e=f.cols[0].field,n=r.find(t=>t.getAttribute("data-field")===e);n&&(s.classList.add(t),s.style.position="sticky",s.style.left=n.style.left)}else if("right"===f.state){const t=f.cols[f.cols.length-1].field,n=r.find(e=>e.getAttribute("data-field")===t);n&&(s.classList.add(e),s.style.position="sticky",s.style.right=n.style.right)}else"none"===f.state&&f.cols.every(t=>String(t.field||"").startsWith("__tbw_"))&&(s.style.borderRightStyle="none");c?a.insertBefore(s,c):a.appendChild(s)}for(let t=0;t<d.length;t++){const e=d[t],n=d[t+1];if("none"!==e.state&&n&&"none"===n.state){const t=e.cols[e.cols.length-1].field;t&&l.addGroupEnd.add(t)}if("none"===e.state&&e.cols.every(t=>String(t.field||"").startsWith("__tbw_"))){const t=e.cols[e.cols.length-1].field;t&&l.removeGroupEnd.add(t)}}}function E(n,s,i,r,o,l,d){const a=[];for(let t=0;t<s.length;t++){const e=v(s[t],o),n=a[a.length-1];n&&n.state===e?n.cols.push(s[t]):a.push({state:e,cols:[s[t]],colStart:i+t})}if(a.length<=1)return;const c=n.parentElement;if(!c)return;const f=n.textContent||"",u=n.getAttribute("data-group")||"",h=n.nextSibling;c.removeChild(n);const p=a.findIndex(t=>"left"===t.state);let g=-1;for(let t=a.length-1;t>=0;t--)if("right"===a[t].state){g=t;break}const m=p>=0?p:g,y=p>=0&&p+1<a.length?p+1:g>=0&&g-1>=0?g-1:-1;let b,C,E,w="";for(let v=0;v<a.length;v++){const s=a[v],i=document.createElement("div");if(i.className=n.className,i.setAttribute("data-group",u),i.style.gridColumn=`${s.colStart+1} / span ${s.cols.length}`,"left"===s.state){const e=s.cols[0].field,n=r.find(t=>t.getAttribute("data-field")===e);n&&(i.classList.add(t),i.style.position="sticky",i.style.left=n.style.left),v===m&&(i.style.borderRightStyle="none",b=i,w=s.cols[s.cols.length-1].field)}else if("right"===s.state){const t=s.cols[s.cols.length-1].field,n=r.find(e=>e.getAttribute("data-field")===t);n&&(i.classList.add(e),i.style.position="sticky",i.style.right=n.style.right),v===m&&(i.style.borderLeftStyle="none",b=i,w=s.cols[0].field)}if(v===y){i.style.overflow="visible";const t=document.createElement("span");t.textContent=f,t.style.position="relative",t.style.zIndex="36",t.style.display="block",t.style.overflow="hidden",t.style.textOverflow="ellipsis",t.style.whiteSpace="nowrap",i.appendChild(t),C=i,E=t}h?c.insertBefore(i,h):c.appendChild(i)}b&&C&&E&&w&&d.push({groupId:u,label:f,pinnedFragment:b,scrollableFragment:C,floatLabel:E,pinnedField:w,isTransferred:!1,floatOffset:0})}function w(n){n.querySelectorAll(`.${t}, .${e}`).forEach(n=>{n.classList.remove(t,e),n.style.position="",n.style.left="",n.style.right=""})}var A="canMoveColumn",S=class extends u{static manifest={hookPriority:{processColumns:-10},ownedProperties:[{property:"pinned",level:"column",description:'the "pinned" column property',isUsed:t=>"left"===t||"right"===t||"start"===t||"end"===t}],queries:[{type:A,description:"Prevents pinned columns from being moved/reordered"},{type:"getStickyOffsets",description:"Returns the offsets for left/right pinned columns"},{type:"getContextMenuItems",description:"Contributes pin/unpin items to the header context menu"}]};name="pinnedColumns";get defaultConfig(){return{}}isApplied=!1;leftOffsets=/* @__PURE__ */new Map;rightOffsets=/* @__PURE__ */new Map;#n={addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set};#s=[];#i=[];#r=/* @__PURE__ */new WeakSet;detach(){this.leftOffsets.clear(),this.rightOffsets.clear(),this.isApplied=!1,this.#n={addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set},this.#s=[],this.#i=[],this.#r=/* @__PURE__ */new WeakSet}static detect(t,e){const n=e?.columns;return!!Array.isArray(n)&&y(n)}processColumns(t){const e=[...t];for(const n of e){const t=n.__element;if(!t||this.#r.has(t))continue;if(this.#r.add(t),null!=n.pinned)continue;const e=t.getAttribute("pinned");"left"!==e&&"right"!==e&&"start"!==e&&"end"!==e||(n.pinned=e)}if(this.isApplied=y(e),!this.isApplied)return e;const s=this.gridElement;return function(t,e="ltr"){const n=[],s=[],i=[];for(const r of t){const t=h(r);t?"left"===p(t,e)?n.push(r):i.push(r):s.push(r)}return[...n,...s,...i]}(e,s?n(s):"ltr")}afterRender(){if(!this.isApplied)return;const t=this.gridElement,e=[...this.columns];if(!y(e))return w(t),void(this.isApplied=!1);queueMicrotask(()=>{const n=b(t,e);this.#n=n.groupEndAdjustments,this.leftOffsets=n.leftOffsets,this.rightOffsets=n.rightOffsets,this.#s=n.splitGroups,this.#o()})}afterCellRender(n){if(!this.isApplied)return;const s=n.column.field,i=n.cellElement,r=this.leftOffsets.get(s);if(void 0!==r)i.classList.contains(t)||i.classList.add(t),i.style.position="sticky",i.style.left=r+"px";else{const t=this.rightOffsets.get(s);void 0!==t&&(i.classList.contains(e)||i.classList.add(e),i.style.position="sticky",i.style.right=t+"px")}this.#n.addGroupEnd.has(s)?n.cellElement.classList.add("group-end"):this.#n.removeGroupEnd.has(s)&&n.cellElement.classList.remove("group-end")}onScroll(t){this.#o()}#o(){if(!this.isApplied||0===this.#s.length)return;const t=this.gridElement;for(const e of this.#s){const n=e.pinnedFragment.getBoundingClientRect(),s=e.scrollableFragment.getBoundingClientRect().right<=n.right;if(s&&!e.isTransferred?(e.pinnedFragment.textContent=e.label,e.pinnedFragment.style.overflow="hidden",e.pinnedFragment.style.textOverflow="ellipsis",e.pinnedFragment.style.whiteSpace="nowrap",e.pinnedFragment.style.borderRightStyle="",e.floatLabel.style.visibility="hidden",e.floatLabel.style.transform="",e.floatOffset=0,this.#n.addGroupEnd.add(e.pinnedField),t.querySelectorAll(`.header-row .cell[data-field="${e.pinnedField}"], .data-grid-row .cell[data-field="${e.pinnedField}"]`).forEach(t=>t.classList.add("group-end")),e.isTransferred=!0):!s&&e.isTransferred&&(e.pinnedFragment.textContent="",e.pinnedFragment.style.overflow="",e.pinnedFragment.style.textOverflow="",e.pinnedFragment.style.whiteSpace="",e.pinnedFragment.style.borderRightStyle="none",e.floatLabel.style.visibility="",e.floatLabel.style.transform="",e.floatOffset=0,this.#n.addGroupEnd.delete(e.pinnedField),t.querySelectorAll(`.header-row .cell[data-field="${e.pinnedField}"], .data-grid-row .cell[data-field="${e.pinnedField}"]`).forEach(t=>t.classList.remove("group-end")),e.isTransferred=!1),!e.isTransferred){const t=e.floatLabel.getBoundingClientRect().left-e.floatOffset,s=n.left;t<s?(e.floatOffset=s-t,e.floatLabel.style.transform=`translateX(${e.floatOffset}px)`):(e.floatOffset=0,e.floatLabel.style.transform="")}}}handleQuery(t){switch(t.type){case A:return null==h(t.context)&&void 0;case"getStickyOffsets":return{left:Object.fromEntries(this.leftOffsets),right:Object.fromEntries(this.rightOffsets)};case"getContextMenuItems":{const e=t.context;if(!e.isHeader)return;const n=e.column;if(!n?.field)return;if(n.lockPinning||n.meta?.lockPinning)return;const s=[];return null!=h(n)?s.push({id:"pinned/unpin",label:this.t("pinnedColumns.unpin","Unpin Column"),icon:"📌",order:40,action:()=>this.setPinPosition(n.field,void 0)}):(s.push({id:"pinned/pin-left",label:this.t("pinnedColumns.pinLeft","Pin Left"),icon:"⬅",order:40,action:()=>this.setPinPosition(n.field,"left")}),s.push({id:"pinned/pin-right",label:this.t("pinnedColumns.pinRight","Pin Right"),icon:"➡",order:41,action:()=>this.setPinPosition(n.field,"right")})),s}default:return}}setPinPosition(t,e){const n=this.columns;if(!n?.length)return;const s=n.findIndex(e=>e.field===t);if(-1===s)return;const i=this.gridElement;if(e)0===this.#i.length&&(this.#i=n.map(t=>t.field)),i.columns=n.map(n=>{if(n.field!==t)return n;const s={...n};return s.pinned=e,s});else{const e={...n[s]};delete e.pinned;const r=[...n];r.splice(s,1);const o=this.#i.indexOf(t);if(o>=0){let t=r.length;for(let e=0;e<r.length;e++)if(!h(r[e])&&this.#i.indexOf(r[e].field)>o){t=e;break}r.splice(t,0,e)}else r.splice(Math.min(s,r.length),0,e);r.some(t=>null!=h(t))||(this.#i=[]),i.columns=r}}refreshStickyOffsets(){const t=[...this.columns],e=b(this.gridElement,t);this.#n=e.groupEndAdjustments,this.leftOffsets=e.leftOffsets,this.rightOffsets=e.rightOffsets,this.#s=e.splitGroups}getLeftPinnedColumns(){return function(t,e="ltr"){return t.filter(t=>g(t,e))}([...this.columns],n(this.gridElement))}getRightPinnedColumns(){return function(t,e="ltr"){return t.filter(t=>m(t,e))}([...this.columns],n(this.gridElement))}clearStickyPositions(){w(this.gridElement)}getHorizontalScrollOffsets(n,s){if(!this.isApplied)return;let i=0,r=0;if(n){const s=n.querySelectorAll(`.${t}`),o=n.querySelectorAll(`.${e}`);s.forEach(t=>{i+=t.offsetWidth}),o.forEach(t=>{r+=t.offsetWidth})}else this.gridElement.querySelectorAll(".header-row .cell").forEach(n=>{n.classList.contains(t)?i+=n.offsetWidth:n.classList.contains(e)&&(r+=n.offsetWidth)});const o=s?.classList.contains(t)||s?.classList.contains(e);return{left:i,right:r,skipScroll:o}}};export{S as PinnedColumnsPlugin};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- var e=/* @__PURE__ */new WeakMap;function t(e){return"__proto__"===e||"constructor"===e||"prototype"===e}var r=/* @__PURE__ */new Map;function n(e,n){if(null==e)return;const o=function(e){if(-1===e.indexOf("."))return null;let t=r.get(e);return void 0===t&&(t=Object.freeze(e.split(".")),r.set(e,t)),t}(n),i=e;return null===o?t(n)?void 0:i[n]:Object.prototype.hasOwnProperty.call(i,n)?i[n]:function(e,r){let n=e;for(let o=0;o<r.length;o++){if(null==n||"object"!=typeof n)return;const e=r[o];if(t(e))return;n=n[e]}return n}(i,o)}function o(t,r,o){return o?.valueAccessor?function(t,r,o=-1){if(!r.valueAccessor)return n(t,r.field);if("object"!=typeof t||null===t)return r.valueAccessor({row:t,column:r,rowIndex:o});const i=t,s=r.field;let a=e.get(i);if(a){const e=a.get(s);if(void 0!==e)return e.v}else a=/* @__PURE__ */new Map,e.set(i,a);const l=r.valueAccessor({row:t,column:r,rowIndex:o});return a.set(s,{v:l}),l}(t,o):n(t,r)}function i(e){return null==e||""===e||"number"==typeof e&&isNaN(e)}var s={sum:(e,t,r)=>{let n=0;for(let s=0;s<e.length;s++){const a=o(e[s],t,r);if(i(a))continue;const l=Number(a);isNaN(l)||(n+=l)}return n},avg:(e,t,r)=>{if(!e.length)return 0;let n=0,s=0;for(let a=0;a<e.length;a++){const l=o(e[a],t,r);if(i(l))continue;const c=Number(l);isNaN(c)||(n+=c,s++)}return s>0?n/s:0},count:e=>e.length,min:(e,t,r)=>{if(!e.length)return 0;let n=1/0;for(let s=0;s<e.length;s++){const a=o(e[s],t,r);if(i(a))continue;const l=Number(a);isNaN(l)||l<n&&(n=l)}return n===1/0?0:n},max:(e,t,r)=>{if(!e.length)return 0;let n=-1/0;for(let s=0;s<e.length;s++){const a=o(e[s],t,r);if(i(a))continue;const l=Number(a);isNaN(l)||l>n&&(n=l)}return n===-1/0?0:n},first:(e,t,r)=>e[0]?o(e[0],t,r):void 0,last:(e,t,r)=>e.length?o(e[e.length-1],t,r):void 0},a=/* @__PURE__ */new Map,l={register(e,t){a.set(e,t)},unregister(e){a.delete(e)},get(e){if(void 0!==e)return"function"==typeof e?e:a.get(e)??s[e]},run(e,t,r,n){const o=this.get(e);return o?o(t,r,n):void 0},has:e=>a.has(e)||e in s,list:()=>[...Object.keys(s),...a.keys()]};function c(e,t,r,n){const o=document.createElement("div");o.className="tbw-aggregation-cell tbw-aggregation-cell-full",o.style.gridColumn="1 / -1";const i="function"==typeof t.label?t.label(n,r):t.label;if(i){const e=document.createElement("span");e.className="tbw-aggregation-label",e.textContent=i,o.appendChild(e)}const s=function(e,t,r){const n=e.aggregators&&Object.keys(e.aggregators).length>0,o=e.cells&&Object.keys(e.cells).length>0;if(!n&&!o)return null;const i=document.createElement("span");i.className="tbw-aggregation-aggregates";for(const s of t){const{value:t,formatter:n}=g(e,s,r);if(null!=t){const e=document.createElement("span");e.className="tbw-aggregation-aggregate",e.setAttribute("data-field",s.field),e.textContent=`${s.header??s.field}: ${n?n(t,s.field,s):String(t)}`,i.appendChild(e)}}return i.children.length>0?i:null}(t,r,n);s&&o.appendChild(s),e.appendChild(o)}function d(e,t,r,n){for(const i of r){const r=document.createElement("div");r.className="tbw-aggregation-cell",r.setAttribute("data-field",i.field);const{value:o,formatter:s}=g(t,i,n);r.textContent=null!=o?s?s(o,i.field,i):String(o):"",e.appendChild(r)}const o="function"==typeof t.label?t.label(n,r):t.label;if(o){const t=document.createElement("span");t.className="tbw-aggregation-label",t.textContent=o,e.appendChild(t)}}function g(e,t,r){let n,o;const i=e.aggregators?.[t.field];if(i)if("object"==typeof(s=i)&&null!==s&&"aggFunc"in s){const e=l.get(i.aggFunc);e&&(n=e(r,t.field,t)),o=i.formatter}else{const e=l.get(i);e&&(n=e(r,t.field,t))}else if(e.cells&&Object.prototype.hasOwnProperty.call(e.cells,t.field)){const o=e.cells[t.field];n="function"==typeof o?o(r,t.field,t):o}var s;return{value:n,formatter:o}}function u(e,t,r,n,o){const i=r?.sourceRows,s=r?.rows,a=Array.isArray(i)?i.length:e.length,l=Array.isArray(s)?s.length:e.length,c=a>0?a:l;return{totalRows:c,filteredRows:o?.cachedResult?.length??(l<a?l:c),selectedRows:n?.selected?.size??0,columns:t,rows:e,grid:r}}function p(){return e=>{const t=document.createElement("span");return t.className="tbw-status-panel tbw-status-panel-row-count",t.textContent=`Total: ${e.totalRows} rows`,t}}function f(){return e=>{if(e.selectedRows<=0)return null;const t=document.createElement("span");return t.className="tbw-status-panel tbw-status-panel-selected-count",t.textContent=`Selected: ${e.selectedRows}`,t}}function h(){return e=>{if(e.filteredRows===e.totalRows)return null;const t=document.createElement("span");return t.className="tbw-status-panel tbw-status-panel-filtered-count",t.textContent=`Filtered: ${e.filteredRows}`,t}}function b(e){const t=document.createElement("div");return t.className="tbw-status-panel tbw-status-panel-custom",t.appendChild(e),t}var m=/* @__PURE__ */new WeakMap;function w(e,t,r){const n=Array.isArray(e.render)?e.render:[{zone:"left",render:e.render}],o=n.map(e=>e.render(t)??null);if(r){const e=m.get(r);if(e&&e.length===o.length&&e.every((e,t)=>e===o[t]))return r}const i=document.createElement("div");i.className="tbw-pinned-rows",i.setAttribute("role","presentation"),i.setAttribute("aria-live","polite"),e.id&&i.setAttribute("data-pinned-row-id",e.id);const s=document.createElement("div");s.className="tbw-pinned-rows-left";const a=document.createElement("div");a.className="tbw-pinned-rows-center";const l=document.createElement("div");l.className="tbw-pinned-rows-right";const c={left:s,center:a,right:l};for(let d=0;d<n.length;d++){const e=n[d],t=o[d];if(null==t)continue;const r=e.zone??"left",i=t.classList?.contains("tbw-status-panel");c[r].appendChild(i?t:b(t))}return 0===s.children.length&&0===a.children.length&&0===l.children.length?null:(i.appendChild(s),i.appendChild(a),i.appendChild(l),m.set(i,o),i)}function v(e,t,r,n,o=!1){const i=function(e){const t=document.createElement("div");return t.className=`tbw-aggregation-rows tbw-aggregation-rows-${e}`,t.setAttribute("role","presentation"),t}(t);return function(e,t,r,n,o=!1){e.innerHTML="";for(const i of t){const t=document.createElement("div");t.className="tbw-aggregation-row",t.setAttribute("role","presentation"),i.id&&t.setAttribute("data-aggregation-id",i.id),i.fullWidth??o?c(t,i,r,n):d(t,i,r,n),e.appendChild(t)}}(i,[e],r,n,o),i}function y(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function C(e,t,r,n){return`${y(r,n)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var x="__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("")),E=(new RegExp(`__(proto|defineGetter|defineSetter)|${x.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("|"))),W=/^on\w+$/i,S=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),N=/^\s*(javascript|vbscript|data|blob):/i;function A(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const n of r){const e=n.tagName.toLowerCase();if(E.has(e)){t.push(n);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===n.namespaceURI)&&Array.from(n.attributes).some(e=>W.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(n);continue}const r=[];for(const t of n.attributes){const e=t.name.toLowerCase();W.test(e)?r.push(t.name):"is"!==e?(S.has(e)&&N.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=>n.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}var R={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var k=class{static dependencies;static manifest;aliases;version="3.5.2";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},r={};for(const n of Object.keys(t))r[n]=this;for(const n of e){const e=n.userConfig;for(const[o,i]of Object.entries(e)){if(void 0===i)continue;if(!(o in t)){t[o]=i,r[o]=n;continue}if(t[o]===i)continue;const e=r[o]?.constructor.name??this.constructor.name,s=n.constructor.name,a=C("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${e} and ${s}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const n of Object.keys(t))delete t[n];Object.assign(t,r)}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const r=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(r),r.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}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{...R,...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 n=this.#t(t,r);var o,i;void 0!==n?"string"==typeof n?(o=e,(i=n)&&"string"==typeof i?-1!==i.indexOf("<")||-1!==i.indexOf("&")?o.replaceChildren(A(i)):o.textContent=i:o.replaceChildren()):n instanceof HTMLElement&&e.replaceChildren(n.cloneNode(!0)):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const r=document.createElement("span");r.setAttribute("part","sort-indicator"),r.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(r,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(r,"sortNone"));const n=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return n?e.insertBefore(r,n):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(C(e,t,this.gridElement.id,this.name)):console.warn(`${y(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(C(e,t,this.gridElement.id,this.name))}},j=class extends k{name="pinnedRows";styles="@layer tbw-plugins{.tbw-scroll-area{container-type:inline-size}.tbw-footer,.tbw-header-pinned{z-index:var(--tbw-z-layer-pinned-rows,20);background:var(--tbw-color-panel-bg);flex-shrink:0;min-width:fit-content}.tbw-pinned-rows{padding:var(--tbw-button-padding,var(--tbw-spacing-md,.5rem) var(--tbw-spacing-lg,.75rem));background:var(--tbw-pinned-rows-bg,var(--tbw-color-panel-bg));border-top:1px solid var(--tbw-pinned-rows-border,var(--tbw-color-border));font-size:var(--tbw-font-size-xs,.75rem);color:var(--tbw-pinned-rows-color,var(--tbw-color-fg-muted));box-sizing:border-box;justify-content:space-between;align-items:center;width:100cqi;min-width:0;min-height:32px;display:flex;position:sticky;left:0}.tbw-pinned-rows+.tbw-pinned-rows{border-top:0}.tbw-pinned-rows-left,.tbw-pinned-rows-center,.tbw-pinned-rows-right{align-items:center;gap:var(--tbw-spacing-xl,1rem);display:flex}.tbw-pinned-rows-left{justify-content:flex-start}.tbw-pinned-rows-center{flex:1;justify-content:center}.tbw-pinned-rows-right{justify-content:flex-end}.tbw-status-panel{white-space:nowrap}.tbw-aggregation-rows{background:var(--tbw-aggregation-bg,var(--tbw-color-header-bg));min-width:fit-content}.tbw-aggregation-rows-top{border-bottom:1px solid var(--tbw-aggregation-border,var(--tbw-color-border))}.tbw-aggregation-rows-bottom{border-top:1px solid var(--tbw-aggregation-border,var(--tbw-color-border))}.tbw-aggregation-row{grid-template-columns:var(--tbw-column-template);font-size:var(--tbw-aggregation-font-size,.8em);font-weight:var(--tbw-aggregation-font-weight,600);background:inherit;display:grid;position:relative}.tbw-aggregation-row>.tbw-aggregation-label{padding:var(--tbw-cell-padding,.125rem .5rem);background:inherit;z-index:1;pointer-events:none;grid-area:1/1;align-items:center;display:flex;position:sticky;left:0}.tbw-aggregation-row>.tbw-aggregation-cell:first-child{grid-area:1/1}.tbw-aggregation-cell:not(:empty){z-index:2;background:inherit;position:relative}.tbw-aggregation-cell{padding:var(--tbw-cell-padding,.125rem .5rem);min-height:var(--tbw-row-height,1.75rem);border-right:1px solid var(--tbw-color-border-cell);text-overflow:ellipsis;white-space:var(--tbw-cell-white-space,nowrap);align-content:center;align-items:center;display:block;overflow:hidden}.tbw-aggregation-cell:last-child{border-right:0}.tbw-aggregation-cell-full{align-items:center;gap:var(--tbw-spacing-lg,.75rem);border-right:0;grid-column:1/-1;display:flex}.tbw-aggregation-label{white-space:nowrap}.tbw-aggregation-aggregates{align-items:center;gap:var(--tbw-spacing-lg,.75rem);opacity:.85;font-weight:400;display:flex}.tbw-aggregation-aggregate{white-space:nowrap}}";get defaultConfig(){return{slots:[{position:"bottom",render:[{zone:"left",render:p()},{zone:"left",render:h()},{zone:"right",render:f()}]}]}}footerWrapper=null;headerWrapper=null;detach(){this.cleanup()}afterRender(){const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.querySelector(".tbw-grid-root");if(!t)return;this.footerWrapper&&!t.contains(this.footerWrapper)&&(this.footerWrapper=null),this.headerWrapper&&!t.contains(this.headerWrapper)&&(this.headerWrapper=null);const r=this.getSelectionState(),n=this.getFilterState(),o=u(this.sourceRows,this.columns,this.gridElement,r,n);this.renderSlotMode(t,e,o)}renderSlotMode(e,t,r){const n=this.config.slots??[],o=n.filter(e=>"top"===e.position),i=n.filter(e=>"top"!==e.position);o.length>0?(this.headerWrapper||(this.headerWrapper=document.createElement("div"),this.headerWrapper.className="tbw-header-pinned",e.insertBefore(this.headerWrapper,e.firstChild)),this.populateSlotWrapper(this.headerWrapper,o,"top",r)):this.headerWrapper&&(this.headerWrapper.remove(),this.headerWrapper=null),i.length>0?(this.footerWrapper||(this.footerWrapper=document.createElement("div"),this.footerWrapper.className="tbw-footer",e.appendChild(this.footerWrapper)),this.populateSlotWrapper(this.footerWrapper,i,"bottom",r)):this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null)}populateSlotWrapper(e,t,r,n){const o=/* @__PURE__ */new Map;for(let a=0;a<e.children.length;a++){const t=e.children[a],r=t.getAttribute("data-pinned-row-id");r&&o.set(r,t)}const i=[];for(const a of t){const e="render"in a&&null!=a.render?w(a,n,a.id?o.get(a.id)??null:null):v(a,r,this.visibleColumns,this.sourceRows,this.config.fullWidth);e&&i.push(e)}const s=e.children;if(s.length===i.length){let e=!0;for(let t=0;t<i.length;t++)if(s[t]!==i[t]){e=!1;break}if(e)return}e.replaceChildren(...i)}cleanup(){this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null),this.headerWrapper&&(this.headerWrapper.remove(),this.headerWrapper=null)}getSelectionState(){try{return this.grid?.getPluginState?.("selection")??null}catch{return null}}getFilterState(){try{return this.grid?.getPluginState?.("filtering")??null}catch{return null}}refresh(){this.requestRender()}getContext(){const e=this.getSelectionState(),t=this.getFilterState();return u(this.rows,this.columns,this.gridElement,e,t)}};export{j as PinnedRowsPlugin,h as filteredCountPanel,p as rowCountPanel,f as selectedCountPanel};
1
+ var e=/* @__PURE__ */new WeakMap;function t(e){return"__proto__"===e||"constructor"===e||"prototype"===e}var r=/* @__PURE__ */new Map;function n(e,n){if(null==e)return;const o=function(e){if(-1===e.indexOf("."))return null;let t=r.get(e);return void 0===t&&(t=Object.freeze(e.split(".")),r.set(e,t)),t}(n),i=e;return null===o?t(n)?void 0:i[n]:Object.prototype.hasOwnProperty.call(i,n)?i[n]:function(e,r){let n=e;for(let o=0;o<r.length;o++){if(null==n||"object"!=typeof n)return;const e=r[o];if(t(e))return;n=n[e]}return n}(i,o)}function o(t,r,o){return o?.valueAccessor?function(t,r,o=-1){if(!r.valueAccessor)return n(t,r.field);if("object"!=typeof t||null===t)return r.valueAccessor({row:t,column:r,rowIndex:o});const i=t,s=r.field;let a=e.get(i);if(a){const e=a.get(s);if(void 0!==e)return e.v}else a=/* @__PURE__ */new Map,e.set(i,a);const l=r.valueAccessor({row:t,column:r,rowIndex:o});return a.set(s,{v:l}),l}(t,o):n(t,r)}function i(e){return null==e||""===e||"number"==typeof e&&isNaN(e)}var s={sum:(e,t,r)=>{let n=0;for(let s=0;s<e.length;s++){const a=o(e[s],t,r);if(i(a))continue;const l=Number(a);isNaN(l)||(n+=l)}return n},avg:(e,t,r)=>{if(!e.length)return 0;let n=0,s=0;for(let a=0;a<e.length;a++){const l=o(e[a],t,r);if(i(l))continue;const c=Number(l);isNaN(c)||(n+=c,s++)}return s>0?n/s:0},count:e=>e.length,min:(e,t,r)=>{if(!e.length)return 0;let n=1/0;for(let s=0;s<e.length;s++){const a=o(e[s],t,r);if(i(a))continue;const l=Number(a);isNaN(l)||l<n&&(n=l)}return n===1/0?0:n},max:(e,t,r)=>{if(!e.length)return 0;let n=-1/0;for(let s=0;s<e.length;s++){const a=o(e[s],t,r);if(i(a))continue;const l=Number(a);isNaN(l)||l>n&&(n=l)}return n===-1/0?0:n},first:(e,t,r)=>e[0]?o(e[0],t,r):void 0,last:(e,t,r)=>e.length?o(e[e.length-1],t,r):void 0},a=/* @__PURE__ */new Map,l={register(e,t){a.set(e,t)},unregister(e){a.delete(e)},get(e){if(void 0!==e)return"function"==typeof e?e:a.get(e)??s[e]},run(e,t,r,n){const o=this.get(e);return o?o(t,r,n):void 0},has:e=>a.has(e)||e in s,list:()=>[...Object.keys(s),...a.keys()]};function c(e,t,r,n){const o=document.createElement("div");o.className="tbw-aggregation-cell tbw-aggregation-cell-full",o.style.gridColumn="1 / -1";const i="function"==typeof t.label?t.label(n,r):t.label;if(i){const e=document.createElement("span");e.className="tbw-aggregation-label",e.textContent=i,o.appendChild(e)}const s=function(e,t,r){const n=e.aggregators&&Object.keys(e.aggregators).length>0,o=e.cells&&Object.keys(e.cells).length>0;if(!n&&!o)return null;const i=document.createElement("span");i.className="tbw-aggregation-aggregates";for(const s of t){const{value:t,formatter:n}=g(e,s,r);if(null!=t){const e=document.createElement("span");e.className="tbw-aggregation-aggregate",e.setAttribute("data-field",s.field),e.textContent=`${s.header??s.field}: ${n?n(t,s.field,s):String(t)}`,i.appendChild(e)}}return i.children.length>0?i:null}(t,r,n);s&&o.appendChild(s),e.appendChild(o)}function d(e,t,r,n){for(const i of r){const r=document.createElement("div");r.className="tbw-aggregation-cell",r.setAttribute("data-field",i.field);const{value:o,formatter:s}=g(t,i,n);r.textContent=null!=o?s?s(o,i.field,i):String(o):"",e.appendChild(r)}const o="function"==typeof t.label?t.label(n,r):t.label;if(o){const t=document.createElement("span");t.className="tbw-aggregation-label",t.textContent=o,e.appendChild(t)}}function g(e,t,r){let n,o;const i=e.aggregators?.[t.field];if(i)if("object"==typeof(s=i)&&null!==s&&"aggFunc"in s){const e=l.get(i.aggFunc);e&&(n=e(r,t.field,t)),o=i.formatter}else{const e=l.get(i);e&&(n=e(r,t.field,t))}else if(e.cells&&Object.prototype.hasOwnProperty.call(e.cells,t.field)){const o=e.cells[t.field];n="function"==typeof o?o(r,t.field,t):o}var s;return{value:n,formatter:o}}function u(e,t,r,n,o){const i=r?.sourceRows,s=r?.rows,a=Array.isArray(i)?i.length:e.length,l=Array.isArray(s)?s.length:e.length,c=a>0?a:l;return{totalRows:c,filteredRows:o?.cachedResult?.length??(l<a?l:c),selectedRows:n?.selected?.size??0,columns:t,rows:e,grid:r}}function p(){return e=>{const t=document.createElement("span");return t.className="tbw-status-panel tbw-status-panel-row-count",t.textContent=`Total: ${e.totalRows} rows`,t}}function f(){return e=>{if(e.selectedRows<=0)return null;const t=document.createElement("span");return t.className="tbw-status-panel tbw-status-panel-selected-count",t.textContent=`Selected: ${e.selectedRows}`,t}}function h(){return e=>{if(e.filteredRows===e.totalRows)return null;const t=document.createElement("span");return t.className="tbw-status-panel tbw-status-panel-filtered-count",t.textContent=`Filtered: ${e.filteredRows}`,t}}function b(e){const t=document.createElement("div");return t.className="tbw-status-panel tbw-status-panel-custom",t.appendChild(e),t}var m=/* @__PURE__ */new WeakMap;function w(e,t,r){const n=Array.isArray(e.render)?e.render:[{zone:"left",render:e.render}],o=n.map(e=>e.render(t)??null);if(r){const e=m.get(r);if(e&&e.length===o.length&&e.every((e,t)=>e===o[t]))return r}const i=document.createElement("div");i.className="tbw-pinned-rows",i.setAttribute("role","presentation"),i.setAttribute("aria-live","polite"),e.id&&i.setAttribute("data-pinned-row-id",e.id);const s=document.createElement("div");s.className="tbw-pinned-rows-left";const a=document.createElement("div");a.className="tbw-pinned-rows-center";const l=document.createElement("div");l.className="tbw-pinned-rows-right";const c={left:s,center:a,right:l};for(let d=0;d<n.length;d++){const e=n[d],t=o[d];if(null==t)continue;const r=e.zone??"left",i=t.classList?.contains("tbw-status-panel");c[r].appendChild(i?t:b(t))}return 0===s.children.length&&0===a.children.length&&0===l.children.length?null:(i.appendChild(s),i.appendChild(a),i.appendChild(l),m.set(i,o),i)}function v(e,t,r,n,o=!1){const i=function(e){const t=document.createElement("div");return t.className=`tbw-aggregation-rows tbw-aggregation-rows-${e}`,t.setAttribute("role","presentation"),t}(t);return function(e,t,r,n,o=!1){e.innerHTML="";for(const i of t){const t=document.createElement("div");t.className="tbw-aggregation-row",t.setAttribute("role","presentation"),i.id&&t.setAttribute("data-aggregation-id",i.id),i.fullWidth??o?c(t,i,r,n):d(t,i,r,n),e.appendChild(t)}}(i,[e],r,n,o),i}function y(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function C(e,t,r,n){return`${y(r,n)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var x="__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("")),E=(new RegExp(`__(proto|defineGetter|defineSetter)|${x.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("|"))),W=/^on\w+$/i,S=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),N=/^\s*(javascript|vbscript|data|blob):/i;function A(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const n of r){const e=n.tagName.toLowerCase();if(E.has(e)){t.push(n);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===n.namespaceURI)&&Array.from(n.attributes).some(e=>W.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(n);continue}const r=[];for(const t of n.attributes){const e=t.name.toLowerCase();W.test(e)?r.push(t.name):"is"!==e?(S.has(e)&&N.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=>n.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}var R={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var k=class{static dependencies;static manifest;aliases;version="3.5.3";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},r={};for(const n of Object.keys(t))r[n]=this;for(const n of e){const e=n.userConfig;for(const[o,i]of Object.entries(e)){if(void 0===i)continue;if(!(o in t)){t[o]=i,r[o]=n;continue}if(t[o]===i)continue;const e=r[o]?.constructor.name??this.constructor.name,s=n.constructor.name,a=C("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${e} and ${s}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const n of Object.keys(t))delete t[n];Object.assign(t,r)}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const r=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(r),r.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}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{...R,...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 n=this.#t(t,r);var o,i;void 0!==n?"string"==typeof n?(o=e,(i=n)&&"string"==typeof i?-1!==i.indexOf("<")||-1!==i.indexOf("&")?o.replaceChildren(A(i)):o.textContent=i:o.replaceChildren()):n instanceof HTMLElement&&e.replaceChildren(n.cloneNode(!0)):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const r=document.createElement("span");r.setAttribute("part","sort-indicator"),r.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(r,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(r,"sortNone"));const n=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return n?e.insertBefore(r,n):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(C(e,t,this.gridElement.id,this.name)):console.warn(`${y(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(C(e,t,this.gridElement.id,this.name))}},j=class extends k{name="pinnedRows";styles="@layer tbw-plugins{.tbw-scroll-area{container-type:inline-size}.tbw-footer,.tbw-header-pinned{z-index:var(--tbw-z-layer-pinned-rows,20);background:var(--tbw-color-panel-bg);flex-shrink:0;min-width:fit-content}.tbw-pinned-rows{padding:var(--tbw-button-padding,var(--tbw-spacing-md,.5rem) var(--tbw-spacing-lg,.75rem));background:var(--tbw-pinned-rows-bg,var(--tbw-color-panel-bg));border-top:1px solid var(--tbw-pinned-rows-border,var(--tbw-color-border));font-size:var(--tbw-font-size-xs,.75rem);color:var(--tbw-pinned-rows-color,var(--tbw-color-fg-muted));box-sizing:border-box;justify-content:space-between;align-items:center;width:100cqi;min-width:0;min-height:32px;display:flex;position:sticky;left:0}.tbw-pinned-rows+.tbw-pinned-rows{border-top:0}.tbw-pinned-rows-left,.tbw-pinned-rows-center,.tbw-pinned-rows-right{align-items:center;gap:var(--tbw-spacing-xl,1rem);display:flex}.tbw-pinned-rows-left{justify-content:flex-start}.tbw-pinned-rows-center{flex:1;justify-content:center}.tbw-pinned-rows-right{justify-content:flex-end}.tbw-status-panel{white-space:nowrap}.tbw-aggregation-rows{background:var(--tbw-aggregation-bg,var(--tbw-color-header-bg));min-width:fit-content}.tbw-aggregation-rows-top{border-bottom:1px solid var(--tbw-aggregation-border,var(--tbw-color-border))}.tbw-aggregation-rows-bottom{border-top:1px solid var(--tbw-aggregation-border,var(--tbw-color-border))}.tbw-aggregation-row{grid-template-columns:var(--tbw-column-template);font-size:var(--tbw-aggregation-font-size,.8em);font-weight:var(--tbw-aggregation-font-weight,600);background:inherit;display:grid;position:relative}.tbw-aggregation-row>.tbw-aggregation-label{padding:var(--tbw-cell-padding,.125rem .5rem);background:inherit;z-index:1;pointer-events:none;grid-area:1/1;align-items:center;display:flex;position:sticky;left:0}.tbw-aggregation-row>.tbw-aggregation-cell:first-child{grid-area:1/1}.tbw-aggregation-cell:not(:empty){z-index:2;background:inherit;position:relative}.tbw-aggregation-cell{padding:var(--tbw-cell-padding,.125rem .5rem);min-height:var(--tbw-row-height,1.75rem);border-right:1px solid var(--tbw-color-border-cell);text-overflow:ellipsis;white-space:var(--tbw-cell-white-space,nowrap);align-content:center;align-items:center;display:block;overflow:hidden}.tbw-aggregation-cell:last-child{border-right:0}.tbw-aggregation-cell-full{align-items:center;gap:var(--tbw-spacing-lg,.75rem);border-right:0;grid-column:1/-1;display:flex}.tbw-aggregation-label{white-space:nowrap}.tbw-aggregation-aggregates{align-items:center;gap:var(--tbw-spacing-lg,.75rem);opacity:.85;font-weight:400;display:flex}.tbw-aggregation-aggregate{white-space:nowrap}}";get defaultConfig(){return{slots:[{position:"bottom",render:[{zone:"left",render:p()},{zone:"left",render:h()},{zone:"right",render:f()}]}]}}footerWrapper=null;headerWrapper=null;detach(){this.cleanup()}afterRender(){const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-scroll-area")??e.querySelector(".tbw-grid-content")??e.querySelector(".tbw-grid-root");if(!t)return;this.footerWrapper&&!t.contains(this.footerWrapper)&&(this.footerWrapper=null),this.headerWrapper&&!t.contains(this.headerWrapper)&&(this.headerWrapper=null);const r=this.getSelectionState(),n=this.getFilterState(),o=u(this.sourceRows,this.columns,this.gridElement,r,n);this.renderSlotMode(t,e,o)}renderSlotMode(e,t,r){const n=this.config.slots??[],o=n.filter(e=>"top"===e.position),i=n.filter(e=>"top"!==e.position);o.length>0?(this.headerWrapper||(this.headerWrapper=document.createElement("div"),this.headerWrapper.className="tbw-header-pinned",e.insertBefore(this.headerWrapper,e.firstChild)),this.populateSlotWrapper(this.headerWrapper,o,"top",r)):this.headerWrapper&&(this.headerWrapper.remove(),this.headerWrapper=null),i.length>0?(this.footerWrapper||(this.footerWrapper=document.createElement("div"),this.footerWrapper.className="tbw-footer",e.appendChild(this.footerWrapper)),this.populateSlotWrapper(this.footerWrapper,i,"bottom",r)):this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null)}populateSlotWrapper(e,t,r,n){const o=/* @__PURE__ */new Map;for(let a=0;a<e.children.length;a++){const t=e.children[a],r=t.getAttribute("data-pinned-row-id");r&&o.set(r,t)}const i=[];for(const a of t){const e="render"in a&&null!=a.render?w(a,n,a.id?o.get(a.id)??null:null):v(a,r,this.visibleColumns,this.sourceRows,this.config.fullWidth);e&&i.push(e)}const s=e.children;if(s.length===i.length){let e=!0;for(let t=0;t<i.length;t++)if(s[t]!==i[t]){e=!1;break}if(e)return}e.replaceChildren(...i)}cleanup(){this.footerWrapper&&(this.footerWrapper.remove(),this.footerWrapper=null),this.headerWrapper&&(this.headerWrapper.remove(),this.headerWrapper=null)}getSelectionState(){try{return this.grid?.getPluginState?.("selection")??null}catch{return null}}getFilterState(){try{return this.grid?.getPluginState?.("filtering")??null}catch{return null}}refresh(){this.requestRender()}getContext(){const e=this.getSelectionState(),t=this.getFilterState();return u(this.rows,this.columns,this.gridElement,e,t)}};export{j as PinnedRowsPlugin,h as filteredCountPanel,p as rowCountPanel,f as selectedCountPanel};
2
2
  //# sourceMappingURL=index.js.map