@toolbox-web/grid 3.0.0 → 3.1.0
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 +1 -1
- package/all.js.map +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/lib/core/internal/dom-builder.d.ts +1 -1
- package/lib/features/registry.js +1 -1
- package/lib/plugins/clipboard/index.js +1 -1
- package/lib/plugins/column-virtualization/index.js +1 -1
- package/lib/plugins/context-menu/index.js +1 -1
- package/lib/plugins/editing/index.js +1 -1
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/export/index.js +1 -1
- package/lib/plugins/filtering/index.js +1 -1
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/index.js +1 -1
- package/lib/plugins/grouping-rows/index.js +1 -1
- package/lib/plugins/master-detail/index.js +1 -1
- package/lib/plugins/multi-sort/index.js +1 -1
- package/lib/plugins/pinned-columns/index.js +1 -1
- package/lib/plugins/pinned-rows/index.js +1 -1
- package/lib/plugins/pivot/index.js +1 -1
- package/lib/plugins/print/index.js +1 -1
- package/lib/plugins/print/index.js.map +1 -1
- package/lib/plugins/reorder-columns/index.js +1 -1
- package/lib/plugins/responsive/index.js +1 -1
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/row-drag-drop/index.js +1 -1
- package/lib/plugins/selection/index.js +1 -1
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js +1 -1
- package/lib/plugins/shell/index.js +1 -1
- package/lib/plugins/shell/index.js.map +1 -1
- package/lib/plugins/shell/types.d.ts +18 -2
- package/lib/plugins/sticky-rows/index.js +1 -1
- package/lib/plugins/tooltip/index.js +1 -1
- package/lib/plugins/tooltip/index.js.map +1 -1
- package/lib/plugins/tree/index.js +1 -1
- package/lib/plugins/undo-redo/index.js +1 -1
- package/lib/plugins/visibility/index.js +1 -1
- 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/filtering.umd.js +1 -1
- package/umd/plugins/filtering.umd.js.map +1 -1
- package/umd/plugins/print.umd.js +1 -1
- package/umd/plugins/print.umd.js.map +1 -1
- package/umd/plugins/responsive.umd.js +1 -1
- package/umd/plugins/responsive.umd.js.map +1 -1
- package/umd/plugins/selection.umd.js +1 -1
- package/umd/plugins/selection.umd.js.map +1 -1
- package/umd/plugins/shell.umd.js.map +1 -1
- package/umd/plugins/tooltip.umd.js +1 -1
- package/umd/plugins/tooltip.umd.js.map +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function t(t,r,o,i){return`${e(o,i)} ${t}: ${r}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(t)}`}var r="__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("")),o=(new RegExp(`__(proto|defineGetter|defineSetter)|${r.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".split("|"))),i=/^on\w+$/i,n=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),s=/^\s*(javascript|vbscript|data|blob):/i;function l(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const l of r){const e=l.tagName.toLowerCase();if(o.has(e)){t.push(l);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===l.namespaceURI)&&Array.from(l.attributes).some(e=>i.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(l);continue}const r=[];for(const t of l.attributes){const e=t.name.toLowerCase();i.test(e)?r.push(t.name):(n.has(e)&&s.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name)}r.forEach(e=>l.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}var d={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var c=class{static dependencies;static manifest;aliases;version="3.0.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const r={...this.userConfig},o={};for(const t of Object.keys(r))o[t]=this;for(const i of e){const e=i.userConfig;for(const[n,s]of Object.entries(e)){if(void 0===s)continue;if(!(n in r)){r[n]=s,o[n]=i;continue}if(r[n]===s)continue;const e=o[n]?.constructor.name??this.constructor.name,l=i.constructor.name,d=t("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${e} and ${l}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(d)}}Object.assign(this.userConfig,r)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const o of Object.keys(t))delete t[o];Object.assign(t,r)}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)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(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?._hostElement}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...d,...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;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}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}setIcon(e,t,r){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const o=this.#t(t,r);void 0!==o?"string"==typeof o?e.innerHTML=l(o):o instanceof HTMLElement&&(e.innerHTML="",e.appendChild(o.cloneNode(!0))):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const r=document.createElement("span");r.setAttribute("part","sort-indicator"),r.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(r,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(r,"sortNone"));const o=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return o?e.insertBefore(r,o):e.appendChild(r),r}warn(r,o){void 0!==o?console.warn(t(r,o,this.gridElement.id,this.name)):console.warn(`${e(this.gridElement.id,this.name)} ${r}`)}throwDiagnostic(e,r){throw new Error(t(e,r,this.gridElement.id,this.name))}};function u(e){return e.map(e=>{return e.id?e:(e.header||function(e,r,o,i){throw new Error(t(e,r,o,i))}("TBW113",'ColumnGroupDefinition requires either an "id" or a "header" to generate an id from.'),{...e,id:(r=e.header,r.toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))});var r})}function a(e){if(!e.length)return[];const t=[],r=/* @__PURE__ */new Map,o=(e,r)=>{if(!r.length)return;const o=t[t.length-1];o&&o.implicit&&o.firstIndex+o.columns.length===e?o.columns.push(...r):t.push({id:"__implicit__"+e,label:void 0,columns:r,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,c="string"==typeof l?void 0:l.label;c&&!r.has(d)&&r.set(d,c);const u=r.get(d)??c,a=t[t.length-1];a&&!a.implicit&&a.id===d?a.columns.push(e):t.push({id:d,label:u,columns:[e],firstIndex:s})}),i.length&&o(n,i),1===t.length&&t[0].implicit&&t[0].columns.length===e.length?[]:t}function g(e){const t=function(e){const t=/* @__PURE__ */new Set;for(let r=0;r<e.length;r++){if(!String(e[r].id).startsWith("__implicit__"))continue;if(!e[r].columns.every(e=>e.field?.startsWith("__tbw_")))continue;let o=null;for(let t=r-1;t>=0;t--)if(!String(e[t].id).startsWith("__implicit__")){o=e[t].id;break}let i=null;for(let t=r+1;t<e.length;t++)if(!String(e[t].id).startsWith("__implicit__")){i=e[t].id;break}o&&i&&o===i&&t.add(String(e[r].id))}return t}(e);return{merged:h(e,t),embedded:t}}function f(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 h(e,t){const r=[];for(const o of e){if(String(o.id).startsWith("__implicit__")&&t.has(String(o.id)))continue;const e=r[r.length-1];e&&!String(o.id).startsWith("__implicit__")&&e.id===o.id?r[r.length-1]={...e,columns:[...e.columns,...o.columns]}:r.push({...o,columns:[...o.columns]})}return r}var p=class extends c{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"},{type:"collectHeaderRows",description:"Contributes a group-header row above the leaf header for exports / printers"}]};name="groupingColumns";styles="@layer tbw-plugins{.header-group-row{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));grid-auto-flow:column;display:grid}.header-group-cell{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;text-overflow:ellipsis;white-space:nowrap;border-right:2px solid var(--tbw-grouping-columns-separator,var(--tbw-color-border-strong,var(--tbw-color-border)));justify-content:center;align-items:center;min-width:0;display:flex;overflow:hidden}.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;#r=/* @__PURE__ */new Set;#o=[];#i=/* @__PURE__ */new Map;attach(e){super.attach(e),this.gridElement.addEventListener("column-move",this.#n,{signal:this.disconnectSignal})}detach(){this.groups=[],this.isActive=!1,this.#r.clear(),this.#o=[],this.#i.clear()}#n=e=>{if(!this.isActive)return;const t=e,{field:r,columnOrder:o}=t.detail;if(this.config.lockGroupOrder){const e=/* @__PURE__ */new Map;for(const t of this.groups){if(t.id.startsWith("__implicit__"))continue;const r=e.get(t.id);r?r.push(...t.columns):e.set(t.id,[...t.columns])}for(const[,i]of e)if(!this.#s(i,o))return t.preventDefault(),void this.#l(r)}this.#d(o)};#d(e){this.#r.clear();const t=/* @__PURE__ */new Map;for(const r of this.groups)for(const e of r.columns)t.set(e.field,r.id);for(let r=0;r<e.length-1;r++)t.get(e[r])!==t.get(e[r+1])&&this.#r.add(e[r])}#s(e,t){const r=e.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}#l(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){return"getColumnGrouping"===e.type?this.#c():"collectHeaderRows"===e.type?this.#u(e.context):void 0}#u(e){const t=e?.columns;if(!Array.isArray(t)||0===t.length)return;const r=a(t);if(0===r.length)return;const{merged:o}=g(r),i=[];for(const n of o){const e=String(n.id).startsWith("__implicit__"),r=n.columns[0],o=n.columns[n.columns.length-1];if(!r||!o)continue;const s=t.findIndex(e=>e.field===r.field),l=t.findIndex(e=>e.field===o.field);if(s<0||l<0)continue;const d=l-s+1;i.push({label:e?"":n.label??n.id,span:d,source:this.name})}return 0!==i.length?i.reduce((e,t)=>e+t.span,0)!==t.length?{cells:[{label:"",span:t.length,source:this.name}]}:{cells:i}:void 0}#c(){let e;if(this.#o.length>0)e=this.#o.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){const t=/* @__PURE__ */new Map;for(const e of this.groups){if(e.id.startsWith("__implicit__"))continue;const r=t.get(e.id);if(r)for(const t of e.columns)r.fields.includes(t.field)||r.fields.push(t.field);else t.set(e.id,{id:e.id,label:e.label??e.id,fields:e.columns.map(e=>e.field)})}e=Array.from(t.values());const r=this.columns;for(const o of r)if(o.hidden&&o.group){const t="string"==typeof o.group?o.group:o.group.id,r="string"==typeof o.group?o.group:o.group.label??o.group.id,i=e.find(e=>e.id===t);i?i.fields.includes(o.field)||i.fields.push(o.field):e.push({id:t,label:r,fields:[o.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 t=this.grid?.getColumnOrder();if(t&&t.length>0){const r=new Map(t.map((e,t)=>[e,t]));for(const t of e)t.fields.sort((e,t)=>(r.get(e)??1/0)-(r.get(t)??1/0))}return e}static detect(e,t){const r=t?.features?.groupingColumns;if(r&&"object"==typeof r&&Array.isArray(r.columnGroups)&&r.columnGroups.length>0)return!0;if(t?.columnGroups&&Array.isArray(t.columnGroups)&&t.columnGroups.length>0)return!0;const o=t?.columns;return!!Array.isArray(o)&&function(e){return e.some(e=>null!=e.group)}(o)}processColumns(e){const t=this.config?.columnGroups,r=this.grid?.gridConfig?.columnGroups;let o,i;if(t&&Array.isArray(t)&&t.length>0?(r&&Array.isArray(r)&&r.length>0&&this.warn("TBW114","columnGroups defined in both gridConfig and groupingColumns feature config. Using feature config (higher precedence)."),o=t):r&&Array.isArray(r)&&r.length>0&&(o=r),o&&o.length>0){const t=u(o);this.#o=t,this.#i.clear();for(const e of t)e.renderer&&this.#i.set(e.id,e.renderer);const r=/* @__PURE__ */new Map;for(const e of t)for(const t of e.children)r.set(t,{id:e.id,label:e.header});i=e.map(e=>{const t=r.get(e.field);return t&&!e.group?{...e,group:t}:e})}else this.#o=[],this.#i.clear(),i=[...e];const n=a(i);if(0===n.length)return this.isActive=!1,this.groups=[],i;if(this.#i.size>0)for(const s of n){const e=this.#i.get(s.id);e&&(s.renderer=e)}this.isActive=!0,this.groups=n,this.#r.clear();for(const s of n){const e=s.columns[s.columns.length-1];e?.field&&this.#r.add(e.field)}return i}afterRender(){if(!this.isActive){const e=(this.gridElement?.querySelector(".header"))?.querySelector(".header-group-row");return void(e&&e.remove())}const e=this.gridElement?.querySelector(".header");if(!e)return;const t=e.querySelector(".header-group-row");t&&t.remove();const r=this.visibleColumns,o=a(r);if(0===o.length)return;if(this.#i.size>0)for(const l of o){const e=this.#i.get(l.id);e&&(l.renderer=e)}this.#r.clear();const i=g(o);for(let l=0;l<i.merged.length;l++){const e=i.merged[l],t=e.columns[e.columns.length-1];t?.field&&l<i.merged.length-1&&this.#r.add(t.field)}const n=function(e,t,r,o){if(0===e.length)return null;const i=document.createElement("div");i.className="header-group-row",i.setAttribute("role","row");const{merged:n}=o??g(e);for(const s of n){const e=String(s.id),o=e.startsWith("__implicit__"),n=f(s,t);if(!n)continue;const[d,c]=n,u=c-d+1,a=o?"":s.label||s.id,g=document.createElement("div");g.className="cell header-group-cell",o&&g.classList.add("implicit-group"),g.setAttribute("data-group",e),g.style.gridColumn=`${d+1} / span ${u}`;const h=!o&&(s.renderer||r)||void 0;if(h&&!o){const t=h({id:e,label:String(a),columns:s.columns,firstIndex:d,isImplicit:!1});t instanceof HTMLElement?g.appendChild(t):"string"==typeof t?g.innerHTML=l(t):g.textContent=a}else g.textContent=a;i.appendChild(g)}return i}(o,r,this.config.groupHeaderRenderer,i);if(n){n.classList.toggle("no-borders",!this.config.showGroupBorders);const t=e.querySelector(".header-row");t?e.insertBefore(n,t):e.appendChild(n)}const s=e.querySelector(".header-row");s&&(s.classList.toggle("no-group-borders",!this.config.showGroupBorders),function(e,t,r,o){if(!t.length||!e)return;const{merged:i,embedded:n}=o??g(t),s=/* @__PURE__ */new Map;for(const d of i)if(!String(d.id).startsWith("__implicit__"))for(const e of d.columns)e.field&&s.set(e.field,d.id);for(let d=0;d<t.length;d++){const e=t[d];if(String(e.id).startsWith("__implicit__")&&n.has(String(e.id)))for(let r=d-1;r>=0;r--)if(!String(t[r].id).startsWith("__implicit__")){for(const o of e.columns)o.field&&s.set(o.field,t[r].id);break}}const l=Array.from(e.querySelectorAll(".cell[data-field]"));l.forEach(e=>{const t=e.getAttribute("data-field")||"",r=s.get(t);r&&(e.classList.add("grouped"),e.getAttribute("data-group")||e.setAttribute("data-group",r))});for(const d of i){const e=d.columns[d.columns.length-1],t=l.find(t=>t.getAttribute("data-field")===e.field);t&&t.classList.add("group-end")}}(s,o,0,i))}afterCellRender(e){this.isActive&&this.config.showGroupBorders&&e.cellElement.classList.toggle("group-end",this.#r.has(e.column.field))}isGroupingActive(){return this.isActive}getGroups(){return this.groups}getGroupColumns(e){return this.groups.filter(t=>t.id===e).flatMap(e=>e.columns)}refresh(){this.requestRender()}};export{p as GroupingColumnsPlugin};
|
|
1
|
+
function e(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function t(t,r,o,i){return`${e(o,i)} ${t}: ${r}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(t)}`}var r="__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("")),o=(new RegExp(`__(proto|defineGetter|defineSetter)|${r.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".split("|"))),i=/^on\w+$/i,n=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),s=/^\s*(javascript|vbscript|data|blob):/i;function l(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const l of r){const e=l.tagName.toLowerCase();if(o.has(e)){t.push(l);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===l.namespaceURI)&&Array.from(l.attributes).some(e=>i.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(l);continue}const r=[];for(const t of l.attributes){const e=t.name.toLowerCase();i.test(e)?r.push(t.name):(n.has(e)&&s.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name)}r.forEach(e=>l.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}var d={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var c=class{static dependencies;static manifest;aliases;version="3.1.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const r={...this.userConfig},o={};for(const t of Object.keys(r))o[t]=this;for(const i of e){const e=i.userConfig;for(const[n,s]of Object.entries(e)){if(void 0===s)continue;if(!(n in r)){r[n]=s,o[n]=i;continue}if(r[n]===s)continue;const e=o[n]?.constructor.name??this.constructor.name,l=i.constructor.name,d=t("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${e} and ${l}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(d)}}Object.assign(this.userConfig,r)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const o of Object.keys(t))delete t[o];Object.assign(t,r)}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)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(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?._hostElement}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...d,...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;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}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}setIcon(e,t,r){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const o=this.#t(t,r);void 0!==o?"string"==typeof o?e.innerHTML=l(o):o instanceof HTMLElement&&(e.innerHTML="",e.appendChild(o.cloneNode(!0))):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const r=document.createElement("span");r.setAttribute("part","sort-indicator"),r.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(r,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(r,"sortNone"));const o=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return o?e.insertBefore(r,o):e.appendChild(r),r}warn(r,o){void 0!==o?console.warn(t(r,o,this.gridElement.id,this.name)):console.warn(`${e(this.gridElement.id,this.name)} ${r}`)}throwDiagnostic(e,r){throw new Error(t(e,r,this.gridElement.id,this.name))}};function u(e){return e.map(e=>{return e.id?e:(e.header||function(e,r,o,i){throw new Error(t(e,r,o,i))}("TBW113",'ColumnGroupDefinition requires either an "id" or a "header" to generate an id from.'),{...e,id:(r=e.header,r.toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))});var r})}function a(e){if(!e.length)return[];const t=[],r=/* @__PURE__ */new Map,o=(e,r)=>{if(!r.length)return;const o=t[t.length-1];o&&o.implicit&&o.firstIndex+o.columns.length===e?o.columns.push(...r):t.push({id:"__implicit__"+e,label:void 0,columns:r,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,c="string"==typeof l?void 0:l.label;c&&!r.has(d)&&r.set(d,c);const u=r.get(d)??c,a=t[t.length-1];a&&!a.implicit&&a.id===d?a.columns.push(e):t.push({id:d,label:u,columns:[e],firstIndex:s})}),i.length&&o(n,i),1===t.length&&t[0].implicit&&t[0].columns.length===e.length?[]:t}function g(e){const t=function(e){const t=/* @__PURE__ */new Set;for(let r=0;r<e.length;r++){if(!String(e[r].id).startsWith("__implicit__"))continue;if(!e[r].columns.every(e=>e.field?.startsWith("__tbw_")))continue;let o=null;for(let t=r-1;t>=0;t--)if(!String(e[t].id).startsWith("__implicit__")){o=e[t].id;break}let i=null;for(let t=r+1;t<e.length;t++)if(!String(e[t].id).startsWith("__implicit__")){i=e[t].id;break}o&&i&&o===i&&t.add(String(e[r].id))}return t}(e);return{merged:h(e,t),embedded:t}}function f(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 h(e,t){const r=[];for(const o of e){if(String(o.id).startsWith("__implicit__")&&t.has(String(o.id)))continue;const e=r[r.length-1];e&&!String(o.id).startsWith("__implicit__")&&e.id===o.id?r[r.length-1]={...e,columns:[...e.columns,...o.columns]}:r.push({...o,columns:[...o.columns]})}return r}var p=class extends c{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"},{type:"collectHeaderRows",description:"Contributes a group-header row above the leaf header for exports / printers"}]};name="groupingColumns";styles="@layer tbw-plugins{.header-group-row{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));grid-auto-flow:column;display:grid}.header-group-cell{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;text-overflow:ellipsis;white-space:nowrap;border-right:2px solid var(--tbw-grouping-columns-separator,var(--tbw-color-border-strong,var(--tbw-color-border)));justify-content:center;align-items:center;min-width:0;display:flex;overflow:hidden}.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;#r=/* @__PURE__ */new Set;#o=[];#i=/* @__PURE__ */new Map;attach(e){super.attach(e),this.gridElement.addEventListener("column-move",this.#n,{signal:this.disconnectSignal})}detach(){this.groups=[],this.isActive=!1,this.#r.clear(),this.#o=[],this.#i.clear()}#n=e=>{if(!this.isActive)return;const t=e,{field:r,columnOrder:o}=t.detail;if(this.config.lockGroupOrder){const e=/* @__PURE__ */new Map;for(const t of this.groups){if(t.id.startsWith("__implicit__"))continue;const r=e.get(t.id);r?r.push(...t.columns):e.set(t.id,[...t.columns])}for(const[,i]of e)if(!this.#s(i,o))return t.preventDefault(),void this.#l(r)}this.#d(o)};#d(e){this.#r.clear();const t=/* @__PURE__ */new Map;for(const r of this.groups)for(const e of r.columns)t.set(e.field,r.id);for(let r=0;r<e.length-1;r++)t.get(e[r])!==t.get(e[r+1])&&this.#r.add(e[r])}#s(e,t){const r=e.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}#l(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){return"getColumnGrouping"===e.type?this.#c():"collectHeaderRows"===e.type?this.#u(e.context):void 0}#u(e){const t=e?.columns;if(!Array.isArray(t)||0===t.length)return;const r=a(t);if(0===r.length)return;const{merged:o}=g(r),i=[];for(const n of o){const e=String(n.id).startsWith("__implicit__"),r=n.columns[0],o=n.columns[n.columns.length-1];if(!r||!o)continue;const s=t.findIndex(e=>e.field===r.field),l=t.findIndex(e=>e.field===o.field);if(s<0||l<0)continue;const d=l-s+1;i.push({label:e?"":n.label??n.id,span:d,source:this.name})}return 0!==i.length?i.reduce((e,t)=>e+t.span,0)!==t.length?{cells:[{label:"",span:t.length,source:this.name}]}:{cells:i}:void 0}#c(){let e;if(this.#o.length>0)e=this.#o.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){const t=/* @__PURE__ */new Map;for(const e of this.groups){if(e.id.startsWith("__implicit__"))continue;const r=t.get(e.id);if(r)for(const t of e.columns)r.fields.includes(t.field)||r.fields.push(t.field);else t.set(e.id,{id:e.id,label:e.label??e.id,fields:e.columns.map(e=>e.field)})}e=Array.from(t.values());const r=this.columns;for(const o of r)if(o.hidden&&o.group){const t="string"==typeof o.group?o.group:o.group.id,r="string"==typeof o.group?o.group:o.group.label??o.group.id,i=e.find(e=>e.id===t);i?i.fields.includes(o.field)||i.fields.push(o.field):e.push({id:t,label:r,fields:[o.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 t=this.grid?.getColumnOrder();if(t&&t.length>0){const r=new Map(t.map((e,t)=>[e,t]));for(const t of e)t.fields.sort((e,t)=>(r.get(e)??1/0)-(r.get(t)??1/0))}return e}static detect(e,t){const r=t?.features?.groupingColumns;if(r&&"object"==typeof r&&Array.isArray(r.columnGroups)&&r.columnGroups.length>0)return!0;if(t?.columnGroups&&Array.isArray(t.columnGroups)&&t.columnGroups.length>0)return!0;const o=t?.columns;return!!Array.isArray(o)&&function(e){return e.some(e=>null!=e.group)}(o)}processColumns(e){const t=this.config?.columnGroups,r=this.grid?.gridConfig?.columnGroups;let o,i;if(t&&Array.isArray(t)&&t.length>0?(r&&Array.isArray(r)&&r.length>0&&this.warn("TBW114","columnGroups defined in both gridConfig and groupingColumns feature config. Using feature config (higher precedence)."),o=t):r&&Array.isArray(r)&&r.length>0&&(o=r),o&&o.length>0){const t=u(o);this.#o=t,this.#i.clear();for(const e of t)e.renderer&&this.#i.set(e.id,e.renderer);const r=/* @__PURE__ */new Map;for(const e of t)for(const t of e.children)r.set(t,{id:e.id,label:e.header});i=e.map(e=>{const t=r.get(e.field);return t&&!e.group?{...e,group:t}:e})}else this.#o=[],this.#i.clear(),i=[...e];const n=a(i);if(0===n.length)return this.isActive=!1,this.groups=[],i;if(this.#i.size>0)for(const s of n){const e=this.#i.get(s.id);e&&(s.renderer=e)}this.isActive=!0,this.groups=n,this.#r.clear();for(const s of n){const e=s.columns[s.columns.length-1];e?.field&&this.#r.add(e.field)}return i}afterRender(){if(!this.isActive){const e=(this.gridElement?.querySelector(".header"))?.querySelector(".header-group-row");return void(e&&e.remove())}const e=this.gridElement?.querySelector(".header");if(!e)return;const t=e.querySelector(".header-group-row");t&&t.remove();const r=this.visibleColumns,o=a(r);if(0===o.length)return;if(this.#i.size>0)for(const l of o){const e=this.#i.get(l.id);e&&(l.renderer=e)}this.#r.clear();const i=g(o);for(let l=0;l<i.merged.length;l++){const e=i.merged[l],t=e.columns[e.columns.length-1];t?.field&&l<i.merged.length-1&&this.#r.add(t.field)}const n=function(e,t,r,o){if(0===e.length)return null;const i=document.createElement("div");i.className="header-group-row",i.setAttribute("role","row");const{merged:n}=o??g(e);for(const s of n){const e=String(s.id),o=e.startsWith("__implicit__"),n=f(s,t);if(!n)continue;const[d,c]=n,u=c-d+1,a=o?"":s.label||s.id,g=document.createElement("div");g.className="cell header-group-cell",o&&g.classList.add("implicit-group"),g.setAttribute("data-group",e),g.style.gridColumn=`${d+1} / span ${u}`;const h=!o&&(s.renderer||r)||void 0;if(h&&!o){const t=h({id:e,label:String(a),columns:s.columns,firstIndex:d,isImplicit:!1});t instanceof HTMLElement?g.appendChild(t):"string"==typeof t?g.innerHTML=l(t):g.textContent=a}else g.textContent=a;i.appendChild(g)}return i}(o,r,this.config.groupHeaderRenderer,i);if(n){n.classList.toggle("no-borders",!this.config.showGroupBorders);const t=e.querySelector(".header-row");t?e.insertBefore(n,t):e.appendChild(n)}const s=e.querySelector(".header-row");s&&(s.classList.toggle("no-group-borders",!this.config.showGroupBorders),function(e,t,r,o){if(!t.length||!e)return;const{merged:i,embedded:n}=o??g(t),s=/* @__PURE__ */new Map;for(const d of i)if(!String(d.id).startsWith("__implicit__"))for(const e of d.columns)e.field&&s.set(e.field,d.id);for(let d=0;d<t.length;d++){const e=t[d];if(String(e.id).startsWith("__implicit__")&&n.has(String(e.id)))for(let r=d-1;r>=0;r--)if(!String(t[r].id).startsWith("__implicit__")){for(const o of e.columns)o.field&&s.set(o.field,t[r].id);break}}const l=Array.from(e.querySelectorAll(".cell[data-field]"));l.forEach(e=>{const t=e.getAttribute("data-field")||"",r=s.get(t);r&&(e.classList.add("grouped"),e.getAttribute("data-group")||e.setAttribute("data-group",r))});for(const d of i){const e=d.columns[d.columns.length-1],t=l.find(t=>t.getAttribute("data-field")===e.field);t&&t.classList.add("group-end")}}(s,o,0,i))}afterCellRender(e){this.isActive&&this.config.showGroupBorders&&e.cellElement.classList.toggle("group-end",this.#r.has(e.column.field))}isGroupingActive(){return this.isActive}getGroups(){return this.groups}getGroupColumns(e){return this.groups.filter(t=>t.id===e).flatMap(e=>e.columns)}refresh(){this.requestRender()}};export{p as GroupingColumnsPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e="expanded",t="group-toggle",r="group-label",o="group-count",n=/* @__PURE__ */new WeakMap;function i(e,t,r){return r?.valueAccessor?function(e,t,r=-1){if(!t.valueAccessor)return e?.[t.field];if("object"!=typeof e||null===e)return t.valueAccessor({row:e,column:t,rowIndex:r});const o=e,i=t.field;let s=n.get(o);if(s){const e=s.get(i);if(void 0!==e)return e.v}else s=/* @__PURE__ */new Map,n.set(o,s);const a=t.valueAccessor({row:e,column:t,rowIndex:r});return s.set(i,{v:a}),a}(e,r):e?.[t]}function s(e){return null==e||""===e||"number"==typeof e&&isNaN(e)}var a={sum:(e,t,r)=>{let o=0;for(let n=0;n<e.length;n++){const a=i(e[n],t,r);if(s(a))continue;const d=Number(a);isNaN(d)||(o+=d)}return o},avg:(e,t,r)=>{if(!e.length)return 0;let o=0,n=0;for(let a=0;a<e.length;a++){const d=i(e[a],t,r);if(s(d))continue;const l=Number(d);isNaN(l)||(o+=l,n++)}return n>0?o/n:0},count:e=>e.length,min:(e,t,r)=>{if(!e.length)return 0;let o=1/0;for(let n=0;n<e.length;n++){const a=i(e[n],t,r);if(s(a))continue;const d=Number(a);isNaN(d)||d<o&&(o=d)}return o===1/0?0:o},max:(e,t,r)=>{if(!e.length)return 0;let o=-1/0;for(let n=0;n<e.length;n++){const a=i(e[n],t,r);if(s(a))continue;const d=Number(a);isNaN(d)||d>o&&(o=d)}return o===-1/0?0:o},first:(e,t,r)=>e[0]?i(e[0],t,r):void 0,last:(e,t,r)=>e.length?i(e[e.length-1],t,r):void 0},d=/* @__PURE__ */new Map,l={register(e,t){d.set(e,t)},unregister(e){d.delete(e)},get(e){if(void 0!==e)return"function"==typeof e?e:d.get(e)??a[e]},run(e,t,r,o){const n=this.get(e);return n?n(t,r,o):void 0},has:e=>d.has(e)||e in a,list:()=>[...Object.keys(a),...d.keys()]},u={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,columnSelected:e=>`Column ${e} selected`,columnSelectionChanged:e=>`${e} columns selected`,columnSelectionCleared:()=>"Column selection cleared",selectionAxisChanged:e=>"column"===e?"Row selection cleared, column selection active":"Column selection cleared, row selection active",editingStarted:e=>`Editing row ${e+1}`,editingCommitted:e=>`Row ${e+1} saved`,dataLoaded:e=>`${e} rows loaded`},p={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function g(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 c(e,t,...r){const o=(e&&"effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.messages?.[t];return o?o(...r):u[t](...r)}function h(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function f(e,t,r,o){return`${h(r,o)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var w="__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("")),m=(new RegExp(`__(proto|defineGetter|defineSetter)|${w.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".split("|"))),y=/^on\w+$/i,v=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),b=/^\s*(javascript|vbscript|data|blob):/i;function x(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const o of r){const e=o.tagName.toLowerCase();if(m.has(e)){t.push(o);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(e=>y.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();y.test(e)?r.push(t.name):(v.has(e)&&b.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name)}r.forEach(e=>o.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}var _=class{static dependencies;static manifest;aliases;version="3.0.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},r={};for(const o of Object.keys(t))r[o]=this;for(const o of e){const e=o.userConfig;for(const[n,i]of Object.entries(e)){if(void 0===i)continue;if(!(n in t)){t[n]=i,r[n]=o;continue}if(t[n]===i)continue;const e=r[n]?.constructor.name??this.constructor.name,s=o.constructor.name,a=f("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${e} and ${s}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const o of Object.keys(t))delete t[o];Object.assign(t,r)}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)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(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?._hostElement}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...p,...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;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}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}setIcon(e,t,r){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const o=this.#t(t,r);void 0!==o?"string"==typeof o?e.innerHTML=x(o):o instanceof HTMLElement&&(e.innerHTML="",e.appendChild(o.cloneNode(!0))):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const r=document.createElement("span");r.setAttribute("part","sort-indicator"),r.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(r,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(r,"sortNone"));const o=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return o?e.insertBefore(r,o):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(f(e,t,this.gridElement.id,this.name)):console.warn(`${h(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(f(e,t,this.gridElement.id,this.name))}};function R({rows:e,config:t,expanded:r,initialExpanded:o,groupSortDirections:n}){const i=t.groupOn;if("function"!=typeof i)return[];const s={key:"__root__",value:null,depth:-1,rows:[],children:/* @__PURE__ */new Map};if(e.forEach(e=>{let t=i(e);null==t||!1===t?t=["__ungrouped__"]:Array.isArray(t)||(t=[t]);let r=s;t.forEach((t,o)=>{const n=null==t?"∅":String(t),i="__root__"===r.key?n:r.key+"||"+n;let s=r.children.get(n);s||(s={key:i,value:t,depth:o,rows:[],children:/* @__PURE__ */new Map,parent:r},r.children.set(n,s)),s.rows.push(e),r=s})}),1===s.children.size&&s.children.has("__ungrouped__")&&s.children.get("__ungrouped__").rows.length===e.length)return[];const a=/* @__PURE__ */new Map;for(let g=0;g<e.length;g++)a.set(e[g],g);const d=/* @__PURE__ */new Set([...r,...o??[]]),l=e=>{const t=[...e.children.values()],r=e===s?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},u=[],p=e=>{if(e===s){for(const t of l(e))p(t);return}const t=d.has(e.key);if(u.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))p(r);else e.rows.forEach(e=>u.push({kind:"data",row:e,rowIndex:a.get(e)??-1}))};return p(s),u}function C(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 A({groups:e,expanded:t,groupRows:r,loadingGroups:o,parentPath:n=[]}){const i=[],s=n.length;for(const a of e){const e=[...n,a.key],d=t.has(a.key),l=r.get(a.key)??[],u=o.has(a.key);if(i.push({kind:"group",key:a.key,value:a.value,depth:s,rows:l,expanded:d}),d)if(a.children?.length){const n=A({groups:a.children,expanded:t,groupRows:r,loadingGroups:o,parentPath:e});i.push(...n)}else u?i.push({kind:"data",row:{__loading:!0,__groupKey:a.key},rowIndex:-1}):l.forEach((e,t)=>{i.push({kind:"data",row:e,rowIndex:t})})}return i}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[]}var S=class extends _{static manifest={modifiesRowStructure:!0,hookPriority:{processRows:10,onHeaderClick:-1},incompatibleWith:[{name:"tree",reason:"Both plugins transform the entire row model. TreePlugin flattens nested hierarchies while GroupingRowsPlugin groups flat rows with synthetic headers. Use one approach per grid."},{name:"pivot",reason:"PivotPlugin creates its own aggregated row and column structure. Row grouping cannot be applied on top of pivot-generated rows."}],events:[{type:"group-toggle",description:"Emitted when groups are expanded/collapsed. Broadcast to both DOM consumers and plugin bus."},{type:"group-expand",description:"Emitted when a pre-defined group is expanded."},{type:"group-collapse",description:"Emitted when a pre-defined group is collapsed."}],queries:[{type:"canMoveRow",description:"Returns false for group header rows (cannot be reordered)"},{type:"grouping:get-grouped-fields",description:"Returns the column field names that match group depth levels (string[])"},{type:"datasource:viewport-mapping",description:"Translates flat viewport row indices to top-level group indices for ServerSide pagination."}],configRules:[{id:"groupingRows/accordion-defaultExpanded",severity:"warn",message:'"accordion: true" and "defaultExpanded" (non-false) are used together.\n → In accordion mode, only one group can be open at a time.\n → Using defaultExpanded with multiple groups will collapse to one on first toggle.\n → Consider using "defaultExpanded: false" or a single group key/index with accordion mode.',check:e=>!0===e.accordion&&!1!==e.defaultExpanded&&void 0!==e.defaultExpanded&&!("number"==typeof e.defaultExpanded)&&!("string"==typeof e.defaultExpanded)&&(!0===e.defaultExpanded||Array.isArray(e.defaultExpanded)&&e.defaultExpanded.length>1)}]};static dependencies=[{name:"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";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-label{align-items:center;gap:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));display:inline-flex}.group-count{color:var(--tbw-grouping-rows-count-color,var(--tbw-color-fg-muted));font-size:var(--tbw-font-size-xs,.85em);font-weight:400}.group-aggregates{align-items:center;gap:var(--tbw-spacing-lg,1rem);margin-left:var(--tbw-spacing-lg,1rem);font-weight:400;font-size:var(--tbw-font-size-sm,.875em);color:var(--tbw-grouping-rows-aggregate-color,var(--tbw-color-fg-muted));display:inline-flex}.group-aggregate{white-space:nowrap}.group-row{padding-left:calc(var(--tbw-group-depth,0) * var(--tbw-group-indent-width,1.25em))}.data-grid-row.tbw-group-slide-in{animation:tbw-group-slide-in var(--tbw-animation-duration,.2s) var(--tbw-animation-easing,ease-out) forwards}@keyframes tbw-group-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.data-grid-row.tbw-group-fade-in{animation:tbw-group-fade-in var(--tbw-animation-duration,.2s) var(--tbw-animation-easing,ease-out) forwards}@keyframes tbw-group-fade-in{0%{opacity:0}to{opacity:1}}}";get defaultConfig(){return{defaultExpanded:!1,showRowCount:!0,indentWidth:20,aggregators:{},animation:"slide",accordion:!1}}expandedKeys=/* @__PURE__ */new Set;flattenedRows=[];isActive=!1;previousVisibleKeys=/* @__PURE__ */new Set;keysToAnimate=/* @__PURE__ */new Set;hasAppliedDefaultExpanded=!1;pendingExpansion;groupConfigDirty=!1;preDefinedGroups=[];groupRowsMap=/* @__PURE__ */new Map;loadingGroups=/* @__PURE__ */new Set;groupedFields=[];userGroupSortDirections=/* @__PURE__ */new Map;flatMeta=[];get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}detach(){(this.gridElement?.querySelector(".rows-body"))?.setAttribute("role","grid"),this.expandedKeys.clear(),this.flattenedRows=[],this.flatMeta=[],this.isActive=!1,this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.hasAppliedDefaultExpanded=!1,this.pendingExpansion=void 0,this.groupConfigDirty=!1,this.preDefinedGroups=[],this.groupRowsMap.clear(),this.loadingGroups.clear(),this.groupedFields=[],this.userGroupSortDirections.clear()}getRowHeight(e,t){if(null!=this.config.groupRowHeight)return!0===e.__isGroupRow?this.config.groupRowHeight:void 0}handleQuery(e){if("canMoveRow"===e.type&&!0===e.context?.__isGroupRow)return!1;if("grouping:get-grouped-fields"===e.type)return[...this.groupedFields];if("datasource:viewport-mapping"===e.type){const{viewportStart:t,viewportEnd:r}=e.context;if(0===this.flattenedRows.length)return;if(0===this.preDefinedGroups.length&&!Array.isArray(this.config.groups))return;const o=this.getActiveGroups();return{startNode:this.getTopLevelGroupIndex(t),endNode:this.getTopLevelGroupIndex(r)+1,totalLoadedNodes:o.length}}}getTopLevelGroupIndex(e){let t=-1;const r=Math.min(e,this.flattenedRows.length-1);for(let o=0;o<=r;o++){const e=this.flattenedRows[o];"group"===e.kind&&0===e.depth&&t++}return Math.max(0,t)}attach(e){super.attach(e),this.on("datasource:data",e=>{const t=e;t.claimed||(t.claimed=!0,this.preDefinedGroups=t.rows,this.groupRowsMap.clear(),this.loadingGroups.clear(),this.hasAppliedDefaultExpanded=!1,this.requestRender())}),this.on("datasource:children",e=>{const t=e;if("grouping-rows"!==t.context?.source)return;t.claimed=!0;const r=t.context.groupKey;r&&(this.groupRowsMap.set(r,t.rows),this.loadingGroups.delete(r),this.requestRender())})}onHeaderClick(e){const t=this.groupedFields.indexOf(e.field);if(-1===t)return;if(!e.column.sortable)return;const r=t,o=this.userGroupSortDirections.get(r)??1;return this.userGroupSortDirections.set(r,1===o?-1:1),this.requestRender(),!0}resolveGroupSortDirections(e){const t=this.config;if("function"!=typeof t.groupOn||0===e.length)return void(this.groupedFields=[]);const r=this.columns.map(e=>e.field),o=function(e,t,r){const o=/* @__PURE__ */new Map;if(0===e.length)return o;const n=e[0];let i=t(n);if(null==i||!1===i)return o;Array.isArray(i)||(i=[i]);for(let s=0;s<i.length;s++){const e=i[s];for(const t of r)if(n[t]===e){o.set(s,t);break}}return o}([...e],t.groupOn,r);if(this.groupedFields=[...o.values()],0===o.size)return;const n=new Map(this.userGroupSortDirections);if(n.size<o.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;t._sortState&&e.set(t._sortState.field,t._sortState.direction)}for(const[r,i]of o)if(!n.has(r)){const t=e.get(i);void 0!==t&&n.set(r,t)}}return n.size>0?n:void 0}static detect(e,t){return"function"==typeof t?.groupOn||"boolean"==typeof t?.enableRowGrouping||Array.isArray(t?.groups)}processRows(e){const t=this.pendingExpansion;if(this.pendingExpansion=void 0,this.groupConfigDirty=!1,this.preDefinedGroups.length>0||Array.isArray(this.config.groups))return this.preDefinedGroups.length>0||Array.isArray(this.config.groups)&&this.config.groups.length>0?this.processPreDefinedGroups():(this.isActive=!1,this.flattenedRows=[],[]);const r=this.config;if("function"!=typeof r.groupOn)return this.isActive=!1,this.flattenedRows=[],[...e];const o=this.resolveGroupSortDirections(e),n=R({rows:[...e],config:r,expanded:/* @__PURE__ */new Set,groupSortDirections:o});if(0===n.length)return this.isActive=!1,this.flattenedRows=[],[...e];let i;const s=void 0!==t;let a;if(s?i=t:this.hasAppliedDefaultExpanded||0!==this.expandedKeys.size||!1===r.defaultExpanded||(i=r.defaultExpanded??!1),void 0!==i){const e=function(e){return e.filter(e=>"group"===e.kind).map(e=>e.key)}(n);a=C(i,e),(s||a.size>0)&&(this.expandedKeys=new Set(a),this.hasAppliedDefaultExpanded=!0)}const d=R({rows:[...e],config:r,expanded:this.expandedKeys,initialExpanded:a,groupSortDirections:o});this.isActive=!0,this.flattenedRows=d,this.computeFlatMeta(),s&&this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.keysToAnimate.clear();const l=/* @__PURE__ */new Set;return d.forEach((e,t)=>{if("data"===e.kind){const e=`data-${t}`;l.add(e),this.previousVisibleKeys.has(e)||this.keysToAnimate.add(e)}}),this.previousVisibleKeys=l,d.map(e=>{return"group"===e.kind?{__isGroupRow:!0,__groupKey:e.key,__groupValue:e.value,__groupDepth:e.depth,__groupRows:e.rows,__groupExpanded:e.expanded,__groupRowCount:(t=e,"group"!==t.kind?0:t.rows.length),__rowCacheKey:`group:${e.key}`}:e.row;var t})}onCellClick(e){const r=e.row;if(r?.__isGroupRow&&e.originalEvent.target?.closest(`.${t}`))return this.toggle(r.__groupKey),!0}onKeyDown(e){if(" "!==e.key)return;const t=this.grid._focusRow,r=this.rows[t];return r?.__isGroupRow?(e.preventDefault(),this.toggle(r.__groupKey),this.requestRenderWithFocus(),!0):void 0}renderRow(e,t,r){if(!0===e?.__loading&&e?.__groupKey){t.className="data-grid-row",t.__isCustomRow=!0,t.innerHTML="";const e=document.createElement("div");return e.className="cell",e.style.gridColumn="1 / -1",e.setAttribute("role","gridcell"),e.textContent=" ",t.appendChild(e),function(e,t){if(t){if(e.classList.add("tbw-row-loading"),e.setAttribute("aria-busy","true"),!e.querySelector(".tbw-row-loading-overlay")){const t=document.createElement("div");t.className="tbw-row-loading-overlay",t.setAttribute("aria-hidden","true");const r=document.createElement("div");r.className="tbw-row-loading-spinner",t.appendChild(r),e.appendChild(t)}}else e.classList.remove("tbw-row-loading"),e.removeAttribute("aria-busy"),e.querySelector(".tbw-row-loading-overlay")?.remove()}(t,!0),!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?t.innerHTML=n:(t.innerHTML="",t.appendChild(n)),!0}const n=()=>{this.toggle(e.__groupKey)};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);const i=this.flatMeta[r];return i&&(t.setAttribute("aria-level",String(i.level)),t.setAttribute("aria-setsize",String(i.setSize)),t.setAttribute("aria-posinset",String(i.posInSet))),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.gridElement?.querySelector(".rows-body");t&&"treegrid"!==t.getAttribute("role")&&t.setAttribute("role","treegrid");for(const n of e.querySelectorAll(".data-grid-row:not(.group-row)")){const e=n.querySelector(".cell[data-row]"),t=e?parseInt(e.getAttribute("data-row")??"-1",10):-1,r=this.flatMeta[t];r&&(n.setAttribute("aria-level",String(r.level)),n.setAttribute("aria-setsize",String(r.setSize)),n.setAttribute("aria-posinset",String(r.posInSet)))}const r=this.animationStyle;if(!1===r||0===this.keysToAnimate.size)return;const o="fade"===r?"tbw-group-fade-in":"tbw-group-slide-in";for(const n of e.querySelectorAll(".data-grid-row:not(.group-row)")){const e=n.querySelector(".cell[data-row]"),t=e?parseInt(e.getAttribute("data-row")??"-1",10):-1,r="data"===this.flattenedRows[t]?.kind?`data-${t}`:void 0;r&&this.keysToAnimate.has(r)&&(n.classList.add(o),n.addEventListener("animationend",()=>n.classList.remove(o),{once:!0}))}this.keysToAnimate.clear()}computeFlatMeta(){const e=this.flattenedRows,t=new Array(e.length),r=/* @__PURE__ */new Map,o=/* @__PURE__ */new Map;let n=null,i=0;for(const l of e)if("group"===l.kind){n&&o.set(n.key,i),n=l,i=0;const e=`${l.key.split("||").slice(0,-1).join("||")}@${l.depth}`;r.set(e,(r.get(e)??0)+1)}else i++;n&&o.set(n.key,i);const s=/* @__PURE__ */new Map;let a=null,d=0;for(let l=0;l<e.length;l++){const n=e[l];if("group"===n.kind){const e=`${n.key.split("||").slice(0,-1).join("||")}@${n.depth}`,o=(s.get(e)??0)+1;s.set(e,o),t[l]={level:n.depth+1,setSize:r.get(e)??1,posInSet:o},a=n,d=0}else{d++;const r=a?.depth??-1,n=a?o.get(a.key)??1:e.length;t[l]={level:r+2,setSize:n,posInSet:d}}}this.flatMeta=t}processPreDefinedGroups(){const e=this.preDefinedGroups.length>0?this.preDefinedGroups:Array.isArray(this.config.groups)?this.config.groups:[];if(0===e.length)return this.isActive=!1,this.flattenedRows=[],[];if(!this.hasAppliedDefaultExpanded&&0===this.expandedKeys.size&&!1!==this.config.defaultExpanded){const t=this.collectGroupKeys(e),r=C(this.config.defaultExpanded??!1,t);r.size>0&&(this.expandedKeys=new Set(r),this.hasAppliedDefaultExpanded=!0)}const t=A({groups:e,expanded:this.expandedKeys,groupRows:this.groupRowsMap,loadingGroups:this.loadingGroups});this.isActive=!0,this.flattenedRows=t,this.computeFlatMeta(),this.keysToAnimate.clear();const r=/* @__PURE__ */new Set;return t.forEach((e,t)=>{if("data"===e.kind){const e=`data-${t}`;r.add(e),this.previousVisibleKeys.has(e)||this.keysToAnimate.add(e)}}),this.previousVisibleKeys=r,t.map(t=>{if("group"===t.kind){const r=this.findGroupDefinition(e,t.key)?.rowCount??t.rows.length;return{__isGroupRow:!0,__groupKey:t.key,__groupValue:t.value,__groupDepth:t.depth,__groupRows:t.rows,__groupExpanded:t.expanded,__groupRowCount:r,__rowCacheKey:`group:${t.key}`}}return t.row})}collectGroupKeys(e){const t=[];for(const r of e)t.push(r.key),r.children?.length&&t.push(...this.collectGroupKeys(r.children));return t}getActiveGroups(){return this.preDefinedGroups.length>0?this.preDefinedGroups:Array.isArray(this.config.groups)?this.config.groups:[]}findGroupDefinition(e,t){for(const r of e){if(r.key===t)return r;if(r.children?.length){const e=this.findGroupDefinition(r.children,t);if(e)return e}}}createToggleButton(r,o){const n=document.createElement("button");return n.type="button",n.className=`${t}${r?` ${e}`:""}`,n.setAttribute("aria-label",r?"Collapse group":"Expand group"),this.setIcon(n,r?"collapse":"expand"),n.addEventListener("click",e=>{e.stopPropagation(),o()}),n}getGroupLabelText(e,t,r){const o=this.config;return o.formatLabel?o.formatLabel(e,t,r):String(e)}renderFullWidthGroupRow(e,t,n){const i=this.config,s=i.aggregators??{},a=e.__groupRows??[],d=document.createElement("div");d.className="cell group-full",d.style.gridColumn="1 / -1",d.setAttribute("role","gridcell"),d.setAttribute("data-col","0"),d.appendChild(this.createToggleButton(e.__groupExpanded,n));const u=document.createElement("span");if(u.className=r,u.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey),d.appendChild(u),!1!==i.showRowCount){const t=document.createElement("span");t.className=o,t.textContent=`(${e.__groupRowCount??e.__groupRows?.length??0})`,d.appendChild(t)}const p=Object.entries(s);if(p.length>0){const e=document.createElement("span");e.className="group-aggregates";for(const[t,r]of p){const o=this.columns.find(e=>e.field===t),n=l.run(r,a,t,o);if(null!=n){const r=document.createElement("span");r.className="group-aggregate",r.setAttribute("data-field",t),r.textContent=`${o?.header??t}: ${n}`,e.appendChild(r)}}e.children.length>0&&d.appendChild(e)}t.appendChild(d)}renderPerColumnGroupRow(e,t,r){const n=this.config,i=n.aggregators??{},s=this.columns,a=e.__groupRows??[],d=(this.gridElement?.querySelector(".body"))?.style.gridTemplateColumns||"";d&&(t.style.display="grid",t.style.gridTemplateColumns=d);let u=!1;s.forEach((s,d)=>{const p=document.createElement("div");if(p.className="cell group-cell",p.setAttribute("data-col",String(d)),p.setAttribute("role","gridcell"),"__tbw_expander"===s.field)return p.setAttribute("data-field",s.field),void t.appendChild(p);if(u){const e=i[s.field];if(e){const t=l.run(e,a,s.field,s);p.textContent=null!=t?String(t):""}else p.textContent=""}else{u=!0,p.appendChild(this.createToggleButton(e.__groupExpanded,r));const t=document.createElement("span"),d=i[s.field];if(d){const r=l.run(d,a,s.field,s);t.textContent=String(null!=r?r:e.__groupValue)}else t.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey);if(p.appendChild(t),!1!==n.showRowCount){const e=document.createElement("span");e.className=o,e.textContent=` (${a.length})`,p.appendChild(e)}}t.appendChild(p)})}expandAll(){if(this.groupConfigDirty)return this.pendingExpansion=!0,this.expandedKeys=/* @__PURE__ */new Set,void this.requestRender();this.expandedKeys=function(e){const t=/* @__PURE__ */new Set;for(const r of e)"group"===r.kind&&t.add(r.key);return t}(this.flattenedRows),this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}collapseAll(){if(this.groupConfigDirty)return this.pendingExpansion=!1,this.expandedKeys=/* @__PURE__ */new Set,void this.requestRender();this.expandedKeys=/* @__PURE__ */new Set,this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}toggle(e){const t=!this.expandedKeys.has(e),r=this.config,o=this.flattenedRows.find(t=>"group"===t.kind&&t.key===e);if(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=this.findGroupDefinition(n,e);t&&(this.loadingGroups.add(e),this.grid?.query?.("datasource:fetch-children",{context:{source:"grouping-rows",groupKey:e,group:t,groupPath:r}}))}}else this.emit("group-collapse",{groupKey:e,groupPath:r})}const i=this.expandedKeys.has(e),s=null!=o?.value?String(o.value):e;if(i){const e=o?.rows?.length??0;g(this.gridElement,c(this.gridElement,"groupExpanded",s,e))}else g(this.gridElement,c(this.gridElement,"groupCollapsed",s));this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}expand(e){this.expandedKeys.has(e)||(this.expandedKeys=/* @__PURE__ */new Set([...this.expandedKeys,e]),this.requestRender())}collapse(e){if(this.expandedKeys.has(e)){const t=new Set(this.expandedKeys);t.delete(e),this.expandedKeys=t,this.requestRender()}}getGroupState(){const e=this.flattenedRows.filter(e=>"group"===e.kind);return{isActive:this.isActive,expandedCount:this.expandedKeys.size,totalGroups:e.length,expandedKeys:[...this.expandedKeys]}}getRowCount(){return this.flattenedRows.length}refreshGroups(){this.requestRender()}getExpandedGroups(){return[...this.expandedKeys]}getFlattenedRows(){return this.flattenedRows}isGroupingActive(){return this.isActive}setGroupOn(e,t){this.config.groupOn=e,this.groupConfigDirty=!0,void 0!==t&&(this.pendingExpansion=t,this.expandedKeys=/* @__PURE__ */new Set,this.hasAppliedDefaultExpanded=!1),this.requestRender()}setGroups(e){this.preDefinedGroups=e,this.groupRowsMap.clear(),this.loadingGroups.clear(),this.expandedKeys.clear(),this.hasAppliedDefaultExpanded=!1,this.requestRender()}getGroups(){return this.preDefinedGroups.length>0?[...this.preDefinedGroups]:Array.isArray(this.config.groups)?[...this.config.groups]:[]}setGroupRows(e,t){this.groupRowsMap.set(e,t),this.loadingGroups.delete(e),this.requestRender()}setGroupLoading(e,t){t?this.loadingGroups.add(e):this.loadingGroups.delete(e),this.requestRender()}clearGroupRows(e){null!=e?this.groupRowsMap.delete(e):this.groupRowsMap.clear(),this.requestRender()}};export{S as GroupingRowsPlugin};
|
|
1
|
+
var e="expanded",t="group-toggle",r="group-label",o="group-count",n=/* @__PURE__ */new WeakMap;function i(e,t,r){return r?.valueAccessor?function(e,t,r=-1){if(!t.valueAccessor)return e?.[t.field];if("object"!=typeof e||null===e)return t.valueAccessor({row:e,column:t,rowIndex:r});const o=e,i=t.field;let s=n.get(o);if(s){const e=s.get(i);if(void 0!==e)return e.v}else s=/* @__PURE__ */new Map,n.set(o,s);const a=t.valueAccessor({row:e,column:t,rowIndex:r});return s.set(i,{v:a}),a}(e,r):e?.[t]}function s(e){return null==e||""===e||"number"==typeof e&&isNaN(e)}var a={sum:(e,t,r)=>{let o=0;for(let n=0;n<e.length;n++){const a=i(e[n],t,r);if(s(a))continue;const d=Number(a);isNaN(d)||(o+=d)}return o},avg:(e,t,r)=>{if(!e.length)return 0;let o=0,n=0;for(let a=0;a<e.length;a++){const d=i(e[a],t,r);if(s(d))continue;const l=Number(d);isNaN(l)||(o+=l,n++)}return n>0?o/n:0},count:e=>e.length,min:(e,t,r)=>{if(!e.length)return 0;let o=1/0;for(let n=0;n<e.length;n++){const a=i(e[n],t,r);if(s(a))continue;const d=Number(a);isNaN(d)||d<o&&(o=d)}return o===1/0?0:o},max:(e,t,r)=>{if(!e.length)return 0;let o=-1/0;for(let n=0;n<e.length;n++){const a=i(e[n],t,r);if(s(a))continue;const d=Number(a);isNaN(d)||d>o&&(o=d)}return o===-1/0?0:o},first:(e,t,r)=>e[0]?i(e[0],t,r):void 0,last:(e,t,r)=>e.length?i(e[e.length-1],t,r):void 0},d=/* @__PURE__ */new Map,l={register(e,t){d.set(e,t)},unregister(e){d.delete(e)},get(e){if(void 0!==e)return"function"==typeof e?e:d.get(e)??a[e]},run(e,t,r,o){const n=this.get(e);return n?n(t,r,o):void 0},has:e=>d.has(e)||e in a,list:()=>[...Object.keys(a),...d.keys()]},u={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,columnSelected:e=>`Column ${e} selected`,columnSelectionChanged:e=>`${e} columns selected`,columnSelectionCleared:()=>"Column selection cleared",selectionAxisChanged:e=>"column"===e?"Row selection cleared, column selection active":"Column selection cleared, row selection active",editingStarted:e=>`Editing row ${e+1}`,editingCommitted:e=>`Row ${e+1} saved`,dataLoaded:e=>`${e} rows loaded`},p={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function g(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 c(e,t,...r){const o=(e&&"effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.messages?.[t];return o?o(...r):u[t](...r)}function h(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function f(e,t,r,o){return`${h(r,o)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var w="__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("")),m=(new RegExp(`__(proto|defineGetter|defineSetter)|${w.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".split("|"))),y=/^on\w+$/i,v=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),b=/^\s*(javascript|vbscript|data|blob):/i;function x(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const o of r){const e=o.tagName.toLowerCase();if(m.has(e)){t.push(o);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(e=>y.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();y.test(e)?r.push(t.name):(v.has(e)&&b.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name)}r.forEach(e=>o.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}var _=class{static dependencies;static manifest;aliases;version="3.1.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},r={};for(const o of Object.keys(t))r[o]=this;for(const o of e){const e=o.userConfig;for(const[n,i]of Object.entries(e)){if(void 0===i)continue;if(!(n in t)){t[n]=i,r[n]=o;continue}if(t[n]===i)continue;const e=r[n]?.constructor.name??this.constructor.name,s=o.constructor.name,a=f("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${e} and ${s}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const o of Object.keys(t))delete t[o];Object.assign(t,r)}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)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(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?._hostElement}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...p,...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;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}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}setIcon(e,t,r){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const o=this.#t(t,r);void 0!==o?"string"==typeof o?e.innerHTML=x(o):o instanceof HTMLElement&&(e.innerHTML="",e.appendChild(o.cloneNode(!0))):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const r=document.createElement("span");r.setAttribute("part","sort-indicator"),r.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(r,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(r,"sortNone"));const o=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return o?e.insertBefore(r,o):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(f(e,t,this.gridElement.id,this.name)):console.warn(`${h(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(f(e,t,this.gridElement.id,this.name))}};function R({rows:e,config:t,expanded:r,initialExpanded:o,groupSortDirections:n}){const i=t.groupOn;if("function"!=typeof i)return[];const s={key:"__root__",value:null,depth:-1,rows:[],children:/* @__PURE__ */new Map};if(e.forEach(e=>{let t=i(e);null==t||!1===t?t=["__ungrouped__"]:Array.isArray(t)||(t=[t]);let r=s;t.forEach((t,o)=>{const n=null==t?"∅":String(t),i="__root__"===r.key?n:r.key+"||"+n;let s=r.children.get(n);s||(s={key:i,value:t,depth:o,rows:[],children:/* @__PURE__ */new Map,parent:r},r.children.set(n,s)),s.rows.push(e),r=s})}),1===s.children.size&&s.children.has("__ungrouped__")&&s.children.get("__ungrouped__").rows.length===e.length)return[];const a=/* @__PURE__ */new Map;for(let g=0;g<e.length;g++)a.set(e[g],g);const d=/* @__PURE__ */new Set([...r,...o??[]]),l=e=>{const t=[...e.children.values()],r=e===s?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},u=[],p=e=>{if(e===s){for(const t of l(e))p(t);return}const t=d.has(e.key);if(u.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))p(r);else e.rows.forEach(e=>u.push({kind:"data",row:e,rowIndex:a.get(e)??-1}))};return p(s),u}function C(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 A({groups:e,expanded:t,groupRows:r,loadingGroups:o,parentPath:n=[]}){const i=[],s=n.length;for(const a of e){const e=[...n,a.key],d=t.has(a.key),l=r.get(a.key)??[],u=o.has(a.key);if(i.push({kind:"group",key:a.key,value:a.value,depth:s,rows:l,expanded:d}),d)if(a.children?.length){const n=A({groups:a.children,expanded:t,groupRows:r,loadingGroups:o,parentPath:e});i.push(...n)}else u?i.push({kind:"data",row:{__loading:!0,__groupKey:a.key},rowIndex:-1}):l.forEach((e,t)=>{i.push({kind:"data",row:e,rowIndex:t})})}return i}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[]}var S=class extends _{static manifest={modifiesRowStructure:!0,hookPriority:{processRows:10,onHeaderClick:-1},incompatibleWith:[{name:"tree",reason:"Both plugins transform the entire row model. TreePlugin flattens nested hierarchies while GroupingRowsPlugin groups flat rows with synthetic headers. Use one approach per grid."},{name:"pivot",reason:"PivotPlugin creates its own aggregated row and column structure. Row grouping cannot be applied on top of pivot-generated rows."}],events:[{type:"group-toggle",description:"Emitted when groups are expanded/collapsed. Broadcast to both DOM consumers and plugin bus."},{type:"group-expand",description:"Emitted when a pre-defined group is expanded."},{type:"group-collapse",description:"Emitted when a pre-defined group is collapsed."}],queries:[{type:"canMoveRow",description:"Returns false for group header rows (cannot be reordered)"},{type:"grouping:get-grouped-fields",description:"Returns the column field names that match group depth levels (string[])"},{type:"datasource:viewport-mapping",description:"Translates flat viewport row indices to top-level group indices for ServerSide pagination."}],configRules:[{id:"groupingRows/accordion-defaultExpanded",severity:"warn",message:'"accordion: true" and "defaultExpanded" (non-false) are used together.\n → In accordion mode, only one group can be open at a time.\n → Using defaultExpanded with multiple groups will collapse to one on first toggle.\n → Consider using "defaultExpanded: false" or a single group key/index with accordion mode.',check:e=>!0===e.accordion&&!1!==e.defaultExpanded&&void 0!==e.defaultExpanded&&!("number"==typeof e.defaultExpanded)&&!("string"==typeof e.defaultExpanded)&&(!0===e.defaultExpanded||Array.isArray(e.defaultExpanded)&&e.defaultExpanded.length>1)}]};static dependencies=[{name:"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";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-label{align-items:center;gap:var(--tbw-panel-gap,var(--tbw-spacing-md,.5rem));display:inline-flex}.group-count{color:var(--tbw-grouping-rows-count-color,var(--tbw-color-fg-muted));font-size:var(--tbw-font-size-xs,.85em);font-weight:400}.group-aggregates{align-items:center;gap:var(--tbw-spacing-lg,1rem);margin-left:var(--tbw-spacing-lg,1rem);font-weight:400;font-size:var(--tbw-font-size-sm,.875em);color:var(--tbw-grouping-rows-aggregate-color,var(--tbw-color-fg-muted));display:inline-flex}.group-aggregate{white-space:nowrap}.group-row{padding-left:calc(var(--tbw-group-depth,0) * var(--tbw-group-indent-width,1.25em))}.data-grid-row.tbw-group-slide-in{animation:tbw-group-slide-in var(--tbw-animation-duration,.2s) var(--tbw-animation-easing,ease-out) forwards}@keyframes tbw-group-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.data-grid-row.tbw-group-fade-in{animation:tbw-group-fade-in var(--tbw-animation-duration,.2s) var(--tbw-animation-easing,ease-out) forwards}@keyframes tbw-group-fade-in{0%{opacity:0}to{opacity:1}}}";get defaultConfig(){return{defaultExpanded:!1,showRowCount:!0,indentWidth:20,aggregators:{},animation:"slide",accordion:!1}}expandedKeys=/* @__PURE__ */new Set;flattenedRows=[];isActive=!1;previousVisibleKeys=/* @__PURE__ */new Set;keysToAnimate=/* @__PURE__ */new Set;hasAppliedDefaultExpanded=!1;pendingExpansion;groupConfigDirty=!1;preDefinedGroups=[];groupRowsMap=/* @__PURE__ */new Map;loadingGroups=/* @__PURE__ */new Set;groupedFields=[];userGroupSortDirections=/* @__PURE__ */new Map;flatMeta=[];get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}detach(){(this.gridElement?.querySelector(".rows-body"))?.setAttribute("role","grid"),this.expandedKeys.clear(),this.flattenedRows=[],this.flatMeta=[],this.isActive=!1,this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.hasAppliedDefaultExpanded=!1,this.pendingExpansion=void 0,this.groupConfigDirty=!1,this.preDefinedGroups=[],this.groupRowsMap.clear(),this.loadingGroups.clear(),this.groupedFields=[],this.userGroupSortDirections.clear()}getRowHeight(e,t){if(null!=this.config.groupRowHeight)return!0===e.__isGroupRow?this.config.groupRowHeight:void 0}handleQuery(e){if("canMoveRow"===e.type&&!0===e.context?.__isGroupRow)return!1;if("grouping:get-grouped-fields"===e.type)return[...this.groupedFields];if("datasource:viewport-mapping"===e.type){const{viewportStart:t,viewportEnd:r}=e.context;if(0===this.flattenedRows.length)return;if(0===this.preDefinedGroups.length&&!Array.isArray(this.config.groups))return;const o=this.getActiveGroups();return{startNode:this.getTopLevelGroupIndex(t),endNode:this.getTopLevelGroupIndex(r)+1,totalLoadedNodes:o.length}}}getTopLevelGroupIndex(e){let t=-1;const r=Math.min(e,this.flattenedRows.length-1);for(let o=0;o<=r;o++){const e=this.flattenedRows[o];"group"===e.kind&&0===e.depth&&t++}return Math.max(0,t)}attach(e){super.attach(e),this.on("datasource:data",e=>{const t=e;t.claimed||(t.claimed=!0,this.preDefinedGroups=t.rows,this.groupRowsMap.clear(),this.loadingGroups.clear(),this.hasAppliedDefaultExpanded=!1,this.requestRender())}),this.on("datasource:children",e=>{const t=e;if("grouping-rows"!==t.context?.source)return;t.claimed=!0;const r=t.context.groupKey;r&&(this.groupRowsMap.set(r,t.rows),this.loadingGroups.delete(r),this.requestRender())})}onHeaderClick(e){const t=this.groupedFields.indexOf(e.field);if(-1===t)return;if(!e.column.sortable)return;const r=t,o=this.userGroupSortDirections.get(r)??1;return this.userGroupSortDirections.set(r,1===o?-1:1),this.requestRender(),!0}resolveGroupSortDirections(e){const t=this.config;if("function"!=typeof t.groupOn||0===e.length)return void(this.groupedFields=[]);const r=this.columns.map(e=>e.field),o=function(e,t,r){const o=/* @__PURE__ */new Map;if(0===e.length)return o;const n=e[0];let i=t(n);if(null==i||!1===i)return o;Array.isArray(i)||(i=[i]);for(let s=0;s<i.length;s++){const e=i[s];for(const t of r)if(n[t]===e){o.set(s,t);break}}return o}([...e],t.groupOn,r);if(this.groupedFields=[...o.values()],0===o.size)return;const n=new Map(this.userGroupSortDirections);if(n.size<o.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;t._sortState&&e.set(t._sortState.field,t._sortState.direction)}for(const[r,i]of o)if(!n.has(r)){const t=e.get(i);void 0!==t&&n.set(r,t)}}return n.size>0?n:void 0}static detect(e,t){return"function"==typeof t?.groupOn||"boolean"==typeof t?.enableRowGrouping||Array.isArray(t?.groups)}processRows(e){const t=this.pendingExpansion;if(this.pendingExpansion=void 0,this.groupConfigDirty=!1,this.preDefinedGroups.length>0||Array.isArray(this.config.groups))return this.preDefinedGroups.length>0||Array.isArray(this.config.groups)&&this.config.groups.length>0?this.processPreDefinedGroups():(this.isActive=!1,this.flattenedRows=[],[]);const r=this.config;if("function"!=typeof r.groupOn)return this.isActive=!1,this.flattenedRows=[],[...e];const o=this.resolveGroupSortDirections(e),n=R({rows:[...e],config:r,expanded:/* @__PURE__ */new Set,groupSortDirections:o});if(0===n.length)return this.isActive=!1,this.flattenedRows=[],[...e];let i;const s=void 0!==t;let a;if(s?i=t:this.hasAppliedDefaultExpanded||0!==this.expandedKeys.size||!1===r.defaultExpanded||(i=r.defaultExpanded??!1),void 0!==i){const e=function(e){return e.filter(e=>"group"===e.kind).map(e=>e.key)}(n);a=C(i,e),(s||a.size>0)&&(this.expandedKeys=new Set(a),this.hasAppliedDefaultExpanded=!0)}const d=R({rows:[...e],config:r,expanded:this.expandedKeys,initialExpanded:a,groupSortDirections:o});this.isActive=!0,this.flattenedRows=d,this.computeFlatMeta(),s&&this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.keysToAnimate.clear();const l=/* @__PURE__ */new Set;return d.forEach((e,t)=>{if("data"===e.kind){const e=`data-${t}`;l.add(e),this.previousVisibleKeys.has(e)||this.keysToAnimate.add(e)}}),this.previousVisibleKeys=l,d.map(e=>{return"group"===e.kind?{__isGroupRow:!0,__groupKey:e.key,__groupValue:e.value,__groupDepth:e.depth,__groupRows:e.rows,__groupExpanded:e.expanded,__groupRowCount:(t=e,"group"!==t.kind?0:t.rows.length),__rowCacheKey:`group:${e.key}`}:e.row;var t})}onCellClick(e){const r=e.row;if(r?.__isGroupRow&&e.originalEvent.target?.closest(`.${t}`))return this.toggle(r.__groupKey),!0}onKeyDown(e){if(" "!==e.key)return;const t=this.grid._focusRow,r=this.rows[t];return r?.__isGroupRow?(e.preventDefault(),this.toggle(r.__groupKey),this.requestRenderWithFocus(),!0):void 0}renderRow(e,t,r){if(!0===e?.__loading&&e?.__groupKey){t.className="data-grid-row",t.__isCustomRow=!0,t.innerHTML="";const e=document.createElement("div");return e.className="cell",e.style.gridColumn="1 / -1",e.setAttribute("role","gridcell"),e.textContent=" ",t.appendChild(e),function(e,t){if(t){if(e.classList.add("tbw-row-loading"),e.setAttribute("aria-busy","true"),!e.querySelector(".tbw-row-loading-overlay")){const t=document.createElement("div");t.className="tbw-row-loading-overlay",t.setAttribute("aria-hidden","true");const r=document.createElement("div");r.className="tbw-row-loading-spinner",t.appendChild(r),e.appendChild(t)}}else e.classList.remove("tbw-row-loading"),e.removeAttribute("aria-busy"),e.querySelector(".tbw-row-loading-overlay")?.remove()}(t,!0),!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?t.innerHTML=n:(t.innerHTML="",t.appendChild(n)),!0}const n=()=>{this.toggle(e.__groupKey)};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);const i=this.flatMeta[r];return i&&(t.setAttribute("aria-level",String(i.level)),t.setAttribute("aria-setsize",String(i.setSize)),t.setAttribute("aria-posinset",String(i.posInSet))),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.gridElement?.querySelector(".rows-body");t&&"treegrid"!==t.getAttribute("role")&&t.setAttribute("role","treegrid");for(const n of e.querySelectorAll(".data-grid-row:not(.group-row)")){const e=n.querySelector(".cell[data-row]"),t=e?parseInt(e.getAttribute("data-row")??"-1",10):-1,r=this.flatMeta[t];r&&(n.setAttribute("aria-level",String(r.level)),n.setAttribute("aria-setsize",String(r.setSize)),n.setAttribute("aria-posinset",String(r.posInSet)))}const r=this.animationStyle;if(!1===r||0===this.keysToAnimate.size)return;const o="fade"===r?"tbw-group-fade-in":"tbw-group-slide-in";for(const n of e.querySelectorAll(".data-grid-row:not(.group-row)")){const e=n.querySelector(".cell[data-row]"),t=e?parseInt(e.getAttribute("data-row")??"-1",10):-1,r="data"===this.flattenedRows[t]?.kind?`data-${t}`:void 0;r&&this.keysToAnimate.has(r)&&(n.classList.add(o),n.addEventListener("animationend",()=>n.classList.remove(o),{once:!0}))}this.keysToAnimate.clear()}computeFlatMeta(){const e=this.flattenedRows,t=new Array(e.length),r=/* @__PURE__ */new Map,o=/* @__PURE__ */new Map;let n=null,i=0;for(const l of e)if("group"===l.kind){n&&o.set(n.key,i),n=l,i=0;const e=`${l.key.split("||").slice(0,-1).join("||")}@${l.depth}`;r.set(e,(r.get(e)??0)+1)}else i++;n&&o.set(n.key,i);const s=/* @__PURE__ */new Map;let a=null,d=0;for(let l=0;l<e.length;l++){const n=e[l];if("group"===n.kind){const e=`${n.key.split("||").slice(0,-1).join("||")}@${n.depth}`,o=(s.get(e)??0)+1;s.set(e,o),t[l]={level:n.depth+1,setSize:r.get(e)??1,posInSet:o},a=n,d=0}else{d++;const r=a?.depth??-1,n=a?o.get(a.key)??1:e.length;t[l]={level:r+2,setSize:n,posInSet:d}}}this.flatMeta=t}processPreDefinedGroups(){const e=this.preDefinedGroups.length>0?this.preDefinedGroups:Array.isArray(this.config.groups)?this.config.groups:[];if(0===e.length)return this.isActive=!1,this.flattenedRows=[],[];if(!this.hasAppliedDefaultExpanded&&0===this.expandedKeys.size&&!1!==this.config.defaultExpanded){const t=this.collectGroupKeys(e),r=C(this.config.defaultExpanded??!1,t);r.size>0&&(this.expandedKeys=new Set(r),this.hasAppliedDefaultExpanded=!0)}const t=A({groups:e,expanded:this.expandedKeys,groupRows:this.groupRowsMap,loadingGroups:this.loadingGroups});this.isActive=!0,this.flattenedRows=t,this.computeFlatMeta(),this.keysToAnimate.clear();const r=/* @__PURE__ */new Set;return t.forEach((e,t)=>{if("data"===e.kind){const e=`data-${t}`;r.add(e),this.previousVisibleKeys.has(e)||this.keysToAnimate.add(e)}}),this.previousVisibleKeys=r,t.map(t=>{if("group"===t.kind){const r=this.findGroupDefinition(e,t.key)?.rowCount??t.rows.length;return{__isGroupRow:!0,__groupKey:t.key,__groupValue:t.value,__groupDepth:t.depth,__groupRows:t.rows,__groupExpanded:t.expanded,__groupRowCount:r,__rowCacheKey:`group:${t.key}`}}return t.row})}collectGroupKeys(e){const t=[];for(const r of e)t.push(r.key),r.children?.length&&t.push(...this.collectGroupKeys(r.children));return t}getActiveGroups(){return this.preDefinedGroups.length>0?this.preDefinedGroups:Array.isArray(this.config.groups)?this.config.groups:[]}findGroupDefinition(e,t){for(const r of e){if(r.key===t)return r;if(r.children?.length){const e=this.findGroupDefinition(r.children,t);if(e)return e}}}createToggleButton(r,o){const n=document.createElement("button");return n.type="button",n.className=`${t}${r?` ${e}`:""}`,n.setAttribute("aria-label",r?"Collapse group":"Expand group"),this.setIcon(n,r?"collapse":"expand"),n.addEventListener("click",e=>{e.stopPropagation(),o()}),n}getGroupLabelText(e,t,r){const o=this.config;return o.formatLabel?o.formatLabel(e,t,r):String(e)}renderFullWidthGroupRow(e,t,n){const i=this.config,s=i.aggregators??{},a=e.__groupRows??[],d=document.createElement("div");d.className="cell group-full",d.style.gridColumn="1 / -1",d.setAttribute("role","gridcell"),d.setAttribute("data-col","0"),d.appendChild(this.createToggleButton(e.__groupExpanded,n));const u=document.createElement("span");if(u.className=r,u.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey),d.appendChild(u),!1!==i.showRowCount){const t=document.createElement("span");t.className=o,t.textContent=`(${e.__groupRowCount??e.__groupRows?.length??0})`,d.appendChild(t)}const p=Object.entries(s);if(p.length>0){const e=document.createElement("span");e.className="group-aggregates";for(const[t,r]of p){const o=this.columns.find(e=>e.field===t),n=l.run(r,a,t,o);if(null!=n){const r=document.createElement("span");r.className="group-aggregate",r.setAttribute("data-field",t),r.textContent=`${o?.header??t}: ${n}`,e.appendChild(r)}}e.children.length>0&&d.appendChild(e)}t.appendChild(d)}renderPerColumnGroupRow(e,t,r){const n=this.config,i=n.aggregators??{},s=this.columns,a=e.__groupRows??[],d=(this.gridElement?.querySelector(".body"))?.style.gridTemplateColumns||"";d&&(t.style.display="grid",t.style.gridTemplateColumns=d);let u=!1;s.forEach((s,d)=>{const p=document.createElement("div");if(p.className="cell group-cell",p.setAttribute("data-col",String(d)),p.setAttribute("role","gridcell"),"__tbw_expander"===s.field)return p.setAttribute("data-field",s.field),void t.appendChild(p);if(u){const e=i[s.field];if(e){const t=l.run(e,a,s.field,s);p.textContent=null!=t?String(t):""}else p.textContent=""}else{u=!0,p.appendChild(this.createToggleButton(e.__groupExpanded,r));const t=document.createElement("span"),d=i[s.field];if(d){const r=l.run(d,a,s.field,s);t.textContent=String(null!=r?r:e.__groupValue)}else t.textContent=this.getGroupLabelText(e.__groupValue,e.__groupDepth||0,e.__groupKey);if(p.appendChild(t),!1!==n.showRowCount){const e=document.createElement("span");e.className=o,e.textContent=` (${a.length})`,p.appendChild(e)}}t.appendChild(p)})}expandAll(){if(this.groupConfigDirty)return this.pendingExpansion=!0,this.expandedKeys=/* @__PURE__ */new Set,void this.requestRender();this.expandedKeys=function(e){const t=/* @__PURE__ */new Set;for(const r of e)"group"===r.kind&&t.add(r.key);return t}(this.flattenedRows),this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}collapseAll(){if(this.groupConfigDirty)return this.pendingExpansion=!1,this.expandedKeys=/* @__PURE__ */new Set,void this.requestRender();this.expandedKeys=/* @__PURE__ */new Set,this.broadcast("group-toggle",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}toggle(e){const t=!this.expandedKeys.has(e),r=this.config,o=this.flattenedRows.find(t=>"group"===t.kind&&t.key===e);if(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=this.findGroupDefinition(n,e);t&&(this.loadingGroups.add(e),this.grid?.query?.("datasource:fetch-children",{context:{source:"grouping-rows",groupKey:e,group:t,groupPath:r}}))}}else this.emit("group-collapse",{groupKey:e,groupPath:r})}const i=this.expandedKeys.has(e),s=null!=o?.value?String(o.value):e;if(i){const e=o?.rows?.length??0;g(this.gridElement,c(this.gridElement,"groupExpanded",s,e))}else g(this.gridElement,c(this.gridElement,"groupCollapsed",s));this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}expand(e){this.expandedKeys.has(e)||(this.expandedKeys=/* @__PURE__ */new Set([...this.expandedKeys,e]),this.requestRender())}collapse(e){if(this.expandedKeys.has(e)){const t=new Set(this.expandedKeys);t.delete(e),this.expandedKeys=t,this.requestRender()}}getGroupState(){const e=this.flattenedRows.filter(e=>"group"===e.kind);return{isActive:this.isActive,expandedCount:this.expandedKeys.size,totalGroups:e.length,expandedKeys:[...this.expandedKeys]}}getRowCount(){return this.flattenedRows.length}refreshGroups(){this.requestRender()}getExpandedGroups(){return[...this.expandedKeys]}getFlattenedRows(){return this.flattenedRows}isGroupingActive(){return this.isActive}setGroupOn(e,t){this.config.groupOn=e,this.groupConfigDirty=!0,void 0!==t&&(this.pendingExpansion=t,this.expandedKeys=/* @__PURE__ */new Set,this.hasAppliedDefaultExpanded=!1),this.requestRender()}setGroups(e){this.preDefinedGroups=e,this.groupRowsMap.clear(),this.loadingGroups.clear(),this.expandedKeys.clear(),this.hasAppliedDefaultExpanded=!1,this.requestRender()}getGroups(){return this.preDefinedGroups.length>0?[...this.preDefinedGroups]:Array.isArray(this.config.groups)?[...this.config.groups]:[]}setGroupRows(e,t){this.groupRowsMap.set(e,t),this.loadingGroups.delete(e),this.requestRender()}setGroupLoading(e,t){t?this.loadingGroups.add(e):this.loadingGroups.delete(e),this.requestRender()}clearGroupRows(e){null!=e?this.groupRowsMap.delete(e):this.groupRowsMap.clear(),this.requestRender()}};export{S as GroupingRowsPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=/{{\s*([^}]+)\s*}}/g,t="__DG_EMPTY__",i=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,n="__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("")),r=new RegExp(`__(proto|defineGetter|defineSetter)|${n.slice(3).join("|")}|this\\b`),s=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".split("|")),o=/^on\w+$/i,a=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),l=/^\s*(javascript|vbscript|data|blob):/i;function d(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],i=e.querySelectorAll("*");for(const n of i){const e=n.tagName.toLowerCase();if(s.has(e)){t.push(n);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===n.namespaceURI)&&Array.from(n.attributes).some(e=>o.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(n);continue}const i=[];for(const t of n.attributes){const e=t.name.toLowerCase();o.test(e)?i.push(t.name):(a.has(e)&&l.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&i.push(t.name)}i.forEach(e=>n.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}function c(e,t){const i=function(e){const t=[];let i=0;for(;i<e.length;){const n=e[i];if(" "!==n){if(n>="0"&&n<="9"||"."===n&&i+1<e.length&&e[i+1]>="0"&&e[i+1]<="9"){const n=i;for(;i<e.length&&(e[i]>="0"&&e[i]<="9"||"."===e[i]);)i++;t.push({type:"num",v:Number(e.slice(n,i))});continue}if("'"===n){let n="";for(i++;i<e.length&&"'"!==e[i];)n+=e[i++];if(i>=e.length)return null;i++,t.push({type:"str",v:n});continue}if(n>="a"&&n<="z"||n>="A"&&n<="Z"||"_"===n||"$"===n){const n=i;for(;i<e.length&&/[\w$.]/.test(e[i]);)i++;t.push({type:"id",v:e.slice(n,i)});continue}if(i+2<e.length){const n=e.slice(i,i+3);if("==="===n||"!=="===n){t.push({type:"op",v:n}),i+=3;continue}}if(i+1<e.length){const n=e.slice(i,i+2);if("=="===n||"!="===n||"<="===n||">="===n||"&&"===n||"||"===n){t.push({type:"op",v:n}),i+=2;continue}}if(!"+-*/%<>!?:(),".includes(n))return null;t.push({type:"op",v:n}),i++}else i++}return t}(e);if(!i)return;const n=i;let r=0;function s(){return n[r]}function o(){return n[r++]}function a(e,t){const i=s();return!!i&&(i.type===e&&(void 0===t||i.v===t))}function l(){const e=function(){let e=d();for(;a("op","||");)o(),e=e||d();return e}();if(a("op","?")){o();const t=l();if(!a("op",":"))return;o();const i=l();return e?t:i}return e}function d(){let e=c();for(;a("op","&&");)o(),e=e&&c();return e}function c(){let e=u();for(;;){const t=s();if(!t||"op"!==t.type)break;if("==="===t.v)o(),e=e===u();else if("!=="===t.v)o(),e=e!==u();else if("=="===t.v)o(),e=e==u();else{if("!="!==t.v)break;o(),e=e!=u()}}return e}function u(){let e=h();for(;;){const t=s();if(!t||"op"!==t.type)break;if("<"===t.v)o(),e=e<h();else if(">"===t.v)o(),e=e>h();else if("<="===t.v)o(),e=e<=h();else{if(">="!==t.v)break;o(),e=e>=h()}}return e}function h(){let e=f();for(;;){const t=s();if(!t||"op"!==t.type)break;if("+"===t.v)o(),e+=f();else{if("-"!==t.v)break;o(),e-=f()}}return e}function f(){let e=g();for(;;){const t=s();if(!t||"op"!==t.type)break;if("*"===t.v)o(),e*=g();else if("/"===t.v)o(),e/=g();else{if("%"!==t.v)break;o(),e%=g()}}return e}function g(){return a("op","!")?(o(),!g()):p()}function p(){const e=s();if(e){if("num"===e.type)return o(),e.v;if("str"===e.type)return o(),e.v;if("id"===e.type)return o(),function(e){if("value"===e)return t.value;if(e.startsWith("row.")){const i=e.slice(4);return t.row?t.row[i]:void 0}if(e.startsWith("typeDefault.")){const i=e.slice(12);return t.typeDefault?t.typeDefault[i]:void 0}return"row"===e?t.row:"typeDefault"===e?t.typeDefault:void 0}(e.v);if("op"===e.type&&"("===e.v){o();const e=l();return a("op",")")&&o(),e}return"op"===e.type&&"-"===e.v?(o(),-p()):void 0}}const m=l();return r<n.length?void 0:m}function u(n,s){if(!n||-1===n.indexOf("{{"))return n;const o=[],a=(l=n.replace(e,(e,n)=>{const a=function(e,n){if(!(e=(e||"").trim()))return t;if(h.test(e))return t;if("value"===e)return null==n.value?t:String(n.value);if(e.startsWith("row.")&&!/[()?]/.test(e)&&!e.includes(":")){const i=e.slice(4),r=n.row?n.row[i]:void 0;return null==r?t:String(r)}if(e.startsWith("typeDefault.")&&!/[()?]/.test(e)&&!e.includes(":")){const i=e.slice(12),r=n.typeDefault?n.typeDefault[i]:void 0;return null==r?t:String(r)}if(e.length>80)return t;if(!i.test(e)||r.test(e))return t;const s=e.match(/\./g);if(s&&s.length>1)return t;try{const i=c(e,n),r=null==i?"":String(i);return h.test(r)?t:r||t}catch{return t}}(n,s);return o.push({expr:n.trim(),result:a}),a}),l?l.replace(new RegExp(t,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):l);var l;const d=o.length&&o.every(e=>""===e.result||e.result===t);return h.test(n)||d?"":a}var h=/Reflect|Proxy|ownKeys/;function f(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function g(e,t,i,n){return`${f(i,n)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var p={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var m=class{static dependencies;static manifest;aliases;version="3.0.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},i={};for(const n of Object.keys(t))i[n]=this;for(const n of e){const e=n.userConfig;for(const[r,s]of Object.entries(e)){if(void 0===s)continue;if(!(r in t)){t[r]=s,i[r]=n;continue}if(t[r]===s)continue;const e=i[r]?.constructor.name??this.constructor.name,o=n.constructor.name,a=g("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${r}" supplied by both ${e} and ${o}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,i={...e.userConfig};for(const n of Object.keys(t))delete t[n];Object.assign(t,i)}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 i=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.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)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(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?._hostElement}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...p,...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;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(t,10);if(!isNaN(i))return i}return 200}setIcon(e,t,i){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const n=this.#t(t,i);void 0!==n?"string"==typeof n?e.innerHTML=d(n):n instanceof HTMLElement&&(e.innerHTML="",e.appendChild(n.cloneNode(!0))):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const i=document.createElement("span");i.setAttribute("part","sort-indicator"),i.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(i,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(i,"sortNone"));const n=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return n?e.insertBefore(i,n):e.appendChild(i),i}warn(e,t){void 0!==t?console.warn(g(e,t,this.gridElement.id,this.name)):console.warn(`${f(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(g(e,t,this.gridElement.id,this.name))}},w="__tbw_expander";function b(e){return e.field===w}function v(e,t){return e.has(t)?e.delete(t):e.add(t),e}function x(e,t,i,n){const r=document.createElement("div");r.className="master-detail-row",r.setAttribute("data-detail-for",String(t)),r.setAttribute("role","row");const s=document.createElement("div");s.className="master-detail-cell",s.setAttribute("role","cell"),s.style.gridColumn=`1 / ${n+1}`;const o=i(e,t);return"string"==typeof o?s.innerHTML=o:o instanceof HTMLElement&&s.appendChild(o),r.appendChild(s),r}var y=class e extends m{name="masterDetail";styles="@layer tbw-plugins{tbw-grid .cell[data-field=__tbw_expander]{justify-content:center;align-items:center;padding:0;display:flex;border-right:none!important}tbw-grid .header-row .cell[data-field=__tbw_expander]{display:none}tbw-grid .master-detail-expander{justify-content:center;align-items:center;width:100%;height:100%;display:flex}tbw-grid .master-detail-toggle{cursor:pointer;opacity:.7;-webkit-user-select:none;user-select:none;justify-content:center;align-items:center;display:inline-flex}tbw-grid .master-detail-toggle:hover{opacity:1}tbw-grid .master-detail-row{background:var(--tbw-master-detail-bg,var(--tbw-color-row-alt));border-bottom:1px solid var(--tbw-master-detail-border,var(--tbw-color-border));grid-column:1/-1;display:grid;overflow:hidden}tbw-grid .master-detail-cell{padding:var(--tbw-detail-padding,var(--tbw-spacing-xl,1rem));overflow:auto}tbw-grid .master-detail-row.tbw-expanding{animation:tbw-detail-expand var(--tbw-animation-duration,.2s) var(--tbw-animation-easing,ease-out) forwards}tbw-grid .master-detail-row.tbw-collapsing{animation:tbw-detail-collapse var(--tbw-animation-duration,.2s) var(--tbw-animation-easing,ease-out) forwards}@keyframes tbw-detail-expand{0%{opacity:0;max-height:0;padding-top:0;padding-bottom:0}to{opacity:1;max-height:var(--tbw-detail-max-height,31.25rem);padding-top:var(--tbw-detail-padding,var(--tbw-spacing-xl,1rem));padding-bottom:var(--tbw-detail-padding,var(--tbw-spacing-xl,1rem))}}@keyframes tbw-detail-collapse{0%{opacity:1;max-height:var(--tbw-detail-max-height,31.25rem)}to{opacity:0;max-height:0}}}";static dependencies=[{name:"serverSide",required:!1,reason:"Fetches detail data via datasource:fetch-children on expand"}];get#i(){return this.grid}get defaultConfig(){return{detailHeight:"auto",expandOnRowClick:!1,animation:"slide"}}attach(e){super.attach(e),this.parseLightDomDetail(),this.on("datasource:children",e=>{const t=e;if("master-detail"!==t.context?.source)return;t.claimed=!0;const i=t.context.row;if(i&&this.expandedRows.has(i)){this.detailDataMap.set(i,t.rows),this.loadingDetails.delete(i);const e=this.detailElements.get(i);e&&(e.remove(),this.detailElements.delete(i),this.measuredDetailHeights.delete(i)),this.requestRender()}})}parseLightDomDetail(){const e=this.gridElement;if(!e)return;const t=e.querySelector("tbw-grid-detail");if(!t)return;const i=this.#i.__frameworkAdapter;if(i?.parseDetailElement){const e=i.parseDetailElement(t);if(e)return void(this.config={...this.config,detailRenderer:e})}const n=t.getAttribute("animation"),r=t.getAttribute("show-expand-column"),s=t.getAttribute("expand-on-row-click"),o=t.getAttribute("height"),a={};null!==n&&(a.animation="false"!==n&&n),null!==r&&(a.showExpandColumn="false"!==r),null!==s&&(a.expandOnRowClick="true"===s),null!==o&&(a.detailHeight="auto"===o?"auto":parseInt(o,10));const l=t.innerHTML.trim();l&&!this.config.detailRenderer&&(a.detailRenderer=(e,t)=>d(u(l,{value:e,row:e}))),Object.keys(a).length>0&&(this.config={...this.config,...a})}get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}animateExpand(e,t,i){if(!this.isAnimationEnabled||!1===this.animationStyle)return!1;e.classList.add("tbw-expanding");let n=!1;const r=()=>{n||(n=!0,e.classList.remove("tbw-expanding"),void 0!==t&&void 0!==i&&this.#n(e,t,i))};return e.addEventListener("animationend",r,{once:!0}),setTimeout(r,this.animationDuration+50),!0}animateCollapse(e,t){if(!this.isAnimationEnabled||!1===this.animationStyle)return void t();e.classList.add("tbw-collapsing");const i=()=>{e.classList.remove("tbw-collapsing"),t()};e.addEventListener("animationend",i,{once:!0}),setTimeout(i,this.animationDuration+50)}#n(e,t,i){if(!e.isConnected)return;const n=e.offsetHeight;if(n>0){const e=this.measuredDetailHeights.get(t);this.measuredDetailHeights.set(t,n),e!==n&&this.grid.invalidateRowHeight(i)}}expandedRows=/* @__PURE__ */new Set;detailElements=/* @__PURE__ */new Map;measuredDetailHeights=/* @__PURE__ */new Map;rowsToAnimate=/* @__PURE__ */new Set;loadingDetails=/* @__PURE__ */new Set;detailDataMap=/* @__PURE__ */new Map;static DEFAULT_DETAIL_HEIGHT=150;getDetailHeight(t){const i=this.detailElements.get(t);if(i&&!i.classList.contains("tbw-expanding")&&!i.classList.contains("tbw-collapsing")){const e=i.offsetHeight;if(e>0)return this.measuredDetailHeights.set(t,e),e}const n=this.measuredDetailHeights.get(t);return n&&n>0?n:"number"==typeof this.config?.detailHeight?this.config.detailHeight:e.DEFAULT_DETAIL_HEIGHT}toggleAndEmit(e,t){if(e?.__isGroupRow)return;this.expandedRows=v(this.expandedRows,e);const i=this.expandedRows.has(e);i?(this.rowsToAnimate.add(e),this.detailDataMap.has(e)||this.grid?.query?.("datasource:is-active",null)&&(this.loadingDetails.add(e),this.grid.query("datasource:fetch-children",{context:{source:"master-detail",row:e,rowIndex:t}}))):this.loadingDetails.delete(e),this.emit("detail-expand",{rowIndex:t,row:e,expanded:i}),this.requestRender()}detach(){this.expandedRows.clear(),this.detailElements.clear(),this.measuredDetailHeights.clear(),this.rowsToAnimate.clear(),this.loadingDetails.clear(),this.detailDataMap.clear()}processColumns(e){if(!(!0===this.config.showExpandColumn||!1!==this.config.showExpandColumn&&this.config.detailRenderer))return[...e];const t=[...e];if(function(e){return e.find(b)}(t))return t;const i=(n=this.name,{field:w,header:"",width:32,resizable:!1,sortable:!1,filterable:!1,lockPosition:!0,utility:!0,meta:{expanderColumn:!0,expanderPlugin:n}});var n;return i.viewRenderer=e=>{const{row:t}=e,i=this.expandedRows.has(t),n=document.createElement("span");n.className="master-detail-expander expander-cell";const r=document.createElement("span");return r.className="master-detail-toggle"+(i?" expanded":""),this.setIcon(r,i?"collapse":"expand"),r.setAttribute("role","button"),r.setAttribute("tabindex","0"),r.setAttribute("aria-expanded",String(i)),r.setAttribute("aria-label",i?"Collapse details":"Expand details"),n.appendChild(r),n},[i,...t]}onRowClick(e){if(this.config.expandOnRowClick&&this.config.detailRenderer)return this.toggleAndEmit(e.row,e.rowIndex),!1}onCellClick(e){if((e.originalEvent?.target)?.classList.contains("master-detail-toggle"))return this.toggleAndEmit(e.row,e.rowIndex),!0;this.expandedRows.size>0&&queueMicrotask(()=>this.#r())}onKeyDown(e){if(" "!==e.key)return;const t=this.grid._focusCol,i=this.grid._focusRow,n=this.visibleColumns[t];if(!n||!b(n))return;const r=this.rows[i];return r?(e.preventDefault(),this.toggleAndEmit(r,i),this.requestRenderWithFocus(),!0):void 0}afterRender(){this.#s(),this.#r()}#s(){const e=this.gridElement?.querySelector('.header-row .cell[data-field="__tbw_expander"]');if(!e)return;const t=parseInt(e.getAttribute("data-col")||"0",10),i=e.nextElementSibling;i&&(i.style.gridColumn=`${t+1} / ${t+3}`)}onScrollRender(){this.config.detailRenderer&&0!==this.expandedRows.size&&this.#r()}#r(){if(!this.config.detailRenderer)return;const e=this.gridElement?.querySelector(".rows");if(!e)return;const t=this.grid,i=t._rowPool,n=t._virtualization?.start??0,r=t._virtualization?.end??0,s=this.columns.length,o=n,a=r,l=/* @__PURE__ */new Map;if(i){const t=Math.min(i.length,a-o);for(let n=0;n<t;n++){const t=i[n];t.parentNode===e&&l.set(o+n,t)}}else{const t=e.querySelectorAll(".data-grid-row");for(const e of t){const t=e.querySelector(".cell[data-row]"),i=t?parseInt(t.getAttribute("data-row")??"-1",10):-1;i>=0&&l.set(i,e)}}for(const[d,c]of this.detailElements){const e=this.rows.indexOf(d),t=this.expandedRows.has(d),i=e>=0&&l.has(e);if(!t||!i){const e=this.#i.__frameworkAdapter;if(e?.unmount){const t=c.querySelector(".master-detail-cell")?.firstElementChild;t&&e.unmount(t)}c.parentNode&&c.remove(),this.detailElements.delete(d)}}for(const[d,c]of l){const e=this.rows[d];if(!e)continue;const t=this.expandedRows.has(e);if(c.classList.toggle("tbw-row-expanded",t),!t)continue;const i=this.detailElements.get(e);if(i){i.previousElementSibling!==c&&c.after(i);continue}const n=x(e,d,this.config.detailRenderer,s);"number"==typeof this.config.detailHeight&&(n.style.height=`${this.config.detailHeight}px`),c.after(n),this.detailElements.set(e,n);const r=this.rowsToAnimate.has(e);r&&this.rowsToAnimate.delete(e),r&&this.animateExpand(n,e,d)||requestAnimationFrame(()=>{this.#n(n,e,d)})}}getRowHeight(e,t){if(this.expandedRows.has(e))return(this.grid.defaultRowHeight??28)+this.getDetailHeight(e)}adjustVirtualStart(e,t,i){if(0===this.expandedRows.size)return e;const n=this.grid?._virtualization?.positionCache;let r=e;if(n&&n.length>0)for(const s of this.expandedRows){const i=this.rows.indexOf(s);i<0||i>=e||n[i].offset+n[i].height>t&&i<r&&(r=i)}else{const n=[];for(const e of this.expandedRows){const t=this.rows.indexOf(e);t>=0&&n.push({index:t,row:e})}n.sort((e,t)=>e.index-t.index);let s=0;for(const{index:o,row:a}of n){const n=o*i+s,l=this.getDetailHeight(a);s+=l,o>=e||n+i+l>t&&o<r&&(r=o)}}return r}expand(e){const t=this.rows[e];t&&!t.__isGroupRow&&(this.rowsToAnimate.add(t),this.expandedRows=function(e,t){return e.add(t),e}(this.expandedRows,t),this.requestRender())}collapse(e){const t=this.rows[e];t&&(this.expandedRows=function(e,t){return e.delete(t),e}(this.expandedRows,t),this.requestRender())}toggle(e){const t=this.rows[e];t&&!t.__isGroupRow&&(this.expandedRows=v(this.expandedRows,t),this.expandedRows.has(t)&&this.rowsToAnimate.add(t),this.requestRender())}isExpanded(e){const t=this.rows[e];return!!t&&function(e,t){return e.has(t)}(this.expandedRows,t)}expandAll(){for(const e of this.rows)e?.__isGroupRow||(this.rowsToAnimate.add(e),this.expandedRows.add(e));this.requestRender()}collapseAll(){this.expandedRows.clear(),this.requestRender()}getExpandedRows(){const e=[];for(const t of this.expandedRows){const i=this.rows.indexOf(t);i>=0&&e.push(i)}return e}getDetailElement(e){const t=this.rows[e];return t?this.detailElements.get(t):void 0}getDetailData(e){const t=this.rows[e];return t?this.detailDataMap.get(t):void 0}isDetailLoading(e){const t=this.rows[e];return!!t&&this.loadingDetails.has(t)}refreshDetailRenderer(){const e=this.config.detailRenderer;if(this.config={...this.config,detailRenderer:void 0},this.parseLightDomDetail(),!this.config.detailRenderer&&e&&(this.config={...this.config,detailRenderer:e}),this.config.detailRenderer){const e=this.#i;"function"==typeof e.refreshColumns?e.refreshColumns():this.requestRender()}}};export{y as MasterDetailPlugin};
|
|
1
|
+
var e=/{{\s*([^}]+)\s*}}/g,t="__DG_EMPTY__",i=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,n="__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("")),r=new RegExp(`__(proto|defineGetter|defineSetter)|${n.slice(3).join("|")}|this\\b`),s=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".split("|")),o=/^on\w+$/i,a=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),l=/^\s*(javascript|vbscript|data|blob):/i;function d(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],i=e.querySelectorAll("*");for(const n of i){const e=n.tagName.toLowerCase();if(s.has(e)){t.push(n);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===n.namespaceURI)&&Array.from(n.attributes).some(e=>o.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(n);continue}const i=[];for(const t of n.attributes){const e=t.name.toLowerCase();o.test(e)?i.push(t.name):(a.has(e)&&l.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&i.push(t.name)}i.forEach(e=>n.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}function c(e,t){const i=function(e){const t=[];let i=0;for(;i<e.length;){const n=e[i];if(" "!==n){if(n>="0"&&n<="9"||"."===n&&i+1<e.length&&e[i+1]>="0"&&e[i+1]<="9"){const n=i;for(;i<e.length&&(e[i]>="0"&&e[i]<="9"||"."===e[i]);)i++;t.push({type:"num",v:Number(e.slice(n,i))});continue}if("'"===n){let n="";for(i++;i<e.length&&"'"!==e[i];)n+=e[i++];if(i>=e.length)return null;i++,t.push({type:"str",v:n});continue}if(n>="a"&&n<="z"||n>="A"&&n<="Z"||"_"===n||"$"===n){const n=i;for(;i<e.length&&/[\w$.]/.test(e[i]);)i++;t.push({type:"id",v:e.slice(n,i)});continue}if(i+2<e.length){const n=e.slice(i,i+3);if("==="===n||"!=="===n){t.push({type:"op",v:n}),i+=3;continue}}if(i+1<e.length){const n=e.slice(i,i+2);if("=="===n||"!="===n||"<="===n||">="===n||"&&"===n||"||"===n){t.push({type:"op",v:n}),i+=2;continue}}if(!"+-*/%<>!?:(),".includes(n))return null;t.push({type:"op",v:n}),i++}else i++}return t}(e);if(!i)return;const n=i;let r=0;function s(){return n[r]}function o(){return n[r++]}function a(e,t){const i=s();return!!i&&(i.type===e&&(void 0===t||i.v===t))}function l(){const e=function(){let e=d();for(;a("op","||");)o(),e=e||d();return e}();if(a("op","?")){o();const t=l();if(!a("op",":"))return;o();const i=l();return e?t:i}return e}function d(){let e=c();for(;a("op","&&");)o(),e=e&&c();return e}function c(){let e=u();for(;;){const t=s();if(!t||"op"!==t.type)break;if("==="===t.v)o(),e=e===u();else if("!=="===t.v)o(),e=e!==u();else if("=="===t.v)o(),e=e==u();else{if("!="!==t.v)break;o(),e=e!=u()}}return e}function u(){let e=h();for(;;){const t=s();if(!t||"op"!==t.type)break;if("<"===t.v)o(),e=e<h();else if(">"===t.v)o(),e=e>h();else if("<="===t.v)o(),e=e<=h();else{if(">="!==t.v)break;o(),e=e>=h()}}return e}function h(){let e=f();for(;;){const t=s();if(!t||"op"!==t.type)break;if("+"===t.v)o(),e+=f();else{if("-"!==t.v)break;o(),e-=f()}}return e}function f(){let e=g();for(;;){const t=s();if(!t||"op"!==t.type)break;if("*"===t.v)o(),e*=g();else if("/"===t.v)o(),e/=g();else{if("%"!==t.v)break;o(),e%=g()}}return e}function g(){return a("op","!")?(o(),!g()):p()}function p(){const e=s();if(e){if("num"===e.type)return o(),e.v;if("str"===e.type)return o(),e.v;if("id"===e.type)return o(),function(e){if("value"===e)return t.value;if(e.startsWith("row.")){const i=e.slice(4);return t.row?t.row[i]:void 0}if(e.startsWith("typeDefault.")){const i=e.slice(12);return t.typeDefault?t.typeDefault[i]:void 0}return"row"===e?t.row:"typeDefault"===e?t.typeDefault:void 0}(e.v);if("op"===e.type&&"("===e.v){o();const e=l();return a("op",")")&&o(),e}return"op"===e.type&&"-"===e.v?(o(),-p()):void 0}}const m=l();return r<n.length?void 0:m}function u(n,s){if(!n||-1===n.indexOf("{{"))return n;const o=[],a=(l=n.replace(e,(e,n)=>{const a=function(e,n){if(!(e=(e||"").trim()))return t;if(h.test(e))return t;if("value"===e)return null==n.value?t:String(n.value);if(e.startsWith("row.")&&!/[()?]/.test(e)&&!e.includes(":")){const i=e.slice(4),r=n.row?n.row[i]:void 0;return null==r?t:String(r)}if(e.startsWith("typeDefault.")&&!/[()?]/.test(e)&&!e.includes(":")){const i=e.slice(12),r=n.typeDefault?n.typeDefault[i]:void 0;return null==r?t:String(r)}if(e.length>80)return t;if(!i.test(e)||r.test(e))return t;const s=e.match(/\./g);if(s&&s.length>1)return t;try{const i=c(e,n),r=null==i?"":String(i);return h.test(r)?t:r||t}catch{return t}}(n,s);return o.push({expr:n.trim(),result:a}),a}),l?l.replace(new RegExp(t,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):l);var l;const d=o.length&&o.every(e=>""===e.result||e.result===t);return h.test(n)||d?"":a}var h=/Reflect|Proxy|ownKeys/;function f(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function g(e,t,i,n){return`${f(i,n)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var p={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var m=class{static dependencies;static manifest;aliases;version="3.1.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},i={};for(const n of Object.keys(t))i[n]=this;for(const n of e){const e=n.userConfig;for(const[r,s]of Object.entries(e)){if(void 0===s)continue;if(!(r in t)){t[r]=s,i[r]=n;continue}if(t[r]===s)continue;const e=i[r]?.constructor.name??this.constructor.name,o=n.constructor.name,a=g("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${r}" supplied by both ${e} and ${o}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,i={...e.userConfig};for(const n of Object.keys(t))delete t[n];Object.assign(t,i)}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 i=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.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)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(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?._hostElement}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...p,...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;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(t,10);if(!isNaN(i))return i}return 200}setIcon(e,t,i){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const n=this.#t(t,i);void 0!==n?"string"==typeof n?e.innerHTML=d(n):n instanceof HTMLElement&&(e.innerHTML="",e.appendChild(n.cloneNode(!0))):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const i=document.createElement("span");i.setAttribute("part","sort-indicator"),i.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(i,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(i,"sortNone"));const n=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return n?e.insertBefore(i,n):e.appendChild(i),i}warn(e,t){void 0!==t?console.warn(g(e,t,this.gridElement.id,this.name)):console.warn(`${f(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(g(e,t,this.gridElement.id,this.name))}},w="__tbw_expander";function b(e){return e.field===w}function v(e,t){return e.has(t)?e.delete(t):e.add(t),e}function x(e,t,i,n){const r=document.createElement("div");r.className="master-detail-row",r.setAttribute("data-detail-for",String(t)),r.setAttribute("role","row");const s=document.createElement("div");s.className="master-detail-cell",s.setAttribute("role","cell"),s.style.gridColumn=`1 / ${n+1}`;const o=i(e,t);return"string"==typeof o?s.innerHTML=o:o instanceof HTMLElement&&s.appendChild(o),r.appendChild(s),r}var y=class e extends m{name="masterDetail";styles="@layer tbw-plugins{tbw-grid .cell[data-field=__tbw_expander]{justify-content:center;align-items:center;padding:0;display:flex;border-right:none!important}tbw-grid .header-row .cell[data-field=__tbw_expander]{display:none}tbw-grid .master-detail-expander{justify-content:center;align-items:center;width:100%;height:100%;display:flex}tbw-grid .master-detail-toggle{cursor:pointer;opacity:.7;-webkit-user-select:none;user-select:none;justify-content:center;align-items:center;display:inline-flex}tbw-grid .master-detail-toggle:hover{opacity:1}tbw-grid .master-detail-row{background:var(--tbw-master-detail-bg,var(--tbw-color-row-alt));border-bottom:1px solid var(--tbw-master-detail-border,var(--tbw-color-border));grid-column:1/-1;display:grid;overflow:hidden}tbw-grid .master-detail-cell{padding:var(--tbw-detail-padding,var(--tbw-spacing-xl,1rem));overflow:auto}tbw-grid .master-detail-row.tbw-expanding{animation:tbw-detail-expand var(--tbw-animation-duration,.2s) var(--tbw-animation-easing,ease-out) forwards}tbw-grid .master-detail-row.tbw-collapsing{animation:tbw-detail-collapse var(--tbw-animation-duration,.2s) var(--tbw-animation-easing,ease-out) forwards}@keyframes tbw-detail-expand{0%{opacity:0;max-height:0;padding-top:0;padding-bottom:0}to{opacity:1;max-height:var(--tbw-detail-max-height,31.25rem);padding-top:var(--tbw-detail-padding,var(--tbw-spacing-xl,1rem));padding-bottom:var(--tbw-detail-padding,var(--tbw-spacing-xl,1rem))}}@keyframes tbw-detail-collapse{0%{opacity:1;max-height:var(--tbw-detail-max-height,31.25rem)}to{opacity:0;max-height:0}}}";static dependencies=[{name:"serverSide",required:!1,reason:"Fetches detail data via datasource:fetch-children on expand"}];get#i(){return this.grid}get defaultConfig(){return{detailHeight:"auto",expandOnRowClick:!1,animation:"slide"}}attach(e){super.attach(e),this.parseLightDomDetail(),this.on("datasource:children",e=>{const t=e;if("master-detail"!==t.context?.source)return;t.claimed=!0;const i=t.context.row;if(i&&this.expandedRows.has(i)){this.detailDataMap.set(i,t.rows),this.loadingDetails.delete(i);const e=this.detailElements.get(i);e&&(e.remove(),this.detailElements.delete(i),this.measuredDetailHeights.delete(i)),this.requestRender()}})}parseLightDomDetail(){const e=this.gridElement;if(!e)return;const t=e.querySelector("tbw-grid-detail");if(!t)return;const i=this.#i.__frameworkAdapter;if(i?.parseDetailElement){const e=i.parseDetailElement(t);if(e)return void(this.config={...this.config,detailRenderer:e})}const n=t.getAttribute("animation"),r=t.getAttribute("show-expand-column"),s=t.getAttribute("expand-on-row-click"),o=t.getAttribute("height"),a={};null!==n&&(a.animation="false"!==n&&n),null!==r&&(a.showExpandColumn="false"!==r),null!==s&&(a.expandOnRowClick="true"===s),null!==o&&(a.detailHeight="auto"===o?"auto":parseInt(o,10));const l=t.innerHTML.trim();l&&!this.config.detailRenderer&&(a.detailRenderer=(e,t)=>d(u(l,{value:e,row:e}))),Object.keys(a).length>0&&(this.config={...this.config,...a})}get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}animateExpand(e,t,i){if(!this.isAnimationEnabled||!1===this.animationStyle)return!1;e.classList.add("tbw-expanding");let n=!1;const r=()=>{n||(n=!0,e.classList.remove("tbw-expanding"),void 0!==t&&void 0!==i&&this.#n(e,t,i))};return e.addEventListener("animationend",r,{once:!0}),setTimeout(r,this.animationDuration+50),!0}animateCollapse(e,t){if(!this.isAnimationEnabled||!1===this.animationStyle)return void t();e.classList.add("tbw-collapsing");const i=()=>{e.classList.remove("tbw-collapsing"),t()};e.addEventListener("animationend",i,{once:!0}),setTimeout(i,this.animationDuration+50)}#n(e,t,i){if(!e.isConnected)return;const n=e.offsetHeight;if(n>0){const e=this.measuredDetailHeights.get(t);this.measuredDetailHeights.set(t,n),e!==n&&this.grid.invalidateRowHeight(i)}}expandedRows=/* @__PURE__ */new Set;detailElements=/* @__PURE__ */new Map;measuredDetailHeights=/* @__PURE__ */new Map;rowsToAnimate=/* @__PURE__ */new Set;loadingDetails=/* @__PURE__ */new Set;detailDataMap=/* @__PURE__ */new Map;static DEFAULT_DETAIL_HEIGHT=150;getDetailHeight(t){const i=this.detailElements.get(t);if(i&&!i.classList.contains("tbw-expanding")&&!i.classList.contains("tbw-collapsing")){const e=i.offsetHeight;if(e>0)return this.measuredDetailHeights.set(t,e),e}const n=this.measuredDetailHeights.get(t);return n&&n>0?n:"number"==typeof this.config?.detailHeight?this.config.detailHeight:e.DEFAULT_DETAIL_HEIGHT}toggleAndEmit(e,t){if(e?.__isGroupRow)return;this.expandedRows=v(this.expandedRows,e);const i=this.expandedRows.has(e);i?(this.rowsToAnimate.add(e),this.detailDataMap.has(e)||this.grid?.query?.("datasource:is-active",null)&&(this.loadingDetails.add(e),this.grid.query("datasource:fetch-children",{context:{source:"master-detail",row:e,rowIndex:t}}))):this.loadingDetails.delete(e),this.emit("detail-expand",{rowIndex:t,row:e,expanded:i}),this.requestRender()}detach(){this.expandedRows.clear(),this.detailElements.clear(),this.measuredDetailHeights.clear(),this.rowsToAnimate.clear(),this.loadingDetails.clear(),this.detailDataMap.clear()}processColumns(e){if(!(!0===this.config.showExpandColumn||!1!==this.config.showExpandColumn&&this.config.detailRenderer))return[...e];const t=[...e];if(function(e){return e.find(b)}(t))return t;const i=(n=this.name,{field:w,header:"",width:32,resizable:!1,sortable:!1,filterable:!1,lockPosition:!0,utility:!0,meta:{expanderColumn:!0,expanderPlugin:n}});var n;return i.viewRenderer=e=>{const{row:t}=e,i=this.expandedRows.has(t),n=document.createElement("span");n.className="master-detail-expander expander-cell";const r=document.createElement("span");return r.className="master-detail-toggle"+(i?" expanded":""),this.setIcon(r,i?"collapse":"expand"),r.setAttribute("role","button"),r.setAttribute("tabindex","0"),r.setAttribute("aria-expanded",String(i)),r.setAttribute("aria-label",i?"Collapse details":"Expand details"),n.appendChild(r),n},[i,...t]}onRowClick(e){if(this.config.expandOnRowClick&&this.config.detailRenderer)return this.toggleAndEmit(e.row,e.rowIndex),!1}onCellClick(e){if((e.originalEvent?.target)?.classList.contains("master-detail-toggle"))return this.toggleAndEmit(e.row,e.rowIndex),!0;this.expandedRows.size>0&&queueMicrotask(()=>this.#r())}onKeyDown(e){if(" "!==e.key)return;const t=this.grid._focusCol,i=this.grid._focusRow,n=this.visibleColumns[t];if(!n||!b(n))return;const r=this.rows[i];return r?(e.preventDefault(),this.toggleAndEmit(r,i),this.requestRenderWithFocus(),!0):void 0}afterRender(){this.#s(),this.#r()}#s(){const e=this.gridElement?.querySelector('.header-row .cell[data-field="__tbw_expander"]');if(!e)return;const t=parseInt(e.getAttribute("data-col")||"0",10),i=e.nextElementSibling;i&&(i.style.gridColumn=`${t+1} / ${t+3}`)}onScrollRender(){this.config.detailRenderer&&0!==this.expandedRows.size&&this.#r()}#r(){if(!this.config.detailRenderer)return;const e=this.gridElement?.querySelector(".rows");if(!e)return;const t=this.grid,i=t._rowPool,n=t._virtualization?.start??0,r=t._virtualization?.end??0,s=this.columns.length,o=n,a=r,l=/* @__PURE__ */new Map;if(i){const t=Math.min(i.length,a-o);for(let n=0;n<t;n++){const t=i[n];t.parentNode===e&&l.set(o+n,t)}}else{const t=e.querySelectorAll(".data-grid-row");for(const e of t){const t=e.querySelector(".cell[data-row]"),i=t?parseInt(t.getAttribute("data-row")??"-1",10):-1;i>=0&&l.set(i,e)}}for(const[d,c]of this.detailElements){const e=this.rows.indexOf(d),t=this.expandedRows.has(d),i=e>=0&&l.has(e);if(!t||!i){const e=this.#i.__frameworkAdapter;if(e?.unmount){const t=c.querySelector(".master-detail-cell")?.firstElementChild;t&&e.unmount(t)}c.parentNode&&c.remove(),this.detailElements.delete(d)}}for(const[d,c]of l){const e=this.rows[d];if(!e)continue;const t=this.expandedRows.has(e);if(c.classList.toggle("tbw-row-expanded",t),!t)continue;const i=this.detailElements.get(e);if(i){i.previousElementSibling!==c&&c.after(i);continue}const n=x(e,d,this.config.detailRenderer,s);"number"==typeof this.config.detailHeight&&(n.style.height=`${this.config.detailHeight}px`),c.after(n),this.detailElements.set(e,n);const r=this.rowsToAnimate.has(e);r&&this.rowsToAnimate.delete(e),r&&this.animateExpand(n,e,d)||requestAnimationFrame(()=>{this.#n(n,e,d)})}}getRowHeight(e,t){if(this.expandedRows.has(e))return(this.grid.defaultRowHeight??28)+this.getDetailHeight(e)}adjustVirtualStart(e,t,i){if(0===this.expandedRows.size)return e;const n=this.grid?._virtualization?.positionCache;let r=e;if(n&&n.length>0)for(const s of this.expandedRows){const i=this.rows.indexOf(s);i<0||i>=e||n[i].offset+n[i].height>t&&i<r&&(r=i)}else{const n=[];for(const e of this.expandedRows){const t=this.rows.indexOf(e);t>=0&&n.push({index:t,row:e})}n.sort((e,t)=>e.index-t.index);let s=0;for(const{index:o,row:a}of n){const n=o*i+s,l=this.getDetailHeight(a);s+=l,o>=e||n+i+l>t&&o<r&&(r=o)}}return r}expand(e){const t=this.rows[e];t&&!t.__isGroupRow&&(this.rowsToAnimate.add(t),this.expandedRows=function(e,t){return e.add(t),e}(this.expandedRows,t),this.requestRender())}collapse(e){const t=this.rows[e];t&&(this.expandedRows=function(e,t){return e.delete(t),e}(this.expandedRows,t),this.requestRender())}toggle(e){const t=this.rows[e];t&&!t.__isGroupRow&&(this.expandedRows=v(this.expandedRows,t),this.expandedRows.has(t)&&this.rowsToAnimate.add(t),this.requestRender())}isExpanded(e){const t=this.rows[e];return!!t&&function(e,t){return e.has(t)}(this.expandedRows,t)}expandAll(){for(const e of this.rows)e?.__isGroupRow||(this.rowsToAnimate.add(e),this.expandedRows.add(e));this.requestRender()}collapseAll(){this.expandedRows.clear(),this.requestRender()}getExpandedRows(){const e=[];for(const t of this.expandedRows){const i=this.rows.indexOf(t);i>=0&&e.push(i)}return e}getDetailElement(e){const t=this.rows[e];return t?this.detailElements.get(t):void 0}getDetailData(e){const t=this.rows[e];return t?this.detailDataMap.get(t):void 0}isDetailLoading(e){const t=this.rows[e];return!!t&&this.loadingDetails.has(t)}refreshDetailRenderer(){const e=this.config.detailRenderer;if(this.config={...this.config,detailRenderer:void 0},this.parseLightDomDetail(),!this.config.detailRenderer&&e&&(this.config={...this.config,detailRenderer:e}),this.config.detailRenderer){const e=this.#i;"function"==typeof e.refreshColumns?e.refreshColumns():this.requestRender()}}};export{y as MasterDetailPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,columnSelected:e=>`Column ${e} selected`,columnSelectionChanged:e=>`${e} columns selected`,columnSelectionCleared:()=>"Column selection cleared",selectionAxisChanged:e=>"column"===e?"Row selection cleared, column selection active":"Column selection cleared, row selection active",editingStarted:e=>`Editing row ${e+1}`,editingCommitted:e=>`Row ${e+1} saved`,dataLoaded:e=>`${e} rows loaded`},t={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function r(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 o(t,r,...o){const i=(t&&"effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.messages?.[r];return i?i(...o):e[r](...o)}function i(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function n(e,t,r,o){return`${i(r,o)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var s="__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("")),l=(new RegExp(`__(proto|defineGetter|defineSetter)|${s.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".split("|"))),a=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),c=/^\s*(javascript|vbscript|data|blob):/i;function u(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const o of r){const e=o.tagName.toLowerCase();if(l.has(e)){t.push(o);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(e=>a.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();a.test(e)?r.push(t.name):(d.has(e)&&c.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name)}r.forEach(e=>o.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}var h=class{static dependencies;static manifest;aliases;version="3.0.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},r={};for(const o of Object.keys(t))r[o]=this;for(const o of e){const e=o.userConfig;for(const[i,s]of Object.entries(e)){if(void 0===s)continue;if(!(i in t)){t[i]=s,r[i]=o;continue}if(t[i]===s)continue;const e=r[i]?.constructor.name??this.constructor.name,l=o.constructor.name,a=n("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${i}" supplied by both ${e} and ${l}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const o of Object.keys(t))delete t[o];Object.assign(t,r)}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)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(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?._hostElement}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;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}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}setIcon(e,t,r){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const o=this.#t(t,r);void 0!==o?"string"==typeof o?e.innerHTML=u(o):o instanceof HTMLElement&&(e.innerHTML="",e.appendChild(o.cloneNode(!0))):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const r=document.createElement("span");r.setAttribute("part","sort-indicator"),r.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(r,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(r,"sortNone"));const o=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return o?e.insertBefore(r,o):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(n(e,t,this.gridElement.id,this.name)):console.warn(`${i(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(n(e,t,this.gridElement.id,this.name))}},f=/* @__PURE__ */new WeakMap;var g=new Intl.Collator(void 0,{sensitivity:"variant"});function m(e,t,r){if(!t.length)return;const o=t.map(e=>{const t=r.find(t=>t.field===e.field),o=t?.sortComparator??p,i=e.field,n=t?.valueAccessor?e=>function(e,t,r=-1){if(!t.valueAccessor)return e?.[t.field];if("object"!=typeof e||null===e)return t.valueAccessor({row:e,column:t,rowIndex:r});const o=e,i=t.field;let n=f.get(o);if(n){const e=n.get(i);if(void 0!==e)return e.v}else n=/* @__PURE__ */new Map,f.set(o,n);const s=t.valueAccessor({row:e,column:t,rowIndex:r});return n.set(i,{v:s}),s}(e,t):e=>e[i];return{field:i,asc:"asc"===e.direction,comparator:o,getValue:n,pinPlaceholders:!t?.sortComparator}}),i=o.some(e=>e.pinPlaceholders)&&function(e){for(let t=0;t<e.length;t++)if(!0===e[t]?.__loading)return!0;return!1}(e),n=e.length,s=o.length,l=new Array(n*s);for(let u=0;u<n;u++){const t=e[u],r=u*s;for(let e=0;e<s;e++)l[r+e]=o[e].getValue(t)}const a=n<=4294967295?new Uint32Array(n):new Array(n);for(let u=0;u<n;u++)a[u]=u;const d=(t,r)=>{if(i){const o=function(e,t){const r=!0===e?.__loading;return r===(!0===t?.__loading)?0:r?1:-1}(e[t],e[r]);if(0!==o)return o}const n=t*s,a=r*s;for(let i=0;i<s;i++){const s=o[i],d=s.comparator(l[n+i],l[a+i],e[t],e[r]);if(0!==d)return s.asc?d:-d}return 0};Uint32Array,a.sort(d);const c=e.slice();for(let u=0;u<n;u++)e[u]=c[a[u]]}function p(e,t){return null==e&&null==t?0:null==e?1:null==t?-1:"number"==typeof e&&"number"==typeof t?e-t:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():"boolean"==typeof e&&"boolean"==typeof t?e===t?0:e?-1:1:g.compare("string"==typeof e?e:String(e),"string"==typeof t?t:String(t))}function b(e,t){const r=e.findIndex(e=>e.field===t);return r>=0?r+1:void 0}function C(e,t){return e.find(e=>e.field===t)?.direction}var S=class extends h{static manifest={queries:[{type:"sort:get-model",description:"Returns the current multi-sort model as SortModel[]"},{type:"sort:set-model",description:"Sets the multi-sort model from context (SortModel[])"}]};name="multiSort";styles='@layer tbw-plugins{.header-cell[data-sort=asc]:after{content:"↑";margin-left:var(--tbw-spacing-xs,.25em);opacity:.8}.header-cell[data-sort=desc]:after{content:"↓";margin-left:var(--tbw-spacing-xs,.25em);opacity:.8}.sort-indicator{margin-left:var(--tbw-spacing-xs,.25em);opacity:.8}.sort-index{font-size:var(--tbw-font-size-2xs,.7em);background:var(--tbw-multi-sort-badge-bg,var(--tbw-color-panel-bg));color:var(--tbw-multi-sort-badge-color,var(--tbw-color-fg));width:var(--tbw-multi-sort-badge-size,1em);height:var(--tbw-multi-sort-badge-size,1em);margin-left:var(--tbw-spacing-xs,.125em);border-radius:50%;justify-content:center;align-items:center;font-weight:600;display:inline-flex}}';get defaultConfig(){return{maxSortColumns:3,showSortIndex:!0}}sortModel=[];cachedSortResult=null;#r=!1;#o=[];get#i(){return this.grid}clearCoreSortState(){this.#i._sortState=null}#n(e){const t=this.grid?.query?.("grouping:get-grouped-fields",null);if(!Array.isArray(t)||0===t.length)return e;const r=t[0];if(!Array.isArray(r)||0===r.length)return e;const o=new Set(r),i=e.filter(e=>!o.has(e.field));return i.length===e.length?e:i}detach(){this.sortModel=[],this.cachedSortResult=null}handleQuery(e){switch(e.type){case"sort:get-model":return[...this.sortModel];case"sort:set-model":{const t=e.context;return!!Array.isArray(t)&&(this.sortModel=[...t],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),!0)}default:return}}processRows(e){if(0===this.sortModel.length)return this.cachedSortResult=null,[...e];const t=this.#i;if(!t._isGridEditMode&&"number"==typeof t._activeEditRows&&-1!==t._activeEditRows&&this.cachedSortResult&&this.cachedSortResult.length===e.length)return[...this.cachedSortResult];const r=this.#n(this.sortModel),o=e;return r.length>0&&m(o,r,this.columns),this.cachedSortResult=o,o}onHeaderClick(e){if(!this.columns.find(t=>t.field===e.field)?.sortable)return!1;const t=e.originalEvent.shiftKey,i=this.config.maxSortColumns??3;if(this.sortModel=function(e,t,r,o){const i=e.find(e=>e.field===t);return r?i?"asc"===i.direction?e.map(e=>e.field===t?{...e,direction:"desc"}:e):e.filter(e=>e.field!==t):e.length<o?[...e,{field:t,direction:"asc"}]:e:"asc"===i?.direction?[{field:t,direction:"desc"}]:"desc"===i?.direction?[]:[{field:t,direction:"asc"}]}(this.sortModel,e.field,t,i),this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),this.grid?.requestStateChange?.(),this.sortModel.length>0){const e=this.sortModel.map(e=>`${this.columns.find(t=>t.field===e.field)?.header??e.field} ${"asc"===e.direction?"ascending":"descending"}`);r(this.gridElement,o(this.gridElement,"sortApplied",e.join(", then "),""))}else r(this.gridElement,o(this.gridElement,"sortCleared"));return!0}afterRender(){const e=this.gridElement;if(!e)return;const t=!1!==this.config.showSortIndex;e.querySelectorAll(".header-row .cell[data-field]").forEach(e=>{const r=e.getAttribute("data-field");if(!r)return;const o=b(this.sortModel,r),i=C(this.sortModel,r);if(e.querySelector(".sort-index")?.remove(),i){const r=this.updateSortIndicator(e,i);if(t&&this.sortModel.length>1&&void 0!==o){const t=document.createElement("span");t.className="sort-index",t.textContent=String(o),r.nextSibling?e.insertBefore(t,r.nextSibling):e.appendChild(t)}}else e.classList.contains("sortable")&&this.updateSortIndicator(e,null)})}getSortModel(){return[...this.sortModel]}setSortModel(e){if(this.sortModel=[...e],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...e]}),this.requestRender(),this.grid?.requestStateChange?.(),e.length>0){const t=e.map(e=>`${this.columns.find(t=>t.field===e.field)?.header??e.field} ${"asc"===e.direction?"ascending":"descending"}`);r(this.gridElement,o(this.gridElement,"sortApplied",t.join(", then "),""))}}clearSort(){this.sortModel=[],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[]}),this.requestRender(),this.grid?.requestStateChange?.(),r(this.gridElement,o(this.gridElement,"sortCleared"))}getSortIndex(e){return b(this.sortModel,e)}getSortDirection(e){return C(this.sortModel,e)}getColumnState(e){const t=this.sortModel.findIndex(t=>t.field===e);if(-1!==t)return{sort:{direction:this.sortModel[t].direction,priority:t}}}applyColumnState(e,t){if(this.#r||(this.#o=[...this.sortModel]),t.sort){const r=this.sortModel.findIndex(t=>t.field===e),o={field:e,direction:t.sort.direction};-1!==r?this.sortModel[r]=o:this.sortModel.splice(t.sort.priority,0,o)}else this.sortModel=this.sortModel.filter(t=>t.field!==e);this.clearCoreSortState(),this.#r||(this.#r=!0,queueMicrotask(()=>{this.#r=!1;const e=this.#o;this.#o=[],function(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r].field!==t[r].field||e[r].direction!==t[r].direction)return!1;return!0}(e,this.sortModel)||(this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender())}))}};export{S as MultiSortPlugin};
|
|
1
|
+
var e={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,columnSelected:e=>`Column ${e} selected`,columnSelectionChanged:e=>`${e} columns selected`,columnSelectionCleared:()=>"Column selection cleared",selectionAxisChanged:e=>"column"===e?"Row selection cleared, column selection active":"Column selection cleared, row selection active",editingStarted:e=>`Editing row ${e+1}`,editingCommitted:e=>`Row ${e+1} saved`,dataLoaded:e=>`${e} rows loaded`},t={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function r(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 o(t,r,...o){const i=(t&&"effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.messages?.[r];return i?i(...o):e[r](...o)}function i(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function n(e,t,r,o){return`${i(r,o)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var s="__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("")),l=(new RegExp(`__(proto|defineGetter|defineSetter)|${s.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".split("|"))),a=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),c=/^\s*(javascript|vbscript|data|blob):/i;function u(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const o of r){const e=o.tagName.toLowerCase();if(l.has(e)){t.push(o);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(e=>a.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();a.test(e)?r.push(t.name):(d.has(e)&&c.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name)}r.forEach(e=>o.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}var h=class{static dependencies;static manifest;aliases;version="3.1.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},r={};for(const o of Object.keys(t))r[o]=this;for(const o of e){const e=o.userConfig;for(const[i,s]of Object.entries(e)){if(void 0===s)continue;if(!(i in t)){t[i]=s,r[i]=o;continue}if(t[i]===s)continue;const e=r[i]?.constructor.name??this.constructor.name,l=o.constructor.name,a=n("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${i}" supplied by both ${e} and ${l}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const o of Object.keys(t))delete t[o];Object.assign(t,r)}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)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(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?._hostElement}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;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}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}setIcon(e,t,r){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const o=this.#t(t,r);void 0!==o?"string"==typeof o?e.innerHTML=u(o):o instanceof HTMLElement&&(e.innerHTML="",e.appendChild(o.cloneNode(!0))):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const r=document.createElement("span");r.setAttribute("part","sort-indicator"),r.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(r,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(r,"sortNone"));const o=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return o?e.insertBefore(r,o):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(n(e,t,this.gridElement.id,this.name)):console.warn(`${i(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(n(e,t,this.gridElement.id,this.name))}},f=/* @__PURE__ */new WeakMap;var g=new Intl.Collator(void 0,{sensitivity:"variant"});function m(e,t,r){if(!t.length)return;const o=t.map(e=>{const t=r.find(t=>t.field===e.field),o=t?.sortComparator??p,i=e.field,n=t?.valueAccessor?e=>function(e,t,r=-1){if(!t.valueAccessor)return e?.[t.field];if("object"!=typeof e||null===e)return t.valueAccessor({row:e,column:t,rowIndex:r});const o=e,i=t.field;let n=f.get(o);if(n){const e=n.get(i);if(void 0!==e)return e.v}else n=/* @__PURE__ */new Map,f.set(o,n);const s=t.valueAccessor({row:e,column:t,rowIndex:r});return n.set(i,{v:s}),s}(e,t):e=>e[i];return{field:i,asc:"asc"===e.direction,comparator:o,getValue:n,pinPlaceholders:!t?.sortComparator}}),i=o.some(e=>e.pinPlaceholders)&&function(e){for(let t=0;t<e.length;t++)if(!0===e[t]?.__loading)return!0;return!1}(e),n=e.length,s=o.length,l=new Array(n*s);for(let u=0;u<n;u++){const t=e[u],r=u*s;for(let e=0;e<s;e++)l[r+e]=o[e].getValue(t)}const a=n<=4294967295?new Uint32Array(n):new Array(n);for(let u=0;u<n;u++)a[u]=u;const d=(t,r)=>{if(i){const o=function(e,t){const r=!0===e?.__loading;return r===(!0===t?.__loading)?0:r?1:-1}(e[t],e[r]);if(0!==o)return o}const n=t*s,a=r*s;for(let i=0;i<s;i++){const s=o[i],d=s.comparator(l[n+i],l[a+i],e[t],e[r]);if(0!==d)return s.asc?d:-d}return 0};Uint32Array,a.sort(d);const c=e.slice();for(let u=0;u<n;u++)e[u]=c[a[u]]}function p(e,t){return null==e&&null==t?0:null==e?1:null==t?-1:"number"==typeof e&&"number"==typeof t?e-t:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():"boolean"==typeof e&&"boolean"==typeof t?e===t?0:e?-1:1:g.compare("string"==typeof e?e:String(e),"string"==typeof t?t:String(t))}function b(e,t){const r=e.findIndex(e=>e.field===t);return r>=0?r+1:void 0}function C(e,t){return e.find(e=>e.field===t)?.direction}var S=class extends h{static manifest={queries:[{type:"sort:get-model",description:"Returns the current multi-sort model as SortModel[]"},{type:"sort:set-model",description:"Sets the multi-sort model from context (SortModel[])"}]};name="multiSort";styles='@layer tbw-plugins{.header-cell[data-sort=asc]:after{content:"↑";margin-left:var(--tbw-spacing-xs,.25em);opacity:.8}.header-cell[data-sort=desc]:after{content:"↓";margin-left:var(--tbw-spacing-xs,.25em);opacity:.8}.sort-indicator{margin-left:var(--tbw-spacing-xs,.25em);opacity:.8}.sort-index{font-size:var(--tbw-font-size-2xs,.7em);background:var(--tbw-multi-sort-badge-bg,var(--tbw-color-panel-bg));color:var(--tbw-multi-sort-badge-color,var(--tbw-color-fg));width:var(--tbw-multi-sort-badge-size,1em);height:var(--tbw-multi-sort-badge-size,1em);margin-left:var(--tbw-spacing-xs,.125em);border-radius:50%;justify-content:center;align-items:center;font-weight:600;display:inline-flex}}';get defaultConfig(){return{maxSortColumns:3,showSortIndex:!0}}sortModel=[];cachedSortResult=null;#r=!1;#o=[];get#i(){return this.grid}clearCoreSortState(){this.#i._sortState=null}#n(e){const t=this.grid?.query?.("grouping:get-grouped-fields",null);if(!Array.isArray(t)||0===t.length)return e;const r=t[0];if(!Array.isArray(r)||0===r.length)return e;const o=new Set(r),i=e.filter(e=>!o.has(e.field));return i.length===e.length?e:i}detach(){this.sortModel=[],this.cachedSortResult=null}handleQuery(e){switch(e.type){case"sort:get-model":return[...this.sortModel];case"sort:set-model":{const t=e.context;return!!Array.isArray(t)&&(this.sortModel=[...t],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),!0)}default:return}}processRows(e){if(0===this.sortModel.length)return this.cachedSortResult=null,[...e];const t=this.#i;if(!t._isGridEditMode&&"number"==typeof t._activeEditRows&&-1!==t._activeEditRows&&this.cachedSortResult&&this.cachedSortResult.length===e.length)return[...this.cachedSortResult];const r=this.#n(this.sortModel),o=e;return r.length>0&&m(o,r,this.columns),this.cachedSortResult=o,o}onHeaderClick(e){if(!this.columns.find(t=>t.field===e.field)?.sortable)return!1;const t=e.originalEvent.shiftKey,i=this.config.maxSortColumns??3;if(this.sortModel=function(e,t,r,o){const i=e.find(e=>e.field===t);return r?i?"asc"===i.direction?e.map(e=>e.field===t?{...e,direction:"desc"}:e):e.filter(e=>e.field!==t):e.length<o?[...e,{field:t,direction:"asc"}]:e:"asc"===i?.direction?[{field:t,direction:"desc"}]:"desc"===i?.direction?[]:[{field:t,direction:"asc"}]}(this.sortModel,e.field,t,i),this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),this.grid?.requestStateChange?.(),this.sortModel.length>0){const e=this.sortModel.map(e=>`${this.columns.find(t=>t.field===e.field)?.header??e.field} ${"asc"===e.direction?"ascending":"descending"}`);r(this.gridElement,o(this.gridElement,"sortApplied",e.join(", then "),""))}else r(this.gridElement,o(this.gridElement,"sortCleared"));return!0}afterRender(){const e=this.gridElement;if(!e)return;const t=!1!==this.config.showSortIndex;e.querySelectorAll(".header-row .cell[data-field]").forEach(e=>{const r=e.getAttribute("data-field");if(!r)return;const o=b(this.sortModel,r),i=C(this.sortModel,r);if(e.querySelector(".sort-index")?.remove(),i){const r=this.updateSortIndicator(e,i);if(t&&this.sortModel.length>1&&void 0!==o){const t=document.createElement("span");t.className="sort-index",t.textContent=String(o),r.nextSibling?e.insertBefore(t,r.nextSibling):e.appendChild(t)}}else e.classList.contains("sortable")&&this.updateSortIndicator(e,null)})}getSortModel(){return[...this.sortModel]}setSortModel(e){if(this.sortModel=[...e],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...e]}),this.requestRender(),this.grid?.requestStateChange?.(),e.length>0){const t=e.map(e=>`${this.columns.find(t=>t.field===e.field)?.header??e.field} ${"asc"===e.direction?"ascending":"descending"}`);r(this.gridElement,o(this.gridElement,"sortApplied",t.join(", then "),""))}}clearSort(){this.sortModel=[],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[]}),this.requestRender(),this.grid?.requestStateChange?.(),r(this.gridElement,o(this.gridElement,"sortCleared"))}getSortIndex(e){return b(this.sortModel,e)}getSortDirection(e){return C(this.sortModel,e)}getColumnState(e){const t=this.sortModel.findIndex(t=>t.field===e);if(-1!==t)return{sort:{direction:this.sortModel[t].direction,priority:t}}}applyColumnState(e,t){if(this.#r||(this.#o=[...this.sortModel]),t.sort){const r=this.sortModel.findIndex(t=>t.field===e),o={field:e,direction:t.sort.direction};-1!==r?this.sortModel[r]=o:this.sortModel.splice(t.sort.priority,0,o)}else this.sortModel=this.sortModel.filter(t=>t.field!==e);this.clearCoreSortState(),this.#r||(this.#r=!0,queueMicrotask(()=>{this.#r=!1;const e=this.#o;this.#o=[],function(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r].field!==t[r].field||e[r].direction!==t[r].direction)return!1;return!0}(e,this.sortModel)||(this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender())}))}};export{S as MultiSortPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var t="sticky-left",e="sticky-right";function s(t){try{if("rtl"===getComputedStyle(t).direction)return"rtl"}catch{}try{if("rtl"===t.closest?.("[dir]")?.getAttribute("dir"))return"rtl"}catch{}return"ltr"}function n(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function i(t,e,s,i){return`${n(s,i)} ${t}: ${e}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}var r="__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(t=>t.split("").reverse().join("")),o=(new RegExp(`__(proto|defineGetter|defineSetter)|${r.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".split("|"))),l=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),a=/^\s*(javascript|vbscript|data|blob):/i;function c(t){if(!t||"string"!=typeof t)return"";if(-1===t.indexOf("<"))return t;const e=document.createElement("template");return e.innerHTML=t,function(t){const e=[],s=t.querySelectorAll("*");for(const n of s){const t=n.tagName.toLowerCase();if(o.has(t)){e.push(n);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===n.namespaceURI)&&Array.from(n.attributes).some(t=>l.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(n);continue}const s=[];for(const e of n.attributes){const t=e.name.toLowerCase();l.test(t)?s.push(e.name):(d.has(t)&&a.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&s.push(e.name)}s.forEach(t=>n.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content),e.innerHTML}var f={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var u=class{static dependencies;static manifest;aliases;version="3.0.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}get resolvedConfig(){return this.#t?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(t){if(0===t.length)return;const e={...this.userConfig},s={};for(const n of Object.keys(e))s[n]=this;for(const n of t){const t=n.userConfig;for(const[r,o]of Object.entries(t)){if(void 0===o)continue;if(!(r in e)){e[r]=o,s[r]=n;continue}if(e[r]===o)continue;const t=s[r]?.constructor.name??this.constructor.name,l=n.constructor.name,d=i("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${r}" supplied by both ${t} and ${l}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(d)}}Object.assign(this.userConfig,e)}refreshUserConfigFrom(t){const e=this.userConfig,s={...t.userConfig};for(const n of Object.keys(e))delete e[n];Object.assign(e,s)}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const s=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(s),s.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}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?._hostElement}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...f,...t}}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;return!e||"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),s=parseInt(e,10);if(!isNaN(s))return s}return 200}setIcon(t,e,s){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const n=this.#e(e,s);void 0!==n?"string"==typeof n?t.innerHTML=c(n):n instanceof HTMLElement&&(t.innerHTML="",t.appendChild(n.cloneNode(!0))):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const s=document.createElement("span");s.setAttribute("part","sort-indicator"),s.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(s,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(s,"sortNone"));const n=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return n?t.insertBefore(s,n):t.appendChild(s),s}warn(t,e){void 0!==e?console.warn(i(t,e,this.gridElement.id,this.name)):console.warn(`${n(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(t,e){throw new Error(i(t,e,this.gridElement.id,this.name))}};function g(t){return t.pinned??t.meta?.pinned}function p(t,e){return function(t,e){return"left"===t||"right"===t?t:"rtl"===e?"start"===t?"right":"left":"start"===t?"left":"right"}(t,e)}function h(t,e){const s=g(t);return!!s&&"left"===p(s,e)}function m(t,e){const s=g(t);return!!s&&"right"===p(s,e)}function y(t){for(let e=0;e<t.length;e++)if(null!=t[e].pinned||null!=t[e].meta?.pinned)return!0;return!1}function b(n,i){const r={groupEndAdjustments:{addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set},leftOffsets:/* @__PURE__ */new Map,rightOffsets:/* @__PURE__ */new Map,splitGroups:[]},o=Array.from(n.querySelectorAll(".header-row .cell"));if(!o.length)return r;const l=s(n),d=/* @__PURE__ */new Map,a=/* @__PURE__ */new Map;let c=0;for(const e of i)if(h(e,l)){const s=o.find(t=>t.getAttribute("data-field")===e.field);s&&(d.set(e.field,c),s.classList.add(t),s.style.position="sticky",s.style.left=c+"px",n.querySelectorAll(`.data-grid-row .cell[data-field="${e.field}"]`).forEach(e=>{e.classList.add(t),e.style.position="sticky",e.style.left=c+"px"}),c+=s.offsetWidth)}let f=0;for(const t of[...i].reverse())if(m(t,l)){const s=o.find(e=>e.getAttribute("data-field")===t.field);s&&(a.set(t.field,f),s.classList.add(e),s.style.position="sticky",s.style.right=f+"px",n.querySelectorAll(`.data-grid-row .cell[data-field="${t.field}"]`).forEach(t=>{t.classList.add(e),t.style.position="sticky",t.style.right=f+"px"}),f+=s.offsetWidth)}const u=[],g=function(s,n,i,r,o){const l={addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set},d=Array.from(s.querySelectorAll(".header-group-row .header-group-cell"));if(!d.length)return l;for(const a of d){const s=a.style.gridColumn;if(!s)continue;const d=s.match(/^(\d+)\s*\/\s*span\s+(\d+)$/);if(!d)continue;const c=parseInt(d[1],10)-1,f=c+parseInt(d[2],10)-1,u=n.slice(c,f+1);if(!u.length)continue;const g=u.every(t=>h(t,r)),p=u.every(t=>m(t,r));if(g){const e=u[0].field,s=i.find(t=>t.getAttribute("data-field")===e);s&&(a.classList.add(t),a.style.position="sticky",a.style.left=s.style.left)}else if(p){const t=u[u.length-1].field,s=i.find(e=>e.getAttribute("data-field")===t);s&&(a.classList.add(e),a.style.position="sticky",a.style.right=s.style.right)}else if(a.classList.contains("implicit-group"))E(a,u,c,i,r,l);else{const t=u.some(t=>h(t,r)),e=u.some(t=>m(t,r));(t||e)&&w(a,u,c,i,r,l,o)}}return l}(n,i,o,l,u);if(g.addGroupEnd.size>0||g.removeGroupEnd.size>0){for(const t of g.addGroupEnd){const e=o.find(e=>e.getAttribute("data-field")===t);e&&e.classList.add("group-end"),n.querySelectorAll(`.data-grid-row .cell[data-field="${t}"]`).forEach(t=>{t.classList.add("group-end")})}for(const t of g.removeGroupEnd){const e=o.find(e=>e.getAttribute("data-field")===t);e&&e.classList.remove("group-end"),n.querySelectorAll(`.data-grid-row .cell[data-field="${t}"]`).forEach(t=>{t.classList.remove("group-end")})}}return{groupEndAdjustments:g,leftOffsets:d,rightOffsets:a,splitGroups:u}}function v(t,e){return h(t,e)?"left":m(t,e)?"right":"none"}function E(s,n,i,r,o,l){const d=[];for(let t=0;t<n.length;t++){const e=v(n[t],o),s=d[d.length-1];s&&s.state===e?s.cols.push(n[t]):d.push({state:e,cols:[n[t]],colStart:i+t})}if(d.length<=1)return;const a=s.parentElement;if(!a)return;const c=s.nextSibling;a.removeChild(s);for(const f of d){const n=document.createElement("div");if(n.className=s.className,n.setAttribute("data-group",s.getAttribute("data-group")||""),n.style.gridColumn=`${f.colStart+1} / span ${f.cols.length}`,"left"===f.state){const e=f.cols[0].field,s=r.find(t=>t.getAttribute("data-field")===e);s&&(n.classList.add(t),n.style.position="sticky",n.style.left=s.style.left)}else if("right"===f.state){const t=f.cols[f.cols.length-1].field,s=r.find(e=>e.getAttribute("data-field")===t);s&&(n.classList.add(e),n.style.position="sticky",n.style.right=s.style.right)}else"none"===f.state&&f.cols.every(t=>String(t.field||"").startsWith("__tbw_"))&&(n.style.borderRightStyle="none");c?a.insertBefore(n,c):a.appendChild(n)}for(let t=0;t<d.length;t++){const e=d[t],s=d[t+1];if("none"!==e.state&&s&&"none"===s.state){const t=e.cols[e.cols.length-1].field;t&&l.addGroupEnd.add(t)}if("none"===e.state&&e.cols.every(t=>String(t.field||"").startsWith("__tbw_"))){const t=e.cols[e.cols.length-1].field;t&&l.removeGroupEnd.add(t)}}}function w(s,n,i,r,o,l,d){const a=[];for(let t=0;t<n.length;t++){const e=v(n[t],o),s=a[a.length-1];s&&s.state===e?s.cols.push(n[t]):a.push({state:e,cols:[n[t]],colStart:i+t})}if(a.length<=1)return;const c=s.parentElement;if(!c)return;const f=s.textContent||"",u=s.getAttribute("data-group")||"",g=s.nextSibling;c.removeChild(s);const p=a.findIndex(t=>"left"===t.state);let h=-1;for(let t=a.length-1;t>=0;t--)if("right"===a[t].state){h=t;break}const m=p>=0?p:h,y=p>=0&&p+1<a.length?p+1:h>=0&&h-1>=0?h-1:-1;let b,E,w,C="";for(let v=0;v<a.length;v++){const n=a[v],i=document.createElement("div");if(i.className=s.className,i.setAttribute("data-group",u),i.style.gridColumn=`${n.colStart+1} / span ${n.cols.length}`,"left"===n.state){const e=n.cols[0].field,s=r.find(t=>t.getAttribute("data-field")===e);s&&(i.classList.add(t),i.style.position="sticky",i.style.left=s.style.left),v===m&&(i.style.borderRightStyle="none",b=i,C=n.cols[n.cols.length-1].field)}else if("right"===n.state){const t=n.cols[n.cols.length-1].field,s=r.find(e=>e.getAttribute("data-field")===t);s&&(i.classList.add(e),i.style.position="sticky",i.style.right=s.style.right),v===m&&(i.style.borderLeftStyle="none",b=i,C=n.cols[0].field)}if(v===y){i.style.overflow="visible";const t=document.createElement("span");t.textContent=f,t.style.position="relative",t.style.zIndex="36",t.style.display="block",t.style.overflow="hidden",t.style.textOverflow="ellipsis",t.style.whiteSpace="nowrap",i.appendChild(t),E=i,w=t}g?c.insertBefore(i,g):c.appendChild(i)}b&&E&&w&&C&&d.push({groupId:u,label:f,pinnedFragment:b,scrollableFragment:E,floatLabel:w,pinnedField:C,isTransferred:!1,floatOffset:0})}function C(s){s.querySelectorAll(`.${t}, .${e}`).forEach(s=>{s.classList.remove(t,e),s.style.position="",s.style.left="",s.style.right=""})}var A="canMoveColumn",S=class extends u{static manifest={hookPriority:{processColumns:-10},ownedProperties:[{property:"pinned",level:"column",description:'the "pinned" column property',isUsed:t=>"left"===t||"right"===t||"start"===t||"end"===t}],queries:[{type:A,description:"Prevents pinned columns from being moved/reordered"},{type:"getStickyOffsets",description:"Returns the offsets for left/right pinned columns"},{type:"getContextMenuItems",description:"Contributes pin/unpin items to the header context menu"}]};name="pinnedColumns";get defaultConfig(){return{}}isApplied=!1;leftOffsets=/* @__PURE__ */new Map;rightOffsets=/* @__PURE__ */new Map;#s={addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set};#n=[];#i=[];#r=/* @__PURE__ */new WeakSet;detach(){this.leftOffsets.clear(),this.rightOffsets.clear(),this.isApplied=!1,this.#s={addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set},this.#n=[],this.#i=[],this.#r=/* @__PURE__ */new WeakSet}static detect(t,e){const s=e?.columns;return!!Array.isArray(s)&&y(s)}processColumns(t){const e=[...t];for(const s of e){const t=s.__element;if(!t||this.#r.has(t))continue;if(this.#r.add(t),null!=s.pinned)continue;const e=t.getAttribute("pinned");"left"!==e&&"right"!==e&&"start"!==e&&"end"!==e||(s.pinned=e)}if(this.isApplied=y(e),!this.isApplied)return e;const n=this.gridElement;return function(t,e="ltr"){const s=[],n=[],i=[];for(const r of t){const t=g(r);t?"left"===p(t,e)?s.push(r):i.push(r):n.push(r)}return[...s,...n,...i]}(e,n?s(n):"ltr")}afterRender(){if(!this.isApplied)return;const t=this.gridElement,e=[...this.columns];if(!y(e))return C(t),void(this.isApplied=!1);queueMicrotask(()=>{const s=b(t,e);this.#s=s.groupEndAdjustments,this.leftOffsets=s.leftOffsets,this.rightOffsets=s.rightOffsets,this.#n=s.splitGroups,this.#o()})}afterCellRender(s){if(!this.isApplied)return;const n=s.column.field,i=s.cellElement,r=this.leftOffsets.get(n);if(void 0!==r)i.classList.contains(t)||i.classList.add(t),i.style.position="sticky",i.style.left=r+"px";else{const t=this.rightOffsets.get(n);void 0!==t&&(i.classList.contains(e)||i.classList.add(e),i.style.position="sticky",i.style.right=t+"px")}this.#s.addGroupEnd.has(n)?s.cellElement.classList.add("group-end"):this.#s.removeGroupEnd.has(n)&&s.cellElement.classList.remove("group-end")}onScroll(t){this.#o()}#o(){if(!this.isApplied||0===this.#n.length)return;const t=this.gridElement;for(const e of this.#n){const s=e.pinnedFragment.getBoundingClientRect(),n=e.scrollableFragment.getBoundingClientRect().right<=s.right;if(n&&!e.isTransferred?(e.pinnedFragment.textContent=e.label,e.pinnedFragment.style.overflow="hidden",e.pinnedFragment.style.textOverflow="ellipsis",e.pinnedFragment.style.whiteSpace="nowrap",e.pinnedFragment.style.borderRightStyle="",e.floatLabel.style.visibility="hidden",e.floatLabel.style.transform="",e.floatOffset=0,this.#s.addGroupEnd.add(e.pinnedField),t.querySelectorAll(`.header-row .cell[data-field="${e.pinnedField}"], .data-grid-row .cell[data-field="${e.pinnedField}"]`).forEach(t=>t.classList.add("group-end")),e.isTransferred=!0):!n&&e.isTransferred&&(e.pinnedFragment.textContent="",e.pinnedFragment.style.overflow="",e.pinnedFragment.style.textOverflow="",e.pinnedFragment.style.whiteSpace="",e.pinnedFragment.style.borderRightStyle="none",e.floatLabel.style.visibility="",e.floatLabel.style.transform="",e.floatOffset=0,this.#s.addGroupEnd.delete(e.pinnedField),t.querySelectorAll(`.header-row .cell[data-field="${e.pinnedField}"], .data-grid-row .cell[data-field="${e.pinnedField}"]`).forEach(t=>t.classList.remove("group-end")),e.isTransferred=!1),!e.isTransferred){const t=e.floatLabel.getBoundingClientRect().left-e.floatOffset,n=s.left;t<n?(e.floatOffset=n-t,e.floatLabel.style.transform=`translateX(${e.floatOffset}px)`):(e.floatOffset=0,e.floatLabel.style.transform="")}}}handleQuery(t){switch(t.type){case A:return null==g(t.context)&&void 0;case"getStickyOffsets":return{left:Object.fromEntries(this.leftOffsets),right:Object.fromEntries(this.rightOffsets)};case"getContextMenuItems":{const e=t.context;if(!e.isHeader)return;const s=e.column;if(!s?.field)return;if(s.lockPinning||s.meta?.lockPinning)return;const n=[];return null!=g(s)?n.push({id:"pinned/unpin",label:"Unpin Column",icon:"📌",order:40,action:()=>this.setPinPosition(s.field,void 0)}):(n.push({id:"pinned/pin-left",label:"Pin Left",icon:"⬅",order:40,action:()=>this.setPinPosition(s.field,"left")}),n.push({id:"pinned/pin-right",label:"Pin Right",icon:"➡",order:41,action:()=>this.setPinPosition(s.field,"right")})),n}default:return}}setPinPosition(t,e){const s=this.columns;if(!s?.length)return;const n=s.findIndex(e=>e.field===t);if(-1===n)return;const i=this.gridElement;if(e)0===this.#i.length&&(this.#i=s.map(t=>t.field)),i.columns=s.map(s=>{if(s.field!==t)return s;const n={...s};return n.pinned=e,n});else{const e={...s[n]};delete e.pinned;const r=[...s];r.splice(n,1);const o=this.#i.indexOf(t);if(o>=0){let t=r.length;for(let e=0;e<r.length;e++)if(!g(r[e])&&this.#i.indexOf(r[e].field)>o){t=e;break}r.splice(t,0,e)}else r.splice(Math.min(n,r.length),0,e);r.some(t=>null!=g(t))||(this.#i=[]),i.columns=r}}refreshStickyOffsets(){const t=[...this.columns],e=b(this.gridElement,t);this.#s=e.groupEndAdjustments,this.leftOffsets=e.leftOffsets,this.rightOffsets=e.rightOffsets,this.#n=e.splitGroups}getLeftPinnedColumns(){return function(t,e="ltr"){return t.filter(t=>h(t,e))}([...this.columns],s(this.gridElement))}getRightPinnedColumns(){return function(t,e="ltr"){return t.filter(t=>m(t,e))}([...this.columns],s(this.gridElement))}clearStickyPositions(){C(this.gridElement)}getHorizontalScrollOffsets(s,n){if(!this.isApplied)return;let i=0,r=0;if(s){const n=s.querySelectorAll(`.${t}`),o=s.querySelectorAll(`.${e}`);n.forEach(t=>{i+=t.offsetWidth}),o.forEach(t=>{r+=t.offsetWidth})}else this.gridElement.querySelectorAll(".header-row .cell").forEach(s=>{s.classList.contains(t)?i+=s.offsetWidth:s.classList.contains(e)&&(r+=s.offsetWidth)});const o=n?.classList.contains(t)||n?.classList.contains(e);return{left:i,right:r,skipScroll:o}}};export{S as PinnedColumnsPlugin};
|
|
1
|
+
var t="sticky-left",e="sticky-right";function s(t){try{if("rtl"===getComputedStyle(t).direction)return"rtl"}catch{}try{if("rtl"===t.closest?.("[dir]")?.getAttribute("dir"))return"rtl"}catch{}return"ltr"}function n(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function i(t,e,s,i){return`${n(s,i)} ${t}: ${e}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}var r="__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(t=>t.split("").reverse().join("")),o=(new RegExp(`__(proto|defineGetter|defineSetter)|${r.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".split("|"))),l=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),a=/^\s*(javascript|vbscript|data|blob):/i;function c(t){if(!t||"string"!=typeof t)return"";if(-1===t.indexOf("<"))return t;const e=document.createElement("template");return e.innerHTML=t,function(t){const e=[],s=t.querySelectorAll("*");for(const n of s){const t=n.tagName.toLowerCase();if(o.has(t)){e.push(n);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===n.namespaceURI)&&Array.from(n.attributes).some(t=>l.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(n);continue}const s=[];for(const e of n.attributes){const t=e.name.toLowerCase();l.test(t)?s.push(e.name):(d.has(t)&&a.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&s.push(e.name)}s.forEach(t=>n.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content),e.innerHTML}var f={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var u=class{static dependencies;static manifest;aliases;version="3.1.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}get resolvedConfig(){return this.#t?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(t){if(0===t.length)return;const e={...this.userConfig},s={};for(const n of Object.keys(e))s[n]=this;for(const n of t){const t=n.userConfig;for(const[r,o]of Object.entries(t)){if(void 0===o)continue;if(!(r in e)){e[r]=o,s[r]=n;continue}if(e[r]===o)continue;const t=s[r]?.constructor.name??this.constructor.name,l=n.constructor.name,d=i("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${r}" supplied by both ${t} and ${l}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(d)}}Object.assign(this.userConfig,e)}refreshUserConfigFrom(t){const e=this.userConfig,s={...t.userConfig};for(const n of Object.keys(e))delete e[n];Object.assign(e,s)}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const s=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(s),s.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}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?._hostElement}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...f,...t}}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;return!e||"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),s=parseInt(e,10);if(!isNaN(s))return s}return 200}setIcon(t,e,s){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const n=this.#e(e,s);void 0!==n?"string"==typeof n?t.innerHTML=c(n):n instanceof HTMLElement&&(t.innerHTML="",t.appendChild(n.cloneNode(!0))):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const s=document.createElement("span");s.setAttribute("part","sort-indicator"),s.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(s,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(s,"sortNone"));const n=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return n?t.insertBefore(s,n):t.appendChild(s),s}warn(t,e){void 0!==e?console.warn(i(t,e,this.gridElement.id,this.name)):console.warn(`${n(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(t,e){throw new Error(i(t,e,this.gridElement.id,this.name))}};function g(t){return t.pinned??t.meta?.pinned}function p(t,e){return function(t,e){return"left"===t||"right"===t?t:"rtl"===e?"start"===t?"right":"left":"start"===t?"left":"right"}(t,e)}function h(t,e){const s=g(t);return!!s&&"left"===p(s,e)}function m(t,e){const s=g(t);return!!s&&"right"===p(s,e)}function y(t){for(let e=0;e<t.length;e++)if(null!=t[e].pinned||null!=t[e].meta?.pinned)return!0;return!1}function b(n,i){const r={groupEndAdjustments:{addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set},leftOffsets:/* @__PURE__ */new Map,rightOffsets:/* @__PURE__ */new Map,splitGroups:[]},o=Array.from(n.querySelectorAll(".header-row .cell"));if(!o.length)return r;const l=s(n),d=/* @__PURE__ */new Map,a=/* @__PURE__ */new Map;let c=0;for(const e of i)if(h(e,l)){const s=o.find(t=>t.getAttribute("data-field")===e.field);s&&(d.set(e.field,c),s.classList.add(t),s.style.position="sticky",s.style.left=c+"px",n.querySelectorAll(`.data-grid-row .cell[data-field="${e.field}"]`).forEach(e=>{e.classList.add(t),e.style.position="sticky",e.style.left=c+"px"}),c+=s.offsetWidth)}let f=0;for(const t of[...i].reverse())if(m(t,l)){const s=o.find(e=>e.getAttribute("data-field")===t.field);s&&(a.set(t.field,f),s.classList.add(e),s.style.position="sticky",s.style.right=f+"px",n.querySelectorAll(`.data-grid-row .cell[data-field="${t.field}"]`).forEach(t=>{t.classList.add(e),t.style.position="sticky",t.style.right=f+"px"}),f+=s.offsetWidth)}const u=[],g=function(s,n,i,r,o){const l={addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set},d=Array.from(s.querySelectorAll(".header-group-row .header-group-cell"));if(!d.length)return l;for(const a of d){const s=a.style.gridColumn;if(!s)continue;const d=s.match(/^(\d+)\s*\/\s*span\s+(\d+)$/);if(!d)continue;const c=parseInt(d[1],10)-1,f=c+parseInt(d[2],10)-1,u=n.slice(c,f+1);if(!u.length)continue;const g=u.every(t=>h(t,r)),p=u.every(t=>m(t,r));if(g){const e=u[0].field,s=i.find(t=>t.getAttribute("data-field")===e);s&&(a.classList.add(t),a.style.position="sticky",a.style.left=s.style.left)}else if(p){const t=u[u.length-1].field,s=i.find(e=>e.getAttribute("data-field")===t);s&&(a.classList.add(e),a.style.position="sticky",a.style.right=s.style.right)}else if(a.classList.contains("implicit-group"))E(a,u,c,i,r,l);else{const t=u.some(t=>h(t,r)),e=u.some(t=>m(t,r));(t||e)&&w(a,u,c,i,r,l,o)}}return l}(n,i,o,l,u);if(g.addGroupEnd.size>0||g.removeGroupEnd.size>0){for(const t of g.addGroupEnd){const e=o.find(e=>e.getAttribute("data-field")===t);e&&e.classList.add("group-end"),n.querySelectorAll(`.data-grid-row .cell[data-field="${t}"]`).forEach(t=>{t.classList.add("group-end")})}for(const t of g.removeGroupEnd){const e=o.find(e=>e.getAttribute("data-field")===t);e&&e.classList.remove("group-end"),n.querySelectorAll(`.data-grid-row .cell[data-field="${t}"]`).forEach(t=>{t.classList.remove("group-end")})}}return{groupEndAdjustments:g,leftOffsets:d,rightOffsets:a,splitGroups:u}}function v(t,e){return h(t,e)?"left":m(t,e)?"right":"none"}function E(s,n,i,r,o,l){const d=[];for(let t=0;t<n.length;t++){const e=v(n[t],o),s=d[d.length-1];s&&s.state===e?s.cols.push(n[t]):d.push({state:e,cols:[n[t]],colStart:i+t})}if(d.length<=1)return;const a=s.parentElement;if(!a)return;const c=s.nextSibling;a.removeChild(s);for(const f of d){const n=document.createElement("div");if(n.className=s.className,n.setAttribute("data-group",s.getAttribute("data-group")||""),n.style.gridColumn=`${f.colStart+1} / span ${f.cols.length}`,"left"===f.state){const e=f.cols[0].field,s=r.find(t=>t.getAttribute("data-field")===e);s&&(n.classList.add(t),n.style.position="sticky",n.style.left=s.style.left)}else if("right"===f.state){const t=f.cols[f.cols.length-1].field,s=r.find(e=>e.getAttribute("data-field")===t);s&&(n.classList.add(e),n.style.position="sticky",n.style.right=s.style.right)}else"none"===f.state&&f.cols.every(t=>String(t.field||"").startsWith("__tbw_"))&&(n.style.borderRightStyle="none");c?a.insertBefore(n,c):a.appendChild(n)}for(let t=0;t<d.length;t++){const e=d[t],s=d[t+1];if("none"!==e.state&&s&&"none"===s.state){const t=e.cols[e.cols.length-1].field;t&&l.addGroupEnd.add(t)}if("none"===e.state&&e.cols.every(t=>String(t.field||"").startsWith("__tbw_"))){const t=e.cols[e.cols.length-1].field;t&&l.removeGroupEnd.add(t)}}}function w(s,n,i,r,o,l,d){const a=[];for(let t=0;t<n.length;t++){const e=v(n[t],o),s=a[a.length-1];s&&s.state===e?s.cols.push(n[t]):a.push({state:e,cols:[n[t]],colStart:i+t})}if(a.length<=1)return;const c=s.parentElement;if(!c)return;const f=s.textContent||"",u=s.getAttribute("data-group")||"",g=s.nextSibling;c.removeChild(s);const p=a.findIndex(t=>"left"===t.state);let h=-1;for(let t=a.length-1;t>=0;t--)if("right"===a[t].state){h=t;break}const m=p>=0?p:h,y=p>=0&&p+1<a.length?p+1:h>=0&&h-1>=0?h-1:-1;let b,E,w,C="";for(let v=0;v<a.length;v++){const n=a[v],i=document.createElement("div");if(i.className=s.className,i.setAttribute("data-group",u),i.style.gridColumn=`${n.colStart+1} / span ${n.cols.length}`,"left"===n.state){const e=n.cols[0].field,s=r.find(t=>t.getAttribute("data-field")===e);s&&(i.classList.add(t),i.style.position="sticky",i.style.left=s.style.left),v===m&&(i.style.borderRightStyle="none",b=i,C=n.cols[n.cols.length-1].field)}else if("right"===n.state){const t=n.cols[n.cols.length-1].field,s=r.find(e=>e.getAttribute("data-field")===t);s&&(i.classList.add(e),i.style.position="sticky",i.style.right=s.style.right),v===m&&(i.style.borderLeftStyle="none",b=i,C=n.cols[0].field)}if(v===y){i.style.overflow="visible";const t=document.createElement("span");t.textContent=f,t.style.position="relative",t.style.zIndex="36",t.style.display="block",t.style.overflow="hidden",t.style.textOverflow="ellipsis",t.style.whiteSpace="nowrap",i.appendChild(t),E=i,w=t}g?c.insertBefore(i,g):c.appendChild(i)}b&&E&&w&&C&&d.push({groupId:u,label:f,pinnedFragment:b,scrollableFragment:E,floatLabel:w,pinnedField:C,isTransferred:!1,floatOffset:0})}function C(s){s.querySelectorAll(`.${t}, .${e}`).forEach(s=>{s.classList.remove(t,e),s.style.position="",s.style.left="",s.style.right=""})}var A="canMoveColumn",S=class extends u{static manifest={hookPriority:{processColumns:-10},ownedProperties:[{property:"pinned",level:"column",description:'the "pinned" column property',isUsed:t=>"left"===t||"right"===t||"start"===t||"end"===t}],queries:[{type:A,description:"Prevents pinned columns from being moved/reordered"},{type:"getStickyOffsets",description:"Returns the offsets for left/right pinned columns"},{type:"getContextMenuItems",description:"Contributes pin/unpin items to the header context menu"}]};name="pinnedColumns";get defaultConfig(){return{}}isApplied=!1;leftOffsets=/* @__PURE__ */new Map;rightOffsets=/* @__PURE__ */new Map;#s={addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set};#n=[];#i=[];#r=/* @__PURE__ */new WeakSet;detach(){this.leftOffsets.clear(),this.rightOffsets.clear(),this.isApplied=!1,this.#s={addGroupEnd:/* @__PURE__ */new Set,removeGroupEnd:/* @__PURE__ */new Set},this.#n=[],this.#i=[],this.#r=/* @__PURE__ */new WeakSet}static detect(t,e){const s=e?.columns;return!!Array.isArray(s)&&y(s)}processColumns(t){const e=[...t];for(const s of e){const t=s.__element;if(!t||this.#r.has(t))continue;if(this.#r.add(t),null!=s.pinned)continue;const e=t.getAttribute("pinned");"left"!==e&&"right"!==e&&"start"!==e&&"end"!==e||(s.pinned=e)}if(this.isApplied=y(e),!this.isApplied)return e;const n=this.gridElement;return function(t,e="ltr"){const s=[],n=[],i=[];for(const r of t){const t=g(r);t?"left"===p(t,e)?s.push(r):i.push(r):n.push(r)}return[...s,...n,...i]}(e,n?s(n):"ltr")}afterRender(){if(!this.isApplied)return;const t=this.gridElement,e=[...this.columns];if(!y(e))return C(t),void(this.isApplied=!1);queueMicrotask(()=>{const s=b(t,e);this.#s=s.groupEndAdjustments,this.leftOffsets=s.leftOffsets,this.rightOffsets=s.rightOffsets,this.#n=s.splitGroups,this.#o()})}afterCellRender(s){if(!this.isApplied)return;const n=s.column.field,i=s.cellElement,r=this.leftOffsets.get(n);if(void 0!==r)i.classList.contains(t)||i.classList.add(t),i.style.position="sticky",i.style.left=r+"px";else{const t=this.rightOffsets.get(n);void 0!==t&&(i.classList.contains(e)||i.classList.add(e),i.style.position="sticky",i.style.right=t+"px")}this.#s.addGroupEnd.has(n)?s.cellElement.classList.add("group-end"):this.#s.removeGroupEnd.has(n)&&s.cellElement.classList.remove("group-end")}onScroll(t){this.#o()}#o(){if(!this.isApplied||0===this.#n.length)return;const t=this.gridElement;for(const e of this.#n){const s=e.pinnedFragment.getBoundingClientRect(),n=e.scrollableFragment.getBoundingClientRect().right<=s.right;if(n&&!e.isTransferred?(e.pinnedFragment.textContent=e.label,e.pinnedFragment.style.overflow="hidden",e.pinnedFragment.style.textOverflow="ellipsis",e.pinnedFragment.style.whiteSpace="nowrap",e.pinnedFragment.style.borderRightStyle="",e.floatLabel.style.visibility="hidden",e.floatLabel.style.transform="",e.floatOffset=0,this.#s.addGroupEnd.add(e.pinnedField),t.querySelectorAll(`.header-row .cell[data-field="${e.pinnedField}"], .data-grid-row .cell[data-field="${e.pinnedField}"]`).forEach(t=>t.classList.add("group-end")),e.isTransferred=!0):!n&&e.isTransferred&&(e.pinnedFragment.textContent="",e.pinnedFragment.style.overflow="",e.pinnedFragment.style.textOverflow="",e.pinnedFragment.style.whiteSpace="",e.pinnedFragment.style.borderRightStyle="none",e.floatLabel.style.visibility="",e.floatLabel.style.transform="",e.floatOffset=0,this.#s.addGroupEnd.delete(e.pinnedField),t.querySelectorAll(`.header-row .cell[data-field="${e.pinnedField}"], .data-grid-row .cell[data-field="${e.pinnedField}"]`).forEach(t=>t.classList.remove("group-end")),e.isTransferred=!1),!e.isTransferred){const t=e.floatLabel.getBoundingClientRect().left-e.floatOffset,n=s.left;t<n?(e.floatOffset=n-t,e.floatLabel.style.transform=`translateX(${e.floatOffset}px)`):(e.floatOffset=0,e.floatLabel.style.transform="")}}}handleQuery(t){switch(t.type){case A:return null==g(t.context)&&void 0;case"getStickyOffsets":return{left:Object.fromEntries(this.leftOffsets),right:Object.fromEntries(this.rightOffsets)};case"getContextMenuItems":{const e=t.context;if(!e.isHeader)return;const s=e.column;if(!s?.field)return;if(s.lockPinning||s.meta?.lockPinning)return;const n=[];return null!=g(s)?n.push({id:"pinned/unpin",label:"Unpin Column",icon:"📌",order:40,action:()=>this.setPinPosition(s.field,void 0)}):(n.push({id:"pinned/pin-left",label:"Pin Left",icon:"⬅",order:40,action:()=>this.setPinPosition(s.field,"left")}),n.push({id:"pinned/pin-right",label:"Pin Right",icon:"➡",order:41,action:()=>this.setPinPosition(s.field,"right")})),n}default:return}}setPinPosition(t,e){const s=this.columns;if(!s?.length)return;const n=s.findIndex(e=>e.field===t);if(-1===n)return;const i=this.gridElement;if(e)0===this.#i.length&&(this.#i=s.map(t=>t.field)),i.columns=s.map(s=>{if(s.field!==t)return s;const n={...s};return n.pinned=e,n});else{const e={...s[n]};delete e.pinned;const r=[...s];r.splice(n,1);const o=this.#i.indexOf(t);if(o>=0){let t=r.length;for(let e=0;e<r.length;e++)if(!g(r[e])&&this.#i.indexOf(r[e].field)>o){t=e;break}r.splice(t,0,e)}else r.splice(Math.min(n,r.length),0,e);r.some(t=>null!=g(t))||(this.#i=[]),i.columns=r}}refreshStickyOffsets(){const t=[...this.columns],e=b(this.gridElement,t);this.#s=e.groupEndAdjustments,this.leftOffsets=e.leftOffsets,this.rightOffsets=e.rightOffsets,this.#n=e.splitGroups}getLeftPinnedColumns(){return function(t,e="ltr"){return t.filter(t=>h(t,e))}([...this.columns],s(this.gridElement))}getRightPinnedColumns(){return function(t,e="ltr"){return t.filter(t=>m(t,e))}([...this.columns],s(this.gridElement))}clearStickyPositions(){C(this.gridElement)}getHorizontalScrollOffsets(s,n){if(!this.isApplied)return;let i=0,r=0;if(s){const n=s.querySelectorAll(`.${t}`),o=s.querySelectorAll(`.${e}`);n.forEach(t=>{i+=t.offsetWidth}),o.forEach(t=>{r+=t.offsetWidth})}else this.gridElement.querySelectorAll(".header-row .cell").forEach(s=>{s.classList.contains(t)?i+=s.offsetWidth:s.classList.contains(e)&&(r+=s.offsetWidth)});const o=n?.classList.contains(t)||n?.classList.contains(e);return{left:i,right:r,skipScroll:o}}};export{S as PinnedColumnsPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|