@toolbox-web/grid 3.9.2 → 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 (123) hide show
  1. package/all.js +1 -1
  2. package/all.js.map +1 -1
  3. package/index.js +1 -1
  4. package/index.js.map +1 -1
  5. package/lib/core/types.d.ts +6 -3
  6. package/lib/features/clipboard.js.map +1 -1
  7. package/lib/features/column-virtualization.js.map +1 -1
  8. package/lib/features/context-menu.js.map +1 -1
  9. package/lib/features/editing.js.map +1 -1
  10. package/lib/features/export.js.map +1 -1
  11. package/lib/features/filtering.js.map +1 -1
  12. package/lib/features/grouping-columns.js.map +1 -1
  13. package/lib/features/grouping-rows.js.map +1 -1
  14. package/lib/features/master-detail.js.map +1 -1
  15. package/lib/features/multi-sort.js.map +1 -1
  16. package/lib/features/pinned-columns.js.map +1 -1
  17. package/lib/features/pinned-rows.js.map +1 -1
  18. package/lib/features/pivot.js.map +1 -1
  19. package/lib/features/print.js.map +1 -1
  20. package/lib/features/registry.js +1 -1
  21. package/lib/features/registry.js.map +1 -1
  22. package/lib/features/reorder-columns.js.map +1 -1
  23. package/lib/features/responsive.js.map +1 -1
  24. package/lib/features/row-drag-drop.js.map +1 -1
  25. package/lib/features/selection.js.map +1 -1
  26. package/lib/features/server-side.js.map +1 -1
  27. package/lib/features/shell.js.map +1 -1
  28. package/lib/features/sticky-rows.js.map +1 -1
  29. package/lib/features/tooltip.js.map +1 -1
  30. package/lib/features/tree.js.map +1 -1
  31. package/lib/features/undo-redo.js.map +1 -1
  32. package/lib/features/visibility.js.map +1 -1
  33. package/lib/plugins/clipboard/index.js.map +1 -1
  34. package/lib/plugins/column-virtualization/index.js.map +1 -1
  35. package/lib/plugins/context-menu/index.js.map +1 -1
  36. package/lib/plugins/editing/editors.d.ts +15 -0
  37. package/lib/plugins/editing/index.js +1 -1
  38. package/lib/plugins/editing/index.js.map +1 -1
  39. package/lib/plugins/editing/internal/helpers.d.ts +23 -0
  40. package/lib/plugins/editing/types.d.ts +16 -1
  41. package/lib/plugins/export/index.js +1 -1
  42. package/lib/plugins/export/index.js.map +1 -1
  43. package/lib/plugins/filtering/filter-model.d.ts +20 -1
  44. package/lib/plugins/filtering/filter-panel-default.d.ts +15 -1
  45. package/lib/plugins/filtering/index.d.ts +1 -1
  46. package/lib/plugins/filtering/index.js +1 -1
  47. package/lib/plugins/filtering/index.js.map +1 -1
  48. package/lib/plugins/filtering/types.d.ts +58 -3
  49. package/lib/plugins/grouping-columns/index.js.map +1 -1
  50. package/lib/plugins/grouping-rows/index.js +1 -1
  51. package/lib/plugins/grouping-rows/index.js.map +1 -1
  52. package/lib/plugins/hierarchy/index.js.map +1 -1
  53. package/lib/plugins/master-detail/index.js +1 -1
  54. package/lib/plugins/master-detail/index.js.map +1 -1
  55. package/lib/plugins/master-detail/master-detail-plugin.d.ts +6 -1
  56. package/lib/plugins/multi-sort/index.js.map +1 -1
  57. package/lib/plugins/pinned-columns/index.js.map +1 -1
  58. package/lib/plugins/pinned-rows/index.js.map +1 -1
  59. package/lib/plugins/pivot/index.js +1 -1
  60. package/lib/plugins/pivot/index.js.map +1 -1
  61. package/lib/plugins/pivot/pivot-plugin.d.ts +2 -0
  62. package/lib/plugins/pivot/types.d.ts +2 -0
  63. package/lib/plugins/print/index.js.map +1 -1
  64. package/lib/plugins/reorder-columns/index.js.map +1 -1
  65. package/lib/plugins/responsive/index.js.map +1 -1
  66. package/lib/plugins/row-drag-drop/index.js.map +1 -1
  67. package/lib/plugins/selection/index.js +1 -1
  68. package/lib/plugins/selection/index.js.map +1 -1
  69. package/lib/plugins/server-side/index.js.map +1 -1
  70. package/lib/plugins/shared/form-field-target.d.ts +10 -0
  71. package/lib/plugins/shared/format-value.d.ts +12 -0
  72. package/lib/plugins/shared/structural-toggle.d.ts +14 -0
  73. package/lib/plugins/shell/index.js.map +1 -1
  74. package/lib/plugins/sticky-rows/index.js.map +1 -1
  75. package/lib/plugins/tooltip/index.js.map +1 -1
  76. package/lib/plugins/tree/index.js +1 -1
  77. package/lib/plugins/tree/index.js.map +1 -1
  78. package/lib/plugins/undo-redo/index.d.ts +1 -1
  79. package/lib/plugins/undo-redo/index.js +1 -1
  80. package/lib/plugins/undo-redo/index.js.map +1 -1
  81. package/lib/plugins/undo-redo/types.d.ts +20 -2
  82. package/lib/plugins/undo-redo/undo-redo-plugin.d.ts +8 -0
  83. package/lib/plugins/visibility/index.js.map +1 -1
  84. package/package.json +1 -1
  85. package/umd/grid.all.umd.js +1 -1
  86. package/umd/grid.all.umd.js.map +1 -1
  87. package/umd/grid.umd.js +1 -1
  88. package/umd/grid.umd.js.map +1 -1
  89. package/umd/plugins/clipboard.umd.js.map +1 -1
  90. package/umd/plugins/column-virtualization.umd.js.map +1 -1
  91. package/umd/plugins/context-menu.umd.js.map +1 -1
  92. package/umd/plugins/editing.umd.js +1 -1
  93. package/umd/plugins/editing.umd.js.map +1 -1
  94. package/umd/plugins/export.umd.js +1 -1
  95. package/umd/plugins/export.umd.js.map +1 -1
  96. package/umd/plugins/filtering.umd.js +1 -1
  97. package/umd/plugins/filtering.umd.js.map +1 -1
  98. package/umd/plugins/grouping-columns.umd.js.map +1 -1
  99. package/umd/plugins/grouping-rows.umd.js +1 -1
  100. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  101. package/umd/plugins/hierarchy.umd.js.map +1 -1
  102. package/umd/plugins/master-detail.umd.js +1 -1
  103. package/umd/plugins/master-detail.umd.js.map +1 -1
  104. package/umd/plugins/multi-sort.umd.js.map +1 -1
  105. package/umd/plugins/pinned-columns.umd.js.map +1 -1
  106. package/umd/plugins/pinned-rows.umd.js.map +1 -1
  107. package/umd/plugins/pivot.umd.js +1 -1
  108. package/umd/plugins/pivot.umd.js.map +1 -1
  109. package/umd/plugins/print.umd.js.map +1 -1
  110. package/umd/plugins/reorder-columns.umd.js.map +1 -1
  111. package/umd/plugins/responsive.umd.js.map +1 -1
  112. package/umd/plugins/row-drag-drop.umd.js.map +1 -1
  113. package/umd/plugins/selection.umd.js +1 -1
  114. package/umd/plugins/selection.umd.js.map +1 -1
  115. package/umd/plugins/server-side.umd.js.map +1 -1
  116. package/umd/plugins/shell.umd.js.map +1 -1
  117. package/umd/plugins/sticky-rows.umd.js.map +1 -1
  118. package/umd/plugins/tooltip.umd.js.map +1 -1
  119. package/umd/plugins/tree.umd.js +1 -1
  120. package/umd/plugins/tree.umd.js.map +1 -1
  121. package/umd/plugins/undo-redo.umd.js +1 -1
  122. package/umd/plugins/undo-redo.umd.js.map +1 -1
  123. package/umd/plugins/visibility.umd.js.map +1 -1
