@toolbox-web/grid 3.0.0-beta.4 → 3.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/all.js +1 -1
  2. package/all.js.map +1 -1
  3. package/index.js +1 -1
  4. package/index.js.map +1 -1
  5. package/lib/features/registry.js +1 -1
  6. package/lib/features/registry.js.map +1 -1
  7. package/lib/plugins/clipboard/index.js +1 -1
  8. package/lib/plugins/clipboard/index.js.map +1 -1
  9. package/lib/plugins/column-virtualization/index.js +1 -1
  10. package/lib/plugins/column-virtualization/index.js.map +1 -1
  11. package/lib/plugins/context-menu/index.js +1 -1
  12. package/lib/plugins/context-menu/index.js.map +1 -1
  13. package/lib/plugins/editing/index.js +1 -1
  14. package/lib/plugins/editing/index.js.map +1 -1
  15. package/lib/plugins/export/index.js +1 -1
  16. package/lib/plugins/export/index.js.map +1 -1
  17. package/lib/plugins/filtering/index.js +1 -1
  18. package/lib/plugins/filtering/index.js.map +1 -1
  19. package/lib/plugins/grouping-columns/index.js +1 -1
  20. package/lib/plugins/grouping-columns/index.js.map +1 -1
  21. package/lib/plugins/grouping-rows/index.js +1 -1
  22. package/lib/plugins/grouping-rows/index.js.map +1 -1
  23. package/lib/plugins/master-detail/index.js +1 -1
  24. package/lib/plugins/master-detail/index.js.map +1 -1
  25. package/lib/plugins/multi-sort/index.js +1 -1
  26. package/lib/plugins/multi-sort/index.js.map +1 -1
  27. package/lib/plugins/pinned-columns/index.js +1 -1
  28. package/lib/plugins/pinned-columns/index.js.map +1 -1
  29. package/lib/plugins/pinned-rows/index.js +1 -1
  30. package/lib/plugins/pinned-rows/index.js.map +1 -1
  31. package/lib/plugins/pivot/index.js +1 -1
  32. package/lib/plugins/pivot/index.js.map +1 -1
  33. package/lib/plugins/print/index.js +1 -1
  34. package/lib/plugins/print/index.js.map +1 -1
  35. package/lib/plugins/reorder-columns/index.js +1 -1
  36. package/lib/plugins/reorder-columns/index.js.map +1 -1
  37. package/lib/plugins/responsive/index.js +1 -1
  38. package/lib/plugins/responsive/index.js.map +1 -1
  39. package/lib/plugins/row-drag-drop/index.js +1 -1
  40. package/lib/plugins/row-drag-drop/index.js.map +1 -1
  41. package/lib/plugins/selection/index.js +1 -1
  42. package/lib/plugins/selection/index.js.map +1 -1
  43. package/lib/plugins/server-side/index.js +1 -1
  44. package/lib/plugins/server-side/index.js.map +1 -1
  45. package/lib/plugins/shell/index.js +1 -1
  46. package/lib/plugins/shell/index.js.map +1 -1
  47. package/lib/plugins/sticky-rows/index.js +1 -1
  48. package/lib/plugins/sticky-rows/index.js.map +1 -1
  49. package/lib/plugins/tooltip/index.js +1 -1
  50. package/lib/plugins/tooltip/index.js.map +1 -1
  51. package/lib/plugins/tree/index.js +1 -1
  52. package/lib/plugins/tree/index.js.map +1 -1
  53. package/lib/plugins/undo-redo/index.js +1 -1
  54. package/lib/plugins/undo-redo/index.js.map +1 -1
  55. package/lib/plugins/visibility/index.js +1 -1
  56. package/lib/plugins/visibility/index.js.map +1 -1
  57. package/package.json +1 -1
  58. package/umd/grid.all.umd.js +1 -1
  59. package/umd/grid.all.umd.js.map +1 -1
  60. package/umd/grid.umd.js +1 -1
  61. package/umd/grid.umd.js.map +1 -1
  62. package/umd/plugins/selection.umd.js +1 -1
  63. package/umd/plugins/selection.umd.js.map +1 -1
package/umd/grid.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGrid={})}(this,function(e){"use strict";const t={STRETCH:"stretch",FIXED:"fixed"},r={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`},i={mode:"reduced-motion",duration:200,easing:"ease-out"},o={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function n(e,t){if(!e)return;const r="effectiveConfig"in e?e.effectiveConfig:void 0;if(!1===r?.a11y?.announcements)return;const i=e.querySelector?.(".tbw-sr-only");i&&(i.textContent="",requestAnimationFrame(()=>{i.textContent=t}))}function s(e,t,...i){const o=e&&"effectiveConfig"in e?e.effectiveConfig:void 0,n=o?.a11y?.messages?.[t];return n?n(...i):r[t](...i)}function a(e){return e.charAt(0).toUpperCase()+e.slice(1)}function l(e){if("id"===e.toLowerCase())return"ID";return e.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[_-]/g," ").split(" ").filter(Boolean).map(a).join(" ")}const c=new Set(["string","number","boolean","date","datetime","currency"]);function d(e){const t=e.lastIndexOf(":");if(t>0){const r=e.slice(t+1).toLowerCase();if(c.has(r)){const i=e.slice(0,t);return{field:i,header:l(i),type:r}}}return{field:e,header:l(e)}}function u(e){return e.map(e=>"string"==typeof e?d(e):e)}function h(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}const g="TBW021",f="TBW041",p="TBW061",w="TBW062";function m(e,t,r,i){return`${h(r,i)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}function b(e,t,r,i){throw new Error(m(e,t,r,i))}function v(e,t,r,i){console.warn(m(e,t,r,i))}function y(e,t,r,i){console.debug(m(e,t,r,i))}function _(e,t,r,i){console.error(m(e,t,r,i))}function C(e,t){if(!(e&&e.length||t&&t.length))return[];if(!e||!e.length)return t||[];if(!t||!t.length)return e;const r={},i=t;for(let s=0;s<i.length;s++){const e=i[s],t=r[e.field];if(t){e.header&&!t.header&&(t.header=e.header),e.type&&!t.type&&(t.type=e.type),e.sortable&&(t.sortable=!0),e.resizable&&(t.resizable=!0),null!=e.width&&null==t.width&&(t.width=e.width),null!=e.minWidth&&null==t.minWidth&&(t.minWidth=e.minWidth),e.__viewTemplate&&(t.__viewTemplate=e.__viewTemplate),e.__headerTemplate&&(t.__headerTemplate=e.__headerTemplate),e.__element&&!t.__element&&(t.__element=e.__element);const r=e.renderer||e.viewRenderer,i=t.renderer||t.viewRenderer;r&&!i&&(t.viewRenderer=r,e.renderer&&(t.renderer=r)),e.editor&&!t.editor&&(t.editor=e.editor),e.headerRenderer&&!t.headerRenderer&&(t.headerRenderer=e.headerRenderer),e.headerLabelRenderer&&!t.headerLabelRenderer&&(t.headerLabelRenderer=e.headerLabelRenderer)}else r[e.field]={...e}}const o=e.map(e=>{const t=r[e.field];if(!t)return e;const i={...e};t.header&&!i.header&&(i.header=t.header),t.type&&!i.type&&(i.type=t.type),i.sortable=e.sortable||t.sortable,!0!==e.resizable&&!0!==t.resizable||(i.resizable=!0),null!=t.width&&null==i.width&&(i.width=t.width),null!=t.minWidth&&null==i.minWidth&&(i.minWidth=t.minWidth),t.__viewTemplate&&(i.__viewTemplate=t.__viewTemplate),t.__headerTemplate&&(i.__headerTemplate=t.__headerTemplate),t.__element&&!i.__element&&(i.__element=t.__element);const o=t.renderer||t.viewRenderer,n=i.renderer||i.viewRenderer;return o&&!n&&(i.viewRenderer=o,t.renderer&&(i.renderer=o)),t.editor&&!i.editor&&(i.editor=t.editor),i.headerRenderer||i.headerLabelRenderer||(t.headerRenderer?i.headerRenderer=t.headerRenderer:t.headerLabelRenderer&&(i.headerLabelRenderer=t.headerLabelRenderer)),delete r[e.field],i}),n=Object.keys(r);for(let s=0;s<n.length;s++)o.push(r[n[s]]);return o}function R(e,t){try{e.part?.add?.(t)}catch{}const r=e.getAttribute("part");r?r.split(/\s+/).includes(t)||e.setAttribute("part",r+" "+t):e.setAttribute("part",t)}function E(e){const r=e.effectiveConfig?.fitMode||e.fitMode||t.STRETCH;if(r!==t.STRETCH&&r!==t.FIXED)return;if(e.__didInitialAutoSize)return;if(!e.isConnected)return;const i=Array.from(e._headerRowEl?.children||[]);if(!i.length)return;let o=!1;const n=e._visibleColumns;for(let t=0;t<n.length;t++){const r=n[t];if(r.width)continue;const s=i[t];let a=s?s.scrollWidth:0;for(let i=0;i<e._rowPool.length;i++){const r=e._rowPool[i].children[t];if(r){const e=r.scrollWidth;e>a&&(a=e)}}a>0&&(r.width=a+2,r.__autoSized=!0,o=!0)}o&&M(e),e.__didInitialAutoSize=!0}const S=/^(?:\d+(?:\.\d+)?(?:px|%|fr|em|rem|ch|vw|vh|vmin|vmax)|calc\(.+\)|min-content|max-content|minmax\(.+\)|fit-content\(.+\)|auto)$/i;function A(e,t){return"number"==typeof e?`${e}px`:(S.test(e)||v("TBW050",`Column '${t??"?"}' has an invalid CSS width value: '${e}'. Expected a number (px) or a valid CSS unit string (e.g. '30%', '2fr', 'calc(...)').`),e)}function M(e){const r=e.effectiveConfig?.fitMode||e.fitMode||t.STRETCH;e._gridTemplate=r===t.STRETCH?e._visibleColumns.map(e=>{if(null!=e.width)return A(e.width,e.field);const t=e.minWidth;return null!=t?`minmax(${t}px, 1fr)`:"1fr"}).join(" ").trim():e._visibleColumns.map(e=>null!=e.width?A(e.width,e.field):"max-content").join(" "),e.style.setProperty("--tbw-column-template",e._gridTemplate)}const x='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])',H={ROOT:"tbw-grid-root",HEADER:"header",HEADER_ROW:"header-row",HEADER_CELL:"header-cell",ROWS_VIEWPORT:"rows-viewport",ROWS_SPACER:"rows-spacer",ROWS_CONTAINER:"rows",DATA_ROW:"data-grid-row",GROUP_ROW:"group-row",DATA_CELL:"cell",SELECTED:"selected",FOCUSED:"focused",EDITING:"editing",EXPANDED:"expanded",COLLAPSED:"collapsed",DRAGGING:"dragging",RESIZING:"resizing",SORTABLE:"sortable",SORTED_ASC:"sorted-asc",SORTED_DESC:"sorted-desc",HIDDEN:"hidden",STICKY_LEFT:"sticky-left",STICKY_RIGHT:"sticky-right",PINNED_TOP:"pinned-top",PINNED_BOTTOM:"pinned-bottom",TREE_TOGGLE:"tree-toggle",TREE_INDENT:"tree-indent",GROUP_TOGGLE:"group-toggle",GROUP_LABEL:"group-label",GROUP_COUNT:"group-count",RANGE_SELECTION:"range-selection",SELECTION_OVERLAY:"selection-overlay"},T={FIELD:"data-field",GROUP_KEY:"data-group-key"},k={ROOT:`.${H.ROOT}`,HEADER:`.${H.HEADER}`,HEADER_ROW:`.${H.HEADER_ROW}`,HEADER_CELL:`.${H.HEADER_CELL}`,ROWS_VIEWPORT:`.${H.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${H.ROWS_CONTAINER}`,DATA_ROW:`.${H.DATA_ROW}`,DATA_CELL:`.${H.DATA_CELL}`,GROUP_ROW:`.${H.GROUP_ROW}`,CELL_BY_FIELD:e=>`.${H.DATA_CELL}[${T.FIELD}="${e}"]`,SELECTED_ROWS:`.${H.DATA_ROW}.${H.SELECTED}`,EDITING_CELL:`.${H.DATA_CELL}.${H.EDITING}`},L=/{{\s*([^}]+)\s*}}/g,P="__DG_EMPTY__",D=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,I="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(e=>e.split("").reverse().join("")),O=new RegExp(`__(proto|defineGetter|defineSetter)|${I.slice(3).join("|")}|this\\b`),z=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,F=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),q=/^\s*(javascript|vbscript|data|blob):/i;function $(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 i of r){const e=i.tagName.toLowerCase();if(z.has(e)){t.push(i);continue}if("svg"===e||"http://www.w3.org/2000/svg"===i.namespaceURI){if(Array.from(i.attributes).some(e=>N.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(i);continue}}const r=[];for(const t of i.attributes){const e=t.name.toLowerCase();N.test(e)?r.push(t.name):(F.has(e)&&q.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name)}r.forEach(e=>i.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}function W(e,t){const r=function(e){const t=[];let r=0;for(;r<e.length;){const i=e[r];if(" "!==i){if(i>="0"&&i<="9"||"."===i&&r+1<e.length&&e[r+1]>="0"&&e[r+1]<="9"){const i=r;for(;r<e.length&&(e[r]>="0"&&e[r]<="9"||"."===e[r]);)r++;t.push({type:"num",v:Number(e.slice(i,r))});continue}if("'"===i){let i="";for(r++;r<e.length&&"'"!==e[r];)i+=e[r++];if(r>=e.length)return null;r++,t.push({type:"str",v:i});continue}if(i>="a"&&i<="z"||i>="A"&&i<="Z"||"_"===i||"$"===i){const i=r;for(;r<e.length&&/[\w$.]/.test(e[r]);)r++;t.push({type:"id",v:e.slice(i,r)});continue}if(r+2<e.length){const i=e.slice(r,r+3);if("==="===i||"!=="===i){t.push({type:"op",v:i}),r+=3;continue}}if(r+1<e.length){const i=e.slice(r,r+2);if("=="===i||"!="===i||"<="===i||">="===i||"&&"===i||"||"===i){t.push({type:"op",v:i}),r+=2;continue}}if(!"+-*/%<>!?:(),".includes(i))return null;t.push({type:"op",v:i}),r++}else r++}return t}(e);if(!r)return;const i=r;let o=0;function n(){return i[o]}function s(){return i[o++]}function a(e,t){const r=n();return!!r&&(r.type===e&&(void 0===t||r.v===t))}function l(){const e=function(){let e=c();for(;a("op","||");)s(),e=e||c();return e}();if(a("op","?")){s();const t=l();if(!a("op",":"))return;s();const r=l();return e?t:r}return e}function c(){let e=d();for(;a("op","&&");)s(),e=e&&d();return e}function d(){let e=u();for(;;){const t=n();if(!t||"op"!==t.type)break;if("==="===t.v)s(),e=e===u();else if("!=="===t.v)s(),e=e!==u();else if("=="===t.v)s(),e=e==u();else{if("!="!==t.v)break;s(),e=e!=u()}}return e}function u(){let e=h();for(;;){const t=n();if(!t||"op"!==t.type)break;if("<"===t.v)s(),e=e<h();else if(">"===t.v)s(),e=e>h();else if("<="===t.v)s(),e=e<=h();else{if(">="!==t.v)break;s(),e=e>=h()}}return e}function h(){let e=g();for(;;){const t=n();if(!t||"op"!==t.type)break;if("+"===t.v)s(),e+=g();else{if("-"!==t.v)break;s(),e-=g()}}return e}function g(){let e=f();for(;;){const t=n();if(!t||"op"!==t.type)break;if("*"===t.v)s(),e*=f();else if("/"===t.v)s(),e/=f();else{if("%"!==t.v)break;s(),e%=f()}}return e}function f(){return a("op","!")?(s(),!f()):p()}function p(){const e=n();if(e){if("num"===e.type)return s(),e.v;if("str"===e.type)return s(),e.v;if("id"===e.type)return s(),function(e){if("value"===e)return t.value;if(e.startsWith("row.")){const r=e.slice(4);return t.row?t.row[r]:void 0}if(e.startsWith("typeDefault.")){const r=e.slice(12);return t.typeDefault?t.typeDefault[r]:void 0}return"row"===e?t.row:"typeDefault"===e?t.typeDefault:void 0}(e.v);if("op"===e.type&&"("===e.v){s();const e=l();return a("op",")")&&s(),e}return"op"===e.type&&"-"===e.v?(s(),-p()):void 0}}const w=l();return o<i.length?void 0:w}function V(e,t){if(!e||-1===e.indexOf("{{"))return e;const r=[],i=e.replace(L,(e,i)=>{const o=function(e,t){if(e=(e||"").trim(),!e)return P;if(U.test(e))return P;if("value"===e)return null==t.value?P:String(t.value);if(e.startsWith("row.")&&!/[()?]/.test(e)&&!e.includes(":")){const r=e.slice(4),i=t.row?t.row[r]:void 0;return null==i?P:String(i)}if(e.startsWith("typeDefault.")&&!/[()?]/.test(e)&&!e.includes(":")){const r=e.slice(12),i=t.typeDefault?t.typeDefault[r]:void 0;return null==i?P:String(i)}if(e.length>80)return P;if(!D.test(e)||O.test(e))return P;const r=e.match(/\./g);if(r&&r.length>1)return P;try{const r=W(e,t),i=null==r?"":String(r);return U.test(i)?P:i||P}catch{return P}}(i,t);return r.push({expr:i.trim(),result:o}),o}),o=(n=i)?n.replace(new RegExp(P,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):n;var n;const s=r.length&&r.every(e=>""===e.result||e.result===P);return U.test(e)||s?"":o}const U=/Reflect|Proxy|ownKeys/;function B(e){if(U.test(e.textContent||"")){for(const t of e.childNodes)t.nodeType===Node.TEXT_NODE&&U.test(t.textContent||"")&&(t.textContent="");U.test(e.textContent||"")&&(e.textContent="")}}function G(e){if(U.test(e)){const e=()=>"";return e.__blocked=!0,e}const t=t=>V(e,t);return t.__blocked=!1,t}function j(e){return e.replace(/([A-Z])/g,"-$1").toLowerCase()}const Y=new WeakMap;function X(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 i=e,o=t.field;let n=Y.get(i);if(n){const e=n.get(o);if(void 0!==e)return e.v}else n=new Map,Y.set(i,n);const s=t.valueAccessor({row:e,column:t,rowIndex:r});return n.set(o,{v:s}),s}function K(e,t){e&&(t?Y.get(e)?.delete(t):Y.delete(e))}function Z(e,t,r){const i=r.find(e=>e.field===t.field),o=i?.sortComparator,{field:n,direction:s}=t,a=[...e];return o?i?.valueAccessor?a.sort((e,t)=>o(X(e,i),X(t,i),e,t)*s):a.sort((e,t)=>o(e[n],t[n],e,t)*s):i?.valueAccessor?J(a,i,s):Q(a,n,s),a}function Q(e,t,r){e.sort((e,i)=>{const o=ee(e,i);if(0!==o)return o;const n=e[t],s=i[t];return null==n&&null==s?0:null==n?-r:null==s||n>s?r:n<s?-r:0})}function J(e,t,r){e.sort((e,i)=>{const o=ee(e,i);if(0!==o)return o;const n=X(e,t),s=X(i,t);return null==n&&null==s?0:null==n?-r:null==s||n>s?r:n<s?-r:0})}function ee(e,t){const r=!0===e?.__loading;return r===(!0===t?.__loading)?0:r?1:-1}function te(e,t,r,i){const o=i.find(e=>e.field===t),n=o?.sortComparator;n?o?.valueAccessor?e.sort((e,t)=>n(X(e,o),X(t,o),e,t)*r):e.sort((e,i)=>n(e[t],i[t],e,i)*r):o?.valueAccessor?J(e,o,r):Q(e,t,r)}function re(e,t,r,i){e._rows=t,e.__rowRenderEpoch++;for(let o=0;o<e._rowPool.length;o++)e._rowPool[o].__epoch=-1;e._schedulerRenderHeader(),e.refreshVirtualWindow(!0),ie(e,r,i)}function ie(e,t,r){const i={field:t.field,direction:r};e.dispatchEvent(new CustomEvent("sort-change",{detail:i})),e._pluginManager?.emitPluginEvent?.("sort-change",i),n(e,s(e,0===r?"sortCleared":"sortApplied",t.header??t.field,1===r?"ascending":"descending")),e.requestStateChange?.()}function oe(e){return e._pluginManager?._hasRowStructurePlugins??!1}function ne(e,t){if(e._sortState&&e._sortState.field===t.field)if(1===e._sortState.direction)se(e,t,-1);else{if(e._sortState=null,oe(e))return e._requestSchedulerPhase(4,"sort-clear"),void ie(e,t,0);e.__rowRenderEpoch++;for(let t=0;t<e._rowPool.length;t++)e._rowPool[t].__epoch=-1;e._rows=e.__originalOrder.slice(),e.__originalOrder=[],e._schedulerRenderHeader();const r=e._headerRowEl?.querySelectorAll('[role="columnheader"].sortable');if(r)for(let t=0;t<r.length;t++){const i=r[t];i.getAttribute("aria-sort")&&("ascending"!==i.getAttribute("aria-sort")&&"descending"!==i.getAttribute("aria-sort")||e._sortState)||i.setAttribute("aria-sort","none")}e.refreshVirtualWindow(!0),ie(e,t,0)}else e._sortState||(e.__originalOrder=e._rows.slice()),se(e,t,1)}function se(e,t,r){if(e._sortState={field:t.field,direction:r},oe(e))return e._requestSchedulerPhase(4,"sort-apply"),void ie(e,t,r);const i={field:t.field,direction:r},o=e._columns,n=e.effectiveConfig?.sortHandler??Z;if(n===Z)return te(e._rows,i.field,r,o),void re(e,e._rows,t,r);const s=n(e._rows,i,o);s&&"function"==typeof s.then?s.then(i=>{re(e,i,t,r)}):re(e,s,t,r)}function ae(e,t){return!1!==e.effectiveConfig?.sortable&&!0===t.sortable}function le(e,t){return!1!==e.effectiveConfig?.resizable&&!1!==t.resizable}function ce(e,t){const r=document.createElement("span");R(r,"sort-indicator");const i=e._sortState?.field===t.field?e._sortState.direction:0,o=1===i?"sortAsc":-1===i?"sortDesc":"sortNone";r.dataset.icon=j(o);const n=e.icons?.[o];return void 0!==n&&function(e,t){"string"==typeof t?e.innerHTML=$(t):t instanceof HTMLElement&&(e.innerHTML="",e.appendChild(t.cloneNode(!0)))}(r,n),r}function de(e,t,r){const i=document.createElement("div");return i.className="resize-handle",i.setAttribute("aria-hidden","true"),i.addEventListener("mousedown",i=>{i.stopPropagation(),i.preventDefault(),e._resizeController.start(i,t,r)}),i.addEventListener("dblclick",r=>{r.stopPropagation(),r.preventDefault(),e._resizeController.resetColumn(t)}),i}function ue(e,t,r,i){i.classList.add(H.SORTABLE),i.tabIndex=0;const o=e._sortState?.field===t.field?e._sortState.direction:0;i.setAttribute("aria-sort",0===o?"none":1===o?"ascending":"descending"),i.addEventListener("click",r=>{e._resizeController?.isResizing||e._dispatchHeaderClick?.(r,t,i)||ne(e,t)}),i.addEventListener("keydown",r=>{if("Enter"===r.key||" "===r.key){if(r.preventDefault(),e._dispatchHeaderClick?.(r,t,i))return;ne(e,t)}})}function he(e){e._headerRowEl=e.findHeaderRow();const t=e._headerRowEl;t&&(t.innerHTML="",e._visibleColumns.forEach((r,i)=>{const o=document.createElement("div");o.className="cell",R(o,"header-cell"),o.setAttribute("role","columnheader"),o.setAttribute("aria-colindex",String(i+1)),o.setAttribute("data-field",r.field),o.setAttribute("data-col",String(i)),r.type&&o.setAttribute("data-type",r.type);const n=r.header??r.field,s=e._sortState?.field===r.field?e._sortState.direction:0,a=1===s?"asc":-1===s?"desc":null;if(r.headerRenderer){const t={column:r,value:n,sortState:a,filterActive:!1,cellEl:o,renderSortIcon:()=>ae(e,r)?ce(e,r):null,renderFilterButton:()=>null},s=r.headerRenderer(t);!function(e,t){if(null!=t)if("string"==typeof t){const r=document.createElement("span");for(r.innerHTML=$(t);r.firstChild;)e.appendChild(r.firstChild)}else t instanceof Node&&e.appendChild(t)}(o,s),ae(e,r)&&ue(e,r,0,o),le(e,r)&&(o.classList.add("resizable"),o.appendChild(de(e,i,o)))}else if(r.headerLabelRenderer){const t={column:r,value:n},s=r.headerLabelRenderer(t),a=document.createElement("span");null==s?a.textContent=n:"string"==typeof s?a.innerHTML=$(s):s instanceof Node&&a.appendChild(s),o.appendChild(a),ae(e,r)&&(ue(e,r,0,o),o.appendChild(ce(e,r))),le(e,r)&&(o.classList.add("resizable"),o.appendChild(de(e,i,o)))}else if(r.__headerTemplate)Array.from(r.__headerTemplate.childNodes).forEach(e=>o.appendChild(e.cloneNode(!0))),ae(e,r)&&(ue(e,r,0,o),o.appendChild(ce(e,r))),le(e,r)&&(o.classList.add("resizable"),o.appendChild(de(e,i,o)));else{const t=document.createElement("span");t.textContent=n,o.appendChild(t),ae(e,r)&&(ue(e,r,0,o),o.appendChild(ce(e,r))),le(e,r)&&(o.classList.add("resizable"),o.appendChild(de(e,i,o)))}t.appendChild(o)}),t.querySelectorAll(`.cell.${H.SORTABLE}`).forEach(e=>{e.getAttribute("aria-sort")||e.setAttribute("aria-sort","none")}),t.children.length>0?(t.setAttribute("role","row"),t.setAttribute("aria-rowindex","1")):(t.removeAttribute("role"),t.removeAttribute("aria-rowindex")))}function ge(e,t){const r=e[0]||{},i=Object.keys(r).map(e=>{const t=r[e],i=null==(o=t)?"string":"number"==typeof o?"number":"boolean"==typeof o?"boolean":o instanceof Date||"string"==typeof o&&/\d{4}-\d{2}-\d{2}/.test(o)&&!isNaN(Date.parse(o))?"date":"string";var o;return{field:e,header:e.charAt(0).toUpperCase()+e.slice(1),type:i}}),o={};return i.forEach(e=>{o[e.field]=e.type||"string"}),{columns:i,typeMap:o}}const fe={STYLE:1,VIRTUALIZATION:2,HEADER:3,ROWS:4,COLUMNS:5,FULL:6};class pe{#e;#t=0;#r=0;#i=null;#o=null;#n=null;#s=!1;constructor(e){this.#e=e}requestPhase(e,t){e>this.#t&&(this.#t=e),0===this.#r&&(this.#a(),this.#r=requestAnimationFrame(()=>this.#l()))}whenReady(){return this.#i?this.#i:Promise.resolve()}setInitialReadyResolver(e){this.#n=e}cancel(){0!==this.#r&&(cancelAnimationFrame(this.#r),this.#r=0),this.#t=0,this.#o&&(this.#o(),this.#o=null,this.#i=null)}get isPending(){return 0!==this.#t}get pendingPhase(){return this.#t}#a(){this.#i||(this.#i=new Promise(e=>{this.#o=e}))}#l(){if(this.#r=0,!this.#e._schedulerIsConnected)return this.#t=0,void(this.#o&&(this.#o(),this.#o=null,this.#i=null));const e=this.#t;this.#t=0,e>=fe.COLUMNS&&this.#e._schedulerMergeConfig(),e>=fe.ROWS&&this.#e._schedulerProcessRows(),e>=fe.COLUMNS&&(this.#e._schedulerProcessColumns(),this.#e._schedulerUpdateTemplate()),e>=fe.HEADER&&this.#e._schedulerRenderHeader(),e>=fe.VIRTUALIZATION&&this.#e.refreshVirtualWindow(!0,!0),e>=fe.STYLE&&this.#e._schedulerAfterRender();const t=!this.#s;t&&(this.#s=!0,this.#n?.()),this.#o&&(this.#o(),this.#o=null,this.#i=null),0!==e&&this.#c(e,t)}#c(e,t){const r=this.#e._virtualization,i=r?.enabled?{start:r.start,end:r.end}:null,o={phase:e,initial:t,rowCount:this.#e._rows?.length??0,visibleRange:i};this.#e._hostElement.dispatchEvent(new CustomEvent("render",{detail:o,bubbles:!0,composed:!0}))}}class we{#d;#u;#h;#g;#f;#p;#w;#m={};#b={};#v=!0;#y=[];#_;#C;#R;#E;#e;constructor(e){this.#e=e}get original(){return this.#m}get effective(){return this.#b}get columns(){return this.#b.columns??[]}set columns(e){this.#b.columns=e}get lightDomColumnsCache(){return this.#f}set lightDomColumnsCache(e){this.#f=e}get originalColumnNodes(){return this.#w}set originalColumnNodes(e){this.#w=e}get initialColumnState(){return this.#E}set initialColumnState(e){this.#E=e}get sourcesChanged(){return this.#v}markSourcesChanged(){this.#v=!0}setGridConfig(e){this.#d!==e&&(this.#d=e,this.#v=!0,this.#f=void 0)}getGridConfig(){return this.#d}setColumns(e){this.#u=e,this.#v=!0}getColumns(){return this.#u}setFitMode(e){this.#h=e,this.#v=!0}getFitMode(){return this.#h}setColumnInference(e){this.#g!==e&&(this.#g=e,this.#v=!0)}getColumnInference(){return this.#g}merge(){const e=(this.#b.columns?.length??0)>0;if(!this.#v&&e)return;const t=this.#S();this.#v=!1,this.#m=t,Object.freeze(this.#m),this.#m.columns&&Object.freeze(this.#m.columns),this.#b=this.#A(this.#m),this.#M()}#A(e){const t={...e};return e.columns&&(t.columns=e.columns.map(e=>({...e}))),e.shell&&(t.shell={...e.shell,header:e.shell.header?{...e.shell.header}:void 0,toolPanel:e.shell.toolPanel?{...e.shell.toolPanel}:void 0,toolPanels:e.shell.toolPanels?.map(e=>({...e})),headerContents:e.shell.headerContents?.map(e=>({...e}))}),t}#M(){const e=this.#b;if(this.#x(),"number"==typeof e.rowHeight&&e.rowHeight>0&&(this.#e._virtualization.rowHeight=e.rowHeight),"fixed"===e.fitMode){this.columns.forEach(e=>{null==e.width&&(e.width="number"==typeof e.minWidth&&Number.isFinite(e.minWidth)&&e.minWidth>0?e.minWidth:80)})}this.#e._applyAnimationConfig(e)}#x(){const e=this.#b.typeDefaults;if(!e)return;const t=this.columns;for(const r of t){if(!r.type)continue;const t=e[r.type];t&&(r.renderer||r.viewRenderer||!t.renderer||(r.renderer=t.renderer),!r.format&&t.format&&(r.format=t.format),!r.editor&&t.editor&&(r.editor=t.editor),!r.editorParams&&t.editorParams&&(r.editorParams=t.editorParams))}}#S(){const e=this.#d?{...this.#d}:{},t=Array.isArray(e.columns)?[...e.columns]:[],r=(this.#f??[]).map(e=>({...e}));let i=C(t,r);this.#u&&this.#u.length&&(i=C(this.#u,r));const o=this.#e.sourceRows;if("merge"===(this.#g??e.columnInference??"auto")&&o.length){i=function(e,t){if(!t.length)return e;const r=new Map;for(const n of t)r.set(n.field,n);const i=new Set(e.map(e=>e.field)),o=e.map(e=>{const t=r.get(e.field);if(!t)return e;const i={...e};for(const[r,o]of Object.entries(t))void 0!==o&&Object.assign(i,{[r]:o});return i});for(const n of t)i.has(n.field)||o.push(n);return o}(ge(o).columns,i)}else if(0===i.length&&o.length){i=ge(o).columns}if(i.length&&(!function(e){const t=[],r=[];for(const n of e)"number"==typeof n.order&&Number.isFinite(n.order)&&n.order>=0?t.push({col:n,order:Math.floor(n.order)}):r.push(n);if(0===t.length)return e;t.sort((e,t)=>e.order-t.order);const i=[];let o=0;for(const{col:n,order:s}of t){for(;i.length<s&&o<r.length;)i.push(r[o++]);const e=Math.min(s,i.length);i.splice(e,0,n)}for(;o<r.length;)i.push(r[o++]);e.length=0,e.push(...i)}(i),i.forEach(e=>{void 0===e.sortable&&(e.sortable=!0),void 0===e.resizable&&(e.resizable=!0),void 0===e.__originalWidth&&"number"==typeof e.width&&(e.__originalWidth=e.width)}),i.forEach(e=>{e.__viewTemplate&&!e.__compiledView&&(e.__compiledView=G(e.__viewTemplate.innerHTML)),e.__editorTemplate&&!e.__compiledEditor&&(e.__compiledEditor=G(e.__editorTemplate.innerHTML))}),e.columns=i),this.#p&&Object.keys(this.#p).length>0){const t={...this.#p},r=e.typeDefaults??{};for(const e of Object.keys(r)){const i=r[e],o=t[e];t[e]=o?{...o,...i}:i}e.typeDefaults=t}return this.#h&&(e.fitMode=this.#h),e.fitMode||(e.fitMode="stretch"),this.#g&&(e.columnInference=this.#g),this.#e._pluginManager?.processConfig?.(e),e.columnState&&!this.#E&&(this.#E=e.columnState),e}collectState(e){const t=this.columns,r=this.#H();return{columns:t.map((t,i)=>{const o={field:t.field,order:i,visible:!t.hidden},n=t;void 0!==n.__renderedWidth?o.width=n.__renderedWidth:void 0!==t.width&&(o.width="string"==typeof t.width?parseFloat(t.width):t.width);const s=r.get(t.field);s&&(o.sort=s);for(const r of e)if(r.getColumnState){const e=r.getColumnState(t.field);e&&Object.assign(o,e)}return o})}}applyState(e,t){if(!e.columns||0===e.columns.length)return;const r=this.columns,i=new Map(e.columns.map(e=>[e.field,e])),o=r.map(e=>{const t=i.get(e.field);if(!t)return e;const r={...e};return void 0!==t.width&&(r.width=t.width,r.__renderedWidth=t.width),void 0!==t.visible&&(r.hidden=!t.visible),r});o.sort((e,t)=>(i.get(e.field)?.order??1/0)-(i.get(t.field)?.order??1/0)),this.columns=o;const n=e.columns.filter(e=>void 0!==e.sort).sort((e,t)=>(e.sort?.priority??0)-(t.sort?.priority??0));if(n.length>0){const e=n[0];e.sort&&(this.#e._sortState={field:e.field,direction:"asc"===e.sort.direction?1:-1})}else this.#e._sortState=null;for(const s of t)if(s.applyColumnState)for(const t of e.columns)s.applyColumnState(t.field,t)}resetState(e){this.#E=void 0,this.#e._sortState=null,this.#b=this.#A(this.#m),this.#M();for(const t of e)if(t.applyColumnState)for(const e of this.columns)t.applyColumnState(e.field,{field:e.field,order:0,visible:!0});this.requestStateChange(e)}#H(){const e=new Map,t=this.#e._sortState;return t&&e.set(t.field,{direction:1===t.direction?"asc":"desc",priority:0}),e}requestStateChange(e){this.#C&&clearTimeout(this.#C),this.#C=setTimeout(()=>{this.#C=void 0;const t=this.collectState(e);this.#e._emit("column-state-change",t)},100)}setColumnVisible(e,t){const r=this.columns,i=r.find(t=>t.field===e);if(!i)return!1;if(!t&&i.lockVisible)return!1;if(!t){if(0===r.filter(t=>!t.hidden&&t.field!==e).length)return!1}return!!i.hidden!=!t&&(i.hidden=!t,this.#e._emit("column-visibility",{field:e,visible:t,visibleColumns:r.filter(e=>!e.hidden).map(e=>e.field)}),this.#e._clearRowPool(),this.#e._setup(),!0)}toggleColumnVisibility(e){const t=this.columns.find(t=>t.field===e);return!!t&&this.setColumnVisible(e,!!t.hidden)}isColumnVisible(e){const t=this.columns.find(t=>t.field===e);return!!t&&!t.hidden}showAllColumns(){const e=this.columns;e.some(e=>e.hidden)&&(e.forEach(e=>e.hidden=!1),this.#e._emit("column-visibility",{visibleColumns:e.map(e=>e.field)}),this.#e._clearRowPool(),this.#e._setup())}getAllColumns(){return this.columns.map(e=>({field:e.field,header:e.header||e.field,visible:!e.hidden,lockVisible:e.lockVisible,utility:!0===e.utility}))}getColumnOrder(){return this.columns.map(e=>e.field)}setColumnOrder(e){if(!e.length)return;const t=new Map(this.columns.map(e=>[e.field,e])),r=[];for(const i of e){const e=t.get(i);e&&(r.push(e),t.delete(i))}for(const i of t.values())r.push(i);this.columns=r,this.#e._invalidateVisibleColumnsCache(),he(this.#e),M(this.#e),this.#e._requestSchedulerPhase(fe.COLUMNS,"configManager")}parseLightDomColumns(e){if(this.#f||(this.#w=Array.from(e.querySelectorAll("tbw-grid-column")),this.#f=this.#w.length?function(e){return Array.from(e.querySelectorAll("tbw-grid-column")).map(e=>{const t=e.getAttribute("field")||"";if(!t)return null;const r=t.includes(":")?d(t):void 0,i={field:r?.field??t,type:e.getAttribute("type")||r?.type||void 0,header:e.getAttribute("header")||r?.header||void 0,sortable:e.hasAttribute("sortable")&&"false"!==e.getAttribute("sortable"),__element:e},o=e.getAttribute("width");if(o){const e=parseFloat(o);!isNaN(e)&&/^\d+(\.\d+)?$/.test(o.trim())?i.width=e:i.width=o}const n=e.getAttribute("minWidth")||e.getAttribute("min-width");if(n){const e=parseFloat(n);isNaN(e)||(i.minWidth=e)}const s=e.getAttribute("order");if(s){const e=parseInt(s,10);Number.isFinite(e)&&e>=0&&(i.order=e)}e.hasAttribute("resizable")&&(i.resizable="false"!==e.getAttribute("resizable"));const a=e.getAttribute("options");a&&(i.options=a.split(",").map(e=>{const[t,r]=e.includes(":")?e.split(":"):[e.trim(),e.trim()];return{value:t.trim(),label:r?.trim()||t.trim()}}));const l=e.querySelector("tbw-grid-column-view"),c=e.querySelector("tbw-grid-column-editor"),u=e.querySelector("tbw-grid-column-header");l&&(i.__viewTemplate=l),u&&(i.__headerTemplate=u);const h=globalThis.DataGridElement,g=h?.getAdapters?.()??[],f=l??e,p=g.find(e=>e.canHandle(f));if(p){const e=p.createRenderer(f);e&&(i.viewRenderer=e)}const w=c??e,m=g.find(e=>e.canHandle(w));if(m){const e=m.createEditor(w);e&&(i.editor=e)}const b=g.find(t=>t.canHandle(e)&&(t.createHeaderRenderer||t.createHeaderLabelRenderer));if(b){const t=b.createHeaderRenderer?.(e);t&&(i.headerRenderer=t);const r=b.createHeaderLabelRenderer?.(e);r&&(i.headerLabelRenderer=r)}return i}).filter(e=>!!e)}(e):[]),!this.#p){const t=function(e){const t=globalThis.DataGridElement,r=t?.getAdapters?.()??[];return Array.from(e.children).filter(e=>"tbw-grid-type"===e.tagName.toLowerCase()).map(e=>{const t=e.getAttribute("name")?.trim();if(!t)return null;const i=Array.from(e.children).find(e=>"tbw-grid-column-view"===e.tagName.toLowerCase()),o=i??e,n=r.find(e=>e.canHandle(o)),s=n?.createRenderer(o),a={};for(const r of Array.from(e.attributes)){if(!r.name.startsWith("data-"))continue;const e=r.name.slice(5).replace(/-([a-z])/g,(e,t)=>t.toUpperCase()).trim();e&&(a[e]=r.value)}return{name:t,params:a,viewTemplate:i,viewRenderer:s}}).filter(e=>null!==e)}(e),r={};for(const e of t){const t={};let i=!1;if(e.viewRenderer)t.renderer=e.viewRenderer,i=!0;else if(e.viewTemplate){const r=G(e.viewTemplate.innerHTML);t.renderer=t=>r({row:t.row,value:t.value,field:t.field,column:t.column,typeDefault:e.params}),i=!0}i&&(r[e.name]=t)}this.#p=r}}clearLightDomCache(){this.#f=void 0,this.#p=void 0}#T=new Map;registerLightDomHandler(e,t){this.#T.set(e.toLowerCase(),t)}unregisterLightDomHandler(e){this.#T.delete(e.toLowerCase())}observeLightDOM(e){this.#_&&this.#_.disconnect();const t=new Set,r=()=>{this.#R=void 0;for(const e of t){const t=this.#T.get(e);t?.()}t.clear()};this.#_=new MutationObserver(e=>{for(const r of e){for(const e of r.addedNodes){if(e.nodeType!==Node.ELEMENT_NODE)continue;const r=e.tagName.toLowerCase();this.#T.has(r)&&t.add(r)}for(const e of r.removedNodes){if(e.nodeType!==Node.ELEMENT_NODE)continue;const r=e.tagName.toLowerCase();this.#T.has(r)&&t.add(r)}if("attributes"===r.type&&r.target.nodeType===Node.ELEMENT_NODE){const e=r.target.tagName.toLowerCase();this.#T.has(e)&&t.add(e)}}t.size>0&&!this.#R&&(this.#R=setTimeout(r,0))}),this.#_.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["title","field","header","width","hidden","id","icon","tooltip","order","name","type"]})}onChange(e){this.#y.push(e)}notifyChange(){for(const e of this.#y)e()}dispose(){this.#_?.disconnect(),this.#y=[],this.#C&&clearTimeout(this.#C),this.#R&&(clearTimeout(this.#R),this.#R=void 0)}}function me(e,t){const r=document.createElement("div");return e&&(r.className=e),r}const be=document.createElement("template");function ve(e){const t=document.createDocumentFragment(),r=me(H.ROOT);{const e=me("tbw-grid-content");e.appendChild(be.content.cloneNode(!0)),r.appendChild(e)}return t.appendChild(r),t}be.innerHTML='\n <div class="tbw-scroll-area">\n <div class="rows-body-wrapper">\n <div class="rows-body" role="grid">\n <div class="header" role="rowgroup">\n <div class="header-row" role="row" part="header-row"></div>\n </div>\n <div class="rows-container" role="presentation">\n <div class="rows-viewport" role="presentation">\n <div class="rows"></div>\n </div>\n </div>\n </div>\n </div>\n </div>\n <div class="faux-vscroll">\n <div class="faux-vscroll-spacer"></div>\n </div>\n <div class="tbw-sr-only" aria-live="polite" aria-atomic="true"></div>\n';function ye(e){const t=document.createElement("div");return t.className="tbw-empty-message",t.textContent=e.filteredOut?"No matching rows":"No data to display",t}function _e(e,t,r="rows"){const i=document.createElement("div");return i.className="tbw-empty-overlay",i.setAttribute("role","status"),i.setAttribute("aria-live","polite"),i.setAttribute("data-overlay-target",r),i.appendChild(function(e,t){const r=(t??ye)(e);if("string"==typeof r){const e=document.createElement("div");return e.className="tbw-empty-message",e.innerHTML=$(r),e}return r}(e,t)),i}function Ce(e){e?.remove()}function Re(){if("undefined"!=typeof window&&window.location){const e=window.location.hostname;if("localhost"===e||"127.0.0.1"===e||"::1"===e)return!0}return"undefined"!=typeof process&&"production"!==process.env?.NODE_ENV}function Ee(e){return`<span role="checkbox" aria-checked="${e}" aria-label="${e}">${e?"&#x1F5F9;":"&#9744;"}</span>`}function Se(e){if(null==e||""===e)return"";if(e instanceof Date)return isNaN(e.getTime())?"":e.toLocaleDateString();if("number"==typeof e||"string"==typeof e){const t=new Date(e);return isNaN(t.getTime())?"":t.toLocaleDateString()}return""}function Ae(e){if(!e)return-1;const t=e.getAttribute("data-row");if(t)return parseInt(t,10);const r=e.closest(".data-grid-row");if(!r)return-1;const i=r.parentElement;if(!i)return-1;const o=i.querySelectorAll(":scope > .data-grid-row");for(let n=0;n<o.length;n++)if(o[n]===r)return n;return-1}function Me(e){e&&e.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function xe(e){return"rtl"===function(e){try{if("rtl"===getComputedStyle(e).direction)return"rtl"}catch{}try{const t=e.closest?.("[dir]")?.getAttribute("dir");if("rtl"===t)return"rtl"}catch{}return"ltr"}(e)}function He(e,t){return e&&"object"==typeof e?"__rowCacheKey"in e?e.__rowCacheKey:"rowId"in e&&null!=e.rowId?`id:${e.rowId}`:t?`id:${t(e)}`:e:e}function Te(e,t,r){const i=He(t,r);return"string"==typeof i?e.byKey.get(i):i&&"object"==typeof i?e.byRef.get(i):void 0}function ke(e,t,r){if(t<0||t>=e.length)return;const i=e[t],o=r-i.height;if(0!==o){i.height=r,i.measured=!0;for(let r=t+1;r<e.length;r++)e[r].offset+=o}}function Le(e,t){if(0===e.length)return-1;if(t<=0)return 0;let r=0,i=e.length-1;for(;r<=i;){const o=Math.floor((r+i)/2),n=e[o],s=n.offset+n.height;if(t<n.offset)i=o-1;else{if(!(t>=s))return o;r=o+1}}return Math.max(0,Math.min(r,e.length-1))}function Pe(e,t){const{positionCache:r,heightCache:i,rows:o,start:n,end:s,getPluginHeight:a,getRowId:l}=e;let c=!1;t.forEach(e=>{const t=e.dataset.rowIndex;if(!t)return;const d=parseInt(t,10);if(d<n||d>=s||d>=o.length)return;const u=o[d],h=a?.(u,d);if(void 0!==h){const e=r[d];return void((!e.measured||Math.abs(e.height-h)>1)&&(ke(r,d,h),c=!0))}const g=e.offsetHeight;if(g>0){const e=r[d];(!e.measured||Math.abs(e.height-g)>1)&&(ke(r,d,g),function(e,t,r,i){const o=He(t,i);"string"==typeof o?e.byKey.set(o,r):o&&"object"==typeof o&&e.byRef.set(o,r)}(i,u,g,l),c=!0)}});const d=c?function(e){let t=0;for(const r of e)r.measured&&t++;return t}(r):0,u=c?function(e,t){let r=0,i=0;for(const o of e)o.measured&&(r+=o.height,i++);return i>0?r/i:t}(r,e.defaultHeight):0;return{hasChanges:c,measuredCount:d,averageHeight:u}}const De=335e5;function Ie(e,t,r=335e5){return{rawContentHeight:e,spacerHeight:Math.min(e,r),viewportHeight:t,capped:e>r}}function Oe(e,t){if(!t.capped)return e;const r=t.spacerHeight-t.viewportHeight,i=t.rawContentHeight-t.viewportHeight;if(r<=0||i<=0)return e;const o=e*i/r;return o<0?0:o>i?i:o}function ze(e,t){if(!t.capped)return e;const r=t.spacerHeight-t.viewportHeight,i=t.rawContentHeight-t.viewportHeight;return r<=0||i<=0?e:e*r/i}function Ne(e){"function"==typeof e.commitActiveRowEdit&&e.commitActiveRowEdit()}function Fe(e){if(!e)return!1;const t=e.tagName;return"INPUT"===t||"SELECT"===t||"TEXTAREA"===t||!!e.isContentEditable}function qe(e,t){if(e._virtualization?.enabled){const{rowHeight:t,container:r,viewportEl:i,scrollMapping:o}=e._virtualization,n=r,s=i?.clientHeight??n?.clientHeight??0;if(n&&s>0){const r=e._focusRow*t,i=o?Oe(n.scrollTop,o):n.scrollTop;if(r<i)n.scrollTop=o?ze(r,o):r;else if(r+t>i+s){const e=r-s+t;n.scrollTop=o?ze(e,o):e}}}const r=void 0!==e._activeEditRows&&-1!==e._activeEditRows||!!e._isGridEditMode;r||e.refreshVirtualWindow(!1),Me(e._bodyEl),Array.from(e._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(e=>{e.setAttribute("aria-selected","false")});const i=e._focusRow,o=e._virtualization.start??0,n=e._virtualization.end??e._rows.length;if(i>=o&&i<n){const n=e._bodyEl.querySelectorAll(".data-grid-row")[i-o];let s=n?.children[e._focusCol];if(s&&s.classList?.contains("cell")||(s=n?.querySelector(`.cell[data-col="${e._focusCol}"]`)??n?.querySelector(".cell[data-col]")),s){s.classList.add("cell-focus"),s.setAttribute("aria-selected","true");const i=e.querySelector(".tbw-scroll-area");if(i&&s&&(!r||t?.forceHorizontalScroll))if(t?.forceScrollLeft)i.scrollLeft=0;else if(t?.forceScrollRight)i.scrollLeft=i.scrollWidth-i.clientWidth;else{const t=e._getHorizontalScrollOffsets?.(n??void 0,s)??{left:0,right:0};if(!t.skipScroll){const e=s.getBoundingClientRect(),r=i.getBoundingClientRect(),o=e.left-r.left+i.scrollLeft,n=o+e.width,a=i.scrollLeft+t.left,l=i.scrollLeft+i.clientWidth-t.right;o<a?i.scrollLeft=o-t.left:n>l&&(i.scrollLeft=n-i.clientWidth+t.right)}}if(r&&s.classList.contains(H.EDITING)){const e=s.querySelector(x);if(e&&document.activeElement!==e)try{e.focus({preventScroll:!0})}catch{}}else if(r&&!s.contains(document.activeElement)){s.hasAttribute("tabindex")||s.setAttribute("tabindex","-1");try{s.focus({preventScroll:!0})}catch{}}else if(!r){const t=document.activeElement;t instanceof HTMLElement&&t!==e&&"function"==typeof e.contains&&e.contains(t)&&!t.classList.contains("cell")&&!t.closest(".cell")||t===e||e.focus({preventScroll:!0})}}}}function $e(e,t){const r=t.renderer||t.viewRenderer;if(r)return r;if(!t.type)return;const i=e.__frameworkAdapter;if(i?.getTypeDefault){const r=i.getTypeDefault(t.type,e._hostElement);if(r?.renderer)return r.renderer}}function We(e,t){if(t.format)return t.format;if(!t.type)return;const r=e.__frameworkAdapter;if(r?.getTypeDefault){const i=r.getTypeDefault(t.type,e._hostElement);if(i?.format)return i.format}}function Ve(e){return(e.__editingCellCount??0)>0}function Ue(e){e.__editingCellCount=0,e.removeAttribute("data-has-editing");e.querySelectorAll(`.cell.${H.EDITING}`).forEach(e=>e.classList.remove(H.EDITING))}const Be=document.createElement("template");Be.innerHTML='<div class="cell" role="gridcell" part="cell"></div>';const Ge=document.createElement("template");function je(){return Be.content.firstElementChild.cloneNode(!0)}function Ye(){return Ge.content.firstElementChild.cloneNode(!0)}function Xe(e){e.__cellDisplayCache=void 0,e.__cellCacheEpoch=void 0,e.__hasSpecialColumns=void 0}function Ke(e,t,r,i){const o=t.children,n=e._visibleColumns,s=n.length,a=o.length,l=s<a?s:a,c=e._focusRow,d=e._focusCol,u=e._hasAfterCellRenderHook?.()??!1;let h=e.__hasSpecialColumns;if(void 0===h){h=!1;const t=e.__frameworkAdapter;for(let r=0;r<s;r++){const i=n[r];if(i.__viewTemplate||i.__compiledView||i.renderer||i.viewRenderer||i.externalView||i.format||i.cellClass||"date"===i.type||"boolean"===i.type||i.type&&t?.getTypeDefault?.(i.type,e._hostElement)?.renderer||i.type&&t?.getTypeDefault?.(i.type,e._hostElement)?.format){h=!0;break}}e.__hasSpecialColumns=h}const g=String(i);if(h){for(let s=0;s<l;s++){if(n[s].externalView){if(!o[s].querySelector("[data-external-view]"))return void Ze(e,t,r,i)}}for(let s=0;s<l;s++){const a=n[s],l=o[s];l.getAttribute("data-row")!==g&&l.setAttribute("data-row",g);const h=l.classList.contains(H.EDITING);if(!h){const e=c===i&&d===s;e!==l.classList.contains("cell-focus")&&(l.classList.toggle("cell-focus",e),l.setAttribute("aria-selected",String(e)))}const m=a.cellClass;if(m){const t=l.getAttribute("data-dynamic-classes");if(t){const e=t.split(" ");for(let t=0;t<e.length;t++)e[t]&&l.classList.remove(e[t])}try{const e=m(X(r,a,i),r,a),t="string"==typeof e?e.split(/\s+/):e;if(t&&t.length>0){let e="";for(let r=0;r<t.length;r++){const i=t[r];i&&"string"==typeof i&&(l.classList.add(i),e+=(e?" ":"")+i)}l.setAttribute("data-dynamic-classes",e)}else l.removeAttribute("data-dynamic-classes")}catch(f){v(p,`cellClass callback error for column '${a.field}': ${f}`,e.id),l.removeAttribute("data-dynamic-classes")}}if(h)continue;const b=$e(e,a);if(b){const o=X(r,a,i),n=b({row:r,value:o,field:a.field,column:a,grid:e,cellEl:l});"string"==typeof n?(e.__frameworkAdapter?.releaseCell?.(l),l.innerHTML=$(n)):n instanceof Node?n.parentElement!==l&&(e.__frameworkAdapter?.releaseCell?.(l),l.innerHTML="",l.appendChild(n)):null==n&&(e.__frameworkAdapter?.releaseCell?.(l),l.textContent=null==o?"":String(o)),u&&e._afterCellRender?.({row:r,rowIndex:i,column:a,colIndex:s,value:o,cellElement:l,rowElement:t});continue}if(a.__compiledView){const o=X(r,a,i),n=a.__compiledView({row:r,value:o,field:a.field,column:a});a.__compiledView.__blocked?l.textContent="":(l.firstElementChild&&e.__frameworkAdapter?.releaseCell?.(l),l.innerHTML=$(n),B(l)),u&&e._afterCellRender?.({row:r,rowIndex:i,column:a,colIndex:s,value:o,cellElement:l,rowElement:t});continue}if(a.__viewTemplate){const o=X(r,a,i),n=a.__viewTemplate.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(n)?l.textContent="":(l.firstElementChild&&e.__frameworkAdapter?.releaseCell?.(l),l.innerHTML=$(V(n,{row:r,value:o})),B(l)),u&&e._afterCellRender?.({row:r,rowIndex:i,column:a,colIndex:s,value:o,cellElement:l,rowElement:t});continue}if(a.externalView)continue;const y=X(r,a,i);let _;l.firstElementChild&&e.__frameworkAdapter?.releaseCell?.(l);const C=We(e,a);if(C){try{const e=C(y,r);_=null==e?"":String(e)}catch(f){v(w,`Format error in column '${a.field}': ${f}`,e.id),_=null==y?"":String(y)}l.textContent=_}else"date"===a.type?(_=Se(y),l.textContent=_):"boolean"===a.type?l.innerHTML=Ee(!!y):(_=null==y?"":String(y),l.textContent=_);u&&e._afterCellRender?.({row:r,rowIndex:i,column:a,colIndex:s,value:y,cellElement:l,rowElement:t})}}else for(let p=0;p<l;p++){const s=o[p];if(s.classList.contains(H.EDITING))continue;s.firstElementChild&&e.__frameworkAdapter?.releaseCell?.(s);const a=n[p],l=X(r,a,i);s.textContent=null==l?"":String(l),s.getAttribute("data-row")!==g&&s.setAttribute("data-row",g);const h=c===i&&d===p;h!==s.classList.contains("cell-focus")&&(s.classList.toggle("cell-focus",h),s.setAttribute("aria-selected",String(h))),u&&e._afterCellRender?.({row:r,rowIndex:i,column:a,colIndex:p,value:l,cellElement:s,rowElement:t})}}function Ze(e,t,r,i){t.classList.remove("tbw-row-loading"),t.removeAttribute("aria-busy");const o=e.__frameworkAdapter;if(o?.releaseCell){o.beginBatch?.(e);try{const e=t.children;for(let t=e.length-1;t>=0;t--)o.releaseCell(e[t]);t.innerHTML=""}finally{o.endBatch?.(e)}}else t.innerHTML="";const n=e._visibleColumns,s=n.length,a=e._focusRow,l=e._focusCol,c=e._hasAfterCellRenderHook?.()??!1,d=document.createDocumentFragment();for(let h=0;h<s;h++){const o=n[h],s=je();s.setAttribute("aria-colindex",String(h+1)),s.setAttribute("data-col",String(h)),s.setAttribute("data-row",String(i)),s.setAttribute("data-field",o.field),s.setAttribute("data-header",o.header??o.field),o.type&&s.setAttribute("data-type",o.type);let g=X(r,o,i);const f=We(e,o);if(f)try{g=f(g,r)}catch(u){v(w,`Format error in column '${o.field}': ${u}`,e.id)}const m=o.__compiledView,b=o.__viewTemplate,y=$e(e,o),_=o.externalView;let C=!1;if(y){const t=y({row:r,value:g,field:o.field,column:o,grid:e,cellEl:s});"string"==typeof t?(s.innerHTML=$(t),C=!0):t instanceof Node?t.parentElement!==s&&(s.textContent="",s.appendChild(t)):null==t&&(s.textContent=null==g?"":String(g))}else if(_){const t=_,i=document.createElement("div");i.setAttribute("data-external-view",""),i.setAttribute("data-field",o.field),s.appendChild(i);const n={row:r,value:g,field:o.field,column:o,grid:e};if(t.mount)try{t.mount({placeholder:i,context:n,spec:t})}catch(u){v("TBW063",`External view mount error for column '${o.field}': ${u}`,e.id)}else queueMicrotask(()=>{try{e.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:i,spec:t,context:n}}))}catch(u){v("TBW064",`External view event dispatch error for column '${o.field}': ${u}`,e.id)}});i.setAttribute("data-mounted","")}else if(m){const e=m({row:r,value:g,field:o.field,column:o}),t=m.__blocked;s.innerHTML=t?"":$(e),C=!0,t&&(s.textContent="",s.setAttribute("data-blocked-template",""))}else if(b){const e=b.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(e)?(s.textContent="",s.setAttribute("data-blocked-template","")):(s.innerHTML=$(V(e,{row:r,value:g})),C=!0)}else f?s.textContent=null==g?"":String(g):"date"===o.type?s.textContent=Se(g):"boolean"===o.type?s.innerHTML=Ee(!!g):s.textContent=null==g?"":String(g);if(C){B(s);const e=s.textContent||"";/Proxy|Reflect\.ownKeys/.test(e)&&(s.textContent=e.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(s.textContent||"")&&(s.textContent=""))}s.hasAttribute("data-blocked-template")&&(s.textContent||"").trim().length&&(s.textContent="");("function"==typeof o.editable?o.editable(r):o.editable)?s.tabIndex=0:"boolean"===o.type&&(s.hasAttribute("tabindex")||(s.tabIndex=0)),a===i&&l===h?(s.classList.add("cell-focus"),s.setAttribute("aria-selected","true")):s.setAttribute("aria-selected","false");const R=o.cellClass;if(R)try{const e=R(X(r,o,i),r,o),t="string"==typeof e?e.split(/\s+/):e;if(t&&t.length>0){let e="";for(const r of t)r&&"string"==typeof r&&(s.classList.add(r),e+=(e?" ":"")+r);s.setAttribute("data-dynamic-classes",e)}}catch(u){v(p,`cellClass callback error for column '${o.field}': ${u}`,e.id)}c&&e._afterCellRender?.({row:r,rowIndex:i,column:o,colIndex:h,value:g,cellElement:s,rowElement:t}),d.appendChild(s)}t.appendChild(d)}function Qe(e,t,r){if(t.target?.closest(".resize-handle"))return;const i=Ae(r.querySelector(".cell[data-row]"));if(i<0)return;const o=e._rows[i];if(!o)return;if(e._dispatchRowClick?.(t,i,o,r))return;const n=t.target?.closest(".cell[data-col]");if(n){const r=Number(n.getAttribute("data-col"));if(!isNaN(r)){if(e._dispatchCellClick?.(t,i,r,n))return;const o=e._focusRow!==i||e._focusCol!==r;if(e._focusRow=i,e._focusCol=r,n.classList.contains(H.EDITING)){o&&(Me(e._bodyEl??e),n.classList.add("cell-focus"));const r=t.target,i=n.contains(r)&&r.matches(x)?r:n.querySelector(x);try{i?.focus({preventScroll:!0})}catch{}return}qe(e)}}}Ge.innerHTML='<div class="data-grid-row" role="row" part="row"></div>';const Je=new WeakMap;function et(e,t){const r=Ae(t),i=function(e){if(!e)return-1;const t=e.getAttribute("data-col");return t?parseInt(t,10):-1}(t);if(r<0||i<0)return;e._focusRow=r,e._focusCol=i,Me(e._bodyEl),t.classList.add("cell-focus"),t.setAttribute("aria-selected","true");const o=t.closest("tbw-grid, [data-tbw-grid]");o&&document.activeElement!==o&&o.focus({preventScroll:!0})}function tt(e,t,r,i){let o=null;const n=r.composedPath?.();if(o=n&&n.length>0?n[0]:r.target,o&&!t.contains(o)){const e=document.elementFromPoint(r.clientX,r.clientY);e&&(o=e)}const s=o?.closest?.("[data-col]"),a=o?.closest?.(".data-grid-row"),l=o?.closest?.(".header-row");let c,d,u,h,g,f;return s&&(c=parseInt(s.getAttribute("data-row")??"-1",10),d=parseInt(s.getAttribute("data-col")??"-1",10),c>=0&&d>=0&&(u=e._rows[c],f=e._visibleColumns[d],h=f?.field,g=u&&h?u[h]:void 0)),{type:i,row:u,rowIndex:void 0!==c&&c>=0?c:void 0,colIndex:void 0!==d&&d>=0?d:void 0,field:h,value:g,column:f,originalEvent:r,cellElement:s??void 0,rowElement:a??void 0,isHeader:!!l,cell:void 0!==c&&void 0!==d&&c>=0&&d>=0?{row:c,col:d}:void 0}}function rt(e,t,r,i){t.addEventListener("keydown",t=>function(e,t){if(e._dispatchKeyDown?.(t))return;const r=e._rows.length-1,i=e._visibleColumns.length-1,o=void 0!==e._activeEditRows&&-1!==e._activeEditRows,n=e._visibleColumns[e._focusCol],s=n?.type,a=t.composedPath?.()??[],l=a.length?a[0]:t.target;if((!l||l===e||l.closest?.(".rows-body"))&&(!Fe(l)||"Home"!==t.key&&"End"!==t.key)&&!(Fe(l)&&("ArrowUp"===t.key||"ArrowDown"===t.key)&&"INPUT"===l.tagName&&"number"===l.type||Fe(l)&&("ArrowLeft"===t.key||"ArrowRight"===t.key)||Fe(l)&&("Enter"===t.key||"Escape"===t.key)||o&&"select"===s&&("ArrowDown"===t.key||"ArrowUp"===t.key))){switch(t.key){case"Tab":return t.preventDefault(),t.shiftKey?e._focusCol>0?e._focusCol-=1:e._focusRow>0&&(e._activeEditRows===e._focusRow&&Ne(e),e._focusRow-=1,e._focusCol=i):e._focusCol<i?e._focusCol+=1:(Ne(e),e._focusRow<r&&(e._focusRow+=1,e._focusCol=0)),void qe(e);case"ArrowDown":o&&Ne(e),e._focusRow=Math.min(r,e._focusRow+1),t.preventDefault();break;case"ArrowUp":o&&Ne(e),e._focusRow=Math.max(0,e._focusRow-1),t.preventDefault();break;case"ArrowRight":{const r=xe(e);e._focusCol=r?Math.max(0,e._focusCol-1):Math.min(i,e._focusCol+1),t.preventDefault();break}case"ArrowLeft":{const r=xe(e);e._focusCol=r?Math.min(i,e._focusCol+1):Math.max(0,e._focusCol-1),t.preventDefault();break}case"Home":return t.ctrlKey||t.metaKey?(o&&Ne(e),e._focusRow=0,e._focusCol=0):e._focusCol=0,t.preventDefault(),void qe(e,{forceScrollLeft:!0});case"End":return t.ctrlKey||t.metaKey?(o&&Ne(e),e._focusRow=r,e._focusCol=i):e._focusCol=i,t.preventDefault(),void qe(e,{forceScrollRight:!0});case"PageDown":e._focusRow=Math.min(r,e._focusRow+20),t.preventDefault();break;case"PageUp":e._focusRow=Math.max(0,e._focusRow-20),t.preventDefault();break;case"Enter":{const r=e._focusRow,i=e._focusCol,o=e._visibleColumns[i],n=e._rows[r],s=o?.field??"",a=s&&n?n[s]:void 0,l=e.querySelector(`[data-row="${r}"][data-col="${i}"]`),c=new CustomEvent("cell-activate",{cancelable:!0,detail:{rowIndex:r,colIndex:i,column:o,field:s,value:a,row:n,cellEl:l,trigger:"keyboard",originalEvent:t}});if(e.dispatchEvent(c),c.defaultPrevented)return void t.preventDefault();break}default:return}qe(e)}}(e,t),{signal:i}),r.addEventListener("mousedown",t=>function(e,t,r){const i=tt(e,t,r,"mousedown");e._dispatchCellMouseDown?.(i)&&Je.set(e,!0)}(e,r,t),{signal:i}),document.addEventListener("mousemove",t=>function(e,t,r){if(!Je.get(e))return;const i=tt(e,t,r,"mousemove");e._dispatchCellMouseMove?.(i)}(e,r,t),{signal:i}),document.addEventListener("mouseup",t=>function(e,t,r){if(!Je.get(e))return;const i=tt(e,t,r,"mouseup");e._dispatchCellMouseUp?.(i),Je.set(e,!1)}(e,r,t),{signal:i})}let it;class ot{#e;#k=new Set;#L=new Map;#P=null;#D=null;constructor(e){this.#e=e,this.#I()}focusCell(e,t){const r=this.#e,i=r._rows.length-1;if(i<0)return;let o;if("string"==typeof t){if(o=r._visibleColumns.findIndex(e=>e.field===t),o<0)return}else o=t;const n=r._visibleColumns.length-1;n<0||(r._focusRow=Math.max(0,Math.min(e,i)),r._focusCol=Math.max(0,Math.min(o,n)),qe(r))}get focusedCell(){const e=this.#e;if(0===e._rows.length||0===e._visibleColumns.length)return null;const t=e._visibleColumns[e._focusCol];return{rowIndex:e._focusRow,colIndex:e._focusCol,field:t?.field??""}}scrollToRow(e,t){const r=this.#e._virtualization;if(!r.enabled)return;const i=r.container;if(!i)return;const o=this.#e._rows.length;if(0===o)return;const n=Math.max(0,Math.min(e,o-1)),s=t?.align??"nearest",a=t?.behavior??"instant";let l,c;const d=r.positionCache;r.variableHeights&&d&&d.length>n?(l=d[n].offset,c=d[n].height):(l=n*r.rowHeight,c=r.rowHeight);const u=r.viewportEl?.clientHeight??i.clientHeight??0;if(u<=0)return;const h=i.scrollTop,g=l+c,f=h+u;let p;switch(s){case"start":p=l;break;case"center":p=l-u/2+c/2;break;case"end":p=g-u;break;default:if(l>=h&&g<=f)return;p=l<h?l:g-u}p=Math.max(0,p);const w=ze(p,r.scrollMapping);"smooth"===a?i.scrollTo({top:w,behavior:"smooth"}):i.scrollTop=w}scrollToRowById(e,t){const r=this.#e._getRowEntry(e);r&&this.scrollToRow(r.index,t)}registerExternalFocusContainer(e){if(this.#k.has(e))return;this.#k.add(e);const t=new AbortController,r=t.signal,i=this.#e;e.addEventListener("focusin",e=>{i.dataset.hasFocus="",this.#O(e.target)},{signal:r}),e.addEventListener("focusout",e=>{const t=e.relatedTarget;t&&this.containsFocus(t)||delete i.dataset.hasFocus,null===t&&this.#z()},{signal:r}),this.#L.set(e,()=>t.abort())}unregisterExternalFocusContainer(e){this.#k.delete(e);const t=this.#L.get(e);t&&(t(),this.#L.delete(e))}containsFocus(e){const t=e??document.activeElement;return!!t&&(!!this.#e.contains(t)||this.isInExternalFocusContainer(t))}isInExternalFocusContainer(e){for(const t of this.#k)if(t.contains(e))return!0;return!1}#I(){const e=this.#e,t=new AbortController,r=t.signal;e.addEventListener("focusin",e=>this.#O(e.target),{signal:r,capture:!0}),e.addEventListener("focusout",e=>{null===e.relatedTarget&&this.#z()},{signal:r}),this.#D=()=>t.abort()}#O(e){if(!(e instanceof HTMLElement))return;if(e===this.#e)return;const t=e.closest?.(".cell");t&&!t.classList.contains("editing")||this.isInExternalFocusContainer(e)||(this.#P=e)}#z(){queueMicrotask(()=>{if(!this.#e.isConnected)return;document.activeElement===document.body&&this.restoreLastFocus()})}restoreLastFocus(){const e=this.#P;if(!e)return!1;if(!e.isConnected)return this.#P=null,!1;if(e===document.activeElement)return!0;try{e.focus({preventScroll:!0})}catch{return!1}return document.activeElement===e}get lastFocusedElement(){return this.#P?.isConnected?this.#P:null}destroy(){for(const e of this.#L.values())e();this.#L.clear(),this.#k.clear(),this.#D?.(),this.#D=null,this.#P=null}}const nt="function"==typeof requestIdleCallback;function st(e){nt?cancelIdleCallback(e):clearTimeout(e)}function at(e,t){if(t){const r=t({size:e});if("string"==typeof r){const e=document.createElement("div");return e.innerHTML=r,e}return r}return function(e){const t=document.createElement("div");return t.className=`tbw-spinner tbw-spinner--${e}`,t.setAttribute("role","progressbar"),t.setAttribute("aria-label","Loading"),t}(e)}function lt(e){let t=null,r=null,i=null,o=null;const n=i=>{if(!t)return;const o=i.clientX-t.startX,n=e._visibleColumns[t.colIndex],s="number"==typeof n?.minWidth&&Number.isFinite(n.minWidth)&&n.minWidth>0?n.minWidth:40,a=Math.max(s,t.startWidth+o);n.width=a,n.__userResized=!0,n.__renderedWidth=a,null==r&&(r=requestAnimationFrame(()=>{r=null,e.updateTemplate?.()})),e.dispatchEvent(new CustomEvent("column-resize",{detail:{field:n.field,width:a}}))};let s=!1;const a=()=>{const r=null!==t;r&&(s=!0,requestAnimationFrame(()=>{s=!1})),window.removeEventListener("mousemove",n),window.removeEventListener("mouseup",a),null!==i&&(document.documentElement.style.cursor=i,i=null),null!==o&&(document.body.style.userSelect=o,o=null),t=null,r&&e.requestStateChange&&e.requestStateChange()};return{get isResizing(){return null!==t||s},start(r,s,l){r.preventDefault();const c=e._headerRowEl??e.findHeaderRow?.();c&&function(t,r){const i=r.querySelectorAll(".cell");for(let o=0;o<e._visibleColumns.length;o++){if(o===t)continue;const r=e._visibleColumns[o];if(null==r.width&&!r.__userResized){const e=i[o],t=e?.getBoundingClientRect().width;t&&(r.width=Math.round(t),r.__userResized=!0,r.__renderedWidth=r.width)}}}(s,c);const d=e._visibleColumns[s],u="number"==typeof d?.width?d.width:void 0,h=d?.__renderedWidth??u??l.getBoundingClientRect().width;t={startX:r.clientX,colIndex:s,startWidth:h},window.addEventListener("mousemove",n),window.addEventListener("mouseup",a),null===i&&(i=document.documentElement.style.cursor),document.documentElement.style.cursor="e-resize",null===o&&(o=document.body.style.userSelect),document.body.style.userSelect="none"},resetColumn(t){const r=e._visibleColumns[t];r&&(r.__userResized=!1,r.__renderedWidth=void 0,r.width=r.__originalWidth,e.updateTemplate?.(),e.requestStateChange?.(),e.dispatchEvent(new CustomEvent("column-resize-reset",{detail:{field:r.field,width:r.width}})))},dispose(){a()}}}const ct="data-animating",dt={change:"--tbw-row-change-duration",insert:"--tbw-row-insert-duration",remove:"--tbw-row-remove-duration"},ut={change:500,insert:300,remove:200};function ht(e,t){const r=dt[t],i=getComputedStyle(e).getPropertyValue(r);if(i){const e=function(e){const t=e.trim().toLowerCase();return t.endsWith("ms")?parseFloat(t):t.endsWith("s")?1e3*parseFloat(t):parseFloat(t)}(i);if(!isNaN(e)&&e>0)return e}return ut[t]}function gt(e,t,r){if(t<0)return Promise.resolve(!1);const i=e.findRenderedRowElement?.(t);return i?new Promise(e=>{!function(e,t,r){e.removeAttribute(ct),e.offsetWidth,e.setAttribute(ct,t);const i=ht(e,t);setTimeout(()=>{"remove"!==t&&e.removeAttribute(ct),r?.()},i)}(i,r,()=>e(!0))}):Promise.resolve(!1)}function ft(e,t){if(t)return t(e);const r=e;return"id"in r&&null!=r.id?String(r.id):"_id"in r&&null!=r._id?String(r._id):void 0}function pt(e,t,r){const i=ft(e,r);return void 0===i&&b("TBW040",'Cannot determine row ID. Configure getRowId in gridConfig or ensure rows have an "id" property.',t),i}class wt{#e;constructor(e){this.#e=e}resolveRowId(e){return pt(e,this.#e.id,this.#e.effectiveConfig?.getRowId)}getRow(e){return this.#e._getRowEntry(e)?.row}getRowEntry(e){return this.#e._getRowEntry(e)}#N(e,t,r,i,o){const n=this.#e,s=[];for(const[a,l]of Object.entries(i)){if("__proto__"===a||"constructor"===a||"prototype"===a)continue;const c=t[a];if(c===l)continue;const d=n.query?.("commitCellValue",{rowIndex:r,rowId:e,field:a,oldValue:c,newValue:l,source:o});d?.includes(!1)||(d?.includes(!0)||(t[a]=l,K(t,a)),s.push({field:a,oldValue:c,newValue:l}),n.dispatchEvent(new CustomEvent("cell-change",{detail:{row:t,rowId:e,rowIndex:r,field:a,oldValue:c,newValue:l,changes:i,source:o},bubbles:!0,composed:!0})))}return s}updateRow(e,t,r="api"){const i=this.#e,o=i._getRowEntry(e);o||b(f,`Row with ID "${e}" not found. Ensure the row exists and getRowId is correctly configured.`,i.id);const{row:n,index:s}=o;this.#N(e,n,s,t,r).length>0&&(Xe(i),i._requestSchedulerPhase(fe.VIRTUALIZATION,"updateRow"),i._emitDataChange())}updateRows(e,t="api"){const r=this.#e;let i=!1;for(const{id:o,changes:n}of e){const e=r._getRowEntry(o);e||b(f,`Row with ID "${o}" not found. Ensure the row exists and getRowId is correctly configured.`,r.id);const{row:s,index:a}=e;this.#N(o,s,a,n,t).length>0&&(i=!0)}i&&(Xe(r),r._requestSchedulerPhase(fe.VIRTUALIZATION,"updateRows"),r._emitDataChange())}async insertRow(e,t,r=!0){const i=this.#e,o=Math.max(0,Math.min(e,i._rows.length));i.sourceRows=[...i.sourceRows,t];const n=[...i._rows];n.splice(o,0,t),i._rows=n,i._sortState&&(i.__originalOrder=[...i.__originalOrder,t]),Xe(i),i._rebuildRowIdMap(),i.__rowRenderEpoch++;for(let s=0;s<i._rowPool.length;s++)i._rowPool[s].__epoch=-1;i.refreshVirtualWindow(!0),i._emitPluginEvent("row-inserted",{row:t,index:o}),i._emitDataChange(),r&&(await new Promise(e=>requestAnimationFrame(()=>e())),await gt(i,o,"insert"))}async removeRow(e,t=!0){const r=this.#e,i=r._rows[e];if(!i)return;t&&await gt(r,e,"remove");const o=r._rows.indexOf(i);if(o<0)return i;const n=[...r._rows];n.splice(o,1),r._rows=n;const s=r.sourceRows.indexOf(i);if(s>=0){const e=[...r.sourceRows];e.splice(s,1),r.sourceRows=e}if(r._sortState){const e=r.__originalOrder.indexOf(i);if(e>=0){const t=[...r.__originalOrder];t.splice(e,1),r.__originalOrder=t}}Xe(r),r._rebuildRowIdMap(),r.__rowRenderEpoch++;for(let a=0;a<r._rowPool.length;a++)r._rowPool[a].__epoch=-1;return r.refreshVirtualWindow(!0),r._emitDataChange(),t&&requestAnimationFrame(()=>{const e=r.querySelectorAll('[data-animating="remove"]');for(let t=0;t<e.length;t++)e[t].removeAttribute("data-animating")}),i}async applyTransaction(e,t=!0){const r=this.#e,i={added:[],updated:[],removed:[]};if(e.remove?.length)for(const{id:a}of e.remove){const e=r._getRowEntry(a);if(!e)continue;const{row:o}=e;if(t){const e=r._rows.indexOf(o);e>=0&&await gt(r,e,"remove")}const n=r._rows.indexOf(o);if(n<0){i.removed.push(o);continue}const s=[...r._rows];s.splice(n,1),r._rows=s;const l=r.sourceRows.indexOf(o);if(l>=0){const e=[...r.sourceRows];e.splice(l,1),r.sourceRows=e}if(r._sortState){const e=r.__originalOrder.indexOf(o);if(e>=0){const t=[...r.__originalOrder];t.splice(e,1),r.__originalOrder=t}}i.removed.push(o)}const o=new Set(e.remove?.map(e=>e.id));if(e.update?.length)for(const{id:a,changes:l}of e.update){if(o.has(a))continue;const e=r._getRowEntry(a);if(!e)continue;const{row:t,index:n}=e;let s=!1;for(const[i,o]of Object.entries(l)){const e=t[i];e!==o&&(s=!0,t[i]=o,K(t,i),r.dispatchEvent(new CustomEvent("cell-change",{detail:{row:t,rowId:a,rowIndex:n,field:i,oldValue:e,newValue:o,changes:l,source:"api"},bubbles:!0,composed:!0})))}s&&i.updated.push(t)}if(e.add?.length)for(const a of e.add){r.sourceRows=[...r.sourceRows,a];const e=[...r._rows];e.push(a),r._rows=e,r._sortState&&(r.__originalOrder=[...r.__originalOrder,a]),i.added.push(a)}const n=i.added.length>0||i.removed.length>0,s=i.updated.length>0;if(n){Xe(r),r._rebuildRowIdMap(),r.__rowRenderEpoch++;for(let e=0;e<r._rowPool.length;e++)r._rowPool[e].__epoch=-1;r.refreshVirtualWindow(!0)}else s&&(Xe(r),r._requestSchedulerPhase(fe.VIRTUALIZATION,"applyTransaction"));if((n||s)&&r._emitDataChange(),t&&i.added.length>0){await new Promise(e=>requestAnimationFrame(()=>e()));for(const e of i.added){const t=r._rows.indexOf(e);t>=0&&await gt(r,t,"insert")}}if(t&&i.updated.length>0)for(const a of i.updated){const e=r._rows.indexOf(a);e>=0&&await gt(r,e,"change")}return t&&i.removed.length>0&&requestAnimationFrame(()=>{const e=r.querySelectorAll('[data-animating="remove"]');for(let t=0;t<e.length;t++)e[t].removeAttribute("data-animating")}),i}#F=null;#q=[];#$=null;applyTransactionAsync(e){return this.#F||(this.#F={add:[],update:[],remove:[]}),e.add&&this.#F.add.push(...e.add),e.update&&this.#F.update.push(...e.update),e.remove&&this.#F.remove.push(...e.remove),new Promise(e=>{this.#q.push(e),null===this.#$&&(this.#$=requestAnimationFrame(()=>{this.#$=null;const e=this.#F,t=this.#q;this.#F=null,this.#q=[],this.applyTransaction(e,!1).then(e=>{for(const r of t)r(e)})}))})}}const mt="tbw-grid";let bt=mt;function vt(){return bt}const yt="tbw-grid-styles";let _t="";const Ct=new Map;function Rt(){const e=function(){const e=vt();return e===mt?yt:`${yt}-${e}`}();let t=document.getElementById(e);return t||(t=document.createElement("style"),t.id=e,t.setAttribute("data-tbw-grid","true"),document.head.appendChild(t)),t}function Et(e){const t=vt();return t===mt?e:e.replace(new RegExp("(?<![-\\w])tbw-grid(?![-\\w])","g"),t)}function St(){const e=Rt(),t=Array.from(Ct.values()).join("\n");e.textContent=`${_t}\n\n/* Plugin Styles */\n${t}`}async function At(e){if(_t)return;if("string"==typeof e&&e.length>0)return _t=Et(e),void St();await new Promise(e=>setTimeout(e,50));const t=function(){try{for(const e of Array.from(document.styleSheets))try{const t=Array.from(e.cssRules||[]).map(e=>e.cssText).join("\n");if(t.includes(".tbw-grid-root")&&t.includes("tbw-grid"))return t}catch{continue}}catch(e){v("TBW120",`Failed to extract grid.css from document stylesheets: ${e}`)}return null}();t?(_t=Et(t),St()):"undefined"!=typeof process&&"test"===process.env?.NODE_ENV||v("TBW121",`Could not find grid.css in document.styleSheets. Grid styling will not work. Available stylesheets: ${Array.from(document.styleSheets).map(e=>e.href||"(inline)").join(", ")}`)}function Mt(e){e.startY=null,e.startX=null,e.lastY=null,e.lastX=null,e.lastTime=null,e.locked=!1}function xt(e){e.momentumRaf&&(cancelAnimationFrame(e.momentumRaf),e.momentumRaf=0)}function Ht(e,t){if(null!==e.lastTime){performance.now()-e.lastTime>60&&(e.velocityY=0,e.velocityX=0)}(Math.abs(e.velocityY)>.1||Math.abs(e.velocityX)>.1)&&function(e,t){const r=.95,i=1;let o=performance.now();const n=()=>{const s=performance.now(),a=s-o;o=s;const l=a/16,c=Math.pow(r,l);e.velocityY*=c,e.velocityX*=c;const d=16*e.velocityY,u=16*e.velocityX,h=Math.abs(d)>=i,g=Math.abs(u)>=i;h&&(t.fauxScrollbar.scrollTop+=d),g&&t.scrollArea&&(t.scrollArea.scrollLeft+=u),e.momentumRaf=h||g?requestAnimationFrame(n):0};e.momentumRaf=requestAnimationFrame(n)}(e,t),Mt(e)}function Tt(e,t,r,i){e.addEventListener("pointerdown",r=>{"touch"===r.pointerType&&null===t.activePointerId&&(t.activePointerId=r.pointerId,e.setPointerCapture(r.pointerId),function(e,t,r){xt(r),r.startY=t,r.startX=e,r.lastY=t,r.lastX=e,r.lastTime=performance.now(),r.velocityY=0,r.velocityX=0,r.locked=!1}(r.clientX,r.clientY,t))},{passive:!0,signal:i}),e.addEventListener("pointermove",e=>{if(e.pointerId!==t.activePointerId)return;const i=function(e,t,r,i){if(null===r.lastY||null===r.lastX)return!1;const o=performance.now(),n=r.lastY-t,s=r.lastX-e;if(null!==r.lastTime){const e=o-r.lastTime;e>0&&(r.velocityY=n/e,r.velocityX=s/e)}if(r.lastY=t,r.lastX=e,r.lastTime=o,r.locked){const{scrollTop:e,scrollHeight:t,clientHeight:r}=i.fauxScrollbar;if(n>0&&e<t-r||n<0&&e>0?i.fauxScrollbar.scrollTop+=n:0!==n&&window.scrollBy(0,n),i.scrollArea){const{scrollLeft:e,scrollWidth:t,clientWidth:r}=i.scrollArea;s>0&&e<t-r||s<0&&e>0?i.scrollArea.scrollLeft+=s:0!==s&&window.scrollBy(s,0)}return!0}const a=null!==r.startY?Math.abs(r.startY-t):0,l=null!==r.startX?Math.abs(r.startX-e):0;if(a<3&&l<3)return!1;const c=a>=l,{scrollHeight:d,clientHeight:u}=i.fauxScrollbar,h=d-u>0;let g=!1;if(i.scrollArea){const{scrollWidth:e,clientWidth:t}=i.scrollArea;g=e-t>0}return!!(c&&h||!c&&g)&&(r.locked=!0,i.fauxScrollbar.scrollTop+=n,i.scrollArea&&(i.scrollArea.scrollLeft+=s),!0)}(e.clientX,e.clientY,t,r);i&&e.preventDefault()},{passive:!1,signal:i}),e.addEventListener("pointerup",e=>{e.pointerId===t.activePointerId&&(t.activePointerId=null,Ht(t,r))},{passive:!0,signal:i}),e.addEventListener("pointercancel",e=>{e.pointerId===t.activePointerId&&(t.activePointerId=null,Mt(t))},{passive:!0,signal:i}),e.addEventListener("lostpointercapture",e=>{e.pointerId===t.activePointerId&&(t.activePointerId=null,Mt(t))},{passive:!0,signal:i})}const kt=[{property:"editable",pluginName:"editing",level:"column",description:"",isUsed:e=>!0===e||"function"==typeof e},{property:"editor",pluginName:"editing",level:"column",description:""},{property:"editorParams",pluginName:"editing",level:"column",description:""},{property:"group",pluginName:"groupingColumns",level:"column",description:""},{property:"pinned",pluginName:"pinnedColumns",level:"column",description:"",isUsed:e=>"left"===e||"right"===e||"start"===e||"end"===e}],Lt=[{property:"rowEditable",pluginName:"editing",level:"config",description:"",isUsed:e=>"function"==typeof e},{property:"columnGroups",pluginName:"groupingColumns",level:"config",description:"",isUsed:e=>Array.isArray(e)&&e.length>0}];function Pt(e){return`import { ${Dt(e)}Plugin } from '@toolbox-web/grid/plugins/${t=e,t.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}';`;var t}function Dt(e){return e.charAt(0).toUpperCase()+e.slice(1)}function It(e,t){return e.some(e=>e.name===t)}class Ot{#e;state;constructor(e,t){this.#e=e,this.state={enabled:!0,rowHeight:28,bypassThreshold:24,start:0,end:0,container:null,viewportEl:null,totalHeightEl:null,positionCache:null,heightCache:{byKey:new Map,byRef:new WeakMap},averageHeight:28,measuredCount:0,variableHeights:!1,cachedViewportHeight:0,cachedFauxHeight:0,cachedScrollAreaHeight:0,scrollAreaEl:null,scrollMapping:{rawContentHeight:0,spacerHeight:0,viewportHeight:0,capped:!1},...t}}updateCachedGeometry(){const e=this.state,t=e.container,r=e.viewportEl??t;r&&(e.cachedViewportHeight=r.clientHeight),t&&(e.cachedFauxHeight=t.clientHeight);const i=e.scrollAreaEl;i&&(e.cachedScrollAreaHeight=i.clientHeight)}calculateTotalSpacerHeight(e,t=!1){const r=this.state;let i,o,n;if(t){const e=r.container??this.#e._hostElement,t=r.viewportEl??e,s=r.scrollAreaEl;i=e?.clientHeight??0,o=t?.clientHeight??0,n=s?s.clientHeight:i,r.cachedFauxHeight=i,r.cachedViewportHeight=o,r.cachedScrollAreaHeight=n}else i=r.cachedFauxHeight,o=r.cachedViewportHeight,n=r.cachedScrollAreaHeight||i;const s=n-o,a=Math.max(0,i-n);let l;return l=r.variableHeights&&r.positionCache?function(e){if(0===e.length)return 0;const t=e[e.length-1];return t.offset+t.height}(r.positionCache):e*r.rowHeight,r.scrollMapping=Ie(l,o),r.scrollMapping.spacerHeight+s+a}initializePositionCache(){const e=this.state;if(!e.variableHeights)return;const t=this.#e,r=t._rows,i=e.rowHeight||28,o=t.effectiveConfig?.rowHeight,n=t.effectiveConfig?.getRowId,s=n?e=>n(e):void 0;e.positionCache=function(e,t,r,i,o){const n=new Array(e.length);let s=0;for(let a=0;a<e.length;a++){const l=e[a];let c=o?.(l,a),d=void 0!==c;void 0===c&&(c=Te(t,l,i.rowId),d=void 0!==c),void 0===c&&(c=r,d=!1),n[a]={offset:s,height:c,measured:d},s+=c}return n}(r,e.heightCache,i,{rowId:s},(e,r)=>{const i=t._getPluginRowHeight(e,r);if(void 0!==i)return i;if(o){const t=o(e,r);if(void 0!==t&&t>0)return t}});const a=function(e,t,r,i){let o=0,n=0;for(let s=0;s<e.length;s++){const r=e[s];if(r.measured){const e=i?.(t[s],s);void 0===e&&(n+=r.height,o++)}}return{measuredCount:o,averageHeight:o>0?n/o:r}}(e.positionCache,r,i,(e,r)=>t._getPluginRowHeight(e,r));e.measuredCount=a.measuredCount,a.measuredCount>0&&(e.averageHeight=a.averageHeight)}invalidateRowHeight(e,t){const r=this.state;if(!r.variableHeights)return;if(!r.positionCache)return;const i=this.#e._rows;if(e<0||e>=i.length)return;const o=i[e];let n=t;void 0===n&&(n=this.#e._getPluginRowHeight(o,e)),void 0===n&&(n=r.rowHeight);const s=r.positionCache[e];if(s&&!(Math.abs(s.height-n)<1)&&(ke(r.positionCache,e,n),r.totalHeightEl)){const e=this.calculateTotalSpacerHeight(i.length);r.totalHeightEl.style.height=`${e}px`}}measureRenderedRowHeights(e,t){const r=this.state;if(!r.variableHeights)return;if(!r.positionCache)return;const i=this.#e,o=i._bodyEl;if(!o)return;const n=o.querySelectorAll(".data-grid-row"),s=i.effectiveConfig?.getRowId,a=i._rows,l=Pe({positionCache:r.positionCache,heightCache:r.heightCache,rows:a,defaultHeight:r.rowHeight,start:e,end:t,getPluginHeight:(e,t)=>i._getPluginRowHeight(e,t),getRowId:s?e=>s(e):void 0},n);if(l.hasChanges&&(r.measuredCount=l.measuredCount,r.averageHeight=l.averageHeight,r.totalHeightEl)){const e=this.calculateTotalSpacerHeight(a.length);r.totalHeightEl.style.height=`${e}px`}}refreshVirtualWindow(e=!1,t=!1){const r=this.state,i=this.#e,o=i._bodyEl;if(!o)return!1;const n=i._rows.length;if(!r.enabled)return i._renderVisibleRows(0,n),t||i._afterPluginRender(),!0;if(n<=r.bypassThreshold)return r.start=0,r.end=n,e&&(o.style.transform="translateY(0px)"),i._renderVisibleRows(0,n,i.__rowRenderEpoch),e&&r.variableHeights&&this.initializePositionCache(),e&&r.totalHeightEl&&(r.totalHeightEl.style.height=`${this.calculateTotalSpacerHeight(n,!0)}px`),i._updateAriaCounts(n,i._visibleColumns.length),t||i._afterPluginRender(),!0;const s=r.container,a=r.viewportEl??s,l=e?r.cachedViewportHeight=a.clientHeight:r.cachedViewportHeight||(r.cachedViewportHeight=a.clientHeight),c=r.rowHeight,d=Oe(s.scrollTop,r.scrollMapping);let u;e&&r.variableHeights&&this.initializePositionCache();const h=r.positionCache;r.variableHeights&&h&&h.length>0?(u=Le(h,d),-1===u&&(u=0)):u=Math.floor(d/c),u-=u%2,u<0&&(u=0),n>0&&u>n-1&&(u=n-1);const g=i._adjustPluginVirtualStart(u,d,c);let f;if(void 0!==g&&g<u&&(u=g,u-=u%2,u<0&&(u=0)),r.variableHeights&&h&&h.length>0){const e=l+3*c;let t=0;for(f=u;f<n&&t<e;)t+=h[f].height,f++;const r=Math.ceil(l/c)+3;f-u<r&&(f=Math.min(u+r,n))}else{f=u+(Math.ceil(l/c)+3)}f>n&&(f=n);const p=r.start,w=r.end;if(!e&&u===p&&f===w)return!1;r.start=u,r.end=f;const m=e?r.cachedFauxHeight=s.clientHeight:r.cachedFauxHeight||(r.cachedFauxHeight=s.clientHeight);if(e){const e=r.scrollAreaEl;e&&(r.cachedScrollAreaHeight=e.clientHeight)}if(0===m&&l>0)return i._requestSchedulerPhase(fe.VIRTUALIZATION,"stale-refs-retry"),!1;if(e&&r.totalHeightEl){const e=this.calculateTotalSpacerHeight(n);r.totalHeightEl.style.height=`${e}px`}let b;b=r.variableHeights&&h&&h[u]?h[u].offset:u*c;const v=-(d-b);return o.style.transform=`translateY(${v}px)`,i._renderVisibleRows(u,f,i.__rowRenderEpoch),e&&r.variableHeights&&this.measureRenderedRowHeights(u,f),i._updateAriaCounts(n,i._visibleColumns.length),e&&!t&&(i._afterPluginRender(),queueMicrotask(()=>{if(!r.totalHeightEl)return;const e=this.calculateTotalSpacerHeight(n);0===r.cachedFauxHeight&&r.cachedViewportHeight>0||(r.totalHeightEl.style.height=`${e}px`)})),!0}}class zt{constructor(e){this.grid=e}plugins=[];getPlugins(){return this.plugins}pluginMap=new Map;cellRenderers=new Map;headerRenderers=new Map;cellEditors=new Map;_hasAfterCellRender=!1;_hasAfterRowRender=!1;_hasProcessRows=!1;_hasRowStructurePlugins=!1;#W=new Map;eventListeners=new Map;queryHandlers=new Map;attachAll(e){const t=this.#V(e);for(const r of t)this.attach(r)}#V(e){if(e.length<2)return e;const t=new Map,r=new Map,i=[];for(const o of e){const e=o.constructor,n=t.get(e);if(!n){t.set(e,o),i.push(o);continue}const s=r.get(n)??[];s.push(o),r.set(n,s)}if(0===r.size)return i;for(const[o,n]of r)o.mergeConfigsFrom(n);return i}attach(e){if(function(e,t,r){const i=e.name,o=e.constructor.dependencies??[];for(const n of o){if(n.when&&!n.when(e.resolvedConfig))continue;const o=n.name,s=n.required??!0,a=n.reason;if(t.some(e=>e.name===o))continue;const l=n.severity??(s?"error":void 0);if(!l)continue;const c="error"===l?"requires":"recommends",d=a??`${Dt(i)}Plugin ${c} ${Dt(o)}Plugin`;if("error"===l){const e=Pt(o);b("TBW020",`Plugin dependency error:\n\n${d}.\n\n → Add the plugin to your gridConfig.plugins array BEFORE ${Dt(i)}Plugin:\n ${e}\n plugins: [new ${Dt(o)}Plugin(), new ${Dt(i)}Plugin()]`,r)}else Re()&&("warn"===l?v(g,`${d}.`,r):y(g,`${d}.`,r))}}(e,this.plugins,this.grid.getAttribute("id")??void 0),this.pluginMap.set(e.constructor,e),this.plugins.push(e),e.cellRenderers)for(const[t,r]of Object.entries(e.cellRenderers))this.cellRenderers.set(t,r);if(e.headerRenderers)for(const[t,r]of Object.entries(e.headerRenderers))this.headerRenderers.set(t,r);if(e.cellEditors)for(const[t,r]of Object.entries(e.cellEditors))this.cellEditors.set(t,r);this.registerQueryHandlers(e),e.attach(this.grid),this.#U();for(const t of this.plugins)t!==e&&t.onPluginAttached&&t.onPluginAttached(e.name,e)}registerQueryHandlers(e){const t=e.constructor.manifest;if(t?.queries)for(const r of t.queries){let t=this.queryHandlers.get(r.type);t||(t=new Set,this.queryHandlers.set(r.type,t)),t.add(e)}}unregisterQueryHandlers(e){for(const[t,r]of this.queryHandlers)r.delete(e),0===r.size&&this.queryHandlers.delete(t)}detachAll(){for(const e of this.plugins)for(const t of this.plugins)t!==e&&t.onPluginDetached&&t.onPluginDetached(e.name);for(let e=this.plugins.length-1;e>=0;e--){const t=this.plugins[e];this.unsubscribeAll(t),this.unregisterQueryHandlers(t),t.detach()}this.plugins=[],this.pluginMap.clear(),this.cellRenderers.clear(),this.headerRenderers.clear(),this.cellEditors.clear(),this.eventListeners.clear(),this.queryHandlers.clear(),this._hasAfterCellRender=!1,this._hasAfterRowRender=!1,this._hasProcessRows=!1,this.#W.clear()}getPlugin(e){return this.pluginMap.get(e)}getPluginByName(e){return this.plugins.find(t=>t.name===e||t.aliases?.includes(e))}hasPlugin(e){return this.pluginMap.has(e)}getAll(){return this.plugins}getRegisteredPluginNames(){return this.plugins.map(e=>e.name)}getCellRenderer(e){return this.cellRenderers.get(e)}getHeaderRenderer(e){return this.headerRenderers.get(e)}getCellEditor(e){return this.cellEditors.get(e)}getPluginStyles(){return this.plugins.filter(e=>e.styles).map(e=>({name:e.name,styles:e.styles}))}processRows(e){if(!this._hasProcessRows)return e;let t=e;for(const r of this.#B("processRows")){const e=r.processRows(t);e!==t&&(t=e)}return t}processColumns(e){let t=[...e];for(const r of this.#B("processColumns"))t=r.processColumns(t);return t}processConfig(e){for(const t of this.#B("processConfig"))t.processConfig(e)}beforeRender(){for(const e of this.plugins)e.beforeRender?.()}afterStructuralRender(){for(const e of this.#B("afterStructuralRender"))e.afterStructuralRender()}beforeStructuralRender(){for(const e of this.plugins)e.beforeStructuralRender?.()}parseLightDom(){for(const e of this.plugins)e.parseLightDom?.()}syncLightDom(){for(const e of this.plugins)e.syncLightDom?.()}needsStructuralRerender(){let e=!1;for(const t of this.plugins)t.needsStructuralRerender?.()&&(e=!0);return e}afterRender(){for(const e of this.#B("afterRender"))e.afterRender()}afterCellRender(e){for(const t of this.#B("afterCellRender"))t.afterCellRender(e)}hasAfterCellRenderHook(){return this._hasAfterCellRender}afterRowRender(e){for(const t of this.#B("afterRowRender"))t.afterRowRender(e)}hasAfterRowRenderHook(){return this._hasAfterRowRender}#U(){this._hasAfterCellRender=this.plugins.some(e=>"function"==typeof e.afterCellRender),this._hasAfterRowRender=this.plugins.some(e=>"function"==typeof e.afterRowRender),this._hasProcessRows=this.plugins.some(e=>"function"==typeof e.processRows),this._hasRowStructurePlugins=this.plugins.some(e=>!0===e.constructor.manifest?.modifiesRowStructure),this.#W.clear()}#B(e){let t=this.#W.get(e);if(t)return t;t=this.plugins.filter(t=>e in t&&"function"==typeof t[e]);const r=t=>{const r=t.constructor.manifest?.hookPriority;if(!r)return 0;return r[e]??0};return t.some(e=>0!==r(e))&&t.sort((e,t)=>r(e)-r(t)),this.#W.set(e,t),t}onScrollRender(){for(const e of this.#B("onScrollRender"))e.onScrollRender()}getRowHeight(e,t){for(const r of this.plugins)if("function"==typeof r.getRowHeight){const i=r.getRowHeight(e,t);if(void 0!==i)return i}}hasRowHeightPlugin(){for(const e of this.plugins)if("function"==typeof e.getRowHeight)return!0;return!1}adjustVirtualStart(e,t,r){let i=e;for(const o of this.plugins)if("function"==typeof o.adjustVirtualStart){const n=o.adjustVirtualStart(e,t,r);n<i&&(i=n)}return i}renderRow(e,t,r){for(const i of this.plugins)if(i.renderRow?.(e,t,r))return!0;return!1}queryPlugins(e){const t=[],r=this.queryHandlers.get(e.type);if(r&&r.size>0){for(const i of r){const r=i.handleQuery?.(e);void 0!==r&&t.push(r)}return t}for(const i of this.plugins){const r=i.handleQuery?.(e);void 0!==r&&t.push(r)}return t}subscribe(e,t,r){let i=this.eventListeners.get(t);i||(i=new Map,this.eventListeners.set(t,i)),i.set(e,r)}unsubscribe(e,t){const r=this.eventListeners.get(t);r&&(r.delete(e),0===r.size&&this.eventListeners.delete(t))}unsubscribeAll(e){for(const[t,r]of this.eventListeners)r.delete(e),0===r.size&&this.eventListeners.delete(t)}emitPluginEvent(e,t){const r=this.eventListeners.get(e);if(r)for(const o of r.values())try{o(t)}catch(i){_("TBW024",`Error in plugin event handler for "${e}": ${i}`,this.grid.getAttribute("id")??void 0)}}onKeyDown(e){for(const t of this.#B("onKeyDown"))if(t.onKeyDown(e))return!0;return!1}onCellClick(e){for(const t of this.#B("onCellClick"))if(t.onCellClick(e))return!0;return!1}onRowClick(e){for(const t of this.#B("onRowClick"))if(t.onRowClick(e))return!0;return!1}onHeaderClick(e){for(const t of this.#B("onHeaderClick"))if(t.onHeaderClick(e))return!0;return!1}onScroll(e){for(const t of this.#B("onScroll"))t.onScroll(e)}onCellMouseDown(e){for(const t of this.#B("onCellMouseDown"))if(t.onCellMouseDown(e))return!0;return!1}onCellMouseMove(e){for(const t of this.#B("onCellMouseMove"))if(t.onCellMouseMove(e))return!0;return!1}onCellMouseUp(e){for(const t of this.#B("onCellMouseUp"))if(t.onCellMouseUp(e))return!0;return!1}getHorizontalScrollOffsets(e,t){let r=0,i=0,o=!1;for(const n of this.plugins){const s=n.getHorizontalScrollOffsets?.(e,t);s&&(r+=s.left,i+=s.right,s.skipScroll&&(o=!0))}return{left:r,right:i,skipScroll:o}}getToolPanels(){const e=[];for(const t of this.plugins){const r=t.getToolPanel?.();r&&e.push({plugin:t,panel:r})}return e.sort((e,t)=>(e.panel.order??0)-(t.panel.order??0))}getHeaderContents(){const e=[];for(const t of this.plugins){const r=t.getHeaderContent?.();r&&e.push({plugin:t,content:r})}return e.sort((e,t)=>(e.content.order??0)-(t.content.order??0))}}class Nt extends HTMLElement{static tagName=mt;static version="3.0.0-beta.4";static get activeTag(){return vt()}static set activeTag(e){!function(e){bt=e}(e)}static#G=0;static adapters=[];static registerAdapter(e){this.adapters.push(e)}static getAdapters(){return this.adapters}static clearAdapters(){this.adapters=[]}static get observedAttributes(){return["rows","columns","grid-config","fit-mode","column-inference","loading"]}get#j(){return this}#Y=!1;#i;#o;#X=[];get#b(){return this.#K?.effective??{}}#Z=!1;#Q=!1;#J={rows:!1,columns:!1,gridConfig:!1,fitMode:!1,columnInference:!1};#ee;#te=0;#re=null;#ie=!1;#oe=!1;#ne=0;#se;#ae={startY:null,startX:null,lastY:null,lastX:null,lastTime:null,velocityY:0,velocityX:0,momentumRaf:0,locked:!1,activePointerId:null};#le;#ce;#de;#ue;#he={scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0};#ge;#fe;#pe;#we;#me;#be;get _pluginManager(){return this.#ge}#ve=!1;#ye;#_e;#E;#K;#Ce=new Map;#Re=!1;#Ee=new Set;#Se=new Map;#Ae;#Me={};#xe=new Map;#He=!1;_rows=[];#Te=[];get _columns(){return this.#b.columns??[]}set _columns(e){this.#b.columns=e,this.#ke=void 0}#ke;get _visibleColumns(){return this.#ke??=this._columns.filter(e=>!e.hidden)}_invalidateVisibleColumnsCache(){this.#ke=void 0}_headerRowEl;_bodyEl;_rowPool=[];_resizeController;get _virtualization(){return this.#we.state}set _virtualization(e){Object.assign(this.#we.state,e)}_focusRow=0;_focusCol=0;_restoreFocusAfterRender=!1;_sortState=null;_gridTemplate="";__rowRenderEpoch=0;__didInitialAutoSize=!1;get __lightDomColumnsCache(){return this.#K?.lightDomColumnsCache}set __lightDomColumnsCache(e){this.#K&&(this.#K.lightDomColumnsCache=e)}get __originalColumnNodes(){return this.#K?.originalColumnNodes}set __originalColumnNodes(e){this.#K&&(this.#K.originalColumnNodes=e)}__originalOrder=[];__frameworkAdapter;__rowsBodyEl=null;get rows(){return this._rows}set rows(e){const t=Array.isArray(e)?e:[],r=this.#X;this.#X=t,r!==t&&this.#Le("rows")}get sourceRows(){return this.#X}set sourceRows(e){this.#X=Array.isArray(e)?e:[]}get columns(){return[...this._columns]}set columns(e){const t=Array.isArray(e)?u(e):e,r=this.#K?.getColumns();this.#K?.setColumns(t),r!==t&&this.#Le("columns")}get gridConfig(){return this.#b}set gridConfig(e){e&&this.__frameworkAdapter?.processConfig&&(e=this.__frameworkAdapter.processConfig(e));const t=this.#K?.getGridConfig();this.#K?.setGridConfig(e),t!==e&&(this.#K.clearLightDomCache(),this.#Le("gridConfig"))}get _sourceConfig(){return this.#K?.getGridConfig()}get fitMode(){return this.#b.fitMode??"stretch"}set fitMode(e){const t=this.#K?.getFitMode();this.#K?.setFitMode(e),t!==e&&this.#Le("fitMode")}get columnInference(){return this.#b.columnInference??"auto"}set columnInference(e){const t=this.#K?.getColumnInference();this.#K?.setColumnInference(e),t!==e&&this.#Le("columnInference")}get loading(){return this.#Re}set loading(e){const t=this.#Re;this.#Re=e,t!==e&&(e?(this.setAttribute("loading",""),this.setAttribute("aria-busy","true")):(this.removeAttribute("loading"),this.removeAttribute("aria-busy")),this.#Pe(),this.#De())}setRowLoading(e,t){const r=this.#Ee.has(e);t?this.#Ee.add(e):this.#Ee.delete(e),r!==t&&this.#Ie(e,t)}setCellLoading(e,t,r){let i=this.#Se.get(e);const o=i?.has(t)??!1;r?(i||(i=new Set,this.#Se.set(e,i)),i.add(t)):(i?.delete(t),0===i?.size&&this.#Se.delete(e)),o!==r&&this.#Oe(e,t,r)}isRowLoading(e){return this.#Ee.has(e)}isCellLoading(e,t){return this.#Se.get(e)?.has(t)??!1}clearAllLoading(){this.loading=!1;for(const e of this.#Ee)this.#Ie(e,!1);this.#Ee.clear();for(const[e,t]of this.#Se)for(const r of t)this.#Oe(e,r,!1);this.#Se.clear()}get effectiveConfig(){return this.#b}get disconnectSignal(){return this.#le||(this.#le=new AbortController),this.#le.signal}constructor(){super(),this.#ze(),this.#i=new Promise(e=>this.#o=e),this.#we=new Ot(this),this.#me=new ot(this),this.#be=new wt(this),this.#ee=new pe(this),this.#ee.setInitialReadyResolver(()=>this.#o?.()),this.#K=new we(this)}async#ze(){await At('@layer tbw-base, tbw-plugins, tbw-theme;\n\n@layer tbw-base{tbw-grid{--tbw-base-icon-size: 1em;--tbw-base-radius: .25em;--tbw-font-size: 1em;--tbw-font-size-sm: .9285em;--tbw-font-size-xs: .7857em;--tbw-font-size-2xs: .7142em;--tbw-spacing-xs: .25em;--tbw-spacing-sm: .375em;--tbw-spacing-md: .5em;--tbw-spacing-lg: .75em;--tbw-spacing-xl: 1em;--tbw-icon-size: var(--tbw-base-icon-size);--tbw-icon-size-sm: .875em;--tbw-checkbox-size: var(--tbw-base-icon-size);--tbw-toggle-size: 1.25em;--tbw-border-radius: var(--tbw-base-radius);--tbw-color-bg: transparent;--tbw-color-panel-bg: light-dark(#eeeeee, #222222);--tbw-color-fg: light-dark(#222222, #eeeeee);--tbw-color-fg-muted: light-dark(#555555, #aaaaaa);--tbw-color-accent: light-dark(#3b82f6, #3b82f6);--tbw-color-accent-fg: light-dark(#ffffff, #000000);--tbw-color-success: light-dark(hsl(122, 39%, 40%), hsl(122, 39%, 49%));--tbw-color-warning: light-dark(hsl(38, 92%, 50%), hsl(38, 92%, 50%));--tbw-color-error: light-dark(hsl(0, 65%, 51%), hsl(0, 65%, 55%));--tbw-color-danger: var(--tbw-color-error);--tbw-color-selection: light-dark(#fff7d6, #333333);--tbw-color-row-alt: var(--tbw-color-bg);--tbw-color-row-hover: light-dark(#f0f6ff, #1c1c1c);--tbw-color-header-bg: color-mix(in hsl, var(--tbw-color-panel-bg) 85%, var(--tbw-color-fg));--tbw-color-header-fg: color-mix(in hsl, var(--tbw-color-fg) 75%, var(--tbw-color-panel-bg));--tbw-color-border: light-dark(#d0d0d4, #454545);--tbw-color-border-strong: light-dark(#777777, #666666);--tbw-color-border-cell: var(--tbw-color-border);--tbw-color-border-header: var(--tbw-color-border);--tbw-color-shadow: light-dark(rgba(0, 0, 0, .1), rgba(0, 0, 0, .3));--tbw-font-family: inherit;--tbw-font-size-header: var(--tbw-font-size);--tbw-font-weight-header: bold;--tbw-cell-padding-header: var(--tbw-spacing-xs) var(--tbw-spacing-md);--tbw-cell-padding-v: var(--tbw-spacing-xs);--tbw-cell-padding-h: var(--tbw-spacing-md);--tbw-cell-padding: var(--tbw-cell-padding-v) var(--tbw-cell-padding-h);--tbw-cell-padding-input: var(--tbw-spacing-xs) var(--tbw-spacing-sm);--tbw-row-height: 1.75em;--tbw-header-height: 1.875em;--tbw-cell-white-space: nowrap;--tbw-border-width: 1px;--tbw-border-style: solid;--tbw-border-input: var(--tbw-border-width) var(--tbw-border-style) var(--tbw-color-border-strong);--tbw-border-header: var(--tbw-border-width) var(--tbw-border-style) var(--tbw-color-border-header);--tbw-row-divider: var(--tbw-border-width) var(--tbw-border-style) var(--tbw-color-border-cell);--tbw-row-hover-outline: 0;--tbw-color-active-row-bg: var(--tbw-color-selection);--tbw-active-row-outline: 0;--tbw-focus-outline-width: 2px;--tbw-focus-outline: var(--tbw-focus-outline-width) var(--tbw-border-style) var(--tbw-color-accent);--tbw-focus-outline-offset: -2px;--tbw-focus-background: rgba(from var(--tbw-color-accent) r g b / 12%);--tbw-range-border-color: var(--tbw-color-accent);--tbw-range-selection-bg: rgba(from var(--tbw-range-border-color) r g b / 12%);--tbw-column-selection-bg: rgba(from var(--tbw-color-accent) r g b / 12%);--tbw-resize-handle-width: 2px;--tbw-resize-handle-color: transparent;--tbw-resize-handle-color-hover: var(--tbw-color-accent);--tbw-resize-handle-border-radius: 0;--tbw-resize-indicator-width: 2px;--tbw-resize-indicator-color: var(--tbw-color-accent);--tbw-resize-indicator-opacity: .6;--tbw-transition-duration: .12s;--tbw-transition-ease: ease;--tbw-animation-duration: .2s;--tbw-animation-easing: ease-out;--tbw-animation-enabled: 1;--tbw-row-change-duration: .5s;--tbw-row-insert-duration: .3s;--tbw-row-remove-duration: .2s;--tbw-row-change-color: rgba(from var(--tbw-color-accent) r g b / 25%);--tbw-sort-indicator-color: var(--tbw-color-fg-muted);--tbw-sort-indicator-active-color: var(--tbw-color-accent);--tbw-sort-indicator-display: inline-flex;--tbw-sort-indicator-visibility: visible;--tbw-header-text-transform: none;--tbw-header-letter-spacing: normal;--tbw-color-header-separator: var(--tbw-color-border-cell);--tbw-density-scale: 1;--tbw-shell-header-height: 2.75em;--tbw-shell-header-bg: var(--tbw-color-panel-bg);--tbw-shell-header-border: var(--tbw-color-border);--tbw-shell-title-font-size: var(--tbw-font-size);--tbw-shell-title-font-weight: 600;--tbw-tool-panel-width: 17.5em;--tbw-tool-panel-bg: var(--tbw-color-panel-bg);--tbw-tool-panel-border: var(--tbw-color-border);--tbw-tool-panel-header-height: 2.5em;--tbw-tool-panel-transition: var(--tbw-animation-duration) var(--tbw-animation-easing);--tbw-toolbar-button-size: 2em;--tbw-toolbar-button-gap: var(--tbw-spacing-xs);--tbw-panel-padding: var(--tbw-spacing-lg);--tbw-panel-gap: var(--tbw-spacing-md);--tbw-menu-item-padding: var(--tbw-spacing-sm) var(--tbw-spacing-lg);--tbw-menu-item-gap: var(--tbw-spacing-md);--tbw-menu-min-width: 10rem;--tbw-button-padding: var(--tbw-spacing-sm) var(--tbw-spacing-lg);--tbw-button-padding-sm: var(--tbw-spacing-xs) var(--tbw-spacing-md);--tbw-input-height: var(--tbw-row-height);--tbw-input-padding: 0 var(--tbw-spacing-md);--tbw-detail-padding: var(--tbw-spacing-xl);--tbw-detail-max-height: 31.25rem;--tbw-indicator-size: var(--tbw-spacing-sm);--tbw-icon-expand: "▶";--tbw-icon-collapse: "▼";--tbw-icon-sort-asc: "▲";--tbw-icon-sort-desc: "▼";--tbw-icon-sort-none: "⇅";--tbw-icon-submenu-arrow: "▶";--tbw-icon-drag-handle: "⋮⋮";--tbw-icon-tool-panel: "☰";--tbw-icon-filter: "";--tbw-icon-filter-active: "";--tbw-icon-print: "🖨️";--tbw-icon-expand-mask: none;--tbw-icon-collapse-mask: none;--tbw-icon-sort-asc-mask: none;--tbw-icon-sort-desc-mask: none;--tbw-icon-sort-none-mask: none;--tbw-icon-submenu-arrow-mask: none;--tbw-icon-drag-handle-mask: none;--tbw-icon-tool-panel-mask: none;--tbw-icon-filter-mask: url("data:image/svg+xml,%3Csvg viewBox=\'0 0 16 16\' width=\'12\' height=\'12\' xmlns=\'http://www.w3.org/2000/svg\'%3E%3Cpath fill=\'currentColor\' d=\'M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z\'/%3E%3C/svg%3E");--tbw-icon-filter-active-mask: var(--tbw-icon-filter-mask);--tbw-icon-print-mask: none}}\n@layer tbw-base{tbw-grid{color-scheme:inherit;position:relative;display:block;width:100%;height:100%;min-height:0;contain:content;font-family:var(--tbw-font-family);font-size:var(--tbw-font-size);font-feature-settings:"tnum","lnum";background:var(--tbw-color-bg);color:var(--tbw-color-fg);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);overflow:clip;outline:none}tbw-grid,tbw-grid *{box-sizing:border-box}tbw-grid>tbw-grid-column,tbw-grid>tbw-grid-type{display:none}tbw-grid .tbw-grid-root{position:relative;display:flex;flex-direction:column;height:100%}tbw-grid .tbw-grid-root.has-shell{display:flex;flex-direction:column;height:100%}tbw-grid .tbw-grid-root:has(.selected){-webkit-user-select:none;user-select:none}tbw-grid .tbw-grid-content{flex:1;min-width:0;min-height:0;display:flex;flex-direction:row;overflow:hidden;touch-action:none}tbw-grid .tbw-scroll-area{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow-x:auto;overflow-y:hidden;overflow-anchor:none}tbw-grid .rows-body-wrapper{flex:1;min-height:0;display:flex;flex-direction:row;width:100%;min-width:fit-content}tbw-grid .rows-body{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow:visible}tbw-grid .rows-container{display:flex;flex-direction:row;flex:1;min-height:0;overflow:visible;position:relative}tbw-grid .rows-viewport{flex:1;min-width:0;position:relative;display:block;overflow:clip;touch-action:none}tbw-grid .rows-viewport .rows{position:absolute;top:0;left:0;min-width:100%;will-change:transform;z-index:var(--tbw-z-layer-rows, 1)}tbw-grid .faux-vscroll{position:sticky;inset-inline-end:0;flex-shrink:0;width:auto;overflow-y:auto;overflow-x:hidden;z-index:var(--tbw-z-layer-header, 30);touch-action:none}tbw-grid .faux-vscroll-spacer{width:1px}tbw-grid .tbw-sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}tbw-grid[data-has-focus] .cell-focus,tbw-grid[data-has-focus] .row-focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}tbw-grid .sticky-left,tbw-grid .sticky-right{position:sticky;z-index:25}tbw-grid .sticky-left{box-shadow:1px 0 0 var(--tbw-color-border)}tbw-grid .sticky-right{box-shadow:-1px 0 0 var(--tbw-color-border)}}\n@layer tbw-base{tbw-grid [data-icon=expand]:empty:before{content:var(--tbw-icon-expand)}tbw-grid [data-icon=collapse]:empty:before{content:var(--tbw-icon-collapse)}tbw-grid [data-icon=sort-asc]:empty:before{content:var(--tbw-icon-sort-asc)}tbw-grid [data-icon=sort-desc]:empty:before{content:var(--tbw-icon-sort-desc)}tbw-grid [data-icon=sort-none]:empty:before{content:var(--tbw-icon-sort-none)}tbw-grid [data-icon=submenu-arrow]:empty:before{content:var(--tbw-icon-submenu-arrow)}tbw-grid [data-icon=drag-handle]:empty:before{content:var(--tbw-icon-drag-handle)}tbw-grid [data-icon=tool-panel]:empty:before{content:var(--tbw-icon-tool-panel)}tbw-grid [data-icon=print]:empty:before{content:var(--tbw-icon-print)}tbw-grid [data-icon=filter]:empty:before{content:var(--tbw-icon-filter)}tbw-grid [data-icon=filter-active]:empty:before{content:var(--tbw-icon-filter-active)}tbw-grid [data-icon]:empty:before{display:inline-block;vertical-align:middle;-webkit-mask-size:contain;mask-size:contain;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;-webkit-mask-position:center;mask-position:center}tbw-grid [data-icon=expand]:empty:before{-webkit-mask-image:var(--tbw-icon-expand-mask);mask-image:var(--tbw-icon-expand-mask)}tbw-grid [data-icon=collapse]:empty:before{-webkit-mask-image:var(--tbw-icon-collapse-mask);mask-image:var(--tbw-icon-collapse-mask)}tbw-grid [data-icon=sort-asc]:empty:before{-webkit-mask-image:var(--tbw-icon-sort-asc-mask);mask-image:var(--tbw-icon-sort-asc-mask)}tbw-grid [data-icon=sort-desc]:empty:before{-webkit-mask-image:var(--tbw-icon-sort-desc-mask);mask-image:var(--tbw-icon-sort-desc-mask)}tbw-grid [data-icon=sort-none]:empty:before{-webkit-mask-image:var(--tbw-icon-sort-none-mask);mask-image:var(--tbw-icon-sort-none-mask)}tbw-grid [data-icon=submenu-arrow]:empty:before{-webkit-mask-image:var(--tbw-icon-submenu-arrow-mask);mask-image:var(--tbw-icon-submenu-arrow-mask)}tbw-grid [data-icon=drag-handle]:empty:before{-webkit-mask-image:var(--tbw-icon-drag-handle-mask);mask-image:var(--tbw-icon-drag-handle-mask)}tbw-grid [data-icon=tool-panel]:empty:before{-webkit-mask-image:var(--tbw-icon-tool-panel-mask);mask-image:var(--tbw-icon-tool-panel-mask)}tbw-grid [data-icon=print]:empty:before{-webkit-mask-image:var(--tbw-icon-print-mask);mask-image:var(--tbw-icon-print-mask)}tbw-grid [data-icon=filter]:empty:before,tbw-grid [data-icon=filter-active]:empty:before{width:var(--tbw-icon-size, 1em);height:var(--tbw-icon-size, 1em);background:currentColor}tbw-grid [data-icon=filter]:empty:before{-webkit-mask-image:var(--tbw-icon-filter-mask);mask-image:var(--tbw-icon-filter-mask)}tbw-grid [data-icon=filter-active]:empty:before{-webkit-mask-image:var(--tbw-icon-filter-active-mask);mask-image:var(--tbw-icon-filter-active-mask)}.tbw-context-menu [data-icon]:empty:before{display:inline-block;width:1em;height:1em;vertical-align:middle}.tbw-context-menu [data-icon=submenu-arrow]:empty:before{content:var(--tbw-icon-submenu-arrow, "▶")}}\n@layer tbw-base{tbw-grid .header{display:block;flex-shrink:0;z-index:var(--tbw-z-layer-header, 30);background:var(--tbw-color-header-bg);overflow:visible}tbw-grid .header-group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-color-header-bg);z-index:var(--tbw-z-layer-header, 30)}tbw-grid .header-group-cell{display:flex;align-items:center;justify-content:flex-start;padding:var(--tbw-cell-padding-header, 2px 8px);color:var(--tbw-color-header-group-fg, var(--tbw-color-header-fg));font-weight:var(--tbw-font-weight-header-group, var(--tbw-font-weight-header));justify-content:var(--tbw-align-header-group, var(--tbw-align-header, flex-start))}tbw-grid .header-group-cell:not(:last-child){border-right:2px solid var(--tbw-color-border)}tbw-grid .header-row{display:grid;grid-template-columns:var(--tbw-column-template);color:var(--tbw-color-header-fg);font-size:var(--tbw-font-size-header);min-height:var(--tbw-header-height);border-bottom:var(--tbw-border-header);z-index:var(--tbw-z-layer-header, 30);text-transform:var(--tbw-header-text-transform);letter-spacing:var(--tbw-header-letter-spacing)}tbw-grid .header-row>.cell{display:flex;align-items:center;gap:4px;padding:var(--tbw-cell-padding-header, 2px 8px);background-color:var(--tbw-color-header-bg);font-weight:var(--tbw-font-weight-header);border-right:1px solid var(--tbw-color-border-cell);overflow:visible;min-width:0}tbw-grid .header-row>.cell>span:first-child{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:inherit}tbw-grid .header-row>.cell>span[part~=sort-indicator]{flex-shrink:0;opacity:.6;color:var(--tbw-sort-indicator-color);display:var(--tbw-sort-indicator-display, inline-flex);visibility:var(--tbw-sort-indicator-visibility, visible);transition:opacity .15s,visibility 0s,display 0s allow-discrete;transition-behavior:allow-discrete}tbw-grid .header-row>.cell:hover>span[part~=sort-indicator]{display:inline-flex;visibility:visible}tbw-grid .header-row>.cell[aria-sort=ascending]>span[part~=sort-indicator],tbw-grid .header-row>.cell[aria-sort=descending]>span[part~=sort-indicator]{display:inline-flex;visibility:visible;opacity:1;color:var(--tbw-sort-indicator-active-color)}tbw-grid .header-row>.cell:last-child{border-right:0}tbw-grid .header-row>.cell:last-child .resize-handle{right:0;width:calc(var(--tbw-resize-hit-area, 18px) / 2)}tbw-grid .header-row>.cell.grouped.group-end:not(:last-child){border-right:2px solid var(--tbw-color-border)}tbw-grid .header-row>.cell.resizable{position:relative}tbw-grid .header-row>.cell.sticky-left,tbw-grid .header-row>.cell.sticky-right{background:var(--tbw-color-header-bg);z-index:35}tbw-grid .header-group-row>.header-group-cell.sticky-left,tbw-grid .header-group-row>.header-group-cell.sticky-right{background:var(--tbw-color-header-bg);z-index:35}tbw-grid .sortable{cursor:pointer;-webkit-user-select:none;user-select:none}tbw-grid .resize-handle{position:absolute;top:0;right:calc(var(--tbw-resize-hit-area, 18px) / -2);width:var(--tbw-resize-hit-area, 18px);height:100%;cursor:e-resize;-webkit-user-select:none;user-select:none;touch-action:none;z-index:20;background:transparent}tbw-grid .resize-handle:before{content:"";position:absolute;top:0;left:50%;transform:translate(-50%);width:var(--tbw-resize-handle-width);height:100%;background:var(--tbw-resize-handle-color);border-radius:var(--tbw-resize-handle-border-radius);transition:background .12s ease}tbw-grid .resize-handle:after{content:"";position:absolute;top:100%;left:50%;transform:translate(-50%);width:var(--tbw-resize-handle-width);height:0;background:var(--tbw-resize-indicator-color, var(--tbw-color-accent));opacity:0;pointer-events:none;transition:opacity .12s ease,height 0s .12s;z-index:1000}tbw-grid .resize-handle:hover:before{background:var(--tbw-resize-handle-color-hover)}tbw-grid .resize-handle:hover:after{height:100vh;opacity:var(--tbw-resize-indicator-opacity, .6);transition:opacity .12s ease,height 0s}}\n@layer tbw-base{tbw-grid .data-grid-row{display:grid;grid-template-columns:var(--tbw-column-template);contain:layout style}tbw-grid .data-grid-row:nth-child(2n){background:var(--tbw-color-row-alt)}@media(hover:hover){tbw-grid .data-grid-row:hover{background:var(--tbw-color-row-hover)}}tbw-grid .data-grid-row>.cell{display:block;padding:var(--tbw-cell-padding, 2px 8px);border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height);align-content:center;border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0;white-space:var(--tbw-cell-white-space, nowrap);text-overflow:ellipsis}tbw-grid .data-grid-row>.cell>*{overflow:hidden;text-overflow:ellipsis;white-space:inherit;min-width:0}tbw-grid .data-grid-row>.cell:last-child{border-right:0}tbw-grid .data-grid-row>.cell[data-type=boolean]{text-align:center}tbw-grid .data-grid-row>.cell[data-type=boolean] input[type=checkbox]{margin:0;width:var(--tbw-checkbox-size);height:var(--tbw-checkbox-size);vertical-align:middle}tbw-grid .data-grid-row>.cell.selected:focus-visible,tbw-grid .data-grid-row>.cell:focus-visible:not(.cell-focus){outline:none}tbw-grid .data-grid-row>.cell.sticky-left,tbw-grid .data-grid-row>.cell.sticky-right{background:var(--tbw-color-panel-bg)}tbw-grid .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}}\n@layer tbw-base{.tbw-loading-overlay{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:1000;pointer-events:all;animation:tbw-fade-in .15s ease-out}.tbw-spinner{--tbw-spinner-size: 48px;--tbw-spinner-border-width: 3px;--tbw-spinner-color: var(--tbw-color-accent);--tbw-spinner-track-color: var(--tbw-color-border);width:var(--tbw-spinner-size);height:var(--tbw-spinner-size);border:var(--tbw-spinner-border-width) solid var(--tbw-spinner-track-color);border-top-color:var(--tbw-spinner-color);border-radius:50%;animation:tbw-spin .8s linear infinite}.tbw-spinner--large{--tbw-spinner-size: min(48px, calc(100% - 16px) )}.tbw-spinner--small{--tbw-spinner-size: calc(var(--tbw-row-height, 28px) * .6);--tbw-spinner-border-width: 2px}.data-grid-row.tbw-row-loading{position:relative;pointer-events:none}.tbw-row-loading-overlay{position:absolute;inset:0;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:26;animation:tbw-fade-in .15s ease-out;pointer-events:none;display:flex;align-items:center}.tbw-row-loading-spinner{--_spinner-size: calc(var(--tbw-row-height, 28px) * .6);margin-left:var(--tbw-spacing-md);width:var(--_spinner-size);height:var(--_spinner-size);border:2px solid var(--tbw-spinner-track-color, var(--tbw-color-border));border-top-color:var(--tbw-spinner-color, var(--tbw-color-accent));border-radius:50%;animation:tbw-spin .8s linear infinite}.cell.tbw-cell-loading{position:relative;pointer-events:none}.cell.tbw-cell-loading:before{content:"";position:absolute;inset:0;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:26;animation:tbw-fade-in .15s ease-out}.cell.tbw-cell-loading:after{--_spinner-size: calc(var(--tbw-row-height, 28px) * .5);content:"";position:absolute;left:var(--tbw-spacing-sm);top:0;bottom:0;margin:auto 0;width:var(--_spinner-size);height:var(--_spinner-size);border:2px solid var(--tbw-spinner-track-color, var(--tbw-color-border));border-top-color:var(--tbw-spinner-color, var(--tbw-color-accent));border-radius:50%;animation:tbw-spin .8s linear infinite;z-index:27}}\n@layer tbw-base{.tbw-empty-overlay{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;padding:var(--tbw-spacing-md, 12px);text-align:center;background:light-dark(rgba(255,255,255,.6),rgba(0,0,0,.4));color:var(--tbw-color-text-secondary, var(--tbw-color-text));z-index:999;pointer-events:all;animation:tbw-fade-in .15s ease-out}.tbw-empty-message{font-family:var(--tbw-font-family, inherit);font-size:var(--tbw-font-size-md, 14px);line-height:1.4;max-width:480px;-webkit-user-select:text;user-select:text}}\n@layer tbw-base{tbw-grid .tbw-expanding{animation:tbw-expand var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}tbw-grid .tbw-collapsing{animation:tbw-collapse var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}tbw-grid[data-animation-mode=off]{--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms}tbw-grid[data-animation-mode=off] .data-grid-row[data-animating]{animation:none}tbw-grid .data-grid-row[data-animating=change]{animation:tbw-row-change var(--tbw-row-change-duration) ease-out}tbw-grid .data-grid-row[data-animating=insert]{animation:tbw-row-insert var(--tbw-row-insert-duration) ease-out;will-change:max-height,opacity}tbw-grid .data-grid-row[data-animating=remove]{animation:tbw-row-remove var(--tbw-row-remove-duration) ease-out forwards;will-change:max-height,opacity,transform;pointer-events:none}}@keyframes tbw-expand{0%{opacity:0;max-height:0;transform:translateY(-8px)}to{opacity:1;max-height:500px;transform:translateY(0)}}@keyframes tbw-collapse{0%{opacity:1;max-height:500px;transform:translateY(0)}to{opacity:0;max-height:0;transform:translateY(-8px)}}@keyframes tbw-row-change{0%{background-color:transparent}20%{background-color:var(--tbw-row-change-color)}to{background-color:transparent}}@keyframes tbw-row-insert{0%{opacity:0;max-height:0;overflow:hidden}to{opacity:1;max-height:var(--tbw-row-height, 28px);overflow:hidden}}@keyframes tbw-row-remove{0%{opacity:1;transform:translateY(0);max-height:var(--tbw-row-height, 28px)}to{opacity:0;max-height:0;transform:translateY(-8px)}}@keyframes tbw-spin{to{transform:rotate(360deg)}}@keyframes tbw-fade-in{0%{opacity:0}to{opacity:1}}\n@layer tbw-base{@media(forced-colors:active){tbw-grid{--tbw-color-border: CanvasText;--tbw-color-border-strong: CanvasText;--tbw-color-border-cell: CanvasText;--tbw-color-border-header: CanvasText;--tbw-color-fg: CanvasText;--tbw-color-bg: Canvas;--tbw-color-panel-bg: Canvas;--tbw-color-header-bg: Canvas;--tbw-color-header-fg: CanvasText;--tbw-color-accent: Highlight;--tbw-color-accent-fg: HighlightText;--tbw-color-selection: Highlight;--tbw-color-row-hover: Highlight;--tbw-focus-outline: 2px solid Highlight;--tbw-range-border-color: Highlight}tbw-grid .cell:focus,tbw-grid .cell.active-cell{outline:2px solid Highlight!important;outline-offset:-2px}tbw-grid .data-grid-row[aria-selected=true]{background:Highlight!important;color:HighlightText!important}}@media(prefers-reduced-motion:reduce){tbw-grid[data-animation-mode=reduced-motion]{--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms}tbw-grid[data-animation-mode=reduced-motion] .data-grid-row[data-animating]{animation:none}}}\n')}getPlugin(e){return this.#ge?.getPlugin(e)}getPluginByName(e){return this.#ge?.getPluginByName(e)}requestRender(){this.#ee.requestPhase(fe.ROWS,"plugin:requestRender")}requestColumnsRender(){this.#ee.requestPhase(fe.COLUMNS,"plugin:requestColumnsRender")}requestRenderWithFocus(){this._restoreFocusAfterRender=!0,this.#ee.requestPhase(fe.ROWS,"plugin:requestRenderWithFocus")}updateTemplate(){M(this)}requestAfterRender(){this.#ee.requestPhase(fe.STYLE,"plugin:requestAfterRender")}requestVirtualRefresh(){this._virtualization.start=-1,this.refreshVirtualWindow(!1)}#Ne(){this.#ge=new zt(this);const e=this.#b?.plugins,t=Array.isArray(e)?e:[],r=this.#b?.features;let i,o=[];if(r&&it){o=it(r).map(e=>this.#Fe(e))}if(0===o.length)i=t;else if(0===t.length)i=o;else{const e=new Set(t.map(e=>e.name));i=[...o.filter(t=>!e.has(t.name)),...t]}this.#ge.attachAll(i)}#Fe(e){const t=this.#Ce.get(e.name);return t&&t!==e?(t.refreshUserConfigFrom(e),t):(this.#Ce.set(e.name,e),e)}#qe(){!function(e){let t=!1;for(const{name:r,styles:i}of e)Ct.has(r)||(Ct.set(r,Et(i)),t=!0);t&&St()}(this.#ge?.getPluginStyles()??[])}#$e(){const e=this.#b?.plugins,t=Array.isArray(e)?e:[],r=this.#b?.features??void 0,i=r!==this.#pe;if((this.#fe===t||void 0!==this.#fe&&this.#fe.length===t.length&&this.#fe.every((e,r)=>e===t[r]))&&!i)return void(this.#fe=t);this.#ge&&this.#ge.detachAll(),this.#Ne(),this.#qe(),this.#fe=t,this.#pe=r,this.#We(),this.#K.markSourcesChanged(),this.#K.merge();const o=this.#ie;if(this.#ie=this.#ge?.getAll().some(e=>e.onScroll)??!1,!o&&this.#ie){const e=this.#j.querySelector(".tbw-grid-content")??this.#j.querySelector(".tbw-grid-root");this.#Ve(e)}}#Ue(){this.#ge?.detachAll()}#Be(){const e=Nt.getAdapters();if(0===e.length&&!this.__frameworkAdapter)return;const t=this.__frameworkAdapter;return r=>{if(t?.createToolPanelRenderer){const e=t.createToolPanelRenderer(r);if(e)return e}for(const t of e)if(t.createToolPanelRenderer){const e=t.createToolPanelRenderer(r);if(e)return e}}}_registerLightDomHandler(e,t){this.#K.registerLightDomHandler(e,t)}_unregisterLightDomHandler(e){this.#K.unregisterLightDomHandler(e)}_requestConfigMerge(){this.#K.markSourcesChanged(),this.#K.merge()}_getToolPanelRendererFactory(){return this.#Be()}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",Nt.version),this.hasAttribute("data-tbw-grid")||this.setAttribute("data-tbw-grid",""),this.id||(this.id="tbw-grid-"+ ++Nt.#G),this._rows=Array.isArray(this.#X)?[...this.#X]:[],this.#le&&(this.#le.abort(),this.#ve=!1),this.#le=new AbortController,this.#ue&&(st(this.#ue),this.#ue=void 0),this.#Ge(),this.#K.parseLightDomColumns(this),this.#K.merge(),this.#Ne();const e=this.#b?.plugins;var t,r;this.#fe=Array.isArray(e)?e:[],this.#pe=this.#b?.features??void 0,this.#Y||(this.#je(),this.#qe(),this.#Y=!0),this.#Ye(),this.#ue=(t=()=>{this.#Xe()},r={timeout:100},nt?requestIdleCallback(t,r):window.setTimeout(()=>{const e=Date.now();t({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-e))})},1))}disconnectedCallback(){this.#ue&&(st(this.#ue),this.#ue=void 0),this.#ne&&(clearTimeout(this.#ne),this.#ne=0),this.#Ue();const e=this.#ge?.getPluginByName("shell");e?.disposeShellState?.(),xt(this.#ae),this.#le&&(this.#le.abort(),this.#le=void 0),this.#ye?.abort(),this.#ye=void 0,this.#ve=!1,this._resizeController&&this._resizeController.dispose(),this.#ce&&(this.#ce.disconnect(),this.#ce=void 0),this.#de&&(this.#de.disconnect(),this.#de=void 0,this.#Ke=!1,this.#Ze=0),Xe(this),this.#Qe.clear(),this._virtualization.heightCache?.byKey.clear(),this.#fe=void 0,this.#pe=void 0;for(let t=0;t<this._rowPool.length;t++)this._rowPool[t].remove();this._rowPool.length=0,this.__rowsBodyEl=null,this.#Z=!1}attributeChangedCallback(e,t,r){if("loading"===e){const e=null!==r&&"false"!==r;return void(this.loading!==e&&(this.loading=e))}if(t!==r&&r&&"null"!==r&&"undefined"!==r)if("rows"===e||"columns"===e||"grid-config"===e)try{const t=JSON.parse(r);"rows"===e?this.rows=t:"columns"===e?this.columns=t:"grid-config"===e&&(this.gridConfig=t)}catch{v("TBW130",`Invalid JSON for '${e}' attribute: ${r}`,this.id)}else"fit-mode"===e?this.fitMode=r:"column-inference"===e&&(this.columnInference=r)}#Ye(){const e=this.#j.querySelector(".tbw-grid-content")??this.#j.querySelector(".tbw-grid-root");if(this._headerRowEl=e?.querySelector(".header-row"),this._virtualization.totalHeightEl=e?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=e?.querySelector(".rows-viewport"),this._bodyEl=e?.querySelector(".rows"),this.__rowsBodyEl=e?.querySelector(".rows-body"),this.setAttribute("data-upgraded",""),this.#Z=!0,this._resizeController=lt(this),this.#Je(),this.#Ve(e),this.#ve)return;this.#ve=!0;const t=this.disconnectSignal;rt(this,this,this.#j,t),this.#We(),queueMicrotask(()=>this.#et()),this.#ee.requestPhase(fe.FULL,"afterConnect")}#We(){const e=this.#b.rowHeight,t=this.#ge.hasRowHeightPlugin();"function"==typeof e||t?this._virtualization.variableHeights||(this._virtualization.variableHeights=!0,this._virtualization.rowHeight="number"==typeof e&&e>0?e:this._virtualization.rowHeight||28,this.#we.initializePositionCache(),"function"!=typeof e&&(this.#oe=!0)):!t&&"function"!=typeof e&&this._virtualization.variableHeights?(this._virtualization.variableHeights=!1,this._virtualization.positionCache=null):"number"==typeof e&&e>0?(this._virtualization.rowHeight=e,this._virtualization.variableHeights=!1):requestAnimationFrame(()=>this.#tt())}#tt(){if(this.#ge.hasRowHeightPlugin())return;const e=this.#b.rowHeight;if("number"==typeof e&&e>0)return;const t=this._bodyEl?.querySelector(".data-grid-row");if(!t)return;const r=this.#rt(),i=[],o=this._bodyEl?.querySelectorAll(".data-grid-row");for(const h of o??[]){if(h.style.getPropertyValue("--tbw-row-height"))continue;let e=0;h.querySelectorAll(".cell").forEach(t=>{const r=t.offsetHeight;r>e&&(e=r)});const t=Math.max(h.getBoundingClientRect().height,e);t>0&&i.push(t)}if(0===i.length)return;i.sort((e,t)=>e-t);const n=i.length>>1,s=i.length%2==1?i[n]:(i[n-1]+i[n])/2,a=this._virtualization.rowHeight,l=this.#Ze,c=r>0&&l>0&&Math.abs(r-l)>1,d=r>0&&0===l,u=s>0&&s-a>1;if(r>0&&(this.#Ze=r),c||d||u){const e=c||d?Math.max(r,s):s;Math.abs(e-a)>1&&(this._virtualization.rowHeight=e,this.#ee.requestPhase(fe.VIRTUALIZATION,"measureRowHeight"))}}#rt(){const e=getComputedStyle(this).getPropertyValue("--tbw-row-height").trim();if(!e)return 0;if(e.endsWith("px"))return parseFloat(e)||0;const t=this._bodyEl?.querySelector('.data-grid-row:not([style*="--tbw-row-height"]) > .cell');if(!t)return 0;const r=parseFloat(getComputedStyle(t).minHeight);return r>0?r:0}#it(){const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const t=e.querySelectorAll(".cell");let r=0;t.forEach(e=>{const t=e.offsetHeight;t>r&&(r=t)});const i=e.getBoundingClientRect(),o=Math.max(i.height,r);if(o>0){if(Math.abs(o-this._virtualization.rowHeight)>1&&(this._virtualization.rowHeight=o),this.#we.initializePositionCache(),this._virtualization.totalHeightEl){const e=this.#we.calculateTotalSpacerHeight(this._rows.length);this._virtualization.totalHeightEl.style.height=`${e}px`}}}#Ve(e){this.#ye?.abort(),this.#ye=new AbortController;const t=this.#ye.signal,r=e?.querySelector(".faux-vscroll"),i=e?.querySelector(".rows");if(this._virtualization.container=r??this,this.#ie=this.#ge?.getAll().some(e=>e.onScroll)??!1,r&&i){r.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#ie)return;const e=r.scrollTop,t=Oe(e,this._virtualization.scrollMapping),o=this._virtualization.rowHeight;if(this._rows.length<=this._virtualization.bypassThreshold)i.style.transform=`translateY(${-e}px)`;else{const e=this._virtualization.positionCache;let r,n;if(this._virtualization.variableHeights&&e&&e.length>0){r=Le(e,t),-1===r&&(r=0);const i=r-r%2;n=e[i]?.offset??i*o}else{r=Math.floor(t/o);n=(r-r%2)*o}const s=-(t-n);i.style.transform=`translateY(${s}px)`}this.#re=e,this.#te||(this.#te=requestAnimationFrame(()=>{this.#te=0,null!==this.#re&&(this.#ot(this.#re),this.#re=null)}))},{passive:!0,signal:t});const e=this.#j.querySelector(".tbw-scroll-area");this.#_e=e,this._virtualization.scrollAreaEl=e,e&&this.#ie&&e.addEventListener("scroll",()=>{const t=this.#he;t.scrollTop=r.scrollTop,t.scrollLeft=e.scrollLeft,t.scrollHeight=r.scrollHeight,t.scrollWidth=e.scrollWidth,t.clientHeight=r.clientHeight,t.clientWidth=e.clientWidth,this.#ge?.onScroll(t)},{passive:!0,signal:t});const o=this.#j.querySelector(".tbw-grid-content"),n=this.#_e;o&&(o.addEventListener("wheel",e=>{try{if(o.querySelector("select:open"))return}catch{}const t=e.shiftKey||Math.abs(e.deltaX)>Math.abs(e.deltaY);if(t&&n){const t=e.shiftKey?e.deltaY:e.deltaX,{scrollLeft:r,scrollWidth:i,clientWidth:o}=n;(t>0&&r<i-o||t<0&&r>0)&&(e.preventDefault(),n.scrollLeft+=t)}else if(!t){const{scrollTop:t,scrollHeight:i,clientHeight:o}=r;(e.deltaY>0&&t<i-o||e.deltaY<0&&t>0)&&(e.preventDefault(),r.scrollTop+=e.deltaY)}},{passive:!1,signal:t}),Tt(o,this.#ae,{fauxScrollbar:r,scrollArea:n},t))}var o,n,s;this._bodyEl&&(o=this,n=this._bodyEl,s=t,n.addEventListener("mousedown",e=>{const t=e.target.closest(".cell[data-col]");if(!t)return;if(t.classList.contains(H.EDITING))return;const r=e.target;r.draggable||r.closest('[draggable="true"]')||e.preventDefault(),et(o,t)},{signal:s}),n.addEventListener("click",e=>{const t=e.target.closest(".data-grid-row");if(t&&Qe(o,e,t),!document.activeElement?.closest(`.cell.${H.EDITING}`)){const t=e.target.closest("tbw-grid, [data-tbw-grid]");t&&t.focus({preventScroll:!0})}},{signal:s}),n.addEventListener("dblclick",e=>{const t=e.target.closest(".data-grid-row");t&&Qe(o,e,t)},{signal:s})),this.#ce?.disconnect(),this._virtualization.viewportEl&&(this.#ce=new ResizeObserver(()=>{this.#nt(),this.#ee.requestPhase(fe.VIRTUALIZATION,"resize-observer")}),this.#ce.observe(this._virtualization.viewportEl)),this.#j.addEventListener("focusin",()=>{this.dataset.hasFocus=""},{signal:t}),this.#j.addEventListener("focusout",e=>{const t=e.relatedTarget;t&&(this.#j.contains(t)||this.#me.isInExternalFocusContainer(t))||delete this.dataset.hasFocus},{signal:t})}#Ke=!1;#Ze=0;#st(){if(this.#Ke)return;const e=this._bodyEl?.querySelector(".data-grid-row");e&&(this.#Ke=!0,this.#de?.disconnect(),this.#de=new ResizeObserver(()=>{this.#tt()}),this.#de.observe(e))}addEventListener(e,t,r){super.addEventListener(e,t,r)}removeEventListener(e,t,r){super.removeEventListener(e,t,r)}on(e,t){const r=e=>{t(e.detail,e)};return this.addEventListener(e,r),()=>this.removeEventListener(e,r)}#at(e,t){this.#Z&&this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}_emitDataChange(){this.#at("data-change",{rowCount:this._rows.length,sourceRowCount:this.#X.length}),function(e,t,r){if(r===t.lastAnnouncedSourceCount)return;const i=t.lastAnnouncedSourceCount;t.lastAnnouncedSourceCount=r,0===r&&i<0||n(e,s(e,"dataLoaded",r))}(this,this.#lt,this.#X.length)}#et(){const e=this._bodyEl?.querySelectorAll(".data-grid-row");e?.forEach((e,t)=>{const r=t===this._focusRow;e.setAttribute("aria-selected",String(r)),e.querySelectorAll(".cell").forEach((e,t)=>{e.setAttribute("aria-selected",String(r&&t===this._focusCol))})})}#Le(e){this.#J[e]=!0,this.#Q||(this.#Q=!0,queueMicrotask(()=>this.#ct()))}#ct(){if(!this.#Q||!this.#Z)return void(this.#Q=!1);const e=this.#J;if(this.#Q=!1,this.#J={rows:!1,columns:!1,gridConfig:!1,fitMode:!1,columnInference:!1},e.gridConfig)return this.#dt(),void(e.rows&&this.#ut());(e.columns||e.columnInference)&&this.#ht(),e.rows&&this.#ut(),e.fitMode&&this.#gt()}#ut(){this._rows=Array.isArray(this.#X)?[...this.#X]:[],this.#He=!0,this.#ee.requestPhase(fe.ROWS,"applyRowsUpdate")}#ft(){this.#He&&this._rebuildRowIdMap()}_rebuildRowIdMap(){this.#He=!1,this.#xe.clear();const e=this.#b.getRowId;for(let t=0;t<this._rows.length;t++){const r=ft(this._rows[t],e);void 0!==r&&this.#xe.set(r,{row:this._rows[t],index:t})}}#ht(){Xe(this),this.#K.merge(),this.#Je()}#gt(){this.#K.merge();if("fixed"===this.#b.fitMode)this.__didInitialAutoSize=!1,E(this);else{for(let e=0;e<this._columns.length;e++){const t=this._columns[e];!t.__userResized&&t.__autoSized&&delete t.width}M(this)}}#dt(){this.#K.parseLightDomColumns(this),this.#K.merge(),this.#$e(),this.#We(),this.#K.markSourcesChanged(),this.#K.merge();const e=this.#K.initialColumnState;if(e){this.#K.initialColumnState=void 0,this.#E=void 0;const t=this.#ge?.getAll()??[];this.#K.applyState(e,t)}if(this.#ge?.needsStructuralRerender()??!1)return this.#ge?.beforeStructuralRender(),this.#je(),this.#qe(),this.#Ye(),void this._rebuildRowIdMap();this._rebuildRowIdMap(),this.#ee.requestPhase(fe.COLUMNS,"applyGridConfigUpdate")}#pt(){if(this.__rowRenderEpoch++,this.#ge){const e=this.#Te.length>0?this.#Te:this._columns,t=e.filter(e=>!e.hidden),r=e.filter(e=>e.hidden),i=this.#ge.processColumns([...t]);if(i!==t){const o=new Set(i.map(e=>e.field));!t.some(e=>o.has(e.field))&&i.length>0?this._columns=[...i,...r]:this._columns=this.#wt(e,i,r)}else this._columns=[...e]}}#wt(e,t,r){if(0===r.length)return t;const i=new Map;for(const a of t)i.set(a.field,a);const o=new Set(e.map(e=>e.field)),n=[];for(const a of t)o.has(a.field)||n.push(a);const s=[];for(const a of e){const e=i.get(a.field);e?s.push(e):a.hidden&&s.push(a)}return s.push(...n),s}#mt(){Xe(this);const e=this.#X;if(!Array.isArray(e))return this._rows=[],this._rebuildRowIdMap(),this._virtualization.variableHeights&&this.#we.initializePositionCache(),void this._emitDataChange();if(!this._sortState&&this.#b.initialSort){const{field:e,direction:t}=this.#b.initialSort;this._columns.find(t=>t.field===e)&&(this._sortState={field:e,direction:"desc"===t?-1:1})}this._sortState&&(this.__originalOrder=this._rows);const t=function(e,t,r=!1){if(!e._sortState)return t;const i=e.effectiveConfig?.sortHandler??Z;if(i===Z)return r||(e.__originalOrder=t.slice()),te(t,e._sortState.field,e._sortState.direction,e._columns),t;r||(e.__originalOrder=t);const o=i(t,e._sortState,e._columns);return o&&"function"==typeof o.then?t:o}(this,this._sortState?[...e]:e,!0),r=this.#ge?.processRows(t)??t;this._rows=r,this.#He=!0,this._emitDataChange()}_renderVisibleRows(e,t,r=this.__rowRenderEpoch){if(this.#se||(this.#se=(e,t,r)=>this.#ge?.renderRow(e,t,r)??!1),function(e,t,r,i,o){const n=Math.max(0,r-t),s=e._bodyEl,a=e._visibleColumns,l=a.length;let c=e.__cachedHeaderRowCount;for(void 0===c&&(c=e.querySelector(".header-group-row")?2:1,e.__cachedHeaderRowCount=c);e._rowPool.length<n;){const t=Ye();e._rowPool.push(t)}if(e._rowPool.length>n){const t=e.__frameworkAdapter,r=t?.releaseCell;t?.beginBatch?.(e);try{for(let i=n;i<e._rowPool.length;i++){const o=e._rowPool[i];if(r){const e=o.children;for(let i=0;i<e.length;i++){const o=e[i];o.firstElementChild&&r.call(t,o)}}o.parentNode===s&&o.remove()}e._rowPool.length=n}finally{t?.endBatch?.(e)}}const d=o&&!1!==e.__hasRenderRowPlugins,u=e._hasAfterRowRenderHook?.()??!1,h=e._virtualization?.variableHeights&&"function"==typeof e.effectiveConfig?.rowHeight?e.effectiveConfig.rowHeight:null;for(let f=0;f<n;f++){const r=t+f,n=e._rows[r],p=e._rowPool[f];if(p.setAttribute("aria-rowindex",String(r+c+1)),d&&o(n,p,r)){p.__epoch=i,p.__rowDataRef=n,p.parentNode!==s&&s.appendChild(p);continue}const w=p.__epoch,m=p.__rowDataRef;let b=p.children.length;b>l&&p.lastElementChild?.classList.contains("tbw-row-loading-overlay")&&b--;const y=w===i&&b===l,_=m!==n,C=!!e._isGridEditMode;let R=!1;if(y&&_)for(let e=0;e<l;e++)if(a[e].externalView&&!p.querySelector(`.cell[data-col="${e}"] [data-external-view]`)){R=!0;break}if(!y||R){const t=Ve(p),o=C&&!_||e._activeEditRows===r;t&&!o?(p.__isCustomRow&&(p.className="data-grid-row",p.setAttribute("role","row"),p.__isCustomRow=!1),Ue(p),Ze(e,p,n,r),p.__epoch=i,p.__rowDataRef=n):t&&o?(Ke(e,p,n,r),p.__rowDataRef=n):(p.__isCustomRow&&(p.className="data-grid-row",p.setAttribute("role","row"),p.__isCustomRow=!1),Ze(e,p,n,r),p.__epoch=i,p.__rowDataRef=n)}else if(_){const t=Ve(p),o=e._activeEditRows===r;t&&!o?(Ue(p),Ze(e,p,n,r),p.__epoch=i,p.__rowDataRef=n):(Ke(e,p,n,r),p.__rowDataRef=n)}else{const t=Ve(p),o=C||e._activeEditRows===r;t&&!o?(Ue(p),Ze(e,p,n,r),p.__epoch=i,p.__rowDataRef=n):Ke(e,p,n,r)}let E=!1;const S=e._changedRowIdSet;if(S&&S.size>0)try{const t=e.getRowId?.(n);t&&(E=S.has(t))}catch{}E!==p.classList.contains("changed")&&p.classList.toggle("changed",E);const A=e.effectiveConfig?.rowClass;if(A){const t=p.getAttribute("data-dynamic-classes");if(t){const e=t.split(" ");for(let t=0;t<e.length;t++)e[t]&&p.classList.remove(e[t])}try{const e=A(n),t="string"==typeof e?e.split(/\s+/):e;if(t&&t.length>0){let e="";for(let r=0;r<t.length;r++){const i=t[r];i&&"string"==typeof i&&(p.classList.add(i),e+=(e?" ":"")+i)}p.setAttribute("data-dynamic-classes",e)}else p.removeAttribute("data-dynamic-classes")}catch(g){v("TBW060",`rowClass callback error: ${g}`,e.id),p.removeAttribute("data-dynamic-classes")}}if(h){const e=h(n,r);void 0!==e&&e>0?p.style.setProperty("--tbw-row-height",`${e}px`):p.style.removeProperty("--tbw-row-height")}u&&e._afterRowRender?.({row:n,rowIndex:r,rowElement:p}),p.parentNode!==s&&s.appendChild(p)}}(this,e,t,r,this.#se),this.#Ee.size>0)for(const i of this.#Ee)this.#Ie(i,!0)}#lt={rowCount:-1,colCount:-1,ariaLabel:void 0,ariaLabelledBy:void 0,ariaDescribedBy:void 0,ariaRoleDescription:void 0,lastAnnouncedSourceCount:-1};_updateAriaCounts(e,t){!function(e,t,r,i,o){if(i===e.rowCount&&o===e.colCount)return!1;const n=e.rowCount;e.rowCount=i,e.colCount=o,t&&(t.setAttribute("aria-rowcount",String(i)),t.setAttribute("aria-colcount",String(o))),i!==n&&r&&(i>0?r.setAttribute("role","rowgroup"):r.removeAttribute("role"))}(this.#lt,this.__rowsBodyEl,this._bodyEl,e,t)}_requestSchedulerPhase(e,t){this.#ee.requestPhase(e,t)}_getPluginRowHeight(e,t){return this.#ge?.getRowHeight?.(e,t)}_adjustPluginVirtualStart(e,t,r){return this.#ge?.adjustVirtualStart(e,t,r)}_afterPluginRender(){this.#ge?.afterRender()}_emitPluginEvent(e,t){this.#ge?.emitPluginEvent(e,t)}_schedulerMergeConfig(){this.#K.parseLightDomColumns(this),this.#K.merge(),this.#$e(),function(e,t,r){const i=kt,o=Lt,n=new Map;function s(e,t,r,i,o=!1){n.has(e)||n.set(e,{description:t,importHint:r,fields:[],isConfigProperty:o});const s=n.get(e);s.fields.includes(i)||s.fields.push(i)}const a=e.features;function l(e){return!!a&&!1===a[e]}for(const d of o){const r=e[d.property];if((d.isUsed?d.isUsed(r):void 0!==r)&&!It(t,d.pluginName)&&!l(d.pluginName)){const e=d.description||`the "${d.property}" ${d.level} property`;s(d.pluginName,e,Pt(d.pluginName),d.property,!0)}}const c=e.columns;if(c&&c.length>0)for(const d of c)for(const e of i){const r=d[e.property];if((e.isUsed?e.isUsed(r):void 0!==r)&&!It(t,e.pluginName)&&!l(e.pluginName)){const t=d.field||"<unknown>",r=e.description||`the "${e.property}" ${e.level} property`;s(e.pluginName,r,Pt(e.pluginName),t)}}if(n.size>0){const e=[];for(const[t,{description:r,importHint:i,fields:o,isConfigProperty:s}]of n)if(s)e.push(`Config uses ${r}, but the required plugin is not loaded.\n → Add the plugin to your gridConfig.plugins array:\n ${i}\n plugins: [new ${Dt(t)}Plugin(), ...]`);else{const n=o.slice(0,3).join(", ")+(o.length>3?`, ... (${o.length} total)`:"");e.push(`Column(s) [${n}] use ${r}, but the required plugin is not loaded.\n → Add the plugin to your gridConfig.plugins array:\n ${i}\n plugins: [new ${Dt(t)}Plugin(), ...]`)}b([...n.values()].some(e=>e.isConfigProperty)?"TBW002":"TBW001",`Configuration error:\n\n${e.join("\n\n")}\n\nThis validation helps catch misconfigurations early. The properties listed above require their respective plugins to function.`,r)}}(this.#b,this.#ge?.getPlugins()??[],this.id),function(e,t){const r=[],i=[];for(const o of e){const e=o.constructor.manifest;if(e?.configRules)for(const t of e.configRules){const e=o.config;if(t.check(e)){const e=`[${Dt(o.name)}Plugin] Configuration warning: ${t.message}`;"error"===t.severity?r.push(e):i.push(e)}}}if(i.length>0&&Re())for(const o of i)v("TBW004",o,t);r.length>0&&b("TBW003",`Configuration error:\n\n${r.join("\n\n")}`,t)}(this.#ge?.getPlugins()??[],this.id),function(e,t){if(!Re())return;const r=new Set(e.map(e=>e.name)),i=new Set;for(const o of e){const e=o.constructor.manifest;if(e?.incompatibleWith)for(const n of e.incompatibleWith)if(r.has(n.name)){const e=[o.name,n.name].sort().join("↔");if(i.has(e))continue;i.add(e),v("TBW022",`${Dt(o.name)}Plugin and ${Dt(n.name)}Plugin are both loaded, but they are currently incompatible.\n\n → ${n.reason}\n\n Consider removing one of these plugins to avoid unexpected behavior.`,t)}}}(this.#ge?.getPlugins()??[],this.id),this.#bt(),this.#Te=[...this._columns]}_schedulerProcessColumns(){this.#pt()}_schedulerProcessRows(){this.#mt()}_schedulerRenderHeader(){he(this)}_schedulerUpdateTemplate(){M(this)}_schedulerAfterRender(){this.#ge?.afterRender(),this.#De(),this._virtualization.enabled&&this._virtualization.totalHeightEl&&queueMicrotask(()=>{if(!this._virtualization.totalHeightEl)return;const e=this.#we.calculateTotalSpacerHeight(this._rows.length);this._virtualization.totalHeightEl.style.height=`${e}px`});"fixed"!==this.#b.fitMode||this.__didInitialAutoSize||(this.__didInitialAutoSize=!0,E(this)),this._restoreFocusAfterRender&&(this._restoreFocusAfterRender=!1,qe(this)),this._virtualization.enabled&&!this.#Ke&&this.#st(),this.#oe&&(this.#oe=!1,requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.#it()})})),this.#Re&&this.#Pe()}get _schedulerIsConnected(){return this.isConnected&&this.#Z}get _hostElement(){return this}get _renderRoot(){return this.#j}_emit(e,t){this.#at(e,t)}get _accordionIcons(){return{expand:this.#b?.icons?.expand??o.expand,collapse:this.#b?.icons?.collapse??o.collapse}}_pluginShellContributions(){return{toolPanels:(this.#ge?.getToolPanels()??[]).map(e=>e.panel),headerContents:(this.#ge?.getHeaderContents()??[]).map(e=>e.content)}}_clearRowPool(){const e=this.__frameworkAdapter,t=e?.releaseCell;if(t){e?.beginBatch?.(this);try{for(let r=0;r<this._rowPool.length;r++){const i=this._rowPool[r].children;for(let r=0;r<i.length;r++){const o=i[r];o.firstElementChild&&t.call(e,o)}}this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML="")}finally{e?.endBatch?.(this)}}else this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML="");this.__rowRenderEpoch++}_setup(){this.#Je()}_applyAnimationConfig(e){const t={...i,...e.animation},r=t.mode??"reduced-motion";let o=1;!1===r||"off"===r?o=0:!0!==r&&"on"!==r||(o=1),this.style.setProperty("--tbw-animation-duration",`${t.duration}ms`),this.style.setProperty("--tbw-animation-easing",t.easing??"ease-out"),this.style.setProperty("--tbw-animation-enabled",String(o)),this.dataset.animationMode="boolean"==typeof r?r?"on":"off":r}#bt(){!function(e,t,r){if(!t)return!1;let i=!1;const o=r?.gridAriaLabelledBy,n=o?void 0:function(e){const t=e?.gridAriaLabel;return t||(e?.shell?.header?.title??void 0)}(r);o!==e.ariaLabelledBy&&(e.ariaLabelledBy=o,o?t.setAttribute("aria-labelledby",o):t.removeAttribute("aria-labelledby"),i=!0),n!==e.ariaLabel&&(e.ariaLabel=n,n?t.setAttribute("aria-label",n):t.removeAttribute("aria-label"),i=!0);const s=r?.gridAriaDescribedBy;s!==e.ariaDescribedBy&&(e.ariaDescribedBy=s,s?t.setAttribute("aria-describedby",s):t.removeAttribute("aria-describedby"),i=!0);const a=r?.gridAriaRoleDescription;a!==e.ariaRoleDescription&&(e.ariaRoleDescription=a,a?t.setAttribute("aria-roledescription",a):t.removeAttribute("aria-roledescription"),i=!0)}(this.#lt,this.__rowsBodyEl,this.#b)}#Pe(){const e=this.querySelector(".tbw-grid-root");var t;e&&(this.#Re?(this.#Ae||(this.#Ae=function(e){const t=document.createElement("div");return t.className="tbw-loading-overlay",t.setAttribute("role","status"),t.setAttribute("aria-live","polite"),t.appendChild(at("large",e)),t}(this.#b?.loadingRenderer)),function(e,t){e.appendChild(t)}(e,this.#Ae)):(t=this.#Ae,t?.remove()))}#De(){!function(e,t,r,i,o,n,s){if(!e)return;if(!function(e,t,r){return!(e||t>0||null===r)}(t,r,o))return Ce(s.el),s.el=void 0,s.renderer=void 0,s.target=void 0,s.sourceRows=void 0,void(s.filteredOut=void 0);const a=i.length,l=a>0&&0===r;if(s.el&&s.renderer===o&&s.target===n&&s.sourceRows===i&&s.filteredOut===l)return;const c="grid"===n?e:e.querySelector(".rows-container")??e;Ce(s.el),s.el=_e({sourceRowCount:a,filteredOut:l},o??void 0,n),function(e,t){e.appendChild(t)}(c,s.el),s.renderer=o,s.target=n,s.sourceRows=i,s.filteredOut=l}(this.querySelector(".tbw-grid-root"),this.#Re,this._rows.length,this.#X,this.#b?.emptyRenderer,this.#b?.emptyOverlay??"rows",this.#Me)}#Ie(e,t){this.#ft();const r=this.#xe.get(e);if(!r)return;const i=this.findRenderedRowElement?.(r.index);i&&function(e,t){if(t){if(e.classList.add("tbw-row-loading"),e.setAttribute("aria-busy","true"),!e.querySelector(".tbw-row-loading-overlay")){const t=document.createElement("div");t.className="tbw-row-loading-overlay",t.setAttribute("aria-hidden","true");const r=document.createElement("div");r.className="tbw-row-loading-spinner",t.appendChild(r),e.appendChild(t)}}else e.classList.remove("tbw-row-loading"),e.removeAttribute("aria-busy"),e.querySelector(".tbw-row-loading-overlay")?.remove()}(i,t)}#Oe(e,t,r){this.#ft();const i=this.#xe.get(e);if(!i)return;const o=this.findRenderedRowElement?.(i.index);if(!o)return;const n=this._visibleColumns.findIndex(e=>e.field===t);if(n<0)return;const s=o.children[n];s&&function(e,t){t?(e.classList.add("tbw-cell-loading"),e.setAttribute("aria-busy","true")):(e.classList.remove("tbw-cell-loading"),e.removeAttribute("aria-busy"))}(s,r)}#Je(){if(this.isConnected&&this._headerRowEl&&this._bodyEl){if(this.#K.parseLightDomColumns(this),this.#E){const e=this.#E;this.#E=void 0,this.#K.merge();const t=this.#ge?.getAll()??[];this.#K.applyState(e,t)}this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),this.#ee.requestPhase(fe.FULL,"setup")}}#ot(e){const t=this._virtualization.container,r=this.#_e,i=r?.scrollLeft??0,o=t?.scrollHeight??0,n=r?.scrollWidth??0,s=t?.clientHeight??0,a=r?.clientWidth??0;if(this.refreshVirtualWindow(!1)&&this.#ge?.onScrollRender(),this._virtualization.variableHeights&&(this.#ne&&clearTimeout(this.#ne),this.#ne=window.setTimeout(()=>{this.#ne=0,this.#we.measureRenderedRowHeights(this._virtualization.start,this._virtualization.end)},100)),this.#ie){const t=this.#he;t.scrollTop=e,t.scrollLeft=i,t.scrollHeight=o,t.scrollWidth=n,t.clientHeight=s,t.clientWidth=a,this.#ge?.onScroll(t)}this.#at("tbw-scroll",{scrollTop:e,scrollHeight:o,clientHeight:s,direction:"vertical"})}findHeaderRow(){return this.#j.querySelector(".header-row")}findRenderedRowElement(e){const t=this._virtualization,r=e-t.start;return r>=0&&r<this._rowPool.length&&r<t.end-t.start?this._rowPool[r]:null}_dispatchCellClick(e,t,r,i){const o=this._rows[t],n=this._visibleColumns[r];if(!o||!n)return!1;const s=n.field,a=o[s],l=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,composed:!0,detail:{rowIndex:t,colIndex:r,column:n,field:s,value:a,row:o,cellEl:i,trigger:"pointer",originalEvent:e}});if(this.dispatchEvent(l),l.defaultPrevented)return!0;const c={row:o,rowIndex:t,colIndex:r,column:n,field:s,value:a,cellEl:i,originalEvent:e},d=this.#ge?.onCellClick(c)??!1;return this.#at("cell-click",c),d}_dispatchRowClick(e,t,r,i){if(!r)return!1;const o={rowIndex:t,row:r,rowEl:i,originalEvent:e},n=this.#ge?.onRowClick(o)??!1;return this.#at("row-click",o),n}_dispatchHeaderClick(e,t,r){if(!t)return!1;const i={colIndex:this._columns.indexOf(t),field:t.field,column:t,headerEl:r,originalEvent:e};return this.#ge?.onHeaderClick(i)??!1}_dispatchKeyDown(e){return this.#ge?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,t){return this.#ge?.getHorizontalScrollOffsets(e,t)??{left:0,right:0}}query(e,t){return this.#ge?.queryPlugins({type:e,context:t})??[]}_dispatchCellMouseDown(e){return this.#ge?.onCellMouseDown(e)??!1}_dispatchCellMouseMove(e){this.#ge?.onCellMouseMove(e)}_dispatchCellMouseUp(e){this.#ge?.onCellMouseUp(e)}_afterCellRender(e){this.#ge?.afterCellRender(e)}_hasAfterCellRenderHook(){return this.#ge?.hasAfterCellRenderHook()??!1}_afterRowRender(e){this.#ge?.afterRowRender(e)}_hasAfterRowRenderHook(){return this.#ge?.hasAfterRowRenderHook()??!1}async ready(){return this.#i}async forceLayout(){return 0===this.#ee.pendingPhase&&this.#ee.requestPhase(fe.FULL,"forceLayout"),this.#ee.whenReady()}async getConfig(){return Object.freeze({...this.#b||{}})}getRowId(e){return pt(e,this.id,this.#b.getRowId)}getRow(e){return this.#be.getRow(e)}_getRowEntry(e){return this.#ft(),this.#xe.get(e)}updateRow(e,t,r="api"){this.#be.updateRow(e,t,r)}updateRows(e,t="api"){this.#be.updateRows(e,t)}animateRow(e,t){return gt(this,e,t)}animateRows(e,t){return function(e,t,r){return Promise.all(t.map(t=>gt(e,t,r))).then(e=>e.filter(Boolean).length)}(this,e,t)}animateRowById(e,t){return function(e,t,r){const i=e._rows??[],o=e.getRowId;if(!o)return Promise.resolve(!1);const n=i.findIndex(e=>{if(null==e)return!1;try{return o(e)===t}catch{return!1}});return n<0?Promise.resolve(!1):gt(e,n,r)}(this,e,t)}async insertRow(e,t,r=!0){return this.#be.insertRow(e,t,r)}async removeRow(e,t=!0){return this.#be.removeRow(e,t)}async applyTransaction(e,t=!0){return this.#be.applyTransaction(e,t)}applyTransactionAsync(e){return this.#be.applyTransactionAsync(e)}focusCell(e,t){this.#me.focusCell(e,t)}get focusedCell(){return this.#me.focusedCell}scrollToRow(e,t){this.#me.scrollToRow(e,t)}scrollToRowById(e,t){this.#me.scrollToRowById(e,t)}setColumnVisible(e,t){const r=this.#K.setColumnVisible(e,t);return r&&this.requestStateChange(),r}toggleColumnVisibility(e){const t=this.#K.toggleColumnVisibility(e);return t&&this.requestStateChange(),t}isColumnVisible(e){return this.#K.isColumnVisible(e)}showAllColumns(){this.#K.showAllColumns(),this.requestStateChange()}getAllColumns(){return this.#K.getAllColumns()}setColumnOrder(e){this.#K.setColumnOrder(e),this.requestStateChange()}getColumnOrder(){return this.#K.getColumnOrder()}getColumnState(){const e=this.#ge?.getAll()??[];return this.#K.collectState(e)}get columnState(){return this.getColumnState()}applyColumnState(e){e&&(this.#Y?this.#vt(e):(this.#E=e,this.#K.initialColumnState=e))}#vt(e){const t=this._columns,r=this._sortState,i=this.#ge?.getAll()??[];this.#K.applyState(e,i);if(!e.columns.some(e=>void 0!==e.sort)&&this.#yt(t,r))return this.#ke=void 0,M(this),void this.#ee.requestPhase(fe.STYLE,"column-width");this.#Je()}#yt(e,t){const r=this._columns,i=this._sortState;if(t?.field!==i?.field||t?.direction!==i?.direction)return!1;if(e.length!==r.length)return!1;for(let o=0;o<e.length;o++){const t=e[o],i=r[o];if(t.field!==i.field)return!1;if(!!t.hidden!=!!i.hidden)return!1}return!0}get sortModel(){return this._sortState?{field:this._sortState.field,direction:1===this._sortState.direction?"asc":"desc"}:null}sort(e,t){if(null===e){if(!this._sortState)return;const e=this._sortState.field;this._sortState=null,this.__rowRenderEpoch++;for(let t=0;t<this._rowPool.length;t++)this._rowPool[t].__epoch=-1;return this._rows=this.__originalOrder.slice(),this.__originalOrder=[],he(this),this.refreshVirtualWindow(!0),this.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e,direction:0}})),this._pluginManager?.emitPluginEvent?.("sort-change",{field:e,direction:0}),void this.requestStateChange?.()}const r=this._columns.find(t=>t.field===e);r&&(t?(this._sortState||(this.__originalOrder=this._rows.slice()),se(this,r,"desc"===t?-1:1)):ne(this,r))}requestStateChange(){const e=this.#ge?.getAll()??[];this.#K.requestStateChange(e)}resetColumnState(){this.#E=void 0,this.__originalOrder=[];const e=this.#ge?.getAll()??[];this.#K.resetState(e),this.#K.merge(),this.#Je()}get defaultRowHeight(){return this._virtualization.rowHeight}#_t=!1;refreshShellHeader(){this.#_t||(this.#_t=!0,queueMicrotask(()=>{this.#_t=!1,this.isConnected&&(this.#Ge(),this.#K.markSourcesChanged(),this.#K.merge(),this.#ge?.beforeStructuralRender(),this.#ge?.afterStructuralRender(),this.#Ct())}))}#Ct(){const e=this.#j.querySelector(".tbw-grid-content")??this.#j.querySelector(".tbw-grid-root");this._headerRowEl=e?.querySelector(".header-row"),this._virtualization.totalHeightEl=e?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=e?.querySelector(".rows-viewport"),this._bodyEl=e?.querySelector(".rows"),this.__rowsBodyEl=e?.querySelector(".rows-body"),this._resizeController=lt(this),this.#Ve(e),this.#ee.requestPhase(fe.COLUMNS,"shellRefresh")}#Qe=new Map;registerStyles(e,t){let r=this.#Qe.get(e);r||(r=new CSSStyleSheet,this.#Qe.set(e,r)),r.replaceSync(t),this.#Rt()}unregisterStyles(e){this.#Qe.delete(e)&&this.#Rt()}getRegisteredStyles(){return Array.from(this.#Qe.keys())}#Rt(){const e=Array.from(this.#Qe.values()),t=document.adoptedStyleSheets.filter(e=>!Array.from(this.#Qe.values()).includes(e));document.adoptedStyleSheets=[...t,...e]}registerExternalFocusContainer(e){this.#me.registerExternalFocusContainer(e)}unregisterExternalFocusContainer(e){this.#me.unregisterExternalFocusContainer(e)}containsFocus(e){return this.#me.containsFocus(e)}get lastFocusedElement(){return this.#me.lastFocusedElement}restoreLastFocus(){return this.#me.restoreLastFocus()}#Ge(){this.#ge?.parseLightDom()}#Xe(){const e=()=>{this.#K.clearLightDomCache(),this.#Je()};this.#K.registerLightDomHandler("tbw-grid-column",e),this.#K.registerLightDomHandler("tbw-grid-detail",e),this.#K.registerLightDomHandler("tbw-grid-type",e),this.#K.observeLightDOM(this)}refreshColumns(){this.#K.clearLightDomCache(),Xe(this),this.#K.parseLightDomColumns(this),this.#ge?.syncLightDom(),this.#ee.requestPhase(fe.COLUMNS,"refreshColumns")}#nt(){this.#we.updateCachedGeometry()}refreshVirtualWindow(e=!1,t=!1){return this.#we.refreshVirtualWindow(e,t)}invalidateRowHeight(e,t){this.#we.invalidateRowHeight(e,t)}#je(){this.#Ge(),this.#K.markSourcesChanged(),this.#K.merge(),function(e){const t=[];for(let r=e.firstChild;r;r=r.nextSibling)1===r.nodeType&&r.classList.contains(H.ROOT)||t.push(r);e.replaceChildren();for(const r of t)e.appendChild(r);e.appendChild(ve())}(this.#j),this.#ge?.afterStructuralRender()}}!function(){const e=Nt.tagName,t=customElements.get(e);if(!t)return customElements.define(e,Nt),void(Nt.activeTag=e);if(t.version===Nt.version)return void(Nt.activeTag=e);const r=`${e}-v${Nt.version.replace(/[^a-zA-Z0-9]+/g,"-").toLowerCase()}`;customElements.get(r)||customElements.define(r,Nt),Nt.activeTag=r}(),globalThis.DataGridElement||(globalThis.DataGridElement=Nt);function Ft(e,t,r){return r?.valueAccessor?X(e,r):e?.[t]}function qt(e){return null==e||""===e||"number"==typeof e&&isNaN(e)}const $t={sum:(e,t,r)=>{let i=0;for(let o=0;o<e.length;o++){const n=Ft(e[o],t,r);if(qt(n))continue;const s=Number(n);isNaN(s)||(i+=s)}return i},avg:(e,t,r)=>{if(!e.length)return 0;let i=0,o=0;for(let n=0;n<e.length;n++){const s=Ft(e[n],t,r);if(qt(s))continue;const a=Number(s);isNaN(a)||(i+=a,o++)}return o>0?i/o:0},count:e=>e.length,min:(e,t,r)=>{if(!e.length)return 0;let i=1/0;for(let o=0;o<e.length;o++){const n=Ft(e[o],t,r);if(qt(n))continue;const s=Number(n);isNaN(s)||s<i&&(i=s)}return i===1/0?0:i},max:(e,t,r)=>{if(!e.length)return 0;let i=-1/0;for(let o=0;o<e.length;o++){const n=Ft(e[o],t,r);if(qt(n))continue;const s=Number(n);isNaN(s)||s>i&&(i=s)}return i===-1/0?0:i},first:(e,t,r)=>e[0]?Ft(e[0],t,r):void 0,last:(e,t,r)=>e.length?Ft(e[e.length-1],t,r):void 0},Wt=new Map,Vt={register(e,t){Wt.set(e,t)},unregister(e){Wt.delete(e)},get(e){if(void 0!==e)return"function"==typeof e?e:Wt.get(e)??$t[e]},run(e,t,r,i){const o=this.get(e);return o?o(t,r,i):void 0},has:e=>Wt.has(e)||e in $t,list:()=>[...Object.keys($t),...Wt.keys()]},Ut={sum:e=>{let t=0;for(let r=0;r<e.length;r++)t+=e[r];return t},avg:e=>{if(!e.length)return 0;let t=0;for(let r=0;r<e.length;r++)t+=e[r];return t/e.length},count:e=>e.length,min:e=>{if(!e.length)return 0;let t=e[0];for(let r=1;r<e.length;r++)e[r]<t&&(t=e[r]);return t},max:e=>{if(!e.length)return 0;let t=e[0];for(let r=1;r<e.length;r++)e[r]>t&&(t=e[r]);return t},first:e=>e[0]??0,last:e=>e[e.length-1]??0};function Bt(e){return Ut[e]??Ut.sum}e.BaseGridPlugin=class{static dependencies;static manifest;aliases;version="3.0.0-beta.4";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#Et;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#Et?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},r={};for(const i of Object.keys(t))r[i]=this;for(const i of e){const e=i.userConfig;for(const[o,n]of Object.entries(e)){if(void 0===n)continue;if(!(o in t)){t[o]=n,r[o]=i;continue}if(t[o]===n)continue;const e=r[o]?.constructor.name??this.constructor.name,s=i.constructor.name,a=m("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${e} and ${s}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const i of Object.keys(t))delete t[i];Object.assign(t,r)}attach(e){this.#Et?.abort(),this.#Et=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#Et?.abort(),this.#Et=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.#Et?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...o,...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=j(t),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const i=this.#St(t,r);void 0!==i?"string"==typeof i?e.innerHTML=$(i):i instanceof HTMLElement&&(e.innerHTML="",e.appendChild(i.cloneNode(!0))):e.innerHTML=""}#St(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 i=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return i?e.insertBefore(r,i):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(m(e,t,this.gridElement.id,this.name)):console.warn(`${h(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(m(e,t,this.gridElement.id,this.name))}},e.CORE_CONSUMED_ADAPTER_METHODS=["canHandle","createRenderer","createEditor","processConfig","getTypeDefault","createToolPanelRenderer","parseDetailElement","parseResponsiveCardElement","releaseCell","unmount","beginBatch","endBatch"],e.ColumnInferenceModeEnum={AUTO:"auto",MERGE:"merge"},e.DEFAULT_A11Y_MESSAGES=r,e.DEFAULT_ANIMATION_CONFIG=i,e.DEFAULT_GRID_ICONS=o,e.DataGridElement=Nt,e.FitModeEnum=t,e.GridCSSVars={COLOR_BG:"--tbw-color-bg",COLOR_FG:"--tbw-color-fg",COLOR_FG_MUTED:"--tbw-color-fg-muted",COLOR_BORDER:"--tbw-color-border",COLOR_ACCENT:"--tbw-color-accent",COLOR_HEADER_BG:"--tbw-color-header-bg",COLOR_HEADER_FG:"--tbw-color-header-fg",COLOR_SELECTION:"--tbw-color-selection",COLOR_ROW_HOVER:"--tbw-color-row-hover",COLOR_ROW_ALT:"--tbw-color-row-alt",ROW_HEIGHT:"--tbw-row-height",HEADER_HEIGHT:"--tbw-header-height",CELL_PADDING:"--tbw-cell-padding",FONT_FAMILY:"--tbw-font-family",FONT_SIZE:"--tbw-font-size",BORDER_RADIUS:"--tbw-border-radius",FOCUS_OUTLINE:"--tbw-focus-outline"},e.GridClasses=H,e.GridDataAttrs=T,e.GridElement=Nt,e.GridSelectors=k,e.MAX_ELEMENT_HEIGHT_PX=De,e.PluginManager=zt,e.RenderPhase=fe,e.aggregatorRegistry=Vt,e.applyColumnDefaults=function(e,t){return t?e.map(e=>({...t,...e})):e},e.builtInSort=Z,e.computeScrollMapping=Ie,e.createGrid=function(e){const t=document.createElement(Nt.activeTag);return e&&(t.gridConfig=e),t},e.defaultComparator=function(e,t){return null==e&&null==t?0:null==e?-1:null==t||e>t?1:e<t?-1:0},e.fromVirtualScrollTop=ze,e.getValueAggregator=Bt,e.hasColumnShorthands=function(e){return e.some(e=>"string"==typeof e)},e.invalidateAccessorCache=K,e.normalizeColumns=u,e.parseColumnShorthand=d,e.queryGrid=function(e,t,r){let i=document,o=!1;return"boolean"==typeof t?o=t:t&&(i=t,o=!!r),o?customElements.whenDefined(Nt.activeTag).then(()=>i.querySelector(e)):i.querySelector(e)},e.resolveCellValue=X,e.runValueAggregator=function(e,t){return Bt(e)(t)},e.setFeatureResolver=function(e){it=e},e.toVirtualScrollTop=Oe,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGrid={})}(this,function(e){"use strict";const t={STRETCH:"stretch",FIXED:"fixed"},r={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`},i={mode:"reduced-motion",duration:200,easing:"ease-out"},o={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function n(e,t){if(!e)return;const r="effectiveConfig"in e?e.effectiveConfig:void 0;if(!1===r?.a11y?.announcements)return;const i=e.querySelector?.(".tbw-sr-only");i&&(i.textContent="","function"==typeof requestAnimationFrame?requestAnimationFrame(()=>{i.textContent=t}):i.textContent=t)}function s(e,t,...i){const o=e&&"effectiveConfig"in e?e.effectiveConfig:void 0,n=o?.a11y?.messages?.[t];return n?n(...i):r[t](...i)}function a(e){return e.charAt(0).toUpperCase()+e.slice(1)}function l(e){if("id"===e.toLowerCase())return"ID";return e.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[_-]/g," ").split(" ").filter(Boolean).map(a).join(" ")}const c=new Set(["string","number","boolean","date","datetime","currency"]);function d(e){const t=e.lastIndexOf(":");if(t>0){const r=e.slice(t+1).toLowerCase();if(c.has(r)){const i=e.slice(0,t);return{field:i,header:l(i),type:r}}}return{field:e,header:l(e)}}function u(e){return e.map(e=>"string"==typeof e?d(e):e)}function h(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}const g="TBW021",f="TBW041",p="TBW061",w="TBW062";function m(e,t,r,i){return`${h(r,i)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}function b(e,t,r,i){throw new Error(m(e,t,r,i))}function v(e,t,r,i){console.warn(m(e,t,r,i))}function y(e,t,r,i){console.debug(m(e,t,r,i))}function _(e,t,r,i){console.error(m(e,t,r,i))}function C(e,t){if(!(e&&e.length||t&&t.length))return[];if(!e||!e.length)return t||[];if(!t||!t.length)return e;const r={},i=t;for(let s=0;s<i.length;s++){const e=i[s],t=r[e.field];if(t){e.header&&!t.header&&(t.header=e.header),e.type&&!t.type&&(t.type=e.type),e.sortable&&(t.sortable=!0),e.resizable&&(t.resizable=!0),null!=e.width&&null==t.width&&(t.width=e.width),null!=e.minWidth&&null==t.minWidth&&(t.minWidth=e.minWidth),e.__viewTemplate&&(t.__viewTemplate=e.__viewTemplate),e.__headerTemplate&&(t.__headerTemplate=e.__headerTemplate),e.__element&&!t.__element&&(t.__element=e.__element);const r=e.renderer||e.viewRenderer,i=t.renderer||t.viewRenderer;r&&!i&&(t.viewRenderer=r,e.renderer&&(t.renderer=r)),e.editor&&!t.editor&&(t.editor=e.editor),e.headerRenderer&&!t.headerRenderer&&(t.headerRenderer=e.headerRenderer),e.headerLabelRenderer&&!t.headerLabelRenderer&&(t.headerLabelRenderer=e.headerLabelRenderer)}else r[e.field]={...e}}const o=e.map(e=>{const t=r[e.field];if(!t)return e;const i={...e};t.header&&!i.header&&(i.header=t.header),t.type&&!i.type&&(i.type=t.type),i.sortable=e.sortable||t.sortable,!0!==e.resizable&&!0!==t.resizable||(i.resizable=!0),null!=t.width&&null==i.width&&(i.width=t.width),null!=t.minWidth&&null==i.minWidth&&(i.minWidth=t.minWidth),t.__viewTemplate&&(i.__viewTemplate=t.__viewTemplate),t.__headerTemplate&&(i.__headerTemplate=t.__headerTemplate),t.__element&&!i.__element&&(i.__element=t.__element);const o=t.renderer||t.viewRenderer,n=i.renderer||i.viewRenderer;return o&&!n&&(i.viewRenderer=o,t.renderer&&(i.renderer=o)),t.editor&&!i.editor&&(i.editor=t.editor),i.headerRenderer||i.headerLabelRenderer||(t.headerRenderer?i.headerRenderer=t.headerRenderer:t.headerLabelRenderer&&(i.headerLabelRenderer=t.headerLabelRenderer)),delete r[e.field],i}),n=Object.keys(r);for(let s=0;s<n.length;s++)o.push(r[n[s]]);return o}function R(e,t){try{e.part?.add?.(t)}catch{}const r=e.getAttribute("part");r?r.split(/\s+/).includes(t)||e.setAttribute("part",r+" "+t):e.setAttribute("part",t)}function E(e){const r=e.effectiveConfig?.fitMode||e.fitMode||t.STRETCH;if(r!==t.STRETCH&&r!==t.FIXED)return;if(e.__didInitialAutoSize)return;if(!e.isConnected)return;const i=Array.from(e._headerRowEl?.children||[]);if(!i.length)return;let o=!1;const n=e._visibleColumns;for(let t=0;t<n.length;t++){const r=n[t];if(r.width)continue;const s=i[t];let a=s?s.scrollWidth:0;for(let i=0;i<e._rowPool.length;i++){const r=e._rowPool[i].children[t];if(r){const e=r.scrollWidth;e>a&&(a=e)}}a>0&&(r.width=a+2,r.__autoSized=!0,o=!0)}o&&M(e),e.__didInitialAutoSize=!0}const S=/^(?:\d+(?:\.\d+)?(?:px|%|fr|em|rem|ch|vw|vh|vmin|vmax)|calc\(.+\)|min-content|max-content|minmax\(.+\)|fit-content\(.+\)|auto)$/i;function A(e,t){return"number"==typeof e?`${e}px`:(S.test(e)||v("TBW050",`Column '${t??"?"}' has an invalid CSS width value: '${e}'. Expected a number (px) or a valid CSS unit string (e.g. '30%', '2fr', 'calc(...)').`),e)}function M(e){const r=e.effectiveConfig?.fitMode||e.fitMode||t.STRETCH;e._gridTemplate=r===t.STRETCH?e._visibleColumns.map(e=>{if(null!=e.width)return A(e.width,e.field);const t=e.minWidth;return null!=t?`minmax(${t}px, 1fr)`:"1fr"}).join(" ").trim():e._visibleColumns.map(e=>null!=e.width?A(e.width,e.field):"max-content").join(" "),e.style.setProperty("--tbw-column-template",e._gridTemplate)}const x='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])',H={ROOT:"tbw-grid-root",HEADER:"header",HEADER_ROW:"header-row",HEADER_CELL:"header-cell",ROWS_VIEWPORT:"rows-viewport",ROWS_SPACER:"rows-spacer",ROWS_CONTAINER:"rows",DATA_ROW:"data-grid-row",GROUP_ROW:"group-row",DATA_CELL:"cell",SELECTED:"selected",FOCUSED:"focused",EDITING:"editing",EXPANDED:"expanded",COLLAPSED:"collapsed",DRAGGING:"dragging",RESIZING:"resizing",SORTABLE:"sortable",SORTED_ASC:"sorted-asc",SORTED_DESC:"sorted-desc",HIDDEN:"hidden",STICKY_LEFT:"sticky-left",STICKY_RIGHT:"sticky-right",PINNED_TOP:"pinned-top",PINNED_BOTTOM:"pinned-bottom",TREE_TOGGLE:"tree-toggle",TREE_INDENT:"tree-indent",GROUP_TOGGLE:"group-toggle",GROUP_LABEL:"group-label",GROUP_COUNT:"group-count",RANGE_SELECTION:"range-selection",SELECTION_OVERLAY:"selection-overlay"},T={FIELD:"data-field",GROUP_KEY:"data-group-key"},k={ROOT:`.${H.ROOT}`,HEADER:`.${H.HEADER}`,HEADER_ROW:`.${H.HEADER_ROW}`,HEADER_CELL:`.${H.HEADER_CELL}`,ROWS_VIEWPORT:`.${H.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${H.ROWS_CONTAINER}`,DATA_ROW:`.${H.DATA_ROW}`,DATA_CELL:`.${H.DATA_CELL}`,GROUP_ROW:`.${H.GROUP_ROW}`,CELL_BY_FIELD:e=>`.${H.DATA_CELL}[${T.FIELD}="${e}"]`,SELECTED_ROWS:`.${H.DATA_ROW}.${H.SELECTED}`,EDITING_CELL:`.${H.DATA_CELL}.${H.EDITING}`},L=/{{\s*([^}]+)\s*}}/g,P="__DG_EMPTY__",D=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,I="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(e=>e.split("").reverse().join("")),O=new RegExp(`__(proto|defineGetter|defineSetter)|${I.slice(3).join("|")}|this\\b`),z=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,F=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),q=/^\s*(javascript|vbscript|data|blob):/i;function $(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 i of r){const e=i.tagName.toLowerCase();if(z.has(e)){t.push(i);continue}if("svg"===e||"http://www.w3.org/2000/svg"===i.namespaceURI){if(Array.from(i.attributes).some(e=>N.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(i);continue}}const r=[];for(const t of i.attributes){const e=t.name.toLowerCase();N.test(e)?r.push(t.name):(F.has(e)&&q.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name)}r.forEach(e=>i.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}function W(e,t){const r=function(e){const t=[];let r=0;for(;r<e.length;){const i=e[r];if(" "!==i){if(i>="0"&&i<="9"||"."===i&&r+1<e.length&&e[r+1]>="0"&&e[r+1]<="9"){const i=r;for(;r<e.length&&(e[r]>="0"&&e[r]<="9"||"."===e[r]);)r++;t.push({type:"num",v:Number(e.slice(i,r))});continue}if("'"===i){let i="";for(r++;r<e.length&&"'"!==e[r];)i+=e[r++];if(r>=e.length)return null;r++,t.push({type:"str",v:i});continue}if(i>="a"&&i<="z"||i>="A"&&i<="Z"||"_"===i||"$"===i){const i=r;for(;r<e.length&&/[\w$.]/.test(e[r]);)r++;t.push({type:"id",v:e.slice(i,r)});continue}if(r+2<e.length){const i=e.slice(r,r+3);if("==="===i||"!=="===i){t.push({type:"op",v:i}),r+=3;continue}}if(r+1<e.length){const i=e.slice(r,r+2);if("=="===i||"!="===i||"<="===i||">="===i||"&&"===i||"||"===i){t.push({type:"op",v:i}),r+=2;continue}}if(!"+-*/%<>!?:(),".includes(i))return null;t.push({type:"op",v:i}),r++}else r++}return t}(e);if(!r)return;const i=r;let o=0;function n(){return i[o]}function s(){return i[o++]}function a(e,t){const r=n();return!!r&&(r.type===e&&(void 0===t||r.v===t))}function l(){const e=function(){let e=c();for(;a("op","||");)s(),e=e||c();return e}();if(a("op","?")){s();const t=l();if(!a("op",":"))return;s();const r=l();return e?t:r}return e}function c(){let e=d();for(;a("op","&&");)s(),e=e&&d();return e}function d(){let e=u();for(;;){const t=n();if(!t||"op"!==t.type)break;if("==="===t.v)s(),e=e===u();else if("!=="===t.v)s(),e=e!==u();else if("=="===t.v)s(),e=e==u();else{if("!="!==t.v)break;s(),e=e!=u()}}return e}function u(){let e=h();for(;;){const t=n();if(!t||"op"!==t.type)break;if("<"===t.v)s(),e=e<h();else if(">"===t.v)s(),e=e>h();else if("<="===t.v)s(),e=e<=h();else{if(">="!==t.v)break;s(),e=e>=h()}}return e}function h(){let e=g();for(;;){const t=n();if(!t||"op"!==t.type)break;if("+"===t.v)s(),e+=g();else{if("-"!==t.v)break;s(),e-=g()}}return e}function g(){let e=f();for(;;){const t=n();if(!t||"op"!==t.type)break;if("*"===t.v)s(),e*=f();else if("/"===t.v)s(),e/=f();else{if("%"!==t.v)break;s(),e%=f()}}return e}function f(){return a("op","!")?(s(),!f()):p()}function p(){const e=n();if(e){if("num"===e.type)return s(),e.v;if("str"===e.type)return s(),e.v;if("id"===e.type)return s(),function(e){if("value"===e)return t.value;if(e.startsWith("row.")){const r=e.slice(4);return t.row?t.row[r]:void 0}if(e.startsWith("typeDefault.")){const r=e.slice(12);return t.typeDefault?t.typeDefault[r]:void 0}return"row"===e?t.row:"typeDefault"===e?t.typeDefault:void 0}(e.v);if("op"===e.type&&"("===e.v){s();const e=l();return a("op",")")&&s(),e}return"op"===e.type&&"-"===e.v?(s(),-p()):void 0}}const w=l();return o<i.length?void 0:w}function V(e,t){if(!e||-1===e.indexOf("{{"))return e;const r=[],i=e.replace(L,(e,i)=>{const o=function(e,t){if(e=(e||"").trim(),!e)return P;if(U.test(e))return P;if("value"===e)return null==t.value?P:String(t.value);if(e.startsWith("row.")&&!/[()?]/.test(e)&&!e.includes(":")){const r=e.slice(4),i=t.row?t.row[r]:void 0;return null==i?P:String(i)}if(e.startsWith("typeDefault.")&&!/[()?]/.test(e)&&!e.includes(":")){const r=e.slice(12),i=t.typeDefault?t.typeDefault[r]:void 0;return null==i?P:String(i)}if(e.length>80)return P;if(!D.test(e)||O.test(e))return P;const r=e.match(/\./g);if(r&&r.length>1)return P;try{const r=W(e,t),i=null==r?"":String(r);return U.test(i)?P:i||P}catch{return P}}(i,t);return r.push({expr:i.trim(),result:o}),o}),o=(n=i)?n.replace(new RegExp(P,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):n;var n;const s=r.length&&r.every(e=>""===e.result||e.result===P);return U.test(e)||s?"":o}const U=/Reflect|Proxy|ownKeys/;function B(e){if(U.test(e.textContent||"")){for(const t of e.childNodes)t.nodeType===Node.TEXT_NODE&&U.test(t.textContent||"")&&(t.textContent="");U.test(e.textContent||"")&&(e.textContent="")}}function G(e){if(U.test(e)){const e=()=>"";return e.__blocked=!0,e}const t=t=>V(e,t);return t.__blocked=!1,t}function j(e){return e.replace(/([A-Z])/g,"-$1").toLowerCase()}const Y=new WeakMap;function X(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 i=e,o=t.field;let n=Y.get(i);if(n){const e=n.get(o);if(void 0!==e)return e.v}else n=new Map,Y.set(i,n);const s=t.valueAccessor({row:e,column:t,rowIndex:r});return n.set(o,{v:s}),s}function K(e,t){e&&(t?Y.get(e)?.delete(t):Y.delete(e))}function Z(e,t,r){const i=r.find(e=>e.field===t.field),o=i?.sortComparator,{field:n,direction:s}=t,a=[...e];return o?i?.valueAccessor?a.sort((e,t)=>o(X(e,i),X(t,i),e,t)*s):a.sort((e,t)=>o(e[n],t[n],e,t)*s):i?.valueAccessor?J(a,i,s):Q(a,n,s),a}function Q(e,t,r){e.sort((e,i)=>{const o=ee(e,i);if(0!==o)return o;const n=e[t],s=i[t];return null==n&&null==s?0:null==n?-r:null==s||n>s?r:n<s?-r:0})}function J(e,t,r){e.sort((e,i)=>{const o=ee(e,i);if(0!==o)return o;const n=X(e,t),s=X(i,t);return null==n&&null==s?0:null==n?-r:null==s||n>s?r:n<s?-r:0})}function ee(e,t){const r=!0===e?.__loading;return r===(!0===t?.__loading)?0:r?1:-1}function te(e,t,r,i){const o=i.find(e=>e.field===t),n=o?.sortComparator;n?o?.valueAccessor?e.sort((e,t)=>n(X(e,o),X(t,o),e,t)*r):e.sort((e,i)=>n(e[t],i[t],e,i)*r):o?.valueAccessor?J(e,o,r):Q(e,t,r)}function re(e,t,r,i){e._rows=t,e.__rowRenderEpoch++;for(let o=0;o<e._rowPool.length;o++)e._rowPool[o].__epoch=-1;e._schedulerRenderHeader(),e.refreshVirtualWindow(!0),ie(e,r,i)}function ie(e,t,r){const i={field:t.field,direction:r};e.dispatchEvent(new CustomEvent("sort-change",{detail:i})),e._pluginManager?.emitPluginEvent?.("sort-change",i),n(e,s(e,0===r?"sortCleared":"sortApplied",t.header??t.field,1===r?"ascending":"descending")),e.requestStateChange?.()}function oe(e){return e._pluginManager?._hasRowStructurePlugins??!1}function ne(e,t){if(e._sortState&&e._sortState.field===t.field)if(1===e._sortState.direction)se(e,t,-1);else{if(e._sortState=null,oe(e))return e._requestSchedulerPhase(4,"sort-clear"),void ie(e,t,0);e.__rowRenderEpoch++;for(let t=0;t<e._rowPool.length;t++)e._rowPool[t].__epoch=-1;e._rows=e.__originalOrder.slice(),e.__originalOrder=[],e._schedulerRenderHeader();const r=e._headerRowEl?.querySelectorAll('[role="columnheader"].sortable');if(r)for(let t=0;t<r.length;t++){const i=r[t];i.getAttribute("aria-sort")&&("ascending"!==i.getAttribute("aria-sort")&&"descending"!==i.getAttribute("aria-sort")||e._sortState)||i.setAttribute("aria-sort","none")}e.refreshVirtualWindow(!0),ie(e,t,0)}else e._sortState||(e.__originalOrder=e._rows.slice()),se(e,t,1)}function se(e,t,r){if(e._sortState={field:t.field,direction:r},oe(e))return e._requestSchedulerPhase(4,"sort-apply"),void ie(e,t,r);const i={field:t.field,direction:r},o=e._columns,n=e.effectiveConfig?.sortHandler??Z;if(n===Z)return te(e._rows,i.field,r,o),void re(e,e._rows,t,r);const s=n(e._rows,i,o);s&&"function"==typeof s.then?s.then(i=>{re(e,i,t,r)}):re(e,s,t,r)}function ae(e,t){return!1!==e.effectiveConfig?.sortable&&!0===t.sortable}function le(e,t){return!1!==e.effectiveConfig?.resizable&&!1!==t.resizable}function ce(e,t){const r=document.createElement("span");R(r,"sort-indicator");const i=e._sortState?.field===t.field?e._sortState.direction:0,o=1===i?"sortAsc":-1===i?"sortDesc":"sortNone";r.dataset.icon=j(o);const n=e.icons?.[o];return void 0!==n&&function(e,t){"string"==typeof t?e.innerHTML=$(t):t instanceof HTMLElement&&(e.innerHTML="",e.appendChild(t.cloneNode(!0)))}(r,n),r}function de(e,t,r){const i=document.createElement("div");return i.className="resize-handle",i.setAttribute("aria-hidden","true"),i.addEventListener("mousedown",i=>{i.stopPropagation(),i.preventDefault(),e._resizeController.start(i,t,r)}),i.addEventListener("dblclick",r=>{r.stopPropagation(),r.preventDefault(),e._resizeController.resetColumn(t)}),i}function ue(e,t,r,i){i.classList.add(H.SORTABLE),i.tabIndex=0;const o=e._sortState?.field===t.field?e._sortState.direction:0;i.setAttribute("aria-sort",0===o?"none":1===o?"ascending":"descending"),i.addEventListener("click",r=>{e._resizeController?.isResizing||e._dispatchHeaderClick?.(r,t,i)||ne(e,t)}),i.addEventListener("keydown",r=>{if("Enter"===r.key||" "===r.key){if(r.preventDefault(),e._dispatchHeaderClick?.(r,t,i))return;ne(e,t)}})}function he(e){e._headerRowEl=e.findHeaderRow();const t=e._headerRowEl;t&&(t.innerHTML="",e._visibleColumns.forEach((r,i)=>{const o=document.createElement("div");o.className="cell",R(o,"header-cell"),o.setAttribute("role","columnheader"),o.setAttribute("aria-colindex",String(i+1)),o.setAttribute("data-field",r.field),o.setAttribute("data-col",String(i)),r.type&&o.setAttribute("data-type",r.type);const n=r.header??r.field,s=e._sortState?.field===r.field?e._sortState.direction:0,a=1===s?"asc":-1===s?"desc":null;if(r.headerRenderer){const t={column:r,value:n,sortState:a,filterActive:!1,cellEl:o,renderSortIcon:()=>ae(e,r)?ce(e,r):null,renderFilterButton:()=>null},s=r.headerRenderer(t);!function(e,t){if(null!=t)if("string"==typeof t){const r=document.createElement("span");for(r.innerHTML=$(t);r.firstChild;)e.appendChild(r.firstChild)}else t instanceof Node&&e.appendChild(t)}(o,s),ae(e,r)&&ue(e,r,0,o),le(e,r)&&(o.classList.add("resizable"),o.appendChild(de(e,i,o)))}else if(r.headerLabelRenderer){const t={column:r,value:n},s=r.headerLabelRenderer(t),a=document.createElement("span");null==s?a.textContent=n:"string"==typeof s?a.innerHTML=$(s):s instanceof Node&&a.appendChild(s),o.appendChild(a),ae(e,r)&&(ue(e,r,0,o),o.appendChild(ce(e,r))),le(e,r)&&(o.classList.add("resizable"),o.appendChild(de(e,i,o)))}else if(r.__headerTemplate)Array.from(r.__headerTemplate.childNodes).forEach(e=>o.appendChild(e.cloneNode(!0))),ae(e,r)&&(ue(e,r,0,o),o.appendChild(ce(e,r))),le(e,r)&&(o.classList.add("resizable"),o.appendChild(de(e,i,o)));else{const t=document.createElement("span");t.textContent=n,o.appendChild(t),ae(e,r)&&(ue(e,r,0,o),o.appendChild(ce(e,r))),le(e,r)&&(o.classList.add("resizable"),o.appendChild(de(e,i,o)))}t.appendChild(o)}),t.querySelectorAll(`.cell.${H.SORTABLE}`).forEach(e=>{e.getAttribute("aria-sort")||e.setAttribute("aria-sort","none")}),t.children.length>0?(t.setAttribute("role","row"),t.setAttribute("aria-rowindex","1")):(t.removeAttribute("role"),t.removeAttribute("aria-rowindex")))}function ge(e,t){const r=e[0]||{},i=Object.keys(r).map(e=>{const t=r[e],i=null==(o=t)?"string":"number"==typeof o?"number":"boolean"==typeof o?"boolean":o instanceof Date||"string"==typeof o&&/\d{4}-\d{2}-\d{2}/.test(o)&&!isNaN(Date.parse(o))?"date":"string";var o;return{field:e,header:e.charAt(0).toUpperCase()+e.slice(1),type:i}}),o={};return i.forEach(e=>{o[e.field]=e.type||"string"}),{columns:i,typeMap:o}}const fe={STYLE:1,VIRTUALIZATION:2,HEADER:3,ROWS:4,COLUMNS:5,FULL:6};class pe{#e;#t=0;#r=0;#i=null;#o=null;#n=null;#s=!1;constructor(e){this.#e=e}requestPhase(e,t){e>this.#t&&(this.#t=e),0===this.#r&&(this.#a(),this.#r=requestAnimationFrame(()=>this.#l()))}whenReady(){return this.#i?this.#i:Promise.resolve()}setInitialReadyResolver(e){this.#n=e}cancel(){0!==this.#r&&(cancelAnimationFrame(this.#r),this.#r=0),this.#t=0,this.#o&&(this.#o(),this.#o=null,this.#i=null)}get isPending(){return 0!==this.#t}get pendingPhase(){return this.#t}#a(){this.#i||(this.#i=new Promise(e=>{this.#o=e}))}#l(){if(this.#r=0,!this.#e._schedulerIsConnected)return this.#t=0,void(this.#o&&(this.#o(),this.#o=null,this.#i=null));const e=this.#t;this.#t=0,e>=fe.COLUMNS&&this.#e._schedulerMergeConfig(),e>=fe.ROWS&&this.#e._schedulerProcessRows(),e>=fe.COLUMNS&&(this.#e._schedulerProcessColumns(),this.#e._schedulerUpdateTemplate()),e>=fe.HEADER&&this.#e._schedulerRenderHeader(),e>=fe.VIRTUALIZATION&&this.#e.refreshVirtualWindow(!0,!0),e>=fe.STYLE&&this.#e._schedulerAfterRender();const t=!this.#s;t&&(this.#s=!0,this.#n?.()),this.#o&&(this.#o(),this.#o=null,this.#i=null),0!==e&&this.#c(e,t)}#c(e,t){const r=this.#e._virtualization,i=r?.enabled?{start:r.start,end:r.end}:null,o={phase:e,initial:t,rowCount:this.#e._rows?.length??0,visibleRange:i};this.#e._hostElement.dispatchEvent(new CustomEvent("render",{detail:o,bubbles:!0,composed:!0}))}}class we{#d;#u;#h;#g;#f;#p;#w;#m={};#b={};#v=!0;#y=[];#_;#C;#R;#E;#e;constructor(e){this.#e=e}get original(){return this.#m}get effective(){return this.#b}get columns(){return this.#b.columns??[]}set columns(e){this.#b.columns=e}get lightDomColumnsCache(){return this.#f}set lightDomColumnsCache(e){this.#f=e}get originalColumnNodes(){return this.#w}set originalColumnNodes(e){this.#w=e}get initialColumnState(){return this.#E}set initialColumnState(e){this.#E=e}get sourcesChanged(){return this.#v}markSourcesChanged(){this.#v=!0}setGridConfig(e){this.#d!==e&&(this.#d=e,this.#v=!0,this.#f=void 0)}getGridConfig(){return this.#d}setColumns(e){this.#u=e,this.#v=!0}getColumns(){return this.#u}setFitMode(e){this.#h=e,this.#v=!0}getFitMode(){return this.#h}setColumnInference(e){this.#g!==e&&(this.#g=e,this.#v=!0)}getColumnInference(){return this.#g}merge(){const e=(this.#b.columns?.length??0)>0;if(!this.#v&&e)return;const t=this.#S();this.#v=!1,this.#m=t,Object.freeze(this.#m),this.#m.columns&&Object.freeze(this.#m.columns),this.#b=this.#A(this.#m),this.#M()}#A(e){const t={...e};return e.columns&&(t.columns=e.columns.map(e=>({...e}))),e.shell&&(t.shell={...e.shell,header:e.shell.header?{...e.shell.header}:void 0,toolPanel:e.shell.toolPanel?{...e.shell.toolPanel}:void 0,toolPanels:e.shell.toolPanels?.map(e=>({...e})),headerContents:e.shell.headerContents?.map(e=>({...e}))}),t}#M(){const e=this.#b;if(this.#x(),"number"==typeof e.rowHeight&&e.rowHeight>0&&(this.#e._virtualization.rowHeight=e.rowHeight),"fixed"===e.fitMode){this.columns.forEach(e=>{null==e.width&&(e.width="number"==typeof e.minWidth&&Number.isFinite(e.minWidth)&&e.minWidth>0?e.minWidth:80)})}this.#e._applyAnimationConfig(e)}#x(){const e=this.#b.typeDefaults;if(!e)return;const t=this.columns;for(const r of t){if(!r.type)continue;const t=e[r.type];t&&(r.renderer||r.viewRenderer||!t.renderer||(r.renderer=t.renderer),!r.format&&t.format&&(r.format=t.format),!r.editor&&t.editor&&(r.editor=t.editor),!r.editorParams&&t.editorParams&&(r.editorParams=t.editorParams))}}#S(){const e=this.#d?{...this.#d}:{},t=Array.isArray(e.columns)?[...e.columns]:[],r=(this.#f??[]).map(e=>({...e}));let i=C(t,r);this.#u&&this.#u.length&&(i=C(this.#u,r));const o=this.#e.sourceRows;if("merge"===(this.#g??e.columnInference??"auto")&&o.length){i=function(e,t){if(!t.length)return e;const r=new Map;for(const n of t)r.set(n.field,n);const i=new Set(e.map(e=>e.field)),o=e.map(e=>{const t=r.get(e.field);if(!t)return e;const i={...e};for(const[r,o]of Object.entries(t))void 0!==o&&Object.assign(i,{[r]:o});return i});for(const n of t)i.has(n.field)||o.push(n);return o}(ge(o).columns,i)}else if(0===i.length&&o.length){i=ge(o).columns}if(i.length&&(!function(e){const t=[],r=[];for(const n of e)"number"==typeof n.order&&Number.isFinite(n.order)&&n.order>=0?t.push({col:n,order:Math.floor(n.order)}):r.push(n);if(0===t.length)return e;t.sort((e,t)=>e.order-t.order);const i=[];let o=0;for(const{col:n,order:s}of t){for(;i.length<s&&o<r.length;)i.push(r[o++]);const e=Math.min(s,i.length);i.splice(e,0,n)}for(;o<r.length;)i.push(r[o++]);e.length=0,e.push(...i)}(i),i.forEach(e=>{void 0===e.sortable&&(e.sortable=!0),void 0===e.resizable&&(e.resizable=!0),void 0===e.__originalWidth&&"number"==typeof e.width&&(e.__originalWidth=e.width)}),i.forEach(e=>{e.__viewTemplate&&!e.__compiledView&&(e.__compiledView=G(e.__viewTemplate.innerHTML)),e.__editorTemplate&&!e.__compiledEditor&&(e.__compiledEditor=G(e.__editorTemplate.innerHTML))}),e.columns=i),this.#p&&Object.keys(this.#p).length>0){const t={...this.#p},r=e.typeDefaults??{};for(const e of Object.keys(r)){const i=r[e],o=t[e];t[e]=o?{...o,...i}:i}e.typeDefaults=t}return this.#h&&(e.fitMode=this.#h),e.fitMode||(e.fitMode="stretch"),this.#g&&(e.columnInference=this.#g),this.#e._pluginManager?.processConfig?.(e),e.columnState&&!this.#E&&(this.#E=e.columnState),e}collectState(e){const t=this.columns,r=this.#H();return{columns:t.map((t,i)=>{const o={field:t.field,order:i,visible:!t.hidden},n=t;void 0!==n.__renderedWidth?o.width=n.__renderedWidth:void 0!==t.width&&(o.width="string"==typeof t.width?parseFloat(t.width):t.width);const s=r.get(t.field);s&&(o.sort=s);for(const r of e)if(r.getColumnState){const e=r.getColumnState(t.field);e&&Object.assign(o,e)}return o})}}applyState(e,t){if(!e.columns||0===e.columns.length)return;const r=this.columns,i=new Map(e.columns.map(e=>[e.field,e])),o=r.map(e=>{const t=i.get(e.field);if(!t)return e;const r={...e};return void 0!==t.width&&(r.width=t.width,r.__renderedWidth=t.width),void 0!==t.visible&&(r.hidden=!t.visible),r});o.sort((e,t)=>(i.get(e.field)?.order??1/0)-(i.get(t.field)?.order??1/0)),this.columns=o;const n=e.columns.filter(e=>void 0!==e.sort).sort((e,t)=>(e.sort?.priority??0)-(t.sort?.priority??0));if(n.length>0){const e=n[0];e.sort&&(this.#e._sortState={field:e.field,direction:"asc"===e.sort.direction?1:-1})}else this.#e._sortState=null;for(const s of t)if(s.applyColumnState)for(const t of e.columns)s.applyColumnState(t.field,t)}resetState(e){this.#E=void 0,this.#e._sortState=null,this.#b=this.#A(this.#m),this.#M();for(const t of e)if(t.applyColumnState)for(const e of this.columns)t.applyColumnState(e.field,{field:e.field,order:0,visible:!0});this.requestStateChange(e)}#H(){const e=new Map,t=this.#e._sortState;return t&&e.set(t.field,{direction:1===t.direction?"asc":"desc",priority:0}),e}requestStateChange(e){this.#C&&clearTimeout(this.#C),this.#C=setTimeout(()=>{this.#C=void 0;const t=this.collectState(e);this.#e._emit("column-state-change",t)},100)}setColumnVisible(e,t){const r=this.columns,i=r.find(t=>t.field===e);if(!i)return!1;if(!t&&i.lockVisible)return!1;if(!t){if(0===r.filter(t=>!t.hidden&&t.field!==e).length)return!1}return!!i.hidden!=!t&&(i.hidden=!t,this.#e._emit("column-visibility",{field:e,visible:t,visibleColumns:r.filter(e=>!e.hidden).map(e=>e.field)}),this.#e._clearRowPool(),this.#e._setup(),!0)}toggleColumnVisibility(e){const t=this.columns.find(t=>t.field===e);return!!t&&this.setColumnVisible(e,!!t.hidden)}isColumnVisible(e){const t=this.columns.find(t=>t.field===e);return!!t&&!t.hidden}showAllColumns(){const e=this.columns;e.some(e=>e.hidden)&&(e.forEach(e=>e.hidden=!1),this.#e._emit("column-visibility",{visibleColumns:e.map(e=>e.field)}),this.#e._clearRowPool(),this.#e._setup())}getAllColumns(){return this.columns.map(e=>({field:e.field,header:e.header||e.field,visible:!e.hidden,lockVisible:e.lockVisible,utility:!0===e.utility}))}getColumnOrder(){return this.columns.map(e=>e.field)}setColumnOrder(e){if(!e.length)return;const t=new Map(this.columns.map(e=>[e.field,e])),r=[];for(const i of e){const e=t.get(i);e&&(r.push(e),t.delete(i))}for(const i of t.values())r.push(i);this.columns=r,this.#e._invalidateVisibleColumnsCache(),he(this.#e),M(this.#e),this.#e._requestSchedulerPhase(fe.COLUMNS,"configManager")}parseLightDomColumns(e){if(this.#f||(this.#w=Array.from(e.querySelectorAll("tbw-grid-column")),this.#f=this.#w.length?function(e){return Array.from(e.querySelectorAll("tbw-grid-column")).map(e=>{const t=e.getAttribute("field")||"";if(!t)return null;const r=t.includes(":")?d(t):void 0,i={field:r?.field??t,type:e.getAttribute("type")||r?.type||void 0,header:e.getAttribute("header")||r?.header||void 0,sortable:e.hasAttribute("sortable")&&"false"!==e.getAttribute("sortable"),__element:e},o=e.getAttribute("width");if(o){const e=parseFloat(o);!isNaN(e)&&/^\d+(\.\d+)?$/.test(o.trim())?i.width=e:i.width=o}const n=e.getAttribute("minWidth")||e.getAttribute("min-width");if(n){const e=parseFloat(n);isNaN(e)||(i.minWidth=e)}const s=e.getAttribute("order");if(s){const e=parseInt(s,10);Number.isFinite(e)&&e>=0&&(i.order=e)}e.hasAttribute("resizable")&&(i.resizable="false"!==e.getAttribute("resizable"));const a=e.getAttribute("options");a&&(i.options=a.split(",").map(e=>{const[t,r]=e.includes(":")?e.split(":"):[e.trim(),e.trim()];return{value:t.trim(),label:r?.trim()||t.trim()}}));const l=e.querySelector("tbw-grid-column-view"),c=e.querySelector("tbw-grid-column-editor"),u=e.querySelector("tbw-grid-column-header");l&&(i.__viewTemplate=l),u&&(i.__headerTemplate=u);const h=globalThis.DataGridElement,g=h?.getAdapters?.()??[],f=l??e,p=g.find(e=>e.canHandle(f));if(p){const e=p.createRenderer(f);e&&(i.viewRenderer=e)}const w=c??e,m=g.find(e=>e.canHandle(w));if(m){const e=m.createEditor(w);e&&(i.editor=e)}const b=g.find(t=>t.canHandle(e)&&(t.createHeaderRenderer||t.createHeaderLabelRenderer));if(b){const t=b.createHeaderRenderer?.(e);t&&(i.headerRenderer=t);const r=b.createHeaderLabelRenderer?.(e);r&&(i.headerLabelRenderer=r)}return i}).filter(e=>!!e)}(e):[]),!this.#p){const t=function(e){const t=globalThis.DataGridElement,r=t?.getAdapters?.()??[];return Array.from(e.children).filter(e=>"tbw-grid-type"===e.tagName.toLowerCase()).map(e=>{const t=e.getAttribute("name")?.trim();if(!t)return null;const i=Array.from(e.children).find(e=>"tbw-grid-column-view"===e.tagName.toLowerCase()),o=i??e,n=r.find(e=>e.canHandle(o)),s=n?.createRenderer(o),a={};for(const r of Array.from(e.attributes)){if(!r.name.startsWith("data-"))continue;const e=r.name.slice(5).replace(/-([a-z])/g,(e,t)=>t.toUpperCase()).trim();e&&(a[e]=r.value)}return{name:t,params:a,viewTemplate:i,viewRenderer:s}}).filter(e=>null!==e)}(e),r={};for(const e of t){const t={};let i=!1;if(e.viewRenderer)t.renderer=e.viewRenderer,i=!0;else if(e.viewTemplate){const r=G(e.viewTemplate.innerHTML);t.renderer=t=>r({row:t.row,value:t.value,field:t.field,column:t.column,typeDefault:e.params}),i=!0}i&&(r[e.name]=t)}this.#p=r}}clearLightDomCache(){this.#f=void 0,this.#p=void 0}#T=new Map;registerLightDomHandler(e,t){this.#T.set(e.toLowerCase(),t)}unregisterLightDomHandler(e){this.#T.delete(e.toLowerCase())}observeLightDOM(e){this.#_&&this.#_.disconnect();const t=new Set,r=()=>{this.#R=void 0;for(const e of t){const t=this.#T.get(e);t?.()}t.clear()};this.#_=new MutationObserver(e=>{for(const r of e){for(const e of r.addedNodes){if(e.nodeType!==Node.ELEMENT_NODE)continue;const r=e.tagName.toLowerCase();this.#T.has(r)&&t.add(r)}for(const e of r.removedNodes){if(e.nodeType!==Node.ELEMENT_NODE)continue;const r=e.tagName.toLowerCase();this.#T.has(r)&&t.add(r)}if("attributes"===r.type&&r.target.nodeType===Node.ELEMENT_NODE){const e=r.target.tagName.toLowerCase();this.#T.has(e)&&t.add(e)}}t.size>0&&!this.#R&&(this.#R=setTimeout(r,0))}),this.#_.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["title","field","header","width","hidden","id","icon","tooltip","order","name","type"]})}onChange(e){this.#y.push(e)}notifyChange(){for(const e of this.#y)e()}dispose(){this.#_?.disconnect(),this.#y=[],this.#C&&clearTimeout(this.#C),this.#R&&(clearTimeout(this.#R),this.#R=void 0)}}function me(e,t){const r=document.createElement("div");return e&&(r.className=e),r}const be=document.createElement("template");function ve(e){const t=document.createDocumentFragment(),r=me(H.ROOT);{const e=me("tbw-grid-content");e.appendChild(be.content.cloneNode(!0)),r.appendChild(e)}return t.appendChild(r),t}be.innerHTML='\n <div class="tbw-scroll-area">\n <div class="rows-body-wrapper">\n <div class="rows-body" role="grid">\n <div class="header" role="rowgroup">\n <div class="header-row" role="row" part="header-row"></div>\n </div>\n <div class="rows-container" role="presentation">\n <div class="rows-viewport" role="presentation">\n <div class="rows"></div>\n </div>\n </div>\n </div>\n </div>\n </div>\n <div class="faux-vscroll">\n <div class="faux-vscroll-spacer"></div>\n </div>\n <div class="tbw-sr-only" aria-live="polite" aria-atomic="true"></div>\n';function ye(e){const t=document.createElement("div");return t.className="tbw-empty-message",t.textContent=e.filteredOut?"No matching rows":"No data to display",t}function _e(e,t,r="rows"){const i=document.createElement("div");return i.className="tbw-empty-overlay",i.setAttribute("role","status"),i.setAttribute("aria-live","polite"),i.setAttribute("data-overlay-target",r),i.appendChild(function(e,t){const r=(t??ye)(e);if("string"==typeof r){const e=document.createElement("div");return e.className="tbw-empty-message",e.innerHTML=$(r),e}return r}(e,t)),i}function Ce(e){e?.remove()}function Re(){if("undefined"!=typeof window&&window.location){const e=window.location.hostname;if("localhost"===e||"127.0.0.1"===e||"::1"===e)return!0}return"undefined"!=typeof process&&"production"!==process.env?.NODE_ENV}function Ee(e){return`<span role="checkbox" aria-checked="${e}" aria-label="${e}">${e?"&#x1F5F9;":"&#9744;"}</span>`}function Se(e){if(null==e||""===e)return"";if(e instanceof Date)return isNaN(e.getTime())?"":e.toLocaleDateString();if("number"==typeof e||"string"==typeof e){const t=new Date(e);return isNaN(t.getTime())?"":t.toLocaleDateString()}return""}function Ae(e){if(!e)return-1;const t=e.getAttribute("data-row");if(t)return parseInt(t,10);const r=e.closest(".data-grid-row");if(!r)return-1;const i=r.parentElement;if(!i)return-1;const o=i.querySelectorAll(":scope > .data-grid-row");for(let n=0;n<o.length;n++)if(o[n]===r)return n;return-1}function Me(e){e&&e.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function xe(e){return"rtl"===function(e){try{if("rtl"===getComputedStyle(e).direction)return"rtl"}catch{}try{const t=e.closest?.("[dir]")?.getAttribute("dir");if("rtl"===t)return"rtl"}catch{}return"ltr"}(e)}function He(e,t){return e&&"object"==typeof e?"__rowCacheKey"in e?e.__rowCacheKey:"rowId"in e&&null!=e.rowId?`id:${e.rowId}`:t?`id:${t(e)}`:e:e}function Te(e,t,r){const i=He(t,r);return"string"==typeof i?e.byKey.get(i):i&&"object"==typeof i?e.byRef.get(i):void 0}function ke(e,t,r){if(t<0||t>=e.length)return;const i=e[t],o=r-i.height;if(0!==o){i.height=r,i.measured=!0;for(let r=t+1;r<e.length;r++)e[r].offset+=o}}function Le(e,t){if(0===e.length)return-1;if(t<=0)return 0;let r=0,i=e.length-1;for(;r<=i;){const o=Math.floor((r+i)/2),n=e[o],s=n.offset+n.height;if(t<n.offset)i=o-1;else{if(!(t>=s))return o;r=o+1}}return Math.max(0,Math.min(r,e.length-1))}function Pe(e,t){const{positionCache:r,heightCache:i,rows:o,start:n,end:s,getPluginHeight:a,getRowId:l}=e;let c=!1;t.forEach(e=>{const t=e.dataset.rowIndex;if(!t)return;const d=parseInt(t,10);if(d<n||d>=s||d>=o.length)return;const u=o[d],h=a?.(u,d);if(void 0!==h){const e=r[d];return void((!e.measured||Math.abs(e.height-h)>1)&&(ke(r,d,h),c=!0))}const g=e.offsetHeight;if(g>0){const e=r[d];(!e.measured||Math.abs(e.height-g)>1)&&(ke(r,d,g),function(e,t,r,i){const o=He(t,i);"string"==typeof o?e.byKey.set(o,r):o&&"object"==typeof o&&e.byRef.set(o,r)}(i,u,g,l),c=!0)}});const d=c?function(e){let t=0;for(const r of e)r.measured&&t++;return t}(r):0,u=c?function(e,t){let r=0,i=0;for(const o of e)o.measured&&(r+=o.height,i++);return i>0?r/i:t}(r,e.defaultHeight):0;return{hasChanges:c,measuredCount:d,averageHeight:u}}const De=335e5;function Ie(e,t,r=335e5){return{rawContentHeight:e,spacerHeight:Math.min(e,r),viewportHeight:t,capped:e>r}}function Oe(e,t){if(!t.capped)return e;const r=t.spacerHeight-t.viewportHeight,i=t.rawContentHeight-t.viewportHeight;if(r<=0||i<=0)return e;const o=e*i/r;return o<0?0:o>i?i:o}function ze(e,t){if(!t.capped)return e;const r=t.spacerHeight-t.viewportHeight,i=t.rawContentHeight-t.viewportHeight;return r<=0||i<=0?e:e*r/i}function Ne(e){"function"==typeof e.commitActiveRowEdit&&e.commitActiveRowEdit()}function Fe(e){if(!e)return!1;const t=e.tagName;return"INPUT"===t||"SELECT"===t||"TEXTAREA"===t||!!e.isContentEditable}function qe(e,t){if(e._virtualization?.enabled){const{rowHeight:t,container:r,viewportEl:i,scrollMapping:o}=e._virtualization,n=r,s=i?.clientHeight??n?.clientHeight??0;if(n&&s>0){const r=e._focusRow*t,i=o?Oe(n.scrollTop,o):n.scrollTop;if(r<i)n.scrollTop=o?ze(r,o):r;else if(r+t>i+s){const e=r-s+t;n.scrollTop=o?ze(e,o):e}}}const r=void 0!==e._activeEditRows&&-1!==e._activeEditRows||!!e._isGridEditMode;r||e.refreshVirtualWindow(!1),Me(e._bodyEl),Array.from(e._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(e=>{e.setAttribute("aria-selected","false")});const i=e._focusRow,o=e._virtualization.start??0,n=e._virtualization.end??e._rows.length;if(i>=o&&i<n){const n=e._bodyEl.querySelectorAll(".data-grid-row")[i-o];let s=n?.children[e._focusCol];if(s&&s.classList?.contains("cell")||(s=n?.querySelector(`.cell[data-col="${e._focusCol}"]`)??n?.querySelector(".cell[data-col]")),s){s.classList.add("cell-focus"),s.setAttribute("aria-selected","true");const i=e.querySelector(".tbw-scroll-area");if(i&&s&&(!r||t?.forceHorizontalScroll))if(t?.forceScrollLeft)i.scrollLeft=0;else if(t?.forceScrollRight)i.scrollLeft=i.scrollWidth-i.clientWidth;else{const t=e._getHorizontalScrollOffsets?.(n??void 0,s)??{left:0,right:0};if(!t.skipScroll){const e=s.getBoundingClientRect(),r=i.getBoundingClientRect(),o=e.left-r.left+i.scrollLeft,n=o+e.width,a=i.scrollLeft+t.left,l=i.scrollLeft+i.clientWidth-t.right;o<a?i.scrollLeft=o-t.left:n>l&&(i.scrollLeft=n-i.clientWidth+t.right)}}if(r&&s.classList.contains(H.EDITING)){const e=s.querySelector(x);if(e&&document.activeElement!==e)try{e.focus({preventScroll:!0})}catch{}}else if(r&&!s.contains(document.activeElement)){s.hasAttribute("tabindex")||s.setAttribute("tabindex","-1");try{s.focus({preventScroll:!0})}catch{}}else if(!r){const t=document.activeElement;t instanceof HTMLElement&&t!==e&&"function"==typeof e.contains&&e.contains(t)&&!t.classList.contains("cell")&&!t.closest(".cell")||t===e||e.focus({preventScroll:!0})}}}}function $e(e,t){const r=t.renderer||t.viewRenderer;if(r)return r;if(!t.type)return;const i=e.__frameworkAdapter;if(i?.getTypeDefault){const r=i.getTypeDefault(t.type,e._hostElement);if(r?.renderer)return r.renderer}}function We(e,t){if(t.format)return t.format;if(!t.type)return;const r=e.__frameworkAdapter;if(r?.getTypeDefault){const i=r.getTypeDefault(t.type,e._hostElement);if(i?.format)return i.format}}function Ve(e){return(e.__editingCellCount??0)>0}function Ue(e){e.__editingCellCount=0,e.removeAttribute("data-has-editing");e.querySelectorAll(`.cell.${H.EDITING}`).forEach(e=>e.classList.remove(H.EDITING))}const Be=document.createElement("template");Be.innerHTML='<div class="cell" role="gridcell" part="cell"></div>';const Ge=document.createElement("template");function je(){return Be.content.firstElementChild.cloneNode(!0)}function Ye(){return Ge.content.firstElementChild.cloneNode(!0)}function Xe(e){e.__cellDisplayCache=void 0,e.__cellCacheEpoch=void 0,e.__hasSpecialColumns=void 0}function Ke(e,t,r,i){const o=t.children,n=e._visibleColumns,s=n.length,a=o.length,l=s<a?s:a,c=e._focusRow,d=e._focusCol,u=e._hasAfterCellRenderHook?.()??!1;let h=e.__hasSpecialColumns;if(void 0===h){h=!1;const t=e.__frameworkAdapter;for(let r=0;r<s;r++){const i=n[r];if(i.__viewTemplate||i.__compiledView||i.renderer||i.viewRenderer||i.externalView||i.format||i.cellClass||"date"===i.type||"boolean"===i.type||i.type&&t?.getTypeDefault?.(i.type,e._hostElement)?.renderer||i.type&&t?.getTypeDefault?.(i.type,e._hostElement)?.format){h=!0;break}}e.__hasSpecialColumns=h}const g=String(i);if(h){for(let s=0;s<l;s++){if(n[s].externalView){if(!o[s].querySelector("[data-external-view]"))return void Ze(e,t,r,i)}}for(let s=0;s<l;s++){const a=n[s],l=o[s];l.getAttribute("data-row")!==g&&l.setAttribute("data-row",g);const h=l.classList.contains(H.EDITING);if(!h){const e=c===i&&d===s;e!==l.classList.contains("cell-focus")&&(l.classList.toggle("cell-focus",e),l.setAttribute("aria-selected",String(e)))}const m=a.cellClass;if(m){const t=l.getAttribute("data-dynamic-classes");if(t){const e=t.split(" ");for(let t=0;t<e.length;t++)e[t]&&l.classList.remove(e[t])}try{const e=m(X(r,a,i),r,a),t="string"==typeof e?e.split(/\s+/):e;if(t&&t.length>0){let e="";for(let r=0;r<t.length;r++){const i=t[r];i&&"string"==typeof i&&(l.classList.add(i),e+=(e?" ":"")+i)}l.setAttribute("data-dynamic-classes",e)}else l.removeAttribute("data-dynamic-classes")}catch(f){v(p,`cellClass callback error for column '${a.field}': ${f}`,e.id),l.removeAttribute("data-dynamic-classes")}}if(h)continue;const b=$e(e,a);if(b){const o=X(r,a,i),n=b({row:r,value:o,field:a.field,column:a,grid:e,cellEl:l});"string"==typeof n?(e.__frameworkAdapter?.releaseCell?.(l),l.innerHTML=$(n)):n instanceof Node?n.parentElement!==l&&(e.__frameworkAdapter?.releaseCell?.(l),l.innerHTML="",l.appendChild(n)):null==n&&(e.__frameworkAdapter?.releaseCell?.(l),l.textContent=null==o?"":String(o)),u&&e._afterCellRender?.({row:r,rowIndex:i,column:a,colIndex:s,value:o,cellElement:l,rowElement:t});continue}if(a.__compiledView){const o=X(r,a,i),n=a.__compiledView({row:r,value:o,field:a.field,column:a});a.__compiledView.__blocked?l.textContent="":(l.firstElementChild&&e.__frameworkAdapter?.releaseCell?.(l),l.innerHTML=$(n),B(l)),u&&e._afterCellRender?.({row:r,rowIndex:i,column:a,colIndex:s,value:o,cellElement:l,rowElement:t});continue}if(a.__viewTemplate){const o=X(r,a,i),n=a.__viewTemplate.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(n)?l.textContent="":(l.firstElementChild&&e.__frameworkAdapter?.releaseCell?.(l),l.innerHTML=$(V(n,{row:r,value:o})),B(l)),u&&e._afterCellRender?.({row:r,rowIndex:i,column:a,colIndex:s,value:o,cellElement:l,rowElement:t});continue}if(a.externalView)continue;const y=X(r,a,i);let _;l.firstElementChild&&e.__frameworkAdapter?.releaseCell?.(l);const C=We(e,a);if(C){try{const e=C(y,r);_=null==e?"":String(e)}catch(f){v(w,`Format error in column '${a.field}': ${f}`,e.id),_=null==y?"":String(y)}l.textContent=_}else"date"===a.type?(_=Se(y),l.textContent=_):"boolean"===a.type?l.innerHTML=Ee(!!y):(_=null==y?"":String(y),l.textContent=_);u&&e._afterCellRender?.({row:r,rowIndex:i,column:a,colIndex:s,value:y,cellElement:l,rowElement:t})}}else for(let p=0;p<l;p++){const s=o[p];if(s.classList.contains(H.EDITING))continue;s.firstElementChild&&e.__frameworkAdapter?.releaseCell?.(s);const a=n[p],l=X(r,a,i);s.textContent=null==l?"":String(l),s.getAttribute("data-row")!==g&&s.setAttribute("data-row",g);const h=c===i&&d===p;h!==s.classList.contains("cell-focus")&&(s.classList.toggle("cell-focus",h),s.setAttribute("aria-selected",String(h))),u&&e._afterCellRender?.({row:r,rowIndex:i,column:a,colIndex:p,value:l,cellElement:s,rowElement:t})}}function Ze(e,t,r,i){t.classList.remove("tbw-row-loading"),t.removeAttribute("aria-busy");const o=e.__frameworkAdapter;if(o?.releaseCell){o.beginBatch?.(e);try{const e=t.children;for(let t=e.length-1;t>=0;t--)o.releaseCell(e[t]);t.innerHTML=""}finally{o.endBatch?.(e)}}else t.innerHTML="";const n=e._visibleColumns,s=n.length,a=e._focusRow,l=e._focusCol,c=e._hasAfterCellRenderHook?.()??!1,d=document.createDocumentFragment();for(let h=0;h<s;h++){const o=n[h],s=je();s.setAttribute("aria-colindex",String(h+1)),s.setAttribute("data-col",String(h)),s.setAttribute("data-row",String(i)),s.setAttribute("data-field",o.field),s.setAttribute("data-header",o.header??o.field),o.type&&s.setAttribute("data-type",o.type);let g=X(r,o,i);const f=We(e,o);if(f)try{g=f(g,r)}catch(u){v(w,`Format error in column '${o.field}': ${u}`,e.id)}const m=o.__compiledView,b=o.__viewTemplate,y=$e(e,o),_=o.externalView;let C=!1;if(y){const t=y({row:r,value:g,field:o.field,column:o,grid:e,cellEl:s});"string"==typeof t?(s.innerHTML=$(t),C=!0):t instanceof Node?t.parentElement!==s&&(s.textContent="",s.appendChild(t)):null==t&&(s.textContent=null==g?"":String(g))}else if(_){const t=_,i=document.createElement("div");i.setAttribute("data-external-view",""),i.setAttribute("data-field",o.field),s.appendChild(i);const n={row:r,value:g,field:o.field,column:o,grid:e};if(t.mount)try{t.mount({placeholder:i,context:n,spec:t})}catch(u){v("TBW063",`External view mount error for column '${o.field}': ${u}`,e.id)}else queueMicrotask(()=>{try{e.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:i,spec:t,context:n}}))}catch(u){v("TBW064",`External view event dispatch error for column '${o.field}': ${u}`,e.id)}});i.setAttribute("data-mounted","")}else if(m){const e=m({row:r,value:g,field:o.field,column:o}),t=m.__blocked;s.innerHTML=t?"":$(e),C=!0,t&&(s.textContent="",s.setAttribute("data-blocked-template",""))}else if(b){const e=b.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(e)?(s.textContent="",s.setAttribute("data-blocked-template","")):(s.innerHTML=$(V(e,{row:r,value:g})),C=!0)}else f?s.textContent=null==g?"":String(g):"date"===o.type?s.textContent=Se(g):"boolean"===o.type?s.innerHTML=Ee(!!g):s.textContent=null==g?"":String(g);if(C){B(s);const e=s.textContent||"";/Proxy|Reflect\.ownKeys/.test(e)&&(s.textContent=e.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(s.textContent||"")&&(s.textContent=""))}s.hasAttribute("data-blocked-template")&&(s.textContent||"").trim().length&&(s.textContent="");("function"==typeof o.editable?o.editable(r):o.editable)?s.tabIndex=0:"boolean"===o.type&&(s.hasAttribute("tabindex")||(s.tabIndex=0)),a===i&&l===h?(s.classList.add("cell-focus"),s.setAttribute("aria-selected","true")):s.setAttribute("aria-selected","false");const R=o.cellClass;if(R)try{const e=R(X(r,o,i),r,o),t="string"==typeof e?e.split(/\s+/):e;if(t&&t.length>0){let e="";for(const r of t)r&&"string"==typeof r&&(s.classList.add(r),e+=(e?" ":"")+r);s.setAttribute("data-dynamic-classes",e)}}catch(u){v(p,`cellClass callback error for column '${o.field}': ${u}`,e.id)}c&&e._afterCellRender?.({row:r,rowIndex:i,column:o,colIndex:h,value:g,cellElement:s,rowElement:t}),d.appendChild(s)}t.appendChild(d)}function Qe(e,t,r){if(t.target?.closest(".resize-handle"))return;const i=Ae(r.querySelector(".cell[data-row]"));if(i<0)return;const o=e._rows[i];if(!o)return;if(e._dispatchRowClick?.(t,i,o,r))return;const n=t.target?.closest(".cell[data-col]");if(n){const r=Number(n.getAttribute("data-col"));if(!isNaN(r)){if(e._dispatchCellClick?.(t,i,r,n))return;const o=e._focusRow!==i||e._focusCol!==r;if(e._focusRow=i,e._focusCol=r,n.classList.contains(H.EDITING)){o&&(Me(e._bodyEl??e),n.classList.add("cell-focus"));const r=t.target,i=n.contains(r)&&r.matches(x)?r:n.querySelector(x);try{i?.focus({preventScroll:!0})}catch{}return}qe(e)}}}Ge.innerHTML='<div class="data-grid-row" role="row" part="row"></div>';const Je=new WeakMap;function et(e,t){const r=Ae(t),i=function(e){if(!e)return-1;const t=e.getAttribute("data-col");return t?parseInt(t,10):-1}(t);if(r<0||i<0)return;e._focusRow=r,e._focusCol=i,Me(e._bodyEl),t.classList.add("cell-focus"),t.setAttribute("aria-selected","true");const o=t.closest("tbw-grid, [data-tbw-grid]");o&&document.activeElement!==o&&o.focus({preventScroll:!0})}function tt(e,t,r,i){let o=null;const n=r.composedPath?.();if(o=n&&n.length>0?n[0]:r.target,o&&!t.contains(o)){const e=document.elementFromPoint(r.clientX,r.clientY);e&&(o=e)}const s=o?.closest?.("[data-col]"),a=o?.closest?.(".data-grid-row"),l=o?.closest?.(".header-row");let c,d,u,h,g,f;return s&&(c=parseInt(s.getAttribute("data-row")??"-1",10),d=parseInt(s.getAttribute("data-col")??"-1",10),c>=0&&d>=0&&(u=e._rows[c],f=e._visibleColumns[d],h=f?.field,g=u&&h?u[h]:void 0)),{type:i,row:u,rowIndex:void 0!==c&&c>=0?c:void 0,colIndex:void 0!==d&&d>=0?d:void 0,field:h,value:g,column:f,originalEvent:r,cellElement:s??void 0,rowElement:a??void 0,isHeader:!!l,cell:void 0!==c&&void 0!==d&&c>=0&&d>=0?{row:c,col:d}:void 0}}function rt(e,t,r,i){t.addEventListener("keydown",t=>function(e,t){if(e._dispatchKeyDown?.(t))return;const r=e._rows.length-1,i=e._visibleColumns.length-1,o=void 0!==e._activeEditRows&&-1!==e._activeEditRows,n=e._visibleColumns[e._focusCol],s=n?.type,a=t.composedPath?.()??[],l=a.length?a[0]:t.target;if((!l||l===e||l.closest?.(".rows-body"))&&(!Fe(l)||"Home"!==t.key&&"End"!==t.key)&&!(Fe(l)&&("ArrowUp"===t.key||"ArrowDown"===t.key)&&"INPUT"===l.tagName&&"number"===l.type||Fe(l)&&("ArrowLeft"===t.key||"ArrowRight"===t.key)||Fe(l)&&("Enter"===t.key||"Escape"===t.key)||o&&"select"===s&&("ArrowDown"===t.key||"ArrowUp"===t.key))){switch(t.key){case"Tab":return t.preventDefault(),t.shiftKey?e._focusCol>0?e._focusCol-=1:e._focusRow>0&&(e._activeEditRows===e._focusRow&&Ne(e),e._focusRow-=1,e._focusCol=i):e._focusCol<i?e._focusCol+=1:(Ne(e),e._focusRow<r&&(e._focusRow+=1,e._focusCol=0)),void qe(e);case"ArrowDown":o&&Ne(e),e._focusRow=Math.min(r,e._focusRow+1),t.preventDefault();break;case"ArrowUp":o&&Ne(e),e._focusRow=Math.max(0,e._focusRow-1),t.preventDefault();break;case"ArrowRight":{const r=xe(e);e._focusCol=r?Math.max(0,e._focusCol-1):Math.min(i,e._focusCol+1),t.preventDefault();break}case"ArrowLeft":{const r=xe(e);e._focusCol=r?Math.min(i,e._focusCol+1):Math.max(0,e._focusCol-1),t.preventDefault();break}case"Home":return t.ctrlKey||t.metaKey?(o&&Ne(e),e._focusRow=0,e._focusCol=0):e._focusCol=0,t.preventDefault(),void qe(e,{forceScrollLeft:!0});case"End":return t.ctrlKey||t.metaKey?(o&&Ne(e),e._focusRow=r,e._focusCol=i):e._focusCol=i,t.preventDefault(),void qe(e,{forceScrollRight:!0});case"PageDown":e._focusRow=Math.min(r,e._focusRow+20),t.preventDefault();break;case"PageUp":e._focusRow=Math.max(0,e._focusRow-20),t.preventDefault();break;case"Enter":{const r=e._focusRow,i=e._focusCol,o=e._visibleColumns[i],n=e._rows[r],s=o?.field??"",a=s&&n?n[s]:void 0,l=e.querySelector(`[data-row="${r}"][data-col="${i}"]`),c=new CustomEvent("cell-activate",{cancelable:!0,detail:{rowIndex:r,colIndex:i,column:o,field:s,value:a,row:n,cellEl:l,trigger:"keyboard",originalEvent:t}});if(e.dispatchEvent(c),c.defaultPrevented)return void t.preventDefault();break}default:return}qe(e)}}(e,t),{signal:i}),r.addEventListener("mousedown",t=>function(e,t,r){const i=tt(e,t,r,"mousedown");e._dispatchCellMouseDown?.(i)&&Je.set(e,!0)}(e,r,t),{signal:i}),document.addEventListener("mousemove",t=>function(e,t,r){if(!Je.get(e))return;const i=tt(e,t,r,"mousemove");e._dispatchCellMouseMove?.(i)}(e,r,t),{signal:i}),document.addEventListener("mouseup",t=>function(e,t,r){if(!Je.get(e))return;const i=tt(e,t,r,"mouseup");e._dispatchCellMouseUp?.(i),Je.set(e,!1)}(e,r,t),{signal:i})}let it;class ot{#e;#k=new Set;#L=new Map;#P=null;#D=null;constructor(e){this.#e=e,this.#I()}focusCell(e,t){const r=this.#e,i=r._rows.length-1;if(i<0)return;let o;if("string"==typeof t){if(o=r._visibleColumns.findIndex(e=>e.field===t),o<0)return}else o=t;const n=r._visibleColumns.length-1;n<0||(r._focusRow=Math.max(0,Math.min(e,i)),r._focusCol=Math.max(0,Math.min(o,n)),qe(r))}get focusedCell(){const e=this.#e;if(0===e._rows.length||0===e._visibleColumns.length)return null;const t=e._visibleColumns[e._focusCol];return{rowIndex:e._focusRow,colIndex:e._focusCol,field:t?.field??""}}scrollToRow(e,t){const r=this.#e._virtualization;if(!r.enabled)return;const i=r.container;if(!i)return;const o=this.#e._rows.length;if(0===o)return;const n=Math.max(0,Math.min(e,o-1)),s=t?.align??"nearest",a=t?.behavior??"instant";let l,c;const d=r.positionCache;r.variableHeights&&d&&d.length>n?(l=d[n].offset,c=d[n].height):(l=n*r.rowHeight,c=r.rowHeight);const u=r.viewportEl?.clientHeight??i.clientHeight??0;if(u<=0)return;const h=i.scrollTop,g=l+c,f=h+u;let p;switch(s){case"start":p=l;break;case"center":p=l-u/2+c/2;break;case"end":p=g-u;break;default:if(l>=h&&g<=f)return;p=l<h?l:g-u}p=Math.max(0,p);const w=ze(p,r.scrollMapping);"smooth"===a?i.scrollTo({top:w,behavior:"smooth"}):i.scrollTop=w}scrollToRowById(e,t){const r=this.#e._getRowEntry(e);r&&this.scrollToRow(r.index,t)}registerExternalFocusContainer(e){if(this.#k.has(e))return;this.#k.add(e);const t=new AbortController,r=t.signal,i=this.#e;e.addEventListener("focusin",e=>{i.dataset.hasFocus="",this.#O(e.target)},{signal:r}),e.addEventListener("focusout",e=>{const t=e.relatedTarget;t&&this.containsFocus(t)||delete i.dataset.hasFocus,null===t&&this.#z()},{signal:r}),this.#L.set(e,()=>t.abort())}unregisterExternalFocusContainer(e){this.#k.delete(e);const t=this.#L.get(e);t&&(t(),this.#L.delete(e))}containsFocus(e){const t=e??document.activeElement;return!!t&&(!!this.#e.contains(t)||this.isInExternalFocusContainer(t))}isInExternalFocusContainer(e){for(const t of this.#k)if(t.contains(e))return!0;return!1}#I(){const e=this.#e,t=new AbortController,r=t.signal;e.addEventListener("focusin",e=>this.#O(e.target),{signal:r,capture:!0}),e.addEventListener("focusout",e=>{null===e.relatedTarget&&this.#z()},{signal:r}),this.#D=()=>t.abort()}#O(e){if(!(e instanceof HTMLElement))return;if(e===this.#e)return;const t=e.closest?.(".cell");t&&!t.classList.contains("editing")||this.isInExternalFocusContainer(e)||(this.#P=e)}#z(){queueMicrotask(()=>{if(!this.#e.isConnected)return;document.activeElement===document.body&&this.restoreLastFocus()})}restoreLastFocus(){const e=this.#P;if(!e)return!1;if(!e.isConnected)return this.#P=null,!1;if(e===document.activeElement)return!0;try{e.focus({preventScroll:!0})}catch{return!1}return document.activeElement===e}get lastFocusedElement(){return this.#P?.isConnected?this.#P:null}destroy(){for(const e of this.#L.values())e();this.#L.clear(),this.#k.clear(),this.#D?.(),this.#D=null,this.#P=null}}const nt="function"==typeof requestIdleCallback;function st(e){nt?cancelIdleCallback(e):clearTimeout(e)}function at(e,t){if(t){const r=t({size:e});if("string"==typeof r){const e=document.createElement("div");return e.innerHTML=r,e}return r}return function(e){const t=document.createElement("div");return t.className=`tbw-spinner tbw-spinner--${e}`,t.setAttribute("role","progressbar"),t.setAttribute("aria-label","Loading"),t}(e)}function lt(e){let t=null,r=null,i=null,o=null;const n=i=>{if(!t)return;const o=i.clientX-t.startX,n=e._visibleColumns[t.colIndex],s="number"==typeof n?.minWidth&&Number.isFinite(n.minWidth)&&n.minWidth>0?n.minWidth:40,a=Math.max(s,t.startWidth+o);n.width=a,n.__userResized=!0,n.__renderedWidth=a,null==r&&(r=requestAnimationFrame(()=>{r=null,e.updateTemplate?.()})),e.dispatchEvent(new CustomEvent("column-resize",{detail:{field:n.field,width:a}}))};let s=!1;const a=()=>{const r=null!==t;r&&(s=!0,requestAnimationFrame(()=>{s=!1})),window.removeEventListener("mousemove",n),window.removeEventListener("mouseup",a),null!==i&&(document.documentElement.style.cursor=i,i=null),null!==o&&(document.body.style.userSelect=o,o=null),t=null,r&&e.requestStateChange&&e.requestStateChange()};return{get isResizing(){return null!==t||s},start(r,s,l){r.preventDefault();const c=e._headerRowEl??e.findHeaderRow?.();c&&function(t,r){const i=r.querySelectorAll(".cell");for(let o=0;o<e._visibleColumns.length;o++){if(o===t)continue;const r=e._visibleColumns[o];if(null==r.width&&!r.__userResized){const e=i[o],t=e?.getBoundingClientRect().width;t&&(r.width=Math.round(t),r.__userResized=!0,r.__renderedWidth=r.width)}}}(s,c);const d=e._visibleColumns[s],u="number"==typeof d?.width?d.width:void 0,h=d?.__renderedWidth??u??l.getBoundingClientRect().width;t={startX:r.clientX,colIndex:s,startWidth:h},window.addEventListener("mousemove",n),window.addEventListener("mouseup",a),null===i&&(i=document.documentElement.style.cursor),document.documentElement.style.cursor="e-resize",null===o&&(o=document.body.style.userSelect),document.body.style.userSelect="none"},resetColumn(t){const r=e._visibleColumns[t];r&&(r.__userResized=!1,r.__renderedWidth=void 0,r.width=r.__originalWidth,e.updateTemplate?.(),e.requestStateChange?.(),e.dispatchEvent(new CustomEvent("column-resize-reset",{detail:{field:r.field,width:r.width}})))},dispose(){a()}}}const ct="data-animating",dt={change:"--tbw-row-change-duration",insert:"--tbw-row-insert-duration",remove:"--tbw-row-remove-duration"},ut={change:500,insert:300,remove:200};function ht(e,t){const r=dt[t],i=getComputedStyle(e).getPropertyValue(r);if(i){const e=function(e){const t=e.trim().toLowerCase();return t.endsWith("ms")?parseFloat(t):t.endsWith("s")?1e3*parseFloat(t):parseFloat(t)}(i);if(!isNaN(e)&&e>0)return e}return ut[t]}function gt(e,t,r){if(t<0)return Promise.resolve(!1);const i=e.findRenderedRowElement?.(t);return i?new Promise(e=>{!function(e,t,r){e.removeAttribute(ct),e.offsetWidth,e.setAttribute(ct,t);const i=ht(e,t);setTimeout(()=>{"remove"!==t&&e.removeAttribute(ct),r?.()},i)}(i,r,()=>e(!0))}):Promise.resolve(!1)}function ft(e,t){if(t)return t(e);const r=e;return"id"in r&&null!=r.id?String(r.id):"_id"in r&&null!=r._id?String(r._id):void 0}function pt(e,t,r){const i=ft(e,r);return void 0===i&&b("TBW040",'Cannot determine row ID. Configure getRowId in gridConfig or ensure rows have an "id" property.',t),i}class wt{#e;constructor(e){this.#e=e}resolveRowId(e){return pt(e,this.#e.id,this.#e.effectiveConfig?.getRowId)}getRow(e){return this.#e._getRowEntry(e)?.row}getRowEntry(e){return this.#e._getRowEntry(e)}#N(e,t,r,i,o){const n=this.#e,s=[];for(const[a,l]of Object.entries(i)){if("__proto__"===a||"constructor"===a||"prototype"===a)continue;const c=t[a];if(c===l)continue;const d=n.query?.("commitCellValue",{rowIndex:r,rowId:e,field:a,oldValue:c,newValue:l,source:o});d?.includes(!1)||(d?.includes(!0)||(t[a]=l,K(t,a)),s.push({field:a,oldValue:c,newValue:l}),n.dispatchEvent(new CustomEvent("cell-change",{detail:{row:t,rowId:e,rowIndex:r,field:a,oldValue:c,newValue:l,changes:i,source:o},bubbles:!0,composed:!0})))}return s}updateRow(e,t,r="api"){const i=this.#e,o=i._getRowEntry(e);o||b(f,`Row with ID "${e}" not found. Ensure the row exists and getRowId is correctly configured.`,i.id);const{row:n,index:s}=o;this.#N(e,n,s,t,r).length>0&&(Xe(i),i._requestSchedulerPhase(fe.VIRTUALIZATION,"updateRow"),i._emitDataChange())}updateRows(e,t="api"){const r=this.#e;let i=!1;for(const{id:o,changes:n}of e){const e=r._getRowEntry(o);e||b(f,`Row with ID "${o}" not found. Ensure the row exists and getRowId is correctly configured.`,r.id);const{row:s,index:a}=e;this.#N(o,s,a,n,t).length>0&&(i=!0)}i&&(Xe(r),r._requestSchedulerPhase(fe.VIRTUALIZATION,"updateRows"),r._emitDataChange())}async insertRow(e,t,r=!0){const i=this.#e,o=Math.max(0,Math.min(e,i._rows.length));i.sourceRows=[...i.sourceRows,t];const n=[...i._rows];n.splice(o,0,t),i._rows=n,i._sortState&&(i.__originalOrder=[...i.__originalOrder,t]),Xe(i),i._rebuildRowIdMap(),i.__rowRenderEpoch++;for(let s=0;s<i._rowPool.length;s++)i._rowPool[s].__epoch=-1;i.refreshVirtualWindow(!0),i._emitPluginEvent("row-inserted",{row:t,index:o}),i._emitDataChange(),r&&(await new Promise(e=>requestAnimationFrame(()=>e())),await gt(i,o,"insert"))}async removeRow(e,t=!0){const r=this.#e,i=r._rows[e];if(!i)return;t&&await gt(r,e,"remove");const o=r._rows.indexOf(i);if(o<0)return i;const n=[...r._rows];n.splice(o,1),r._rows=n;const s=r.sourceRows.indexOf(i);if(s>=0){const e=[...r.sourceRows];e.splice(s,1),r.sourceRows=e}if(r._sortState){const e=r.__originalOrder.indexOf(i);if(e>=0){const t=[...r.__originalOrder];t.splice(e,1),r.__originalOrder=t}}Xe(r),r._rebuildRowIdMap(),r.__rowRenderEpoch++;for(let a=0;a<r._rowPool.length;a++)r._rowPool[a].__epoch=-1;return r.refreshVirtualWindow(!0),r._emitDataChange(),t&&requestAnimationFrame(()=>{const e=r.querySelectorAll('[data-animating="remove"]');for(let t=0;t<e.length;t++)e[t].removeAttribute("data-animating")}),i}async applyTransaction(e,t=!0){const r=this.#e,i={added:[],updated:[],removed:[]};if(e.remove?.length)for(const{id:a}of e.remove){const e=r._getRowEntry(a);if(!e)continue;const{row:o}=e;if(t){const e=r._rows.indexOf(o);e>=0&&await gt(r,e,"remove")}const n=r._rows.indexOf(o);if(n<0){i.removed.push(o);continue}const s=[...r._rows];s.splice(n,1),r._rows=s;const l=r.sourceRows.indexOf(o);if(l>=0){const e=[...r.sourceRows];e.splice(l,1),r.sourceRows=e}if(r._sortState){const e=r.__originalOrder.indexOf(o);if(e>=0){const t=[...r.__originalOrder];t.splice(e,1),r.__originalOrder=t}}i.removed.push(o)}const o=new Set(e.remove?.map(e=>e.id));if(e.update?.length)for(const{id:a,changes:l}of e.update){if(o.has(a))continue;const e=r._getRowEntry(a);if(!e)continue;const{row:t,index:n}=e;let s=!1;for(const[i,o]of Object.entries(l)){const e=t[i];e!==o&&(s=!0,t[i]=o,K(t,i),r.dispatchEvent(new CustomEvent("cell-change",{detail:{row:t,rowId:a,rowIndex:n,field:i,oldValue:e,newValue:o,changes:l,source:"api"},bubbles:!0,composed:!0})))}s&&i.updated.push(t)}if(e.add?.length)for(const a of e.add){r.sourceRows=[...r.sourceRows,a];const e=[...r._rows];e.push(a),r._rows=e,r._sortState&&(r.__originalOrder=[...r.__originalOrder,a]),i.added.push(a)}const n=i.added.length>0||i.removed.length>0,s=i.updated.length>0;if(n){Xe(r),r._rebuildRowIdMap(),r.__rowRenderEpoch++;for(let e=0;e<r._rowPool.length;e++)r._rowPool[e].__epoch=-1;r.refreshVirtualWindow(!0)}else s&&(Xe(r),r._requestSchedulerPhase(fe.VIRTUALIZATION,"applyTransaction"));if((n||s)&&r._emitDataChange(),t&&i.added.length>0){await new Promise(e=>requestAnimationFrame(()=>e()));for(const e of i.added){const t=r._rows.indexOf(e);t>=0&&await gt(r,t,"insert")}}if(t&&i.updated.length>0)for(const a of i.updated){const e=r._rows.indexOf(a);e>=0&&await gt(r,e,"change")}return t&&i.removed.length>0&&requestAnimationFrame(()=>{const e=r.querySelectorAll('[data-animating="remove"]');for(let t=0;t<e.length;t++)e[t].removeAttribute("data-animating")}),i}#F=null;#q=[];#$=null;applyTransactionAsync(e){return this.#F||(this.#F={add:[],update:[],remove:[]}),e.add&&this.#F.add.push(...e.add),e.update&&this.#F.update.push(...e.update),e.remove&&this.#F.remove.push(...e.remove),new Promise(e=>{this.#q.push(e),null===this.#$&&(this.#$=requestAnimationFrame(()=>{this.#$=null;const e=this.#F,t=this.#q;this.#F=null,this.#q=[],this.applyTransaction(e,!1).then(e=>{for(const r of t)r(e)})}))})}}const mt="tbw-grid";let bt=mt;function vt(){return bt}const yt="tbw-grid-styles";let _t="";const Ct=new Map;function Rt(){const e=function(){const e=vt();return e===mt?yt:`${yt}-${e}`}();let t=document.getElementById(e);return t||(t=document.createElement("style"),t.id=e,t.setAttribute("data-tbw-grid","true"),document.head.appendChild(t)),t}function Et(e){const t=vt();return t===mt?e:e.replace(new RegExp("(?<![-\\w])tbw-grid(?![-\\w])","g"),t)}function St(){const e=Rt(),t=Array.from(Ct.values()).join("\n");e.textContent=`${_t}\n\n/* Plugin Styles */\n${t}`}async function At(e){if(_t)return;if("string"==typeof e&&e.length>0)return _t=Et(e),void St();await new Promise(e=>setTimeout(e,50));const t=function(){try{for(const e of Array.from(document.styleSheets))try{const t=Array.from(e.cssRules||[]).map(e=>e.cssText).join("\n");if(t.includes(".tbw-grid-root")&&t.includes("tbw-grid"))return t}catch{continue}}catch(e){v("TBW120",`Failed to extract grid.css from document stylesheets: ${e}`)}return null}();t?(_t=Et(t),St()):"undefined"!=typeof process&&"test"===process.env?.NODE_ENV||v("TBW121",`Could not find grid.css in document.styleSheets. Grid styling will not work. Available stylesheets: ${Array.from(document.styleSheets).map(e=>e.href||"(inline)").join(", ")}`)}function Mt(e){e.startY=null,e.startX=null,e.lastY=null,e.lastX=null,e.lastTime=null,e.locked=!1}function xt(e){e.momentumRaf&&(cancelAnimationFrame(e.momentumRaf),e.momentumRaf=0)}function Ht(e,t){if(null!==e.lastTime){performance.now()-e.lastTime>60&&(e.velocityY=0,e.velocityX=0)}(Math.abs(e.velocityY)>.1||Math.abs(e.velocityX)>.1)&&function(e,t){const r=.95,i=1;let o=performance.now();const n=()=>{const s=performance.now(),a=s-o;o=s;const l=a/16,c=Math.pow(r,l);e.velocityY*=c,e.velocityX*=c;const d=16*e.velocityY,u=16*e.velocityX,h=Math.abs(d)>=i,g=Math.abs(u)>=i;h&&(t.fauxScrollbar.scrollTop+=d),g&&t.scrollArea&&(t.scrollArea.scrollLeft+=u),e.momentumRaf=h||g?requestAnimationFrame(n):0};e.momentumRaf=requestAnimationFrame(n)}(e,t),Mt(e)}function Tt(e,t,r,i){e.addEventListener("pointerdown",r=>{"touch"===r.pointerType&&null===t.activePointerId&&(t.activePointerId=r.pointerId,e.setPointerCapture(r.pointerId),function(e,t,r){xt(r),r.startY=t,r.startX=e,r.lastY=t,r.lastX=e,r.lastTime=performance.now(),r.velocityY=0,r.velocityX=0,r.locked=!1}(r.clientX,r.clientY,t))},{passive:!0,signal:i}),e.addEventListener("pointermove",e=>{if(e.pointerId!==t.activePointerId)return;const i=function(e,t,r,i){if(null===r.lastY||null===r.lastX)return!1;const o=performance.now(),n=r.lastY-t,s=r.lastX-e;if(null!==r.lastTime){const e=o-r.lastTime;e>0&&(r.velocityY=n/e,r.velocityX=s/e)}if(r.lastY=t,r.lastX=e,r.lastTime=o,r.locked){const{scrollTop:e,scrollHeight:t,clientHeight:r}=i.fauxScrollbar;if(n>0&&e<t-r||n<0&&e>0?i.fauxScrollbar.scrollTop+=n:0!==n&&window.scrollBy(0,n),i.scrollArea){const{scrollLeft:e,scrollWidth:t,clientWidth:r}=i.scrollArea;s>0&&e<t-r||s<0&&e>0?i.scrollArea.scrollLeft+=s:0!==s&&window.scrollBy(s,0)}return!0}const a=null!==r.startY?Math.abs(r.startY-t):0,l=null!==r.startX?Math.abs(r.startX-e):0;if(a<3&&l<3)return!1;const c=a>=l,{scrollHeight:d,clientHeight:u}=i.fauxScrollbar,h=d-u>0;let g=!1;if(i.scrollArea){const{scrollWidth:e,clientWidth:t}=i.scrollArea;g=e-t>0}return!!(c&&h||!c&&g)&&(r.locked=!0,i.fauxScrollbar.scrollTop+=n,i.scrollArea&&(i.scrollArea.scrollLeft+=s),!0)}(e.clientX,e.clientY,t,r);i&&e.preventDefault()},{passive:!1,signal:i}),e.addEventListener("pointerup",e=>{e.pointerId===t.activePointerId&&(t.activePointerId=null,Ht(t,r))},{passive:!0,signal:i}),e.addEventListener("pointercancel",e=>{e.pointerId===t.activePointerId&&(t.activePointerId=null,Mt(t))},{passive:!0,signal:i}),e.addEventListener("lostpointercapture",e=>{e.pointerId===t.activePointerId&&(t.activePointerId=null,Mt(t))},{passive:!0,signal:i})}const kt=[{property:"editable",pluginName:"editing",level:"column",description:"",isUsed:e=>!0===e||"function"==typeof e},{property:"editor",pluginName:"editing",level:"column",description:""},{property:"editorParams",pluginName:"editing",level:"column",description:""},{property:"group",pluginName:"groupingColumns",level:"column",description:""},{property:"pinned",pluginName:"pinnedColumns",level:"column",description:"",isUsed:e=>"left"===e||"right"===e||"start"===e||"end"===e}],Lt=[{property:"rowEditable",pluginName:"editing",level:"config",description:"",isUsed:e=>"function"==typeof e},{property:"columnGroups",pluginName:"groupingColumns",level:"config",description:"",isUsed:e=>Array.isArray(e)&&e.length>0}];function Pt(e){return`import { ${Dt(e)}Plugin } from '@toolbox-web/grid/plugins/${t=e,t.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}';`;var t}function Dt(e){return e.charAt(0).toUpperCase()+e.slice(1)}function It(e,t){return e.some(e=>e.name===t)}class Ot{#e;state;constructor(e,t){this.#e=e,this.state={enabled:!0,rowHeight:28,bypassThreshold:24,start:0,end:0,container:null,viewportEl:null,totalHeightEl:null,positionCache:null,heightCache:{byKey:new Map,byRef:new WeakMap},averageHeight:28,measuredCount:0,variableHeights:!1,cachedViewportHeight:0,cachedFauxHeight:0,cachedScrollAreaHeight:0,scrollAreaEl:null,scrollMapping:{rawContentHeight:0,spacerHeight:0,viewportHeight:0,capped:!1},...t}}updateCachedGeometry(){const e=this.state,t=e.container,r=e.viewportEl??t;r&&(e.cachedViewportHeight=r.clientHeight),t&&(e.cachedFauxHeight=t.clientHeight);const i=e.scrollAreaEl;i&&(e.cachedScrollAreaHeight=i.clientHeight)}calculateTotalSpacerHeight(e,t=!1){const r=this.state;let i,o,n;if(t){const e=r.container??this.#e._hostElement,t=r.viewportEl??e,s=r.scrollAreaEl;i=e?.clientHeight??0,o=t?.clientHeight??0,n=s?s.clientHeight:i,r.cachedFauxHeight=i,r.cachedViewportHeight=o,r.cachedScrollAreaHeight=n}else i=r.cachedFauxHeight,o=r.cachedViewportHeight,n=r.cachedScrollAreaHeight||i;const s=n-o,a=Math.max(0,i-n);let l;return l=r.variableHeights&&r.positionCache?function(e){if(0===e.length)return 0;const t=e[e.length-1];return t.offset+t.height}(r.positionCache):e*r.rowHeight,r.scrollMapping=Ie(l,o),r.scrollMapping.spacerHeight+s+a}initializePositionCache(){const e=this.state;if(!e.variableHeights)return;const t=this.#e,r=t._rows,i=e.rowHeight||28,o=t.effectiveConfig?.rowHeight,n=t.effectiveConfig?.getRowId,s=n?e=>n(e):void 0;e.positionCache=function(e,t,r,i,o){const n=new Array(e.length);let s=0;for(let a=0;a<e.length;a++){const l=e[a];let c=o?.(l,a),d=void 0!==c;void 0===c&&(c=Te(t,l,i.rowId),d=void 0!==c),void 0===c&&(c=r,d=!1),n[a]={offset:s,height:c,measured:d},s+=c}return n}(r,e.heightCache,i,{rowId:s},(e,r)=>{const i=t._getPluginRowHeight(e,r);if(void 0!==i)return i;if(o){const t=o(e,r);if(void 0!==t&&t>0)return t}});const a=function(e,t,r,i){let o=0,n=0;for(let s=0;s<e.length;s++){const r=e[s];if(r.measured){const e=i?.(t[s],s);void 0===e&&(n+=r.height,o++)}}return{measuredCount:o,averageHeight:o>0?n/o:r}}(e.positionCache,r,i,(e,r)=>t._getPluginRowHeight(e,r));e.measuredCount=a.measuredCount,a.measuredCount>0&&(e.averageHeight=a.averageHeight)}invalidateRowHeight(e,t){const r=this.state;if(!r.variableHeights)return;if(!r.positionCache)return;const i=this.#e._rows;if(e<0||e>=i.length)return;const o=i[e];let n=t;void 0===n&&(n=this.#e._getPluginRowHeight(o,e)),void 0===n&&(n=r.rowHeight);const s=r.positionCache[e];if(s&&!(Math.abs(s.height-n)<1)&&(ke(r.positionCache,e,n),r.totalHeightEl)){const e=this.calculateTotalSpacerHeight(i.length);r.totalHeightEl.style.height=`${e}px`}}measureRenderedRowHeights(e,t){const r=this.state;if(!r.variableHeights)return;if(!r.positionCache)return;const i=this.#e,o=i._bodyEl;if(!o)return;const n=o.querySelectorAll(".data-grid-row"),s=i.effectiveConfig?.getRowId,a=i._rows,l=Pe({positionCache:r.positionCache,heightCache:r.heightCache,rows:a,defaultHeight:r.rowHeight,start:e,end:t,getPluginHeight:(e,t)=>i._getPluginRowHeight(e,t),getRowId:s?e=>s(e):void 0},n);if(l.hasChanges&&(r.measuredCount=l.measuredCount,r.averageHeight=l.averageHeight,r.totalHeightEl)){const e=this.calculateTotalSpacerHeight(a.length);r.totalHeightEl.style.height=`${e}px`}}refreshVirtualWindow(e=!1,t=!1){const r=this.state,i=this.#e,o=i._bodyEl;if(!o)return!1;const n=i._rows.length;if(!r.enabled)return i._renderVisibleRows(0,n),t||i._afterPluginRender(),!0;if(n<=r.bypassThreshold)return r.start=0,r.end=n,e&&(o.style.transform="translateY(0px)"),i._renderVisibleRows(0,n,i.__rowRenderEpoch),e&&r.variableHeights&&this.initializePositionCache(),e&&r.totalHeightEl&&(r.totalHeightEl.style.height=`${this.calculateTotalSpacerHeight(n,!0)}px`),i._updateAriaCounts(n,i._visibleColumns.length),t||i._afterPluginRender(),!0;const s=r.container,a=r.viewportEl??s,l=e?r.cachedViewportHeight=a.clientHeight:r.cachedViewportHeight||(r.cachedViewportHeight=a.clientHeight),c=r.rowHeight,d=Oe(s.scrollTop,r.scrollMapping);let u;e&&r.variableHeights&&this.initializePositionCache();const h=r.positionCache;r.variableHeights&&h&&h.length>0?(u=Le(h,d),-1===u&&(u=0)):u=Math.floor(d/c),u-=u%2,u<0&&(u=0),n>0&&u>n-1&&(u=n-1);const g=i._adjustPluginVirtualStart(u,d,c);let f;if(void 0!==g&&g<u&&(u=g,u-=u%2,u<0&&(u=0)),r.variableHeights&&h&&h.length>0){const e=l+3*c;let t=0;for(f=u;f<n&&t<e;)t+=h[f].height,f++;const r=Math.ceil(l/c)+3;f-u<r&&(f=Math.min(u+r,n))}else{f=u+(Math.ceil(l/c)+3)}f>n&&(f=n);const p=r.start,w=r.end;if(!e&&u===p&&f===w)return!1;r.start=u,r.end=f;const m=e?r.cachedFauxHeight=s.clientHeight:r.cachedFauxHeight||(r.cachedFauxHeight=s.clientHeight);if(e){const e=r.scrollAreaEl;e&&(r.cachedScrollAreaHeight=e.clientHeight)}if(0===m&&l>0)return i._requestSchedulerPhase(fe.VIRTUALIZATION,"stale-refs-retry"),!1;if(e&&r.totalHeightEl){const e=this.calculateTotalSpacerHeight(n);r.totalHeightEl.style.height=`${e}px`}let b;b=r.variableHeights&&h&&h[u]?h[u].offset:u*c;const v=-(d-b);return o.style.transform=`translateY(${v}px)`,i._renderVisibleRows(u,f,i.__rowRenderEpoch),e&&r.variableHeights&&this.measureRenderedRowHeights(u,f),i._updateAriaCounts(n,i._visibleColumns.length),e&&!t&&(i._afterPluginRender(),queueMicrotask(()=>{if(!r.totalHeightEl)return;const e=this.calculateTotalSpacerHeight(n);0===r.cachedFauxHeight&&r.cachedViewportHeight>0||(r.totalHeightEl.style.height=`${e}px`)})),!0}}class zt{constructor(e){this.grid=e}plugins=[];getPlugins(){return this.plugins}pluginMap=new Map;cellRenderers=new Map;headerRenderers=new Map;cellEditors=new Map;_hasAfterCellRender=!1;_hasAfterRowRender=!1;_hasProcessRows=!1;_hasRowStructurePlugins=!1;#W=new Map;eventListeners=new Map;queryHandlers=new Map;attachAll(e){const t=this.#V(e);for(const r of t)this.attach(r)}#V(e){if(e.length<2)return e;const t=new Map,r=new Map,i=[];for(const o of e){const e=o.constructor,n=t.get(e);if(!n){t.set(e,o),i.push(o);continue}const s=r.get(n)??[];s.push(o),r.set(n,s)}if(0===r.size)return i;for(const[o,n]of r)o.mergeConfigsFrom(n);return i}attach(e){if(function(e,t,r){const i=e.name,o=e.constructor.dependencies??[];for(const n of o){if(n.when&&!n.when(e.resolvedConfig))continue;const o=n.name,s=n.required??!0,a=n.reason;if(t.some(e=>e.name===o))continue;const l=n.severity??(s?"error":void 0);if(!l)continue;const c="error"===l?"requires":"recommends",d=a??`${Dt(i)}Plugin ${c} ${Dt(o)}Plugin`;if("error"===l){const e=Pt(o);b("TBW020",`Plugin dependency error:\n\n${d}.\n\n → Add the plugin to your gridConfig.plugins array BEFORE ${Dt(i)}Plugin:\n ${e}\n plugins: [new ${Dt(o)}Plugin(), new ${Dt(i)}Plugin()]`,r)}else Re()&&("warn"===l?v(g,`${d}.`,r):y(g,`${d}.`,r))}}(e,this.plugins,this.grid.getAttribute("id")??void 0),this.pluginMap.set(e.constructor,e),this.plugins.push(e),e.cellRenderers)for(const[t,r]of Object.entries(e.cellRenderers))this.cellRenderers.set(t,r);if(e.headerRenderers)for(const[t,r]of Object.entries(e.headerRenderers))this.headerRenderers.set(t,r);if(e.cellEditors)for(const[t,r]of Object.entries(e.cellEditors))this.cellEditors.set(t,r);this.registerQueryHandlers(e),e.attach(this.grid),this.#U();for(const t of this.plugins)t!==e&&t.onPluginAttached&&t.onPluginAttached(e.name,e)}registerQueryHandlers(e){const t=e.constructor.manifest;if(t?.queries)for(const r of t.queries){let t=this.queryHandlers.get(r.type);t||(t=new Set,this.queryHandlers.set(r.type,t)),t.add(e)}}unregisterQueryHandlers(e){for(const[t,r]of this.queryHandlers)r.delete(e),0===r.size&&this.queryHandlers.delete(t)}detachAll(){for(const e of this.plugins)for(const t of this.plugins)t!==e&&t.onPluginDetached&&t.onPluginDetached(e.name);for(let e=this.plugins.length-1;e>=0;e--){const t=this.plugins[e];this.unsubscribeAll(t),this.unregisterQueryHandlers(t),t.detach()}this.plugins=[],this.pluginMap.clear(),this.cellRenderers.clear(),this.headerRenderers.clear(),this.cellEditors.clear(),this.eventListeners.clear(),this.queryHandlers.clear(),this._hasAfterCellRender=!1,this._hasAfterRowRender=!1,this._hasProcessRows=!1,this.#W.clear()}getPlugin(e){return this.pluginMap.get(e)}getPluginByName(e){return this.plugins.find(t=>t.name===e||t.aliases?.includes(e))}hasPlugin(e){return this.pluginMap.has(e)}getAll(){return this.plugins}getRegisteredPluginNames(){return this.plugins.map(e=>e.name)}getCellRenderer(e){return this.cellRenderers.get(e)}getHeaderRenderer(e){return this.headerRenderers.get(e)}getCellEditor(e){return this.cellEditors.get(e)}getPluginStyles(){return this.plugins.filter(e=>e.styles).map(e=>({name:e.name,styles:e.styles}))}processRows(e){if(!this._hasProcessRows)return e;let t=e;for(const r of this.#B("processRows")){const e=r.processRows(t);e!==t&&(t=e)}return t}processColumns(e){let t=[...e];for(const r of this.#B("processColumns"))t=r.processColumns(t);return t}processConfig(e){for(const t of this.#B("processConfig"))t.processConfig(e)}beforeRender(){for(const e of this.plugins)e.beforeRender?.()}afterStructuralRender(){for(const e of this.#B("afterStructuralRender"))e.afterStructuralRender()}beforeStructuralRender(){for(const e of this.plugins)e.beforeStructuralRender?.()}parseLightDom(){for(const e of this.plugins)e.parseLightDom?.()}syncLightDom(){for(const e of this.plugins)e.syncLightDom?.()}needsStructuralRerender(){let e=!1;for(const t of this.plugins)t.needsStructuralRerender?.()&&(e=!0);return e}afterRender(){for(const e of this.#B("afterRender"))e.afterRender()}afterCellRender(e){for(const t of this.#B("afterCellRender"))t.afterCellRender(e)}hasAfterCellRenderHook(){return this._hasAfterCellRender}afterRowRender(e){for(const t of this.#B("afterRowRender"))t.afterRowRender(e)}hasAfterRowRenderHook(){return this._hasAfterRowRender}#U(){this._hasAfterCellRender=this.plugins.some(e=>"function"==typeof e.afterCellRender),this._hasAfterRowRender=this.plugins.some(e=>"function"==typeof e.afterRowRender),this._hasProcessRows=this.plugins.some(e=>"function"==typeof e.processRows),this._hasRowStructurePlugins=this.plugins.some(e=>!0===e.constructor.manifest?.modifiesRowStructure),this.#W.clear()}#B(e){let t=this.#W.get(e);if(t)return t;t=this.plugins.filter(t=>e in t&&"function"==typeof t[e]);const r=t=>{const r=t.constructor.manifest?.hookPriority;if(!r)return 0;return r[e]??0};return t.some(e=>0!==r(e))&&t.sort((e,t)=>r(e)-r(t)),this.#W.set(e,t),t}onScrollRender(){for(const e of this.#B("onScrollRender"))e.onScrollRender()}getRowHeight(e,t){for(const r of this.plugins)if("function"==typeof r.getRowHeight){const i=r.getRowHeight(e,t);if(void 0!==i)return i}}hasRowHeightPlugin(){for(const e of this.plugins)if("function"==typeof e.getRowHeight)return!0;return!1}adjustVirtualStart(e,t,r){let i=e;for(const o of this.plugins)if("function"==typeof o.adjustVirtualStart){const n=o.adjustVirtualStart(e,t,r);n<i&&(i=n)}return i}renderRow(e,t,r){for(const i of this.plugins)if(i.renderRow?.(e,t,r))return!0;return!1}queryPlugins(e){const t=[],r=this.queryHandlers.get(e.type);if(r&&r.size>0){for(const i of r){const r=i.handleQuery?.(e);void 0!==r&&t.push(r)}return t}for(const i of this.plugins){const r=i.handleQuery?.(e);void 0!==r&&t.push(r)}return t}subscribe(e,t,r){let i=this.eventListeners.get(t);i||(i=new Map,this.eventListeners.set(t,i)),i.set(e,r)}unsubscribe(e,t){const r=this.eventListeners.get(t);r&&(r.delete(e),0===r.size&&this.eventListeners.delete(t))}unsubscribeAll(e){for(const[t,r]of this.eventListeners)r.delete(e),0===r.size&&this.eventListeners.delete(t)}emitPluginEvent(e,t){const r=this.eventListeners.get(e);if(r)for(const o of r.values())try{o(t)}catch(i){_("TBW024",`Error in plugin event handler for "${e}": ${i}`,this.grid.getAttribute("id")??void 0)}}onKeyDown(e){for(const t of this.#B("onKeyDown"))if(t.onKeyDown(e))return!0;return!1}onCellClick(e){for(const t of this.#B("onCellClick"))if(t.onCellClick(e))return!0;return!1}onRowClick(e){for(const t of this.#B("onRowClick"))if(t.onRowClick(e))return!0;return!1}onHeaderClick(e){for(const t of this.#B("onHeaderClick"))if(t.onHeaderClick(e))return!0;return!1}onScroll(e){for(const t of this.#B("onScroll"))t.onScroll(e)}onCellMouseDown(e){for(const t of this.#B("onCellMouseDown"))if(t.onCellMouseDown(e))return!0;return!1}onCellMouseMove(e){for(const t of this.#B("onCellMouseMove"))if(t.onCellMouseMove(e))return!0;return!1}onCellMouseUp(e){for(const t of this.#B("onCellMouseUp"))if(t.onCellMouseUp(e))return!0;return!1}getHorizontalScrollOffsets(e,t){let r=0,i=0,o=!1;for(const n of this.plugins){const s=n.getHorizontalScrollOffsets?.(e,t);s&&(r+=s.left,i+=s.right,s.skipScroll&&(o=!0))}return{left:r,right:i,skipScroll:o}}getToolPanels(){const e=[];for(const t of this.plugins){const r=t.getToolPanel?.();r&&e.push({plugin:t,panel:r})}return e.sort((e,t)=>(e.panel.order??0)-(t.panel.order??0))}getHeaderContents(){const e=[];for(const t of this.plugins){const r=t.getHeaderContent?.();r&&e.push({plugin:t,content:r})}return e.sort((e,t)=>(e.content.order??0)-(t.content.order??0))}}class Nt extends HTMLElement{static tagName=mt;static version="3.0.0-rc.0";static get activeTag(){return vt()}static set activeTag(e){!function(e){bt=e}(e)}static#G=0;static adapters=[];static registerAdapter(e){this.adapters.push(e)}static getAdapters(){return this.adapters}static clearAdapters(){this.adapters=[]}static get observedAttributes(){return["rows","columns","grid-config","fit-mode","column-inference","loading"]}get#j(){return this}#Y=!1;#i;#o;#X=[];get#b(){return this.#K?.effective??{}}#Z=!1;#Q=!1;#J={rows:!1,columns:!1,gridConfig:!1,fitMode:!1,columnInference:!1};#ee;#te=0;#re=null;#ie=!1;#oe=!1;#ne=0;#se;#ae={startY:null,startX:null,lastY:null,lastX:null,lastTime:null,velocityY:0,velocityX:0,momentumRaf:0,locked:!1,activePointerId:null};#le;#ce;#de;#ue;#he={scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0};#ge;#fe;#pe;#we;#me;#be;get _pluginManager(){return this.#ge}#ve=!1;#ye;#_e;#E;#K;#Ce=new Map;#Re=!1;#Ee=new Set;#Se=new Map;#Ae;#Me={};#xe=new Map;#He=!1;_rows=[];#Te=[];get _columns(){return this.#b.columns??[]}set _columns(e){this.#b.columns=e,this.#ke=void 0}#ke;get _visibleColumns(){return this.#ke??=this._columns.filter(e=>!e.hidden)}_invalidateVisibleColumnsCache(){this.#ke=void 0}_headerRowEl;_bodyEl;_rowPool=[];_resizeController;get _virtualization(){return this.#we.state}set _virtualization(e){Object.assign(this.#we.state,e)}_focusRow=0;_focusCol=0;_restoreFocusAfterRender=!1;_sortState=null;_gridTemplate="";__rowRenderEpoch=0;__didInitialAutoSize=!1;get __lightDomColumnsCache(){return this.#K?.lightDomColumnsCache}set __lightDomColumnsCache(e){this.#K&&(this.#K.lightDomColumnsCache=e)}get __originalColumnNodes(){return this.#K?.originalColumnNodes}set __originalColumnNodes(e){this.#K&&(this.#K.originalColumnNodes=e)}__originalOrder=[];__frameworkAdapter;__rowsBodyEl=null;get rows(){return this._rows}set rows(e){const t=Array.isArray(e)?e:[],r=this.#X;this.#X=t,r!==t&&this.#Le("rows")}get sourceRows(){return this.#X}set sourceRows(e){this.#X=Array.isArray(e)?e:[]}get columns(){return[...this._columns]}set columns(e){const t=Array.isArray(e)?u(e):e,r=this.#K?.getColumns();this.#K?.setColumns(t),r!==t&&this.#Le("columns")}get gridConfig(){return this.#b}set gridConfig(e){e&&this.__frameworkAdapter?.processConfig&&(e=this.__frameworkAdapter.processConfig(e));const t=this.#K?.getGridConfig();this.#K?.setGridConfig(e),t!==e&&(this.#K.clearLightDomCache(),this.#Le("gridConfig"))}get _sourceConfig(){return this.#K?.getGridConfig()}get fitMode(){return this.#b.fitMode??"stretch"}set fitMode(e){const t=this.#K?.getFitMode();this.#K?.setFitMode(e),t!==e&&this.#Le("fitMode")}get columnInference(){return this.#b.columnInference??"auto"}set columnInference(e){const t=this.#K?.getColumnInference();this.#K?.setColumnInference(e),t!==e&&this.#Le("columnInference")}get loading(){return this.#Re}set loading(e){const t=this.#Re;this.#Re=e,t!==e&&(e?(this.setAttribute("loading",""),this.setAttribute("aria-busy","true")):(this.removeAttribute("loading"),this.removeAttribute("aria-busy")),this.#Pe(),this.#De())}setRowLoading(e,t){const r=this.#Ee.has(e);t?this.#Ee.add(e):this.#Ee.delete(e),r!==t&&this.#Ie(e,t)}setCellLoading(e,t,r){let i=this.#Se.get(e);const o=i?.has(t)??!1;r?(i||(i=new Set,this.#Se.set(e,i)),i.add(t)):(i?.delete(t),0===i?.size&&this.#Se.delete(e)),o!==r&&this.#Oe(e,t,r)}isRowLoading(e){return this.#Ee.has(e)}isCellLoading(e,t){return this.#Se.get(e)?.has(t)??!1}clearAllLoading(){this.loading=!1;for(const e of this.#Ee)this.#Ie(e,!1);this.#Ee.clear();for(const[e,t]of this.#Se)for(const r of t)this.#Oe(e,r,!1);this.#Se.clear()}get effectiveConfig(){return this.#b}get disconnectSignal(){return this.#le||(this.#le=new AbortController),this.#le.signal}constructor(){super(),this.#ze(),this.#i=new Promise(e=>this.#o=e),this.#we=new Ot(this),this.#me=new ot(this),this.#be=new wt(this),this.#ee=new pe(this),this.#ee.setInitialReadyResolver(()=>this.#o?.()),this.#K=new we(this)}async#ze(){await At('@layer tbw-base, tbw-plugins, tbw-theme;\n\n@layer tbw-base{tbw-grid{--tbw-base-icon-size: 1em;--tbw-base-radius: .25em;--tbw-font-size: 1em;--tbw-font-size-sm: .9285em;--tbw-font-size-xs: .7857em;--tbw-font-size-2xs: .7142em;--tbw-spacing-xs: .25em;--tbw-spacing-sm: .375em;--tbw-spacing-md: .5em;--tbw-spacing-lg: .75em;--tbw-spacing-xl: 1em;--tbw-icon-size: var(--tbw-base-icon-size);--tbw-icon-size-sm: .875em;--tbw-checkbox-size: var(--tbw-base-icon-size);--tbw-toggle-size: 1.25em;--tbw-border-radius: var(--tbw-base-radius);--tbw-color-bg: transparent;--tbw-color-panel-bg: light-dark(#eeeeee, #222222);--tbw-color-fg: light-dark(#222222, #eeeeee);--tbw-color-fg-muted: light-dark(#555555, #aaaaaa);--tbw-color-accent: light-dark(#3b82f6, #3b82f6);--tbw-color-accent-fg: light-dark(#ffffff, #000000);--tbw-color-success: light-dark(hsl(122, 39%, 40%), hsl(122, 39%, 49%));--tbw-color-warning: light-dark(hsl(38, 92%, 50%), hsl(38, 92%, 50%));--tbw-color-error: light-dark(hsl(0, 65%, 51%), hsl(0, 65%, 55%));--tbw-color-danger: var(--tbw-color-error);--tbw-color-selection: light-dark(#fff7d6, #333333);--tbw-color-row-alt: var(--tbw-color-bg);--tbw-color-row-hover: light-dark(#f0f6ff, #1c1c1c);--tbw-color-header-bg: color-mix(in hsl, var(--tbw-color-panel-bg) 85%, var(--tbw-color-fg));--tbw-color-header-fg: color-mix(in hsl, var(--tbw-color-fg) 75%, var(--tbw-color-panel-bg));--tbw-color-border: light-dark(#d0d0d4, #454545);--tbw-color-border-strong: light-dark(#777777, #666666);--tbw-color-border-cell: var(--tbw-color-border);--tbw-color-border-header: var(--tbw-color-border);--tbw-color-shadow: light-dark(rgba(0, 0, 0, .1), rgba(0, 0, 0, .3));--tbw-font-family: inherit;--tbw-font-size-header: var(--tbw-font-size);--tbw-font-weight-header: bold;--tbw-cell-padding-header: var(--tbw-spacing-xs) var(--tbw-spacing-md);--tbw-cell-padding-v: var(--tbw-spacing-xs);--tbw-cell-padding-h: var(--tbw-spacing-md);--tbw-cell-padding: var(--tbw-cell-padding-v) var(--tbw-cell-padding-h);--tbw-cell-padding-input: var(--tbw-spacing-xs) var(--tbw-spacing-sm);--tbw-row-height: 1.75em;--tbw-header-height: 1.875em;--tbw-cell-white-space: nowrap;--tbw-border-width: 1px;--tbw-border-style: solid;--tbw-border-input: var(--tbw-border-width) var(--tbw-border-style) var(--tbw-color-border-strong);--tbw-border-header: var(--tbw-border-width) var(--tbw-border-style) var(--tbw-color-border-header);--tbw-row-divider: var(--tbw-border-width) var(--tbw-border-style) var(--tbw-color-border-cell);--tbw-row-hover-outline: 0;--tbw-color-active-row-bg: var(--tbw-color-selection);--tbw-active-row-outline: 0;--tbw-focus-outline-width: 2px;--tbw-focus-outline: var(--tbw-focus-outline-width) var(--tbw-border-style) var(--tbw-color-accent);--tbw-focus-outline-offset: -2px;--tbw-focus-background: rgba(from var(--tbw-color-accent) r g b / 12%);--tbw-range-border-color: var(--tbw-color-accent);--tbw-range-selection-bg: rgba(from var(--tbw-range-border-color) r g b / 12%);--tbw-column-selection-bg: rgba(from var(--tbw-color-accent) r g b / 12%);--tbw-resize-handle-width: 2px;--tbw-resize-handle-color: transparent;--tbw-resize-handle-color-hover: var(--tbw-color-accent);--tbw-resize-handle-border-radius: 0;--tbw-resize-indicator-width: 2px;--tbw-resize-indicator-color: var(--tbw-color-accent);--tbw-resize-indicator-opacity: .6;--tbw-transition-duration: .12s;--tbw-transition-ease: ease;--tbw-animation-duration: .2s;--tbw-animation-easing: ease-out;--tbw-animation-enabled: 1;--tbw-row-change-duration: .5s;--tbw-row-insert-duration: .3s;--tbw-row-remove-duration: .2s;--tbw-row-change-color: rgba(from var(--tbw-color-accent) r g b / 25%);--tbw-sort-indicator-color: var(--tbw-color-fg-muted);--tbw-sort-indicator-active-color: var(--tbw-color-accent);--tbw-sort-indicator-display: inline-flex;--tbw-sort-indicator-visibility: visible;--tbw-header-text-transform: none;--tbw-header-letter-spacing: normal;--tbw-color-header-separator: var(--tbw-color-border-cell);--tbw-density-scale: 1;--tbw-shell-header-height: 2.75em;--tbw-shell-header-bg: var(--tbw-color-panel-bg);--tbw-shell-header-border: var(--tbw-color-border);--tbw-shell-title-font-size: var(--tbw-font-size);--tbw-shell-title-font-weight: 600;--tbw-tool-panel-width: 17.5em;--tbw-tool-panel-bg: var(--tbw-color-panel-bg);--tbw-tool-panel-border: var(--tbw-color-border);--tbw-tool-panel-header-height: 2.5em;--tbw-tool-panel-transition: var(--tbw-animation-duration) var(--tbw-animation-easing);--tbw-toolbar-button-size: 2em;--tbw-toolbar-button-gap: var(--tbw-spacing-xs);--tbw-panel-padding: var(--tbw-spacing-lg);--tbw-panel-gap: var(--tbw-spacing-md);--tbw-menu-item-padding: var(--tbw-spacing-sm) var(--tbw-spacing-lg);--tbw-menu-item-gap: var(--tbw-spacing-md);--tbw-menu-min-width: 10rem;--tbw-button-padding: var(--tbw-spacing-sm) var(--tbw-spacing-lg);--tbw-button-padding-sm: var(--tbw-spacing-xs) var(--tbw-spacing-md);--tbw-input-height: var(--tbw-row-height);--tbw-input-padding: 0 var(--tbw-spacing-md);--tbw-detail-padding: var(--tbw-spacing-xl);--tbw-detail-max-height: 31.25rem;--tbw-indicator-size: var(--tbw-spacing-sm);--tbw-icon-expand: "▶";--tbw-icon-collapse: "▼";--tbw-icon-sort-asc: "▲";--tbw-icon-sort-desc: "▼";--tbw-icon-sort-none: "⇅";--tbw-icon-submenu-arrow: "▶";--tbw-icon-drag-handle: "⋮⋮";--tbw-icon-tool-panel: "☰";--tbw-icon-filter: "";--tbw-icon-filter-active: "";--tbw-icon-print: "🖨️";--tbw-icon-expand-mask: none;--tbw-icon-collapse-mask: none;--tbw-icon-sort-asc-mask: none;--tbw-icon-sort-desc-mask: none;--tbw-icon-sort-none-mask: none;--tbw-icon-submenu-arrow-mask: none;--tbw-icon-drag-handle-mask: none;--tbw-icon-tool-panel-mask: none;--tbw-icon-filter-mask: url("data:image/svg+xml,%3Csvg viewBox=\'0 0 16 16\' width=\'12\' height=\'12\' xmlns=\'http://www.w3.org/2000/svg\'%3E%3Cpath fill=\'currentColor\' d=\'M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z\'/%3E%3C/svg%3E");--tbw-icon-filter-active-mask: var(--tbw-icon-filter-mask);--tbw-icon-print-mask: none}}\n@layer tbw-base{tbw-grid{color-scheme:inherit;position:relative;display:block;width:100%;height:100%;min-height:0;contain:content;font-family:var(--tbw-font-family);font-size:var(--tbw-font-size);font-feature-settings:"tnum","lnum";background:var(--tbw-color-bg);color:var(--tbw-color-fg);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);overflow:clip;outline:none}tbw-grid,tbw-grid *{box-sizing:border-box}tbw-grid>tbw-grid-column,tbw-grid>tbw-grid-type{display:none}tbw-grid .tbw-grid-root{position:relative;display:flex;flex-direction:column;height:100%}tbw-grid .tbw-grid-root.has-shell{display:flex;flex-direction:column;height:100%}tbw-grid .tbw-grid-root:has(.selected){-webkit-user-select:none;user-select:none}tbw-grid .tbw-grid-content{flex:1;min-width:0;min-height:0;display:flex;flex-direction:row;overflow:hidden;touch-action:none}tbw-grid .tbw-scroll-area{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow-x:auto;overflow-y:hidden;overflow-anchor:none}tbw-grid .rows-body-wrapper{flex:1;min-height:0;display:flex;flex-direction:row;width:100%;min-width:fit-content}tbw-grid .rows-body{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow:visible}tbw-grid .rows-container{display:flex;flex-direction:row;flex:1;min-height:0;overflow:visible;position:relative}tbw-grid .rows-viewport{flex:1;min-width:0;position:relative;display:block;overflow:clip;touch-action:none}tbw-grid .rows-viewport .rows{position:absolute;top:0;left:0;min-width:100%;will-change:transform;z-index:var(--tbw-z-layer-rows, 1)}tbw-grid .faux-vscroll{position:sticky;inset-inline-end:0;flex-shrink:0;width:auto;overflow-y:auto;overflow-x:hidden;z-index:var(--tbw-z-layer-header, 30);touch-action:none}tbw-grid .faux-vscroll-spacer{width:1px}tbw-grid .tbw-sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}tbw-grid[data-has-focus] .cell-focus,tbw-grid[data-has-focus] .row-focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}tbw-grid .sticky-left,tbw-grid .sticky-right{position:sticky;z-index:25}tbw-grid .sticky-left{box-shadow:1px 0 0 var(--tbw-color-border)}tbw-grid .sticky-right{box-shadow:-1px 0 0 var(--tbw-color-border)}}\n@layer tbw-base{tbw-grid [data-icon=expand]:empty:before{content:var(--tbw-icon-expand)}tbw-grid [data-icon=collapse]:empty:before{content:var(--tbw-icon-collapse)}tbw-grid [data-icon=sort-asc]:empty:before{content:var(--tbw-icon-sort-asc)}tbw-grid [data-icon=sort-desc]:empty:before{content:var(--tbw-icon-sort-desc)}tbw-grid [data-icon=sort-none]:empty:before{content:var(--tbw-icon-sort-none)}tbw-grid [data-icon=submenu-arrow]:empty:before{content:var(--tbw-icon-submenu-arrow)}tbw-grid [data-icon=drag-handle]:empty:before{content:var(--tbw-icon-drag-handle)}tbw-grid [data-icon=tool-panel]:empty:before{content:var(--tbw-icon-tool-panel)}tbw-grid [data-icon=print]:empty:before{content:var(--tbw-icon-print)}tbw-grid [data-icon=filter]:empty:before{content:var(--tbw-icon-filter)}tbw-grid [data-icon=filter-active]:empty:before{content:var(--tbw-icon-filter-active)}tbw-grid [data-icon]:empty:before{display:inline-block;vertical-align:middle;-webkit-mask-size:contain;mask-size:contain;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;-webkit-mask-position:center;mask-position:center}tbw-grid [data-icon=expand]:empty:before{-webkit-mask-image:var(--tbw-icon-expand-mask);mask-image:var(--tbw-icon-expand-mask)}tbw-grid [data-icon=collapse]:empty:before{-webkit-mask-image:var(--tbw-icon-collapse-mask);mask-image:var(--tbw-icon-collapse-mask)}tbw-grid [data-icon=sort-asc]:empty:before{-webkit-mask-image:var(--tbw-icon-sort-asc-mask);mask-image:var(--tbw-icon-sort-asc-mask)}tbw-grid [data-icon=sort-desc]:empty:before{-webkit-mask-image:var(--tbw-icon-sort-desc-mask);mask-image:var(--tbw-icon-sort-desc-mask)}tbw-grid [data-icon=sort-none]:empty:before{-webkit-mask-image:var(--tbw-icon-sort-none-mask);mask-image:var(--tbw-icon-sort-none-mask)}tbw-grid [data-icon=submenu-arrow]:empty:before{-webkit-mask-image:var(--tbw-icon-submenu-arrow-mask);mask-image:var(--tbw-icon-submenu-arrow-mask)}tbw-grid [data-icon=drag-handle]:empty:before{-webkit-mask-image:var(--tbw-icon-drag-handle-mask);mask-image:var(--tbw-icon-drag-handle-mask)}tbw-grid [data-icon=tool-panel]:empty:before{-webkit-mask-image:var(--tbw-icon-tool-panel-mask);mask-image:var(--tbw-icon-tool-panel-mask)}tbw-grid [data-icon=print]:empty:before{-webkit-mask-image:var(--tbw-icon-print-mask);mask-image:var(--tbw-icon-print-mask)}tbw-grid [data-icon=filter]:empty:before,tbw-grid [data-icon=filter-active]:empty:before{width:var(--tbw-icon-size, 1em);height:var(--tbw-icon-size, 1em);background:currentColor}tbw-grid [data-icon=filter]:empty:before{-webkit-mask-image:var(--tbw-icon-filter-mask);mask-image:var(--tbw-icon-filter-mask)}tbw-grid [data-icon=filter-active]:empty:before{-webkit-mask-image:var(--tbw-icon-filter-active-mask);mask-image:var(--tbw-icon-filter-active-mask)}.tbw-context-menu [data-icon]:empty:before{display:inline-block;width:1em;height:1em;vertical-align:middle}.tbw-context-menu [data-icon=submenu-arrow]:empty:before{content:var(--tbw-icon-submenu-arrow, "▶")}}\n@layer tbw-base{tbw-grid .header{display:block;flex-shrink:0;z-index:var(--tbw-z-layer-header, 30);background:var(--tbw-color-header-bg);overflow:visible}tbw-grid .header-group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-color-header-bg);z-index:var(--tbw-z-layer-header, 30)}tbw-grid .header-group-cell{display:flex;align-items:center;justify-content:flex-start;padding:var(--tbw-cell-padding-header, 2px 8px);color:var(--tbw-color-header-group-fg, var(--tbw-color-header-fg));font-weight:var(--tbw-font-weight-header-group, var(--tbw-font-weight-header));justify-content:var(--tbw-align-header-group, var(--tbw-align-header, flex-start))}tbw-grid .header-group-cell:not(:last-child){border-right:2px solid var(--tbw-color-border)}tbw-grid .header-row{display:grid;grid-template-columns:var(--tbw-column-template);color:var(--tbw-color-header-fg);font-size:var(--tbw-font-size-header);min-height:var(--tbw-header-height);border-bottom:var(--tbw-border-header);z-index:var(--tbw-z-layer-header, 30);text-transform:var(--tbw-header-text-transform);letter-spacing:var(--tbw-header-letter-spacing)}tbw-grid .header-row>.cell{display:flex;align-items:center;gap:4px;padding:var(--tbw-cell-padding-header, 2px 8px);background-color:var(--tbw-color-header-bg);font-weight:var(--tbw-font-weight-header);border-right:1px solid var(--tbw-color-border-cell);overflow:visible;min-width:0}tbw-grid .header-row>.cell>span:first-child{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:inherit}tbw-grid .header-row>.cell>span[part~=sort-indicator]{flex-shrink:0;opacity:.6;color:var(--tbw-sort-indicator-color);display:var(--tbw-sort-indicator-display, inline-flex);visibility:var(--tbw-sort-indicator-visibility, visible);transition:opacity .15s,visibility 0s,display 0s allow-discrete;transition-behavior:allow-discrete}tbw-grid .header-row>.cell:hover>span[part~=sort-indicator]{display:inline-flex;visibility:visible}tbw-grid .header-row>.cell[aria-sort=ascending]>span[part~=sort-indicator],tbw-grid .header-row>.cell[aria-sort=descending]>span[part~=sort-indicator]{display:inline-flex;visibility:visible;opacity:1;color:var(--tbw-sort-indicator-active-color)}tbw-grid .header-row>.cell:last-child{border-right:0}tbw-grid .header-row>.cell:last-child .resize-handle{right:0;width:calc(var(--tbw-resize-hit-area, 18px) / 2)}tbw-grid .header-row>.cell.grouped.group-end:not(:last-child){border-right:2px solid var(--tbw-color-border)}tbw-grid .header-row>.cell.resizable{position:relative}tbw-grid .header-row>.cell.sticky-left,tbw-grid .header-row>.cell.sticky-right{background:var(--tbw-color-header-bg);z-index:35}tbw-grid .header-group-row>.header-group-cell.sticky-left,tbw-grid .header-group-row>.header-group-cell.sticky-right{background:var(--tbw-color-header-bg);z-index:35}tbw-grid .sortable{cursor:pointer;-webkit-user-select:none;user-select:none}tbw-grid .resize-handle{position:absolute;top:0;right:calc(var(--tbw-resize-hit-area, 18px) / -2);width:var(--tbw-resize-hit-area, 18px);height:100%;cursor:e-resize;-webkit-user-select:none;user-select:none;touch-action:none;z-index:20;background:transparent}tbw-grid .resize-handle:before{content:"";position:absolute;top:0;left:50%;transform:translate(-50%);width:var(--tbw-resize-handle-width);height:100%;background:var(--tbw-resize-handle-color);border-radius:var(--tbw-resize-handle-border-radius);transition:background .12s ease}tbw-grid .resize-handle:after{content:"";position:absolute;top:100%;left:50%;transform:translate(-50%);width:var(--tbw-resize-handle-width);height:0;background:var(--tbw-resize-indicator-color, var(--tbw-color-accent));opacity:0;pointer-events:none;transition:opacity .12s ease,height 0s .12s;z-index:1000}tbw-grid .resize-handle:hover:before{background:var(--tbw-resize-handle-color-hover)}tbw-grid .resize-handle:hover:after{height:100vh;opacity:var(--tbw-resize-indicator-opacity, .6);transition:opacity .12s ease,height 0s}}\n@layer tbw-base{tbw-grid .data-grid-row{display:grid;grid-template-columns:var(--tbw-column-template);contain:layout style}tbw-grid .data-grid-row:nth-child(2n){background:var(--tbw-color-row-alt)}@media(hover:hover){tbw-grid .data-grid-row:hover{background:var(--tbw-color-row-hover)}}tbw-grid .data-grid-row>.cell{display:block;padding:var(--tbw-cell-padding, 2px 8px);border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height);align-content:center;border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0;white-space:var(--tbw-cell-white-space, nowrap);text-overflow:ellipsis}tbw-grid .data-grid-row>.cell>*{overflow:hidden;text-overflow:ellipsis;white-space:inherit;min-width:0}tbw-grid .data-grid-row>.cell:last-child{border-right:0}tbw-grid .data-grid-row>.cell[data-type=boolean]{text-align:center}tbw-grid .data-grid-row>.cell[data-type=boolean] input[type=checkbox]{margin:0;width:var(--tbw-checkbox-size);height:var(--tbw-checkbox-size);vertical-align:middle}tbw-grid .data-grid-row>.cell.selected:focus-visible,tbw-grid .data-grid-row>.cell:focus-visible:not(.cell-focus){outline:none}tbw-grid .data-grid-row>.cell.sticky-left,tbw-grid .data-grid-row>.cell.sticky-right{background:var(--tbw-color-panel-bg)}tbw-grid .selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}}\n@layer tbw-base{.tbw-loading-overlay{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:1000;pointer-events:all;animation:tbw-fade-in .15s ease-out}.tbw-spinner{--tbw-spinner-size: 48px;--tbw-spinner-border-width: 3px;--tbw-spinner-color: var(--tbw-color-accent);--tbw-spinner-track-color: var(--tbw-color-border);width:var(--tbw-spinner-size);height:var(--tbw-spinner-size);border:var(--tbw-spinner-border-width) solid var(--tbw-spinner-track-color);border-top-color:var(--tbw-spinner-color);border-radius:50%;animation:tbw-spin .8s linear infinite}.tbw-spinner--large{--tbw-spinner-size: min(48px, calc(100% - 16px) )}.tbw-spinner--small{--tbw-spinner-size: calc(var(--tbw-row-height, 28px) * .6);--tbw-spinner-border-width: 2px}.data-grid-row.tbw-row-loading{position:relative;pointer-events:none}.tbw-row-loading-overlay{position:absolute;inset:0;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:26;animation:tbw-fade-in .15s ease-out;pointer-events:none;display:flex;align-items:center}.tbw-row-loading-spinner{--_spinner-size: calc(var(--tbw-row-height, 28px) * .6);margin-left:var(--tbw-spacing-md);width:var(--_spinner-size);height:var(--_spinner-size);border:2px solid var(--tbw-spinner-track-color, var(--tbw-color-border));border-top-color:var(--tbw-spinner-color, var(--tbw-color-accent));border-radius:50%;animation:tbw-spin .8s linear infinite}.cell.tbw-cell-loading{position:relative;pointer-events:none}.cell.tbw-cell-loading:before{content:"";position:absolute;inset:0;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:26;animation:tbw-fade-in .15s ease-out}.cell.tbw-cell-loading:after{--_spinner-size: calc(var(--tbw-row-height, 28px) * .5);content:"";position:absolute;left:var(--tbw-spacing-sm);top:0;bottom:0;margin:auto 0;width:var(--_spinner-size);height:var(--_spinner-size);border:2px solid var(--tbw-spinner-track-color, var(--tbw-color-border));border-top-color:var(--tbw-spinner-color, var(--tbw-color-accent));border-radius:50%;animation:tbw-spin .8s linear infinite;z-index:27}}\n@layer tbw-base{.tbw-empty-overlay{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;padding:var(--tbw-spacing-md, 12px);text-align:center;background:light-dark(rgba(255,255,255,.6),rgba(0,0,0,.4));color:var(--tbw-color-text-secondary, var(--tbw-color-text));z-index:999;pointer-events:all;animation:tbw-fade-in .15s ease-out}.tbw-empty-message{font-family:var(--tbw-font-family, inherit);font-size:var(--tbw-font-size-md, 14px);line-height:1.4;max-width:480px;-webkit-user-select:text;user-select:text}}\n@layer tbw-base{tbw-grid .tbw-expanding{animation:tbw-expand var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}tbw-grid .tbw-collapsing{animation:tbw-collapse var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}tbw-grid[data-animation-mode=off]{--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms}tbw-grid[data-animation-mode=off] .data-grid-row[data-animating]{animation:none}tbw-grid .data-grid-row[data-animating=change]{animation:tbw-row-change var(--tbw-row-change-duration) ease-out}tbw-grid .data-grid-row[data-animating=insert]{animation:tbw-row-insert var(--tbw-row-insert-duration) ease-out;will-change:max-height,opacity}tbw-grid .data-grid-row[data-animating=remove]{animation:tbw-row-remove var(--tbw-row-remove-duration) ease-out forwards;will-change:max-height,opacity,transform;pointer-events:none}}@keyframes tbw-expand{0%{opacity:0;max-height:0;transform:translateY(-8px)}to{opacity:1;max-height:500px;transform:translateY(0)}}@keyframes tbw-collapse{0%{opacity:1;max-height:500px;transform:translateY(0)}to{opacity:0;max-height:0;transform:translateY(-8px)}}@keyframes tbw-row-change{0%{background-color:transparent}20%{background-color:var(--tbw-row-change-color)}to{background-color:transparent}}@keyframes tbw-row-insert{0%{opacity:0;max-height:0;overflow:hidden}to{opacity:1;max-height:var(--tbw-row-height, 28px);overflow:hidden}}@keyframes tbw-row-remove{0%{opacity:1;transform:translateY(0);max-height:var(--tbw-row-height, 28px)}to{opacity:0;max-height:0;transform:translateY(-8px)}}@keyframes tbw-spin{to{transform:rotate(360deg)}}@keyframes tbw-fade-in{0%{opacity:0}to{opacity:1}}\n@layer tbw-base{@media(forced-colors:active){tbw-grid{--tbw-color-border: CanvasText;--tbw-color-border-strong: CanvasText;--tbw-color-border-cell: CanvasText;--tbw-color-border-header: CanvasText;--tbw-color-fg: CanvasText;--tbw-color-bg: Canvas;--tbw-color-panel-bg: Canvas;--tbw-color-header-bg: Canvas;--tbw-color-header-fg: CanvasText;--tbw-color-accent: Highlight;--tbw-color-accent-fg: HighlightText;--tbw-color-selection: Highlight;--tbw-color-row-hover: Highlight;--tbw-focus-outline: 2px solid Highlight;--tbw-range-border-color: Highlight}tbw-grid .cell:focus,tbw-grid .cell.active-cell{outline:2px solid Highlight!important;outline-offset:-2px}tbw-grid .data-grid-row[aria-selected=true]{background:Highlight!important;color:HighlightText!important}}@media(prefers-reduced-motion:reduce){tbw-grid[data-animation-mode=reduced-motion]{--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms}tbw-grid[data-animation-mode=reduced-motion] .data-grid-row[data-animating]{animation:none}}}\n')}getPlugin(e){return this.#ge?.getPlugin(e)}getPluginByName(e){return this.#ge?.getPluginByName(e)}requestRender(){this.#ee.requestPhase(fe.ROWS,"plugin:requestRender")}requestColumnsRender(){this.#ee.requestPhase(fe.COLUMNS,"plugin:requestColumnsRender")}requestRenderWithFocus(){this._restoreFocusAfterRender=!0,this.#ee.requestPhase(fe.ROWS,"plugin:requestRenderWithFocus")}updateTemplate(){M(this)}requestAfterRender(){this.#ee.requestPhase(fe.STYLE,"plugin:requestAfterRender")}requestVirtualRefresh(){this._virtualization.start=-1,this.refreshVirtualWindow(!1)}#Ne(){this.#ge=new zt(this);const e=this.#b?.plugins,t=Array.isArray(e)?e:[],r=this.#b?.features;let i,o=[];if(r&&it){o=it(r).map(e=>this.#Fe(e))}if(0===o.length)i=t;else if(0===t.length)i=o;else{const e=new Set(t.map(e=>e.name));i=[...o.filter(t=>!e.has(t.name)),...t]}this.#ge.attachAll(i)}#Fe(e){const t=this.#Ce.get(e.name);return t&&t!==e?(t.refreshUserConfigFrom(e),t):(this.#Ce.set(e.name,e),e)}#qe(){!function(e){let t=!1;for(const{name:r,styles:i}of e)Ct.has(r)||(Ct.set(r,Et(i)),t=!0);t&&St()}(this.#ge?.getPluginStyles()??[])}#$e(){const e=this.#b?.plugins,t=Array.isArray(e)?e:[],r=this.#b?.features??void 0,i=r!==this.#pe;if((this.#fe===t||void 0!==this.#fe&&this.#fe.length===t.length&&this.#fe.every((e,r)=>e===t[r]))&&!i)return void(this.#fe=t);this.#ge&&this.#ge.detachAll(),this.#Ne(),this.#qe(),this.#fe=t,this.#pe=r,this.#We(),this.#K.markSourcesChanged(),this.#K.merge();const o=this.#ie;if(this.#ie=this.#ge?.getAll().some(e=>e.onScroll)??!1,!o&&this.#ie){const e=this.#j.querySelector(".tbw-grid-content")??this.#j.querySelector(".tbw-grid-root");this.#Ve(e)}}#Ue(){this.#ge?.detachAll()}#Be(){const e=Nt.getAdapters();if(0===e.length&&!this.__frameworkAdapter)return;const t=this.__frameworkAdapter;return r=>{if(t?.createToolPanelRenderer){const e=t.createToolPanelRenderer(r);if(e)return e}for(const t of e)if(t.createToolPanelRenderer){const e=t.createToolPanelRenderer(r);if(e)return e}}}_registerLightDomHandler(e,t){this.#K.registerLightDomHandler(e,t)}_unregisterLightDomHandler(e){this.#K.unregisterLightDomHandler(e)}_requestConfigMerge(){this.#K.markSourcesChanged(),this.#K.merge()}_getToolPanelRendererFactory(){return this.#Be()}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",Nt.version),this.hasAttribute("data-tbw-grid")||this.setAttribute("data-tbw-grid",""),this.id||(this.id="tbw-grid-"+ ++Nt.#G),this._rows=Array.isArray(this.#X)?[...this.#X]:[],this.#le&&(this.#le.abort(),this.#ve=!1),this.#le=new AbortController,this.#ue&&(st(this.#ue),this.#ue=void 0),this.#Ge(),this.#K.parseLightDomColumns(this),this.#K.merge(),this.#Ne();const e=this.#b?.plugins;var t,r;this.#fe=Array.isArray(e)?e:[],this.#pe=this.#b?.features??void 0,this.#Y||(this.#je(),this.#qe(),this.#Y=!0),this.#Ye(),this.#ue=(t=()=>{this.#Xe()},r={timeout:100},nt?requestIdleCallback(t,r):window.setTimeout(()=>{const e=Date.now();t({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-e))})},1))}disconnectedCallback(){this.#ue&&(st(this.#ue),this.#ue=void 0),this.#ne&&(clearTimeout(this.#ne),this.#ne=0),this.#Ue();const e=this.#ge?.getPluginByName("shell");e?.disposeShellState?.(),xt(this.#ae),this.#le&&(this.#le.abort(),this.#le=void 0),this.#ye?.abort(),this.#ye=void 0,this.#ve=!1,this._resizeController&&this._resizeController.dispose(),this.#ce&&(this.#ce.disconnect(),this.#ce=void 0),this.#de&&(this.#de.disconnect(),this.#de=void 0,this.#Ke=!1,this.#Ze=0),Xe(this),this.#Qe.clear(),this._virtualization.heightCache?.byKey.clear(),this.#fe=void 0,this.#pe=void 0;for(let t=0;t<this._rowPool.length;t++)this._rowPool[t].remove();this._rowPool.length=0,this.__rowsBodyEl=null,this.#Z=!1}attributeChangedCallback(e,t,r){if("loading"===e){const e=null!==r&&"false"!==r;return void(this.loading!==e&&(this.loading=e))}if(t!==r&&r&&"null"!==r&&"undefined"!==r)if("rows"===e||"columns"===e||"grid-config"===e)try{const t=JSON.parse(r);"rows"===e?this.rows=t:"columns"===e?this.columns=t:"grid-config"===e&&(this.gridConfig=t)}catch{v("TBW130",`Invalid JSON for '${e}' attribute: ${r}`,this.id)}else"fit-mode"===e?this.fitMode=r:"column-inference"===e&&(this.columnInference=r)}#Ye(){const e=this.#j.querySelector(".tbw-grid-content")??this.#j.querySelector(".tbw-grid-root");if(this._headerRowEl=e?.querySelector(".header-row"),this._virtualization.totalHeightEl=e?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=e?.querySelector(".rows-viewport"),this._bodyEl=e?.querySelector(".rows"),this.__rowsBodyEl=e?.querySelector(".rows-body"),this.setAttribute("data-upgraded",""),this.#Z=!0,this._resizeController=lt(this),this.#Je(),this.#Ve(e),this.#ve)return;this.#ve=!0;const t=this.disconnectSignal;rt(this,this,this.#j,t),this.#We(),queueMicrotask(()=>this.#et()),this.#ee.requestPhase(fe.FULL,"afterConnect")}#We(){const e=this.#b.rowHeight,t=this.#ge.hasRowHeightPlugin();"function"==typeof e||t?this._virtualization.variableHeights||(this._virtualization.variableHeights=!0,this._virtualization.rowHeight="number"==typeof e&&e>0?e:this._virtualization.rowHeight||28,this.#we.initializePositionCache(),"function"!=typeof e&&(this.#oe=!0)):!t&&"function"!=typeof e&&this._virtualization.variableHeights?(this._virtualization.variableHeights=!1,this._virtualization.positionCache=null):"number"==typeof e&&e>0?(this._virtualization.rowHeight=e,this._virtualization.variableHeights=!1):requestAnimationFrame(()=>this.#tt())}#tt(){if(this.#ge.hasRowHeightPlugin())return;const e=this.#b.rowHeight;if("number"==typeof e&&e>0)return;const t=this._bodyEl?.querySelector(".data-grid-row");if(!t)return;const r=this.#rt(),i=[],o=this._bodyEl?.querySelectorAll(".data-grid-row");for(const h of o??[]){if(h.style.getPropertyValue("--tbw-row-height"))continue;let e=0;h.querySelectorAll(".cell").forEach(t=>{const r=t.offsetHeight;r>e&&(e=r)});const t=Math.max(h.getBoundingClientRect().height,e);t>0&&i.push(t)}if(0===i.length)return;i.sort((e,t)=>e-t);const n=i.length>>1,s=i.length%2==1?i[n]:(i[n-1]+i[n])/2,a=this._virtualization.rowHeight,l=this.#Ze,c=r>0&&l>0&&Math.abs(r-l)>1,d=r>0&&0===l,u=s>0&&s-a>1;if(r>0&&(this.#Ze=r),c||d||u){const e=c||d?Math.max(r,s):s;Math.abs(e-a)>1&&(this._virtualization.rowHeight=e,this.#ee.requestPhase(fe.VIRTUALIZATION,"measureRowHeight"))}}#rt(){const e=getComputedStyle(this).getPropertyValue("--tbw-row-height").trim();if(!e)return 0;if(e.endsWith("px"))return parseFloat(e)||0;const t=this._bodyEl?.querySelector('.data-grid-row:not([style*="--tbw-row-height"]) > .cell');if(!t)return 0;const r=parseFloat(getComputedStyle(t).minHeight);return r>0?r:0}#it(){const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const t=e.querySelectorAll(".cell");let r=0;t.forEach(e=>{const t=e.offsetHeight;t>r&&(r=t)});const i=e.getBoundingClientRect(),o=Math.max(i.height,r);if(o>0){if(Math.abs(o-this._virtualization.rowHeight)>1&&(this._virtualization.rowHeight=o),this.#we.initializePositionCache(),this._virtualization.totalHeightEl){const e=this.#we.calculateTotalSpacerHeight(this._rows.length);this._virtualization.totalHeightEl.style.height=`${e}px`}}}#Ve(e){this.#ye?.abort(),this.#ye=new AbortController;const t=this.#ye.signal,r=e?.querySelector(".faux-vscroll"),i=e?.querySelector(".rows");if(this._virtualization.container=r??this,this.#ie=this.#ge?.getAll().some(e=>e.onScroll)??!1,r&&i){r.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#ie)return;const e=r.scrollTop,t=Oe(e,this._virtualization.scrollMapping),o=this._virtualization.rowHeight;if(this._rows.length<=this._virtualization.bypassThreshold)i.style.transform=`translateY(${-e}px)`;else{const e=this._virtualization.positionCache;let r,n;if(this._virtualization.variableHeights&&e&&e.length>0){r=Le(e,t),-1===r&&(r=0);const i=r-r%2;n=e[i]?.offset??i*o}else{r=Math.floor(t/o);n=(r-r%2)*o}const s=-(t-n);i.style.transform=`translateY(${s}px)`}this.#re=e,this.#te||(this.#te=requestAnimationFrame(()=>{this.#te=0,null!==this.#re&&(this.#ot(this.#re),this.#re=null)}))},{passive:!0,signal:t});const e=this.#j.querySelector(".tbw-scroll-area");this.#_e=e,this._virtualization.scrollAreaEl=e,e&&this.#ie&&e.addEventListener("scroll",()=>{const t=this.#he;t.scrollTop=r.scrollTop,t.scrollLeft=e.scrollLeft,t.scrollHeight=r.scrollHeight,t.scrollWidth=e.scrollWidth,t.clientHeight=r.clientHeight,t.clientWidth=e.clientWidth,this.#ge?.onScroll(t)},{passive:!0,signal:t});const o=this.#j.querySelector(".tbw-grid-content"),n=this.#_e;o&&(o.addEventListener("wheel",e=>{try{if(o.querySelector("select:open"))return}catch{}const t=e.shiftKey||Math.abs(e.deltaX)>Math.abs(e.deltaY);if(t&&n){const t=e.shiftKey?e.deltaY:e.deltaX,{scrollLeft:r,scrollWidth:i,clientWidth:o}=n;(t>0&&r<i-o||t<0&&r>0)&&(e.preventDefault(),n.scrollLeft+=t)}else if(!t){const{scrollTop:t,scrollHeight:i,clientHeight:o}=r;(e.deltaY>0&&t<i-o||e.deltaY<0&&t>0)&&(e.preventDefault(),r.scrollTop+=e.deltaY)}},{passive:!1,signal:t}),Tt(o,this.#ae,{fauxScrollbar:r,scrollArea:n},t))}var o,n,s;this._bodyEl&&(o=this,n=this._bodyEl,s=t,n.addEventListener("mousedown",e=>{const t=e.target.closest(".cell[data-col]");if(!t)return;if(t.classList.contains(H.EDITING))return;const r=e.target;r.draggable||r.closest('[draggable="true"]')||e.preventDefault(),et(o,t)},{signal:s}),n.addEventListener("click",e=>{const t=e.target.closest(".data-grid-row");if(t&&Qe(o,e,t),!document.activeElement?.closest(`.cell.${H.EDITING}`)){const t=e.target.closest("tbw-grid, [data-tbw-grid]");t&&t.focus({preventScroll:!0})}},{signal:s}),n.addEventListener("dblclick",e=>{const t=e.target.closest(".data-grid-row");t&&Qe(o,e,t)},{signal:s})),this.#ce?.disconnect(),this._virtualization.viewportEl&&(this.#ce=new ResizeObserver(()=>{this.#nt(),this.#ee.requestPhase(fe.VIRTUALIZATION,"resize-observer")}),this.#ce.observe(this._virtualization.viewportEl)),this.#j.addEventListener("focusin",()=>{this.dataset.hasFocus=""},{signal:t}),this.#j.addEventListener("focusout",e=>{const t=e.relatedTarget;t&&(this.#j.contains(t)||this.#me.isInExternalFocusContainer(t))||delete this.dataset.hasFocus},{signal:t})}#Ke=!1;#Ze=0;#st(){if(this.#Ke)return;const e=this._bodyEl?.querySelector(".data-grid-row");e&&(this.#Ke=!0,this.#de?.disconnect(),this.#de=new ResizeObserver(()=>{this.#tt()}),this.#de.observe(e))}addEventListener(e,t,r){super.addEventListener(e,t,r)}removeEventListener(e,t,r){super.removeEventListener(e,t,r)}on(e,t){const r=e=>{t(e.detail,e)};return this.addEventListener(e,r),()=>this.removeEventListener(e,r)}#at(e,t){this.#Z&&this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}_emitDataChange(){this.#at("data-change",{rowCount:this._rows.length,sourceRowCount:this.#X.length}),function(e,t,r){if(r===t.lastAnnouncedSourceCount)return;const i=t.lastAnnouncedSourceCount;t.lastAnnouncedSourceCount=r,0===r&&i<0||n(e,s(e,"dataLoaded",r))}(this,this.#lt,this.#X.length)}#et(){const e=this._bodyEl?.querySelectorAll(".data-grid-row");e?.forEach((e,t)=>{const r=t===this._focusRow;e.setAttribute("aria-selected",String(r)),e.querySelectorAll(".cell").forEach((e,t)=>{e.setAttribute("aria-selected",String(r&&t===this._focusCol))})})}#Le(e){this.#J[e]=!0,this.#Q||(this.#Q=!0,queueMicrotask(()=>this.#ct()))}#ct(){if(!this.#Q||!this.#Z)return void(this.#Q=!1);const e=this.#J;if(this.#Q=!1,this.#J={rows:!1,columns:!1,gridConfig:!1,fitMode:!1,columnInference:!1},e.gridConfig)return this.#dt(),void(e.rows&&this.#ut());(e.columns||e.columnInference)&&this.#ht(),e.rows&&this.#ut(),e.fitMode&&this.#gt()}#ut(){this._rows=Array.isArray(this.#X)?[...this.#X]:[],this.#He=!0,this.#ee.requestPhase(fe.ROWS,"applyRowsUpdate")}#ft(){this.#He&&this._rebuildRowIdMap()}_rebuildRowIdMap(){this.#He=!1,this.#xe.clear();const e=this.#b.getRowId;for(let t=0;t<this._rows.length;t++){const r=ft(this._rows[t],e);void 0!==r&&this.#xe.set(r,{row:this._rows[t],index:t})}}#ht(){Xe(this),this.#K.merge(),this.#Je()}#gt(){this.#K.merge();if("fixed"===this.#b.fitMode)this.__didInitialAutoSize=!1,E(this);else{for(let e=0;e<this._columns.length;e++){const t=this._columns[e];!t.__userResized&&t.__autoSized&&delete t.width}M(this)}}#dt(){this.#K.parseLightDomColumns(this),this.#K.merge(),this.#$e(),this.#We(),this.#K.markSourcesChanged(),this.#K.merge();const e=this.#K.initialColumnState;if(e){this.#K.initialColumnState=void 0,this.#E=void 0;const t=this.#ge?.getAll()??[];this.#K.applyState(e,t)}if(this.#ge?.needsStructuralRerender()??!1)return this.#ge?.beforeStructuralRender(),this.#je(),this.#qe(),this.#Ye(),void this._rebuildRowIdMap();this._rebuildRowIdMap(),this.#ee.requestPhase(fe.COLUMNS,"applyGridConfigUpdate")}#pt(){if(this.__rowRenderEpoch++,this.#ge){const e=this.#Te.length>0?this.#Te:this._columns,t=e.filter(e=>!e.hidden),r=e.filter(e=>e.hidden),i=this.#ge.processColumns([...t]);if(i!==t){const o=new Set(i.map(e=>e.field));!t.some(e=>o.has(e.field))&&i.length>0?this._columns=[...i,...r]:this._columns=this.#wt(e,i,r)}else this._columns=[...e]}}#wt(e,t,r){if(0===r.length)return t;const i=new Map;for(const a of t)i.set(a.field,a);const o=new Set(e.map(e=>e.field)),n=[];for(const a of t)o.has(a.field)||n.push(a);const s=[];for(const a of e){const e=i.get(a.field);e?s.push(e):a.hidden&&s.push(a)}return s.push(...n),s}#mt(){Xe(this);const e=this.#X;if(!Array.isArray(e))return this._rows=[],this._rebuildRowIdMap(),this._virtualization.variableHeights&&this.#we.initializePositionCache(),void this._emitDataChange();if(!this._sortState&&this.#b.initialSort){const{field:e,direction:t}=this.#b.initialSort;this._columns.find(t=>t.field===e)&&(this._sortState={field:e,direction:"desc"===t?-1:1})}this._sortState&&(this.__originalOrder=this._rows);const t=function(e,t,r=!1){if(!e._sortState)return t;const i=e.effectiveConfig?.sortHandler??Z;if(i===Z)return r||(e.__originalOrder=t.slice()),te(t,e._sortState.field,e._sortState.direction,e._columns),t;r||(e.__originalOrder=t);const o=i(t,e._sortState,e._columns);return o&&"function"==typeof o.then?t:o}(this,this._sortState?[...e]:e,!0),r=this.#ge?.processRows(t)??t;this._rows=r,this.#He=!0,this._emitDataChange()}_renderVisibleRows(e,t,r=this.__rowRenderEpoch){if(this.#se||(this.#se=(e,t,r)=>this.#ge?.renderRow(e,t,r)??!1),function(e,t,r,i,o){const n=Math.max(0,r-t),s=e._bodyEl,a=e._visibleColumns,l=a.length;let c=e.__cachedHeaderRowCount;for(void 0===c&&(c=e.querySelector(".header-group-row")?2:1,e.__cachedHeaderRowCount=c);e._rowPool.length<n;){const t=Ye();e._rowPool.push(t)}if(e._rowPool.length>n){const t=e.__frameworkAdapter,r=t?.releaseCell;t?.beginBatch?.(e);try{for(let i=n;i<e._rowPool.length;i++){const o=e._rowPool[i];if(r){const e=o.children;for(let i=0;i<e.length;i++){const o=e[i];o.firstElementChild&&r.call(t,o)}}o.parentNode===s&&o.remove()}e._rowPool.length=n}finally{t?.endBatch?.(e)}}const d=o&&!1!==e.__hasRenderRowPlugins,u=e._hasAfterRowRenderHook?.()??!1,h=e._virtualization?.variableHeights&&"function"==typeof e.effectiveConfig?.rowHeight?e.effectiveConfig.rowHeight:null;for(let f=0;f<n;f++){const r=t+f,n=e._rows[r],p=e._rowPool[f];if(p.setAttribute("aria-rowindex",String(r+c+1)),d&&o(n,p,r)){p.__epoch=i,p.__rowDataRef=n,p.parentNode!==s&&s.appendChild(p);continue}const w=p.__epoch,m=p.__rowDataRef;let b=p.children.length;b>l&&p.lastElementChild?.classList.contains("tbw-row-loading-overlay")&&b--;const y=w===i&&b===l,_=m!==n,C=!!e._isGridEditMode;let R=!1;if(y&&_)for(let e=0;e<l;e++)if(a[e].externalView&&!p.querySelector(`.cell[data-col="${e}"] [data-external-view]`)){R=!0;break}if(!y||R){const t=Ve(p),o=C&&!_||e._activeEditRows===r;t&&!o?(p.__isCustomRow&&(p.className="data-grid-row",p.setAttribute("role","row"),p.__isCustomRow=!1),Ue(p),Ze(e,p,n,r),p.__epoch=i,p.__rowDataRef=n):t&&o?(Ke(e,p,n,r),p.__rowDataRef=n):(p.__isCustomRow&&(p.className="data-grid-row",p.setAttribute("role","row"),p.__isCustomRow=!1),Ze(e,p,n,r),p.__epoch=i,p.__rowDataRef=n)}else if(_){const t=Ve(p),o=e._activeEditRows===r;t&&!o?(Ue(p),Ze(e,p,n,r),p.__epoch=i,p.__rowDataRef=n):(Ke(e,p,n,r),p.__rowDataRef=n)}else{const t=Ve(p),o=C||e._activeEditRows===r;t&&!o?(Ue(p),Ze(e,p,n,r),p.__epoch=i,p.__rowDataRef=n):Ke(e,p,n,r)}let E=!1;const S=e._changedRowIdSet;if(S&&S.size>0)try{const t=e.getRowId?.(n);t&&(E=S.has(t))}catch{}E!==p.classList.contains("changed")&&p.classList.toggle("changed",E);const A=e.effectiveConfig?.rowClass;if(A){const t=p.getAttribute("data-dynamic-classes");if(t){const e=t.split(" ");for(let t=0;t<e.length;t++)e[t]&&p.classList.remove(e[t])}try{const e=A(n),t="string"==typeof e?e.split(/\s+/):e;if(t&&t.length>0){let e="";for(let r=0;r<t.length;r++){const i=t[r];i&&"string"==typeof i&&(p.classList.add(i),e+=(e?" ":"")+i)}p.setAttribute("data-dynamic-classes",e)}else p.removeAttribute("data-dynamic-classes")}catch(g){v("TBW060",`rowClass callback error: ${g}`,e.id),p.removeAttribute("data-dynamic-classes")}}if(h){const e=h(n,r);void 0!==e&&e>0?p.style.setProperty("--tbw-row-height",`${e}px`):p.style.removeProperty("--tbw-row-height")}u&&e._afterRowRender?.({row:n,rowIndex:r,rowElement:p}),p.parentNode!==s&&s.appendChild(p)}}(this,e,t,r,this.#se),this.#Ee.size>0)for(const i of this.#Ee)this.#Ie(i,!0)}#lt={rowCount:-1,colCount:-1,ariaLabel:void 0,ariaLabelledBy:void 0,ariaDescribedBy:void 0,ariaRoleDescription:void 0,lastAnnouncedSourceCount:-1};_updateAriaCounts(e,t){!function(e,t,r,i,o){if(i===e.rowCount&&o===e.colCount)return!1;const n=e.rowCount;e.rowCount=i,e.colCount=o,t&&(t.setAttribute("aria-rowcount",String(i)),t.setAttribute("aria-colcount",String(o))),i!==n&&r&&(i>0?r.setAttribute("role","rowgroup"):r.removeAttribute("role"))}(this.#lt,this.__rowsBodyEl,this._bodyEl,e,t)}_requestSchedulerPhase(e,t){this.#ee.requestPhase(e,t)}_getPluginRowHeight(e,t){return this.#ge?.getRowHeight?.(e,t)}_adjustPluginVirtualStart(e,t,r){return this.#ge?.adjustVirtualStart(e,t,r)}_afterPluginRender(){this.#ge?.afterRender()}_emitPluginEvent(e,t){this.#ge?.emitPluginEvent(e,t)}_schedulerMergeConfig(){this.#K.parseLightDomColumns(this),this.#K.merge(),this.#$e(),function(e,t,r){const i=kt,o=Lt,n=new Map;function s(e,t,r,i,o=!1){n.has(e)||n.set(e,{description:t,importHint:r,fields:[],isConfigProperty:o});const s=n.get(e);s.fields.includes(i)||s.fields.push(i)}const a=e.features;function l(e){return!!a&&!1===a[e]}for(const d of o){const r=e[d.property];if((d.isUsed?d.isUsed(r):void 0!==r)&&!It(t,d.pluginName)&&!l(d.pluginName)){const e=d.description||`the "${d.property}" ${d.level} property`;s(d.pluginName,e,Pt(d.pluginName),d.property,!0)}}const c=e.columns;if(c&&c.length>0)for(const d of c)for(const e of i){const r=d[e.property];if((e.isUsed?e.isUsed(r):void 0!==r)&&!It(t,e.pluginName)&&!l(e.pluginName)){const t=d.field||"<unknown>",r=e.description||`the "${e.property}" ${e.level} property`;s(e.pluginName,r,Pt(e.pluginName),t)}}if(n.size>0){const e=[];for(const[t,{description:r,importHint:i,fields:o,isConfigProperty:s}]of n)if(s)e.push(`Config uses ${r}, but the required plugin is not loaded.\n → Add the plugin to your gridConfig.plugins array:\n ${i}\n plugins: [new ${Dt(t)}Plugin(), ...]`);else{const n=o.slice(0,3).join(", ")+(o.length>3?`, ... (${o.length} total)`:"");e.push(`Column(s) [${n}] use ${r}, but the required plugin is not loaded.\n → Add the plugin to your gridConfig.plugins array:\n ${i}\n plugins: [new ${Dt(t)}Plugin(), ...]`)}b([...n.values()].some(e=>e.isConfigProperty)?"TBW002":"TBW001",`Configuration error:\n\n${e.join("\n\n")}\n\nThis validation helps catch misconfigurations early. The properties listed above require their respective plugins to function.`,r)}}(this.#b,this.#ge?.getPlugins()??[],this.id),function(e,t){const r=[],i=[];for(const o of e){const e=o.constructor.manifest;if(e?.configRules)for(const t of e.configRules){const e=o.config;if(t.check(e)){const e=`[${Dt(o.name)}Plugin] Configuration warning: ${t.message}`;"error"===t.severity?r.push(e):i.push(e)}}}if(i.length>0&&Re())for(const o of i)v("TBW004",o,t);r.length>0&&b("TBW003",`Configuration error:\n\n${r.join("\n\n")}`,t)}(this.#ge?.getPlugins()??[],this.id),function(e,t){if(!Re())return;const r=new Set(e.map(e=>e.name)),i=new Set;for(const o of e){const e=o.constructor.manifest;if(e?.incompatibleWith)for(const n of e.incompatibleWith)if(r.has(n.name)){const e=[o.name,n.name].sort().join("↔");if(i.has(e))continue;i.add(e),v("TBW022",`${Dt(o.name)}Plugin and ${Dt(n.name)}Plugin are both loaded, but they are currently incompatible.\n\n → ${n.reason}\n\n Consider removing one of these plugins to avoid unexpected behavior.`,t)}}}(this.#ge?.getPlugins()??[],this.id),this.#bt(),this.#Te=[...this._columns]}_schedulerProcessColumns(){this.#pt()}_schedulerProcessRows(){this.#mt()}_schedulerRenderHeader(){he(this)}_schedulerUpdateTemplate(){M(this)}_schedulerAfterRender(){this.#ge?.afterRender(),this.#De(),this._virtualization.enabled&&this._virtualization.totalHeightEl&&queueMicrotask(()=>{if(!this._virtualization.totalHeightEl)return;const e=this.#we.calculateTotalSpacerHeight(this._rows.length);this._virtualization.totalHeightEl.style.height=`${e}px`});"fixed"!==this.#b.fitMode||this.__didInitialAutoSize||(this.__didInitialAutoSize=!0,E(this)),this._restoreFocusAfterRender&&(this._restoreFocusAfterRender=!1,qe(this)),this._virtualization.enabled&&!this.#Ke&&this.#st(),this.#oe&&(this.#oe=!1,requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.#it()})})),this.#Re&&this.#Pe()}get _schedulerIsConnected(){return this.isConnected&&this.#Z}get _hostElement(){return this}get _renderRoot(){return this.#j}_emit(e,t){this.#at(e,t)}get _accordionIcons(){return{expand:this.#b?.icons?.expand??o.expand,collapse:this.#b?.icons?.collapse??o.collapse}}_pluginShellContributions(){return{toolPanels:(this.#ge?.getToolPanels()??[]).map(e=>e.panel),headerContents:(this.#ge?.getHeaderContents()??[]).map(e=>e.content)}}_clearRowPool(){const e=this.__frameworkAdapter,t=e?.releaseCell;if(t){e?.beginBatch?.(this);try{for(let r=0;r<this._rowPool.length;r++){const i=this._rowPool[r].children;for(let r=0;r<i.length;r++){const o=i[r];o.firstElementChild&&t.call(e,o)}}this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML="")}finally{e?.endBatch?.(this)}}else this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML="");this.__rowRenderEpoch++}_setup(){this.#Je()}_applyAnimationConfig(e){const t={...i,...e.animation},r=t.mode??"reduced-motion";let o=1;!1===r||"off"===r?o=0:!0!==r&&"on"!==r||(o=1),this.style.setProperty("--tbw-animation-duration",`${t.duration}ms`),this.style.setProperty("--tbw-animation-easing",t.easing??"ease-out"),this.style.setProperty("--tbw-animation-enabled",String(o)),this.dataset.animationMode="boolean"==typeof r?r?"on":"off":r}#bt(){!function(e,t,r){if(!t)return!1;let i=!1;const o=r?.gridAriaLabelledBy,n=o?void 0:function(e){const t=e?.gridAriaLabel;return t||(e?.shell?.header?.title??void 0)}(r);o!==e.ariaLabelledBy&&(e.ariaLabelledBy=o,o?t.setAttribute("aria-labelledby",o):t.removeAttribute("aria-labelledby"),i=!0),n!==e.ariaLabel&&(e.ariaLabel=n,n?t.setAttribute("aria-label",n):t.removeAttribute("aria-label"),i=!0);const s=r?.gridAriaDescribedBy;s!==e.ariaDescribedBy&&(e.ariaDescribedBy=s,s?t.setAttribute("aria-describedby",s):t.removeAttribute("aria-describedby"),i=!0);const a=r?.gridAriaRoleDescription;a!==e.ariaRoleDescription&&(e.ariaRoleDescription=a,a?t.setAttribute("aria-roledescription",a):t.removeAttribute("aria-roledescription"),i=!0)}(this.#lt,this.__rowsBodyEl,this.#b)}#Pe(){const e=this.querySelector(".tbw-grid-root");var t;e&&(this.#Re?(this.#Ae||(this.#Ae=function(e){const t=document.createElement("div");return t.className="tbw-loading-overlay",t.setAttribute("role","status"),t.setAttribute("aria-live","polite"),t.appendChild(at("large",e)),t}(this.#b?.loadingRenderer)),function(e,t){e.appendChild(t)}(e,this.#Ae)):(t=this.#Ae,t?.remove()))}#De(){!function(e,t,r,i,o,n,s){if(!e)return;if(!function(e,t,r){return!(e||t>0||null===r)}(t,r,o))return Ce(s.el),s.el=void 0,s.renderer=void 0,s.target=void 0,s.sourceRows=void 0,void(s.filteredOut=void 0);const a=i.length,l=a>0&&0===r;if(s.el&&s.renderer===o&&s.target===n&&s.sourceRows===i&&s.filteredOut===l)return;const c="grid"===n?e:e.querySelector(".rows-container")??e;Ce(s.el),s.el=_e({sourceRowCount:a,filteredOut:l},o??void 0,n),function(e,t){e.appendChild(t)}(c,s.el),s.renderer=o,s.target=n,s.sourceRows=i,s.filteredOut=l}(this.querySelector(".tbw-grid-root"),this.#Re,this._rows.length,this.#X,this.#b?.emptyRenderer,this.#b?.emptyOverlay??"rows",this.#Me)}#Ie(e,t){this.#ft();const r=this.#xe.get(e);if(!r)return;const i=this.findRenderedRowElement?.(r.index);i&&function(e,t){if(t){if(e.classList.add("tbw-row-loading"),e.setAttribute("aria-busy","true"),!e.querySelector(".tbw-row-loading-overlay")){const t=document.createElement("div");t.className="tbw-row-loading-overlay",t.setAttribute("aria-hidden","true");const r=document.createElement("div");r.className="tbw-row-loading-spinner",t.appendChild(r),e.appendChild(t)}}else e.classList.remove("tbw-row-loading"),e.removeAttribute("aria-busy"),e.querySelector(".tbw-row-loading-overlay")?.remove()}(i,t)}#Oe(e,t,r){this.#ft();const i=this.#xe.get(e);if(!i)return;const o=this.findRenderedRowElement?.(i.index);if(!o)return;const n=this._visibleColumns.findIndex(e=>e.field===t);if(n<0)return;const s=o.children[n];s&&function(e,t){t?(e.classList.add("tbw-cell-loading"),e.setAttribute("aria-busy","true")):(e.classList.remove("tbw-cell-loading"),e.removeAttribute("aria-busy"))}(s,r)}#Je(){if(this.isConnected&&this._headerRowEl&&this._bodyEl){if(this.#K.parseLightDomColumns(this),this.#E){const e=this.#E;this.#E=void 0,this.#K.merge();const t=this.#ge?.getAll()??[];this.#K.applyState(e,t)}this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),this.#ee.requestPhase(fe.FULL,"setup")}}#ot(e){const t=this._virtualization.container,r=this.#_e,i=r?.scrollLeft??0,o=t?.scrollHeight??0,n=r?.scrollWidth??0,s=t?.clientHeight??0,a=r?.clientWidth??0;if(this.refreshVirtualWindow(!1)&&this.#ge?.onScrollRender(),this._virtualization.variableHeights&&(this.#ne&&clearTimeout(this.#ne),this.#ne=window.setTimeout(()=>{this.#ne=0,this.#we.measureRenderedRowHeights(this._virtualization.start,this._virtualization.end)},100)),this.#ie){const t=this.#he;t.scrollTop=e,t.scrollLeft=i,t.scrollHeight=o,t.scrollWidth=n,t.clientHeight=s,t.clientWidth=a,this.#ge?.onScroll(t)}this.#at("tbw-scroll",{scrollTop:e,scrollHeight:o,clientHeight:s,direction:"vertical"})}findHeaderRow(){return this.#j.querySelector(".header-row")}findRenderedRowElement(e){const t=this._virtualization,r=e-t.start;return r>=0&&r<this._rowPool.length&&r<t.end-t.start?this._rowPool[r]:null}_dispatchCellClick(e,t,r,i){const o=this._rows[t],n=this._visibleColumns[r];if(!o||!n)return!1;const s=n.field,a=o[s],l=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,composed:!0,detail:{rowIndex:t,colIndex:r,column:n,field:s,value:a,row:o,cellEl:i,trigger:"pointer",originalEvent:e}});if(this.dispatchEvent(l),l.defaultPrevented)return!0;const c={row:o,rowIndex:t,colIndex:r,column:n,field:s,value:a,cellEl:i,originalEvent:e},d=this.#ge?.onCellClick(c)??!1;return this.#at("cell-click",c),d}_dispatchRowClick(e,t,r,i){if(!r)return!1;const o={rowIndex:t,row:r,rowEl:i,originalEvent:e},n=this.#ge?.onRowClick(o)??!1;return this.#at("row-click",o),n}_dispatchHeaderClick(e,t,r){if(!t)return!1;const i={colIndex:this._columns.indexOf(t),field:t.field,column:t,headerEl:r,originalEvent:e};return this.#ge?.onHeaderClick(i)??!1}_dispatchKeyDown(e){return this.#ge?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,t){return this.#ge?.getHorizontalScrollOffsets(e,t)??{left:0,right:0}}query(e,t){return this.#ge?.queryPlugins({type:e,context:t})??[]}_dispatchCellMouseDown(e){return this.#ge?.onCellMouseDown(e)??!1}_dispatchCellMouseMove(e){this.#ge?.onCellMouseMove(e)}_dispatchCellMouseUp(e){this.#ge?.onCellMouseUp(e)}_afterCellRender(e){this.#ge?.afterCellRender(e)}_hasAfterCellRenderHook(){return this.#ge?.hasAfterCellRenderHook()??!1}_afterRowRender(e){this.#ge?.afterRowRender(e)}_hasAfterRowRenderHook(){return this.#ge?.hasAfterRowRenderHook()??!1}async ready(){return this.#i}async forceLayout(){return 0===this.#ee.pendingPhase&&this.#ee.requestPhase(fe.FULL,"forceLayout"),this.#ee.whenReady()}async getConfig(){return Object.freeze({...this.#b||{}})}getRowId(e){return pt(e,this.id,this.#b.getRowId)}getRow(e){return this.#be.getRow(e)}_getRowEntry(e){return this.#ft(),this.#xe.get(e)}updateRow(e,t,r="api"){this.#be.updateRow(e,t,r)}updateRows(e,t="api"){this.#be.updateRows(e,t)}animateRow(e,t){return gt(this,e,t)}animateRows(e,t){return function(e,t,r){return Promise.all(t.map(t=>gt(e,t,r))).then(e=>e.filter(Boolean).length)}(this,e,t)}animateRowById(e,t){return function(e,t,r){const i=e._rows??[],o=e.getRowId;if(!o)return Promise.resolve(!1);const n=i.findIndex(e=>{if(null==e)return!1;try{return o(e)===t}catch{return!1}});return n<0?Promise.resolve(!1):gt(e,n,r)}(this,e,t)}async insertRow(e,t,r=!0){return this.#be.insertRow(e,t,r)}async removeRow(e,t=!0){return this.#be.removeRow(e,t)}async applyTransaction(e,t=!0){return this.#be.applyTransaction(e,t)}applyTransactionAsync(e){return this.#be.applyTransactionAsync(e)}focusCell(e,t){this.#me.focusCell(e,t)}get focusedCell(){return this.#me.focusedCell}scrollToRow(e,t){this.#me.scrollToRow(e,t)}scrollToRowById(e,t){this.#me.scrollToRowById(e,t)}setColumnVisible(e,t){const r=this.#K.setColumnVisible(e,t);return r&&this.requestStateChange(),r}toggleColumnVisibility(e){const t=this.#K.toggleColumnVisibility(e);return t&&this.requestStateChange(),t}isColumnVisible(e){return this.#K.isColumnVisible(e)}showAllColumns(){this.#K.showAllColumns(),this.requestStateChange()}getAllColumns(){return this.#K.getAllColumns()}setColumnOrder(e){this.#K.setColumnOrder(e),this.requestStateChange()}getColumnOrder(){return this.#K.getColumnOrder()}getColumnState(){const e=this.#ge?.getAll()??[];return this.#K.collectState(e)}get columnState(){return this.getColumnState()}applyColumnState(e){e&&(this.#Y?this.#vt(e):(this.#E=e,this.#K.initialColumnState=e))}#vt(e){const t=this._columns,r=this._sortState,i=this.#ge?.getAll()??[];this.#K.applyState(e,i);if(!e.columns.some(e=>void 0!==e.sort)&&this.#yt(t,r))return this.#ke=void 0,M(this),void this.#ee.requestPhase(fe.STYLE,"column-width");this.#Je()}#yt(e,t){const r=this._columns,i=this._sortState;if(t?.field!==i?.field||t?.direction!==i?.direction)return!1;if(e.length!==r.length)return!1;for(let o=0;o<e.length;o++){const t=e[o],i=r[o];if(t.field!==i.field)return!1;if(!!t.hidden!=!!i.hidden)return!1}return!0}get sortModel(){return this._sortState?{field:this._sortState.field,direction:1===this._sortState.direction?"asc":"desc"}:null}sort(e,t){if(null===e){if(!this._sortState)return;const e=this._sortState.field;this._sortState=null,this.__rowRenderEpoch++;for(let t=0;t<this._rowPool.length;t++)this._rowPool[t].__epoch=-1;return this._rows=this.__originalOrder.slice(),this.__originalOrder=[],he(this),this.refreshVirtualWindow(!0),this.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e,direction:0}})),this._pluginManager?.emitPluginEvent?.("sort-change",{field:e,direction:0}),void this.requestStateChange?.()}const r=this._columns.find(t=>t.field===e);r&&(t?(this._sortState||(this.__originalOrder=this._rows.slice()),se(this,r,"desc"===t?-1:1)):ne(this,r))}requestStateChange(){const e=this.#ge?.getAll()??[];this.#K.requestStateChange(e)}resetColumnState(){this.#E=void 0,this.__originalOrder=[];const e=this.#ge?.getAll()??[];this.#K.resetState(e),this.#K.merge(),this.#Je()}get defaultRowHeight(){return this._virtualization.rowHeight}#_t=!1;refreshShellHeader(){this.#_t||(this.#_t=!0,queueMicrotask(()=>{this.#_t=!1,this.isConnected&&(this.#Ge(),this.#K.markSourcesChanged(),this.#K.merge(),this.#ge?.beforeStructuralRender(),this.#ge?.afterStructuralRender(),this.#Ct())}))}#Ct(){const e=this.#j.querySelector(".tbw-grid-content")??this.#j.querySelector(".tbw-grid-root");this._headerRowEl=e?.querySelector(".header-row"),this._virtualization.totalHeightEl=e?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=e?.querySelector(".rows-viewport"),this._bodyEl=e?.querySelector(".rows"),this.__rowsBodyEl=e?.querySelector(".rows-body"),this._resizeController=lt(this),this.#Ve(e),this.#ee.requestPhase(fe.COLUMNS,"shellRefresh")}#Qe=new Map;registerStyles(e,t){let r=this.#Qe.get(e);r||(r=new CSSStyleSheet,this.#Qe.set(e,r)),r.replaceSync(t),this.#Rt()}unregisterStyles(e){this.#Qe.delete(e)&&this.#Rt()}getRegisteredStyles(){return Array.from(this.#Qe.keys())}#Rt(){const e=Array.from(this.#Qe.values()),t=document.adoptedStyleSheets.filter(e=>!Array.from(this.#Qe.values()).includes(e));document.adoptedStyleSheets=[...t,...e]}registerExternalFocusContainer(e){this.#me.registerExternalFocusContainer(e)}unregisterExternalFocusContainer(e){this.#me.unregisterExternalFocusContainer(e)}containsFocus(e){return this.#me.containsFocus(e)}get lastFocusedElement(){return this.#me.lastFocusedElement}restoreLastFocus(){return this.#me.restoreLastFocus()}#Ge(){this.#ge?.parseLightDom()}#Xe(){const e=()=>{this.#K.clearLightDomCache(),this.#Je()};this.#K.registerLightDomHandler("tbw-grid-column",e),this.#K.registerLightDomHandler("tbw-grid-detail",e),this.#K.registerLightDomHandler("tbw-grid-type",e),this.#K.observeLightDOM(this)}refreshColumns(){this.#K.clearLightDomCache(),Xe(this),this.#K.parseLightDomColumns(this),this.#ge?.syncLightDom(),this.#ee.requestPhase(fe.COLUMNS,"refreshColumns")}#nt(){this.#we.updateCachedGeometry()}refreshVirtualWindow(e=!1,t=!1){return this.#we.refreshVirtualWindow(e,t)}invalidateRowHeight(e,t){this.#we.invalidateRowHeight(e,t)}#je(){this.#Ge(),this.#K.markSourcesChanged(),this.#K.merge(),function(e){const t=[];for(let r=e.firstChild;r;r=r.nextSibling)1===r.nodeType&&r.classList.contains(H.ROOT)||t.push(r);e.replaceChildren();for(const r of t)e.appendChild(r);e.appendChild(ve())}(this.#j),this.#ge?.afterStructuralRender()}}!function(){const e=Nt.tagName,t=customElements.get(e);if(!t)return customElements.define(e,Nt),void(Nt.activeTag=e);if(t.version===Nt.version)return void(Nt.activeTag=e);const r=`${e}-v${Nt.version.replace(/[^a-zA-Z0-9]+/g,"-").toLowerCase()}`;customElements.get(r)||customElements.define(r,Nt),Nt.activeTag=r}(),globalThis.DataGridElement||(globalThis.DataGridElement=Nt);function Ft(e,t,r){return r?.valueAccessor?X(e,r):e?.[t]}function qt(e){return null==e||""===e||"number"==typeof e&&isNaN(e)}const $t={sum:(e,t,r)=>{let i=0;for(let o=0;o<e.length;o++){const n=Ft(e[o],t,r);if(qt(n))continue;const s=Number(n);isNaN(s)||(i+=s)}return i},avg:(e,t,r)=>{if(!e.length)return 0;let i=0,o=0;for(let n=0;n<e.length;n++){const s=Ft(e[n],t,r);if(qt(s))continue;const a=Number(s);isNaN(a)||(i+=a,o++)}return o>0?i/o:0},count:e=>e.length,min:(e,t,r)=>{if(!e.length)return 0;let i=1/0;for(let o=0;o<e.length;o++){const n=Ft(e[o],t,r);if(qt(n))continue;const s=Number(n);isNaN(s)||s<i&&(i=s)}return i===1/0?0:i},max:(e,t,r)=>{if(!e.length)return 0;let i=-1/0;for(let o=0;o<e.length;o++){const n=Ft(e[o],t,r);if(qt(n))continue;const s=Number(n);isNaN(s)||s>i&&(i=s)}return i===-1/0?0:i},first:(e,t,r)=>e[0]?Ft(e[0],t,r):void 0,last:(e,t,r)=>e.length?Ft(e[e.length-1],t,r):void 0},Wt=new Map,Vt={register(e,t){Wt.set(e,t)},unregister(e){Wt.delete(e)},get(e){if(void 0!==e)return"function"==typeof e?e:Wt.get(e)??$t[e]},run(e,t,r,i){const o=this.get(e);return o?o(t,r,i):void 0},has:e=>Wt.has(e)||e in $t,list:()=>[...Object.keys($t),...Wt.keys()]},Ut={sum:e=>{let t=0;for(let r=0;r<e.length;r++)t+=e[r];return t},avg:e=>{if(!e.length)return 0;let t=0;for(let r=0;r<e.length;r++)t+=e[r];return t/e.length},count:e=>e.length,min:e=>{if(!e.length)return 0;let t=e[0];for(let r=1;r<e.length;r++)e[r]<t&&(t=e[r]);return t},max:e=>{if(!e.length)return 0;let t=e[0];for(let r=1;r<e.length;r++)e[r]>t&&(t=e[r]);return t},first:e=>e[0]??0,last:e=>e[e.length-1]??0};function Bt(e){return Ut[e]??Ut.sum}e.BaseGridPlugin=class{static dependencies;static manifest;aliases;version="3.0.0-rc.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#Et;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#Et?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},r={};for(const i of Object.keys(t))r[i]=this;for(const i of e){const e=i.userConfig;for(const[o,n]of Object.entries(e)){if(void 0===n)continue;if(!(o in t)){t[o]=n,r[o]=i;continue}if(t[o]===n)continue;const e=r[o]?.constructor.name??this.constructor.name,s=i.constructor.name,a=m("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${e} and ${s}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const i of Object.keys(t))delete t[i];Object.assign(t,r)}attach(e){this.#Et?.abort(),this.#Et=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#Et?.abort(),this.#Et=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.#Et?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...o,...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=j(t),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const i=this.#St(t,r);void 0!==i?"string"==typeof i?e.innerHTML=$(i):i instanceof HTMLElement&&(e.innerHTML="",e.appendChild(i.cloneNode(!0))):e.innerHTML=""}#St(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 i=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return i?e.insertBefore(r,i):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(m(e,t,this.gridElement.id,this.name)):console.warn(`${h(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(m(e,t,this.gridElement.id,this.name))}},e.CORE_CONSUMED_ADAPTER_METHODS=["canHandle","createRenderer","createEditor","processConfig","getTypeDefault","createToolPanelRenderer","parseDetailElement","parseResponsiveCardElement","releaseCell","unmount","beginBatch","endBatch"],e.ColumnInferenceModeEnum={AUTO:"auto",MERGE:"merge"},e.DEFAULT_A11Y_MESSAGES=r,e.DEFAULT_ANIMATION_CONFIG=i,e.DEFAULT_GRID_ICONS=o,e.DataGridElement=Nt,e.FitModeEnum=t,e.GridCSSVars={COLOR_BG:"--tbw-color-bg",COLOR_FG:"--tbw-color-fg",COLOR_FG_MUTED:"--tbw-color-fg-muted",COLOR_BORDER:"--tbw-color-border",COLOR_ACCENT:"--tbw-color-accent",COLOR_HEADER_BG:"--tbw-color-header-bg",COLOR_HEADER_FG:"--tbw-color-header-fg",COLOR_SELECTION:"--tbw-color-selection",COLOR_ROW_HOVER:"--tbw-color-row-hover",COLOR_ROW_ALT:"--tbw-color-row-alt",ROW_HEIGHT:"--tbw-row-height",HEADER_HEIGHT:"--tbw-header-height",CELL_PADDING:"--tbw-cell-padding",FONT_FAMILY:"--tbw-font-family",FONT_SIZE:"--tbw-font-size",BORDER_RADIUS:"--tbw-border-radius",FOCUS_OUTLINE:"--tbw-focus-outline"},e.GridClasses=H,e.GridDataAttrs=T,e.GridElement=Nt,e.GridSelectors=k,e.MAX_ELEMENT_HEIGHT_PX=De,e.PluginManager=zt,e.RenderPhase=fe,e.aggregatorRegistry=Vt,e.applyColumnDefaults=function(e,t){return t?e.map(e=>({...t,...e})):e},e.builtInSort=Z,e.computeScrollMapping=Ie,e.createGrid=function(e){const t=document.createElement(Nt.activeTag);return e&&(t.gridConfig=e),t},e.defaultComparator=function(e,t){return null==e&&null==t?0:null==e?-1:null==t||e>t?1:e<t?-1:0},e.fromVirtualScrollTop=ze,e.getValueAggregator=Bt,e.hasColumnShorthands=function(e){return e.some(e=>"string"==typeof e)},e.invalidateAccessorCache=K,e.normalizeColumns=u,e.parseColumnShorthand=d,e.queryGrid=function(e,t,r){let i=document,o=!1;return"boolean"==typeof t?o=t:t&&(i=t,o=!!r),o?customElements.whenDefined(Nt.activeTag).then(()=>i.querySelector(e)):i.querySelector(e)},e.resolveCellValue=X,e.runValueAggregator=function(e,t){return Bt(e)(t)},e.setFeatureResolver=function(e){it=e},e.toVirtualScrollTop=Oe,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
2
2
  //# sourceMappingURL=grid.umd.js.map