@toolbox-web/grid 3.10.0 → 3.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/all.js +1 -1
  2. package/all.js.map +1 -1
  3. package/index.js +1 -1
  4. package/lib/features/registry.js +1 -1
  5. package/lib/plugins/editing/index.js +1 -1
  6. package/lib/plugins/editing/index.js.map +1 -1
  7. package/lib/plugins/editing/internal/helpers.d.ts +23 -0
  8. package/lib/plugins/editing/types.d.ts +11 -0
  9. package/lib/plugins/grouping-rows/index.js +1 -1
  10. package/lib/plugins/grouping-rows/index.js.map +1 -1
  11. package/lib/plugins/master-detail/index.js +1 -1
  12. package/lib/plugins/master-detail/index.js.map +1 -1
  13. package/lib/plugins/master-detail/master-detail-plugin.d.ts +6 -1
  14. package/lib/plugins/shared/structural-toggle.d.ts +14 -0
  15. package/lib/plugins/tree/index.js +1 -1
  16. package/lib/plugins/tree/index.js.map +1 -1
  17. package/lib/plugins/undo-redo/index.d.ts +1 -1
  18. package/lib/plugins/undo-redo/index.js +1 -1
  19. package/lib/plugins/undo-redo/index.js.map +1 -1
  20. package/lib/plugins/undo-redo/types.d.ts +20 -2
  21. package/lib/plugins/undo-redo/undo-redo-plugin.d.ts +8 -0
  22. package/package.json +1 -1
  23. package/umd/grid.all.umd.js +1 -1
  24. package/umd/grid.all.umd.js.map +1 -1
  25. package/umd/grid.umd.js +1 -1
  26. package/umd/plugins/editing.umd.js +1 -1
  27. package/umd/plugins/editing.umd.js.map +1 -1
  28. package/umd/plugins/grouping-rows.umd.js +1 -1
  29. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  30. package/umd/plugins/master-detail.umd.js +1 -1
  31. package/umd/plugins/master-detail.umd.js.map +1 -1
  32. package/umd/plugins/tree.umd.js +1 -1
  33. package/umd/plugins/tree.umd.js.map +1 -1
  34. package/umd/plugins/undo-redo.umd.js +1 -1
  35. package/umd/plugins/undo-redo.umd.js.map +1 -1
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@toolbox-web/grid")):"function"==typeof define&&define.amd?define(["exports","@toolbox-web/grid"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGridPlugin_groupingRows={},e.TbwGrid)}(this,function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});var r="expanded",o="group-toggle",n="group-label",s="group-count";function i(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 a(e,r,...o){const n=(e&&"effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.messages?.[r];return n?n(...o):t.DEFAULT_A11Y_MESSAGES[r](...o)}var d="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(e=>e.split("").reverse().join("")),u=(new RegExp(`__(proto|defineGetter|defineSetter)|${d.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("|"))),p=/^on\w+$/i,l=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),h=/^\s*(javascript|vbscript|data|blob):/i;function c(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(u.has(e)){t.push(o);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(e=>p.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();p.test(e)?r.push(t.name):"is"!==e?(l.has(e)&&h.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 g(e,t){t&&"string"==typeof t?-1!==t.indexOf("<")||-1!==t.indexOf("&")?e.replaceChildren(c(t)):e.textContent=t:e.replaceChildren()}function f(e,t){if(t){const r=t({size:e});if("string"==typeof r){const e=document.createElement("div");return g(e,r),e}return r}return function(e){const t=document.createElement("div");return t.className=`tbw-spinner tbw-spinner--${e}`,t.setAttribute("role","progressbar"),t.setAttribute("aria-label","Loading"),t}(e)}function w(e,t){if(!e.firstElementChild)return;const r=e.querySelector(":scope > .tbw-cell-loading-overlay");r&&(t?.unmount?.(r),r.remove())}function y(e,t){if(!e.firstElementChild)return;const r=e.querySelector(":scope > .tbw-row-loading-overlay");r&&(t?.unmount?.(r),r.remove())}function m(e,t,r,o){const n=t;if(function(e,t,r,o){const{style:n}=t;n.getPropertyValue("--tbw-row-height")&&n.removeProperty("--tbw-row-height");const s=e._getPluginRowHeight?.(r,o),i=void 0!==s&&s>0?`${s}px`:"";n.height!==i&&(n.height=i)}(e,n,r,o),n.__rowDataRef===r&&n.__isCustomRow&&n.classList.contains("tbw-row-loading"))return;!function(e,t){t.classList.remove("tbw-row-loading"),t.removeAttribute("aria-busy");const r=e.__frameworkAdapter;if(r?.releaseCell||r?.unmount){r.beginBatch?.(e);try{y(t,r);const e=t.children;for(let t=e.length-1;t>=0;t--){const o=e[t];w(o,r),r.releaseCell?.(o)}t.innerHTML=""}finally{r.endBatch?.(e)}}else t.innerHTML=""}(e,n),n.className="data-grid-row placeholder-row",n.__isCustomRow=!0;const s=document.createElement("div");s.className="cell",s.style.gridColumn="1 / -1",s.setAttribute("role","gridcell"),s.textContent=" ",n.appendChild(s),function(e,t,r,o){if(t){if(e.classList.add("tbw-row-loading"),e.setAttribute("aria-busy","true"),!e.querySelector(":scope > .tbw-row-loading-overlay")){const t=document.createElement("div");if(t.className="tbw-row-loading-overlay",t.setAttribute("aria-hidden","true"),r)t.appendChild(f("small",r));else{const e=document.createElement("div");e.className="tbw-row-loading-spinner",t.appendChild(e)}e.appendChild(t)}}else e.classList.remove("tbw-row-loading"),e.removeAttribute("aria-busy"),y(e,o)}(n,!0,e.effectiveConfig?.loadingRenderer)}function v(e,t,r=new WeakMap){const o=[];for(const p of["structure","transform"])for(const r of t)r.hierarchyStage===p&&r.beginHierarchy(e)&&o.push(r);if(0===o.length)return[...e];const n=[],s=(e,t,r)=>{const n={parent:t?t.row:null,parentKey:t?.key??null,depth:r};for(const s of o)e=s.processSiblings(e,n);return e},i=(e,t)=>{const o=e.length;for(let a=0;a<o;a++){const d=e[a];n.push(d.row),"object"==typeof d.row&&null!==d.row&&r.set(d.row,{level:t+1,setSize:o,posInSet:a+1});const u=d.children;d.expanded&&u&&i(d.shaped?u:s(u,d,t+1),t+1)}},a=new Array(e.length);for(let p=0;p<e.length;p++)a[p]={row:e[p]};i(s(a,null,0),0);const d=e=>"object"==typeof e&&null!==e?r.get(e):void 0;let u=!1;for(const p of o)p.endHierarchy(n,d)&&(u=!0);if(!u)for(const p of n)"object"==typeof p&&null!==p&&r.delete(p);return n}function b(e,t,r){const o=String(r);e.getAttribute(t)!==o&&e.setAttribute(t,o)}function x(e){return"function"==typeof e.processSiblings}function _(e){return e.constructor.manifest?.hookPriority?.processRows??0}var R=class extends t.BaseGridPlugin{static manifest={modifiesRowStructure:!0};name="hierarchy";#e=new WeakMap;detach(){this.gridElement?.querySelector(".rows-body")?.setAttribute("role","grid"),this.#e=new WeakMap}process(e,t){const r=this.#t();return r.includes(t)?r[r.length-1]!==t?e:(this.#e=new WeakMap,v(e,r,this.#e)):(this.#e=new WeakMap,v(e,[t],this.#e))}getRowMeta(e){return"object"==typeof e&&null!==e?this.#e.get(e):void 0}afterRender(){this.#r()}onScrollRender(){this.#r()}#t(){return(this.grid?._pluginManager?.getPlugins?.()??[]).filter(x).sort((e,t)=>_(e)-_(t))}#r(){if(0===this.#t().length)return;const e=this.gridElement?.querySelector(".rows");if(!e)return;let t=!1;for(const n of e.querySelectorAll(".data-grid-row")){const e=this.getRowMeta(n.__rowDataRef);e?(t=!0,b(n,"aria-level",e.level),b(n,"aria-setsize",e.setSize),b(n,"aria-posinset",e.posInSet)):(n.removeAttribute("aria-level"),n.removeAttribute("aria-setsize"),n.removeAttribute("aria-posinset"))}const r=t?"treegrid":"grid",o=this.gridElement?.querySelector(".rows-body");o&&o.getAttribute("role")!==r&&o.setAttribute("role",r)}},G={parent:null,depth:0};function S(e,t){if(!0===e)return new Set(t);if(!1===e||null==e)return new Set;if("number"==typeof e){const r=t[e];return r?new Set([r]):new Set}return"string"==typeof e?new Set([e]):Array.isArray(e)?new Set(e):new Set}function k(e){return"group"!==e.kind?0:e.rows.length}function A({groups:e,expanded:t,groupRows:r,loadingGroups:o,parentPath:n=[]}){const s=[],i=n.length;for(const a of e){const e=[...n,a.key],d=t.has(a.key),u=r.get(a.key)??[],p=o.has(a.key);if(s.push({kind:"group",key:a.key,value:a.value,depth:i,rows:u,expanded:d}),d)if(a.children?.length){const n=A({groups:a.children,expanded:t,groupRows:r,loadingGroups:o,parentPath:e});s.push(...n)}else p?s.push({kind:"data",row:{__loading:!0,__groupKey:a.key,__rowCacheKey:`__loading:group:${a.key}`},rowIndex:-1}):u.forEach((e,t)=>{s.push({kind:"data",row:e,rowIndex:t})})}return s}function E(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=E(o.children,t,e);if(r.length>0)return r}}return[]}function K(e){const t=[];for(const r of e)t.push(r.key),r.children?.length&&t.push(...K(r.children));return t}function C(e,t){for(const r of e){if(r.key===t)return r;const e=r.children?.length?C(r.children,t):void 0;if(e)return e}}function q(e){const t=e;return null!=t&&"object"==typeof t&&!0===t.__loading&&"number"==typeof t.__index}var D=class extends t.BaseGridPlugin{static manifest={modifiesRowStructure:!0,hookPriority:{processRows:10,onHeaderClick:-1},incompatibleWith:[{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."},{type:"group-load-error",description:"Emitted when a pre-defined group's ServerSide getChildRows() fails. The group leaves its loading state."}],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:"hierarchy",required:!0,reason:"Builds the hierarchical row model",provide:()=>new R},{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";hierarchyStage="transform";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)}.group-toggle{position:relative}.group-toggle:after{content:"";inline-size:var(--tbw-touch-target-min,24px);block-size:var(--tbw-touch-target-min,24px);position:absolute;inset-block-start:50%;inset-inline-start:50%;translate:-50% -50%}@media (pointer:coarse){.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=new Set;flattenedRows=[];isActive=!1;previousVisibleKeys=new Set;keysToAnimate=new Set;hasAppliedDefaultExpanded=!1;pendingExpansion;groupConfigDirty=!1;preDefinedGroups=[];#o=[];#n=!1;#s;#i=new Set;groupRowsMap=new Map;loadingGroups=new Set;#a=new Map;#d=new Set;#u=!1;groupedFields=[];userGroupSortDirections=new Map;#p="groupOn";#l;#h=!1;#c;#g=!1;#f=new WeakMap;#w=new WeakMap;#y={owners:[],count:0};#m=!1;#v=new Set;get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}detach(){this.expandedKeys.clear(),this.flattenedRows=[],this.isActive=!1,this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.hasAppliedDefaultExpanded=!1,this.pendingExpansion=void 0,this.groupConfigDirty=!1,this.preDefinedGroups=[],this.#b(),this.#y={owners:[],count:0},this.groupRowsMap.clear(),this.#x(),this.#d.clear(),this.loadingGroups.clear(),this.groupedFields=[],this.userGroupSortDirections.clear(),this.#v.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||"predefined"!==this.#p)return;return function({owners:e,count:t},r,o){const n=e.length-1,s=t=>e[Math.max(0,Math.min(t,n))]??0;return{startNode:s(r),endNode:s(o)+1,totalLoadedNodes:t}}(this.#y,t,r)}}attach(e){super.attach(e),this.on("datasource:data",e=>{const t=e;if(t.claimed)return;t.claimed=!0;const r=t.rows;if(this.#n&&void 0!==t.generation&&t.generation===this.#s)return this.#_(r,t.startNode),void this.requestRender();const o=[...this.expandedKeys].filter(e=>this.groupRowsMap.has(e)||this.#a.has(e));this.#o=[],this.#n=void 0!==t.generation,this.#s=t.generation,this.hasAppliedDefaultExpanded||=this.expandedKeys.size>0,this.#_(r,this.#n?t.startNode:0),this.groupRowsMap.clear(),this.#x(),this.#d.clear(),this.loadingGroups.clear();for(const n of o){const e=C(this.preDefinedGroups,n);e&&this.#R(n,e,E(this.preDefinedGroups,n))}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.#a.delete(r),this.groupRowsMap.set(r,t.rows),this.loadingGroups.delete(r),this.requestRender())}),this.on("datasource:error",e=>{const t=e;if("grouping-rows"!==t.context?.source)return;const r=t.context.groupKey;r&&this.#a.delete(r)&&(this.loadingGroups.delete(r),this.emit("group-load-error",{groupKey:r,groupPath:t.context.groupPath??[r],error:t.error}),this.requestRender())})}#x(e){for(const[t,r]of this.#a)null!=e&&t!==e||(r.abort(),this.#a.delete(t),this.loadingGroups.delete(t))}#b(){this.#o=[],this.#n=!1,this.#s=void 0,this.#i.clear()}#_(e,t){const r=Number.isInteger(t)&&t>0?t:0;for(let n=0;n<e.length;n++)this.#o[r+n]=e[n];this.preDefinedGroups=this.#o.filter(e=>null!=e);const o=!0===this.config.defaultExpanded&&this.hasAppliedDefaultExpanded;for(const n of K(e))o&&!this.#i.has(n)&&this.expandedKeys.add(n),this.#i.add(n)}#R(e,t,r){if(this.#d.add(e),this.loadingGroups.add(e),this.#a.has(e))return;const o=this.queryBoolean("datasource:is-active")?new AbortController:void 0;o&&this.#a.set(e,o),this.grid?.query?.("datasource:fetch-children",{context:{source:"grouping-rows",groupKey:e,group:t,groupPath:r},signal:o?.signal})}#G(e){return"group"===e.kind&&e.expanded&&!this.groupRowsMap.has(e.key)&&!this.loadingGroups.has(e.key)&&!this.#d.has(e.key)}#S(){this.#u||(this.#u=!0,queueMicrotask(()=>{this.#u=!1,this.#k()}))}#k(){if(!this.isActive||"predefined"!==this.#p)return;const e=this.queryBoolean("datasource:is-active"),t=this.getActiveGroups();let r=!1;for(const o of this.flattenedRows){if(!this.#G(o))continue;const n=E(t,o.key);if(!n.every(e=>this.expandedKeys.has(e)))continue;const s=C(t,o.key);e&&s&&!s.children?.length?(this.#R(o.key,s,n),r=!0):this.#d.add(o.key)}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,t){const r=this.config;if("function"!=typeof r.groupOn||0===e.length)return void(this.groupedFields=[]);const o=this.columns.map(e=>e.field),n=function(e,t,r,o=G){const n=new Map;let s,i=null;for(const a of e)if(i=t(a,o),null!=i&&!1!==i){s=a;break}if(void 0===s)return n;Array.isArray(i)||(i=[i]);for(let a=0;a<i.length;a++){const e=i[a];for(const t of r)if(s[t]===e){n.set(a,t);break}}return n}([...e],r.groupOn,o,t);if(this.groupedFields=[...n.values()],0===n.size)return;const s=new Map(this.userGroupSortDirections);if(s.size<n.size){const e=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._sortState;t&&e.set(t.field,t.direction)}for(const[r,o]of n)if(!s.has(r)){const t=e.get(o);void 0!==t&&s.set(r,t)}}return s.size>0?s:void 0}static detect(e,t){return"function"==typeof t?.groupOn||"boolean"==typeof t?.enableRowGrouping||Array.isArray(t?.groups)}processRows(e){const t=this.grid?.getPluginByName?.("hierarchy");return t?t.process(e,this):v(e,[this])}beginHierarchy(e){return this.#l=this.pendingExpansion,this.pendingExpansion=void 0,this.groupConfigDirty=!1,this.#h=!1,this.#m=!1,this.#f=new WeakMap,this.#w=new WeakMap,this.preDefinedGroups.length>0||Array.isArray(this.config.groups)?(this.#p="predefined",!0):"function"!=typeof this.config.groupOn?(this.isActive=!1,this.flattenedRows=[],this.groupedFields=[],!1):(this.#p="groupOn",this.groupedFields=[],this.#c=void 0,this.#g=!1,!0)}processSiblings(e,t){const r=null===t.parentKey&&null===t.parent;if("predefined"===this.#p)return r?this.#A(t.depth,e):e;const o=this.config,n=e.map(e=>e.row),s={parent:t.parent,depth:t.depth};this.#g||(this.#c=this.resolveGroupSortDirections(n,s),this.#g=this.groupedFields.length>0);const i=(e,i)=>function({rows:e,config:t,expanded:r,initialExpanded:o,groupSortDirections:n,context:s=G,keyPrefix:i=""}){const a=t.groupOn;if("function"!=typeof a)return[];const d={key:"__root__",value:null,depth:-1,rows:[],children:new Map};if(e.forEach(e=>{let t=a(e,s);null==t||!1===t?t=["__ungrouped__"]:Array.isArray(t)||(t=[t]);let r=d;t.forEach((t,o)=>{const n=null==t?"∅":String(t),s="__root__"===r.key?i+n:r.key+"||"+n;let a=r.children.get(n);a||(a={key:s,value:t,depth:o,rows:[],children:new Map,parent:r},r.children.set(n,a)),a.rows.push(e),r=a})}),1===d.children.size&&d.children.has("__ungrouped__")&&d.children.get("__ungrouped__").rows.length===e.length)return[];const u=new Map;for(let g=0;g<e.length;g++)u.set(e[g],g);const p=new Set([...r,...o??[]]),l=e=>{const t=[...e.children.values()],r=e===d?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},h=[],c=e=>{if(e===d){for(const t of l(e))c(t);return}const t=p.has(e.key);if(h.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))c(r);else e.rows.forEach(e=>h.push({kind:"data",row:e,rowIndex:u.get(e)??-1}))};return c(d),h}({rows:n,config:o,expanded:e,initialExpanded:i,groupSortDirections:this.#c,context:s,keyPrefix:r?"":`${t.parentKey??""}::`}),a=r?this.#E(i):this.#K(i);if(0===a.length)return e;const d=new Map;for(const u of e)d.set(u.row,u);return this.#C(a,t.depth,e=>d.get(e)??{row:e},k)}endHierarchy(e){if(!this.#m)return this.isActive=!1,this.flattenedRows=[],!1;this.isActive=!0,this.flattenedRows=e.map(e=>this.#f.get(e)??{kind:"data",row:e,rowIndex:-1}),this.#h&&this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.keysToAnimate.clear();const t=new Set,r="predefined"===this.#p;r&&(this.#y=function(e,t){const r=new Array(e.length);let o=0,n=0;for(let s=0;s<e.length;s++){const i=t.get(e[s]);void 0!==i&&(o=i,n++),r[s]=o}return{owners:r,count:n}}(e,this.#w));let o=!1;return this.flattenedRows.forEach((e,n)=>{if("data"===e.kind){const e=`data-${n}`;t.add(e),this.previousVisibleKeys.has(e)||this.keysToAnimate.add(e)}else r&&!o&&(o=this.#G(e))}),this.previousVisibleKeys=t,o&&this.#S(),!0}#E(e){const t=this.config,r=e(new Set);if(0===r.length)return r;const o=this.#l;let n;const s=void 0!==o;let i;if(s?n=o:this.hasAppliedDefaultExpanded||0!==this.expandedKeys.size||!1===t.defaultExpanded||(n=t.defaultExpanded??!1),void 0!==n){i=S(n,r.filter(e=>"group"===e.kind).map(e=>e.key)),(s||i.size>0)&&(this.expandedKeys=new Set(i),this.hasAppliedDefaultExpanded=!0)}return this.#h=s,e(this.expandedKeys,i)}#K(e){const t=e(this.expandedKeys),r=this.#l;if(void 0===r&&!0!==this.config.defaultExpanded)return t;const o=[];for(const i of t)"group"===i.kind&&0===i.depth&&o.push(i.key);const n=void 0!==r?S(r,o):new Set(o.filter(e=>!this.#v.has(e)));void 0!==r&&(this.#h=!0);let s=!1;for(const i of o)this.#v.add(i),n.has(i)&&!this.expandedKeys.has(i)&&(this.expandedKeys.add(i),s=!0);return s?e(this.expandedKeys):t}#C(e,t,r,o){this.#m=!0;const n=[],s=[];for(const i of e){if("data"===i.kind){const e=r(i.row);(s.length>0?s[s.length-1].children:n).push(e),"object"==typeof i.row&&null!==i.row&&this.#f.set(i.row,i);continue}const e=0===t?i:{...i,depth:t+i.depth},a={__isGroupRow:!0,__groupKey:i.key,__groupValue:i.value,__groupDepth:e.depth,__groupRows:i.rows,__groupExpanded:i.expanded,__groupRowCount:o(i),__rowCacheKey:`group:${i.key}`};this.#f.set(a,e);const d={row:a,key:i.key,expanded:i.expanded,shaped:!0,children:[]};s.length=i.depth,(i.depth>0?s[i.depth-1].children:n).push(d),s.push(d)}return n}onCellClick(e){const t=e.row;if(t?.__isGroupRow&&e.originalEvent.target?.closest(`.${o}`))return this.toggle(t.__groupKey),!0}onKeyDown(e){if(" "!==e.key)return;if(function(e){const t=e.composedPath?.()??[],r=t.length?t[0]:e.target;if(!(r instanceof HTMLElement))return!1;const o=r.tagName;return"INPUT"===o||"SELECT"===o||"TEXTAREA"===o||r.isContentEditable}(e))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)return m(this.grid,t,e,r),!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?g(t,n):t.replaceChildren(n),!0}const n=()=>{this.toggle(e.__groupKey)};return 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),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.animationStyle;if(!(!1!==t&&this.keysToAnimate.size>0))return;const r="fade"===t?"tbw-group-fade-in":"tbw-group-slide-in";for(const o of e.querySelectorAll(".data-grid-row:not(.group-row)")){const e=o.querySelector(".cell[data-row]"),t=e?parseInt(e.getAttribute("data-row")??"-1",10):-1;"data"===this.flattenedRows[t]?.kind&&this.keysToAnimate.has(`data-${t}`)&&(o.classList.add(r),o.addEventListener("animationend",()=>o.classList.remove(r),{once:!0}))}this.keysToAnimate.clear()}#A(e,t){const r=this.getActiveGroups(),{slots:o,groups:n}=this.#n?function(e,t){let r=e.slice();if(t.length>0){const o=new Map;e.forEach((e,t)=>o.set(e,t)),r=[];for(const{row:e}of t){const t=q(e)?e.__index:o.get(e);void 0!==t&&(r[t]=e)}}const o=r.filter(e=>null!=e&&!q(e));return{slots:r,groups:o}}(this.#o,t):{slots:r,groups:r};if(0===o.length)return[];const s=this.config.defaultExpanded??!1;if(!this.hasAppliedDefaultExpanded&&0===this.expandedKeys.size&&!1!==s){const e=this.#n?"number"==typeof s?function(e){const t=[];for(const r of e){if(null==r||q(r))break;t.push(r)}return t}(this.#o):this.preDefinedGroups:n,t=S(s,K(e));t.size>0&&(this.expandedKeys=new Set(t),this.hasAppliedDefaultExpanded=!0)}const i=A({groups:n,expanded:this.expandedKeys,groupRows:this.groupRowsMap,loadingGroups:this.loadingGroups});return function(e,t,r){const o=[];let n=0;for(let s=0;s<e.length;s++){const i=e[s];if(null==i)continue;const a=q(i)?{row:i}:t[n++];r.set(a.row,s),o.push(a)}return o}(o,this.#C(i,e,e=>({row:e}),e=>C(n,e.key)?.rowCount??e.rows.length),this.#w)}getActiveGroups(){return this.preDefinedGroups.length>0?this.preDefinedGroups:Array.isArray(this.config.groups)?this.config.groups:[]}createToggleButton(e,t){const n=document.createElement("button");return n.type="button",n.className=`${o}${e?` ${r}`:""}`,n.setAttribute("aria-label",e?"Collapse group":"Expand group"),this.setIcon(n,e?"collapse":"expand"),n.addEventListener("click",e=>{e.stopPropagation(),t()}),n}getGroupLabelText(e,t,r){const o=this.config;return o.formatLabel?o.formatLabel(e,t,r):String(e)}renderFullWidthGroupRow(e,r,o){const i=this.config,a=i.aggregators??{},d=e.__groupRows??[],u=document.createElement("div");u.className="cell group-full",u.style.gridColumn="1 / -1",u.setAttribute("role","gridcell"),u.setAttribute("data-col","0"),u.appendChild(this.createToggleButton(e.__groupExpanded,o));const p=document.createElement("span");if(p.className=n,p.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey),u.appendChild(p),!1!==i.showRowCount){const t=document.createElement("span");t.className=s,t.textContent=`(${e.__groupRowCount??e.__groupRows?.length??0})`,u.appendChild(t)}const l=Object.entries(a);if(l.length>0){const e=document.createElement("span");e.className="group-aggregates";for(const[r,o]of l){const n=this.columns.find(e=>e.field===r),s=t.aggregatorRegistry.run(o,d,r,n);if(null!=s){const t=document.createElement("span");t.className="group-aggregate",t.setAttribute("data-field",r),t.textContent=`${n?.header??r}: ${s}`,e.appendChild(t)}}e.children.length>0&&u.appendChild(e)}r.appendChild(u)}renderPerColumnGroupRow(e,r,o){const n=this.config,i=n.aggregators??{},a=this.columns,d=e.__groupRows??[],u=(this.gridElement?.querySelector(".body"))?.style.gridTemplateColumns||"";u&&(r.style.display="grid",r.style.gridTemplateColumns=u);let p=!1;a.forEach((a,u)=>{const l=document.createElement("div");if(l.className="cell group-cell",l.setAttribute("data-col",String(u)),l.setAttribute("role","gridcell"),"__tbw_expander"===a.field)return l.setAttribute("data-field",a.field),void r.appendChild(l);if(p){const e=i[a.field];if(e){const r=t.aggregatorRegistry.run(e,d,a.field,a);l.textContent=null!=r?String(r):""}else l.textContent=""}else{p=!0,l.appendChild(this.createToggleButton(e.__groupExpanded,o));const r=document.createElement("span"),u=i[a.field];if(u){const o=t.aggregatorRegistry.run(u,d,a.field,a);r.textContent=String(null!=o?o:e.__groupValue)}else r.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey);if(l.appendChild(r),!1!==n.showRowCount){const e=document.createElement("span");e.className=s,e.textContent=` (${d.length})`,l.appendChild(e)}}r.appendChild(l)})}expandAll(){if(this.groupConfigDirty)return this.pendingExpansion=!0,this.expandedKeys=new Set,void this.requestRender();const e=function(e){const t=new Set;for(const r of e)"group"===r.kind&&t.add(r.key);return t}(this.flattenedRows);for(const t of e)this.expandedKeys.has(t)||this.#d.delete(t);this.expandedKeys=e,this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}collapseAll(){if(this.groupConfigDirty)return this.pendingExpansion=!1,this.expandedKeys=new Set,void this.requestRender();this.expandedKeys=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(("function"==typeof r.accordion?o&&r.accordion(o.depth):r.accordion)&&t&&o){const t=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=E(n,e);if(t){if(this.emit("group-expand",{groupKey:e,groupPath:r}),!this.groupRowsMap.has(e)){const t=C(n,e);t&&this.#R(e,t,r)}}else this.emit("group-collapse",{groupKey:e,groupPath:r})}const s=this.expandedKeys.has(e),d=null!=o?.value?String(o.value):e;if(s){const e=o?.rows?.length??0;i(this.gridElement,a(this.gridElement,"groupExpanded",d,e))}else i(this.gridElement,a(this.gridElement,"groupCollapsed",d));this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}expand(e){this.expandedKeys.has(e)||(this.expandedKeys=new Set([...this.expandedKeys,e]),this.#d.delete(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=new Set,this.hasAppliedDefaultExpanded=!1),this.requestRender()}setGroups(e){this.#b(),this.preDefinedGroups=e,this.groupRowsMap.clear(),this.#x(),this.#d.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.#x(e),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){this.#x(e),null!=e?this.groupRowsMap.delete(e):this.groupRowsMap.clear(),this.requestRender()}};e.GroupingRowsPlugin=D});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@toolbox-web/grid")):"function"==typeof define&&define.amd?define(["exports","@toolbox-web/grid"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGridPlugin_groupingRows={},e.TbwGrid)}(this,function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});var r="expanded",o="group-toggle",n="group-label",s="group-count";function i(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 a(e,r,...o){const n=(e&&"effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.messages?.[r];return n?n(...o):t.DEFAULT_A11Y_MESSAGES[r](...o)}var d="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(e=>e.split("").reverse().join("")),u=(new RegExp(`__(proto|defineGetter|defineSetter)|${d.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("|"))),p=/^on\w+$/i,l=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),c=/^\s*(javascript|vbscript|data|blob):/i;function g(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(u.has(e)){t.push(o);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(e=>p.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();p.test(e)?r.push(t.name):"is"!==e?(l.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}function h(e,t){t&&"string"==typeof t?-1!==t.indexOf("<")||-1!==t.indexOf("&")?e.replaceChildren(g(t)):e.textContent=t:e.replaceChildren()}function f(e,t){if(t){const r=t({size:e});if("string"==typeof r){const e=document.createElement("div");return h(e,r),e}return r}return function(e){const t=document.createElement("div");return t.className=`tbw-spinner tbw-spinner--${e}`,t.setAttribute("role","progressbar"),t.setAttribute("aria-label","Loading"),t}(e)}function w(e,t){if(!e.firstElementChild)return;const r=e.querySelector(":scope > .tbw-cell-loading-overlay");r&&(t?.unmount?.(r),r.remove())}function y(e,t){if(!e.firstElementChild)return;const r=e.querySelector(":scope > .tbw-row-loading-overlay");r&&(t?.unmount?.(r),r.remove())}function m(e,t,r,o){const n=t;if(function(e,t,r,o){const{style:n}=t;n.getPropertyValue("--tbw-row-height")&&n.removeProperty("--tbw-row-height");const s=e._getPluginRowHeight?.(r,o),i=void 0!==s&&s>0?`${s}px`:"";n.height!==i&&(n.height=i)}(e,n,r,o),n.__rowDataRef===r&&n.__isCustomRow&&n.classList.contains("tbw-row-loading"))return;!function(e,t){t.classList.remove("tbw-row-loading"),t.removeAttribute("aria-busy");const r=e.__frameworkAdapter;if(r?.releaseCell||r?.unmount){r.beginBatch?.(e);try{y(t,r);const e=t.children;for(let t=e.length-1;t>=0;t--){const o=e[t];w(o,r),r.releaseCell?.(o)}t.innerHTML=""}finally{r.endBatch?.(e)}}else t.innerHTML=""}(e,n),n.className="data-grid-row placeholder-row",n.__isCustomRow=!0;const s=document.createElement("div");s.className="cell",s.style.gridColumn="1 / -1",s.setAttribute("role","gridcell"),s.textContent=" ",n.appendChild(s),function(e,t,r,o){if(t){if(e.classList.add("tbw-row-loading"),e.setAttribute("aria-busy","true"),!e.querySelector(":scope > .tbw-row-loading-overlay")){const t=document.createElement("div");if(t.className="tbw-row-loading-overlay",t.setAttribute("aria-hidden","true"),r)t.appendChild(f("small",r));else{const e=document.createElement("div");e.className="tbw-row-loading-spinner",t.appendChild(e)}e.appendChild(t)}}else e.classList.remove("tbw-row-loading"),e.removeAttribute("aria-busy"),y(e,o)}(n,!0,e.effectiveConfig?.loadingRenderer)}function v(e,t,r=new WeakMap){const o=[];for(const p of["structure","transform"])for(const r of t)r.hierarchyStage===p&&r.beginHierarchy(e)&&o.push(r);if(0===o.length)return[...e];const n=[],s=(e,t,r)=>{const n={parent:t?t.row:null,parentKey:t?.key??null,depth:r};for(const s of o)e=s.processSiblings(e,n);return e},i=(e,t)=>{const o=e.length;for(let a=0;a<o;a++){const d=e[a];n.push(d.row),"object"==typeof d.row&&null!==d.row&&r.set(d.row,{level:t+1,setSize:o,posInSet:a+1});const u=d.children;d.expanded&&u&&i(d.shaped?u:s(u,d,t+1),t+1)}},a=new Array(e.length);for(let p=0;p<e.length;p++)a[p]={row:e[p]};i(s(a,null,0),0);const d=e=>"object"==typeof e&&null!==e?r.get(e):void 0;let u=!1;for(const p of o)p.endHierarchy(n,d)&&(u=!0);if(!u)for(const p of n)"object"==typeof p&&null!==p&&r.delete(p);return n}function b(e,t,r){const o=String(r);e.getAttribute(t)!==o&&e.setAttribute(t,o)}function x(e){return"function"==typeof e.processSiblings}function _(e){return e.constructor.manifest?.hookPriority?.processRows??0}var R=class extends t.BaseGridPlugin{static manifest={modifiesRowStructure:!0};name="hierarchy";#e=new WeakMap;detach(){this.gridElement?.querySelector(".rows-body")?.setAttribute("role","grid"),this.#e=new WeakMap}process(e,t){const r=this.#t();return r.includes(t)?r[r.length-1]!==t?e:(this.#e=new WeakMap,v(e,r,this.#e)):(this.#e=new WeakMap,v(e,[t],this.#e))}getRowMeta(e){return"object"==typeof e&&null!==e?this.#e.get(e):void 0}afterRender(){this.#r()}onScrollRender(){this.#r()}#t(){return(this.grid?._pluginManager?.getPlugins?.()??[]).filter(x).sort((e,t)=>_(e)-_(t))}#r(){if(0===this.#t().length)return;const e=this.gridElement?.querySelector(".rows");if(!e)return;let t=!1;for(const n of e.querySelectorAll(".data-grid-row")){const e=this.getRowMeta(n.__rowDataRef);e?(t=!0,b(n,"aria-level",e.level),b(n,"aria-setsize",e.setSize),b(n,"aria-posinset",e.posInSet)):(n.removeAttribute("aria-level"),n.removeAttribute("aria-setsize"),n.removeAttribute("aria-posinset"))}const r=t?"treegrid":"grid",o=this.gridElement?.querySelector(".rows-body");o&&o.getAttribute("role")!==r&&o.setAttribute("role",r)}},G={parent:null,depth:0};function S(e,t){if(!0===e)return new Set(t);if(!1===e||null==e)return new Set;if("number"==typeof e){const r=t[e];return r?new Set([r]):new Set}return"string"==typeof e?new Set([e]):Array.isArray(e)?new Set(e):new Set}function k(e){return"group"!==e.kind?0:e.rows.length}function A({groups:e,expanded:t,groupRows:r,loadingGroups:o,parentPath:n=[]}){const s=[],i=n.length;for(const a of e){const e=[...n,a.key],d=t.has(a.key),u=r.get(a.key)??[],p=o.has(a.key);if(s.push({kind:"group",key:a.key,value:a.value,depth:i,rows:u,expanded:d}),d)if(a.children?.length){const n=A({groups:a.children,expanded:t,groupRows:r,loadingGroups:o,parentPath:e});s.push(...n)}else p?s.push({kind:"data",row:{__loading:!0,__groupKey:a.key,__rowCacheKey:`__loading:group:${a.key}`},rowIndex:-1}):u.forEach((e,t)=>{s.push({kind:"data",row:e,rowIndex:t})})}return s}function E(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=E(o.children,t,e);if(r.length>0)return r}}return[]}function K(e){const t=[];for(const r of e)t.push(r.key),r.children?.length&&t.push(...K(r.children));return t}function C(e,t){for(const r of e){if(r.key===t)return r;const e=r.children?.length?C(r.children,t):void 0;if(e)return e}}function q(e){const t=e;return null!=t&&"object"==typeof t&&!0===t.__loading&&"number"==typeof t.__index}var D=class extends t.BaseGridPlugin{static manifest={modifiesRowStructure:!0,hookPriority:{processRows:10,onHeaderClick:-1,onCellClick:-10},incompatibleWith:[{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."},{type:"group-load-error",description:"Emitted when a pre-defined group's ServerSide getChildRows() fails. The group leaves its loading state."}],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:"hierarchy",required:!0,reason:"Builds the hierarchical row model",provide:()=>new R},{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";hierarchyStage="transform";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)}.group-toggle{position:relative}.group-toggle:after{content:"";inline-size:var(--tbw-touch-target-min,24px);block-size:var(--tbw-touch-target-min,24px);position:absolute;inset-block-start:50%;inset-inline-start:50%;translate:-50% -50%}@media (pointer:coarse){.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=new Set;flattenedRows=[];isActive=!1;previousVisibleKeys=new Set;keysToAnimate=new Set;hasAppliedDefaultExpanded=!1;pendingExpansion;groupConfigDirty=!1;preDefinedGroups=[];#o=[];#n=!1;#s;#i=new Set;groupRowsMap=new Map;loadingGroups=new Set;#a=new Map;#d=new Set;#u=!1;groupedFields=[];userGroupSortDirections=new Map;#p="groupOn";#l;#c=!1;#g;#h=!1;#f=new WeakMap;#w=new WeakMap;#y={owners:[],count:0};#m=!1;#v=new Set;get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}detach(){this.expandedKeys.clear(),this.flattenedRows=[],this.isActive=!1,this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.hasAppliedDefaultExpanded=!1,this.pendingExpansion=void 0,this.groupConfigDirty=!1,this.preDefinedGroups=[],this.#b(),this.#y={owners:[],count:0},this.groupRowsMap.clear(),this.#x(),this.#d.clear(),this.loadingGroups.clear(),this.groupedFields=[],this.userGroupSortDirections.clear(),this.#v.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||"predefined"!==this.#p)return;return function({owners:e,count:t},r,o){const n=e.length-1,s=t=>e[Math.max(0,Math.min(t,n))]??0;return{startNode:s(r),endNode:s(o)+1,totalLoadedNodes:t}}(this.#y,t,r)}}attach(e){super.attach(e),this.on("datasource:data",e=>{const t=e;if(t.claimed)return;t.claimed=!0;const r=t.rows;if(this.#n&&void 0!==t.generation&&t.generation===this.#s)return this.#_(r,t.startNode),void this.requestRender();const o=[...this.expandedKeys].filter(e=>this.groupRowsMap.has(e)||this.#a.has(e));this.#o=[],this.#n=void 0!==t.generation,this.#s=t.generation,this.hasAppliedDefaultExpanded||=this.expandedKeys.size>0,this.#_(r,this.#n?t.startNode:0),this.groupRowsMap.clear(),this.#x(),this.#d.clear(),this.loadingGroups.clear();for(const n of o){const e=C(this.preDefinedGroups,n);e&&this.#R(n,e,E(this.preDefinedGroups,n))}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.#a.delete(r),this.groupRowsMap.set(r,t.rows),this.loadingGroups.delete(r),this.requestRender())}),this.on("datasource:error",e=>{const t=e;if("grouping-rows"!==t.context?.source)return;const r=t.context.groupKey;r&&this.#a.delete(r)&&(this.loadingGroups.delete(r),this.emit("group-load-error",{groupKey:r,groupPath:t.context.groupPath??[r],error:t.error}),this.requestRender())})}#x(e){for(const[t,r]of this.#a)null!=e&&t!==e||(r.abort(),this.#a.delete(t),this.loadingGroups.delete(t))}#b(){this.#o=[],this.#n=!1,this.#s=void 0,this.#i.clear()}#_(e,t){const r=Number.isInteger(t)&&t>0?t:0;for(let n=0;n<e.length;n++)this.#o[r+n]=e[n];this.preDefinedGroups=this.#o.filter(e=>null!=e);const o=!0===this.config.defaultExpanded&&this.hasAppliedDefaultExpanded;for(const n of K(e))o&&!this.#i.has(n)&&this.expandedKeys.add(n),this.#i.add(n)}#R(e,t,r){if(this.#d.add(e),this.loadingGroups.add(e),this.#a.has(e))return;const o=this.queryBoolean("datasource:is-active")?new AbortController:void 0;o&&this.#a.set(e,o),this.grid?.query?.("datasource:fetch-children",{context:{source:"grouping-rows",groupKey:e,group:t,groupPath:r},signal:o?.signal})}#G(e){return"group"===e.kind&&e.expanded&&!this.groupRowsMap.has(e.key)&&!this.loadingGroups.has(e.key)&&!this.#d.has(e.key)}#S(){this.#u||(this.#u=!0,queueMicrotask(()=>{this.#u=!1,this.#k()}))}#k(){if(!this.isActive||"predefined"!==this.#p)return;const e=this.queryBoolean("datasource:is-active"),t=this.getActiveGroups();let r=!1;for(const o of this.flattenedRows){if(!this.#G(o))continue;const n=E(t,o.key);if(!n.every(e=>this.expandedKeys.has(e)))continue;const s=C(t,o.key);e&&s&&!s.children?.length?(this.#R(o.key,s,n),r=!0):this.#d.add(o.key)}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,t){const r=this.config;if("function"!=typeof r.groupOn||0===e.length)return void(this.groupedFields=[]);const o=this.columns.map(e=>e.field),n=function(e,t,r,o=G){const n=new Map;let s,i=null;for(const a of e)if(i=t(a,o),null!=i&&!1!==i){s=a;break}if(void 0===s)return n;Array.isArray(i)||(i=[i]);for(let a=0;a<i.length;a++){const e=i[a];for(const t of r)if(s[t]===e){n.set(a,t);break}}return n}([...e],r.groupOn,o,t);if(this.groupedFields=[...n.values()],0===n.size)return;const s=new Map(this.userGroupSortDirections);if(s.size<n.size){const e=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._sortState;t&&e.set(t.field,t.direction)}for(const[r,o]of n)if(!s.has(r)){const t=e.get(o);void 0!==t&&s.set(r,t)}}return s.size>0?s:void 0}static detect(e,t){return"function"==typeof t?.groupOn||"boolean"==typeof t?.enableRowGrouping||Array.isArray(t?.groups)}processRows(e){const t=this.grid?.getPluginByName?.("hierarchy");return t?t.process(e,this):v(e,[this])}beginHierarchy(e){return this.#l=this.pendingExpansion,this.pendingExpansion=void 0,this.groupConfigDirty=!1,this.#c=!1,this.#m=!1,this.#f=new WeakMap,this.#w=new WeakMap,this.preDefinedGroups.length>0||Array.isArray(this.config.groups)?(this.#p="predefined",!0):"function"!=typeof this.config.groupOn?(this.isActive=!1,this.flattenedRows=[],this.groupedFields=[],!1):(this.#p="groupOn",this.groupedFields=[],this.#g=void 0,this.#h=!1,!0)}processSiblings(e,t){const r=null===t.parentKey&&null===t.parent;if("predefined"===this.#p)return r?this.#A(t.depth,e):e;const o=this.config,n=e.map(e=>e.row),s={parent:t.parent,depth:t.depth};this.#h||(this.#g=this.resolveGroupSortDirections(n,s),this.#h=this.groupedFields.length>0);const i=(e,i)=>function({rows:e,config:t,expanded:r,initialExpanded:o,groupSortDirections:n,context:s=G,keyPrefix:i=""}){const a=t.groupOn;if("function"!=typeof a)return[];const d={key:"__root__",value:null,depth:-1,rows:[],children:new Map};if(e.forEach(e=>{let t=a(e,s);null==t||!1===t?t=["__ungrouped__"]:Array.isArray(t)||(t=[t]);let r=d;t.forEach((t,o)=>{const n=null==t?"∅":String(t),s="__root__"===r.key?i+n:r.key+"||"+n;let a=r.children.get(n);a||(a={key:s,value:t,depth:o,rows:[],children:new Map,parent:r},r.children.set(n,a)),a.rows.push(e),r=a})}),1===d.children.size&&d.children.has("__ungrouped__")&&d.children.get("__ungrouped__").rows.length===e.length)return[];const u=new Map;for(let h=0;h<e.length;h++)u.set(e[h],h);const p=new Set([...r,...o??[]]),l=e=>{const t=[...e.children.values()],r=e===d?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},c=[],g=e=>{if(e===d){for(const t of l(e))g(t);return}const t=p.has(e.key);if(c.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))g(r);else e.rows.forEach(e=>c.push({kind:"data",row:e,rowIndex:u.get(e)??-1}))};return g(d),c}({rows:n,config:o,expanded:e,initialExpanded:i,groupSortDirections:this.#g,context:s,keyPrefix:r?"":`${t.parentKey??""}::`}),a=r?this.#E(i):this.#K(i);if(0===a.length)return e;const d=new Map;for(const u of e)d.set(u.row,u);return this.#C(a,t.depth,e=>d.get(e)??{row:e},k)}endHierarchy(e){if(!this.#m)return this.isActive=!1,this.flattenedRows=[],!1;this.isActive=!0,this.flattenedRows=e.map(e=>this.#f.get(e)??{kind:"data",row:e,rowIndex:-1}),this.#c&&this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.keysToAnimate.clear();const t=new Set,r="predefined"===this.#p;r&&(this.#y=function(e,t){const r=new Array(e.length);let o=0,n=0;for(let s=0;s<e.length;s++){const i=t.get(e[s]);void 0!==i&&(o=i,n++),r[s]=o}return{owners:r,count:n}}(e,this.#w));let o=!1;return this.flattenedRows.forEach((e,n)=>{if("data"===e.kind){const e=`data-${n}`;t.add(e),this.previousVisibleKeys.has(e)||this.keysToAnimate.add(e)}else r&&!o&&(o=this.#G(e))}),this.previousVisibleKeys=t,o&&this.#S(),!0}#E(e){const t=this.config,r=e(new Set);if(0===r.length)return r;const o=this.#l;let n;const s=void 0!==o;let i;if(s?n=o:this.hasAppliedDefaultExpanded||0!==this.expandedKeys.size||!1===t.defaultExpanded||(n=t.defaultExpanded??!1),void 0!==n){i=S(n,r.filter(e=>"group"===e.kind).map(e=>e.key)),(s||i.size>0)&&(this.expandedKeys=new Set(i),this.hasAppliedDefaultExpanded=!0)}return this.#c=s,e(this.expandedKeys,i)}#K(e){const t=e(this.expandedKeys),r=this.#l;if(void 0===r&&!0!==this.config.defaultExpanded)return t;const o=[];for(const i of t)"group"===i.kind&&0===i.depth&&o.push(i.key);const n=void 0!==r?S(r,o):new Set(o.filter(e=>!this.#v.has(e)));void 0!==r&&(this.#c=!0);let s=!1;for(const i of o)this.#v.add(i),n.has(i)&&!this.expandedKeys.has(i)&&(this.expandedKeys.add(i),s=!0);return s?e(this.expandedKeys):t}#C(e,t,r,o){this.#m=!0;const n=[],s=[];for(const i of e){if("data"===i.kind){const e=r(i.row);(s.length>0?s[s.length-1].children:n).push(e),"object"==typeof i.row&&null!==i.row&&this.#f.set(i.row,i);continue}const e=0===t?i:{...i,depth:t+i.depth},a={__isGroupRow:!0,__groupKey:i.key,__groupValue:i.value,__groupDepth:e.depth,__groupRows:i.rows,__groupExpanded:i.expanded,__groupRowCount:o(i),__rowCacheKey:`group:${i.key}`};this.#f.set(a,e);const d={row:a,key:i.key,expanded:i.expanded,shaped:!0,children:[]};s.length=i.depth,(i.depth>0?s[i.depth-1].children:n).push(d),s.push(d)}return n}onCellClick(e){const t=e.row;if(t?.__isGroupRow&&e.originalEvent.target?.closest(`.${o}`))return"dblclick"===e.originalEvent.type||this.toggle(t.__groupKey),!0}onKeyDown(e){if(" "!==e.key)return;if(function(e){const t=e.composedPath?.()??[],r=t.length?t[0]:e.target;if(!(r instanceof HTMLElement))return!1;const o=r.tagName;return"INPUT"===o||"SELECT"===o||"TEXTAREA"===o||r.isContentEditable}(e))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)return m(this.grid,t,e,r),!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?h(t,n):t.replaceChildren(n),!0}const n=()=>{this.toggle(e.__groupKey)};return 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),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.animationStyle;if(!(!1!==t&&this.keysToAnimate.size>0))return;const r="fade"===t?"tbw-group-fade-in":"tbw-group-slide-in";for(const o of e.querySelectorAll(".data-grid-row:not(.group-row)")){const e=o.querySelector(".cell[data-row]"),t=e?parseInt(e.getAttribute("data-row")??"-1",10):-1;"data"===this.flattenedRows[t]?.kind&&this.keysToAnimate.has(`data-${t}`)&&(o.classList.add(r),o.addEventListener("animationend",()=>o.classList.remove(r),{once:!0}))}this.keysToAnimate.clear()}#A(e,t){const r=this.getActiveGroups(),{slots:o,groups:n}=this.#n?function(e,t){let r=e.slice();if(t.length>0){const o=new Map;e.forEach((e,t)=>o.set(e,t)),r=[];for(const{row:e}of t){const t=q(e)?e.__index:o.get(e);void 0!==t&&(r[t]=e)}}const o=r.filter(e=>null!=e&&!q(e));return{slots:r,groups:o}}(this.#o,t):{slots:r,groups:r};if(0===o.length)return[];const s=this.config.defaultExpanded??!1;if(!this.hasAppliedDefaultExpanded&&0===this.expandedKeys.size&&!1!==s){const e=this.#n?"number"==typeof s?function(e){const t=[];for(const r of e){if(null==r||q(r))break;t.push(r)}return t}(this.#o):this.preDefinedGroups:n,t=S(s,K(e));t.size>0&&(this.expandedKeys=new Set(t),this.hasAppliedDefaultExpanded=!0)}const i=A({groups:n,expanded:this.expandedKeys,groupRows:this.groupRowsMap,loadingGroups:this.loadingGroups});return function(e,t,r){const o=[];let n=0;for(let s=0;s<e.length;s++){const i=e[s];if(null==i)continue;const a=q(i)?{row:i}:t[n++];r.set(a.row,s),o.push(a)}return o}(o,this.#C(i,e,e=>({row:e}),e=>C(n,e.key)?.rowCount??e.rows.length),this.#w)}getActiveGroups(){return this.preDefinedGroups.length>0?this.preDefinedGroups:Array.isArray(this.config.groups)?this.config.groups:[]}createToggleButton(e,t){const n=document.createElement("button");return n.type="button",n.className=`${o}${e?` ${r}`:""}`,n.setAttribute("aria-label",e?"Collapse group":"Expand group"),this.setIcon(n,e?"collapse":"expand"),n.addEventListener("click",e=>{e.stopPropagation(),t()}),n}getGroupLabelText(e,t,r){const o=this.config;return o.formatLabel?o.formatLabel(e,t,r):String(e)}renderFullWidthGroupRow(e,r,o){const i=this.config,a=i.aggregators??{},d=e.__groupRows??[],u=document.createElement("div");u.className="cell group-full",u.style.gridColumn="1 / -1",u.setAttribute("role","gridcell"),u.setAttribute("data-col","0"),u.appendChild(this.createToggleButton(e.__groupExpanded,o));const p=document.createElement("span");if(p.className=n,p.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey),u.appendChild(p),!1!==i.showRowCount){const t=document.createElement("span");t.className=s,t.textContent=`(${e.__groupRowCount??e.__groupRows?.length??0})`,u.appendChild(t)}const l=Object.entries(a);if(l.length>0){const e=document.createElement("span");e.className="group-aggregates";for(const[r,o]of l){const n=this.columns.find(e=>e.field===r),s=t.aggregatorRegistry.run(o,d,r,n);if(null!=s){const t=document.createElement("span");t.className="group-aggregate",t.setAttribute("data-field",r),t.textContent=`${n?.header??r}: ${s}`,e.appendChild(t)}}e.children.length>0&&u.appendChild(e)}r.appendChild(u)}renderPerColumnGroupRow(e,r,o){const n=this.config,i=n.aggregators??{},a=this.columns,d=e.__groupRows??[],u=(this.gridElement?.querySelector(".body"))?.style.gridTemplateColumns||"";u&&(r.style.display="grid",r.style.gridTemplateColumns=u);let p=!1;a.forEach((a,u)=>{const l=document.createElement("div");if(l.className="cell group-cell",l.setAttribute("data-col",String(u)),l.setAttribute("role","gridcell"),"__tbw_expander"===a.field)return l.setAttribute("data-field",a.field),void r.appendChild(l);if(p){const e=i[a.field];if(e){const r=t.aggregatorRegistry.run(e,d,a.field,a);l.textContent=null!=r?String(r):""}else l.textContent=""}else{p=!0,l.appendChild(this.createToggleButton(e.__groupExpanded,o));const r=document.createElement("span"),u=i[a.field];if(u){const o=t.aggregatorRegistry.run(u,d,a.field,a);r.textContent=String(null!=o?o:e.__groupValue)}else r.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey);if(l.appendChild(r),!1!==n.showRowCount){const e=document.createElement("span");e.className=s,e.textContent=` (${d.length})`,l.appendChild(e)}}r.appendChild(l)})}expandAll(){if(this.groupConfigDirty)return this.pendingExpansion=!0,this.expandedKeys=new Set,void this.requestRender();const e=function(e){const t=new Set;for(const r of e)"group"===r.kind&&t.add(r.key);return t}(this.flattenedRows);for(const t of e)this.expandedKeys.has(t)||this.#d.delete(t);this.expandedKeys=e,this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}collapseAll(){if(this.groupConfigDirty)return this.pendingExpansion=!1,this.expandedKeys=new Set,void this.requestRender();this.expandedKeys=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(("function"==typeof r.accordion?o&&r.accordion(o.depth):r.accordion)&&t&&o){const t=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=E(n,e);if(t){if(this.emit("group-expand",{groupKey:e,groupPath:r}),!this.groupRowsMap.has(e)){const t=C(n,e);t&&this.#R(e,t,r)}}else this.emit("group-collapse",{groupKey:e,groupPath:r})}const s=this.expandedKeys.has(e),d=null!=o?.value?String(o.value):e;if(s){const e=o?.rows?.length??0;i(this.gridElement,a(this.gridElement,"groupExpanded",d,e))}else i(this.gridElement,a(this.gridElement,"groupCollapsed",d));this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}expand(e){this.expandedKeys.has(e)||(this.expandedKeys=new Set([...this.expandedKeys,e]),this.#d.delete(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=new Set,this.hasAppliedDefaultExpanded=!1),this.requestRender()}setGroups(e){this.#b(),this.preDefinedGroups=e,this.groupRowsMap.clear(),this.#x(),this.#d.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.#x(e),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){this.#x(e),null!=e?this.groupRowsMap.delete(e):this.groupRowsMap.clear(),this.requestRender()}};e.GroupingRowsPlugin=D});
2
2
  //# sourceMappingURL=grouping-rows.umd.js.map