@toolbox-web/grid 3.9.1 → 3.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/all.js +1 -1
  2. package/all.js.map +1 -1
  3. package/custom-elements.json +2 -2
  4. package/index.js +1 -1
  5. package/index.js.map +1 -1
  6. package/lib/core/grid.d.ts +8 -4
  7. package/lib/core/plugin/base-plugin.d.ts +7 -0
  8. package/lib/core/types.d.ts +2 -0
  9. package/lib/features/registry.js +1 -1
  10. package/lib/plugins/context-menu/context-menu-plugin.d.ts +9 -4
  11. package/lib/plugins/context-menu/index.js +1 -1
  12. package/lib/plugins/context-menu/index.js.map +1 -1
  13. package/lib/plugins/context-menu/types.d.ts +8 -4
  14. package/lib/plugins/editing/index.js +1 -1
  15. package/lib/plugins/editing/index.js.map +1 -1
  16. package/lib/plugins/editing/internal/dirty-tracking-manager.d.ts +2 -1
  17. package/lib/plugins/filtering/filter-model.d.ts +2 -1
  18. package/lib/plugins/filtering/filtering-plugin.d.ts +5 -2
  19. package/lib/plugins/filtering/index.js +1 -1
  20. package/lib/plugins/filtering/index.js.map +1 -1
  21. package/lib/plugins/grouping-rows/grouping-rows-plugin.d.ts +7 -14
  22. package/lib/plugins/grouping-rows/grouping-rows.d.ts +48 -0
  23. package/lib/plugins/grouping-rows/index.d.ts +1 -1
  24. package/lib/plugins/grouping-rows/index.js +1 -1
  25. package/lib/plugins/grouping-rows/index.js.map +1 -1
  26. package/lib/plugins/grouping-rows/types.d.ts +21 -0
  27. package/lib/plugins/master-detail/index.d.ts +1 -1
  28. package/lib/plugins/master-detail/index.js +1 -1
  29. package/lib/plugins/master-detail/index.js.map +1 -1
  30. package/lib/plugins/master-detail/master-detail-plugin.d.ts +28 -6
  31. package/lib/plugins/master-detail/master-detail.d.ts +0 -8
  32. package/lib/plugins/master-detail/types.d.ts +25 -1
  33. package/lib/plugins/multi-sort/index.js +1 -1
  34. package/lib/plugins/multi-sort/index.js.map +1 -1
  35. package/lib/plugins/selection/index.js +1 -1
  36. package/lib/plugins/selection/index.js.map +1 -1
  37. package/lib/plugins/selection/selection-plugin.d.ts +8 -1
  38. package/lib/plugins/server-side/datasource-types.d.ts +28 -0
  39. package/lib/plugins/server-side/datasource.d.ts +7 -0
  40. package/lib/plugins/server-side/index.js +1 -1
  41. package/lib/plugins/server-side/index.js.map +1 -1
  42. package/lib/plugins/server-side/server-side-plugin.d.ts +61 -8
  43. package/lib/plugins/server-side/types.d.ts +9 -1
  44. package/lib/plugins/tree/index.js +1 -1
  45. package/lib/plugins/tree/index.js.map +1 -1
  46. package/lib/plugins/tree/tree-plugin.d.ts +5 -11
  47. package/lib/plugins/tree/types.d.ts +22 -6
  48. package/lib/plugins/undo-redo/history.d.ts +2 -1
  49. package/lib/plugins/undo-redo/index.js +1 -1
  50. package/lib/plugins/undo-redo/index.js.map +1 -1
  51. package/lib/plugins/undo-redo/types.d.ts +13 -1
  52. package/lib/plugins/undo-redo/undo-redo-plugin.d.ts +15 -2
  53. package/package.json +1 -1
  54. package/umd/grid.all.umd.js +1 -1
  55. package/umd/grid.all.umd.js.map +1 -1
  56. package/umd/grid.umd.js +1 -1
  57. package/umd/grid.umd.js.map +1 -1
  58. package/umd/plugins/context-menu.umd.js +1 -1
  59. package/umd/plugins/context-menu.umd.js.map +1 -1
  60. package/umd/plugins/editing.umd.js +1 -1
  61. package/umd/plugins/editing.umd.js.map +1 -1
  62. package/umd/plugins/filtering.umd.js +1 -1
  63. package/umd/plugins/filtering.umd.js.map +1 -1
  64. package/umd/plugins/grouping-rows.umd.js +1 -1
  65. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  66. package/umd/plugins/master-detail.umd.js +1 -1
  67. package/umd/plugins/master-detail.umd.js.map +1 -1
  68. package/umd/plugins/multi-sort.umd.js +1 -1
  69. package/umd/plugins/multi-sort.umd.js.map +1 -1
  70. package/umd/plugins/selection.umd.js +1 -1
  71. package/umd/plugins/selection.umd.js.map +1 -1
  72. package/umd/plugins/server-side.umd.js +1 -1
  73. package/umd/plugins/server-side.umd.js.map +1 -1
  74. package/umd/plugins/tree.umd.js +1 -1
  75. package/umd/plugins/tree.umd.js.map +1 -1
  76. package/umd/plugins/undo-redo.umd.js +1 -1
  77. package/umd/plugins/undo-redo.umd.js.map +1 -1
