@toolbox-web/grid 3.8.2 → 3.9.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 (100) hide show
  1. package/all.d.ts +1 -0
  2. package/all.js +1 -1
  3. package/all.js.map +1 -1
  4. package/index.js +1 -1
  5. package/index.js.map +1 -1
  6. package/lib/core/defaults.d.ts +1 -1
  7. package/lib/core/internal/aria.d.ts +1 -1
  8. package/lib/core/internal/config-manager.d.ts +0 -4
  9. package/lib/core/plugin/base-plugin.d.ts +14 -0
  10. package/lib/core/plugin/plugin-manager.d.ts +5 -1
  11. package/lib/core/plugin/types.d.ts +2 -0
  12. package/lib/core/types.d.ts +6 -0
  13. package/lib/features/registry.js +1 -1
  14. package/lib/plugins/clipboard/clipboard-plugin.d.ts +2 -3
  15. package/lib/plugins/clipboard/index.js +1 -1
  16. package/lib/plugins/clipboard/index.js.map +1 -1
  17. package/lib/plugins/column-virtualization/index.js +1 -1
  18. package/lib/plugins/column-virtualization/index.js.map +1 -1
  19. package/lib/plugins/context-menu/index.js +1 -1
  20. package/lib/plugins/context-menu/index.js.map +1 -1
  21. package/lib/plugins/editing/index.js +1 -1
  22. package/lib/plugins/editing/index.js.map +1 -1
  23. package/lib/plugins/export/index.js +1 -1
  24. package/lib/plugins/export/index.js.map +1 -1
  25. package/lib/plugins/filtering/index.js +1 -1
  26. package/lib/plugins/filtering/index.js.map +1 -1
  27. package/lib/plugins/grouping-columns/index.js +1 -1
  28. package/lib/plugins/grouping-columns/index.js.map +1 -1
  29. package/lib/plugins/grouping-rows/grouping-rows-plugin.d.ts +20 -24
  30. package/lib/plugins/grouping-rows/grouping-rows.d.ts +9 -4
  31. package/lib/plugins/grouping-rows/index.d.ts +1 -1
  32. package/lib/plugins/grouping-rows/index.js +1 -1
  33. package/lib/plugins/grouping-rows/index.js.map +1 -1
  34. package/lib/plugins/grouping-rows/types.d.ts +32 -4
  35. package/lib/plugins/hierarchy/hierarchy-plugin.d.ts +79 -0
  36. package/lib/plugins/hierarchy/hierarchy.d.ts +28 -0
  37. package/lib/plugins/hierarchy/index.d.ts +9 -0
  38. package/lib/plugins/hierarchy/index.js +2 -0
  39. package/lib/plugins/hierarchy/index.js.map +1 -0
  40. package/lib/plugins/hierarchy/types.d.ts +92 -0
  41. package/lib/plugins/master-detail/index.js +1 -1
  42. package/lib/plugins/master-detail/index.js.map +1 -1
  43. package/lib/plugins/multi-sort/index.js +1 -1
  44. package/lib/plugins/multi-sort/index.js.map +1 -1
  45. package/lib/plugins/pinned-columns/index.js +1 -1
  46. package/lib/plugins/pinned-columns/index.js.map +1 -1
  47. package/lib/plugins/pinned-rows/index.js +1 -1
  48. package/lib/plugins/pinned-rows/index.js.map +1 -1
  49. package/lib/plugins/pivot/index.js +1 -1
  50. package/lib/plugins/pivot/index.js.map +1 -1
  51. package/lib/plugins/print/index.js +1 -1
  52. package/lib/plugins/print/index.js.map +1 -1
  53. package/lib/plugins/reorder-columns/index.js +1 -1
  54. package/lib/plugins/reorder-columns/index.js.map +1 -1
  55. package/lib/plugins/responsive/index.js +1 -1
  56. package/lib/plugins/responsive/index.js.map +1 -1
  57. package/lib/plugins/row-drag-drop/index.js +1 -1
  58. package/lib/plugins/row-drag-drop/index.js.map +1 -1
  59. package/lib/plugins/row-drag-drop/row-drag-drop-plugin.d.ts +1 -0
  60. package/lib/plugins/row-drag-drop/types.d.ts +3 -2
  61. package/lib/plugins/selection/index.js +1 -1
  62. package/lib/plugins/selection/index.js.map +1 -1
  63. package/lib/plugins/selection/selection-plugin.d.ts +2 -2
  64. package/lib/plugins/server-side/index.js +1 -1
  65. package/lib/plugins/server-side/index.js.map +1 -1
  66. package/lib/plugins/shell/index.js +1 -1
  67. package/lib/plugins/shell/index.js.map +1 -1
  68. package/lib/plugins/sticky-rows/index.js +1 -1
  69. package/lib/plugins/sticky-rows/index.js.map +1 -1
  70. package/lib/plugins/tooltip/index.js +1 -1
  71. package/lib/plugins/tooltip/index.js.map +1 -1
  72. package/lib/plugins/tree/index.js +1 -1
  73. package/lib/plugins/tree/index.js.map +1 -1
  74. package/lib/plugins/tree/tree-datasource.d.ts +7 -10
  75. package/lib/plugins/tree/tree-plugin.d.ts +23 -3
  76. package/lib/plugins/undo-redo/index.js +1 -1
  77. package/lib/plugins/undo-redo/index.js.map +1 -1
  78. package/lib/plugins/visibility/index.js +1 -1
  79. package/lib/plugins/visibility/index.js.map +1 -1
  80. package/package.json +1 -1
  81. package/umd/grid.all.umd.js +1 -1
  82. package/umd/grid.all.umd.js.map +1 -1
  83. package/umd/grid.umd.js +1 -1
  84. package/umd/grid.umd.js.map +1 -1
  85. package/umd/plugins/clipboard.umd.js +1 -1
  86. package/umd/plugins/clipboard.umd.js.map +1 -1
  87. package/umd/plugins/editing.umd.js +1 -1
  88. package/umd/plugins/editing.umd.js.map +1 -1
  89. package/umd/plugins/grouping-rows.umd.js +1 -1
  90. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  91. package/umd/plugins/hierarchy.umd.js +2 -0
  92. package/umd/plugins/hierarchy.umd.js.map +1 -0
  93. package/umd/plugins/row-drag-drop.umd.js +1 -1
  94. package/umd/plugins/row-drag-drop.umd.js.map +1 -1
  95. package/umd/plugins/selection.umd.js +1 -1
  96. package/umd/plugins/selection.umd.js.map +1 -1
  97. package/umd/plugins/tooltip.umd.js +1 -1
  98. package/umd/plugins/tooltip.umd.js.map +1 -1
  99. package/umd/plugins/tree.umd.js +1 -1
  100. package/umd/plugins/tree.umd.js.map +1 -1