@@ -1,2 +1,2 @@
1
- import{BaseGridPlugin as e,DEFAULT_A11Y_MESSAGES as t,aggregatorRegistry as r}from"@toolbox-web/grid";import{HierarchyPlugin as o,buildHierarchy as n}from"@toolbox-web/grid/plugins/hierarchy";var s="expanded",i="group-toggle",a="group-label",d="group-count";function p(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 u(e,r,...o){const n=(e&&"effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.messages?.[r];return n?n(...o):t[r](...o)}var l="__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("")),h=(new RegExp(`__(proto|defineGetter|defineSetter)|${l.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("|"))),g=/^on\w+$/i,c=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),f=/^\s*(javascript|vbscript|data|blob):/i;function w(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(h.has(e)){t.push(o);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(e=>g.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();g.test(e)?r.push(t.name):"is"!==e?(c.has(e)&&f.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 y(e,t){t&&"string"==typeof t?-1!==t.indexOf("<")||-1!==t.indexOf("&")?e.replaceChildren(w(t)):e.textContent=t:e.replaceChildren()}function m(e,t){if(t){const r=t({size:e});if("string"==typeof r){const e=document.createElement("div");return y(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 v(e,t){if(!e.firstElementChild)return;const r=e.querySelector(":scope > .tbw-cell-loading-overlay");r&&(t?.unmount?.(r),r.remove())}function x(e,t){if(!e.firstElementChild)return;const r=e.querySelector(":scope > .tbw-row-loading-overlay");r&&(t?.unmount?.(r),r.remove())}function b(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{x(t,r);const e=t.children;for(let t=e.length-1;t>=0;t--){const o=e[t];v(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(m("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"),x(e,o)}(n,!0,e.effectiveConfig?.loadingRenderer)}var _={parent:null,depth:0};function R(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(e){return"group"!==e.kind?0:e.rows.length}function k({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),p=r.get(a.key)??[],u=o.has(a.key);if(s.push({kind:"group",key:a.key,value:a.value,depth:i,rows:p,expanded:d}),d)if(a.children?.length){const n=k({groups:a.children,expanded:t,groupRows:r,loadingGroups:o,parentPath:e});s.push(...n)}else u?s.push({kind:"data",row:{__loading:!0,__groupKey:a.key,__rowCacheKey:`__loading:group:${a.key}`},rowIndex:-1}):p.forEach((e,t)=>{s.push({kind:"data",row:e,rowIndex:t})})}return s}function S(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=S(o.children,t,e);if(r.length>0)return r}}return[]}function E(e){const t=[];for(const r of e)t.push(r.key),r.children?.length&&t.push(...E(r.children));return t}function K(e,t){for(const r of e){if(r.key===t)return r;const e=r.children?.length?K(r.children,t):void 0;if(e)return e}}function A(e){const t=e;return null!=t&&"object"==typeof t&&!0===t.__loading&&"number"==typeof t.__index}var C=class extends e{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 o},{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=/* @__PURE__ */new Set;flattenedRows=[];isActive=!1;previousVisibleKeys=/* @__PURE__ */new Set;keysToAnimate=/* @__PURE__ */new Set;hasAppliedDefaultExpanded=!1;pendingExpansion;groupConfigDirty=!1;preDefinedGroups=[];#e=[];#t=!1;#r;#o=/* @__PURE__ */new Set;groupRowsMap=/* @__PURE__ */new Map;loadingGroups=/* @__PURE__ */new Set;#n=/* @__PURE__ */new Map;#s=/* @__PURE__ */new Set;#i=!1;groupedFields=[];userGroupSortDirections=/* @__PURE__ */new Map;#a="groupOn";#d;#p=!1;#u;#l=!1;#h=/* @__PURE__ */new WeakMap;#g=/* @__PURE__ */new WeakMap;#c={owners:[],count:0};#f=!1;#w=/* @__PURE__ */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.#y(),this.#c={owners:[],count:0},this.groupRowsMap.clear(),this.#m(),this.#s.clear(),this.loadingGroups.clear(),this.groupedFields=[],this.userGroupSortDirections.clear(),this.#w.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.#a)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.#c,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.#t&&void 0!==t.generation&&t.generation===this.#r)return this.#v(r,t.startNode),void this.requestRender();const o=[...this.expandedKeys].filter(e=>this.groupRowsMap.has(e)||this.#n.has(e));this.#e=[],this.#t=void 0!==t.generation,this.#r=t.generation,this.hasAppliedDefaultExpanded||=this.expandedKeys.size>0,this.#v(r,this.#t?t.startNode:0),this.groupRowsMap.clear(),this.#m(),this.#s.clear(),this.loadingGroups.clear();for(const n of o){const e=K(this.preDefinedGroups,n);e&&this.#x(n,e,S(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.#n.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.#n.delete(r)&&(this.loadingGroups.delete(r),this.emit("group-load-error",{groupKey:r,groupPath:t.context.groupPath??[r],error:t.error}),this.requestRender())})}#m(e){for(const[t,r]of this.#n)null!=e&&t!==e||(r.abort(),this.#n.delete(t),this.loadingGroups.delete(t))}#y(){this.#e=[],this.#t=!1,this.#r=void 0,this.#o.clear()}#v(e,t){const r=Number.isInteger(t)&&t>0?t:0;for(let n=0;n<e.length;n++)this.#e[r+n]=e[n];this.preDefinedGroups=this.#e.filter(e=>null!=e);const o=!0===this.config.defaultExpanded&&this.hasAppliedDefaultExpanded;for(const n of E(e))o&&!this.#o.has(n)&&this.expandedKeys.add(n),this.#o.add(n)}#x(e,t,r){if(this.#s.add(e),this.loadingGroups.add(e),this.#n.has(e))return;const o=this.queryBoolean("datasource:is-active")?new AbortController:void 0;o&&this.#n.set(e,o),this.grid?.query?.("datasource:fetch-children",{context:{source:"grouping-rows",groupKey:e,group:t,groupPath:r},signal:o?.signal})}#b(e){return"group"===e.kind&&e.expanded&&!this.groupRowsMap.has(e.key)&&!this.loadingGroups.has(e.key)&&!this.#s.has(e.key)}#_(){this.#i||(this.#i=!0,queueMicrotask(()=>{this.#i=!1,this.#R()}))}#R(){if(!this.isActive||"predefined"!==this.#a)return;const e=this.queryBoolean("datasource:is-active"),t=this.getActiveGroups();let r=!1;for(const o of this.flattenedRows){if(!this.#b(o))continue;const n=S(t,o.key);if(!n.every(e=>this.expandedKeys.has(e)))continue;const s=K(t,o.key);e&&s&&!s.children?.length?(this.#x(o.key,s,n),r=!0):this.#s.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=_){const n=/* @__PURE__ */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=/* @__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._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):n(e,[this])}beginHierarchy(e){return this.#d=this.pendingExpansion,this.pendingExpansion=void 0,this.groupConfigDirty=!1,this.#p=!1,this.#f=!1,this.#h=/* @__PURE__ */new WeakMap,this.#g=/* @__PURE__ */new WeakMap,this.preDefinedGroups.length>0||Array.isArray(this.config.groups)?(this.#a="predefined",!0):"function"!=typeof this.config.groupOn?(this.isActive=!1,this.flattenedRows=[],this.groupedFields=[],!1):(this.#a="groupOn",this.groupedFields=[],this.#u=void 0,this.#l=!1,!0)}processSiblings(e,t){const r=null===t.parentKey&&null===t.parent;if("predefined"===this.#a)return r?this.#G(t.depth,e):e;const o=this.config,n=e.map(e=>e.row),s={parent:t.parent,depth:t.depth};this.#l||(this.#u=this.resolveGroupSortDirections(n,s),this.#l=this.groupedFields.length>0);const i=(e,i)=>function({rows:e,config:t,expanded:r,initialExpanded:o,groupSortDirections:n,context:s=_,keyPrefix:i=""}){const a=t.groupOn;if("function"!=typeof a)return[];const d={key:"__root__",value:null,depth:-1,rows:[],children:/* @__PURE__ */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:/* @__PURE__ */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 p=/* @__PURE__ */new Map;for(let c=0;c<e.length;c++)p.set(e[c],c);const u=/* @__PURE__ */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=[],g=e=>{if(e===d){for(const t of l(e))g(t);return}const t=u.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))g(r);else e.rows.forEach(e=>h.push({kind:"data",row:e,rowIndex:p.get(e)??-1}))};return g(d),h}({rows:n,config:o,expanded:e,initialExpanded:i,groupSortDirections:this.#u,context:s,keyPrefix:r?"":`${t.parentKey??""}::`}),a=r?this.#k(i):this.#S(i);if(0===a.length)return e;const d=/* @__PURE__ */new Map;for(const p of e)d.set(p.row,p);return this.#E(a,t.depth,e=>d.get(e)??{row:e},G)}endHierarchy(e){if(!this.#f)return this.isActive=!1,this.flattenedRows=[],!1;this.isActive=!0,this.flattenedRows=e.map(e=>this.#h.get(e)??{kind:"data",row:e,rowIndex:-1}),this.#p&&this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.keysToAnimate.clear();const t=/* @__PURE__ */new Set,r="predefined"===this.#a;r&&(this.#c=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.#g));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.#b(e))}),this.previousVisibleKeys=t,o&&this.#_(),!0}#k(e){const t=this.config,r=e(/* @__PURE__ */new Set);if(0===r.length)return r;const o=this.#d;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=R(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.#p=s,e(this.expandedKeys,i)}#S(e){const t=e(this.expandedKeys),r=this.#d;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?R(r,o):new Set(o.filter(e=>!this.#w.has(e)));void 0!==r&&(this.#p=!0);let s=!1;for(const i of o)this.#w.add(i),n.has(i)&&!this.expandedKeys.has(i)&&(this.expandedKeys.add(i),s=!0);return s?e(this.expandedKeys):t}#E(e,t,r,o){this.#f=!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.#h.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.#h.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(`.${i}`))return this.toggle(t.__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)return b(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?y(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()}#G(e,t){const r=this.getActiveGroups(),{slots:o,groups:n}=this.#t?function(e,t){let r=e.slice();if(t.length>0){const o=/* @__PURE__ */new Map;e.forEach((e,t)=>o.set(e,t)),r=[];for(const{row:e}of t){const t=A(e)?e.__index:o.get(e);void 0!==t&&(r[t]=e)}}const o=r.filter(e=>null!=e&&!A(e));return{slots:r,groups:o}}(this.#e,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.#t?"number"==typeof s?function(e){const t=[];for(const r of e){if(null==r||A(r))break;t.push(r)}return t}(this.#e):this.preDefinedGroups:n,t=R(s,E(e));t.size>0&&(this.expandedKeys=new Set(t),this.hasAppliedDefaultExpanded=!0)}const i=k({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=A(i)?{row:i}:t[n++];r.set(a.row,s),o.push(a)}return o}(o,this.#E(i,e,e=>({row:e}),e=>K(n,e.key)?.rowCount??e.rows.length),this.#g)}getActiveGroups(){return this.preDefinedGroups.length>0?this.preDefinedGroups:Array.isArray(this.config.groups)?this.config.groups:[]}createToggleButton(e,t){const r=document.createElement("button");return r.type="button",r.className=`${i}${e?` ${s}`:""}`,r.setAttribute("aria-label",e?"Collapse group":"Expand group"),this.setIcon(r,e?"collapse":"expand"),r.addEventListener("click",e=>{e.stopPropagation(),t()}),r}getGroupLabelText(e,t,r){const o=this.config;return o.formatLabel?o.formatLabel(e,t,r):String(e)}renderFullWidthGroupRow(e,t,o){const n=this.config,s=n.aggregators??{},i=e.__groupRows??[],p=document.createElement("div");p.className="cell group-full",p.style.gridColumn="1 / -1",p.setAttribute("role","gridcell"),p.setAttribute("data-col","0"),p.appendChild(this.createToggleButton(e.__groupExpanded,o));const u=document.createElement("span");if(u.className=a,u.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey),p.appendChild(u),!1!==n.showRowCount){const t=document.createElement("span");t.className=d,t.textContent=`(${e.__groupRowCount??e.__groupRows?.length??0})`,p.appendChild(t)}const l=Object.entries(s);if(l.length>0){const e=document.createElement("span");e.className="group-aggregates";for(const[t,o]of l){const n=this.columns.find(e=>e.field===t),s=r.run(o,i,t,n);if(null!=s){const r=document.createElement("span");r.className="group-aggregate",r.setAttribute("data-field",t),r.textContent=`${n?.header??t}: ${s}`,e.appendChild(r)}}e.children.length>0&&p.appendChild(e)}t.appendChild(p)}renderPerColumnGroupRow(e,t,o){const n=this.config,s=n.aggregators??{},i=this.columns,a=e.__groupRows??[],p=(this.gridElement?.querySelector(".body"))?.style.gridTemplateColumns||"";p&&(t.style.display="grid",t.style.gridTemplateColumns=p);let u=!1;i.forEach((i,p)=>{const l=document.createElement("div");if(l.className="cell group-cell",l.setAttribute("data-col",String(p)),l.setAttribute("role","gridcell"),"__tbw_expander"===i.field)return l.setAttribute("data-field",i.field),void t.appendChild(l);if(u){const e=s[i.field];if(e){const t=r.run(e,a,i.field,i);l.textContent=null!=t?String(t):""}else l.textContent=""}else{u=!0,l.appendChild(this.createToggleButton(e.__groupExpanded,o));const t=document.createElement("span"),p=s[i.field];if(p){const o=r.run(p,a,i.field,i);t.textContent=String(null!=o?o:e.__groupValue)}else t.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey);if(l.appendChild(t),!1!==n.showRowCount){const e=document.createElement("span");e.className=d,e.textContent=` (${a.length})`,l.appendChild(e)}}t.appendChild(l)})}expandAll(){if(this.groupConfigDirty)return this.pendingExpansion=!0,this.expandedKeys=/* @__PURE__ */new Set,void this.requestRender();const e=function(e){const t=/* @__PURE__ */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.#s.delete(t);this.expandedKeys=e,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(("function"==typeof r.accordion?o&&r.accordion(o.depth):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=S(n,e);if(t){if(this.emit("group-expand",{groupKey:e,groupPath:r}),!this.groupRowsMap.has(e)){const t=K(n,e);t&&this.#x(e,t,r)}}else this.emit("group-collapse",{groupKey:e,groupPath:r})}const s=this.expandedKeys.has(e),i=null!=o?.value?String(o.value):e;if(s){const e=o?.rows?.length??0;p(this.gridElement,u(this.gridElement,"groupExpanded",i,e))}else p(this.gridElement,u(this.gridElement,"groupCollapsed",i));this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}expand(e){this.expandedKeys.has(e)||(this.expandedKeys=/* @__PURE__ */new Set([...this.expandedKeys,e]),this.#s.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=/* @__PURE__ */new Set,this.hasAppliedDefaultExpanded=!1),this.requestRender()}setGroups(e){this.#y(),this.preDefinedGroups=e,this.groupRowsMap.clear(),this.#m(),this.#s.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.#m(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.#m(e),null!=e?this.groupRowsMap.delete(e):this.groupRowsMap.clear(),this.requestRender()}};export{C as GroupingRowsPlugin};
1
+ import{BaseGridPlugin as e,DEFAULT_A11Y_MESSAGES as t,aggregatorRegistry as r}from"@toolbox-web/grid";import{HierarchyPlugin as o,buildHierarchy as n}from"@toolbox-web/grid/plugins/hierarchy";var s="expanded",i="group-toggle",a="group-label",d="group-count";function p(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 u(e,r,...o){const n=(e&&"effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.messages?.[r];return n?n(...o):t[r](...o)}var l="__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("")),h=(new RegExp(`__(proto|defineGetter|defineSetter)|${l.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("|"))),g=/^on\w+$/i,c=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),f=/^\s*(javascript|vbscript|data|blob):/i;function w(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(h.has(e)){t.push(o);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(e=>g.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();g.test(e)?r.push(t.name):"is"!==e?(c.has(e)&&f.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 y(e,t){t&&"string"==typeof t?-1!==t.indexOf("<")||-1!==t.indexOf("&")?e.replaceChildren(w(t)):e.textContent=t:e.replaceChildren()}function m(e,t){if(t){const r=t({size:e});if("string"==typeof r){const e=document.createElement("div");return y(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 v(e,t){if(!e.firstElementChild)return;const r=e.querySelector(":scope > .tbw-cell-loading-overlay");r&&(t?.unmount?.(r),r.remove())}function x(e,t){if(!e.firstElementChild)return;const r=e.querySelector(":scope > .tbw-row-loading-overlay");r&&(t?.unmount?.(r),r.remove())}function b(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{x(t,r);const e=t.children;for(let t=e.length-1;t>=0;t--){const o=e[t];v(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(m("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"),x(e,o)}(n,!0,e.effectiveConfig?.loadingRenderer)}var _={parent:null,depth:0};function R(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(e){return"group"!==e.kind?0:e.rows.length}function k({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),p=r.get(a.key)??[],u=o.has(a.key);if(s.push({kind:"group",key:a.key,value:a.value,depth:i,rows:p,expanded:d}),d)if(a.children?.length){const n=k({groups:a.children,expanded:t,groupRows:r,loadingGroups:o,parentPath:e});s.push(...n)}else u?s.push({kind:"data",row:{__loading:!0,__groupKey:a.key,__rowCacheKey:`__loading:group:${a.key}`},rowIndex:-1}):p.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 S(e){const t=[];for(const r of e)t.push(r.key),r.children?.length&&t.push(...S(r.children));return t}function K(e,t){for(const r of e){if(r.key===t)return r;const e=r.children?.length?K(r.children,t):void 0;if(e)return e}}function A(e){const t=e;return null!=t&&"object"==typeof t&&!0===t.__loading&&"number"==typeof t.__index}var C=class extends e{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 o},{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=/* @__PURE__ */new Set;flattenedRows=[];isActive=!1;previousVisibleKeys=/* @__PURE__ */new Set;keysToAnimate=/* @__PURE__ */new Set;hasAppliedDefaultExpanded=!1;pendingExpansion;groupConfigDirty=!1;preDefinedGroups=[];#e=[];#t=!1;#r;#o=/* @__PURE__ */new Set;groupRowsMap=/* @__PURE__ */new Map;loadingGroups=/* @__PURE__ */new Set;#n=/* @__PURE__ */new Map;#s=/* @__PURE__ */new Set;#i=!1;groupedFields=[];userGroupSortDirections=/* @__PURE__ */new Map;#a="groupOn";#d;#p=!1;#u;#l=!1;#h=/* @__PURE__ */new WeakMap;#g=/* @__PURE__ */new WeakMap;#c={owners:[],count:0};#f=!1;#w=/* @__PURE__ */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.#y(),this.#c={owners:[],count:0},this.groupRowsMap.clear(),this.#m(),this.#s.clear(),this.loadingGroups.clear(),this.groupedFields=[],this.userGroupSortDirections.clear(),this.#w.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.#a)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.#c,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.#t&&void 0!==t.generation&&t.generation===this.#r)return this.#v(r,t.startNode),void this.requestRender();const o=[...this.expandedKeys].filter(e=>this.groupRowsMap.has(e)||this.#n.has(e));this.#e=[],this.#t=void 0!==t.generation,this.#r=t.generation,this.hasAppliedDefaultExpanded||=this.expandedKeys.size>0,this.#v(r,this.#t?t.startNode:0),this.groupRowsMap.clear(),this.#m(),this.#s.clear(),this.loadingGroups.clear();for(const n of o){const e=K(this.preDefinedGroups,n);e&&this.#x(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.#n.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.#n.delete(r)&&(this.loadingGroups.delete(r),this.emit("group-load-error",{groupKey:r,groupPath:t.context.groupPath??[r],error:t.error}),this.requestRender())})}#m(e){for(const[t,r]of this.#n)null!=e&&t!==e||(r.abort(),this.#n.delete(t),this.loadingGroups.delete(t))}#y(){this.#e=[],this.#t=!1,this.#r=void 0,this.#o.clear()}#v(e,t){const r=Number.isInteger(t)&&t>0?t:0;for(let n=0;n<e.length;n++)this.#e[r+n]=e[n];this.preDefinedGroups=this.#e.filter(e=>null!=e);const o=!0===this.config.defaultExpanded&&this.hasAppliedDefaultExpanded;for(const n of S(e))o&&!this.#o.has(n)&&this.expandedKeys.add(n),this.#o.add(n)}#x(e,t,r){if(this.#s.add(e),this.loadingGroups.add(e),this.#n.has(e))return;const o=this.queryBoolean("datasource:is-active")?new AbortController:void 0;o&&this.#n.set(e,o),this.grid?.query?.("datasource:fetch-children",{context:{source:"grouping-rows",groupKey:e,group:t,groupPath:r},signal:o?.signal})}#b(e){return"group"===e.kind&&e.expanded&&!this.groupRowsMap.has(e.key)&&!this.loadingGroups.has(e.key)&&!this.#s.has(e.key)}#_(){this.#i||(this.#i=!0,queueMicrotask(()=>{this.#i=!1,this.#R()}))}#R(){if(!this.isActive||"predefined"!==this.#a)return;const e=this.queryBoolean("datasource:is-active"),t=this.getActiveGroups();let r=!1;for(const o of this.flattenedRows){if(!this.#b(o))continue;const n=E(t,o.key);if(!n.every(e=>this.expandedKeys.has(e)))continue;const s=K(t,o.key);e&&s&&!s.children?.length?(this.#x(o.key,s,n),r=!0):this.#s.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=_){const n=/* @__PURE__ */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=/* @__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._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):n(e,[this])}beginHierarchy(e){return this.#d=this.pendingExpansion,this.pendingExpansion=void 0,this.groupConfigDirty=!1,this.#p=!1,this.#f=!1,this.#h=/* @__PURE__ */new WeakMap,this.#g=/* @__PURE__ */new WeakMap,this.preDefinedGroups.length>0||Array.isArray(this.config.groups)?(this.#a="predefined",!0):"function"!=typeof this.config.groupOn?(this.isActive=!1,this.flattenedRows=[],this.groupedFields=[],!1):(this.#a="groupOn",this.groupedFields=[],this.#u=void 0,this.#l=!1,!0)}processSiblings(e,t){const r=null===t.parentKey&&null===t.parent;if("predefined"===this.#a)return r?this.#G(t.depth,e):e;const o=this.config,n=e.map(e=>e.row),s={parent:t.parent,depth:t.depth};this.#l||(this.#u=this.resolveGroupSortDirections(n,s),this.#l=this.groupedFields.length>0);const i=(e,i)=>function({rows:e,config:t,expanded:r,initialExpanded:o,groupSortDirections:n,context:s=_,keyPrefix:i=""}){const a=t.groupOn;if("function"!=typeof a)return[];const d={key:"__root__",value:null,depth:-1,rows:[],children:/* @__PURE__ */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:/* @__PURE__ */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 p=/* @__PURE__ */new Map;for(let c=0;c<e.length;c++)p.set(e[c],c);const u=/* @__PURE__ */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=[],g=e=>{if(e===d){for(const t of l(e))g(t);return}const t=u.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))g(r);else e.rows.forEach(e=>h.push({kind:"data",row:e,rowIndex:p.get(e)??-1}))};return g(d),h}({rows:n,config:o,expanded:e,initialExpanded:i,groupSortDirections:this.#u,context:s,keyPrefix:r?"":`${t.parentKey??""}::`}),a=r?this.#k(i):this.#E(i);if(0===a.length)return e;const d=/* @__PURE__ */new Map;for(const p of e)d.set(p.row,p);return this.#S(a,t.depth,e=>d.get(e)??{row:e},G)}endHierarchy(e){if(!this.#f)return this.isActive=!1,this.flattenedRows=[],!1;this.isActive=!0,this.flattenedRows=e.map(e=>this.#h.get(e)??{kind:"data",row:e,rowIndex:-1}),this.#p&&this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.keysToAnimate.clear();const t=/* @__PURE__ */new Set,r="predefined"===this.#a;r&&(this.#c=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.#g));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.#b(e))}),this.previousVisibleKeys=t,o&&this.#_(),!0}#k(e){const t=this.config,r=e(/* @__PURE__ */new Set);if(0===r.length)return r;const o=this.#d;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=R(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.#p=s,e(this.expandedKeys,i)}#E(e){const t=e(this.expandedKeys),r=this.#d;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?R(r,o):new Set(o.filter(e=>!this.#w.has(e)));void 0!==r&&(this.#p=!0);let s=!1;for(const i of o)this.#w.add(i),n.has(i)&&!this.expandedKeys.has(i)&&(this.expandedKeys.add(i),s=!0);return s?e(this.expandedKeys):t}#S(e,t,r,o){this.#f=!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.#h.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.#h.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(`.${i}`))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 b(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?y(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()}#G(e,t){const r=this.getActiveGroups(),{slots:o,groups:n}=this.#t?function(e,t){let r=e.slice();if(t.length>0){const o=/* @__PURE__ */new Map;e.forEach((e,t)=>o.set(e,t)),r=[];for(const{row:e}of t){const t=A(e)?e.__index:o.get(e);void 0!==t&&(r[t]=e)}}const o=r.filter(e=>null!=e&&!A(e));return{slots:r,groups:o}}(this.#e,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.#t?"number"==typeof s?function(e){const t=[];for(const r of e){if(null==r||A(r))break;t.push(r)}return t}(this.#e):this.preDefinedGroups:n,t=R(s,S(e));t.size>0&&(this.expandedKeys=new Set(t),this.hasAppliedDefaultExpanded=!0)}const i=k({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=A(i)?{row:i}:t[n++];r.set(a.row,s),o.push(a)}return o}(o,this.#S(i,e,e=>({row:e}),e=>K(n,e.key)?.rowCount??e.rows.length),this.#g)}getActiveGroups(){return this.preDefinedGroups.length>0?this.preDefinedGroups:Array.isArray(this.config.groups)?this.config.groups:[]}createToggleButton(e,t){const r=document.createElement("button");return r.type="button",r.className=`${i}${e?` ${s}`:""}`,r.setAttribute("aria-label",e?"Collapse group":"Expand group"),this.setIcon(r,e?"collapse":"expand"),r.addEventListener("click",e=>{e.stopPropagation(),t()}),r}getGroupLabelText(e,t,r){const o=this.config;return o.formatLabel?o.formatLabel(e,t,r):String(e)}renderFullWidthGroupRow(e,t,o){const n=this.config,s=n.aggregators??{},i=e.__groupRows??[],p=document.createElement("div");p.className="cell group-full",p.style.gridColumn="1 / -1",p.setAttribute("role","gridcell"),p.setAttribute("data-col","0"),p.appendChild(this.createToggleButton(e.__groupExpanded,o));const u=document.createElement("span");if(u.className=a,u.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey),p.appendChild(u),!1!==n.showRowCount){const t=document.createElement("span");t.className=d,t.textContent=`(${e.__groupRowCount??e.__groupRows?.length??0})`,p.appendChild(t)}const l=Object.entries(s);if(l.length>0){const e=document.createElement("span");e.className="group-aggregates";for(const[t,o]of l){const n=this.columns.find(e=>e.field===t),s=r.run(o,i,t,n);if(null!=s){const r=document.createElement("span");r.className="group-aggregate",r.setAttribute("data-field",t),r.textContent=`${n?.header??t}: ${s}`,e.appendChild(r)}}e.children.length>0&&p.appendChild(e)}t.appendChild(p)}renderPerColumnGroupRow(e,t,o){const n=this.config,s=n.aggregators??{},i=this.columns,a=e.__groupRows??[],p=(this.gridElement?.querySelector(".body"))?.style.gridTemplateColumns||"";p&&(t.style.display="grid",t.style.gridTemplateColumns=p);let u=!1;i.forEach((i,p)=>{const l=document.createElement("div");if(l.className="cell group-cell",l.setAttribute("data-col",String(p)),l.setAttribute("role","gridcell"),"__tbw_expander"===i.field)return l.setAttribute("data-field",i.field),void t.appendChild(l);if(u){const e=s[i.field];if(e){const t=r.run(e,a,i.field,i);l.textContent=null!=t?String(t):""}else l.textContent=""}else{u=!0,l.appendChild(this.createToggleButton(e.__groupExpanded,o));const t=document.createElement("span"),p=s[i.field];if(p){const o=r.run(p,a,i.field,i);t.textContent=String(null!=o?o:e.__groupValue)}else t.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey);if(l.appendChild(t),!1!==n.showRowCount){const e=document.createElement("span");e.className=d,e.textContent=` (${a.length})`,l.appendChild(e)}}t.appendChild(l)})}expandAll(){if(this.groupConfigDirty)return this.pendingExpansion=!0,this.expandedKeys=/* @__PURE__ */new Set,void this.requestRender();const e=function(e){const t=/* @__PURE__ */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.#s.delete(t);this.expandedKeys=e,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(("function"==typeof r.accordion?o&&r.accordion(o.depth):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=E(n,e);if(t){if(this.emit("group-expand",{groupKey:e,groupPath:r}),!this.groupRowsMap.has(e)){const t=K(n,e);t&&this.#x(e,t,r)}}else this.emit("group-collapse",{groupKey:e,groupPath:r})}const s=this.expandedKeys.has(e),i=null!=o?.value?String(o.value):e;if(s){const e=o?.rows?.length??0;p(this.gridElement,u(this.gridElement,"groupExpanded",i,e))}else p(this.gridElement,u(this.gridElement,"groupCollapsed",i));this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}expand(e){this.expandedKeys.has(e)||(this.expandedKeys=/* @__PURE__ */new Set([...this.expandedKeys,e]),this.#s.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=/* @__PURE__ */new Set,this.hasAppliedDefaultExpanded=!1),this.requestRender()}setGroups(e){this.#y(),this.preDefinedGroups=e,this.groupRowsMap.clear(),this.#m(),this.#s.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.#m(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.#m(e),null!=e?this.groupRowsMap.delete(e):this.groupRowsMap.clear(),this.requestRender()}};export{C as GroupingRowsPlugin};
2
2
  //# sourceMappingURL=index.js.map