@@ -164,11 +164,6 @@ export declare class GroupingRowsPlugin extends BaseGridPlugin<GroupingRowsConfi
164
164
  * @internal
165
165
  */
166
166
  handleQuery(query: PluginQuery): unknown;
167
- /**
168
- * Translate a flat row index to the top-level group index it belongs to.
169
- * Walks flattenedRows up to the given index and counts depth-0 groups encountered.
170
- */
171
- private getTopLevelGroupIndex;
172
167
  /** @internal */
173
168
  attach(grid: GridElement): void;
174
169
  /**
@@ -211,18 +206,10 @@ export declare class GroupingRowsPlugin extends BaseGridPlugin<GroupingRowsConfi
211
206
  renderRow(row: any, rowEl: HTMLElement, rowIndex: number): boolean;
212
207
  /** @internal */
213
208
  afterRender(): void;
214
- /**
215
- * Collect all group keys from a pre-defined group tree.
216
- */
217
- private collectGroupKeys;
218
209
  /**
219
210
  * Get the active group definitions (pre-defined or empty).
220
211
  */
221
212
  private getActiveGroups;
222
- /**
223
- * Find a group definition by key in the pre-defined group tree.
224
- */
225
- private findGroupDefinition;
226
213
  /**
227
214
  * Create a toggle button for expanding/collapsing a group.
228
215
  */
@@ -241,6 +228,9 @@ export declare class GroupingRowsPlugin extends BaseGridPlugin<GroupingRowsConfi
241
228
  * call defers until the next render rebuilds the group model against the
