@toolbox-web/grid 2.17.1 → 2.17.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/all.js +1 -1
  2. package/all.js.map +1 -1
  3. package/index.js +1 -1
  4. package/lib/features/registry.js +1 -1
  5. package/lib/plugins/clipboard/index.js +1 -1
  6. package/lib/plugins/column-virtualization/index.js +1 -1
  7. package/lib/plugins/context-menu/index.js +1 -1
  8. package/lib/plugins/editing/index.js +1 -1
  9. package/lib/plugins/export/index.js +1 -1
  10. package/lib/plugins/filtering/index.js +1 -1
  11. package/lib/plugins/grouping-columns/index.js +1 -1
  12. package/lib/plugins/grouping-rows/index.js +1 -1
  13. package/lib/plugins/master-detail/index.js +1 -1
  14. package/lib/plugins/multi-sort/index.js +1 -1
  15. package/lib/plugins/pinned-columns/index.js +1 -1
  16. package/lib/plugins/pinned-rows/index.js +1 -1
  17. package/lib/plugins/pivot/index.js +1 -1
  18. package/lib/plugins/print/index.js +1 -1
  19. package/lib/plugins/reorder-columns/index.js +1 -1
  20. package/lib/plugins/reorder-rows/index.js +1 -1
  21. package/lib/plugins/responsive/index.js +1 -1
  22. package/lib/plugins/row-drag-drop/index.js +1 -1
  23. package/lib/plugins/selection/index.js +1 -1
  24. package/lib/plugins/server-side/index.js +1 -1
  25. package/lib/plugins/shell/index.js +1 -1
  26. package/lib/plugins/sticky-rows/StickyRowsPlugin.d.ts +23 -0
  27. package/lib/plugins/sticky-rows/index.js +1 -1
  28. package/lib/plugins/sticky-rows/index.js.map +1 -1
  29. package/lib/plugins/tooltip/index.js +1 -1
  30. package/lib/plugins/tree/index.js +1 -1
  31. package/lib/plugins/undo-redo/index.js +1 -1
  32. package/lib/plugins/visibility/index.js +1 -1
  33. package/package.json +1 -1
  34. package/umd/grid.all.umd.js +1 -1
  35. package/umd/grid.all.umd.js.map +1 -1
  36. package/umd/grid.umd.js +1 -1
  37. package/umd/plugins/sticky-rows.umd.js +1 -1
  38. package/umd/plugins/sticky-rows.umd.js.map +1 -1
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("../../core/plugin/base-plugin")):"function"==typeof define&&define.amd?define(["exports","../../core/plugin/base-plugin"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TbwGridPlugin_stickyRows={},t.TbwGrid)}(this,function(t,e){"use strict";class i extends e.BaseGridPlugin{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=new Map;displayedIndices=[];lastPushOffset=0;detach(){this.container?.remove(),this.container=null,this.cloneCache.clear(),this.stickyIndices=[],this.displayedIndices=[],this.lastPushOffset=0}afterRender(){this.recomputeStickyIndices(),this.ensureContainer(),this.primeCloneCache(),this.refreshDisplay()}onScrollRender(){this.primeCloneCache(),this.refreshClonesInWindow(),this.refreshDisplay()}onScroll(t){this.refreshDisplay(t.scrollTop)}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(),i=[];for(let s=0;s<t.length;s++)e(t[s],s)&&i.push(s);(i.length!==this.stickyIndices.length||i.some((t,e)=>t!==this.stickyIndices[e]))&&this.cloneCache.clear(),this.stickyIndices=i}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(),i=e?.positionCache;if(i&&i[t])return i[t].offset;return t*(e?.rowHeight??28)}heightOf(t){const e=this.getVirtualState(),i=e?.positionCache;return i&&i[t]?i[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,i=[];let s=0;for(const n of this.stickyIndices)if(i.length<e){if(!(this.offsetOf(n)<t+s))break;i.push(n),s+=this.heightOf(n)}else{const e=this.heightOf(i[0]);if(!(this.offsetOf(n)<t+s-e))break;i.shift(),s-=e,i.push(n),s+=this.heightOf(n)}if(i.length===e&&i.length>0){const e=this.findNextSticky(i[i.length-1]);if(null!=e){const n=this.offsetOf(e)-(t+s);if(n<0){const t=this.heightOf(i[0]);return{indices:i,pushOffset:Math.min(-n,t)}}}}return{indices:i,pushOffset:0}}const e=[];for(const o of this.stickyIndices){if(!(this.offsetOf(o)<t))break;e.push(o)}if(0===e.length)return{indices:e,pushOffset:0};const i=e[e.length-1],s=this.findNextSticky(i);let n=0;if(null!=s){const e=this.heightOf(i),o=this.offsetOf(s)-t;o<e&&(n=e-Math.max(0,o))}return{indices:[i],pushOffset:n}}findRenderedRow(t){const e=this.gridElement;if(!e)return null;const i=e.querySelector(`.rows .data-grid-row .cell[data-row="${t}"]`);return i?.parentElement??null}buildClone(t){const e=this.findRenderedRow(t);if(!e)return this.cloneCache.get(t)??null;const i=e.cloneNode(!0);return i.classList.add("tbw-sticky-row"),i.removeAttribute("aria-rowindex"),i.setAttribute("aria-hidden","true"),i.dataset.stickyRow=String(t),i.classList.remove("row-focus","cell-focus"),i.querySelectorAll(".cell-focus, .row-focus").forEach(t=>t.classList.remove("cell-focus","row-focus")),i.removeAttribute("tabindex"),i.querySelectorAll("[tabindex]").forEach(t=>t.removeAttribute("tabindex")),this.cloneCache.set(t,i),i}refreshClonesInWindow(){if(this.displayedIndices.length)for(const t of this.displayedIndices){if(this.findRenderedRow(t)){const e=this.buildClone(t),i=this.container?.querySelector(`[data-sticky-row="${t}"]`);e&&i&&i!==e&&i.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:i,pushOffset:s}=this.computeDisplay(e);this.container.dataset.mode!==this.config.mode&&(this.container.dataset.mode=this.config.mode??"push");if(!(i.length===this.displayedIndices.length&&i.every((t,e)=>t===this.displayedIndices[e]))){const t=document.createDocumentFragment(),e=[];for(const s of i){let i=this.cloneCache.get(s)??null;i=this.buildClone(s)??i,i&&(t.appendChild(i),e.push(s))}this.container.replaceChildren(t),this.displayedIndices=e}s!==this.lastPushOffset&&(this.container.style.transform=s>0?`translateY(${-s}px)`:"",this.lastPushOffset=s)}findNextSticky(t){for(const e of this.stickyIndices)if(e>t)return e;return null}}t.StickyRowsPlugin=i,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("../../core/plugin/base-plugin")):"function"==typeof define&&define.amd?define(["exports","../../core/plugin/base-plugin"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TbwGridPlugin_stickyRows={},t.TbwGrid)}(this,function(t,e){"use strict";class s extends e.BaseGridPlugin{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=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.refreshDisplay()}onScrollRender(){this.primeCloneCache(),this.refreshClonesInWindow(),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 o of this.stickyIndices){if(!(this.offsetOf(o)<t))break;e.push(o)}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),o=this.offsetOf(i)-t;o<e&&(n=e-Math.max(0,o))}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}}t.StickyRowsPlugin=s,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
2
2
  //# sourceMappingURL=sticky-rows.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sticky-rows.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/sticky-rows/StickyRowsPlugin.ts"],"sourcesContent":["/**\n * Sticky Rows Plugin (Class-based)\n *\n * Pins selected data rows below the header as the user scrolls past them.\n * See `types.ts` for configuration.\n *\n * @module Plugins/Sticky Rows\n */\n\nimport type { RowPosition } from '../../core/internal/virtualization';\nimport { BaseGridPlugin } from '../../core/plugin/base-plugin';\nimport type { ScrollEvent } from '../../core/plugin/types';\nimport styles from './sticky-rows.css?inline';\nimport type { StickyPredicate, StickyRowsConfig } from './types';\n\n/** Internal shape of the virtualization state we read from the grid. */\ninterface VirtualStateLike {\n start?: number;\n end?: number;\n rowHeight?: number;\n positionCache?: RowPosition[] | null;\n /** The faux-scroll element — the source of truth for the live scroll\n * position (per-pixel, unlike `start` which only updates when the\n * rendered window shifts). */\n container?: HTMLElement | null;\n}\n\n/**\n * Sticky Rows plugin for `<tbw-grid>`.\n *\n * Marks specific rows as \"sticky\" so they pin below the grid header when their\n * natural scroll position would take them off-screen. Behavior when multiple\n * sticky rows would be stuck simultaneously is controlled by `mode`:\n *\n * - `'push'` (default) — only one stuck at a time; the next sticky row pushes\n * the previous one out of view (iOS section-header behavior).\n * - `'stack'` — sticky rows stack below the header up to `maxStacked`.\n *\n * The plugin renders **clones** of the real rows; the originals continue to\n * exist in the data flow. Clones inherit the row's grid-template alignment so\n * they line up perfectly with the column boundaries below.\n *\n * @example\n * ```ts\n * import '@toolbox-web/grid/features/sticky-rows';\n *\n * grid.gridConfig = {\n * features: { stickyRows: { isSticky: 'isSection', mode: 'stack' } },\n * };\n * ```\n *\n * @see {@link StickyRowsConfig} for all configuration options.\n *\n * @internal Extends BaseGridPlugin.\n * @since 2.7.0\n */\nexport class StickyRowsPlugin extends BaseGridPlugin<StickyRowsConfig> {\n /** @internal */\n readonly name = 'stickyRows';\n /** @internal */\n override readonly styles = styles;\n\n /** @internal */\n protected override get defaultConfig(): Partial<StickyRowsConfig> {\n return {\n mode: 'push',\n maxStacked: Infinity,\n };\n }\n\n // #region Internal State\n /** Container element that holds the stuck-row clones. */\n private container: HTMLElement | null = null;\n\n /** Indices in `grid.rows` whose rows are sticky, sorted ascending. */\n private stickyIndices: number[] = [];\n\n /** Cached clone DOM keyed by row index. Survives the row leaving the\n * virtualization window so we can keep showing it while stuck. */\n private cloneCache: Map<number, HTMLElement> = new Map();\n\n /** Currently displayed indices (in DOM order). Used to skip work when the\n * set hasn't changed between scroll ticks. */\n private displayedIndices: number[] = [];\n\n /** Last applied push-mode translation, to skip writes on no-op ticks. */\n private lastPushOffset = 0;\n // #endregion\n\n // #region Lifecycle\n /** @internal */\n override detach(): void {\n this.container?.remove();\n this.container = null;\n this.cloneCache.clear();\n this.stickyIndices = [];\n this.displayedIndices = [];\n this.lastPushOffset = 0;\n }\n // #endregion\n\n // #region Hooks\n\n /** @internal Recompute the sticky-index list and refresh display. */\n override afterRender(): void {\n this.recomputeStickyIndices();\n this.ensureContainer();\n // Pre-cache clones for any sticky row currently in the rendered window\n // BEFORE it scrolls out — otherwise findRenderedRow() returns null at\n // display time and we'd render an empty container.\n this.primeCloneCache();\n this.refreshDisplay();\n }\n\n /** @internal Re-render clones after a scroll-driven row pool refresh. */\n override onScrollRender(): void {\n // The pool may have repopulated rows we're tracking. Refresh clone DOM\n // for any displayed indices that are now back in the rendered window,\n // and pre-cache any sticky rows that just entered the window so we have\n // a clone ready when they scroll past.\n this.primeCloneCache();\n this.refreshClonesInWindow();\n this.refreshDisplay();\n }\n\n /** @internal Update which clones show / how they're positioned. */\n override onScroll(event: ScrollEvent): void {\n this.refreshDisplay(event.scrollTop);\n }\n\n // #endregion\n\n // #region Private — predicate + indices\n\n private resolvePredicate(): StickyPredicate {\n const cfg = this.config.isSticky;\n if (typeof cfg === 'function') return cfg;\n if (typeof cfg === 'string') {\n const field = cfg;\n return (row) => {\n if (row == null || typeof row !== 'object') return false;\n return Boolean((row as Record<string, unknown>)[field]);\n };\n }\n return () => false;\n }\n\n private recomputeStickyIndices(): void {\n const rows = this.rows;\n const predicate = this.resolvePredicate();\n const next: number[] = [];\n for (let i = 0; i < rows.length; i++) {\n if (predicate(rows[i], i)) next.push(i);\n }\n // Drop cache entries whose indices are no longer sticky (e.g. data\n // shuffled, predicate flipped). Indices that remain may still point at a\n // different row after re-sort — drop those too so we re-clone from the\n // fresh DOM on the next render.\n if (next.length !== this.stickyIndices.length || next.some((v, i) => v !== this.stickyIndices[i])) {\n this.cloneCache.clear();\n }\n this.stickyIndices = next;\n }\n\n // #endregion\n\n // #region Private — DOM container\n\n private ensureContainer(): void {\n const grid = this.gridElement;\n if (!grid) return;\n\n // Container is an OVERLAY positioned at the top of the rows-viewport\n // (not a flex child of rows-body). Why: a flow-positioned container\n // takes vertical space, which pushes the rows-viewport down by the\n // sticky height. The rows are positioned in scroll coordinates that\n // are agnostic of that shift, so live-row geometry ends up partially\n // overlapping the sticky container — producing duplicate visible rows\n // during the push transition (#279 follow-up). Overlaying on top of\n // the row pool, with `overflow: clip` on rows-viewport hiding the\n // live row underneath, eliminates the overlap entirely.\n const rowsViewport = grid.querySelector('.rows-viewport');\n if (!rowsViewport) {\n // Grid hasn't built its DOM yet; bail and try again on next afterRender.\n this.container = null;\n return;\n }\n\n if (this.container && rowsViewport.contains(this.container)) return;\n\n // Container was either never created or got wiped out. Re-create.\n this.container = document.createElement('div');\n this.container.className = 'tbw-sticky-rows';\n this.container.setAttribute('role', 'presentation');\n this.container.dataset['mode'] = this.config.mode ?? 'push';\n if (this.config.className) this.container.classList.add(this.config.className);\n\n // Insert as the FIRST child of rows-viewport so it overlays on top of\n // the row pool. Z-index in CSS keeps it above `.rows`.\n rowsViewport.insertBefore(this.container, rowsViewport.firstChild);\n }\n\n // #endregion\n\n // #region Private — offsets + which-to-display\n\n /** Pixel offset of the top of `index` from the start of the scroll area. */\n private offsetOf(index: number): number {\n const v = this.getVirtualState();\n const cache = v?.positionCache;\n if (cache && cache[index]) return cache[index].offset;\n const h = v?.rowHeight ?? 28;\n return index * h;\n }\n\n /** Estimated height of `index` (used for push-mode displacement). */\n private heightOf(index: number): number {\n const v = this.getVirtualState();\n const cache = v?.positionCache;\n if (cache && cache[index]) return cache[index].height;\n return v?.rowHeight ?? 28;\n }\n\n private getVirtualState(): VirtualStateLike | undefined {\n return (this.grid as unknown as { _virtualization?: VirtualStateLike })?._virtualization;\n }\n\n private getCurrentScrollTop(): number {\n const v = this.getVirtualState();\n // PRIMARY source: the live `scrollTop` of the faux-scroll element. This\n // updates per-pixel as the user drags, unlike `_virtualization.start`\n // which only ticks over when the rendered window shifts (every\n // `rowHeight` px). Reading the stale start-derived value caused\n // `afterRender` to clobber the correct displayed-set that `onScroll`\n // had just computed (#279 follow-up).\n const liveScrollTop = v?.container?.scrollTop;\n if (typeof liveScrollTop === 'number') return liveScrollTop;\n // Fallbacks (unit tests / pre-mount): derive from window-start.\n if (\n typeof v?.start === 'number' &&\n typeof v?.rowHeight === 'number' &&\n (!v.positionCache || !v.positionCache.length)\n ) {\n return v.start * v.rowHeight;\n }\n if (v?.positionCache && typeof v.start === 'number' && v.positionCache[v.start]) {\n return v.positionCache[v.start].offset;\n }\n return 0;\n }\n\n /**\n * Compute the displayed sticky indices and any upward push offset, given\n * the current scroll offset.\n *\n * - `'push'` mode: a row qualifies once its top has scrolled past the\n * viewport top (strict `<`); only the highest qualifying index is\n * shown. As the next sticky approaches from below, the stuck clone\n * slides upward by `heightOfStuck - distance` (iOS section-header\n * behavior).\n * - `'stack'` mode: each subsequent sticky qualifies once its top\n * reaches the bottom of the existing stack (`offsetOf(idx) < scrollTop\n * + cumulativeHeightOfStuck`), so `— B —` latches when it meets\n * `— A —`'s bottom — not after `— A —` covers it. When the stack is\n * at `maxStacked` and the **live** next sticky row's top crosses the\n * bottom of the stack (`distance <= 0`), the entire stack translates\n * upward by `-distance`. Live rows above the stack (including the\n * incoming sticky) scroll up naturally beneath the overlay; rows-\n * viewport's `overflow: clip` hides anything above the top edge. When\n * the oldest is fully off (pushOffset ≥ heightOf(oldest)), the next\n * tick qualifies the new sticky and we slice to `last max` with\n * transform reset — at that exact pixel the live new sticky is sitting\n * precisely behind its slot in the new stack, producing a seamless\n * swap with no duplicate row visible.\n *\n * Strict `<` keeps the qualification edge symmetric with push mode and\n * avoids briefly rendering both a clone and the live row at the swap\n * pixel.\n */\n private computeDisplay(scrollTop: number): { indices: number[]; pushOffset: number } {\n if (this.config.mode === 'stack') {\n const max = this.config.maxStacked ?? Infinity;\n const qualifying: number[] = [];\n let stuckHeight = 0;\n for (const idx of this.stickyIndices) {\n if (qualifying.length < max) {\n // Within the cap: a sticky qualifies once its top reaches the\n // bottom of the existing stack.\n if (this.offsetOf(idx) < scrollTop + stuckHeight) {\n qualifying.push(idx);\n stuckHeight += this.heightOf(idx);\n } else {\n break; // sorted ascending — anything after won't qualify either\n }\n } else {\n // At cap: evict-and-promote only after `idx` has fully crossed\n // the slot of the current oldest. WHY: while `idx` is mid-cross\n // (its top is past the stack bottom but the oldest isn't yet\n // off the top), we want to ANIMATE that transition by sliding\n // the existing stack upward — not snap to the post-evict state.\n // Without this clamp, qualification fires the instant the new\n // sticky crosses the stack bottom (same scrollTop where the\n // anticipation block would otherwise activate), and the\n // anticipation never gets a chance to render.\n const oldestH = this.heightOf(qualifying[0]);\n if (this.offsetOf(idx) < scrollTop + stuckHeight - oldestH) {\n qualifying.shift();\n stuckHeight -= oldestH;\n qualifying.push(idx);\n stuckHeight += this.heightOf(idx);\n } else {\n break;\n }\n }\n }\n\n // Anticipation: at-cap and the live next sticky has crossed the\n // stack bottom but not yet fully past the oldest's slot. Translate\n // the entire stack up by `-distance` so the user sees the live\n // next-sticky scrolling up against the bottom of the stack while\n // the oldest slides off the top — exactly mirroring iOS Contacts.\n // Do NOT add the new sticky to the displayed list during this\n // window: it's still in the row pool and visible there. Adding a\n // clone too would produce a visible duplicate AND would cover the\n // last regular row under the previous section while live-next is\n // still approaching.\n if (qualifying.length === max && qualifying.length > 0) {\n const next = this.findNextSticky(qualifying[qualifying.length - 1]);\n if (next != null) {\n const distance = this.offsetOf(next) - (scrollTop + stuckHeight);\n if (distance < 0) {\n const oldestH = this.heightOf(qualifying[0]);\n return { indices: qualifying, pushOffset: Math.min(-distance, oldestH) };\n }\n }\n }\n return { indices: qualifying, pushOffset: 0 };\n }\n\n // 'push' mode.\n const qualifying: number[] = [];\n for (const idx of this.stickyIndices) {\n if (this.offsetOf(idx) < scrollTop) qualifying.push(idx);\n else break;\n }\n if (qualifying.length === 0) return { indices: qualifying, pushOffset: 0 };\n const stuck = qualifying[qualifying.length - 1];\n const next = this.findNextSticky(stuck);\n let pushOffset = 0;\n if (next != null) {\n const stuckH = this.heightOf(stuck);\n const distance = this.offsetOf(next) - scrollTop;\n if (distance < stuckH) {\n pushOffset = stuckH - Math.max(0, distance);\n }\n }\n return { indices: [stuck], pushOffset };\n }\n\n // #endregion\n\n // #region Private — clone management\n\n /** Locate a rendered row in the viewport by its data index. */\n private findRenderedRow(index: number): HTMLElement | null {\n const grid = this.gridElement;\n if (!grid) return null;\n // Cells carry `data-row=\"<index>\"`. The row element is the parent.\n const cell = grid.querySelector(`.rows .data-grid-row .cell[data-row=\"${index}\"]`);\n return (cell?.parentElement as HTMLElement | null) ?? null;\n }\n\n /** Build (or refresh) a clone for `index`, using the live row when present. */\n private buildClone(index: number): HTMLElement | null {\n const live = this.findRenderedRow(index);\n if (!live) return this.cloneCache.get(index) ?? null;\n const clone = live.cloneNode(true) as HTMLElement;\n clone.classList.add('tbw-sticky-row');\n clone.removeAttribute('aria-rowindex');\n // Stuck clones are decorative — the original row is still present in the\n // accessibility tree below. Hide clones from AT to avoid double-reads.\n clone.setAttribute('aria-hidden', 'true');\n clone.dataset['stickyRow'] = String(index);\n // Drop any focus styling from the source — clones are non-interactive.\n clone.classList.remove('row-focus', 'cell-focus');\n clone.querySelectorAll('.cell-focus, .row-focus').forEach((el) => el.classList.remove('cell-focus', 'row-focus'));\n // Strip tabindex on cells so the clone isn't a tab target.\n clone.removeAttribute('tabindex');\n clone.querySelectorAll('[tabindex]').forEach((el) => el.removeAttribute('tabindex'));\n\n this.cloneCache.set(index, clone);\n return clone;\n }\n\n /** Refresh cached clones for any displayed indices that are now in-window.\n * Pulls fresh DOM so edits / re-renders are reflected when the row swings\n * back into view. */\n private refreshClonesInWindow(): void {\n if (!this.displayedIndices.length) return;\n for (const idx of this.displayedIndices) {\n const live = this.findRenderedRow(idx);\n if (live) {\n // Re-clone to pick up any post-render changes.\n const fresh = this.buildClone(idx);\n const existingClone = this.container?.querySelector(`[data-sticky-row=\"${idx}\"]`);\n if (fresh && existingClone && existingClone !== fresh) {\n existingClone.replaceWith(fresh);\n }\n }\n }\n }\n\n /** Build clones for any sticky row currently rendered in the viewport so we\n * have one ready when the row scrolls past. Without this, a sticky row\n * that's never been displayed-as-stuck won't have a cache entry, and once\n * the live row leaves the rendered window we have nothing to render. */\n private primeCloneCache(): void {\n if (!this.stickyIndices.length) return;\n for (const idx of this.stickyIndices) {\n if (this.findRenderedRow(idx)) {\n // buildClone() handles the live → cache path itself.\n this.buildClone(idx);\n }\n }\n }\n\n /** Reconcile the container DOM with the desired displayed indices. */\n private refreshDisplay(scrollTopOverride?: number): void {\n if (!this.container) return;\n\n const scrollTop = scrollTopOverride ?? this.getCurrentScrollTop();\n const { indices: desired, pushOffset } = this.computeDisplay(scrollTop);\n\n // Update the container's mode marker (in case config changed).\n if (this.container.dataset['mode'] !== this.config.mode) {\n this.container.dataset['mode'] = this.config.mode ?? 'push';\n }\n\n const sameSet =\n desired.length === this.displayedIndices.length && desired.every((v, i) => v === this.displayedIndices[i]);\n\n if (!sameSet) {\n // Rebuild the container's children. cloneCache survives between calls so\n // we re-use existing clones for indices that remain displayed.\n const fragment = document.createDocumentFragment();\n const appended: number[] = [];\n for (const idx of desired) {\n let clone = this.cloneCache.get(idx) ?? null;\n // Always try to refresh from live DOM if available.\n const fresh = this.buildClone(idx);\n clone = fresh ?? clone;\n if (clone) {\n fragment.appendChild(clone);\n appended.push(idx);\n }\n }\n this.container.replaceChildren(fragment);\n // Track only the indices we actually appended so a subsequent refresh\n // (after a missing index gets primed via onScrollRender) will detect a\n // diff and retry rather than incorrectly believing the set is settled.\n this.displayedIndices = appended;\n }\n\n // Apply the upward translation to the entire container so push-mode\n // (1 child) and stack-mode anticipation (max+1 children) both slide\n // uniformly. CSS `overflow: clip` on `.rows-viewport` hides anything\n // translated above its top edge.\n if (pushOffset !== this.lastPushOffset) {\n this.container.style.transform = pushOffset > 0 ? `translateY(${-pushOffset}px)` : '';\n this.lastPushOffset = pushOffset;\n }\n }\n\n /** Find the next sticky index strictly greater than `current`. */\n private findNextSticky(current: number): number | null {\n for (const idx of this.stickyIndices) {\n if (idx > current) return idx;\n }\n return null;\n }\n\n // #endregion\n}\n"],"names":["StickyRowsPlugin","BaseGridPlugin","name","styles","defaultConfig","mode","maxStacked","Infinity","container","stickyIndices","cloneCache","Map","displayedIndices","lastPushOffset","detach","this","remove","clear","afterRender","recomputeStickyIndices","ensureContainer","primeCloneCache","refreshDisplay","onScrollRender","refreshClonesInWindow","onScroll","event","scrollTop","resolvePredicate","cfg","config","isSticky","field","row","Boolean","rows","predicate","next","i","length","push","some","v","grid","gridElement","rowsViewport","querySelector","contains","document","createElement","className","setAttribute","dataset","classList","add","insertBefore","firstChild","offsetOf","index","getVirtualState","cache","positionCache","offset","rowHeight","heightOf","height","_virtualization","getCurrentScrollTop","liveScrollTop","start","computeDisplay","max","qualifying","stuckHeight","idx","oldestH","shift","findNextSticky","distance","indices","pushOffset","Math","min","stuck","stuckH","findRenderedRow","cell","parentElement","buildClone","live","get","clone","cloneNode","removeAttribute","String","querySelectorAll","forEach","el","set","fresh","existingClone","replaceWith","scrollTopOverride","desired","every","fragment","createDocumentFragment","appended","appendChild","replaceChildren","style","transform","current"],"mappings":"oVAwDO,MAAMA,UAAyBC,EAAAA,eAE3BC,KAAO,aAEEC,oeAGlB,iBAAuBC,GACrB,MAAO,CACLC,KAAM,OACNC,WAAYC,IAEhB,CAIQC,UAAgC,KAGhCC,cAA0B,GAI1BC,eAA2CC,IAI3CC,iBAA6B,GAG7BC,eAAiB,EAKhB,MAAAC,GACPC,KAAKP,WAAWQ,SAChBD,KAAKP,UAAY,KACjBO,KAAKL,WAAWO,QAChBF,KAAKN,cAAgB,GACrBM,KAAKH,iBAAmB,GACxBG,KAAKF,eAAiB,CACxB,CAMS,WAAAK,GACPH,KAAKI,yBACLJ,KAAKK,kBAILL,KAAKM,kBACLN,KAAKO,gBACP,CAGS,cAAAC,GAKPR,KAAKM,kBACLN,KAAKS,wBACLT,KAAKO,gBACP,CAGS,QAAAG,CAASC,GAChBX,KAAKO,eAAeI,EAAM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biB,EACbA,IACFc,EAASG,YAAYjB,GACrBgB,EAASnE,KAAKkC,GAElB,CACA3D,KAAKP,UAAUqG,gBAAgBJ,GAI/B1F,KAAKH,iBAAmB+F,CAC1B,CAMI3B,IAAejE,KAAKF,iBACtBE,KAAKP,UAAUsG,MAAMC,UAAY/B,EAAa,EAAI,eAAeA,OAAkB,GACnFjE,KAAKF,eAAiBmE,EAE1B,CAGQ,cAAAH,CAAemC,GACrB,IAAA,MAAWtC,KAAO3D,KAAKN,cACrB,GAAIiE,EAAMsC,EAAS,OAAOtC,EAE5B,OAAO,IACT"}
