@toolbox-web/grid 3.10.0 → 3.10.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.
- package/all.js +2 -1
- package/all.js.map +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/lib/features/registry.js +1 -1
- package/lib/plugins/editing/editing-plugin.d.ts +11 -5
- package/lib/plugins/editing/index.js +2 -1
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/editing/internal/editor-injection.d.ts +9 -2
- package/lib/plugins/editing/internal/helpers.d.ts +23 -0
- package/lib/plugins/editing/types.d.ts +11 -0
- package/lib/plugins/grouping-rows/index.js +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/hierarchy/hierarchy.d.ts +5 -1
- package/lib/plugins/hierarchy/index.js +1 -1
- package/lib/plugins/hierarchy/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js +1 -1
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/master-detail/master-detail-plugin.d.ts +6 -1
- package/lib/plugins/shared/structural-toggle.d.ts +14 -0
- package/lib/plugins/tree/index.js +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.d.ts +1 -1
- package/lib/plugins/undo-redo/index.js +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/undo-redo/types.d.ts +20 -2
- package/lib/plugins/undo-redo/undo-redo-plugin.d.ts +8 -0
- package/package.json +1 -1
- package/umd/grid.all.umd.js +1 -1
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +1 -1
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/editing.umd.js +1 -1
- package/umd/plugins/editing.umd.js.map +1 -1
- package/umd/plugins/grouping-rows.umd.js +1 -1
- package/umd/plugins/grouping-rows.umd.js.map +1 -1
- package/umd/plugins/hierarchy.umd.js +1 -1
- package/umd/plugins/hierarchy.umd.js.map +1 -1
- package/umd/plugins/master-detail.umd.js +1 -1
- package/umd/plugins/master-detail.umd.js.map +1 -1
- package/umd/plugins/tree.umd.js +1 -1
- package/umd/plugins/tree.umd.js.map +1 -1
- package/umd/plugins/undo-redo.umd.js +1 -1
- package/umd/plugins/undo-redo.umd.js.map +1 -1
|
@@ -17,9 +17,16 @@ export interface EditorInjectionDeps<T> {
|
|
|
17
17
|
editorValueCallbacks: Map<string, (newValue: unknown) => void>;
|
|
18
18
|
/** Returns `true` when an edit session is active (#activeEditRow !== -1). */
|
|
19
19
|
isEditSessionActive: () => boolean;
|
|
20
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Commit a single cell value change. `rowIndex` is honoured in grid mode only — in
|
|
22
|
+
* row mode the plugin substitutes the active edit row, because editors outlive
|
|
23
|
+
* their row moving to another index and this index can be stale (#572).
|
|
24
|
+
*/
|
|
21
25
|
commitCellValue: (rowIndex: number, column: ColumnConfig<T>, newValue: unknown, rowData: T) => void;
|
|
22
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Exit editing for a row (commit or revert). `rowIndex` is honoured in grid mode
|
|
28
|
+
* only — row mode always exits the active edit row (#572).
|
|
29
|
+
*/
|
|
23
30
|
exitRowEdit: (rowIndex: number, revert: boolean) => void;
|
|
24
31
|
}
|
|
25
32
|
/**
|
|
@@ -58,6 +58,11 @@ export declare function wireEditorInputs(editorHost: HTMLElement, column: Column
|
|
|
58
58
|
* ```ts
|
|
59
59
|
* if (shouldPreventEditClose(config, e)) return;
|
|
60
60
|
* ```
|
|
61
|
+
*
|
|
62
|
+
* The callback is consulted at most once per event (#558): one keystroke
|
|
63
|
+
* reaches several close paths (document capture, editor host, plugin
|
|
64
|
+
* `onKeyDown`) with different DOM state in between, so every path reuses
|
|
65
|
+
* the first verdict instead of re-asking.
|
|
61
66
|
*/
|
|
62
67
|
export declare function shouldPreventEditClose(config: EditingConfig, event: MouseEvent | KeyboardEvent): boolean;
|
|
63
68
|
/**
|
|
@@ -77,6 +82,24 @@ export declare function shouldPreventEditClose(config: EditingConfig, event: Mou
|
|
|
77
82
|
* @internal
|
|
78
83
|
*/
|
|
79
84
|
export declare function isInsideOpenAriaOverlay(target: Node | null | undefined, scopeEl: HTMLElement): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Returns `true` when this Escape keystroke belongs to an open ARIA overlay
|
|
87
|
+
* (combobox list, menu, picker) rather than to the row edit — i.e. the
|
|
88
|
+
* keystroke originates from an `aria-expanded="true"` + `aria-controls`
|
|
89
|
+
* control (or a descendant of one) inside `scopeEl`, or from inside the
|
|
90
|
+
* panel such a control owns — whether that panel is portalled to `<body>`
|
|
91
|
+
* or rendered inline beside its trigger. Standard dialog-stack behaviour:
|
|
92
|
+
* the first Escape closes the overlay, the next one cancels the edit (#558).
|
|
93
|
+
*
|
|
94
|
+
* The verdict is remembered per event: the overlay's own handler flips
|
|
95
|
+
* `aria-expanded` to `"false"` while the event is still propagating, so the
|
|
96
|
+
* later (bubble-phase) close paths must not re-read the live DOM. It is
|
|
97
|
+
* shared only with related scopes (the row and its editor host nest); an
|
|
98
|
+
* unrelated grid's row judges the keystroke on its own.
|
|
99
|
+
*
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
102
|
+
export declare function isEscapeForOpenOverlay(event: KeyboardEvent, scopeEl: HTMLElement | null | undefined): boolean;
|
|
80
103
|
/**
|
|
81
104
|
* Shallow-compare a snapshot against the current row to detect changes.
|
|
82
105
|
* Returns `true` if any own-property value differs between the two objects.
|
|
@@ -433,6 +433,17 @@ export interface EditingConfig {
|
|
|
433
433
|
* overlay container, allowing keyboard navigation and selection within
|
|
434
434
|
* open dropdowns before the edit commits.
|
|
435
435
|
*
|
|
436
|
+
* The callback is consulted **at most once per event**: Enter/Escape reach
|
|
437
|
+
* several close paths, and all of them reuse the first verdict, so a check
|
|
438
|
+
* against live DOM state (e.g. "is a listbox open?") stays consistent even
|
|
439
|
+
* after the overlay's own handler has closed it.
|
|
440
|
+
*
|
|
441
|
+
* In row mode, Escape from (or from inside the panel of) a control that
|
|
442
|
+
* declares an open overlay via `aria-expanded="true"` + `aria-controls` is
|
|
443
|
+
* left to that overlay automatically — the first Escape closes the popup,
|
|
444
|
+
* the next one cancels the row edit. No callback is needed for such
|
|
445
|
+
* ARIA-compliant comboboxes.
|
|
446
|
+
*
|
|
436
447
|
* @example
|
|
437
448
|
* ```typescript
|
|
438
449
|
* // Angular Material / CDK - prevent close when overlay is open
|
|
@@ -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 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},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 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};
|
|
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
|