@@ -1,2 +1,2 @@
1
- var t=/* @__PURE__ */new WeakMap;function e(t){return"__proto__"===t||"constructor"===t||"prototype"===t}var s=/* @__PURE__ */new Map;function i(t,i){if(null==t)return;const n=function(t){if(-1===t.indexOf("."))return null;let e=s.get(t);return void 0===e&&(e=Object.freeze(t.split(".")),s.set(t,e)),e}(i),r=t;return null===n?e(i)?void 0:r[i]:Object.prototype.hasOwnProperty.call(r,i)?r[i]:function(t,s){let i=t;for(let n=0;n<s.length;n++){if(null==i||"object"!=typeof i)return;const t=s[n];if(e(t))return;i=i[t]}return i}(r,n)}function n(e,s,n=-1){if(!s.valueAccessor)return i(e,s.field);if("object"!=typeof e||null===e)return s.valueAccessor({row:e,column:s,rowIndex:n});const r=e,o=s.field;let c=t.get(r);if(c){const t=c.get(o);if(void 0!==t)return t.v}else c=/* @__PURE__ */new Map,t.set(r,c);const l=s.valueAccessor({row:e,column:s,rowIndex:n});return c.set(o,{v:l}),l}var r={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function o(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function c(t,e,s,i){return`${o(s,i)} ${t}: ${e}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}var l="__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("")),a=(new RegExp(`__(proto|defineGetter|defineSetter)|${l.slice(3).join("|")}|this\\b`),new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing|math".split("|"))),h=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),u=/^\s*(javascript|vbscript|data|blob):/i;function f(t){const e=document.createElement("template");return t&&"string"==typeof t&&(e.innerHTML=t,function(t){const e=[],s=t.querySelectorAll("*");for(const i of s){const t=i.tagName.toLowerCase();if(a.has(t)){e.push(i);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===i.namespaceURI)&&Array.from(i.attributes).some(t=>h.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(i);continue}const s=[];for(const e of i.attributes){const t=e.name.toLowerCase();h.test(t)?s.push(e.name):"is"!==t?(d.has(t)&&u.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&s.push(e.name):s.push(e.name)}s.forEach(t=>i.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content)),e.content}var g=class{static dependencies;static manifest;aliases;version="3.8.2";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}get resolvedConfig(){return this.#t?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(t){if(0===t.length)return;const e={...this.userConfig},s={};for(const i of Object.keys(e))s[i]=this;for(const i of t){const t=i.userConfig;for(const[n,r]of Object.entries(t)){if(void 0===r)continue;if(!(n in e)){e[n]=r,s[n]=i;continue}if(e[n]===r)continue;const t=s[n]?.constructor.name??this.constructor.name,o=i.constructor.name,l=c("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${t} and ${o}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,e)}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)}queryBoolean(t,e=null){const s=this.grid?.query?.(t,e);return Array.isArray(s)?s.some(Boolean):!!s}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{...r,...t}}t(t,e){return this.grid?.effectiveConfig?.locale?.[t]??e}get translate(){return(t,e)=>this.t(t,e)}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;return!e||"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),s=parseInt(e,10);if(!isNaN(s))return s}return 200}setIcon(t,e,s){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const i=this.#e(e,s);var n,r;void 0!==i?"string"==typeof i?(n=t,(r=i)&&"string"==typeof r?-1!==r.indexOf("<")||-1!==r.indexOf("&")?n.replaceChildren(f(r)):n.textContent=r:n.replaceChildren()):i instanceof HTMLElement&&t.replaceChildren(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(t,e){void 0!==e?console.warn(c(t,e,this.gridElement.id,this.name)):console.warn(`${o(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(t,e){throw new Error(c(t,e,this.gridElement.id,this.name))}},p=class extends g{name="stickyRows";styles="@layer tbw-plugins{.tbw-sticky-rows{z-index:var(--tbw-z-layer-sticky-rows,22);background:var(--tbw-color-bg,var(--tbw-color-panel-bg));width:fit-content;min-width:100%;display:block;position:absolute;top:0;left:0;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=[];templateClone=null;lastPushOffset=0;settlePassScheduled=!1;detach(){this.container?.remove(),this.container=null,this.cloneCache.clear(),this.templateClone=null,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)}getVerticalScrollOffsets(t){if(this.container&&0!==this.displayedIndices.length)return null!=t&&this.displayedIndices.includes(t)?{top:0,bottom:0,skipScroll:!0}:{top:this.container.offsetHeight,bottom:0}}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;return s&&s[t]?s[t].offset: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;return e?e.querySelector(`.rows .data-grid-row .cell[data-row="${t}"]`)?.parentElement??null: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.templateClone=s.cloneNode(!0),this.cloneCache.set(t,s),s}synthesizeClone(t){const e=this.templateClone,s=this.rows[t];if(!e||null==s)return null;const i=e.cloneNode(!0),r=Array.from(i.querySelectorAll(".cell"));if(r.some(t=>null!=t.firstElementChild))return null;i.dataset.stickyRow=String(t),i.dataset.syntheticStickyRow="",i.removeAttribute("aria-rowindex");const o=this.visibleColumns;for(const c of r){c.setAttribute("data-row",String(t));const e=c.getAttribute("data-field"),i=e?o.find(t=>t.field===e):void 0,r=i?n(s,i,t):null;c.textContent=null==r?"":String(r)}return i}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);if(this.container.dataset.mode!==this.config.mode&&(this.container.dataset.mode=this.config.mode??"push"),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||(s=this.synthesizeClone(i),s&&this.cloneCache.set(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{p as StickyRowsPlugin};
1
+ var t=/* @__PURE__ */new WeakMap;function e(t){return"__proto__"===t||"constructor"===t||"prototype"===t}var s=/* @__PURE__ */new Map;function i(t,i){if(null==t)return;const n=function(t){if(-1===t.indexOf("."))return null;let e=s.get(t);return void 0===e&&(e=Object.freeze(t.split(".")),s.set(t,e)),e}(i),r=t;return null===n?e(i)?void 0:r[i]:Object.prototype.hasOwnProperty.call(r,i)?r[i]:function(t,s){let i=t;for(let n=0;n<s.length;n++){if(null==i||"object"!=typeof i)return;const t=s[n];if(e(t))return;i=i[t]}return i}(r,n)}function n(e,s,n=-1){if(!s.valueAccessor)return i(e,s.field);if("object"!=typeof e||null===e)return s.valueAccessor({row:e,column:s,rowIndex:n});const r=e,o=s.field;let c=t.get(r);if(c){const t=c.get(o);if(void 0!==t)return t.v}else c=/* @__PURE__ */new Map,t.set(r,c);const l=s.valueAccessor({row:e,column:s,rowIndex:n});return c.set(o,{v:l}),l}var r={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function o(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function c(t,e,s,i){return`${o(s,i)} ${t}: ${e}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}var l="__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("")),a=(new RegExp(`__(proto|defineGetter|defineSetter)|${l.slice(3).join("|")}|this\\b`),new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing|math".split("|"))),h=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),u=/^\s*(javascript|vbscript|data|blob):/i;function f(t){const e=document.createElement("template");return t&&"string"==typeof t&&(e.innerHTML=t,function(t){const e=[],s=t.querySelectorAll("*");for(const i of s){const t=i.tagName.toLowerCase();if(a.has(t)){e.push(i);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===i.namespaceURI)&&Array.from(i.attributes).some(t=>h.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(i);continue}const s=[];for(const e of i.attributes){const t=e.name.toLowerCase();h.test(t)?s.push(e.name):"is"!==t?(d.has(t)&&u.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&s.push(e.name):s.push(e.name)}s.forEach(t=>i.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content)),e.content}var g=class{static dependencies;static manifest;aliases;version="3.9.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}get resolvedConfig(){return this.#t?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(t){if(0===t.length)return;const e={...this.userConfig},s={};for(const i of Object.keys(e))s[i]=this;for(const i of t){const t=i.userConfig;for(const[n,r]of Object.entries(t)){if(void 0===r)continue;if(!(n in e)){e[n]=r,s[n]=i;continue}if(e[n]===r)continue;const t=s[n]?.constructor.name??this.constructor.name,o=i.constructor.name,l=c("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${t} and ${o}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,e)}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)}queryBoolean(t,e=null){const s=this.grid?.query?.(t,e);return Array.isArray(s)?s.some(Boolean):!!s}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{...r,...t}}t(t,e){return this.grid?.effectiveConfig?.locale?.[t]??e}get translate(){return(t,e)=>this.t(t,e)}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;return!e||"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),s=parseInt(e,10);if(!isNaN(s))return s}return 200}setIcon(t,e,s){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const i=this.#e(e,s);var n,r;void 0!==i?"string"==typeof i?(n=t,(r=i)&&"string"==typeof r?-1!==r.indexOf("<")||-1!==r.indexOf("&")?n.replaceChildren(f(r)):n.textContent=r:n.replaceChildren()):i instanceof HTMLElement&&t.replaceChildren(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(t,e){void 0!==e?console.warn(c(t,e,this.gridElement.id,this.name)):console.warn(`${o(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(t,e){throw new Error(c(t,e,this.gridElement.id,this.name))}},p=class extends g{name="stickyRows";styles="@layer tbw-plugins{.tbw-sticky-rows{z-index:var(--tbw-z-layer-sticky-rows,22);background:var(--tbw-color-bg,var(--tbw-color-panel-bg));width:fit-content;min-width:100%;display:block;position:absolute;top:0;left:0;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=[];templateClone=null;lastPushOffset=0;settlePassScheduled=!1;detach(){this.container?.remove(),this.container=null,this.cloneCache.clear(),this.templateClone=null,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)}getVerticalScrollOffsets(t){if(this.container&&0!==this.displayedIndices.length)return null!=t&&this.displayedIndices.includes(t)?{top:0,bottom:0,skipScroll:!0}:{top:this.container.offsetHeight,bottom:0}}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;return s&&s[t]?s[t].offset: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;return e?e.querySelector(`.rows .data-grid-row .cell[data-row="${t}"]`)?.parentElement??null: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.templateClone=s.cloneNode(!0),this.cloneCache.set(t,s),s}synthesizeClone(t){const e=this.templateClone,s=this.rows[t];if(!e||null==s)return null;const i=e.cloneNode(!0),r=Array.from(i.querySelectorAll(".cell"));if(r.some(t=>null!=t.firstElementChild))return null;i.dataset.stickyRow=String(t),i.dataset.syntheticStickyRow="",i.removeAttribute("aria-rowindex");const o=this.visibleColumns;for(const c of r){c.setAttribute("data-row",String(t));const e=c.getAttribute("data-field"),i=e?o.find(t=>t.field===e):void 0,r=i?n(s,i,t):null;c.textContent=null==r?"":String(r)}return i}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);if(this.container.dataset.mode!==this.config.mode&&(this.container.dataset.mode=this.config.mode??"push"),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||(s=this.synthesizeClone(i),s&&this.cloneCache.set(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{p as StickyRowsPlugin};
2
2
  //# sourceMappingURL=index.js.map