@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
@@ -1,2 +1,2 @@
1
- function t(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function e(e,s,i,n){return`${t(i,n)} ${e}: ${s}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(e)}`}const s="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(t=>t.split("").reverse().join(""));new RegExp(`__(proto|defineGetter|defineSetter)|${s.slice(3).join("|")}|this\\b`);const i=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,r=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),o=/^\s*(javascript|vbscript|data|blob):/i;function c(t){if(!t||"string"!=typeof t)return"";if(-1===t.indexOf("<"))return t;const e=document.createElement("template");return e.innerHTML=t,function(t){const e=[],s=t.querySelectorAll("*");for(const c of s){const t=c.tagName.toLowerCase();if(i.has(t)){e.push(c);continue}if("svg"===t||"http://www.w3.org/2000/svg"===c.namespaceURI){if(Array.from(c.attributes).some(t=>n.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(c);continue}}const s=[];for(const e of c.attributes){const t=e.name.toLowerCase();n.test(t)?s.push(e.name):(r.has(t)&&o.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&s.push(e.name)}s.forEach(t=>c.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content),e.innerHTML}const a={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};class l{static dependencies;static manifest;aliases;version="3.0.0-beta.4";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}get resolvedConfig(){return this.#t?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(t){if(0===t.length)return;const s={...this.userConfig},i={};for(const e of Object.keys(s))i[e]=this;for(const n of t){const t=n.userConfig;for(const[r,o]of Object.entries(t)){if(void 0===o)continue;if(!(r in s)){s[r]=o,i[r]=n;continue}if(s[r]===o)continue;const t=i[r]?.constructor.name??this.constructor.name,c=n.constructor.name,a=e("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${r}" supplied by both ${t} and ${c}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,s)}refreshUserConfigFrom(t){const e=this.userConfig,s={...t.userConfig};for(const i of Object.keys(e))delete e[i];Object.assign(e,s)}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const s=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(s),s.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...a,...t}}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;if(e){return"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),s=parseInt(e,10);if(!isNaN(s))return s}return 200}setIcon(t,e,s){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const i=this.#e(e,s);void 0!==i?"string"==typeof i?t.innerHTML=c(i):i instanceof HTMLElement&&(t.innerHTML="",t.appendChild(i.cloneNode(!0))):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const s=document.createElement("span");s.setAttribute("part","sort-indicator"),s.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(s,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(s,"sortNone"));const i=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return i?t.insertBefore(s,i):t.appendChild(s),s}warn(s,i){void 0!==i?console.warn(e(s,i,this.gridElement.id,this.name)):console.warn(`${t(this.gridElement.id,this.name)} ${s}`)}throwDiagnostic(t,s){throw new Error(e(t,s,this.gridElement.id,this.name))}}class h extends l{name="stickyRows";styles="@layer tbw-plugins{.tbw-sticky-rows{position:absolute;top:0;left:0;display:block;z-index:var(--tbw-z-layer-sticky-rows, 22);background:var(--tbw-color-bg, var(--tbw-color-panel-bg));min-width:100%;width:fit-content;overflow:visible}.tbw-sticky-rows:empty{display:none}.tbw-sticky-rows .tbw-sticky-row{box-shadow:0 1px 0 var(--tbw-color-border);background:var(--tbw-color-bg, var(--tbw-color-panel-bg))}.tbw-sticky-rows[data-mode=push] .tbw-sticky-row{will-change:transform}}";get defaultConfig(){return{mode:"push",maxStacked:1/0}}container=null;stickyIndices=[];cloneCache=/* @__PURE__ */new Map;displayedIndices=[];lastPushOffset=0;settlePassScheduled=!1;detach(){this.container?.remove(),this.container=null,this.cloneCache.clear(),this.stickyIndices=[],this.displayedIndices=[],this.lastPushOffset=0,this.settlePassScheduled=!1}afterRender(){this.settlePassScheduled=!1,this.recomputeStickyIndices(),this.ensureContainer(),this.primeCloneCache(),this.refreshClonesInWindow(),this.refreshDisplay()}onScrollRender(){this.primeCloneCache(),this.refreshDisplay(),this.maybeScheduleSettlePass()}onScroll(t){this.refreshDisplay(t.scrollTop)}maybeScheduleSettlePass(){this.settlePassScheduled||this.stickyIndices.some(t=>null!=this.findRenderedRow(t))&&(this.settlePassScheduled=!0,this.requestAfterRender())}resolvePredicate(){const t=this.config.isSticky;if("function"==typeof t)return t;if("string"==typeof t){const e=t;return t=>null!=t&&"object"==typeof t&&Boolean(t[e])}return()=>!1}recomputeStickyIndices(){const t=this.rows,e=this.resolvePredicate(),s=[];for(let i=0;i<t.length;i++)e(t[i],i)&&s.push(i);(s.length!==this.stickyIndices.length||s.some((t,e)=>t!==this.stickyIndices[e]))&&this.cloneCache.clear(),this.stickyIndices=s}ensureContainer(){const t=this.gridElement;if(!t)return;const e=t.querySelector(".rows-viewport");e?this.container&&e.contains(this.container)||(this.container=document.createElement("div"),this.container.className="tbw-sticky-rows",this.container.setAttribute("role","presentation"),this.container.dataset.mode=this.config.mode??"push",this.config.className&&this.container.classList.add(this.config.className),e.insertBefore(this.container,e.firstChild)):this.container=null}offsetOf(t){const e=this.getVirtualState(),s=e?.positionCache;if(s&&s[t])return s[t].offset;return t*(e?.rowHeight??28)}heightOf(t){const e=this.getVirtualState(),s=e?.positionCache;return s&&s[t]?s[t].height:e?.rowHeight??28}getVirtualState(){return this.grid?._virtualization}getCurrentScrollTop(){const t=this.getVirtualState(),e=t?.container?.scrollTop;return"number"==typeof e?e:"number"!=typeof t?.start||"number"!=typeof t?.rowHeight||t.positionCache&&t.positionCache.length?t?.positionCache&&"number"==typeof t.start&&t.positionCache[t.start]?t.positionCache[t.start].offset:0:t.start*t.rowHeight}computeDisplay(t){if("stack"===this.config.mode){const e=this.config.maxStacked??1/0,s=[];let i=0;for(const n of this.stickyIndices)if(s.length<e){if(!(this.offsetOf(n)<t+i))break;s.push(n),i+=this.heightOf(n)}else{const e=this.heightOf(s[0]);if(!(this.offsetOf(n)<t+i-e))break;s.shift(),i-=e,s.push(n),i+=this.heightOf(n)}if(s.length===e&&s.length>0){const e=this.findNextSticky(s[s.length-1]);if(null!=e){const n=this.offsetOf(e)-(t+i);if(n<0){const t=this.heightOf(s[0]);return{indices:s,pushOffset:Math.min(-n,t)}}}}return{indices:s,pushOffset:0}}const e=[];for(const r of this.stickyIndices){if(!(this.offsetOf(r)<t))break;e.push(r)}if(0===e.length)return{indices:e,pushOffset:0};const s=e[e.length-1],i=this.findNextSticky(s);let n=0;if(null!=i){const e=this.heightOf(s),r=this.offsetOf(i)-t;r<e&&(n=e-Math.max(0,r))}return{indices:[s],pushOffset:n}}findRenderedRow(t){const e=this.gridElement;if(!e)return null;const s=e.querySelector(`.rows .data-grid-row .cell[data-row="${t}"]`);return s?.parentElement??null}buildClone(t){const e=this.findRenderedRow(t);if(!e)return this.cloneCache.get(t)??null;const s=e.cloneNode(!0);return s.classList.add("tbw-sticky-row"),s.removeAttribute("aria-rowindex"),s.setAttribute("aria-hidden","true"),s.dataset.stickyRow=String(t),s.classList.remove("row-focus","cell-focus"),s.querySelectorAll(".cell-focus, .row-focus").forEach(t=>t.classList.remove("cell-focus","row-focus")),s.removeAttribute("tabindex"),s.querySelectorAll("[tabindex]").forEach(t=>t.removeAttribute("tabindex")),this.cloneCache.set(t,s),s}refreshClonesInWindow(){if(this.displayedIndices.length)for(const t of this.displayedIndices){if(this.findRenderedRow(t)){const e=this.buildClone(t),s=this.container?.querySelector(`[data-sticky-row="${t}"]`);e&&s&&s!==e&&s.replaceWith(e)}}}primeCloneCache(){if(this.stickyIndices.length)for(const t of this.stickyIndices)this.findRenderedRow(t)&&this.buildClone(t)}refreshDisplay(t){if(!this.container)return;const e=t??this.getCurrentScrollTop(),{indices:s,pushOffset:i}=this.computeDisplay(e);this.container.dataset.mode!==this.config.mode&&(this.container.dataset.mode=this.config.mode??"push");if(!(s.length===this.displayedIndices.length&&s.every((t,e)=>t===this.displayedIndices[e]))){const t=document.createDocumentFragment(),e=[];for(const i of s){let s=this.cloneCache.get(i)??null;s=this.buildClone(i)??s,s&&(t.appendChild(s),e.push(i))}this.container.replaceChildren(t),this.displayedIndices=e}i!==this.lastPushOffset&&(this.container.style.transform=i>0?`translateY(${-i}px)`:"",this.lastPushOffset=i)}findNextSticky(t){for(const e of this.stickyIndices)if(e>t)return e;return null}}export{h as StickyRowsPlugin};
1
+ function t(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function e(e,s,i,n){return`${t(i,n)} ${e}: ${s}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(e)}`}const s="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(t=>t.split("").reverse().join(""));new RegExp(`__(proto|defineGetter|defineSetter)|${s.slice(3).join("|")}|this\\b`);const i=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,r=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),o=/^\s*(javascript|vbscript|data|blob):/i;function c(t){if(!t||"string"!=typeof t)return"";if(-1===t.indexOf("<"))return t;const e=document.createElement("template");return e.innerHTML=t,function(t){const e=[],s=t.querySelectorAll("*");for(const c of s){const t=c.tagName.toLowerCase();if(i.has(t)){e.push(c);continue}if("svg"===t||"http://www.w3.org/2000/svg"===c.namespaceURI){if(Array.from(c.attributes).some(t=>n.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(c);continue}}const s=[];for(const e of c.attributes){const t=e.name.toLowerCase();n.test(t)?s.push(e.name):(r.has(t)&&o.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&s.push(e.name)}s.forEach(t=>c.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content),e.innerHTML}const a={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};class l{static dependencies;static manifest;aliases;version="3.0.0-rc.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}get resolvedConfig(){return this.#t?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(t){if(0===t.length)return;const s={...this.userConfig},i={};for(const e of Object.keys(s))i[e]=this;for(const n of t){const t=n.userConfig;for(const[r,o]of Object.entries(t)){if(void 0===o)continue;if(!(r in s)){s[r]=o,i[r]=n;continue}if(s[r]===o)continue;const t=i[r]?.constructor.name??this.constructor.name,c=n.constructor.name,a=e("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${r}" supplied by both ${t} and ${c}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,s)}refreshUserConfigFrom(t){const e=this.userConfig,s={...t.userConfig};for(const i of Object.keys(e))delete e[i];Object.assign(e,s)}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const s=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(s),s.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...a,...t}}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;if(e){return"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),s=parseInt(e,10);if(!isNaN(s))return s}return 200}setIcon(t,e,s){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const i=this.#e(e,s);void 0!==i?"string"==typeof i?t.innerHTML=c(i):i instanceof HTMLElement&&(t.innerHTML="",t.appendChild(i.cloneNode(!0))):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const s=document.createElement("span");s.setAttribute("part","sort-indicator"),s.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(s,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(s,"sortNone"));const i=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return i?t.insertBefore(s,i):t.appendChild(s),s}warn(s,i){void 0!==i?console.warn(e(s,i,this.gridElement.id,this.name)):console.warn(`${t(this.gridElement.id,this.name)} ${s}`)}throwDiagnostic(t,s){throw new Error(e(t,s,this.gridElement.id,this.name))}}class h extends l{name="stickyRows";styles="@layer tbw-plugins{.tbw-sticky-rows{position:absolute;top:0;left:0;display:block;z-index:var(--tbw-z-layer-sticky-rows, 22);background:var(--tbw-color-bg, var(--tbw-color-panel-bg));min-width:100%;width:fit-content;overflow:visible}.tbw-sticky-rows:empty{display:none}.tbw-sticky-rows .tbw-sticky-row{box-shadow:0 1px 0 var(--tbw-color-border);background:var(--tbw-color-bg, var(--tbw-color-panel-bg))}.tbw-sticky-rows[data-mode=push] .tbw-sticky-row{will-change:transform}}";get defaultConfig(){return{mode:"push",maxStacked:1/0}}container=null;stickyIndices=[];cloneCache=/* @__PURE__ */new Map;displayedIndices=[];lastPushOffset=0;settlePassScheduled=!1;detach(){this.container?.remove(),this.container=null,this.cloneCache.clear(),this.stickyIndices=[],this.displayedIndices=[],this.lastPushOffset=0,this.settlePassScheduled=!1}afterRender(){this.settlePassScheduled=!1,this.recomputeStickyIndices(),this.ensureContainer(),this.primeCloneCache(),this.refreshClonesInWindow(),this.refreshDisplay()}onScrollRender(){this.primeCloneCache(),this.refreshDisplay(),this.maybeScheduleSettlePass()}onScroll(t){this.refreshDisplay(t.scrollTop)}maybeScheduleSettlePass(){this.settlePassScheduled||this.stickyIndices.some(t=>null!=this.findRenderedRow(t))&&(this.settlePassScheduled=!0,this.requestAfterRender())}resolvePredicate(){const t=this.config.isSticky;if("function"==typeof t)return t;if("string"==typeof t){const e=t;return t=>null!=t&&"object"==typeof t&&Boolean(t[e])}return()=>!1}recomputeStickyIndices(){const t=this.rows,e=this.resolvePredicate(),s=[];for(let i=0;i<t.length;i++)e(t[i],i)&&s.push(i);(s.length!==this.stickyIndices.length||s.some((t,e)=>t!==this.stickyIndices[e]))&&this.cloneCache.clear(),this.stickyIndices=s}ensureContainer(){const t=this.gridElement;if(!t)return;const e=t.querySelector(".rows-viewport");e?this.container&&e.contains(this.container)||(this.container=document.createElement("div"),this.container.className="tbw-sticky-rows",this.container.setAttribute("role","presentation"),this.container.dataset.mode=this.config.mode??"push",this.config.className&&this.container.classList.add(this.config.className),e.insertBefore(this.container,e.firstChild)):this.container=null}offsetOf(t){const e=this.getVirtualState(),s=e?.positionCache;if(s&&s[t])return s[t].offset;return t*(e?.rowHeight??28)}heightOf(t){const e=this.getVirtualState(),s=e?.positionCache;return s&&s[t]?s[t].height:e?.rowHeight??28}getVirtualState(){return this.grid?._virtualization}getCurrentScrollTop(){const t=this.getVirtualState(),e=t?.container?.scrollTop;return"number"==typeof e?e:"number"!=typeof t?.start||"number"!=typeof t?.rowHeight||t.positionCache&&t.positionCache.length?t?.positionCache&&"number"==typeof t.start&&t.positionCache[t.start]?t.positionCache[t.start].offset:0:t.start*t.rowHeight}computeDisplay(t){if("stack"===this.config.mode){const e=this.config.maxStacked??1/0,s=[];let i=0;for(const n of this.stickyIndices)if(s.length<e){if(!(this.offsetOf(n)<t+i))break;s.push(n),i+=this.heightOf(n)}else{const e=this.heightOf(s[0]);if(!(this.offsetOf(n)<t+i-e))break;s.shift(),i-=e,s.push(n),i+=this.heightOf(n)}if(s.length===e&&s.length>0){const e=this.findNextSticky(s[s.length-1]);if(null!=e){const n=this.offsetOf(e)-(t+i);if(n<0){const t=this.heightOf(s[0]);return{indices:s,pushOffset:Math.min(-n,t)}}}}return{indices:s,pushOffset:0}}const e=[];for(const r of this.stickyIndices){if(!(this.offsetOf(r)<t))break;e.push(r)}if(0===e.length)return{indices:e,pushOffset:0};const s=e[e.length-1],i=this.findNextSticky(s);let n=0;if(null!=i){const e=this.heightOf(s),r=this.offsetOf(i)-t;r<e&&(n=e-Math.max(0,r))}return{indices:[s],pushOffset:n}}findRenderedRow(t){const e=this.gridElement;if(!e)return null;const s=e.querySelector(`.rows .data-grid-row .cell[data-row="${t}"]`);return s?.parentElement??null}buildClone(t){const e=this.findRenderedRow(t);if(!e)return this.cloneCache.get(t)??null;const s=e.cloneNode(!0);return s.classList.add("tbw-sticky-row"),s.removeAttribute("aria-rowindex"),s.setAttribute("aria-hidden","true"),s.dataset.stickyRow=String(t),s.classList.remove("row-focus","cell-focus"),s.querySelectorAll(".cell-focus, .row-focus").forEach(t=>t.classList.remove("cell-focus","row-focus")),s.removeAttribute("tabindex"),s.querySelectorAll("[tabindex]").forEach(t=>t.removeAttribute("tabindex")),this.cloneCache.set(t,s),s}refreshClonesInWindow(){if(this.displayedIndices.length)for(const t of this.displayedIndices){if(this.findRenderedRow(t)){const e=this.buildClone(t),s=this.container?.querySelector(`[data-sticky-row="${t}"]`);e&&s&&s!==e&&s.replaceWith(e)}}}primeCloneCache(){if(this.stickyIndices.length)for(const t of this.stickyIndices)this.findRenderedRow(t)&&this.buildClone(t)}refreshDisplay(t){if(!this.container)return;const e=t??this.getCurrentScrollTop(),{indices:s,pushOffset:i}=this.computeDisplay(e);this.container.dataset.mode!==this.config.mode&&(this.container.dataset.mode=this.config.mode??"push");if(!(s.length===this.displayedIndices.length&&s.every((t,e)=>t===this.displayedIndices[e]))){const t=document.createDocumentFragment(),e=[];for(const i of s){let s=this.cloneCache.get(i)??null;s=this.buildClone(i)??s,s&&(t.appendChild(s),e.push(i))}this.container.replaceChildren(t),this.displayedIndices=e}i!==this.lastPushOffset&&(this.container.style.transform=i>0?`translateY(${-i}px)`:"",this.lastPushOffset=i)}findNextSticky(t){for(const e of this.stickyIndices)if(e>t)return e;return null}}export{h as StickyRowsPlugin};
2
2
  //# sourceMappingURL=index.js.map