242
229
  * new `groupOn` (issue #335). The `group-toggle` event is emitted once
243
230
  * the new keys are known.
231
+ *
232
+ * With `ServerSidePlugin` active, every newly expanded pre-defined group
233
+ * requests its rows via `getChildRows()` after the next render (#534).
244
234
  */
245
235
  expandAll(): void;
246
236
  /**
@@ -265,6 +255,8 @@ export declare class GroupingRowsPlugin extends BaseGridPlugin<GroupingRowsConfi
265
255
  isExpanded(key: string): boolean;
266
256
  /**
267
257
  * Expand a specific group.
258
+ * With `ServerSidePlugin` active, an expanded pre-defined group without rows requests
259
+ * them via `getChildRows()` after the next render, like {@link toggle}.
268
260
  * @param key - The group key to expand
269
261
  */
270
262
  expand(key: string): void;
@@ -381,7 +373,8 @@ export declare class GroupingRowsPlugin extends BaseGridPlugin<GroupingRowsConfi
381
373
  * Clear cached row data for one or all groups.
382
374
  *
383
375
  * Use when the server data has changed and groups need to be re-fetched
384
- * on next expand.
376
+ * on next expand. Also cancels any in-flight ServerSide fetch for the
377
+ * cleared groups, so a stale response cannot repopulate them.
385
378
  *
386
379
  * @param groupKey - Specific group key to clear, or omit to clear all
387
380
  */
@@ -1,3 +1,4 @@
1
+ import { HierarchyNode } from '../hierarchy';
1
2
  import { DefaultExpandedValue, GroupDefinition, GroupingRowsConfig, GroupOnContext, RenderRow } from './types';
2
3
  interface BuildGroupingArgs {
3
4
  rows: any[];
@@ -108,4 +109,51 @@ export declare function buildPreDefinedGroupModel({ groups, expanded, groupRows,
108
109
  * @returns Array of group keys from root to target, or empty array if not found
109
110
  */
110
111
  export declare function getGroupPath(groups: GroupDefinition[], targetKey: string, parentPath?: string[]): string[];
112
+ /** Every group key of a pre-defined group tree, depth-first. */
113
+ export declare function collectGroupKeys(groups: GroupDefinition[]): string[];
114
+ /** Find a group definition by key anywhere in a pre-defined group tree. */
115
+ export declare function findGroupDefinition(groups: GroupDefinition[], key: string): GroupDefinition | undefined;
116
+ /** A ServerSide loading placeholder standing in for an unloaded root node (mirrors `isLoadingPlaceholder`). */
117
+ export declare function isRootPlaceholder(row: unknown): row is {
118
+ __loading: true;
119
+ __index: number;
120
+ };
121
+ /**
122
+ * The definitions before the first gap or placeholder — the contiguous run from node 0.
123
+ * A numeric `defaultExpanded` (a depth-first key index) resolves against the leading LOADED
124
+ * definitions (`#nodeGroups`, never the filtered render slots), so blocks landing out of order
125
+ * cannot shift it onto a later group.
126
+ */
127
+ export declare function leadingGroups(slots: readonly unknown[]): GroupDefinition[];
128
+ /**
129
+ * Node-indexed root slots. ServerSide's root list (`input`) is authoritative: a placeholder sits
130
+ * at its `__index`, and a definition renders only while ServerSide still lists that object — at
131
+ * its node index in `nodeGroups` (sparse, by node index). So definitions whose block ServerSide
132
+ * dropped (`purgeCache()`, an infinite-scroll estimate that shrank) or that a local filter
133
+ * removed do not render. An empty `input` means no node count yet (a refetch in flight, or no
134
+ * ServerSide input) → the loaded definitions. `groups` = the rendered definitions, in node order.
135
+ */
136
+ export declare function buildRootSlots(nodeGroups: readonly (GroupDefinition | undefined)[], input: readonly HierarchyNode[]): {
137
+ slots: unknown[];
138
+ groups: GroupDefinition[];
139
+ };
140
+ /**
141
+ * Root list in node order: `groupNodes[k]` (the node of the k-th definition in `slots`) or a
142
+ * placeholder node. Records each root's node index (slot index) in `rootIndexOf`.
143
+ */
144
+ export declare function interleaveRootNodes(slots: readonly unknown[], groupNodes: readonly HierarchyNode[], rootIndexOf: WeakMap<object, number>): HierarchyNode[];
145
+ /** Index-aligned with `rows`: node index of the root each rendered row belongs to, plus the root count. */
146
+ export declare function computeRootOwners(rows: readonly unknown[], rootIndexOf: WeakMap<object, number>): {
147
+ owners: number[];
148
+ count: number;
149
+ };
150
+ /** Translate a rendered row range to the root nodes that own it (see {@link computeRootOwners}). */
151
+ export declare function mapViewportToNodes({ owners, count }: {
152
+ owners: readonly number[];
153
+ count: number;
154
+ }, viewportStart: number, viewportEnd: number): {
155
+ startNode: number;
156
+ endNode: number;
157
+ totalLoadedNodes: number;
158
+ };
111
159
  export {};
@@ -6,4 +6,4 @@
6
6
  */
7
7
  export { GroupingRowsPlugin } from './grouping-rows-plugin';
8
8
  export type { GroupState } from './grouping-rows-plugin';
9
- export type { AggregatorMap, DataRowModelItem, DefaultExpandedValue, GroupCollapseDetail, GroupDefinition, GroupExpandDetail, GroupingRowsConfig, GroupOnContext, GroupRowModelItem, GroupRowRenderParams, GroupToggleDetail, RenderRow, } from './types';
9
+ export type { AggregatorMap, DataRowModelItem, DefaultExpandedValue, GroupCollapseDetail, GroupDefinition, GroupExpandDetail, GroupingRowsConfig, GroupLoadErrorDetail, GroupOnContext, GroupRowModelItem, GroupRowRenderParams, GroupToggleDetail, RenderRow, } from './types';
@@ -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 i="expanded",s="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("")),g=(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("|"))),c=/^on\w+$/i,h=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(g.has(e)){t.push(o);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(e=>c.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();c.test(e)?r.push(t.name):"is"!==e?(h.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 x(e,t){if(!e.firstElementChild)return;const r=e.querySelector(":scope > .tbw-cell-loading-overlay");r&&(t?.unmount?.(r),r.remove())}function v(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 i=e._getPluginRowHeight?.(r,o),s=void 0!==i&&i>0?`${i}px`:"";n.height!==s&&(n.height=s)}(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{v(t,r);const e=t.children;for(let t=e.length-1;t>=0;t--){const o=e[t];x(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 i=document.createElement("div");i.className="cell",i.style.gridColumn="1 / -1",i.setAttribute("role","gridcell"),i.textContent=" ",n.appendChild(i),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"),v(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 k(e){return"group"!==e.kind?0:e.rows.length}function E({groups:e,expanded:t,groupRows:r,loadingGroups:o,parentPath:n=[]}){const i=[],s=n.length;for(const a of e){const e=[...n,a.key],d=t.has(a.key),p=r.get(a.key)??[],u=o.has(a.key);if(i.push({kind:"group",key:a.key,value:a.value,depth:s,rows:p,expanded:d}),d)if(a.children?.length){const n=E({groups:a.children,expanded:t,groupRows:r,loadingGroups:o,parentPath:e});i.push(...n)}else u?i.push({kind:"data",row:{__loading:!0,__groupKey:a.key,__rowCacheKey:`__loading:group:${a.key}`},rowIndex:-1}):p.forEach((e,t)=>{i.push({kind:"data",row:e,rowIndex:t})})}return i}function A(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=A(o.children,t,e);if(r.length>0)return r}}return[]}var S=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."}],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=[];groupRowsMap=/* @__PURE__ */new Map;loadingGroups=/* @__PURE__ */new Set;groupedFields=[];userGroupSortDirections=/* @__PURE__ */new Map;#e="groupOn";#t;#r=!1;#o;#n=!1;#i=/* @__PURE__ */new WeakMap;#s=!1;#a=/* @__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.groupRowsMap.clear(),this.loadingGroups.clear(),this.groupedFields=[],this.userGroupSortDirections.clear(),this.#a.clear()}getRowHeight(e,t){if(null!=this.config.groupRowHeight)return!0===e.__isGroupRow?this.config.groupRowHeight:void 0}handleQuery(e){if("canMoveRow"===e.type&&!0===e.context?.__isGroupRow)return!1;if("grouping:get-grouped-fields"===e.type)return[...this.groupedFields];if("datasource:viewport-mapping"===e.type){const{viewportStart:t,viewportEnd:r}=e.context;if(0===this.flattenedRows.length)return;if(0===this.preDefinedGroups.length&&!Array.isArray(this.config.groups))return;const o=this.getActiveGroups();return{startNode:this.getTopLevelGroupIndex(t),endNode:this.getTopLevelGroupIndex(r)+1,totalLoadedNodes:o.length}}}getTopLevelGroupIndex(e){let t=-1;const r=Math.min(e,this.flattenedRows.length-1);for(let o=0;o<=r;o++){const e=this.flattenedRows[o];"group"===e.kind&&0===e.depth&&t++}return Math.max(0,t)}attach(e){super.attach(e),this.on("datasource:data",e=>{const t=e;t.claimed||(t.claimed=!0,this.preDefinedGroups=t.rows,this.groupRowsMap.clear(),this.loadingGroups.clear(),this.hasAppliedDefaultExpanded=!1,this.requestRender())}),this.on("datasource:children",e=>{const t=e;if("grouping-rows"!==t.context?.source)return;t.claimed=!0;const r=t.context.groupKey;r&&(this.groupRowsMap.set(r,t.rows),this.loadingGroups.delete(r),this.requestRender())})}onHeaderClick(e){const t=this.groupedFields.indexOf(e.field);if(-1===t)return;if(!e.column.sortable)return;const r=t,o=this.userGroupSortDirections.get(r)??1;return this.userGroupSortDirections.set(r,1===o?-1:1),this.requestRender(),!0}resolveGroupSortDirections(e,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 i,s=null;for(const a of e)if(s=t(a,o),null!=s&&!1!==s){i=a;break}if(void 0===i)return n;Array.isArray(s)||(s=[s]);for(let a=0;a<s.length;a++){const e=s[a];for(const t of r)if(i[t]===e){n.set(a,t);break}}return n}([...e],r.groupOn,o,t);if(this.groupedFields=[...n.values()],0===n.size)return;const i=new Map(this.userGroupSortDirections);if(i.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(!i.has(r)){const t=e.get(o);void 0!==t&&i.set(r,t)}}return i.size>0?i: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.#t=this.pendingExpansion,this.pendingExpansion=void 0,this.groupConfigDirty=!1,this.#r=!1,this.#s=!1,this.#i=/* @__PURE__ */new WeakMap,this.preDefinedGroups.length>0||Array.isArray(this.config.groups)?(this.#e="predefined",!0):"function"!=typeof this.config.groupOn?(this.isActive=!1,this.flattenedRows=[],this.groupedFields=[],!1):(this.#e="groupOn",this.groupedFields=[],this.#o=void 0,this.#n=!1,!0)}processSiblings(e,t){const r=null===t.parentKey&&null===t.parent;if("predefined"===this.#e)return r?this.#d(t.depth):e;const o=this.config,n=e.map(e=>e.row),i={parent:t.parent,depth:t.depth};this.#n||(this.#o=this.resolveGroupSortDirections(n,i),this.#n=this.groupedFields.length>0);const s=(e,s)=>function({rows:e,config:t,expanded:r,initialExpanded:o,groupSortDirections:n,context:i=_,keyPrefix:s=""}){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,i);null==t||!1===t?t=["__ungrouped__"]:Array.isArray(t)||(t=[t]);let r=d;t.forEach((t,o)=>{const n=null==t?"∅":String(t),i="__root__"===r.key?s+n:r.key+"||"+n;let a=r.children.get(n);a||(a={key:i,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 h=0;h<e.length;h++)p.set(e[h],h);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},g=[],c=e=>{if(e===d){for(const t of l(e))c(t);return}const t=u.has(e.key);if(g.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=>g.push({kind:"data",row:e,rowIndex:p.get(e)??-1}))};return c(d),g}({rows:n,config:o,expanded:e,initialExpanded:s,groupSortDirections:this.#o,context:i,keyPrefix:r?"":`${t.parentKey??""}::`}),a=r?this.#p(s):this.#u(s);if(0===a.length)return e;const d=/* @__PURE__ */new Map;for(const p of e)d.set(p.row,p);return this.#l(a,t.depth,e=>d.get(e)??{row:e},k)}endHierarchy(e){if(!this.#s)return this.isActive=!1,this.flattenedRows=[],!1;this.isActive=!0,this.flattenedRows=e.map(e=>this.#i.get(e)??{kind:"data",row:e,rowIndex:-1}),this.#r&&this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.keysToAnimate.clear();const t=/* @__PURE__ */new Set;return this.flattenedRows.forEach((e,r)=>{if("data"===e.kind){const e=`data-${r}`;t.add(e),this.previousVisibleKeys.has(e)||this.keysToAnimate.add(e)}}),this.previousVisibleKeys=t,!0}#p(e){const t=this.config,r=e(/* @__PURE__ */new Set);if(0===r.length)return r;const o=this.#t;let n;const i=void 0!==o;let s;if(i?n=o:this.hasAppliedDefaultExpanded||0!==this.expandedKeys.size||!1===t.defaultExpanded||(n=t.defaultExpanded??!1),void 0!==n){s=R(n,r.filter(e=>"group"===e.kind).map(e=>e.key)),(i||s.size>0)&&(this.expandedKeys=new Set(s),this.hasAppliedDefaultExpanded=!0)}return this.#r=i,e(this.expandedKeys,s)}#u(e){const t=e(this.expandedKeys),r=this.#t;if(void 0===r&&!0!==this.config.defaultExpanded)return t;const o=[];for(const s of t)"group"===s.kind&&0===s.depth&&o.push(s.key);const n=void 0!==r?R(r,o):new Set(o.filter(e=>!this.#a.has(e)));void 0!==r&&(this.#r=!0);let i=!1;for(const s of o)this.#a.add(s),n.has(s)&&!this.expandedKeys.has(s)&&(this.expandedKeys.add(s),i=!0);return i?e(this.expandedKeys):t}#l(e,t,r,o){this.#s=!0;const n=[],i=[];for(const s of e){if("data"===s.kind){const e=r(s.row);(i.length>0?i[i.length-1].children:n).push(e),"object"==typeof s.row&&null!==s.row&&this.#i.set(s.row,s);continue}const e=0===t?s:{...s,depth:t+s.depth},a={__isGroupRow:!0,__groupKey:s.key,__groupValue:s.value,__groupDepth:e.depth,__groupRows:s.rows,__groupExpanded:s.expanded,__groupRowCount:o(s),__rowCacheKey:`group:${s.key}`};this.#i.set(a,e);const d={row:a,key:s.key,expanded:s.expanded,shaped:!0,children:[]};i.length=s.depth,(s.depth>0?i[s.depth-1].children:n).push(d),i.push(d)}return n}onCellClick(e){const t=e.row;if(t?.__isGroupRow&&e.originalEvent.target?.closest(`.${s}`))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()}#d(e){const t=this.getActiveGroups();if(0===t.length)return[];if(!this.hasAppliedDefaultExpanded&&0===this.expandedKeys.size&&!1!==this.config.defaultExpanded){const e=this.collectGroupKeys(t),r=R(this.config.defaultExpanded??!1,e);r.size>0&&(this.expandedKeys=new Set(r),this.hasAppliedDefaultExpanded=!0)}const r=E({groups:t,expanded:this.expandedKeys,groupRows:this.groupRowsMap,loadingGroups:this.loadingGroups});return this.#l(r,e,e=>({row:e}),e=>this.findGroupDefinition(t,e.key)?.rowCount??e.rows.length)}collectGroupKeys(e){const t=[];for(const r of e)t.push(r.key),r.children?.length&&t.push(...this.collectGroupKeys(r.children));return t}getActiveGroups(){return this.preDefinedGroups.length>0?this.preDefinedGroups:Array.isArray(this.config.groups)?this.config.groups:[]}findGroupDefinition(e,t){for(const r of e){if(r.key===t)return r;if(r.children?.length){const e=this.findGroupDefinition(r.children,t);if(e)return e}}}createToggleButton(e,t){const r=document.createElement("button");return r.type="button",r.className=`${s}${e?` ${i}`:""}`,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,i=n.aggregators??{},s=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(i);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),i=r.run(o,s,t,n);if(null!=i){const r=document.createElement("span");r.className="group-aggregate",r.setAttribute("data-field",t),r.textContent=`${n?.header??t}: ${i}`,e.appendChild(r)}}e.children.length>0&&p.appendChild(e)}t.appendChild(p)}renderPerColumnGroupRow(e,t,o){const n=this.config,i=n.aggregators??{},s=this.columns,a=e.__groupRows??[],p=(this.gridElement?.querySelector(".body"))?.style.gridTemplateColumns||"";p&&(t.style.display="grid",t.style.gridTemplateColumns=p);let u=!1;s.forEach((s,p)=>{const l=document.createElement("div");if(l.className="cell group-cell",l.setAttribute("data-col",String(p)),l.setAttribute("role","gridcell"),"__tbw_expander"===s.field)return l.setAttribute("data-field",s.field),void t.appendChild(l);if(u){const e=i[s.field];if(e){const t=r.run(e,a,s.field,s);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=i[s.field];if(p){const o=r.run(p,a,s.field,s);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();this.expandedKeys=function(e){const t=/* @__PURE__ */new Set;for(const r of e)"group"===r.kind&&t.add(r.key);return t}(this.flattenedRows),this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}collapseAll(){if(this.groupConfigDirty)return this.pendingExpansion=!1,this.expandedKeys=/* @__PURE__ */new Set,void this.requestRender();this.expandedKeys=/* @__PURE__ */new Set,this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}toggle(e){const t=!this.expandedKeys.has(e),r=this.config,o=this.flattenedRows.find(t=>"group"===t.kind&&t.key===e);if(("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=A(n,e);if(t){if(this.emit("group-expand",{groupKey:e,groupPath:r}),!this.groupRowsMap.has(e)){const t=this.findGroupDefinition(n,e);t&&(this.loadingGroups.add(e),this.grid?.query?.("datasource:fetch-children",{context:{source:"grouping-rows",groupKey:e,group:t,groupPath:r}}))}}else this.emit("group-collapse",{groupKey:e,groupPath:r})}const i=this.expandedKeys.has(e),s=null!=o?.value?String(o.value):e;if(i){const e=o?.rows?.length??0;p(this.gridElement,u(this.gridElement,"groupExpanded",s,e))}else p(this.gridElement,u(this.gridElement,"groupCollapsed",s));this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}expand(e){this.expandedKeys.has(e)||(this.expandedKeys=/* @__PURE__ */new Set([...this.expandedKeys,e]),this.requestRender())}collapse(e){if(this.expandedKeys.has(e)){const t=new Set(this.expandedKeys);t.delete(e),this.expandedKeys=t,this.requestRender()}}getGroupState(){const e=this.flattenedRows.filter(e=>"group"===e.kind);return{isActive:this.isActive,expandedCount:this.expandedKeys.size,totalGroups:e.length,expandedKeys:[...this.expandedKeys]}}getRowCount(){return this.flattenedRows.length}refreshGroups(){this.requestRender()}getExpandedGroups(){return[...this.expandedKeys]}getFlattenedRows(){return this.flattenedRows}isGroupingActive(){return this.isActive}setGroupOn(e,t){this.config.groupOn=e,this.groupConfigDirty=!0,void 0!==t&&(this.pendingExpansion=t,this.expandedKeys=/* @__PURE__ */new Set,this.hasAppliedDefaultExpanded=!1),this.requestRender()}setGroups(e){this.preDefinedGroups=e,this.groupRowsMap.clear(),this.loadingGroups.clear(),this.expandedKeys.clear(),this.hasAppliedDefaultExpanded=!1,this.requestRender()}getGroups(){return this.preDefinedGroups.length>0?[...this.preDefinedGroups]:Array.isArray(this.config.groups)?[...this.config.groups]:[]}setGroupRows(e,t){this.groupRowsMap.set(e,t),this.loadingGroups.delete(e),this.requestRender()}setGroupLoading(e,t){t?this.loadingGroups.add(e):this.loadingGroups.delete(e),this.requestRender()}clearGroupRows(e){null!=e?this.groupRowsMap.delete(e):this.groupRowsMap.clear(),this.requestRender()}};export{S 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 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};
2
2
  //# sourceMappingURL=index.js.map