@toolbox-web/grid 2.17.1 → 2.17.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/all.js +1 -1
- package/all.js.map +1 -1
- package/index.js +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/export/index.js +1 -1
- package/lib/plugins/filtering/index.js +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/reorder-columns/index.js +1 -1
- package/lib/plugins/reorder-rows/index.js +1 -1
- package/lib/plugins/responsive/index.js +1 -1
- package/lib/plugins/row-drag-drop/index.js +1 -1
- package/lib/plugins/selection/index.js +1 -1
- package/lib/plugins/server-side/index.js +1 -1
- package/lib/plugins/shell/index.js +1 -1
- package/lib/plugins/sticky-rows/StickyRowsPlugin.d.ts +23 -0
- package/lib/plugins/sticky-rows/index.js +1 -1
- package/lib/plugins/sticky-rows/index.js.map +1 -1
- package/lib/plugins/tooltip/index.js +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/plugins/sticky-rows.umd.js +1 -1
- package/umd/plugins/sticky-rows.umd.js.map +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e="(Blank)";function t(e){if("number"==typeof e)return e;if(e instanceof Date)return e.getTime();const t=Number(e);if(!isNaN(t))return t;return new Date(e).getTime()}function r(r,n,i=!1,l){if(!n.length)return r;const a=n.map(r=>function(r,n,i){const l=r.field,a=r.operator,s=i?e=>i(e[l],e):e=>e[l];if("blank"===a)return e=>{const t=s(e);return null==t||""===t||"number"==typeof t&&isNaN(t)};if("notBlank"===a)return e=>{const t=s(e);return null!=t&&""!==t&&!("number"==typeof t&&isNaN(t))};if(i&&("notIn"===a||"in"===a)){const t=r.value;if("notIn"===a){if(!Array.isArray(t))return()=>!0;const r=new Set(t);return t=>{const n=i(t[l],t),a=Array.isArray(n)?n:null!=n?[n]:[];return 0===a.length?!r.has(e):!a.some(e=>r.has(e))}}if(!Array.isArray(t))return()=>!1;const n=new Set(t);return t=>{const r=i(t[l],t),a=Array.isArray(r)?r:null!=r?[r]:[];return 0===a.length?n.has(e):a.some(e=>n.has(e))}}if("notIn"===a){if(!Array.isArray(r.value))return()=>!0;const t=new Set(r.value);return r=>{const n=r[l];return null==n||""===n?!t.has(e):!t.has(n)}}if("in"===a){if(!Array.isArray(r.value))return()=>!1;const t=new Set(r.value);return r=>{const n=r[l];return null==n||""===n?t.has(e):t.has(n)}}const o="number"===r.type&&!i,c=e=>null==e||""===e||"number"==typeof e&&isNaN(e);if("greaterThan"===a){const e=t(r.value);return o?t=>{const r=t[l];return!c(r)&&r>e}:r=>{const n=s(r);if(c(n))return!1;const i=t(n);return!isNaN(i)&&i>e}}if("greaterThanOrEqual"===a){const e=t(r.value);return o?t=>{const r=t[l];return!c(r)&&r>=e}:r=>{const n=s(r);if(c(n))return!1;const i=t(n);return!isNaN(i)&&i>=e}}if("lessThan"===a){const e=t(r.value);return o?t=>{const r=t[l];return!c(r)&&r<e}:r=>{const n=s(r);if(c(n))return!1;const i=t(n);return!isNaN(i)&&i<e}}if("lessThanOrEqual"===a){const e=t(r.value);return o?t=>{const r=t[l];return!c(r)&&r<=e}:r=>{const n=s(r);if(c(n))return!1;const i=t(n);return!isNaN(i)&&i<=e}}if("between"===a){const e=t(r.value),n=t(r.valueTo);return o?t=>{const r=t[l];return!c(r)&&(r>=e&&r<=n)}:r=>{const i=s(r);if(c(i))return!1;const l=t(i);return!isNaN(l)&&l>=e&&l<=n}}const d=n?String(r.value):String(r.value).toLowerCase();return"contains"===a?n?e=>{const t=s(e);return null!=t&&String(t).includes(d)}:e=>{const t=s(e);return null!=t&&String(t).toLowerCase().includes(d)}:"notContains"===a?n?e=>{const t=s(e);return null!=t&&!String(t).includes(d)}:e=>{const t=s(e);return null!=t&&!String(t).toLowerCase().includes(d)}:"equals"===a?n?e=>{const t=s(e);return null!=t&&String(t)===d}:e=>{const t=s(e);return null!=t&&String(t).toLowerCase()===d}:"notEquals"===a?n?e=>{const t=s(e);return null!=t&&String(t)!==d}:e=>{const t=s(e);return null!=t&&String(t).toLowerCase()!==d}:"startsWith"===a?n?e=>{const t=s(e);return null!=t&&String(t).startsWith(d)}:e=>{const t=s(e);return null!=t&&String(t).toLowerCase().startsWith(d)}:"endsWith"===a?n?e=>{const t=s(e);return null!=t&&String(t).endsWith(d)}:e=>{const t=s(e);return null!=t&&String(t).toLowerCase().endsWith(d)}:()=>!0}(r,i,l?.get(r.field)));return 1===a.length?r.filter(a[0]):r.filter(e=>{for(let t=0;t<a.length;t++)if(!a[t](e))return!1;return!0})}function n(t,r,n){const i=/* @__PURE__ */new Set;let l=!1;for(const e of t){const t=e[r];if(n){const r=n(t,e);if(Array.isArray(r)){0===r.length&&(l=!0);for(const e of r)null!=e&&i.add(e)}else null!=r?i.add(r):l=!0}else null!=t&&""!==t?i.add(t):l=!0}return l&&i.add(e),[...i].sort((e,t)=>"number"==typeof e&&"number"==typeof t?e-t:String(e).localeCompare(String(t)))}const i={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`},l={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function a(e,t){if(!e)return;const r="effectiveConfig"in e?e.effectiveConfig:void 0;if(!1===r?.a11y?.announcements)return;const n=e.querySelector?.(".tbw-sr-only");n&&(n.textContent="",requestAnimationFrame(()=>{n.textContent=t}))}function s(e,t,...r){const n=e&&"effectiveConfig"in e?e.effectiveConfig:void 0,l=n?.a11y?.messages?.[t];return l?l(...r):i[t](...r)}const o=/* @__PURE__ */new WeakMap;function c(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function d(e,t,r,n){return`${c(r,n)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}const u="__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(""));new RegExp(`__(proto|defineGetter|defineSetter)|${u.slice(3).join("|")}|this\\b`);const p=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("|")),f=/^on\w+$/i,h=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),b=/^\s*(javascript|vbscript|data|blob):/i;function g(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 n of r){const e=n.tagName.toLowerCase();if(p.has(e)){t.push(n);continue}if("svg"===e||"http://www.w3.org/2000/svg"===n.namespaceURI){if(Array.from(n.attributes).some(e=>f.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(n);continue}}const r=[];for(const t of n.attributes){const e=t.name.toLowerCase();f.test(e)?r.push(t.name):(h.has(e)&&b.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name)}r.forEach(e=>n.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}class m{static dependencies;static manifest;aliases;version="2.17.1";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 n of Object.keys(t))r[n]=this;for(const n of e){const e=n.userConfig;for(const[i,l]of Object.entries(e)){if(void 0===l)continue;if(!(i in t)){t[i]=l,r[i]=n;continue}if(t[i]===l)continue;const e=r[i]?.constructor.name??this.constructor.name,a=n.constructor.name,s=d("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${i}" supplied by both ${e} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(s)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig;for(const r of Object.keys(t))delete t[r];Object.assign(t,e.userConfig)}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{...l,...e}}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),r=parseInt(t,10);if(!isNaN(r))return r}return 200}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 n=this.#t(t,r);void 0!==n?"string"==typeof n?e.innerHTML=g(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 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 n=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return n?e.insertBefore(r,n):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(d(e,t,this.gridElement.id,this.name)):console.warn(`${c(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(d(e,t,this.gridElement.id,this.name))}}function v(e){return e?e.toISOString().split("T")[0]:""}function w(e){return e?"string"==typeof e?e:"number"==typeof e?v(new Date(e)):"":""}const y=335e5;function x(e){const{totalRows:t,viewportHeight:r,scrollTop:n,rowHeight:i,overscan:l,maxSpacerHeight:a=y}=e,s=Math.ceil(r/i),o=t*i,c=function(e,t,r=y){return{rawContentHeight:e,spacerHeight:Math.min(e,r),viewportHeight:t,capped:e>r}}(o,r,a),d=function(e,t){if(!t.capped)return e;const r=t.spacerHeight-t.viewportHeight,n=t.rawContentHeight-t.viewportHeight;if(r<=0||n<=0)return e;const i=e*n/r;return i<0?0:i>n?n:i}(n,c);let u=Math.floor(d/i)-l;u<0&&(u=0);let p=u+s+2*l;return p>t&&(p=t),p===t&&u>0&&(u=Math.max(0,p-s-2*l)),{start:u,end:p,offsetY:u*i,totalHeight:c.spacerHeight,rawContentHeight:o}}function C(e,t,r,n,i,l){const{field:a,column:s}=t,o=function(e){if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-filter-item-height");if(t&&t.trim()){const e=parseFloat(t);if(!isNaN(e)&&e>0)return e}}return 28}(e),c=e=>{if(null==e)return"(Blank)";if(s.format&&!s.filterValue){const t=s.format(e,void 0);if(t)return t}return String(e)};r=r.slice().sort((e,t)=>"number"==typeof e&&"number"==typeof t?e-t:c(e).localeCompare(c(t)));const d=document.createElement("div");d.className="tbw-filter-search";const u=document.createElement("input");u.type="text",u.placeholder="Search...",u.className="tbw-filter-search-input",u.value=l.get(a)??"",d.appendChild(u),e.appendChild(d);const p=document.createElement("div");p.className="tbw-filter-actions";const f=document.createElement("label");f.className="tbw-filter-value-item",f.style.padding="0",f.style.margin="0";const h=document.createElement("input");h.type="checkbox",h.className="tbw-filter-checkbox";const b=document.createElement("span");b.textContent="Select All",f.appendChild(h),f.appendChild(b),p.appendChild(f);const g=/* @__PURE__ */new Map;r.forEach(e=>{const t=null==e?"__null__":String(e);g.set(t,!n.has(e))});const m=()=>{const e=[...g.values()],t=e.every(e=>e),r=e.every(e=>!e);h.checked=t,h.indeterminate=!t&&!r};h.addEventListener("change",()=>{const e=h.checked;for(const t of g.keys())g.set(t,e);m(),k()}),m(),e.appendChild(p);const v=document.createElement("div");v.className="tbw-filter-values";const w=document.createElement("div");w.className="tbw-filter-values-spacer",v.appendChild(w);const y=document.createElement("div");y.className="tbw-filter-values-content",v.appendChild(y);let C=[];const E=(e,t)=>{const r=c(e),n=null==e?"__null__":String(e),i=document.createElement("label");i.className="tbw-filter-value-item",i.style.position="absolute",i.style.top=`calc(var(--tbw-filter-item-height, 28px) * ${t})`,i.style.left="0",i.style.right="0",i.style.boxSizing="border-box";const l=document.createElement("input");l.type="checkbox",l.className="tbw-filter-checkbox",l.checked=g.get(n)??!0,l.dataset.value=n,l.addEventListener("change",()=>{g.set(n,l.checked),m()});const a=document.createElement("span");return a.textContent=r,i.appendChild(l),i.appendChild(a),i},k=()=>{const e=C.length,t=v.clientHeight,r=v.scrollTop;if(w.style.height=e*o+"px",e<=50/3)return y.innerHTML="",y.style.transform="translateY(0px)",void C.forEach((e,t)=>{y.appendChild(E(e,t))});const n=x({totalRows:e,viewportHeight:t,scrollTop:r,rowHeight:o,overscan:3});y.style.transform=`translateY(${n.offsetY}px)`,y.innerHTML="";for(let i=n.start;i<n.end;i++)y.appendChild(E(C[i],i-n.start))},F=e=>{const t=i.caseSensitive??!1,n=t?e:e.toLowerCase();if(C=r.filter(r=>{const i=c(r),l=t?i:i.toLowerCase();return!e||l.includes(n)}),C.sort((e,t)=>{const r=null==e?"__null__":String(e),n=null==t?"__null__":String(t),i=g.get(r)??!0;return i!==(g.get(n)??!0)?i?-1:1:"number"==typeof e&&"number"==typeof t?e-t:c(e).localeCompare(c(t))}),0===C.length){w.style.height="0px",y.innerHTML="";const e=document.createElement("div");return e.className="tbw-filter-no-match",e.textContent="No matching values",void y.appendChild(e)}k()};let S;v.addEventListener("scroll",()=>{C.length>0&&k()},{passive:!0}),F(u.value),e.appendChild(v),u.addEventListener("input",()=>{clearTimeout(S),S=setTimeout(()=>{l.set(a,u.value),F(u.value)},i.debounceMs??150)});const A=document.createElement("div");A.className="tbw-filter-buttons";const N=document.createElement("button");N.type="button",N.className="tbw-filter-apply-btn",N.textContent="Apply",N.addEventListener("click",()=>{const e=[];for(const[t,n]of g)if(!n)if("__null__"===t)e.push(null);else{const n=r.find(e=>String(e)===t);e.push(void 0!==n?n:t)}t.applySetFilter(e)}),A.appendChild(N);const T=document.createElement("button");T.type="button",T.className="tbw-filter-clear-btn",T.textContent="Clear Filter",T.addEventListener("click",()=>{t.clearFilter()}),A.appendChild(T),e.appendChild(A)}function E(e,t){if("number"==typeof e)return e;if("string"==typeof e){const r=parseFloat(e);return isNaN(r)?t:r}return t}class k extends m{static manifest={events:[{type:"filter-change",description:"Emitted when filter criteria change. Broadcast to both DOM consumers and plugin bus."}],queries:[{type:"getContextMenuItems",description:"Contributes filter-related items to the header context menu"}]};name="filtering";styles='@layer tbw-plugins{tbw-grid .tbw-quick-filter-input{flex:1;max-width:300px;height:var(--tbw-input-height, 1.75rem);padding:var(--tbw-input-padding, 0 .5rem);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);color:var(--tbw-color-fg);font-size:var(--tbw-font-size-sm, .8125rem)}tbw-grid .tbw-quick-filter-input:focus{outline:none;border-color:var(--tbw-color-accent)}tbw-grid .header-cell.filtered:before{content:"";position:absolute;top:var(--tbw-spacing-xs, .25rem);right:var(--tbw-spacing-xs, .25rem);width:var(--tbw-indicator-size, .375rem);height:var(--tbw-indicator-size, .375rem);background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border-radius:50%}tbw-grid .tbw-filter-btn{display:var(--tbw-filter-btn-display, inline-flex);visibility:var(--tbw-filter-btn-visibility, visible);align-items:center;justify-content:center;background:transparent;border:none;cursor:pointer;padding:2px;margin-left:var(--tbw-spacing-xs, .25rem);opacity:.4;transition:opacity .15s,visibility 0s,display 0s allow-discrete;color:inherit;vertical-align:middle;transition-behavior:allow-discrete}tbw-grid .tbw-filter-btn:hover,tbw-grid .tbw-filter-btn.active{opacity:1;visibility:visible;display:inline-flex}tbw-grid .tbw-filter-btn.active{color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}tbw-grid .header-row .cell:hover .tbw-filter-btn,tbw-grid .header-row .cell.filtered .tbw-filter-btn{display:inline-flex;visibility:visible}}';get defaultConfig(){return{debounceMs:300,caseSensitive:!1}}isFilteringEnabled(){return!1!==this.grid.effectiveConfig?.filterable}isColumnFilterable(e){return!!this.isFilteringEnabled()&&!1!==e.filterable}getDataRows(){const e=this.sourceRows;if(e.length>0)return e;const t=this.rows;return 0===t.length?t:t.filter(e=>null!=e&&!0!==e.__loading)}getFilterValues(){const e=this.grid.effectiveConfig?.columns;if(!e)return;let t;for(const r of e){if(!r.field)continue;const e=this.getFilterExtractor(r);e&&(t||(t=/* @__PURE__ */new Map),t.set(r.field,e))}return t}getFilterExtractor(e){return e.filterValue?e.filterValue:e.valueAccessor?(t,r)=>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 n=e,i=t.field;let l=o.get(n);if(l){const e=l.get(i);if(void 0!==e)return e.v}else l=/* @__PURE__ */new Map,o.set(n,l);const a=t.valueAccessor({row:e,column:t,rowIndex:r});return l.set(i,{v:a}),a}(r,e):void 0}filters=/* @__PURE__ */new Map;cachedResult=null;cacheKey=null;cachedInputRows=null;openPanelField=null;panelElement=null;panelAnchorElement=null;panelButtonElement=null;searchText=/* @__PURE__ */new Map;excludedValues=/* @__PURE__ */new Map;panelAbortController=null;globalStylesInjected=!1;columnLookup=null;columnLookupRef=null;getColumnByField(e){const t=this.grid.effectiveConfig?.columns;if(!t)return;let r=this.columnLookup;if(t!==this.columnLookupRef||!r){r=/* @__PURE__ */new Map;for(const e of t)e.field&&r.set(e.field,e);this.columnLookup=r,this.columnLookupRef=t}return r.get(e)}computeSelected(){const t={},r=[];for(const[e,n]of this.filters)if("set"===n.type)if("in"===n.operator&&Array.isArray(n.value))t[e]=n.value;else if("notIn"===n.operator){const t=this.getColumnByField(e);r.push({field:e,filterValue:t?this.getFilterExtractor(t):void 0})}if(r.length>0){const n=function(t,r){const n=/* @__PURE__ */new Map;for(const{field:e,filterValue:l}of r)n.set(e,{values:/* @__PURE__ */new Set,hasBlank:!1,hasExtractor:!!l});for(const e of t)for(const{field:t,filterValue:i}of r){const r=n.get(t),l=e[t];if(i){const t=i(l,e);if(Array.isArray(t)){0===t.length&&(r.hasBlank=!0);for(const e of t)null!=e&&r.values.add(e)}else null!=t?r.values.add(t):r.hasBlank=!0}else null!=l&&""!==l?r.values.add(l):r.hasBlank=!0}const i=/* @__PURE__ */new Map;for(const[l,{values:a,hasBlank:s}]of n)s&&a.add(e),i.set(l,[...a].sort((e,t)=>"number"==typeof e&&"number"==typeof t?e-t:String(e).localeCompare(String(t))));return i}(this.getDataRows(),r);for(const{field:e}of r){const r=this.excludedValues.get(e),i=n.get(e)??[];t[e]=r?i.filter(e=>!r.has(e)):i}}return t}invalidateCache(){this.cachedResult=null,this.cacheKey=null,this.cachedInputRows=null}notifyFilterChange(e,t,r){r?this.emitPluginEvent("filter-change",{filters:e}):(this.broadcast("filter-change",{filters:e,filteredRowCount:t,selected:this.computeSelected()}),this.config.trackColumnState&&this.grid.requestStateChange?.())}syncExcludedValues(t,r){if(r)if("set"===r.type&&"notIn"===r.operator&&Array.isArray(r.value))this.excludedValues.set(t,new Set(r.value));else if("set"===r.type&&"in"===r.operator&&Array.isArray(r.value)){const n=this.getDataRows();if(!n||0===n.length)return void this.excludedValues.delete(t);const i=r.value,l=new Set(i.map(t=>null==t?e:t)),a=this.getUniqueValues(t),s=new Set(a.filter(e=>!l.has(e)));this.excludedValues.set(t,s)}else"set"===r.type&&this.excludedValues.delete(t);else this.excludedValues.delete(t)}attach(e){super.attach(e),this.injectGlobalStyles()}detach(){this.filters.clear(),this.invalidateCache(),this.columnLookup=null,this.columnLookupRef=null,this.openPanelField=null,this.panelElement&&(this.panelElement.remove(),this.panelElement=null),this.searchText.clear(),this.excludedValues.clear(),this.panelAbortController?.abort(),this.panelAbortController=null}handleQuery(e){if("filter:get-model"===e.type){if(!this.filters.size)return;return Object.fromEntries(this.filters)}if("getContextMenuItems"===e.type){const t=e.context;if(!t.isHeader)return;const r=t.column;if(!r?.field)return;if(!this.isFilteringEnabled())return;if(!this.isColumnFilterable(r))return;const n=[],i=this.isFieldFiltered(r.field),l=this.filters.size>0;return i&&n.push({id:"filtering/clear-column-filter",label:"Clear Filter",icon:"✕",order:20,action:()=>this.clearFieldFilter(r.field)}),l&&n.push({id:"filtering/clear-all-filters",label:"Clear All Filters",icon:"✕",order:21,disabled:!l,action:()=>this.clearAllFilters()}),n.length>0?n:void 0}}processRows(e){if(!this.filters.size)return e;const t=[...this.filters.values()];if(this.config.filterHandler)return this.cachedResult?this.cachedResult:e;const n=(i=t,JSON.stringify(i.map(e=>({field:e.field,operator:e.operator,value:e.value,valueTo:e.valueTo}))));var i;const l=e===this.cachedInputRows;if(this.cacheKey===n&&this.cachedResult&&l)return this.cachedResult;if(!l)for(const[r,s]of this.filters)"set"===s.type&&"in"===s.operator&&this.syncExcludedValues(r,s);const a=r(e,t,this.config.caseSensitive,this.getFilterValues());return this.cachedResult=a,this.cacheKey=n,this.cachedInputRows=e,a}afterRender(){const e=this.gridElement;if(!e)return;e.querySelectorAll('[part~="header-cell"]').forEach(e=>{const t=e.getAttribute("data-col");if(null===t)return;const r=this.visibleColumns[parseInt(t,10)];if(!r||!this.isColumnFilterable(r))return;if(!0===r.utility)return;const n=r.field;if(!n)return;const i=this.filters.has(n);let l=e.querySelector(".tbw-filter-btn");if(l){const t=l.classList.contains("active");return l.classList.toggle("active",i),e.classList.toggle("filtered",i),i?e.setAttribute("aria-description","Filtered"):e.removeAttribute("aria-description"),void(t!==i&&this.setIcon(l,i?"filterActive":"filter"))}l=document.createElement("button"),l.type="button",l.className="tbw-filter-btn",l.setAttribute("aria-label",`Filter ${r.header??n}`),this.setIcon(l,i?"filterActive":"filter"),i&&(l.classList.add("active"),e.classList.add("filtered"),e.setAttribute("aria-description","Filtered")),l.addEventListener("click",e=>{e.stopPropagation(),this.toggleFilterPanel(n,r,l)});const a=e.querySelector(".resize-handle");a?e.insertBefore(l,a):e.appendChild(l)})}setFilter(e,t,r){if(null===t)this.filters.delete(e),this.syncExcludedValues(e,null);else{const r={...t,field:e};this.filters.set(e,r),this.syncExcludedValues(e,r)}if(this.invalidateCache(),this.notifyFilterChange([...this.filters.values()],0,r?.silent),!r?.silent){const r=this.getColumnByField(e)?.header??e;a(this.gridElement,s(this.gridElement,null===t?"filterCleared":"filterApplied",r))}this.requestRender()}getFilter(e){return this.filters.get(e)}getFilters(){return[...this.filters.values()]}getFilterModel(){return this.getFilters()}setFilterModel(e,t){this.filters.clear(),this.excludedValues.clear();for(const r of e)this.filters.set(r.field,r),this.syncExcludedValues(r.field,r);this.invalidateCache(),this.notifyFilterChange([...this.filters.values()],0,t?.silent),this.requestRender()}clearAllFilters(e){this.filters.clear(),this.excludedValues.clear(),this.searchText.clear(),this.applyFiltersInternal(e?.silent),e?.silent||a(this.gridElement,s(this.gridElement,"allFiltersCleared"))}clearFieldFilter(e,t){if(this.filters.delete(e),this.excludedValues.delete(e),this.searchText.delete(e),this.applyFiltersInternal(t?.silent),!t?.silent){const t=this.getColumnByField(e)?.header??e;a(this.gridElement,s(this.gridElement,"filterCleared",t))}}isFieldFiltered(e){return this.filters.has(e)}getFilteredRowCount(){return this.cachedResult?.length??this.rows.length}getActiveFilters(){return this.getFilters()}getUniqueValues(e){const t=this.getColumnByField(e),r=t?.filterValue;return n(this.getDataRows(),e,r)}getStaleFilters(){const e=[];for(const[t,r]of this.filters){if("set"!==r.type)continue;const n=this.getUniqueValues(t);if("notIn"===r.operator&&Array.isArray(r.value)){const t=new Set(r.value);0===n.filter(e=>!t.has(e)).length&&e.push(r)}else if("in"===r.operator&&Array.isArray(r.value)){const t=new Set(r.value);0===n.filter(e=>t.has(e)).length&&e.push(r)}}return e}getBlankMode(e){const t=this.filters.get(e);return"blank"===t?.operator?"blanksOnly":"notBlank"===t?.operator?"nonBlanksOnly":"all"}toggleBlankFilter(e,t){if("all"===t){const t=this.filters.get(e);if(t?.valueTo&&"object"==typeof t.valueTo){const r=t.valueTo;this.setFilter(e,r)}else this.setFilter(e,null);return}const r=this.filters.get(e),n=r&&"blank"!==r.operator&&"notBlank"!==r.operator?{type:r.type,operator:r.operator,value:r.value,valueTo:r.valueTo}:r?.valueTo;this.setFilter(e,{type:r?.type??"text",operator:"blanksOnly"===t?"blank":"notBlank",value:"",valueTo:n})}copyGridThemeContext(e){const t=this.gridElement;if(!t)return;for(const n of t.classList)n.startsWith("tbw-")||"selecting"===n||e.classList.add(n);const r=t.dataset.theme;r&&(e.dataset.theme=r)}injectGlobalStyles(){if(this.globalStylesInjected)return;if(document.getElementById("tbw-filter-panel-styles"))return void(this.globalStylesInjected=!0);const e=document.createElement("style");e.id="tbw-filter-panel-styles",e.textContent="@layer tbw-plugins{.tbw-filter-panel{position:fixed;background:var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));color:var(--tbw-filter-panel-fg, var(--tbw-color-fg, light-dark(#222222, #eeeeee)));border:1px solid var(--tbw-filter-panel-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-panel-radius, var(--tbw-border-radius, .25rem));box-shadow:0 4px 16px var(--tbw-filter-panel-shadow, var(--tbw-color-shadow, light-dark(rgba(0, 0, 0, .1), rgba(0, 0, 0, .3))));padding:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));z-index:10000;min-width:200px;max-width:280px;max-height:350px;display:flex;flex-direction:column;font-family:var(--tbw-font-family, system-ui, sans-serif);font-size:var(--tbw-font-size, .8125rem);transform-origin:top center}.tbw-filter-panel.tbw-filter-panel-above{transform-origin:bottom center}.tbw-filter-panel.tbw-filter-panel-animated{animation:tbw-filter-panel-enter var(--tbw-animation-duration, .15s) var(--tbw-animation-easing, ease-out)}.tbw-filter-panel.tbw-filter-panel-above.tbw-filter-panel-animated{animation:tbw-filter-panel-enter-above var(--tbw-animation-duration, .15s) var(--tbw-animation-easing, ease-out)}@keyframes tbw-filter-panel-enter{0%{opacity:0;transform:scaleY(.3) translateY(-10px)}to{opacity:1;transform:scaleY(1) translateY(0)}}@keyframes tbw-filter-panel-enter-above{0%{opacity:0;transform:scaleY(.3) translateY(10px)}to{opacity:1;transform:scaleY(1) translateY(0)}}@supports (anchor-name: --test){.tbw-filter-panel{position-anchor:--tbw-filter-anchor;top:anchor(bottom);right:anchor(right);margin-top:4px;position-try-fallbacks:flip-inline,flip-block,flip-block flip-inline}}.tbw-filter-search{margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));min-height:var(--tbw-filter-item-height, 28px)}.tbw-filter-search-input{height:var(--tbw-filter-item-height, 28px);width:100%;padding:var(--tbw-filter-search-padding, var(--tbw-spacing-sm, .375rem) var(--tbw-spacing-md, .5rem));background:var(--tbw-filter-input-bg, var(--tbw-color-bg, transparent));color:inherit;border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-input-radius, var(--tbw-border-radius, .25rem));font-size:inherit;box-sizing:border-box}.tbw-filter-search-input:focus{outline:none;border-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));box-shadow:0 0 0 2px rgba(from var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6)) r g b / 15%)}.tbw-filter-actions{display:flex;padding:var(--tbw-button-padding-sm, .25rem .125rem);margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border-bottom:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));min-height:var(--tbw-filter-item-height, 28px)}.tbw-filter-actions .tbw-filter-value-item{flex:1}.tbw-filter-values{flex:1;overflow-y:auto;margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));max-height:180px;position:relative}.tbw-filter-values-spacer{width:1px}.tbw-filter-values-content{position:absolute;top:0;left:0;right:0}.tbw-filter-value-item{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding:var(--tbw-button-padding-sm, .25rem .125rem);cursor:pointer;border-radius:3px;height:var(--tbw-filter-item-height, 28px)}.tbw-filter-value-item:hover{background:var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)))}.tbw-filter-checkbox{margin:0;cursor:pointer;accent-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}.tbw-filter-no-match{color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem)) 0;text-align:center;font-style:italic}.tbw-filter-buttons{display:flex;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding-top:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border-top:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)))}.tbw-filter-apply-btn{flex:1;padding:var(--tbw-filter-btn-padding, var(--tbw-button-padding, .375rem .75rem));background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));color:var(--tbw-filter-accent-fg, var(--tbw-color-accent-fg, light-dark(#ffffff, #000000)));border:none;border-radius:var(--tbw-border-radius, .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);font-weight:var(--tbw-filter-btn-font-weight, 500);min-height:var(--tbw-filter-btn-min-height, auto)}.tbw-filter-apply-btn:hover{filter:brightness(.9)}.tbw-filter-clear-btn{flex:1;padding:var(--tbw-filter-btn-padding, var(--tbw-button-padding, .375rem .75rem));background:transparent;color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-border-radius, .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);font-weight:var(--tbw-filter-btn-font-weight, 500);min-height:var(--tbw-filter-btn-min-height, auto)}.tbw-filter-clear-btn:hover{background:var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)))}.tbw-filter-range-inputs,.tbw-filter-date-range{display:flex;align-items:flex-end;gap:var(--tbw-spacing-sm, .375rem);margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-filter-range-group,.tbw-filter-date-group{display:flex;flex-direction:column;gap:var(--tbw-spacing-xs, .25rem);flex:1}.tbw-filter-range-label{font-size:var(--tbw-font-size-xs, .75rem);color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)))}.tbw-filter-range-input,.tbw-filter-date-input{width:100%;height:var(--tbw-filter-item-height, 28px);padding:var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-sm, .375rem);background:var(--tbw-filter-input-bg, var(--tbw-color-bg, transparent));color:inherit;border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-input-radius, var(--tbw-border-radius, .25rem));font-size:inherit;box-sizing:border-box}.tbw-filter-range-input:focus,.tbw-filter-date-input:focus{outline:none;border-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));box-shadow:0 0 0 2px rgba(from var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6)) r g b / 15%)}.tbw-filter-range-separator{color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));padding-bottom:var(--tbw-spacing-xs, .25rem)}.tbw-filter-blank-option{display:flex;align-items:center;gap:var(--tbw-spacing-sm, .375rem);padding:var(--tbw-spacing-xs, .25rem) 0;margin-bottom:var(--tbw-spacing-xs, .25rem);font-size:var(--tbw-font-size-sm, .8125rem);cursor:pointer;-webkit-user-select:none;user-select:none}.tbw-filter-blank-checkbox{accent-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));margin:0;cursor:pointer}.tbw-filter-date-range.tbw-filter-disabled,.tbw-filter-range-inputs.tbw-filter-disabled,.tbw-filter-range-slider.tbw-filter-disabled{opacity:.4;pointer-events:none}.tbw-filter-range-slider{position:relative;height:24px;margin:var(--tbw-spacing-md, .5rem) 0 var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-filter-range-track{position:absolute;top:50%;left:0;right:0;height:4px;background:var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:2px;transform:translateY(-50%)}.tbw-filter-range-fill{position:absolute;top:50%;height:4px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border-radius:2px;transform:translateY(-50%)}.tbw-filter-range-thumb{position:absolute;top:0;width:100%;height:100%;background:none;pointer-events:none;-webkit-appearance:none;appearance:none}.tbw-filter-range-thumb::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;width:16px;height:16px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border:2px solid var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));border-radius:50%;cursor:pointer;pointer-events:all;box-shadow:0 1px 3px #0003}.tbw-filter-range-thumb::-moz-range-thumb{width:16px;height:16px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border:2px solid var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));border-radius:50%;cursor:pointer;pointer-events:all;box-shadow:0 1px 3px #0003}.tbw-filter-range-thumb::-webkit-slider-thumb:hover{transform:scale(1.1)}.tbw-filter-range-thumb::-moz-range-thumb:hover{transform:scale(1.1)}}",document.head.appendChild(e),this.globalStylesInjected=!0}toggleFilterPanel(e,t,r){if(this.openPanelField===e)return void this.closeFilterPanel();this.closeFilterPanel();const i=document.createElement("div");if(i.className="tbw-filter-panel",this.copyGridThemeContext(i),this.isAnimationEnabled&&i.classList.add("tbw-filter-panel-animated"),this.panelElement=i,this.openPanelField=e,r.classList.add("active"),this.panelButtonElement=r,this.config.valuesHandler)return i.innerHTML='<div class="tbw-filter-loading">Loading...</div>',document.body.appendChild(i),this.positionPanel(i,r),this.setupPanelCloseHandler(i,r),void this.config.valuesHandler(e,t).then(r=>{this.openPanelField===e&&this.panelElement&&(i.innerHTML="",this.renderPanelContent(e,t,i,r))});const l=n(this.getDataRows(),e,this.getFilterExtractor(t));document.body.appendChild(i),this.positionPanel(i,r),this.renderPanelContent(e,t,i,l),this.setupPanelCloseHandler(i,r)}renderPanelContent(t,r,n,i){const l=this.filters.get(t);if("in"===l?.operator&&"set"===l.type&&Array.isArray(l.value)&&!this.excludedValues.has(t)){const r=l.value,n=new Set(r.map(t=>null==t?e:t)),a=new Set(i.filter(e=>!n.has(e)));this.excludedValues.set(t,a)}let a=this.excludedValues.get(t);a||(a=/* @__PURE__ */new Set,this.excludedValues.set(t,a));const s=this.searchText.get(t)??"",o={field:t,column:r,uniqueValues:i,excludedValues:a,searchText:s,currentFilter:this.filters.get(t),applySetFilter:(e,r)=>{this.applySetFilter(t,e,r),this.closeFilterPanel()},applyTextFilter:(e,r,n)=>{this.applyTextFilter(t,e,r,n),this.closeFilterPanel()},clearFilter:()=>{this.clearFieldFilter(t),this.closeFilterPanel()},closePanel:()=>this.closeFilterPanel()};let c=!1;if(this.config.filterPanelRenderer&&(this.config.filterPanelRenderer(n,o),c=n.children.length>0),!c&&r.type){const e=this.grid.effectiveConfig.typeDefaults?.[r.type];e?.filterPanelRenderer&&(e.filterPanelRenderer(n,o),c=n.children.length>0)}if(!c){const e=r.filterType??r.type;"number"===e?function(e,t,r,n){const{field:i,column:l}=t,a=l.filterParams,s=l.editorParams,o=r.filter(e=>"number"==typeof e&&!isNaN(e)),c=o.length>0?Math.min(...o):0,d=o.length>0?Math.max(...o):100,u=E(a?.min??s?.min,c),p=E(a?.max??s?.max,d),f=a?.step??s?.step??1,h=o.length>0?Math.max(u,c):u,b=o.length>0?Math.min(p,d):p,g=n.get(i);let m=h,v=b;const w="blank"===g?.operator;"between"===g?.operator?(m=E(g.value,h),v=E(g.valueTo,b)):"greaterThanOrEqual"===g?.operator?m=E(g.value,h):"lessThanOrEqual"===g?.operator&&(v=E(g.value,b));const y=document.createElement("div");y.className="tbw-filter-range-inputs";const x=document.createElement("div");x.className="tbw-filter-range-group";const C=document.createElement("label");C.textContent="Min",C.className="tbw-filter-range-label";const k=document.createElement("input");k.type="number",k.className="tbw-filter-range-input",k.min=String(u),k.max=String(p),k.step=String(f),k.value=String(m),x.appendChild(C),x.appendChild(k),y.appendChild(x);const F=document.createElement("span");F.className="tbw-filter-range-separator",F.textContent="–",y.appendChild(F);const S=document.createElement("div");S.className="tbw-filter-range-group";const A=document.createElement("label");A.textContent="Max",A.className="tbw-filter-range-label";const N=document.createElement("input");N.type="number",N.className="tbw-filter-range-input",N.min=String(u),N.max=String(p),N.step=String(f),N.value=String(v),S.appendChild(A),S.appendChild(N),y.appendChild(S),e.appendChild(y);const T=document.createElement("div");T.className="tbw-filter-range-slider";const L=document.createElement("div");L.className="tbw-filter-range-track";const R=document.createElement("div");R.className="tbw-filter-range-fill";const P=document.createElement("input");P.type="range",P.className="tbw-filter-range-thumb tbw-filter-range-thumb-min",P.min=String(u),P.max=String(p),P.step=String(f),P.value=String(m);const M=document.createElement("input");M.type="range",M.className="tbw-filter-range-thumb tbw-filter-range-thumb-max",M.min=String(u),M.max=String(p),M.step=String(f),M.value=String(v),T.appendChild(L),T.appendChild(R),T.appendChild(P),T.appendChild(M),e.appendChild(T);const q=document.createElement("label");q.className="tbw-filter-blank-option";const V=document.createElement("input");V.type="checkbox",V.className="tbw-filter-blank-checkbox",V.checked=w;const _=document.createTextNode("Blank");q.appendChild(V),q.appendChild(_);const B=e=>{k.disabled=e,N.disabled=e,P.disabled=e,M.disabled=e,y.classList.toggle("tbw-filter-disabled",e),T.classList.toggle("tbw-filter-disabled",e)};B(w),V.addEventListener("change",()=>{B(V.checked)}),e.appendChild(q);const H=()=>{const e=parseFloat(P.value),t=parseFloat(M.value),r=p-u,n=(e-u)/r*100,i=(t-u)/r*100;R.style.left=`${n}%`,R.style.width=i-n+"%"};P.addEventListener("input",()=>{const e=Math.min(parseFloat(P.value),parseFloat(M.value));P.value=String(e),k.value=String(e),H()}),M.addEventListener("input",()=>{const e=Math.max(parseFloat(M.value),parseFloat(P.value));M.value=String(e),N.value=String(e),H()}),k.addEventListener("input",()=>{const e=parseFloat(k.value);let t=Number.isFinite(e)?e:u;t=Math.max(u,Math.min(t,parseFloat(N.value))),P.value=String(t),H()}),N.addEventListener("input",()=>{const e=parseFloat(N.value);let t=Number.isFinite(e)?e:p;t=Math.min(p,Math.max(t,parseFloat(k.value))),M.value=String(t),H()}),H();const $=document.createElement("div");$.className="tbw-filter-buttons";const I=document.createElement("button");I.type="button",I.className="tbw-filter-apply-btn",I.textContent="Apply",I.addEventListener("click",()=>{if(V.checked)return void t.applyTextFilter("blank","");const e=parseFloat(k.value),r=parseFloat(N.value),n=Number.isFinite(e)?e:h,i=Number.isFinite(r)?r:b;n!==h||i!==b?t.applyTextFilter("between",n,i):t.clearFilter()}),$.appendChild(I);const z=document.createElement("button");z.type="button",z.className="tbw-filter-clear-btn",z.textContent="Clear Filter",z.addEventListener("click",()=>{t.clearFilter()}),$.appendChild(z),e.appendChild($)}(n,o,i,this.filters):"date"===e?function(e,t,r,n){const{field:i,column:l}=t,a=l.filterParams,s=l.editorParams,o=r.filter(e=>e instanceof Date||"string"==typeof e&&!isNaN(Date.parse(e))).map(e=>e instanceof Date?e:new Date(e)).filter(e=>!isNaN(e.getTime())),c=o.length>0?new Date(Math.min(...o.map(e=>e.getTime()))):null,d=o.length>0?new Date(Math.max(...o.map(e=>e.getTime()))):null,u=w(a?.min)||w(s?.min)||v(c),p=w(a?.max)||w(s?.max)||v(d),f=v(c)||w(a?.min)||w(s?.min),h=v(d)||w(a?.max)||w(s?.max),b=n.get(i);let g=f,m=h;const y="blank"===b?.operator;"between"===b?.operator?(g=w(b.value)||f,m=w(b.valueTo)||h):"greaterThanOrEqual"===b?.operator?g=w(b.value)||f:"lessThanOrEqual"===b?.operator&&(m=w(b.value)||h);const x=document.createElement("div");x.className="tbw-filter-date-range";const C=document.createElement("div");C.className="tbw-filter-date-group";const E=document.createElement("label");E.textContent="From",E.className="tbw-filter-range-label";const k=document.createElement("input");k.type="date",k.className="tbw-filter-date-input",u&&(k.min=u),p&&(k.max=p),k.value=g,C.appendChild(E),C.appendChild(k),x.appendChild(C);const F=document.createElement("span");F.className="tbw-filter-range-separator",F.textContent="–",x.appendChild(F);const S=document.createElement("div");S.className="tbw-filter-date-group";const A=document.createElement("label");A.textContent="To",A.className="tbw-filter-range-label";const N=document.createElement("input");N.type="date",N.className="tbw-filter-date-input",u&&(N.min=u),p&&(N.max=p),N.value=m,S.appendChild(A),S.appendChild(N),x.appendChild(S),e.appendChild(x);const T=document.createElement("label");T.className="tbw-filter-blank-option";const L=document.createElement("input");L.type="checkbox",L.className="tbw-filter-blank-checkbox",L.checked=y;const R=document.createTextNode("Show only blank");T.appendChild(L),T.appendChild(R);const P=e=>{k.disabled=e,N.disabled=e,x.classList.toggle("tbw-filter-disabled",e)};P(y),L.addEventListener("change",()=>{P(L.checked)}),e.appendChild(T);const M=document.createElement("div");M.className="tbw-filter-buttons";const q=document.createElement("button");q.type="button",q.className="tbw-filter-apply-btn",q.textContent="Apply",q.addEventListener("click",()=>{if(L.checked)return void t.applyTextFilter("blank","");const e=k.value,r=N.value,n=e&&e!==f?e:"",i=r&&r!==h?r:"";n&&i?t.applyTextFilter("between",n,i):n?t.applyTextFilter("greaterThanOrEqual",n):i?t.applyTextFilter("lessThanOrEqual",i):t.clearFilter()}),M.appendChild(q);const V=document.createElement("button");V.type="button",V.className="tbw-filter-clear-btn",V.textContent="Clear Filter",V.addEventListener("click",()=>{t.clearFilter()}),M.appendChild(V),e.appendChild(M)}(n,o,i,this.filters):C(n,o,i,a,{caseSensitive:this.config.caseSensitive,debounceMs:this.config.debounceMs},this.searchText)}}setupPanelCloseHandler(e,t){this.panelAbortController=new AbortController;const{signal:r}=this.panelAbortController;setTimeout(()=>{r.aborted||document.addEventListener("click",r=>{e.contains(r.target)||r.target===t||this.closeFilterPanel()},{signal:r})},0)}closeFilterPanel(){const e=this.panelElement;if(e&&(e.remove(),this.panelElement=null),this.panelAnchorElement&&(this.panelAnchorElement.style.anchorName="",this.panelAnchorElement=null),this.panelButtonElement){const e=this.openPanelField;e&&this.filters.has(e)||this.panelButtonElement.classList.remove("active"),this.panelButtonElement=null}this.openPanelField=null,this.panelAbortController?.abort(),this.panelAbortController=null}static supportsAnchorPositioning=null;static checkAnchorPositioningSupport(){return null===k.supportsAnchorPositioning&&(k.supportsAnchorPositioning=CSS.supports("anchor-name","--test")),k.supportsAnchorPositioning}positionPanel(e,t){const r=t.closest(".header-row")??t;if(r.style.anchorName="--tbw-filter-anchor",this.panelAnchorElement=r,k.checkAnchorPositioningSupport()){r.style.anchorName="",t.style.anchorName="--tbw-filter-anchor",this.panelAnchorElement=t;const n=r.getBoundingClientRect().bottom-t.getBoundingClientRect().bottom;return e.style.marginTop=`${n+4}px`,void requestAnimationFrame(()=>{const r=e.getBoundingClientRect(),n=t.getBoundingClientRect();r.top<n.top&&e.classList.add("tbw-filter-panel-above")})}const n=r.getBoundingClientRect(),i=t.getBoundingClientRect();e.style.position="fixed",e.style.top=`${n.bottom+4}px`,e.style.left=`${i.right}px`,requestAnimationFrame(()=>{const t=e.getBoundingClientRect();e.style.left=i.right-t.width+"px";i.right-t.width<8&&(e.style.left=`${i.left}px`),t.bottom>window.innerHeight-8&&(e.style.top=n.top-t.height-4+"px",e.classList.add("tbw-filter-panel-above"))})}applySetFilter(e,t,r){if(this.excludedValues.set(e,new Set(t)),0===t.length)this.filters.delete(e);else{const n=this.filters.get(e);if("in"===n?.operator){const n=this.getUniqueValues(e),i=new Set(t),l=n.filter(e=>!i.has(e));this.filters.set(e,{field:e,type:"set",operator:"in",value:l,...void 0!==r&&{valueTo:r}})}else this.filters.set(e,{field:e,type:"set",operator:"notIn",value:t,...void 0!==r&&{valueTo:r}})}this.applyFiltersInternal()}applyTextFilter(e,t,r,n){const i=this.getColumnByField(e),l=i?.filterType??i?.type??"text";this.filters.set(e,{field:e,type:l,operator:t,value:r,valueTo:n}),this.applyFiltersInternal()}applyFiltersInternal(e){this.invalidateCache();const t=[...this.filters.values()];if(this.config.filterHandler){this.gridElement.setAttribute("aria-busy","true");const r=this.config.filterHandler(t,this.sourceRows),n=r=>{this.gridElement.removeAttribute("aria-busy"),this.cachedResult=r,this.grid.rows=r,this.notifyFilterChange(t,r.length,e),this.requestRender()};return void(r&&"function"==typeof r.then?r.then(n):n(r))}this.notifyFilterChange(t,0,e),this.requestRender()}getColumnState(e){if(!this.config.trackColumnState)return;const t=this.filters.get(e);return t?{filter:{type:t.type,operator:t.operator,value:t.value,valueTo:t.valueTo}}:void 0}applyColumnState(e,t){if(!this.config.trackColumnState)return;if(!t.filter)return void this.filters.delete(e);const r={field:e,type:t.filter.type,operator:t.filter.operator,value:t.filter.value,valueTo:t.filter.valueTo};this.filters.set(e,r),this.invalidateCache()}}export{e as BLANK_FILTER_VALUE,k as FilteringPlugin};
|
|
1
|
+
const e="(Blank)";function t(e){if("number"==typeof e)return e;if(e instanceof Date)return e.getTime();const t=Number(e);if(!isNaN(t))return t;return new Date(e).getTime()}function r(r,n,i=!1,l){if(!n.length)return r;const a=n.map(r=>function(r,n,i){const l=r.field,a=r.operator,s=i?e=>i(e[l],e):e=>e[l];if("blank"===a)return e=>{const t=s(e);return null==t||""===t||"number"==typeof t&&isNaN(t)};if("notBlank"===a)return e=>{const t=s(e);return null!=t&&""!==t&&!("number"==typeof t&&isNaN(t))};if(i&&("notIn"===a||"in"===a)){const t=r.value;if("notIn"===a){if(!Array.isArray(t))return()=>!0;const r=new Set(t);return t=>{const n=i(t[l],t),a=Array.isArray(n)?n:null!=n?[n]:[];return 0===a.length?!r.has(e):!a.some(e=>r.has(e))}}if(!Array.isArray(t))return()=>!1;const n=new Set(t);return t=>{const r=i(t[l],t),a=Array.isArray(r)?r:null!=r?[r]:[];return 0===a.length?n.has(e):a.some(e=>n.has(e))}}if("notIn"===a){if(!Array.isArray(r.value))return()=>!0;const t=new Set(r.value);return r=>{const n=r[l];return null==n||""===n?!t.has(e):!t.has(n)}}if("in"===a){if(!Array.isArray(r.value))return()=>!1;const t=new Set(r.value);return r=>{const n=r[l];return null==n||""===n?t.has(e):t.has(n)}}const o="number"===r.type&&!i,c=e=>null==e||""===e||"number"==typeof e&&isNaN(e);if("greaterThan"===a){const e=t(r.value);return o?t=>{const r=t[l];return!c(r)&&r>e}:r=>{const n=s(r);if(c(n))return!1;const i=t(n);return!isNaN(i)&&i>e}}if("greaterThanOrEqual"===a){const e=t(r.value);return o?t=>{const r=t[l];return!c(r)&&r>=e}:r=>{const n=s(r);if(c(n))return!1;const i=t(n);return!isNaN(i)&&i>=e}}if("lessThan"===a){const e=t(r.value);return o?t=>{const r=t[l];return!c(r)&&r<e}:r=>{const n=s(r);if(c(n))return!1;const i=t(n);return!isNaN(i)&&i<e}}if("lessThanOrEqual"===a){const e=t(r.value);return o?t=>{const r=t[l];return!c(r)&&r<=e}:r=>{const n=s(r);if(c(n))return!1;const i=t(n);return!isNaN(i)&&i<=e}}if("between"===a){const e=t(r.value),n=t(r.valueTo);return o?t=>{const r=t[l];return!c(r)&&(r>=e&&r<=n)}:r=>{const i=s(r);if(c(i))return!1;const l=t(i);return!isNaN(l)&&l>=e&&l<=n}}const d=n?String(r.value):String(r.value).toLowerCase();return"contains"===a?n?e=>{const t=s(e);return null!=t&&String(t).includes(d)}:e=>{const t=s(e);return null!=t&&String(t).toLowerCase().includes(d)}:"notContains"===a?n?e=>{const t=s(e);return null!=t&&!String(t).includes(d)}:e=>{const t=s(e);return null!=t&&!String(t).toLowerCase().includes(d)}:"equals"===a?n?e=>{const t=s(e);return null!=t&&String(t)===d}:e=>{const t=s(e);return null!=t&&String(t).toLowerCase()===d}:"notEquals"===a?n?e=>{const t=s(e);return null!=t&&String(t)!==d}:e=>{const t=s(e);return null!=t&&String(t).toLowerCase()!==d}:"startsWith"===a?n?e=>{const t=s(e);return null!=t&&String(t).startsWith(d)}:e=>{const t=s(e);return null!=t&&String(t).toLowerCase().startsWith(d)}:"endsWith"===a?n?e=>{const t=s(e);return null!=t&&String(t).endsWith(d)}:e=>{const t=s(e);return null!=t&&String(t).toLowerCase().endsWith(d)}:()=>!0}(r,i,l?.get(r.field)));return 1===a.length?r.filter(a[0]):r.filter(e=>{for(let t=0;t<a.length;t++)if(!a[t](e))return!1;return!0})}function n(t,r,n){const i=/* @__PURE__ */new Set;let l=!1;for(const e of t){const t=e[r];if(n){const r=n(t,e);if(Array.isArray(r)){0===r.length&&(l=!0);for(const e of r)null!=e&&i.add(e)}else null!=r?i.add(r):l=!0}else null!=t&&""!==t?i.add(t):l=!0}return l&&i.add(e),[...i].sort((e,t)=>"number"==typeof e&&"number"==typeof t?e-t:String(e).localeCompare(String(t)))}const i={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`},l={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function a(e,t){if(!e)return;const r="effectiveConfig"in e?e.effectiveConfig:void 0;if(!1===r?.a11y?.announcements)return;const n=e.querySelector?.(".tbw-sr-only");n&&(n.textContent="",requestAnimationFrame(()=>{n.textContent=t}))}function s(e,t,...r){const n=e&&"effectiveConfig"in e?e.effectiveConfig:void 0,l=n?.a11y?.messages?.[t];return l?l(...r):i[t](...r)}const o=/* @__PURE__ */new WeakMap;function c(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function d(e,t,r,n){return`${c(r,n)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}const u="__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(""));new RegExp(`__(proto|defineGetter|defineSetter)|${u.slice(3).join("|")}|this\\b`);const p=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("|")),f=/^on\w+$/i,h=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),b=/^\s*(javascript|vbscript|data|blob):/i;function g(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 n of r){const e=n.tagName.toLowerCase();if(p.has(e)){t.push(n);continue}if("svg"===e||"http://www.w3.org/2000/svg"===n.namespaceURI){if(Array.from(n.attributes).some(e=>f.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(n);continue}}const r=[];for(const t of n.attributes){const e=t.name.toLowerCase();f.test(e)?r.push(t.name):(h.has(e)&&b.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name)}r.forEach(e=>n.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}class m{static dependencies;static manifest;aliases;version="2.17.2";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 n of Object.keys(t))r[n]=this;for(const n of e){const e=n.userConfig;for(const[i,l]of Object.entries(e)){if(void 0===l)continue;if(!(i in t)){t[i]=l,r[i]=n;continue}if(t[i]===l)continue;const e=r[i]?.constructor.name??this.constructor.name,a=n.constructor.name,s=d("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${i}" supplied by both ${e} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(s)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig;for(const r of Object.keys(t))delete t[r];Object.assign(t,e.userConfig)}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{...l,...e}}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),r=parseInt(t,10);if(!isNaN(r))return r}return 200}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 n=this.#t(t,r);void 0!==n?"string"==typeof n?e.innerHTML=g(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 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 n=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return n?e.insertBefore(r,n):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(d(e,t,this.gridElement.id,this.name)):console.warn(`${c(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(d(e,t,this.gridElement.id,this.name))}}function v(e){return e?e.toISOString().split("T")[0]:""}function w(e){return e?"string"==typeof e?e:"number"==typeof e?v(new Date(e)):"":""}const y=335e5;function x(e){const{totalRows:t,viewportHeight:r,scrollTop:n,rowHeight:i,overscan:l,maxSpacerHeight:a=y}=e,s=Math.ceil(r/i),o=t*i,c=function(e,t,r=y){return{rawContentHeight:e,spacerHeight:Math.min(e,r),viewportHeight:t,capped:e>r}}(o,r,a),d=function(e,t){if(!t.capped)return e;const r=t.spacerHeight-t.viewportHeight,n=t.rawContentHeight-t.viewportHeight;if(r<=0||n<=0)return e;const i=e*n/r;return i<0?0:i>n?n:i}(n,c);let u=Math.floor(d/i)-l;u<0&&(u=0);let p=u+s+2*l;return p>t&&(p=t),p===t&&u>0&&(u=Math.max(0,p-s-2*l)),{start:u,end:p,offsetY:u*i,totalHeight:c.spacerHeight,rawContentHeight:o}}function C(e,t,r,n,i,l){const{field:a,column:s}=t,o=function(e){if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-filter-item-height");if(t&&t.trim()){const e=parseFloat(t);if(!isNaN(e)&&e>0)return e}}return 28}(e),c=e=>{if(null==e)return"(Blank)";if(s.format&&!s.filterValue){const t=s.format(e,void 0);if(t)return t}return String(e)};r=r.slice().sort((e,t)=>"number"==typeof e&&"number"==typeof t?e-t:c(e).localeCompare(c(t)));const d=document.createElement("div");d.className="tbw-filter-search";const u=document.createElement("input");u.type="text",u.placeholder="Search...",u.className="tbw-filter-search-input",u.value=l.get(a)??"",d.appendChild(u),e.appendChild(d);const p=document.createElement("div");p.className="tbw-filter-actions";const f=document.createElement("label");f.className="tbw-filter-value-item",f.style.padding="0",f.style.margin="0";const h=document.createElement("input");h.type="checkbox",h.className="tbw-filter-checkbox";const b=document.createElement("span");b.textContent="Select All",f.appendChild(h),f.appendChild(b),p.appendChild(f);const g=/* @__PURE__ */new Map;r.forEach(e=>{const t=null==e?"__null__":String(e);g.set(t,!n.has(e))});const m=()=>{const e=[...g.values()],t=e.every(e=>e),r=e.every(e=>!e);h.checked=t,h.indeterminate=!t&&!r};h.addEventListener("change",()=>{const e=h.checked;for(const t of g.keys())g.set(t,e);m(),k()}),m(),e.appendChild(p);const v=document.createElement("div");v.className="tbw-filter-values";const w=document.createElement("div");w.className="tbw-filter-values-spacer",v.appendChild(w);const y=document.createElement("div");y.className="tbw-filter-values-content",v.appendChild(y);let C=[];const E=(e,t)=>{const r=c(e),n=null==e?"__null__":String(e),i=document.createElement("label");i.className="tbw-filter-value-item",i.style.position="absolute",i.style.top=`calc(var(--tbw-filter-item-height, 28px) * ${t})`,i.style.left="0",i.style.right="0",i.style.boxSizing="border-box";const l=document.createElement("input");l.type="checkbox",l.className="tbw-filter-checkbox",l.checked=g.get(n)??!0,l.dataset.value=n,l.addEventListener("change",()=>{g.set(n,l.checked),m()});const a=document.createElement("span");return a.textContent=r,i.appendChild(l),i.appendChild(a),i},k=()=>{const e=C.length,t=v.clientHeight,r=v.scrollTop;if(w.style.height=e*o+"px",e<=50/3)return y.innerHTML="",y.style.transform="translateY(0px)",void C.forEach((e,t)=>{y.appendChild(E(e,t))});const n=x({totalRows:e,viewportHeight:t,scrollTop:r,rowHeight:o,overscan:3});y.style.transform=`translateY(${n.offsetY}px)`,y.innerHTML="";for(let i=n.start;i<n.end;i++)y.appendChild(E(C[i],i-n.start))},F=e=>{const t=i.caseSensitive??!1,n=t?e:e.toLowerCase();if(C=r.filter(r=>{const i=c(r),l=t?i:i.toLowerCase();return!e||l.includes(n)}),C.sort((e,t)=>{const r=null==e?"__null__":String(e),n=null==t?"__null__":String(t),i=g.get(r)??!0;return i!==(g.get(n)??!0)?i?-1:1:"number"==typeof e&&"number"==typeof t?e-t:c(e).localeCompare(c(t))}),0===C.length){w.style.height="0px",y.innerHTML="";const e=document.createElement("div");return e.className="tbw-filter-no-match",e.textContent="No matching values",void y.appendChild(e)}k()};let S;v.addEventListener("scroll",()=>{C.length>0&&k()},{passive:!0}),F(u.value),e.appendChild(v),u.addEventListener("input",()=>{clearTimeout(S),S=setTimeout(()=>{l.set(a,u.value),F(u.value)},i.debounceMs??150)});const A=document.createElement("div");A.className="tbw-filter-buttons";const N=document.createElement("button");N.type="button",N.className="tbw-filter-apply-btn",N.textContent="Apply",N.addEventListener("click",()=>{const e=[];for(const[t,n]of g)if(!n)if("__null__"===t)e.push(null);else{const n=r.find(e=>String(e)===t);e.push(void 0!==n?n:t)}t.applySetFilter(e)}),A.appendChild(N);const T=document.createElement("button");T.type="button",T.className="tbw-filter-clear-btn",T.textContent="Clear Filter",T.addEventListener("click",()=>{t.clearFilter()}),A.appendChild(T),e.appendChild(A)}function E(e,t){if("number"==typeof e)return e;if("string"==typeof e){const r=parseFloat(e);return isNaN(r)?t:r}return t}class k extends m{static manifest={events:[{type:"filter-change",description:"Emitted when filter criteria change. Broadcast to both DOM consumers and plugin bus."}],queries:[{type:"getContextMenuItems",description:"Contributes filter-related items to the header context menu"}]};name="filtering";styles='@layer tbw-plugins{tbw-grid .tbw-quick-filter-input{flex:1;max-width:300px;height:var(--tbw-input-height, 1.75rem);padding:var(--tbw-input-padding, 0 .5rem);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);background:var(--tbw-color-bg);color:var(--tbw-color-fg);font-size:var(--tbw-font-size-sm, .8125rem)}tbw-grid .tbw-quick-filter-input:focus{outline:none;border-color:var(--tbw-color-accent)}tbw-grid .header-cell.filtered:before{content:"";position:absolute;top:var(--tbw-spacing-xs, .25rem);right:var(--tbw-spacing-xs, .25rem);width:var(--tbw-indicator-size, .375rem);height:var(--tbw-indicator-size, .375rem);background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border-radius:50%}tbw-grid .tbw-filter-btn{display:var(--tbw-filter-btn-display, inline-flex);visibility:var(--tbw-filter-btn-visibility, visible);align-items:center;justify-content:center;background:transparent;border:none;cursor:pointer;padding:2px;margin-left:var(--tbw-spacing-xs, .25rem);opacity:.4;transition:opacity .15s,visibility 0s,display 0s allow-discrete;color:inherit;vertical-align:middle;transition-behavior:allow-discrete}tbw-grid .tbw-filter-btn:hover,tbw-grid .tbw-filter-btn.active{opacity:1;visibility:visible;display:inline-flex}tbw-grid .tbw-filter-btn.active{color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}tbw-grid .header-row .cell:hover .tbw-filter-btn,tbw-grid .header-row .cell.filtered .tbw-filter-btn{display:inline-flex;visibility:visible}}';get defaultConfig(){return{debounceMs:300,caseSensitive:!1}}isFilteringEnabled(){return!1!==this.grid.effectiveConfig?.filterable}isColumnFilterable(e){return!!this.isFilteringEnabled()&&!1!==e.filterable}getDataRows(){const e=this.sourceRows;if(e.length>0)return e;const t=this.rows;return 0===t.length?t:t.filter(e=>null!=e&&!0!==e.__loading)}getFilterValues(){const e=this.grid.effectiveConfig?.columns;if(!e)return;let t;for(const r of e){if(!r.field)continue;const e=this.getFilterExtractor(r);e&&(t||(t=/* @__PURE__ */new Map),t.set(r.field,e))}return t}getFilterExtractor(e){return e.filterValue?e.filterValue:e.valueAccessor?(t,r)=>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 n=e,i=t.field;let l=o.get(n);if(l){const e=l.get(i);if(void 0!==e)return e.v}else l=/* @__PURE__ */new Map,o.set(n,l);const a=t.valueAccessor({row:e,column:t,rowIndex:r});return l.set(i,{v:a}),a}(r,e):void 0}filters=/* @__PURE__ */new Map;cachedResult=null;cacheKey=null;cachedInputRows=null;openPanelField=null;panelElement=null;panelAnchorElement=null;panelButtonElement=null;searchText=/* @__PURE__ */new Map;excludedValues=/* @__PURE__ */new Map;panelAbortController=null;globalStylesInjected=!1;columnLookup=null;columnLookupRef=null;getColumnByField(e){const t=this.grid.effectiveConfig?.columns;if(!t)return;let r=this.columnLookup;if(t!==this.columnLookupRef||!r){r=/* @__PURE__ */new Map;for(const e of t)e.field&&r.set(e.field,e);this.columnLookup=r,this.columnLookupRef=t}return r.get(e)}computeSelected(){const t={},r=[];for(const[e,n]of this.filters)if("set"===n.type)if("in"===n.operator&&Array.isArray(n.value))t[e]=n.value;else if("notIn"===n.operator){const t=this.getColumnByField(e);r.push({field:e,filterValue:t?this.getFilterExtractor(t):void 0})}if(r.length>0){const n=function(t,r){const n=/* @__PURE__ */new Map;for(const{field:e,filterValue:l}of r)n.set(e,{values:/* @__PURE__ */new Set,hasBlank:!1,hasExtractor:!!l});for(const e of t)for(const{field:t,filterValue:i}of r){const r=n.get(t),l=e[t];if(i){const t=i(l,e);if(Array.isArray(t)){0===t.length&&(r.hasBlank=!0);for(const e of t)null!=e&&r.values.add(e)}else null!=t?r.values.add(t):r.hasBlank=!0}else null!=l&&""!==l?r.values.add(l):r.hasBlank=!0}const i=/* @__PURE__ */new Map;for(const[l,{values:a,hasBlank:s}]of n)s&&a.add(e),i.set(l,[...a].sort((e,t)=>"number"==typeof e&&"number"==typeof t?e-t:String(e).localeCompare(String(t))));return i}(this.getDataRows(),r);for(const{field:e}of r){const r=this.excludedValues.get(e),i=n.get(e)??[];t[e]=r?i.filter(e=>!r.has(e)):i}}return t}invalidateCache(){this.cachedResult=null,this.cacheKey=null,this.cachedInputRows=null}notifyFilterChange(e,t,r){r?this.emitPluginEvent("filter-change",{filters:e}):(this.broadcast("filter-change",{filters:e,filteredRowCount:t,selected:this.computeSelected()}),this.config.trackColumnState&&this.grid.requestStateChange?.())}syncExcludedValues(t,r){if(r)if("set"===r.type&&"notIn"===r.operator&&Array.isArray(r.value))this.excludedValues.set(t,new Set(r.value));else if("set"===r.type&&"in"===r.operator&&Array.isArray(r.value)){const n=this.getDataRows();if(!n||0===n.length)return void this.excludedValues.delete(t);const i=r.value,l=new Set(i.map(t=>null==t?e:t)),a=this.getUniqueValues(t),s=new Set(a.filter(e=>!l.has(e)));this.excludedValues.set(t,s)}else"set"===r.type&&this.excludedValues.delete(t);else this.excludedValues.delete(t)}attach(e){super.attach(e),this.injectGlobalStyles()}detach(){this.filters.clear(),this.invalidateCache(),this.columnLookup=null,this.columnLookupRef=null,this.openPanelField=null,this.panelElement&&(this.panelElement.remove(),this.panelElement=null),this.searchText.clear(),this.excludedValues.clear(),this.panelAbortController?.abort(),this.panelAbortController=null}handleQuery(e){if("filter:get-model"===e.type){if(!this.filters.size)return;return Object.fromEntries(this.filters)}if("getContextMenuItems"===e.type){const t=e.context;if(!t.isHeader)return;const r=t.column;if(!r?.field)return;if(!this.isFilteringEnabled())return;if(!this.isColumnFilterable(r))return;const n=[],i=this.isFieldFiltered(r.field),l=this.filters.size>0;return i&&n.push({id:"filtering/clear-column-filter",label:"Clear Filter",icon:"✕",order:20,action:()=>this.clearFieldFilter(r.field)}),l&&n.push({id:"filtering/clear-all-filters",label:"Clear All Filters",icon:"✕",order:21,disabled:!l,action:()=>this.clearAllFilters()}),n.length>0?n:void 0}}processRows(e){if(!this.filters.size)return e;const t=[...this.filters.values()];if(this.config.filterHandler)return this.cachedResult?this.cachedResult:e;const n=(i=t,JSON.stringify(i.map(e=>({field:e.field,operator:e.operator,value:e.value,valueTo:e.valueTo}))));var i;const l=e===this.cachedInputRows;if(this.cacheKey===n&&this.cachedResult&&l)return this.cachedResult;if(!l)for(const[r,s]of this.filters)"set"===s.type&&"in"===s.operator&&this.syncExcludedValues(r,s);const a=r(e,t,this.config.caseSensitive,this.getFilterValues());return this.cachedResult=a,this.cacheKey=n,this.cachedInputRows=e,a}afterRender(){const e=this.gridElement;if(!e)return;e.querySelectorAll('[part~="header-cell"]').forEach(e=>{const t=e.getAttribute("data-col");if(null===t)return;const r=this.visibleColumns[parseInt(t,10)];if(!r||!this.isColumnFilterable(r))return;if(!0===r.utility)return;const n=r.field;if(!n)return;const i=this.filters.has(n);let l=e.querySelector(".tbw-filter-btn");if(l){const t=l.classList.contains("active");return l.classList.toggle("active",i),e.classList.toggle("filtered",i),i?e.setAttribute("aria-description","Filtered"):e.removeAttribute("aria-description"),void(t!==i&&this.setIcon(l,i?"filterActive":"filter"))}l=document.createElement("button"),l.type="button",l.className="tbw-filter-btn",l.setAttribute("aria-label",`Filter ${r.header??n}`),this.setIcon(l,i?"filterActive":"filter"),i&&(l.classList.add("active"),e.classList.add("filtered"),e.setAttribute("aria-description","Filtered")),l.addEventListener("click",e=>{e.stopPropagation(),this.toggleFilterPanel(n,r,l)});const a=e.querySelector(".resize-handle");a?e.insertBefore(l,a):e.appendChild(l)})}setFilter(e,t,r){if(null===t)this.filters.delete(e),this.syncExcludedValues(e,null);else{const r={...t,field:e};this.filters.set(e,r),this.syncExcludedValues(e,r)}if(this.invalidateCache(),this.notifyFilterChange([...this.filters.values()],0,r?.silent),!r?.silent){const r=this.getColumnByField(e)?.header??e;a(this.gridElement,s(this.gridElement,null===t?"filterCleared":"filterApplied",r))}this.requestRender()}getFilter(e){return this.filters.get(e)}getFilters(){return[...this.filters.values()]}getFilterModel(){return this.getFilters()}setFilterModel(e,t){this.filters.clear(),this.excludedValues.clear();for(const r of e)this.filters.set(r.field,r),this.syncExcludedValues(r.field,r);this.invalidateCache(),this.notifyFilterChange([...this.filters.values()],0,t?.silent),this.requestRender()}clearAllFilters(e){this.filters.clear(),this.excludedValues.clear(),this.searchText.clear(),this.applyFiltersInternal(e?.silent),e?.silent||a(this.gridElement,s(this.gridElement,"allFiltersCleared"))}clearFieldFilter(e,t){if(this.filters.delete(e),this.excludedValues.delete(e),this.searchText.delete(e),this.applyFiltersInternal(t?.silent),!t?.silent){const t=this.getColumnByField(e)?.header??e;a(this.gridElement,s(this.gridElement,"filterCleared",t))}}isFieldFiltered(e){return this.filters.has(e)}getFilteredRowCount(){return this.cachedResult?.length??this.rows.length}getActiveFilters(){return this.getFilters()}getUniqueValues(e){const t=this.getColumnByField(e),r=t?.filterValue;return n(this.getDataRows(),e,r)}getStaleFilters(){const e=[];for(const[t,r]of this.filters){if("set"!==r.type)continue;const n=this.getUniqueValues(t);if("notIn"===r.operator&&Array.isArray(r.value)){const t=new Set(r.value);0===n.filter(e=>!t.has(e)).length&&e.push(r)}else if("in"===r.operator&&Array.isArray(r.value)){const t=new Set(r.value);0===n.filter(e=>t.has(e)).length&&e.push(r)}}return e}getBlankMode(e){const t=this.filters.get(e);return"blank"===t?.operator?"blanksOnly":"notBlank"===t?.operator?"nonBlanksOnly":"all"}toggleBlankFilter(e,t){if("all"===t){const t=this.filters.get(e);if(t?.valueTo&&"object"==typeof t.valueTo){const r=t.valueTo;this.setFilter(e,r)}else this.setFilter(e,null);return}const r=this.filters.get(e),n=r&&"blank"!==r.operator&&"notBlank"!==r.operator?{type:r.type,operator:r.operator,value:r.value,valueTo:r.valueTo}:r?.valueTo;this.setFilter(e,{type:r?.type??"text",operator:"blanksOnly"===t?"blank":"notBlank",value:"",valueTo:n})}copyGridThemeContext(e){const t=this.gridElement;if(!t)return;for(const n of t.classList)n.startsWith("tbw-")||"selecting"===n||e.classList.add(n);const r=t.dataset.theme;r&&(e.dataset.theme=r)}injectGlobalStyles(){if(this.globalStylesInjected)return;if(document.getElementById("tbw-filter-panel-styles"))return void(this.globalStylesInjected=!0);const e=document.createElement("style");e.id="tbw-filter-panel-styles",e.textContent="@layer tbw-plugins{.tbw-filter-panel{position:fixed;background:var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));color:var(--tbw-filter-panel-fg, var(--tbw-color-fg, light-dark(#222222, #eeeeee)));border:1px solid var(--tbw-filter-panel-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-panel-radius, var(--tbw-border-radius, .25rem));box-shadow:0 4px 16px var(--tbw-filter-panel-shadow, var(--tbw-color-shadow, light-dark(rgba(0, 0, 0, .1), rgba(0, 0, 0, .3))));padding:var(--tbw-panel-padding, var(--tbw-spacing-lg, .75rem));z-index:10000;min-width:200px;max-width:280px;max-height:350px;display:flex;flex-direction:column;font-family:var(--tbw-font-family, system-ui, sans-serif);font-size:var(--tbw-font-size, .8125rem);transform-origin:top center}.tbw-filter-panel.tbw-filter-panel-above{transform-origin:bottom center}.tbw-filter-panel.tbw-filter-panel-animated{animation:tbw-filter-panel-enter var(--tbw-animation-duration, .15s) var(--tbw-animation-easing, ease-out)}.tbw-filter-panel.tbw-filter-panel-above.tbw-filter-panel-animated{animation:tbw-filter-panel-enter-above var(--tbw-animation-duration, .15s) var(--tbw-animation-easing, ease-out)}@keyframes tbw-filter-panel-enter{0%{opacity:0;transform:scaleY(.3) translateY(-10px)}to{opacity:1;transform:scaleY(1) translateY(0)}}@keyframes tbw-filter-panel-enter-above{0%{opacity:0;transform:scaleY(.3) translateY(10px)}to{opacity:1;transform:scaleY(1) translateY(0)}}@supports (anchor-name: --test){.tbw-filter-panel{position-anchor:--tbw-filter-anchor;top:anchor(bottom);right:anchor(right);margin-top:4px;position-try-fallbacks:flip-inline,flip-block,flip-block flip-inline}}.tbw-filter-search{margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));min-height:var(--tbw-filter-item-height, 28px)}.tbw-filter-search-input{height:var(--tbw-filter-item-height, 28px);width:100%;padding:var(--tbw-filter-search-padding, var(--tbw-spacing-sm, .375rem) var(--tbw-spacing-md, .5rem));background:var(--tbw-filter-input-bg, var(--tbw-color-bg, transparent));color:inherit;border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-input-radius, var(--tbw-border-radius, .25rem));font-size:inherit;box-sizing:border-box}.tbw-filter-search-input:focus{outline:none;border-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));box-shadow:0 0 0 2px rgba(from var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6)) r g b / 15%)}.tbw-filter-actions{display:flex;padding:var(--tbw-button-padding-sm, .25rem .125rem);margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border-bottom:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));min-height:var(--tbw-filter-item-height, 28px)}.tbw-filter-actions .tbw-filter-value-item{flex:1}.tbw-filter-values{flex:1;overflow-y:auto;margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));max-height:180px;position:relative}.tbw-filter-values-spacer{width:1px}.tbw-filter-values-content{position:absolute;top:0;left:0;right:0}.tbw-filter-value-item{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding:var(--tbw-button-padding-sm, .25rem .125rem);cursor:pointer;border-radius:3px;height:var(--tbw-filter-item-height, 28px)}.tbw-filter-value-item:hover{background:var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)))}.tbw-filter-checkbox{margin:0;cursor:pointer;accent-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6))}.tbw-filter-no-match{color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));padding:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem)) 0;text-align:center;font-style:italic}.tbw-filter-buttons{display:flex;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding-top:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));border-top:1px solid var(--tbw-filter-divider, var(--tbw-color-border, light-dark(#d0d0d4, #454545)))}.tbw-filter-apply-btn{flex:1;padding:var(--tbw-filter-btn-padding, var(--tbw-button-padding, .375rem .75rem));background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));color:var(--tbw-filter-accent-fg, var(--tbw-color-accent-fg, light-dark(#ffffff, #000000)));border:none;border-radius:var(--tbw-border-radius, .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);font-weight:var(--tbw-filter-btn-font-weight, 500);min-height:var(--tbw-filter-btn-min-height, auto)}.tbw-filter-apply-btn:hover{filter:brightness(.9)}.tbw-filter-clear-btn{flex:1;padding:var(--tbw-filter-btn-padding, var(--tbw-button-padding, .375rem .75rem));background:transparent;color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-border-radius, .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);font-weight:var(--tbw-filter-btn-font-weight, 500);min-height:var(--tbw-filter-btn-min-height, auto)}.tbw-filter-clear-btn:hover{background:var(--tbw-filter-hover, var(--tbw-color-row-hover, light-dark(#f0f6ff, #1c1c1c)))}.tbw-filter-range-inputs,.tbw-filter-date-range{display:flex;align-items:flex-end;gap:var(--tbw-spacing-sm, .375rem);margin-bottom:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-filter-range-group,.tbw-filter-date-group{display:flex;flex-direction:column;gap:var(--tbw-spacing-xs, .25rem);flex:1}.tbw-filter-range-label{font-size:var(--tbw-font-size-xs, .75rem);color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)))}.tbw-filter-range-input,.tbw-filter-date-input{width:100%;height:var(--tbw-filter-item-height, 28px);padding:var(--tbw-spacing-xs, .25rem) var(--tbw-spacing-sm, .375rem);background:var(--tbw-filter-input-bg, var(--tbw-color-bg, transparent));color:inherit;border:1px solid var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:var(--tbw-filter-input-radius, var(--tbw-border-radius, .25rem));font-size:inherit;box-sizing:border-box}.tbw-filter-range-input:focus,.tbw-filter-date-input:focus{outline:none;border-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));box-shadow:0 0 0 2px rgba(from var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6)) r g b / 15%)}.tbw-filter-range-separator{color:var(--tbw-filter-muted, var(--tbw-color-fg-muted, light-dark(#555555, #aaaaaa)));padding-bottom:var(--tbw-spacing-xs, .25rem)}.tbw-filter-blank-option{display:flex;align-items:center;gap:var(--tbw-spacing-sm, .375rem);padding:var(--tbw-spacing-xs, .25rem) 0;margin-bottom:var(--tbw-spacing-xs, .25rem);font-size:var(--tbw-font-size-sm, .8125rem);cursor:pointer;-webkit-user-select:none;user-select:none}.tbw-filter-blank-checkbox{accent-color:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));margin:0;cursor:pointer}.tbw-filter-date-range.tbw-filter-disabled,.tbw-filter-range-inputs.tbw-filter-disabled,.tbw-filter-range-slider.tbw-filter-disabled{opacity:.4;pointer-events:none}.tbw-filter-range-slider{position:relative;height:24px;margin:var(--tbw-spacing-md, .5rem) 0 var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-filter-range-track{position:absolute;top:50%;left:0;right:0;height:4px;background:var(--tbw-filter-input-border, var(--tbw-color-border, light-dark(#d0d0d4, #454545)));border-radius:2px;transform:translateY(-50%)}.tbw-filter-range-fill{position:absolute;top:50%;height:4px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border-radius:2px;transform:translateY(-50%)}.tbw-filter-range-thumb{position:absolute;top:0;width:100%;height:100%;background:none;pointer-events:none;-webkit-appearance:none;appearance:none}.tbw-filter-range-thumb::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;width:16px;height:16px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border:2px solid var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));border-radius:50%;cursor:pointer;pointer-events:all;box-shadow:0 1px 3px #0003}.tbw-filter-range-thumb::-moz-range-thumb{width:16px;height:16px;background:var(--tbw-filter-accent, var(--tbw-color-accent, #3b82f6));border:2px solid var(--tbw-filter-panel-bg, var(--tbw-color-panel-bg, light-dark(#eeeeee, #222222)));border-radius:50%;cursor:pointer;pointer-events:all;box-shadow:0 1px 3px #0003}.tbw-filter-range-thumb::-webkit-slider-thumb:hover{transform:scale(1.1)}.tbw-filter-range-thumb::-moz-range-thumb:hover{transform:scale(1.1)}}",document.head.appendChild(e),this.globalStylesInjected=!0}toggleFilterPanel(e,t,r){if(this.openPanelField===e)return void this.closeFilterPanel();this.closeFilterPanel();const i=document.createElement("div");if(i.className="tbw-filter-panel",this.copyGridThemeContext(i),this.isAnimationEnabled&&i.classList.add("tbw-filter-panel-animated"),this.panelElement=i,this.openPanelField=e,r.classList.add("active"),this.panelButtonElement=r,this.config.valuesHandler)return i.innerHTML='<div class="tbw-filter-loading">Loading...</div>',document.body.appendChild(i),this.positionPanel(i,r),this.setupPanelCloseHandler(i,r),void this.config.valuesHandler(e,t).then(r=>{this.openPanelField===e&&this.panelElement&&(i.innerHTML="",this.renderPanelContent(e,t,i,r))});const l=n(this.getDataRows(),e,this.getFilterExtractor(t));document.body.appendChild(i),this.positionPanel(i,r),this.renderPanelContent(e,t,i,l),this.setupPanelCloseHandler(i,r)}renderPanelContent(t,r,n,i){const l=this.filters.get(t);if("in"===l?.operator&&"set"===l.type&&Array.isArray(l.value)&&!this.excludedValues.has(t)){const r=l.value,n=new Set(r.map(t=>null==t?e:t)),a=new Set(i.filter(e=>!n.has(e)));this.excludedValues.set(t,a)}let a=this.excludedValues.get(t);a||(a=/* @__PURE__ */new Set,this.excludedValues.set(t,a));const s=this.searchText.get(t)??"",o={field:t,column:r,uniqueValues:i,excludedValues:a,searchText:s,currentFilter:this.filters.get(t),applySetFilter:(e,r)=>{this.applySetFilter(t,e,r),this.closeFilterPanel()},applyTextFilter:(e,r,n)=>{this.applyTextFilter(t,e,r,n),this.closeFilterPanel()},clearFilter:()=>{this.clearFieldFilter(t),this.closeFilterPanel()},closePanel:()=>this.closeFilterPanel()};let c=!1;if(this.config.filterPanelRenderer&&(this.config.filterPanelRenderer(n,o),c=n.children.length>0),!c&&r.type){const e=this.grid.effectiveConfig.typeDefaults?.[r.type];e?.filterPanelRenderer&&(e.filterPanelRenderer(n,o),c=n.children.length>0)}if(!c){const e=r.filterType??r.type;"number"===e?function(e,t,r,n){const{field:i,column:l}=t,a=l.filterParams,s=l.editorParams,o=r.filter(e=>"number"==typeof e&&!isNaN(e)),c=o.length>0?Math.min(...o):0,d=o.length>0?Math.max(...o):100,u=E(a?.min??s?.min,c),p=E(a?.max??s?.max,d),f=a?.step??s?.step??1,h=o.length>0?Math.max(u,c):u,b=o.length>0?Math.min(p,d):p,g=n.get(i);let m=h,v=b;const w="blank"===g?.operator;"between"===g?.operator?(m=E(g.value,h),v=E(g.valueTo,b)):"greaterThanOrEqual"===g?.operator?m=E(g.value,h):"lessThanOrEqual"===g?.operator&&(v=E(g.value,b));const y=document.createElement("div");y.className="tbw-filter-range-inputs";const x=document.createElement("div");x.className="tbw-filter-range-group";const C=document.createElement("label");C.textContent="Min",C.className="tbw-filter-range-label";const k=document.createElement("input");k.type="number",k.className="tbw-filter-range-input",k.min=String(u),k.max=String(p),k.step=String(f),k.value=String(m),x.appendChild(C),x.appendChild(k),y.appendChild(x);const F=document.createElement("span");F.className="tbw-filter-range-separator",F.textContent="–",y.appendChild(F);const S=document.createElement("div");S.className="tbw-filter-range-group";const A=document.createElement("label");A.textContent="Max",A.className="tbw-filter-range-label";const N=document.createElement("input");N.type="number",N.className="tbw-filter-range-input",N.min=String(u),N.max=String(p),N.step=String(f),N.value=String(v),S.appendChild(A),S.appendChild(N),y.appendChild(S),e.appendChild(y);const T=document.createElement("div");T.className="tbw-filter-range-slider";const L=document.createElement("div");L.className="tbw-filter-range-track";const R=document.createElement("div");R.className="tbw-filter-range-fill";const P=document.createElement("input");P.type="range",P.className="tbw-filter-range-thumb tbw-filter-range-thumb-min",P.min=String(u),P.max=String(p),P.step=String(f),P.value=String(m);const M=document.createElement("input");M.type="range",M.className="tbw-filter-range-thumb tbw-filter-range-thumb-max",M.min=String(u),M.max=String(p),M.step=String(f),M.value=String(v),T.appendChild(L),T.appendChild(R),T.appendChild(P),T.appendChild(M),e.appendChild(T);const q=document.createElement("label");q.className="tbw-filter-blank-option";const V=document.createElement("input");V.type="checkbox",V.className="tbw-filter-blank-checkbox",V.checked=w;const _=document.createTextNode("Blank");q.appendChild(V),q.appendChild(_);const B=e=>{k.disabled=e,N.disabled=e,P.disabled=e,M.disabled=e,y.classList.toggle("tbw-filter-disabled",e),T.classList.toggle("tbw-filter-disabled",e)};B(w),V.addEventListener("change",()=>{B(V.checked)}),e.appendChild(q);const H=()=>{const e=parseFloat(P.value),t=parseFloat(M.value),r=p-u,n=(e-u)/r*100,i=(t-u)/r*100;R.style.left=`${n}%`,R.style.width=i-n+"%"};P.addEventListener("input",()=>{const e=Math.min(parseFloat(P.value),parseFloat(M.value));P.value=String(e),k.value=String(e),H()}),M.addEventListener("input",()=>{const e=Math.max(parseFloat(M.value),parseFloat(P.value));M.value=String(e),N.value=String(e),H()}),k.addEventListener("input",()=>{const e=parseFloat(k.value);let t=Number.isFinite(e)?e:u;t=Math.max(u,Math.min(t,parseFloat(N.value))),P.value=String(t),H()}),N.addEventListener("input",()=>{const e=parseFloat(N.value);let t=Number.isFinite(e)?e:p;t=Math.min(p,Math.max(t,parseFloat(k.value))),M.value=String(t),H()}),H();const $=document.createElement("div");$.className="tbw-filter-buttons";const I=document.createElement("button");I.type="button",I.className="tbw-filter-apply-btn",I.textContent="Apply",I.addEventListener("click",()=>{if(V.checked)return void t.applyTextFilter("blank","");const e=parseFloat(k.value),r=parseFloat(N.value),n=Number.isFinite(e)?e:h,i=Number.isFinite(r)?r:b;n!==h||i!==b?t.applyTextFilter("between",n,i):t.clearFilter()}),$.appendChild(I);const z=document.createElement("button");z.type="button",z.className="tbw-filter-clear-btn",z.textContent="Clear Filter",z.addEventListener("click",()=>{t.clearFilter()}),$.appendChild(z),e.appendChild($)}(n,o,i,this.filters):"date"===e?function(e,t,r,n){const{field:i,column:l}=t,a=l.filterParams,s=l.editorParams,o=r.filter(e=>e instanceof Date||"string"==typeof e&&!isNaN(Date.parse(e))).map(e=>e instanceof Date?e:new Date(e)).filter(e=>!isNaN(e.getTime())),c=o.length>0?new Date(Math.min(...o.map(e=>e.getTime()))):null,d=o.length>0?new Date(Math.max(...o.map(e=>e.getTime()))):null,u=w(a?.min)||w(s?.min)||v(c),p=w(a?.max)||w(s?.max)||v(d),f=v(c)||w(a?.min)||w(s?.min),h=v(d)||w(a?.max)||w(s?.max),b=n.get(i);let g=f,m=h;const y="blank"===b?.operator;"between"===b?.operator?(g=w(b.value)||f,m=w(b.valueTo)||h):"greaterThanOrEqual"===b?.operator?g=w(b.value)||f:"lessThanOrEqual"===b?.operator&&(m=w(b.value)||h);const x=document.createElement("div");x.className="tbw-filter-date-range";const C=document.createElement("div");C.className="tbw-filter-date-group";const E=document.createElement("label");E.textContent="From",E.className="tbw-filter-range-label";const k=document.createElement("input");k.type="date",k.className="tbw-filter-date-input",u&&(k.min=u),p&&(k.max=p),k.value=g,C.appendChild(E),C.appendChild(k),x.appendChild(C);const F=document.createElement("span");F.className="tbw-filter-range-separator",F.textContent="–",x.appendChild(F);const S=document.createElement("div");S.className="tbw-filter-date-group";const A=document.createElement("label");A.textContent="To",A.className="tbw-filter-range-label";const N=document.createElement("input");N.type="date",N.className="tbw-filter-date-input",u&&(N.min=u),p&&(N.max=p),N.value=m,S.appendChild(A),S.appendChild(N),x.appendChild(S),e.appendChild(x);const T=document.createElement("label");T.className="tbw-filter-blank-option";const L=document.createElement("input");L.type="checkbox",L.className="tbw-filter-blank-checkbox",L.checked=y;const R=document.createTextNode("Show only blank");T.appendChild(L),T.appendChild(R);const P=e=>{k.disabled=e,N.disabled=e,x.classList.toggle("tbw-filter-disabled",e)};P(y),L.addEventListener("change",()=>{P(L.checked)}),e.appendChild(T);const M=document.createElement("div");M.className="tbw-filter-buttons";const q=document.createElement("button");q.type="button",q.className="tbw-filter-apply-btn",q.textContent="Apply",q.addEventListener("click",()=>{if(L.checked)return void t.applyTextFilter("blank","");const e=k.value,r=N.value,n=e&&e!==f?e:"",i=r&&r!==h?r:"";n&&i?t.applyTextFilter("between",n,i):n?t.applyTextFilter("greaterThanOrEqual",n):i?t.applyTextFilter("lessThanOrEqual",i):t.clearFilter()}),M.appendChild(q);const V=document.createElement("button");V.type="button",V.className="tbw-filter-clear-btn",V.textContent="Clear Filter",V.addEventListener("click",()=>{t.clearFilter()}),M.appendChild(V),e.appendChild(M)}(n,o,i,this.filters):C(n,o,i,a,{caseSensitive:this.config.caseSensitive,debounceMs:this.config.debounceMs},this.searchText)}}setupPanelCloseHandler(e,t){this.panelAbortController=new AbortController;const{signal:r}=this.panelAbortController;setTimeout(()=>{r.aborted||document.addEventListener("click",r=>{e.contains(r.target)||r.target===t||this.closeFilterPanel()},{signal:r})},0)}closeFilterPanel(){const e=this.panelElement;if(e&&(e.remove(),this.panelElement=null),this.panelAnchorElement&&(this.panelAnchorElement.style.anchorName="",this.panelAnchorElement=null),this.panelButtonElement){const e=this.openPanelField;e&&this.filters.has(e)||this.panelButtonElement.classList.remove("active"),this.panelButtonElement=null}this.openPanelField=null,this.panelAbortController?.abort(),this.panelAbortController=null}static supportsAnchorPositioning=null;static checkAnchorPositioningSupport(){return null===k.supportsAnchorPositioning&&(k.supportsAnchorPositioning=CSS.supports("anchor-name","--test")),k.supportsAnchorPositioning}positionPanel(e,t){const r=t.closest(".header-row")??t;if(r.style.anchorName="--tbw-filter-anchor",this.panelAnchorElement=r,k.checkAnchorPositioningSupport()){r.style.anchorName="",t.style.anchorName="--tbw-filter-anchor",this.panelAnchorElement=t;const n=r.getBoundingClientRect().bottom-t.getBoundingClientRect().bottom;return e.style.marginTop=`${n+4}px`,void requestAnimationFrame(()=>{const r=e.getBoundingClientRect(),n=t.getBoundingClientRect();r.top<n.top&&e.classList.add("tbw-filter-panel-above")})}const n=r.getBoundingClientRect(),i=t.getBoundingClientRect();e.style.position="fixed",e.style.top=`${n.bottom+4}px`,e.style.left=`${i.right}px`,requestAnimationFrame(()=>{const t=e.getBoundingClientRect();e.style.left=i.right-t.width+"px";i.right-t.width<8&&(e.style.left=`${i.left}px`),t.bottom>window.innerHeight-8&&(e.style.top=n.top-t.height-4+"px",e.classList.add("tbw-filter-panel-above"))})}applySetFilter(e,t,r){if(this.excludedValues.set(e,new Set(t)),0===t.length)this.filters.delete(e);else{const n=this.filters.get(e);if("in"===n?.operator){const n=this.getUniqueValues(e),i=new Set(t),l=n.filter(e=>!i.has(e));this.filters.set(e,{field:e,type:"set",operator:"in",value:l,...void 0!==r&&{valueTo:r}})}else this.filters.set(e,{field:e,type:"set",operator:"notIn",value:t,...void 0!==r&&{valueTo:r}})}this.applyFiltersInternal()}applyTextFilter(e,t,r,n){const i=this.getColumnByField(e),l=i?.filterType??i?.type??"text";this.filters.set(e,{field:e,type:l,operator:t,value:r,valueTo:n}),this.applyFiltersInternal()}applyFiltersInternal(e){this.invalidateCache();const t=[...this.filters.values()];if(this.config.filterHandler){this.gridElement.setAttribute("aria-busy","true");const r=this.config.filterHandler(t,this.sourceRows),n=r=>{this.gridElement.removeAttribute("aria-busy"),this.cachedResult=r,this.grid.rows=r,this.notifyFilterChange(t,r.length,e),this.requestRender()};return void(r&&"function"==typeof r.then?r.then(n):n(r))}this.notifyFilterChange(t,0,e),this.requestRender()}getColumnState(e){if(!this.config.trackColumnState)return;const t=this.filters.get(e);return t?{filter:{type:t.type,operator:t.operator,value:t.value,valueTo:t.valueTo}}:void 0}applyColumnState(e,t){if(!this.config.trackColumnState)return;if(!t.filter)return void this.filters.delete(e);const r={field:e,type:t.filter.type,operator:t.filter.operator,value:t.filter.value,valueTo:t.filter.valueTo};this.filters.set(e,r),this.invalidateCache()}}export{e as BLANK_FILTER_VALUE,k as FilteringPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function t(t,r,o,n){return`${e(o,n)} ${t}: ${r}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(t)}`}const 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(""));new RegExp(`__(proto|defineGetter|defineSetter)|${r.slice(3).join("|")}|this\\b`);const o=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("|")),n=/^on\w+$/i,i=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){if(Array.from(l.attributes).some(e=>n.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();n.test(e)?r.push(t.name):(i.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}const d={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};class c{static dependencies;static manifest;aliases;version="2.17.1";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 n of e){const e=n.userConfig;for(const[i,s]of Object.entries(e)){if(void 0===s)continue;if(!(i in r)){r[i]=s,o[i]=n;continue}if(r[i]===s)continue;const e=o[i]?.constructor.name??this.constructor.name,l=n.constructor.name,d=t("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(d)}}Object.assign(this.userConfig,r)}refreshUserConfigFrom(e){const t=this.userConfig;for(const r of Object.keys(t))delete t[r];Object.assign(t,e.userConfig)}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;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),r=parseInt(t,10);if(!isNaN(r))return r}return 200}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,n){throw new Error(t(e,r,o,n))}("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 n=[],i=0;return e.forEach((e,s)=>{const l=e.group;if(!l)return 0===n.length&&(i=s),void n.push(e);n.length&&(o(i,n.slice()),n=[]);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})}),n.length&&o(i,n),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 n=null;for(let t=r+1;t<e.length;t++)if(!String(e[t].id).startsWith("__implicit__")){n=e[t].id;break}o&&n&&o===n&&t.add(String(e[r].id))}return t}(e),r=function(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}(e,t);return{merged:r,embedded:t}}function f(e,t){const r=e.columns[0],o=e.columns[e.columns.length-1],n=r?t.findIndex(e=>e.field===r.field):-1,i=o?t.findIndex(e=>e.field===o.field):-1;return-1!==n&&-1!==i?[n,i]:null}class h 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{display:grid;grid-auto-flow:column;background:var(--tbw-grouping-columns-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-grouping-columns-border, var(--tbw-color-border))}.header-group-cell{display:flex;align-items:center;justify-content:center;padding:var(--tbw-button-padding-sm, .25rem .5rem);font-weight:600;font-size:var(--tbw-font-size-sm, .9em);text-transform:uppercase;letter-spacing:.5px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-group-cell:last-child{border-right:none}.header-row .cell.grouped{border-top:none}.header-row .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-row .cell.group-end:last-child{border-right:none}.rows .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.rows .cell.group-end:last-child{border-right:none}.header-group-row.no-borders{border-bottom:none}.header-group-row.no-borders .header-group-cell{border-right:none}.header-row.no-group-borders .cell.group-end{border-right:1px solid var(--tbw-color-border)}}";get defaultConfig(){return{showGroupBorders:!0,lockGroupOrder:!1}}groups=[];isActive=!1;#r=/* @__PURE__ */new Set;#o=[];#n=/* @__PURE__ */new Map;attach(e){super.attach(e),this.gridElement.addEventListener("column-move",this.#i,{signal:this.disconnectSignal})}detach(){this.groups=[],this.isActive=!1,this.#r.clear(),this.#o=[],this.#n.clear()}#i=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[,n]of e)if(!this.#s(n,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),n=[];for(const i of o){const e=String(i.id).startsWith("__implicit__"),r=i.columns[0],o=i.columns[i.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;n.push({label:e?"":i.label??i.id,span:d,source:this.name})}if(0===n.length)return;return n.reduce((e,t)=>e+t.span,0)!==t.length?{cells:[{label:"",span:t.length,source:this.name}]}:{cells:n}}#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,n=e.find(e=>e.id===t);n?n.fields.includes(o.field)||n.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,n=r.get(t);n?n.fields.includes(e.field)||n.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,n;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.#n.clear();for(const e of t)e.renderer&&this.#n.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});n=e.map(e=>{const t=r.get(e.field);return t&&!e.group?{...e,group:t}:e})}else this.#o=[],this.#n.clear(),n=[...e];const i=a(n);if(0===i.length)return this.isActive=!1,this.groups=[],n;if(this.#n.size>0)for(const s of i){const e=this.#n.get(s.id);e&&(s.renderer=e)}this.isActive=!0,this.groups=i,this.#r.clear();for(const s of i){const e=s.columns[s.columns.length-1];e?.field&&this.#r.add(e.field)}return n}afterRender(){if(!this.isActive){const e=this.gridElement?.querySelector(".header"),t=e?.querySelector(".header-group-row");return void(t&&t.remove())}const e=this.gridElement?.querySelector(".header");if(!e)return;const t=e.querySelector(".header-group-row");t&&t.remove();const r=this.visibleColumns,o=a(r);if(0===o.length)return;if(this.#n.size>0)for(const l of o){const e=this.#n.get(l.id);e&&(l.renderer=e)}this.#r.clear();const n=g(o);for(let l=0;l<n.merged.length;l++){const e=n.merged[l],t=e.columns[e.columns.length-1];t?.field&&l<n.merged.length-1&&this.#r.add(t.field)}const i=function(e,t,r,o){if(0===e.length)return null;const n=document.createElement("div");n.className="header-group-row",n.setAttribute("role","row");const{merged:i}=o??g(e);for(const s of i){const e=String(s.id),o=e.startsWith("__implicit__"),i=f(s,t);if(!i)continue;const[d,c]=i,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;n.appendChild(g)}return n}(o,r,this.config.groupHeaderRenderer,n);if(i){i.classList.toggle("no-borders",!this.config.showGroupBorders);const t=e.querySelector(".header-row");t?e.insertBefore(i,t):e.appendChild(i)}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:n,embedded:i}=o??g(t),s=/* @__PURE__ */new Map;for(const d of n)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__")&&i.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 n){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,n))}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{h as GroupingColumnsPlugin};
|
|
1
|
+
function e(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function t(t,r,o,n){return`${e(o,n)} ${t}: ${r}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(t)}`}const 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(""));new RegExp(`__(proto|defineGetter|defineSetter)|${r.slice(3).join("|")}|this\\b`);const o=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("|")),n=/^on\w+$/i,i=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){if(Array.from(l.attributes).some(e=>n.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();n.test(e)?r.push(t.name):(i.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}const d={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};class c{static dependencies;static manifest;aliases;version="2.17.2";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 n of e){const e=n.userConfig;for(const[i,s]of Object.entries(e)){if(void 0===s)continue;if(!(i in r)){r[i]=s,o[i]=n;continue}if(r[i]===s)continue;const e=o[i]?.constructor.name??this.constructor.name,l=n.constructor.name,d=t("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(d)}}Object.assign(this.userConfig,r)}refreshUserConfigFrom(e){const t=this.userConfig;for(const r of Object.keys(t))delete t[r];Object.assign(t,e.userConfig)}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;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),r=parseInt(t,10);if(!isNaN(r))return r}return 200}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,n){throw new Error(t(e,r,o,n))}("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 n=[],i=0;return e.forEach((e,s)=>{const l=e.group;if(!l)return 0===n.length&&(i=s),void n.push(e);n.length&&(o(i,n.slice()),n=[]);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})}),n.length&&o(i,n),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 n=null;for(let t=r+1;t<e.length;t++)if(!String(e[t].id).startsWith("__implicit__")){n=e[t].id;break}o&&n&&o===n&&t.add(String(e[r].id))}return t}(e),r=function(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}(e,t);return{merged:r,embedded:t}}function f(e,t){const r=e.columns[0],o=e.columns[e.columns.length-1],n=r?t.findIndex(e=>e.field===r.field):-1,i=o?t.findIndex(e=>e.field===o.field):-1;return-1!==n&&-1!==i?[n,i]:null}class h 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{display:grid;grid-auto-flow:column;background:var(--tbw-grouping-columns-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-grouping-columns-border, var(--tbw-color-border))}.header-group-cell{display:flex;align-items:center;justify-content:center;padding:var(--tbw-button-padding-sm, .25rem .5rem);font-weight:600;font-size:var(--tbw-font-size-sm, .9em);text-transform:uppercase;letter-spacing:.5px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-group-cell:last-child{border-right:none}.header-row .cell.grouped{border-top:none}.header-row .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-row .cell.group-end:last-child{border-right:none}.rows .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.rows .cell.group-end:last-child{border-right:none}.header-group-row.no-borders{border-bottom:none}.header-group-row.no-borders .header-group-cell{border-right:none}.header-row.no-group-borders .cell.group-end{border-right:1px solid var(--tbw-color-border)}}";get defaultConfig(){return{showGroupBorders:!0,lockGroupOrder:!1}}groups=[];isActive=!1;#r=/* @__PURE__ */new Set;#o=[];#n=/* @__PURE__ */new Map;attach(e){super.attach(e),this.gridElement.addEventListener("column-move",this.#i,{signal:this.disconnectSignal})}detach(){this.groups=[],this.isActive=!1,this.#r.clear(),this.#o=[],this.#n.clear()}#i=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[,n]of e)if(!this.#s(n,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),n=[];for(const i of o){const e=String(i.id).startsWith("__implicit__"),r=i.columns[0],o=i.columns[i.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;n.push({label:e?"":i.label??i.id,span:d,source:this.name})}if(0===n.length)return;return n.reduce((e,t)=>e+t.span,0)!==t.length?{cells:[{label:"",span:t.length,source:this.name}]}:{cells:n}}#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,n=e.find(e=>e.id===t);n?n.fields.includes(o.field)||n.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,n=r.get(t);n?n.fields.includes(e.field)||n.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,n;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.#n.clear();for(const e of t)e.renderer&&this.#n.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});n=e.map(e=>{const t=r.get(e.field);return t&&!e.group?{...e,group:t}:e})}else this.#o=[],this.#n.clear(),n=[...e];const i=a(n);if(0===i.length)return this.isActive=!1,this.groups=[],n;if(this.#n.size>0)for(const s of i){const e=this.#n.get(s.id);e&&(s.renderer=e)}this.isActive=!0,this.groups=i,this.#r.clear();for(const s of i){const e=s.columns[s.columns.length-1];e?.field&&this.#r.add(e.field)}return n}afterRender(){if(!this.isActive){const e=this.gridElement?.querySelector(".header"),t=e?.querySelector(".header-group-row");return void(t&&t.remove())}const e=this.gridElement?.querySelector(".header");if(!e)return;const t=e.querySelector(".header-group-row");t&&t.remove();const r=this.visibleColumns,o=a(r);if(0===o.length)return;if(this.#n.size>0)for(const l of o){const e=this.#n.get(l.id);e&&(l.renderer=e)}this.#r.clear();const n=g(o);for(let l=0;l<n.merged.length;l++){const e=n.merged[l],t=e.columns[e.columns.length-1];t?.field&&l<n.merged.length-1&&this.#r.add(t.field)}const i=function(e,t,r,o){if(0===e.length)return null;const n=document.createElement("div");n.className="header-group-row",n.setAttribute("role","row");const{merged:i}=o??g(e);for(const s of i){const e=String(s.id),o=e.startsWith("__implicit__"),i=f(s,t);if(!i)continue;const[d,c]=i,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;n.appendChild(g)}return n}(o,r,this.config.groupHeaderRenderer,n);if(i){i.classList.toggle("no-borders",!this.config.showGroupBorders);const t=e.querySelector(".header-row");t?e.insertBefore(i,t):e.appendChild(i)}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:n,embedded:i}=o??g(t),s=/* @__PURE__ */new Map;for(const d of n)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__")&&i.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 n){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,n))}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{h as GroupingColumnsPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const 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)}const 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 c(e,t){if(!e)return;const r="effectiveConfig"in e?e.effectiveConfig:void 0;if(!1===r?.a11y?.announcements)return;const o=e.querySelector?.(".tbw-sr-only");o&&(o.textContent="",requestAnimationFrame(()=>{o.textContent=t}))}function g(e,t,...r){const o=e&&"effectiveConfig"in e?e.effectiveConfig:void 0,n=o?.a11y?.messages?.[t];return n?n(...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)}`}const 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(""));new RegExp(`__(proto|defineGetter|defineSetter)|${w.slice(3).join("|")}|this\\b`);const m=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,b=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),v=/^\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){if(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):(b.has(e)&&v.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}class _{static dependencies;static manifest;aliases;version="2.17.
|
|
1
|
+
const 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)}const 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 c(e,t){if(!e)return;const r="effectiveConfig"in e?e.effectiveConfig:void 0;if(!1===r?.a11y?.announcements)return;const o=e.querySelector?.(".tbw-sr-only");o&&(o.textContent="",requestAnimationFrame(()=>{o.textContent=t}))}function g(e,t,...r){const o=e&&"effectiveConfig"in e?e.effectiveConfig:void 0,n=o?.a11y?.messages?.[t];return n?n(...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)}`}const 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(""));new RegExp(`__(proto|defineGetter|defineSetter)|${w.slice(3).join("|")}|this\\b`);const m=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,b=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),v=/^\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){if(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):(b.has(e)&&v.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}class _{static dependencies;static manifest;aliases;version="2.17.2";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;for(const r of Object.keys(t))delete t[r];Object.assign(t,e.userConfig)}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;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),r=parseInt(t,10);if(!isNaN(r))return r}return 200}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__")){if(s.children.get("__ungrouped__").rows.length===e.length)return[]}const a=/* @__PURE__ */new Map;for(let c=0;c<e.length;c++)a.set(e[c],c);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__ */
|
|
2
2
|
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[]}class S 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{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-grouping-rows-bg, var(--tbw-color-panel-bg));font-weight:500;border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height)}.group-row .cell{display:flex;align-items:center;padding:var(--tbw-cell-padding, .125rem .5rem)}@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;display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-toggle-size, 1.25rem);height:var(--tbw-toggle-size, 1.25rem);margin-right:.25rem;background:none;border:0;font:inherit}.group-toggle:hover{background:var(--tbw-grouping-rows-toggle-hover, var(--tbw-color-row-hover));border-radius:var(--tbw-border-radius, .125rem)}.group-label{display:inline-flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.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{display:inline-flex;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))}.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(){const e=this.gridElement?.querySelector(".rows-body");e?.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){const t=e.context;if(!0===t?.__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){const o=e.originalEvent.target;if(o?.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){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)}}(t),!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];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="";return!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=this.flattenedRows[t],i="data"===r?.kind?`data-${t}`:void 0;i&&this.keysToAnimate.has(i)&&(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),o=r?.rowCount??t.rows.length;return{__isGroupRow:!0,__groupKey:t.key,__groupValue:t.value,__groupDepth:t.depth,__groupRows:t.rows,__groupExpanded:t.expanded,__groupRowCount:o,__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);const i=o?.header??t;r.textContent=`${i}: ${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"),u=d?.style.gridTemplateColumns||"";u&&(t.style.display="grid",t.style.gridTemplateColumns=u);let p=!1;s.forEach((s,d)=>{const u=document.createElement("div");if(u.className="cell group-cell",u.setAttribute("data-col",String(d)),u.setAttribute("role","gridcell"),"__tbw_expander"===s.field)return u.setAttribute("data-field",s.field),void t.appendChild(u);if(p){const e=i[s.field];if(e){const t=l.run(e,a,s.field,s);u.textContent=null!=t?String(t):""}else u.textContent=""}else{p=!0,u.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(u.appendChild(t),!1!==n.showRowCount){const e=document.createElement("span");e.className=o,e.textContent=` (${a.length})`,u.appendChild(e)}}t.appendChild(u)})}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;c(this.gridElement,g(this.gridElement,"groupExpanded",s,e))}else c(this.gridElement,g(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};
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const 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){if(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}return"row"===e?t.row: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=n.replace(e,(e,n)=>{const a=function(e,n){if(e=(e||"").trim(),!e)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.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=(d=a)?d.replace(new RegExp(t,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):d;var d;const u=o.length&&o.every(e=>""===e.result||e.result===t);return h.test(n)||u?"":l}const 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)}`}const p={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};class m{static dependencies;static manifest;aliases;version="2.17.1";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;for(const i of Object.keys(t))delete t[i];Object.assign(t,e.userConfig)}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;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),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))}}const 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}class R extends m{name="masterDetail";styles="@layer tbw-plugins{tbw-grid .cell[data-field=__tbw_expander]{border-right:none!important;padding:0;display:flex;align-items:center;justify-content:center}tbw-grid .header-row .cell[data-field=__tbw_expander]{display:none}tbw-grid .master-detail-expander{display:flex;align-items:center;justify-content:center;width:100%;height:100%}tbw-grid .master-detail-toggle{cursor:pointer;opacity:.7;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center}tbw-grid .master-detail-toggle:hover{opacity:1}tbw-grid .master-detail-row{grid-column:1 / -1;display:grid;background:var(--tbw-master-detail-bg, var(--tbw-color-row-alt));border-bottom:1px solid var(--tbw-master-detail-border, var(--tbw-color-border));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(e){const t=this.detailElements.get(e);if(t){if(!(t.classList.contains("tbw-expanding")||t.classList.contains("tbw-collapsing"))){const i=t.offsetHeight;if(i>0)return this.measuredDetailHeights.set(e,i),i}}const i=this.measuredDetailHeights.get(e);return i&&i>0?i:"number"==typeof this.config?.detailHeight?this.config.detailHeight:R.DEFAULT_DETAIL_HEIGHT}toggleAndEmit(e,t){if(e?.__isGroupRow)return;this.expandedRows=v(this.expandedRows,e);const i=this.expandedRows.has(e);if(i){if(this.rowsToAnimate.add(e),!this.detailDataMap.has(e)){const i=this.grid?.query?.("datasource:is-active",null);i&&(this.loadingDetails.add(e),this.grid.query("datasource:fetch-children",{context:{source:"master-detail",row:e,rowIndex:t}}))}}else 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],i=function(e){return e.find(b)}(t);if(i)return t;const n=(r=this.name,{field:w,header:"",width:32,resizable:!1,sortable:!1,filterable:!1,lockPosition:!0,utility:!0,meta:{expanderColumn:!0,expanderPlugin:r}});var r;return n.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},[n,...t]}onRowClick(e){if(this.config.expandOnRowClick&&this.config.detailRenderer)return this.toggleAndEmit(e.row,e.rowIndex),!1}onCellClick(e){const t=e.originalEvent?.target;if(t?.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"),i=t?.firstElementChild;i&&e.unmount(i)}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;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);if(i<0||i>=e)continue;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{R as MasterDetailPlugin};
|
|
1
|
+
const 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){if(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}return"row"===e?t.row: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=n.replace(e,(e,n)=>{const a=function(e,n){if(e=(e||"").trim(),!e)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.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=(d=a)?d.replace(new RegExp(t,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):d;var d;const u=o.length&&o.every(e=>""===e.result||e.result===t);return h.test(n)||u?"":l}const 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)}`}const p={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};class m{static dependencies;static manifest;aliases;version="2.17.2";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;for(const i of Object.keys(t))delete t[i];Object.assign(t,e.userConfig)}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;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),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))}}const 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}class R extends m{name="masterDetail";styles="@layer tbw-plugins{tbw-grid .cell[data-field=__tbw_expander]{border-right:none!important;padding:0;display:flex;align-items:center;justify-content:center}tbw-grid .header-row .cell[data-field=__tbw_expander]{display:none}tbw-grid .master-detail-expander{display:flex;align-items:center;justify-content:center;width:100%;height:100%}tbw-grid .master-detail-toggle{cursor:pointer;opacity:.7;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center}tbw-grid .master-detail-toggle:hover{opacity:1}tbw-grid .master-detail-row{grid-column:1 / -1;display:grid;background:var(--tbw-master-detail-bg, var(--tbw-color-row-alt));border-bottom:1px solid var(--tbw-master-detail-border, var(--tbw-color-border));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(e){const t=this.detailElements.get(e);if(t){if(!(t.classList.contains("tbw-expanding")||t.classList.contains("tbw-collapsing"))){const i=t.offsetHeight;if(i>0)return this.measuredDetailHeights.set(e,i),i}}const i=this.measuredDetailHeights.get(e);return i&&i>0?i:"number"==typeof this.config?.detailHeight?this.config.detailHeight:R.DEFAULT_DETAIL_HEIGHT}toggleAndEmit(e,t){if(e?.__isGroupRow)return;this.expandedRows=v(this.expandedRows,e);const i=this.expandedRows.has(e);if(i){if(this.rowsToAnimate.add(e),!this.detailDataMap.has(e)){const i=this.grid?.query?.("datasource:is-active",null);i&&(this.loadingDetails.add(e),this.grid.query("datasource:fetch-children",{context:{source:"master-detail",row:e,rowIndex:t}}))}}else 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],i=function(e){return e.find(b)}(t);if(i)return t;const n=(r=this.name,{field:w,header:"",width:32,resizable:!1,sortable:!1,filterable:!1,lockPosition:!0,utility:!0,meta:{expanderColumn:!0,expanderPlugin:r}});var r;return n.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},[n,...t]}onRowClick(e){if(this.config.expandOnRowClick&&this.config.detailRenderer)return this.toggleAndEmit(e.row,e.rowIndex),!1}onCellClick(e){const t=e.originalEvent?.target;if(t?.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"),i=t?.firstElementChild;i&&e.unmount(i)}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;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);if(i<0||i>=e)continue;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{R as MasterDetailPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|