1
+ {"version":3,"file":"sticky-rows.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/sticky-rows/StickyRowsPlugin.ts"],"sourcesContent":["/**\n * Sticky Rows Plugin (Class-based)\n *\n * Pins selected data rows below the header as the user scrolls past them.\n * See `types.ts` for configuration.\n *\n * @module Plugins/Sticky Rows\n */\n\nimport type { RowPosition } from '../../core/internal/virtualization';\nimport { BaseGridPlugin } from '../../core/plugin/base-plugin';\nimport type { ScrollEvent } from '../../core/plugin/types';\nimport styles from './sticky-rows.css?inline';\nimport type { StickyPredicate, StickyRowsConfig } from './types';\n\n/** Internal shape of the virtualization state we read from the grid. */\ninterface VirtualStateLike {\n start?: number;\n end?: number;\n rowHeight?: number;\n positionCache?: RowPosition[] | null;\n /** The faux-scroll element — the source of truth for the live scroll\n * position (per-pixel, unlike `start` which only updates when the\n * rendered window shifts). */\n container?: HTMLElement | null;\n}\n\n/**\n * Sticky Rows plugin for `<tbw-grid>`.\n *\n * Marks specific rows as \"sticky\" so they pin below the grid header when their\n * natural scroll position would take them off-screen. Behavior when multiple\n * sticky rows would be stuck simultaneously is controlled by `mode`:\n *\n * - `'push'` (default) — only one stuck at a time; the next sticky row pushes\n * the previous one out of view (iOS section-header behavior).\n * - `'stack'` — sticky rows stack below the header up to `maxStacked`.\n *\n * The plugin renders **clones** of the real rows; the originals continue to\n * exist in the data flow. Clones inherit the row's grid-template alignment so\n * they line up perfectly with the column boundaries below.\n *\n * @example\n * ```ts\n * import '@toolbox-web/grid/features/sticky-rows';\n *\n * grid.gridConfig = {\n * features: { stickyRows: { isSticky: 'isSection', mode: 'stack' } },\n * };\n * ```\n *\n * @see {@link StickyRowsConfig} for all configuration options.\n *\n * @internal Extends BaseGridPlugin.\n * @since 2.7.0\n */\nexport class StickyRowsPlugin extends BaseGridPlugin<StickyRowsConfig> {\n /** @internal */\n readonly name = 'stickyRows';\n /** @internal */\n override readonly styles = styles;\n\n /** @internal */\n protected override get defaultConfig(): Partial<StickyRowsConfig> {\n return {\n mode: 'push',\n maxStacked: Infinity,\n };\n }\n\n // #region Internal State\n /** Container element that holds the stuck-row clones. */\n private container: HTMLElement | null = null;\n\n /** Indices in `grid.rows` whose rows are sticky, sorted ascending. */\n private stickyIndices: number[] = [];\n\n /** Cached clone DOM keyed by row index. Survives the row leaving the\n * virtualization window so we can keep showing it while stuck. */\n private cloneCache: Map<number, HTMLElement> = new Map();\n\n /** Currently displayed indices (in DOM order). Used to skip work when the\n * set hasn't changed between scroll ticks. */\n private displayedIndices: number[] = [];\n\n /** Last applied push-mode translation, to skip writes on no-op ticks. */\n private lastPushOffset = 0;\n\n /** True while a deferred \"settle\" style pass is already queued. Coalesces\n * multiple scroll ticks into a single re-capture. See\n * {@link maybeScheduleSettlePass}. */\n private settlePassScheduled = false;\n // #endregion\n\n // #region Lifecycle\n /** @internal */\n override detach(): void {\n this.container?.remove();\n this.container = null;\n this.cloneCache.clear();\n this.stickyIndices = [];\n this.displayedIndices = [];\n this.lastPushOffset = 0;\n this.settlePassScheduled = false;\n }\n // #endregion\n\n // #region Hooks\n\n /** @internal Recompute the sticky-index list and refresh display. */\n override afterRender(): void {\n // A style pass is now running — possibly the deferred settle pass we\n // requested. Clear the flag so a later scroll tick can queue a fresh one.\n this.settlePassScheduled = false;\n this.recomputeStickyIndices();\n this.ensureContainer();\n // Pre-cache clones for any sticky row currently in the rendered window\n // BEFORE it scrolls out — otherwise findRenderedRow() returns null at\n // display time and we'd render an empty container.\n this.primeCloneCache();\n this.refreshDisplay();\n }\n\n /** @internal Re-render clones after a scroll-driven row pool refresh. */\n override onScrollRender(): void {\n // The pool may have repopulated rows we're tracking. Refresh clone DOM\n // for any displayed indices that are now back in the rendered window,\n // and pre-cache any sticky rows that just entered the window so we have\n // a clone ready when they scroll past.\n this.primeCloneCache();\n this.refreshClonesInWindow();\n this.refreshDisplay();\n this.maybeScheduleSettlePass();\n }\n\n /** @internal Update which clones show / how they're positioned. */\n override onScroll(event: ScrollEvent): void {\n this.refreshDisplay(event.scrollTop);\n }\n\n /**\n * Queue a single deferred style pass that re-captures sticky clones once\n * async framework cell content has settled.\n *\n * WHY: framework adapters (React/Vue) flush custom cell content on a\n * microtask (`PortalManager` batches via `queueMicrotask` + `flushSync`)\n * AFTER this synchronous scroll hook. When a sticky row is recycled back\n * into the rendered window on scroll-up, the grid sets the cell\n * `data-row` attribute synchronously but the cell's rendered content still\n * shows the PREVIOUS row. A clone captured during the hook therefore holds\n * stale content, and because clones are cached by index it stays wrong\n * forever (symptom: scrolling down, back up, then down again pins a\n * different row than the first time). Re-running `afterRender` on the next\n * style pass — after the microtask flush — re-captures the now-settled\n * clone. Only schedule when a sticky row is actually in the rendered window\n * (the only case where a stale capture could have happened) to avoid\n * needless style passes during ordinary scrolling.\n */\n private maybeScheduleSettlePass(): void {\n if (this.settlePassScheduled) return;\n if (!this.stickyIndices.some((idx) => this.findRenderedRow(idx) != null)) return;\n this.settlePassScheduled = true;\n this.requestAfterRender();\n }\n\n // #endregion\n\n // #region Private — predicate + indices\n\n private resolvePredicate(): StickyPredicate {\n const cfg = this.config.isSticky;\n if (typeof cfg === 'function') return cfg;\n if (typeof cfg === 'string') {\n const field = cfg;\n return (row) => {\n if (row == null || typeof row !== 'object') return false;\n return Boolean((row as Record<string, unknown>)[field]);\n };\n }\n return () => false;\n }\n\n private recomputeStickyIndices(): void {\n const rows = this.rows;\n const predicate = this.resolvePredicate();\n const next: number[] = [];\n for (let i = 0; i < rows.length; i++) {\n if (predicate(rows[i], i)) next.push(i);\n }\n // Drop cache entries whose indices are no longer sticky (e.g. data\n // shuffled, predicate flipped). Indices that remain may still point at a\n // different row after re-sort — drop those too so we re-clone from the\n // fresh DOM on the next render.\n if (next.length !== this.stickyIndices.length || next.some((v, i) => v !== this.stickyIndices[i])) {\n this.cloneCache.clear();\n }\n this.stickyIndices = next;\n }\n\n // #endregion\n\n // #region Private — DOM container\n\n private ensureContainer(): void {\n const grid = this.gridElement;\n if (!grid) return;\n\n // Container is an OVERLAY positioned at the top of the rows-viewport\n // (not a flex child of rows-body). Why: a flow-positioned container\n // takes vertical space, which pushes the rows-viewport down by the\n // sticky height. The rows are positioned in scroll coordinates that\n // are agnostic of that shift, so live-row geometry ends up partially\n // overlapping the sticky container — producing duplicate visible rows\n // during the push transition (#279 follow-up). Overlaying on top of\n // the row pool, with `overflow: clip` on rows-viewport hiding the\n // live row underneath, eliminates the overlap entirely.\n const rowsViewport = grid.querySelector('.rows-viewport');\n if (!rowsViewport) {\n // Grid hasn't built its DOM yet; bail and try again on next afterRender.\n this.container = null;\n return;\n }\n\n if (this.container && rowsViewport.contains(this.container)) return;\n\n // Container was either never created or got wiped out. Re-create.\n this.container = document.createElement('div');\n this.container.className = 'tbw-sticky-rows';\n this.container.setAttribute('role', 'presentation');\n this.container.dataset['mode'] = this.config.mode ?? 'push';\n if (this.config.className) this.container.classList.add(this.config.className);\n\n // Insert as the FIRST child of rows-viewport so it overlays on top of\n // the row pool. Z-index in CSS keeps it above `.rows`.\n rowsViewport.insertBefore(this.container, rowsViewport.firstChild);\n }\n\n // #endregion\n\n // #region Private — offsets + which-to-display\n\n /** Pixel offset of the top of `index` from the start of the scroll area. */\n private offsetOf(index: number): number {\n const v = this.getVirtualState();\n const cache = v?.positionCache;\n if (cache && cache[index]) return cache[index].offset;\n const h = v?.rowHeight ?? 28;\n return index * h;\n }\n\n /** Estimated height of `index` (used for push-mode displacement). */\n private heightOf(index: number): number {\n const v = this.getVirtualState();\n const cache = v?.positionCache;\n if (cache && cache[index]) return cache[index].height;\n return v?.rowHeight ?? 28;\n }\n\n private getVirtualState(): VirtualStateLike | undefined {\n return (this.grid as unknown as { _virtualization?: VirtualStateLike })?._virtualization;\n }\n\n private getCurrentScrollTop(): number {\n const v = this.getVirtualState();\n // PRIMARY source: the live `scrollTop` of the faux-scroll element. This\n // updates per-pixel as the user drags, unlike `_virtualization.start`\n // which only ticks over when the rendered window shifts (every\n // `rowHeight` px). Reading the stale start-derived value caused\n // `afterRender` to clobber the correct displayed-set that `onScroll`\n // had just computed (#279 follow-up).\n const liveScrollTop = v?.container?.scrollTop;\n if (typeof liveScrollTop === 'number') return liveScrollTop;\n // Fallbacks (unit tests / pre-mount): derive from window-start.\n if (\n typeof v?.start === 'number' &&\n typeof v?.rowHeight === 'number' &&\n (!v.positionCache || !v.positionCache.length)\n ) {\n return v.start * v.rowHeight;\n }\n if (v?.positionCache && typeof v.start === 'number' && v.positionCache[v.start]) {\n return v.positionCache[v.start].offset;\n }\n return 0;\n }\n\n /**\n * Compute the displayed sticky indices and any upward push offset, given\n * the current scroll offset.\n *\n * - `'push'` mode: a row qualifies once its top has scrolled past the\n * viewport top (strict `<`); only the highest qualifying index is\n * shown. As the next sticky approaches from below, the stuck clone\n * slides upward by `heightOfStuck - distance` (iOS section-header\n * behavior).\n * - `'stack'` mode: each subsequent sticky qualifies once its top\n * reaches the bottom of the existing stack (`offsetOf(idx) < scrollTop\n * + cumulativeHeightOfStuck`), so `— B —` latches when it meets\n * `— A —`'s bottom — not after `— A —` covers it. When the stack is\n * at `maxStacked` and the **live** next sticky row's top crosses the\n * bottom of the stack (`distance <= 0`), the entire stack translates\n * upward by `-distance`. Live rows above the stack (including the\n * incoming sticky) scroll up naturally beneath the overlay; rows-\n * viewport's `overflow: clip` hides anything above the top edge. When\n * the oldest is fully off (pushOffset ≥ heightOf(oldest)), the next\n * tick qualifies the new sticky and we slice to `last max` with\n * transform reset — at that exact pixel the live new sticky is sitting\n * precisely behind its slot in the new stack, producing a seamless\n * swap with no duplicate row visible.\n *\n * Strict `<` keeps the qualification edge symmetric with push mode and\n * avoids briefly rendering both a clone and the live row at the swap\n * pixel.\n */\n private computeDisplay(scrollTop: number): { indices: number[]; pushOffset: number } {\n if (this.config.mode === 'stack') {\n const max = this.config.maxStacked ?? Infinity;\n const qualifying: number[] = [];\n let stuckHeight = 0;\n for (const idx of this.stickyIndices) {\n if (qualifying.length < max) {\n // Within the cap: a sticky qualifies once its top reaches the\n // bottom of the existing stack.\n if (this.offsetOf(idx) < scrollTop + stuckHeight) {\n qualifying.push(idx);\n stuckHeight += this.heightOf(idx);\n } else {\n break; // sorted ascending — anything after won't qualify either\n }\n } else {\n // At cap: evict-and-promote only after `idx` has fully crossed\n // the slot of the current oldest. WHY: while `idx` is mid-cross\n // (its top is past the stack bottom but the oldest isn't yet\n // off the top), we want to ANIMATE that transition by sliding\n // the existing stack upward — not snap to the post-evict state.\n // Without this clamp, qualification fires the instant the new\n // sticky crosses the stack bottom (same scrollTop where the\n // anticipation block would otherwise activate), and the\n // anticipation never gets a chance to render.\n const oldestH = this.heightOf(qualifying[0]);\n if (this.offsetOf(idx) < scrollTop + stuckHeight - oldestH) {\n qualifying.shift();\n stuckHeight -= oldestH;\n qualifying.push(idx);\n stuckHeight += this.heightOf(idx);\n } else {\n break;\n }\n }\n }\n\n // Anticipation: at-cap and the live next sticky has crossed the\n // stack bottom but not yet fully past the oldest's slot. Translate\n // the entire stack up by `-distance` so the user sees the live\n // next-sticky scrolling up against the bottom of the stack while\n // the oldest slides off the top — exactly mirroring iOS Contacts.\n // Do NOT add the new sticky to the displayed list during this\n // window: it's still in the row pool and visible there. Adding a\n // clone too would produce a visible duplicate AND would cover the\n // last regular row under the previous section while live-next is\n // still approaching.\n if (qualifying.length === max && qualifying.length > 0) {\n const next = this.findNextSticky(qualifying[qualifying.length - 1]);\n if (next != null) {\n const distance = this.offsetOf(next) - (scrollTop + stuckHeight);\n if (distance < 0) {\n const oldestH = this.heightOf(qualifying[0]);\n return { indices: qualifying, pushOffset: Math.min(-distance, oldestH) };\n }\n }\n }\n return { indices: qualifying, pushOffset: 0 };\n }\n\n // 'push' mode.\n const qualifying: number[] = [];\n for (const idx of this.stickyIndices) {\n if (this.offsetOf(idx) < scrollTop) qualifying.push(idx);\n else break;\n }\n if (qualifying.length === 0) return { indices: qualifying, pushOffset: 0 };\n const stuck = qualifying[qualifying.length - 1];\n const next = this.findNextSticky(stuck);\n let pushOffset = 0;\n if (next != null) {\n const stuckH = this.heightOf(stuck);\n const distance = this.offsetOf(next) - scrollTop;\n if (distance < stuckH) {\n pushOffset = stuckH - Math.max(0, distance);\n }\n }\n return { indices: [stuck], pushOffset };\n }\n\n // #endregion\n\n // #region Private — clone management\n\n /** Locate a rendered row in the viewport by its data index. */\n private findRenderedRow(index: number): HTMLElement | null {\n const grid = this.gridElement;\n if (!grid) return null;\n // Cells carry `data-row=\"<index>\"`. The row element is the parent.\n const cell = grid.querySelector(`.rows .data-grid-row .cell[data-row=\"${index}\"]`);\n return (cell?.parentElement as HTMLElement | null) ?? null;\n }\n\n /** Build (or refresh) a clone for `index`, using the live row when present. */\n private buildClone(index: number): HTMLElement | null {\n const live = this.findRenderedRow(index);\n if (!live) return this.cloneCache.get(index) ?? null;\n const clone = live.cloneNode(true) as HTMLElement;\n clone.classList.add('tbw-sticky-row');\n clone.removeAttribute('aria-rowindex');\n // Stuck clones are decorative — the original row is still present in the\n // accessibility tree below. Hide clones from AT to avoid double-reads.\n clone.setAttribute('aria-hidden', 'true');\n clone.dataset['stickyRow'] = String(index);\n // Drop any focus styling from the source — clones are non-interactive.\n clone.classList.remove('row-focus', 'cell-focus');\n clone.querySelectorAll('.cell-focus, .row-focus').forEach((el) => el.classList.remove('cell-focus', 'row-focus'));\n // Strip tabindex on cells so the clone isn't a tab target.\n clone.removeAttribute('tabindex');\n clone.querySelectorAll('[tabindex]').forEach((el) => el.removeAttribute('tabindex'));\n\n this.cloneCache.set(index, clone);\n return clone;\n }\n\n /** Refresh cached clones for any displayed indices that are now in-window.\n * Pulls fresh DOM so edits / re-renders are reflected when the row swings\n * back into view. */\n private refreshClonesInWindow(): void {\n if (!this.displayedIndices.length) return;\n for (const idx of this.displayedIndices) {\n const live = this.findRenderedRow(idx);\n if (live) {\n // Re-clone to pick up any post-render changes.\n const fresh = this.buildClone(idx);\n const existingClone = this.container?.querySelector(`[data-sticky-row=\"${idx}\"]`);\n if (fresh && existingClone && existingClone !== fresh) {\n existingClone.replaceWith(fresh);\n }\n }\n }\n }\n\n /** Build clones for any sticky row currently rendered in the viewport so we\n * have one ready when the row scrolls past. Without this, a sticky row\n * that's never been displayed-as-stuck won't have a cache entry, and once\n * the live row leaves the rendered window we have nothing to render. */\n private primeCloneCache(): void {\n if (!this.stickyIndices.length) return;\n for (const idx of this.stickyIndices) {\n if (this.findRenderedRow(idx)) {\n // buildClone() handles the live → cache path itself.\n this.buildClone(idx);\n }\n }\n }\n\n /** Reconcile the container DOM with the desired displayed indices. */\n private refreshDisplay(scrollTopOverride?: number): void {\n if (!this.container) return;\n\n const scrollTop = scrollTopOverride ?? this.getCurrentScrollTop();\n const { indices: desired, pushOffset } = this.computeDisplay(scrollTop);\n\n // Update the container's mode marker (in case config changed).\n if (this.container.dataset['mode'] !== this.config.mode) {\n this.container.dataset['mode'] = this.config.mode ?? 'push';\n }\n\n const sameSet =\n desired.length === this.displayedIndices.length && desired.every((v, i) => v === this.displayedIndices[i]);\n\n if (!sameSet) {\n // Rebuild the container's children. cloneCache survives between calls so\n // we re-use existing clones for indices that remain displayed.\n const fragment = document.createDocumentFragment();\n const appended: number[] = [];\n for (const idx of desired) {\n let clone = this.cloneCache.get(idx) ?? null;\n // Always try to refresh from live DOM if available.\n const fresh = this.buildClone(idx);\n clone = fresh ?? clone;\n if (clone) {\n fragment.appendChild(clone);\n appended.push(idx);\n }\n }\n this.container.replaceChildren(fragment);\n // Track only the indices we actually appended so a subsequent refresh\n // (after a missing index gets primed via onScrollRender) will detect a\n // diff and retry rather than incorrectly believing the set is settled.\n this.displayedIndices = appended;\n }\n\n // Apply the upward translation to the entire container so push-mode\n // (1 child) and stack-mode anticipation (max+1 children) both slide\n // uniformly. CSS `overflow: clip` on `.rows-viewport` hides anything\n // translated above its top edge.\n if (pushOffset !== this.lastPushOffset) {\n this.container.style.transform = pushOffset > 0 ? `translateY(${-pushOffset}px)` : '';\n this.lastPushOffset = pushOffset;\n }\n }\n\n /** Find the next sticky index strictly greater than `current`. */\n private findNextSticky(current: number): number | null {\n for (const idx of this.stickyIndices) {\n if (idx > current) return idx;\n }\n return null;\n }\n\n // #endregion\n}\n"],"names":["StickyRowsPlugin","BaseGridPlugin","name","styles","defaultConfig","mode","maxStacked","Infinity","container","stickyIndices","cloneCache","Map","displayedIndices","lastPushOffset","settlePassScheduled","detach","this","remove","clear","afterRender","recomputeStickyIndices","ensureContainer","primeCloneCache","refreshDisplay","onScrollRender","refreshClonesInWindow","maybeScheduleSettlePass","onScroll","event","scrollTop","some","idx","findRenderedRow","requestAfterRender","resolvePredicate","cfg","config","isSticky","field","row","Boolean","rows","predicate","next","i","length","push","v","grid","gridElement","rowsViewport","querySelector","contains","document","createElement","className","setAttribute","dataset","classList","add","insertBefore","firstChild","offsetOf","index","getVirtualState","cache","positionCache","offset","rowHeight","heightOf","height","_virtualization","getCurrentScrollTop","liveScrollTop","start","computeDisplay","max","qualifying","stuckHeight","oldestH","shift","findNextSticky","distance","indices","pushOffset","Math","min","stuck","stuckH","cell","parentElement","buildClone","live","get","clone","cloneNode","removeAttribute","String","querySelectorAll","forEach","el","set","fresh","existingClone","replaceWith","scrollTopOverride","desired","every","fragment","createDocumentFragment","appended","appendChild","replaceChildren","style","transform","current"],"mappings":"oVAwDO,MAAMA,UAAyBC,EAAAA,eAE3BC,KAAO,aAEEC,oeAGlB,iBAAuBC,GACrB,MAAO,CACLC,KAAM,OACNC,WAAYC,IAEhB,CAIQC,UAAgC,KAGhCC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