@toolbox-web/grid 1.24.1 → 1.24.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.
@@ -1,5 +1,5 @@
1
1
  import { ColumnConfig } from '../../core/types';
2
- import { ColumnGroup } from './types';
2
+ import { ColumnGroup, GroupingColumnsConfig } from './types';
3
3
  /**
4
4
  * Compute column groups from column configuration.
5
5
  * Handles explicit groups (via column.group) and creates implicit groups for ungrouped columns.
@@ -30,7 +30,7 @@ export declare function findEmbeddedImplicitGroups(groups: ColumnGroup[], column
30
30
  * @param columns - The column configurations (final array including any plugin-added columns)
31
31
  * @returns The group header row element, or null if no groups
32
32
  */
33
- export declare function buildGroupHeaderRow(groups: ColumnGroup[], columns: ColumnConfig[]): HTMLElement | null;
33
+ export declare function buildGroupHeaderRow(groups: ColumnGroup[], columns: ColumnConfig[], renderer?: GroupingColumnsConfig['groupHeaderRenderer']): HTMLElement | null;
34
34
  /**
35
35
  * Check if any columns have group configuration.
36
36
  *
@@ -1 +1 @@
1
- {"version":3,"file":"grouping-columns.d.ts","sourceRoot":"","sources":["../../../../../../libs/grid/src/lib/plugins/grouping-columns/grouping-columns.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,WAAW,EAAuB,MAAM,SAAS,CAAC;AAEhE;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,CA+DnF;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,WAAW,EAAE,WAAW,GAAG,IAAI,EAC/B,MAAM,EAAE,WAAW,EAAE,EACrB,OAAO,EAAE,YAAY,EAAE,GACtB,IAAI,CAmCN;AAcD;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAuBtG;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,WAAW,GAAG,IAAI,CAmCtG;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,OAAO,CAEhE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAIzE"}
1
+ {"version":3,"file":"grouping-columns.d.ts","sourceRoot":"","sources":["../../../../../../libs/grid/src/lib/plugins/grouping-columns/grouping-columns.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,WAAW,EAAgD,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEhH;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,CA+DnF;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,WAAW,EAAE,WAAW,GAAG,IAAI,EAC/B,MAAM,EAAE,WAAW,EAAE,EACrB,OAAO,EAAE,YAAY,EAAE,GACtB,IAAI,CAmCN;AAcD;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAuBtG;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,WAAW,EAAE,EACrB,OAAO,EAAE,YAAY,EAAE,EACvB,QAAQ,CAAC,EAAE,qBAAqB,CAAC,qBAAqB,CAAC,GACtD,WAAW,GAAG,IAAI,CAwDpB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,OAAO,CAEhE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAIzE"}
@@ -5,5 +5,5 @@
5
5
  * @module Plugins/Grouping Columns
6
6
  */
7
7
  export { GroupingColumnsPlugin } from './GroupingColumnsPlugin';
8
- export type { ColumnGroup, ColumnGroupDefinition, GroupingColumnsConfig } from './types';
8
+ export type { ColumnGroup, ColumnGroupDefinition, GroupHeaderRenderParams, GroupingColumnsConfig } from './types';
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../libs/grid/src/lib/plugins/grouping-columns/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,YAAY,EAAE,WAAW,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../libs/grid/src/lib/plugins/grouping-columns/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,YAAY,EAAE,WAAW,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC"}
@@ -1,2 +1,2 @@
1
- const e='<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>',t={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:e,filterActive:e,print:"🖨️"};class r{static dependencies;static manifest;aliases;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const r=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(r),r.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...t,...e}}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),r=parseInt(t,10);if(!isNaN(r))return r}return 200}resolveIcon(e,t){return void 0!==t?t:this.gridIcons[e]}setIcon(e,t){"string"==typeof t?e.innerHTML=t:t instanceof HTMLElement&&(e.innerHTML="",e.appendChild(t.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}function o(e){if(!e.length)return[];const t=/* @__PURE__ */new Map,r=[],o=(e,t)=>{if(!t.length)return;const o=r[r.length-1];o&&o.implicit&&o.firstIndex+o.columns.length===e?o.columns.push(...t):r.push({id:"__implicit__"+e,label:void 0,columns:t,firstIndex:e,implicit:!0})};let i=[],n=0;return e.forEach((e,s)=>{const l=e.group;if(!l)return 0===i.length&&(n=s),void i.push(e);i.length&&(o(n,i.slice()),i=[]);const d="string"==typeof l?l:l.id;let u=t.get(d);u||(u={id:d,label:"string"==typeof l?void 0:l.label,columns:[],firstIndex:s},t.set(d,u),r.push(u)),u.columns.push(e)}),i.length&&o(n,i),1===r.length&&r[0].implicit&&r[0].columns.length===e.length?[]:r}function i(e,t){const r=e.columns[0],o=e.columns[e.columns.length-1],i=r?t.findIndex(e=>e.field===r.field):-1,n=o?t.findIndex(e=>e.field===o.field):-1;return-1!==i&&-1!==n?[i,n]:null}function n(e,t){const r=/* @__PURE__ */new Set,o=[];for(const n of e){if(String(n.id).startsWith("__implicit__"))continue;const e=i(n,t);e&&o.push(e)}for(const n of e){if(!String(n.id).startsWith("__implicit__"))continue;const e=i(n,t);if(!e)continue;const[s,l]=e;o.some(([e,t])=>s>=e&&l<=t)&&r.add(String(n.id))}return r}class s extends r{static manifest={ownedProperties:[{property:"group",level:"column",description:'the "group" column property'},{property:"columnGroups",level:"config",description:'the "columnGroups" config property',isUsed:e=>Array.isArray(e)&&e.length>0}],queries:[{type:"getColumnGrouping",description:"Returns column group metadata for the visibility panel"}]};name="groupingColumns";styles="@layer tbw-plugins{.header-group-row{display:grid;grid-auto-flow:column;background:var(--tbw-grouping-columns-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-grouping-columns-border, var(--tbw-color-border))}.header-group-cell{display:flex;align-items:center;justify-content:center;padding:var(--tbw-button-padding-sm, .25rem .5rem);font-weight:600;font-size:var(--tbw-font-size-sm, .9em);text-transform:uppercase;letter-spacing:.5px;border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-group-cell:last-child{border-right:none}.header-row .cell.grouped{border-top:none}.header-row .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-row .cell.group-end:last-child{border-right:none}.rows .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.rows .cell.group-end:last-child{border-right:none}.header-group-row.no-borders{border-bottom:none}.header-group-row.no-borders .header-group-cell{border-right:none}.header-row.no-group-borders .cell.group-end{border-right:1px solid var(--tbw-color-border)}}";get defaultConfig(){return{showGroupBorders:!0,lockGroupOrder:!1}}groups=[];isActive=!1;#t=/* @__PURE__ */new Set;attach(e){super.attach(e),e.addEventListener("column-move",this.#r,{signal:this.disconnectSignal})}detach(){this.groups=[],this.isActive=!1,this.#t.clear()}#r=e=>{if(!this.isActive)return;const t=e,{field:r,columnOrder:o}=t.detail;if(this.config.lockGroupOrder)for(const i of this.groups)if(!i.id.startsWith("__implicit__")&&!this.#o(i,o))return t.preventDefault(),void this.#i(r);this.#n(o)};#n(e){this.#t.clear();const t=this.#s(e);for(const r of this.groups){const o=new Set(r.columns.map(e=>e.field));for(let r=e.length-1;r>=0;r--)if(o.has(e[r])){const o=e[r];o!==t&&this.#t.add(o);break}}}#s(e){if(0===this.groups.length)return null;for(let t=e.length-1;t>=0;t--){const r=e[t];for(const t of this.groups)if(t.columns.some(e=>e.field===r)){const r=new Set(t.columns.map(e=>e.field));for(let t=e.length-1;t>=0;t--)if(r.has(e[t]))return e[t]}}return null}#o(e,t){const r=e.columns.map(e=>t.indexOf(e.field)).filter(e=>-1!==e).sort((e,t)=>e-t);return r.length<=1||r.length===r[r.length-1]-r[0]+1}#i(e){const t=this.gridElement?.querySelector(`.header-row [part~="header-cell"][data-field="${e}"]`);t&&(t.style.setProperty("--_flash-color","var(--tbw-color-error)"),t.animate([{backgroundColor:"rgba(from var(--_flash-color) r g b / 30%)"},{backgroundColor:"transparent"}],{duration:400,easing:"ease-out"}))}handleQuery(e){if("getColumnGrouping"===e.type)return this.#l()}#l(){let e;const t=this.grid?.gridConfig?.columnGroups;if(t&&Array.isArray(t)&&t.length>0)e=t.filter(e=>e.children.length>0).map(e=>({id:e.id,label:e.header,fields:[...e.children]}));else if(this.isActive&&this.groups.length>0){e=this.groups.filter(e=>!e.id.startsWith("__implicit__")).map(e=>({id:e.id,label:e.label??e.id,fields:e.columns.map(e=>e.field)}));const t=this.columns;for(const r of t)if(r.hidden&&r.group){const t="string"==typeof r.group?r.group:r.group.id,o="string"==typeof r.group?r.group:r.group.label??r.group.id,i=e.find(e=>e.id===t);i?i.fields.includes(r.field)||i.fields.push(r.field):e.push({id:t,label:o,fields:[r.field]})}}else{const t=this.columns,r=/* @__PURE__ */new Map;for(const e of t){if(!e.group)continue;const t="string"==typeof e.group?e.group:e.group.id,o="string"==typeof e.group?e.group:e.group.label??e.group.id,i=r.get(t);i?i.fields.includes(e.field)||i.fields.push(e.field):r.set(t,{id:t,label:o,fields:[e.field]})}e=Array.from(r.values())}const r=this.grid?.getColumnOrder();if(r&&r.length>0){const t=new Map(r.map((e,t)=>[e,t]));for(const r of e)r.fields.sort((e,r)=>(t.get(e)??1/0)-(t.get(r)??1/0))}return e}static detect(e,t){if(t?.columnGroups&&Array.isArray(t.columnGroups)&&t.columnGroups.length>0)return!0;const r=t?.columns;return!!Array.isArray(r)&&function(e){return e.some(e=>null!=e.group)}(r)}processColumns(e){const t=this.grid?.gridConfig?.columnGroups;let r;if(t&&Array.isArray(t)&&t.length>0){const o=/* @__PURE__ */new Map;for(const e of t)for(const t of e.children)o.set(t,{id:e.id,label:e.header});r=e.map(e=>{const t=o.get(e.field);return t&&!e.group?{...e,group:t}:e})}else r=[...e];const i=o(r);if(0===i.length)return this.isActive=!1,this.groups=[],r;this.isActive=!0,this.groups=i,this.#t.clear();for(const o of i){const e=o.columns[o.columns.length-1];e?.field&&this.#t.add(e.field)}return r}afterRender(){if(!this.isActive){const e=this.gridElement?.querySelector(".header"),t=e?.querySelector(".header-group-row");return void(t&&t.remove())}const e=this.gridElement?.querySelector(".header");if(!e)return;const t=e.querySelector(".header-group-row");t&&t.remove();const r=this.visibleColumns,s=o(r);if(0===s.length)return;this.#t.clear();const l=n(s,r);for(let o=0;o<s.length;o++){const e=s[o];if(String(e.id).startsWith("__implicit__")&&l.has(String(e.id)))continue;const t=e.columns[e.columns.length-1];t?.field&&o<s.length-1&&this.#t.add(t.field)}const d=function(e,t){if(0===e.length)return null;const r=document.createElement("div");r.className="header-group-row",r.setAttribute("role","row");const o=n(e,t);for(const n of e){const e=String(n.id),s=e.startsWith("__implicit__");if(s&&o.has(e))continue;const l=i(n,t);if(!l)continue;const[d,u]=l,c=u-d+1,a=s?"":n.label||n.id,g=document.createElement("div");g.className="cell header-group-cell",s&&g.classList.add("implicit-group"),g.setAttribute("data-group",e),g.style.gridColumn=`${d+1} / span ${c}`,g.textContent=a,r.appendChild(g)}return r}(s,r);if(d){d.classList.toggle("no-borders",!this.config.showGroupBorders);const t=e.querySelector(".header-row");t?e.insertBefore(d,t):e.appendChild(d)}const u=e.querySelector(".header-row");u&&(u.classList.toggle("no-group-borders",!this.config.showGroupBorders),function(e,t,r){if(!t.length||!e)return;const o=n(t,r),i=/* @__PURE__ */new Map;for(const n of t)if(!String(n.id).startsWith("__implicit__")||!o.has(String(n.id)))for(const e of n.columns)e.field&&i.set(e.field,n.id);const s=Array.from(e.querySelectorAll(".cell[data-field]"));s.forEach(e=>{const t=e.getAttribute("data-field")||"",r=i.get(t);r&&(e.classList.add("grouped"),e.getAttribute("data-group")||e.setAttribute("data-group",r))});for(const n of t){if(String(n.id).startsWith("__implicit__")&&o.has(String(n.id)))continue;const e=n.columns[n.columns.length-1],t=s.find(t=>t.getAttribute("data-field")===e.field);t&&t.classList.add("group-end")}}(u,s,r))}afterCellRender(e){this.isActive&&this.config.showGroupBorders&&e.cellElement.classList.toggle("group-end",this.#t.has(e.column.field))}isGroupingActive(){return this.isActive}getGroups(){return this.groups}getGroupColumns(e){const t=this.groups.find(t=>t.id===e);return t?t.columns:[]}refresh(){this.requestRender()}}export{s as GroupingColumnsPlugin};
1
+ const e='<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>',t={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:e,filterActive:e,print:"🖨️"};class r{static dependencies;static manifest;aliases;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const r=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(r),r.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...t,...e}}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),r=parseInt(t,10);if(!isNaN(r))return r}return 200}resolveIcon(e,t){return void 0!==t?t:this.gridIcons[e]}setIcon(e,t){"string"==typeof t?e.innerHTML=t:t instanceof HTMLElement&&(e.innerHTML="",e.appendChild(t.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}function o(e){if(!e.length)return[];const t=/* @__PURE__ */new Map,r=[],o=(e,t)=>{if(!t.length)return;const o=r[r.length-1];o&&o.implicit&&o.firstIndex+o.columns.length===e?o.columns.push(...t):r.push({id:"__implicit__"+e,label:void 0,columns:t,firstIndex:e,implicit:!0})};let i=[],n=0;return e.forEach((e,s)=>{const l=e.group;if(!l)return 0===i.length&&(n=s),void i.push(e);i.length&&(o(n,i.slice()),i=[]);const d="string"==typeof l?l:l.id;let u=t.get(d);u||(u={id:d,label:"string"==typeof l?void 0:l.label,columns:[],firstIndex:s},t.set(d,u),r.push(u)),u.columns.push(e)}),i.length&&o(n,i),1===r.length&&r[0].implicit&&r[0].columns.length===e.length?[]:r}function i(e,t){const r=e.columns[0],o=e.columns[e.columns.length-1],i=r?t.findIndex(e=>e.field===r.field):-1,n=o?t.findIndex(e=>e.field===o.field):-1;return-1!==i&&-1!==n?[i,n]:null}function n(e,t){const r=/* @__PURE__ */new Set,o=[];for(const n of e){if(String(n.id).startsWith("__implicit__"))continue;const e=i(n,t);e&&o.push(e)}for(const n of e){if(!String(n.id).startsWith("__implicit__"))continue;const e=i(n,t);if(!e)continue;const[s,l]=e;o.some(([e,t])=>s>=e&&l<=t)&&r.add(String(n.id))}return r}class s extends r{static manifest={ownedProperties:[{property:"group",level:"column",description:'the "group" column property'},{property:"columnGroups",level:"config",description:'the "columnGroups" config property',isUsed:e=>Array.isArray(e)&&e.length>0}],queries:[{type:"getColumnGrouping",description:"Returns column group metadata for the visibility panel"}]};name="groupingColumns";styles="@layer tbw-plugins{.header-group-row{display:grid;grid-auto-flow:column;background:var(--tbw-grouping-columns-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-grouping-columns-border, var(--tbw-color-border))}.header-group-cell{display:flex;align-items:center;justify-content:center;padding:var(--tbw-button-padding-sm, .25rem .5rem);font-weight:600;font-size:var(--tbw-font-size-sm, .9em);text-transform:uppercase;letter-spacing:.5px;border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-group-cell:last-child{border-right:none}.header-row .cell.grouped{border-top:none}.header-row .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-row .cell.group-end:last-child{border-right:none}.rows .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.rows .cell.group-end:last-child{border-right:none}.header-group-row.no-borders{border-bottom:none}.header-group-row.no-borders .header-group-cell{border-right:none}.header-row.no-group-borders .cell.group-end{border-right:1px solid var(--tbw-color-border)}}";get defaultConfig(){return{showGroupBorders:!0,lockGroupOrder:!1}}groups=[];isActive=!1;#t=/* @__PURE__ */new Set;attach(e){super.attach(e),e.addEventListener("column-move",this.#r,{signal:this.disconnectSignal})}detach(){this.groups=[],this.isActive=!1,this.#t.clear()}#r=e=>{if(!this.isActive)return;const t=e,{field:r,columnOrder:o}=t.detail;if(this.config.lockGroupOrder)for(const i of this.groups)if(!i.id.startsWith("__implicit__")&&!this.#o(i,o))return t.preventDefault(),void this.#i(r);this.#n(o)};#n(e){this.#t.clear();const t=this.#s(e);for(const r of this.groups){const o=new Set(r.columns.map(e=>e.field));for(let r=e.length-1;r>=0;r--)if(o.has(e[r])){const o=e[r];o!==t&&this.#t.add(o);break}}}#s(e){if(0===this.groups.length)return null;for(let t=e.length-1;t>=0;t--){const r=e[t];for(const t of this.groups)if(t.columns.some(e=>e.field===r)){const r=new Set(t.columns.map(e=>e.field));for(let t=e.length-1;t>=0;t--)if(r.has(e[t]))return e[t]}}return null}#o(e,t){const r=e.columns.map(e=>t.indexOf(e.field)).filter(e=>-1!==e).sort((e,t)=>e-t);return r.length<=1||r.length===r[r.length-1]-r[0]+1}#i(e){const t=this.gridElement?.querySelector(`.header-row [part~="header-cell"][data-field="${e}"]`);t&&(t.style.setProperty("--_flash-color","var(--tbw-color-error)"),t.animate([{backgroundColor:"rgba(from var(--_flash-color) r g b / 30%)"},{backgroundColor:"transparent"}],{duration:400,easing:"ease-out"}))}handleQuery(e){if("getColumnGrouping"===e.type)return this.#l()}#l(){let e;const t=this.grid?.gridConfig?.columnGroups;if(t&&Array.isArray(t)&&t.length>0)e=t.filter(e=>e.children.length>0).map(e=>({id:e.id,label:e.header,fields:[...e.children]}));else if(this.isActive&&this.groups.length>0){e=this.groups.filter(e=>!e.id.startsWith("__implicit__")).map(e=>({id:e.id,label:e.label??e.id,fields:e.columns.map(e=>e.field)}));const t=this.columns;for(const r of t)if(r.hidden&&r.group){const t="string"==typeof r.group?r.group:r.group.id,o="string"==typeof r.group?r.group:r.group.label??r.group.id,i=e.find(e=>e.id===t);i?i.fields.includes(r.field)||i.fields.push(r.field):e.push({id:t,label:o,fields:[r.field]})}}else{const t=this.columns,r=/* @__PURE__ */new Map;for(const e of t){if(!e.group)continue;const t="string"==typeof e.group?e.group:e.group.id,o="string"==typeof e.group?e.group:e.group.label??e.group.id,i=r.get(t);i?i.fields.includes(e.field)||i.fields.push(e.field):r.set(t,{id:t,label:o,fields:[e.field]})}e=Array.from(r.values())}const r=this.grid?.getColumnOrder();if(r&&r.length>0){const t=new Map(r.map((e,t)=>[e,t]));for(const r of e)r.fields.sort((e,r)=>(t.get(e)??1/0)-(t.get(r)??1/0))}return e}static detect(e,t){if(t?.columnGroups&&Array.isArray(t.columnGroups)&&t.columnGroups.length>0)return!0;const r=t?.columns;return!!Array.isArray(r)&&function(e){return e.some(e=>null!=e.group)}(r)}processColumns(e){const t=this.grid?.gridConfig?.columnGroups;let r;if(t&&Array.isArray(t)&&t.length>0){const o=/* @__PURE__ */new Map;for(const e of t)for(const t of e.children)o.set(t,{id:e.id,label:e.header});r=e.map(e=>{const t=o.get(e.field);return t&&!e.group?{...e,group:t}:e})}else r=[...e];const i=o(r);if(0===i.length)return this.isActive=!1,this.groups=[],r;this.isActive=!0,this.groups=i,this.#t.clear();for(const o of i){const e=o.columns[o.columns.length-1];e?.field&&this.#t.add(e.field)}return r}afterRender(){if(!this.isActive){const e=this.gridElement?.querySelector(".header"),t=e?.querySelector(".header-group-row");return void(t&&t.remove())}const e=this.gridElement?.querySelector(".header");if(!e)return;const t=e.querySelector(".header-group-row");t&&t.remove();const r=this.visibleColumns,s=o(r);if(0===s.length)return;this.#t.clear();const l=n(s,r);for(let o=0;o<s.length;o++){const e=s[o];if(String(e.id).startsWith("__implicit__")&&l.has(String(e.id)))continue;const t=e.columns[e.columns.length-1];t?.field&&o<s.length-1&&this.#t.add(t.field)}const d=function(e,t,r){if(0===e.length)return null;const o=document.createElement("div");o.className="header-group-row",o.setAttribute("role","row");const s=n(e,t);for(const n of e){const e=String(n.id),l=e.startsWith("__implicit__");if(l&&s.has(e))continue;const d=i(n,t);if(!d)continue;const[u,c]=d,a=c-u+1,g=l?"":n.label||n.id,h=document.createElement("div");if(h.className="cell header-group-cell",l&&h.classList.add("implicit-group"),h.setAttribute("data-group",e),h.style.gridColumn=`${u+1} / span ${a}`,r&&!l){const t=r({id:e,label:String(g),columns:n.columns,firstIndex:u,isImplicit:!1});t instanceof HTMLElement?h.appendChild(t):"string"==typeof t?h.innerHTML=t:h.textContent=g}else h.textContent=g;o.appendChild(h)}return o}(s,r,this.config.groupHeaderRenderer);if(d){d.classList.toggle("no-borders",!this.config.showGroupBorders);const t=e.querySelector(".header-row");t?e.insertBefore(d,t):e.appendChild(d)}const u=e.querySelector(".header-row");u&&(u.classList.toggle("no-group-borders",!this.config.showGroupBorders),function(e,t,r){if(!t.length||!e)return;const o=n(t,r),i=/* @__PURE__ */new Map;for(const n of t)if(!String(n.id).startsWith("__implicit__")||!o.has(String(n.id)))for(const e of n.columns)e.field&&i.set(e.field,n.id);const s=Array.from(e.querySelectorAll(".cell[data-field]"));s.forEach(e=>{const t=e.getAttribute("data-field")||"",r=i.get(t);r&&(e.classList.add("grouped"),e.getAttribute("data-group")||e.setAttribute("data-group",r))});for(const n of t){if(String(n.id).startsWith("__implicit__")&&o.has(String(n.id)))continue;const e=n.columns[n.columns.length-1],t=s.find(t=>t.getAttribute("data-field")===e.field);t&&t.classList.add("group-end")}}(u,s,r))}afterCellRender(e){this.isActive&&this.config.showGroupBorders&&e.cellElement.classList.toggle("group-end",this.#t.has(e.column.field))}isGroupingActive(){return this.isActive}getGroups(){return this.groups}getGroupColumns(e){const t=this.groups.find(t=>t.id===e);return t?t.columns:[]}refresh(){this.requestRender()}}export{s as GroupingColumnsPlugin};
2
2
  //# sourceMappingURL=index.js.map