@toolbox-web/grid 2.0.0-rc.3 → 2.0.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 (69) hide show
  1. package/all.js +2 -2
  2. package/all.js.map +1 -1
  3. package/index.js +1 -1
  4. package/index.js.map +1 -1
  5. package/lib/core/internal/shell-controller.d.ts +46 -0
  6. package/lib/core/internal/shell.d.ts +2 -46
  7. package/lib/core/internal/sorting.d.ts +4 -1
  8. package/lib/plugins/clipboard/index.js +1 -1
  9. package/lib/plugins/clipboard/index.js.map +1 -1
  10. package/lib/plugins/column-virtualization/index.js +1 -1
  11. package/lib/plugins/column-virtualization/index.js.map +1 -1
  12. package/lib/plugins/context-menu/index.js +1 -1
  13. package/lib/plugins/context-menu/index.js.map +1 -1
  14. package/lib/plugins/editing/index.js +1 -1
  15. package/lib/plugins/editing/index.js.map +1 -1
  16. package/lib/plugins/export/index.js +1 -1
  17. package/lib/plugins/export/index.js.map +1 -1
  18. package/lib/plugins/filtering/FilteringPlugin.d.ts +3 -1
  19. package/lib/plugins/filtering/index.js +1 -1
  20. package/lib/plugins/filtering/index.js.map +1 -1
  21. package/lib/plugins/grouping-columns/index.js +1 -1
  22. package/lib/plugins/grouping-columns/index.js.map +1 -1
  23. package/lib/plugins/grouping-rows/index.js +2 -2
  24. package/lib/plugins/grouping-rows/index.js.map +1 -1
  25. package/lib/plugins/master-detail/index.js +1 -1
  26. package/lib/plugins/master-detail/index.js.map +1 -1
  27. package/lib/plugins/multi-sort/index.js +1 -1
  28. package/lib/plugins/multi-sort/index.js.map +1 -1
  29. package/lib/plugins/pinned-columns/index.js +1 -1
  30. package/lib/plugins/pinned-columns/index.js.map +1 -1
  31. package/lib/plugins/pinned-rows/index.js +1 -1
  32. package/lib/plugins/pinned-rows/index.js.map +1 -1
  33. package/lib/plugins/pivot/index.js +1 -1
  34. package/lib/plugins/pivot/index.js.map +1 -1
  35. package/lib/plugins/print/index.js +1 -1
  36. package/lib/plugins/print/index.js.map +1 -1
  37. package/lib/plugins/reorder-columns/index.js +1 -1
  38. package/lib/plugins/reorder-columns/index.js.map +1 -1
  39. package/lib/plugins/reorder-rows/index.js +1 -1
  40. package/lib/plugins/reorder-rows/index.js.map +1 -1
  41. package/lib/plugins/responsive/index.js +1 -1
  42. package/lib/plugins/responsive/index.js.map +1 -1
  43. package/lib/plugins/selection/index.js +1 -1
  44. package/lib/plugins/selection/index.js.map +1 -1
  45. package/lib/plugins/server-side/ServerSidePlugin.d.ts +13 -0
  46. package/lib/plugins/server-side/index.js +1 -1
  47. package/lib/plugins/server-side/index.js.map +1 -1
  48. package/lib/plugins/tooltip/index.js +1 -1
  49. package/lib/plugins/tooltip/index.js.map +1 -1
  50. package/lib/plugins/tree/TreePlugin.d.ts +8 -0
  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/filtering.umd.js +1 -1
  63. package/umd/plugins/filtering.umd.js.map +1 -1
  64. package/umd/plugins/server-side.umd.js +1 -1
  65. package/umd/plugins/server-side.umd.js.map +1 -1
  66. package/umd/plugins/tooltip.umd.js +1 -1
  67. package/umd/plugins/tooltip.umd.js.map +1 -1
  68. package/umd/plugins/tree.umd.js +1 -1
  69. package/umd/plugins/tree.umd.js.map +1 -1
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("../../core/internal/diagnostics"),require("../../core/plugin/base-plugin")):"function"==typeof define&&define.amd?define(["exports","../../core/internal/diagnostics","../../core/plugin/base-plugin"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TbwGridPlugin_serverSide={},t.TbwGrid,t.TbwGrid)}(this,function(t,e,o){"use strict";function s(t,e){return Math.floor(t/e)}async function a(t,e,o,s){const a=function(t,e){return{start:t*e,end:(t+1)*e}}(e,o);return t.getRows({startNode:a.start,endNode:a.end,sortModel:s.sortModel,filterModel:s.filterModel})}function i(t,e,o){const a=s(t,e),i=o.get(a);if(!i)return;return i[t%e]}class r extends o.BaseGridPlugin{static manifest={modifiesRowStructure:!0,hookPriority:{processRows:-10},incompatibleWith:[{name:"pivot",reason:"PivotPlugin requires the full dataset to compute aggregations. ServerSidePlugin lazy-loads rows in blocks, so pivot aggregation cannot be performed client-side."}],events:[{type:"datasource:data",description:"Root data page/block loaded"},{type:"datasource:children",description:"Child data loaded for a parent context"},{type:"datasource:loading",description:"Loading state changed"},{type:"datasource:error",description:"Fetch operation failed"}],queries:[{type:"datasource:fetch-children",description:"Request child rows for a parent context"},{type:"datasource:is-active",description:"Check if ServerSide plugin has an active data source"}]};name="serverSide";get defaultConfig(){return{pageSize:100,cacheBlockSize:100,maxConcurrentRequests:2}}dataSource=null;totalNodeCount=0;loadedBlocks=new Map;loadingBlocks=new Set;lastRequestId=0;scrollDebounceTimer;managedNodes=[];attach(t){super.attach(t),this.on("sort-change",()=>this.onModelChange()),this.on("filter-change",()=>this.onModelChange())}detach(){this.dataSource=null,this.totalNodeCount=0,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.lastRequestId=0,this.scrollDebounceTimer&&(clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=void 0)}getEnrichmentParams(){const t=this.grid?.query?.("sort:get-model",null),e=this.grid?.query?.("filter:get-model",null);return{sortModel:t?.[0],filterModel:e?.[0]}}getViewportMapping(t,e){const o={viewportStart:t,viewportEnd:e},s=this.grid?.query?.("datasource:viewport-mapping",o);return s?.[0]?s[0]:{startNode:t,endNode:e,totalLoadedNodes:this.totalNodeCount}}onModelChange(){this.dataSource&&(this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.totalNodeCount=0,this.requestRender())}loadRequiredBlocks(){if(!this.dataSource)return;const t=this.grid,o=this.config.cacheBlockSize??100,i=this.getViewportMapping(t._virtualization.start,t._virtualization.end),r=function(t,e,o){const a=s(t,o),i=s(e-1,o),r=[];for(let s=a;s<=i;s++)r.push(s);return r}(i.startNode,i.endNode,o),d=this.getEnrichmentParams(),n=this.grid?.getAttribute?.("id")??void 0;for(const s of r)if(!this.loadedBlocks.has(s)&&!this.loadingBlocks.has(s)){if(this.loadingBlocks.size>=(this.config.maxConcurrentRequests??2)){e.debugDiagnostic(e.DATASOURCE_THROTTLED,"Concurrent request limit reached, deferring block load",n);break}this.loadingBlocks.add(s),this.broadcast("datasource:loading",{loading:!0}),a(this.dataSource,s,o,d).then(t=>{this.loadedBlocks.set(s,t.rows),this.totalNodeCount=t.totalNodeCount,this.loadingBlocks.delete(s);const e=s*o;for(let o=0;o<t.rows.length;o++)e+o<this.managedNodes.length&&(this.managedNodes[e+o]=t.rows[o]);const a={rows:t.rows,totalNodeCount:t.totalNodeCount,startNode:e,endNode:e+t.rows.length,claimed:!1};this.broadcast("datasource:data",a),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}),this.requestVirtualRefresh(),this.loadRequiredBlocks()}).catch(t=>{this.loadingBlocks.delete(s);const o=t instanceof Error?t:new Error(String(t));e.errorDiagnostic(e.DATASOURCE_FETCH_ERROR,`getRows() failed: ${o.message}`,n),this.broadcast("datasource:error",{error:o}),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1})})}}processRows(t){if(!this.dataSource)return[...t];const e=this.config.cacheBlockSize??100,o=Number.isFinite(this.totalNodeCount)&&this.totalNodeCount>=0?this.totalNodeCount:0;for(;this.managedNodes.length<o;){const t=this.managedNodes.length;this.managedNodes.push({__loading:!0,__index:t})}this.managedNodes.length=o;for(let s=0;s<o;s++){const t=i(s,e,this.loadedBlocks);t&&(this.managedNodes[s]=t)}return this.managedNodes}onScroll(t){this.dataSource&&(this.loadRequiredBlocks(),this.scrollDebounceTimer&&clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=setTimeout(()=>{this.loadRequiredBlocks()},100))}handleQuery(t){switch(t.type){case"datasource:is-active":return null!=this.dataSource;case"datasource:fetch-children":{const{context:e}=t.context;return void this.fetchChildren(e)}}}fetchChildren(t){if(!this.dataSource)return;const o=this.grid?.getAttribute?.("id")??void 0;if(!this.dataSource.getChildRows)return void e.warnDiagnostic(e.DATASOURCE_NO_CHILD_HANDLER,`Plugin "${t.source}" requested child rows but getChildRows() is not implemented on the dataSource`,o);const s=this.getEnrichmentParams();this.broadcast("datasource:loading",{loading:!0,context:t}),this.dataSource.getChildRows({context:t,sortModel:s.sortModel,filterModel:s.filterModel}).then(e=>{const o={rows:e.rows,context:t,claimed:!1};this.broadcast("datasource:children",o),this.broadcast("datasource:loading",{loading:!1,context:t})}).catch(s=>{const a=s instanceof Error?s:new Error(String(s));e.errorDiagnostic(e.DATASOURCE_CHILD_FETCH_ERROR,`getChildRows() failed: ${a.message}`,o),this.broadcast("datasource:error",{error:a,context:t}),this.broadcast("datasource:loading",{loading:!1,context:t})})}setDataSource(t){this.dataSource=t,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.totalNodeCount=0;const o=this.config.cacheBlockSize??100,s=this.getEnrichmentParams(),i=this.grid?.getAttribute?.("id")??void 0;this.broadcast("datasource:loading",{loading:!0}),a(t,0,o,s).then(t=>{this.loadedBlocks.set(0,t.rows),this.totalNodeCount=t.totalNodeCount;const e={rows:t.rows,totalNodeCount:t.totalNodeCount,startNode:0,endNode:t.rows.length,claimed:!1};this.broadcast("datasource:data",e),this.broadcast("datasource:loading",{loading:!1}),this.requestRender()}).catch(t=>{const o=t instanceof Error?t:new Error(String(t));e.errorDiagnostic(e.DATASOURCE_FETCH_ERROR,`getRows() failed: ${o.message}`,i),this.broadcast("datasource:error",{error:o}),this.broadcast("datasource:loading",{loading:!1})})}refresh(){if(!this.dataSource)return;const t=this.dataSource;this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.totalNodeCount=0,this.setDataSource(t)}purgeCache(){this.loadedBlocks.clear(),this.managedNodes=[]}getTotalNodeCount(){return this.totalNodeCount}getTotalRowCount(){return this.totalNodeCount}isNodeLoaded(t){const e=s(t,this.config.cacheBlockSize??100);return this.loadedBlocks.has(e)}isRowLoaded(t){return this.isNodeLoaded(t)}getLoadedBlockCount(){return this.loadedBlocks.size}}t.ServerSidePlugin=r,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("../../core/internal/diagnostics"),require("../../core/plugin/base-plugin")):"function"==typeof define&&define.amd?define(["exports","../../core/internal/diagnostics","../../core/plugin/base-plugin"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TbwGridPlugin_serverSide={},t.TbwGrid,t.TbwGrid)}(this,function(t,e,o){"use strict";function i(t,e){return Math.floor(t/e)}async function s(t,e,o,i){const s=function(t,e){return{start:t*e,end:(t+1)*e}}(e,o);return t.getRows({startNode:s.start,endNode:s.end,sortModel:i.sortModel,filterModel:i.filterModel})}function a(t,e,o){const s=i(t,e),a=o.get(s);if(!a)return;return a[t%e]}class r extends o.BaseGridPlugin{static manifest={modifiesRowStructure:!0,hookPriority:{processRows:-10},incompatibleWith:[{name:"pivot",reason:"PivotPlugin requires the full dataset to compute aggregations. ServerSidePlugin lazy-loads rows in blocks, so pivot aggregation cannot be performed client-side."}],events:[{type:"datasource:data",description:"Root data page/block loaded"},{type:"datasource:children",description:"Child data loaded for a parent context"},{type:"datasource:loading",description:"Loading state changed"},{type:"datasource:error",description:"Fetch operation failed"}],queries:[{type:"datasource:fetch-children",description:"Request child rows for a parent context"},{type:"datasource:is-active",description:"Check if ServerSide plugin has an active data source"}]};name="serverSide";get defaultConfig(){return{pageSize:100,cacheBlockSize:100,maxConcurrentRequests:2}}dataSource=null;totalNodeCount=0;infiniteScrollMode=!1;loadedBlocks=new Map;loadingBlocks=new Set;lastRequestId=0;scrollDebounceTimer;managedNodes=[];attach(t){super.attach(t),this.on("sort-change",()=>this.onModelChange()),this.on("filter-change",()=>this.onModelChange())}detach(){this.dataSource=null,this.totalNodeCount=0,this.infiniteScrollMode=!1,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.lastRequestId=0,this.scrollDebounceTimer&&(clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=void 0)}getEnrichmentParams(){const t=this.grid?.query?.("sort:get-model",null),e=this.grid?.query?.("filter:get-model",null);return{sortModel:t?.[0],filterModel:e?.[0]}}getViewportMapping(t,e){const o={viewportStart:t,viewportEnd:e},i=this.grid?.query?.("datasource:viewport-mapping",o);return i?.[0]?i[0]:{startNode:t,endNode:e,totalLoadedNodes:this.totalNodeCount}}onModelChange(){this.dataSource&&(this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.totalNodeCount=0,this.infiniteScrollMode=!1,this.requestRender())}applyServerResult(t,e,o){void 0!==t.lastNode?(this.totalNodeCount=t.lastNode+1,this.infiniteScrollMode=!1):-1===t.totalNodeCount?this.infiniteScrollMode=!0:(this.totalNodeCount=t.totalNodeCount,this.infiniteScrollMode=!1),this.infiniteScrollMode&&t.rows.length<o&&(this.totalNodeCount=e*o+t.rows.length,this.infiniteScrollMode=!1)}getInfiniteScrollEstimate(t){let e=0;for(const[o,i]of this.loadedBlocks){const s=o*t+i.length;s>e&&(e=s)}return e+t}loadRequiredBlocks(){if(!this.dataSource)return;const t=this.grid,o=this.config.cacheBlockSize??100,a=this.getViewportMapping(t._virtualization.start,t._virtualization.end),r=function(t,e,o){const s=i(t,o),a=i(e-1,o),r=[];for(let i=s;i<=a;i++)r.push(i);return r}(a.startNode,a.endNode,o),d=this.getEnrichmentParams(),n=this.grid?.getAttribute?.("id")??void 0;for(const i of r)if(!this.loadedBlocks.has(i)&&!this.loadingBlocks.has(i)){if(this.loadingBlocks.size>=(this.config.maxConcurrentRequests??2)){e.debugDiagnostic(e.DATASOURCE_THROTTLED,"Concurrent request limit reached, deferring block load",n);break}this.loadingBlocks.add(i),this.broadcast("datasource:loading",{loading:!0}),s(this.dataSource,i,o,d).then(t=>{this.loadedBlocks.set(i,t.rows),this.applyServerResult(t,i,o),this.loadingBlocks.delete(i);const e=i*o;for(let o=0;o<t.rows.length;o++)e+o<this.managedNodes.length&&(this.managedNodes[e+o]=t.rows[o]);const s={rows:t.rows,totalNodeCount:t.totalNodeCount,startNode:e,endNode:e+t.rows.length,claimed:!1};this.broadcast("datasource:data",s),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}),this.requestVirtualRefresh(),this.loadRequiredBlocks()}).catch(t=>{this.loadingBlocks.delete(i);const o=t instanceof Error?t:new Error(String(t));e.errorDiagnostic(e.DATASOURCE_FETCH_ERROR,`getRows() failed: ${o.message}`,n),this.broadcast("datasource:error",{error:o}),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1})})}}processRows(t){if(!this.dataSource)return[...t];const e=this.config.cacheBlockSize??100,o=this.infiniteScrollMode?this.getInfiniteScrollEstimate(e):Number.isFinite(this.totalNodeCount)&&this.totalNodeCount>=0?this.totalNodeCount:0;for(;this.managedNodes.length<o;){const t=this.managedNodes.length;this.managedNodes.push({__loading:!0,__index:t})}this.managedNodes.length=o;for(let i=0;i<o;i++){const t=a(i,e,this.loadedBlocks);t&&(this.managedNodes[i]=t)}return this.managedNodes}onScroll(t){this.dataSource&&(this.loadRequiredBlocks(),this.scrollDebounceTimer&&clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=setTimeout(()=>{this.loadRequiredBlocks()},100))}handleQuery(t){switch(t.type){case"datasource:is-active":return null!=this.dataSource;case"datasource:fetch-children":{const{context:e}=t.context;return void this.fetchChildren(e)}}}fetchChildren(t){if(!this.dataSource)return;const o=this.grid?.getAttribute?.("id")??void 0;if(!this.dataSource.getChildRows)return void e.warnDiagnostic(e.DATASOURCE_NO_CHILD_HANDLER,`Plugin "${t.source}" requested child rows but getChildRows() is not implemented on the dataSource`,o);const i=this.getEnrichmentParams();this.broadcast("datasource:loading",{loading:!0,context:t}),this.dataSource.getChildRows({context:t,sortModel:i.sortModel,filterModel:i.filterModel}).then(e=>{const o={rows:e.rows,context:t,claimed:!1};this.broadcast("datasource:children",o),this.broadcast("datasource:loading",{loading:!1,context:t})}).catch(i=>{const s=i instanceof Error?i:new Error(String(i));e.errorDiagnostic(e.DATASOURCE_CHILD_FETCH_ERROR,`getChildRows() failed: ${s.message}`,o),this.broadcast("datasource:error",{error:s,context:t}),this.broadcast("datasource:loading",{loading:!1,context:t})})}setDataSource(t){this.dataSource=t,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.totalNodeCount=0,this.infiniteScrollMode=!1;const o=this.config.cacheBlockSize??100,i=this.getEnrichmentParams(),a=this.grid?.getAttribute?.("id")??void 0;this.broadcast("datasource:loading",{loading:!0}),s(t,0,o,i).then(t=>{this.loadedBlocks.set(0,t.rows),this.applyServerResult(t,0,o);const e={rows:t.rows,totalNodeCount:t.totalNodeCount,startNode:0,endNode:t.rows.length,claimed:!1};this.broadcast("datasource:data",e),this.broadcast("datasource:loading",{loading:!1}),this.requestRender()}).catch(t=>{const o=t instanceof Error?t:new Error(String(t));e.errorDiagnostic(e.DATASOURCE_FETCH_ERROR,`getRows() failed: ${o.message}`,a),this.broadcast("datasource:error",{error:o}),this.broadcast("datasource:loading",{loading:!1})})}refresh(){if(!this.dataSource)return;const t=this.dataSource;this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.totalNodeCount=0,this.infiniteScrollMode=!1,this.setDataSource(t)}purgeCache(){this.loadedBlocks.clear(),this.managedNodes=[]}getTotalNodeCount(){return this.totalNodeCount}getTotalRowCount(){return this.totalNodeCount}isNodeLoaded(t){const e=i(t,this.config.cacheBlockSize??100);return this.loadedBlocks.has(e)}isRowLoaded(t){return this.isNodeLoaded(t)}getLoadedBlockCount(){return this.loadedBlocks.size}}t.ServerSidePlugin=r,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
2
2
  //# sourceMappingURL=server-side.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server-side.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/server-side/datasource.ts","../../../../../libs/grid/src/lib/plugins/server-side/ServerSidePlugin.ts"],"sourcesContent":["import type { GetRowsParams, GetRowsResult, ServerSideDataSource } from './datasource-types';\n\nexport function getBlockNumber(nodeIndex: number, blockSize: number): number {\n return Math.floor(nodeIndex / blockSize);\n}\n\nexport function getBlockRange(blockNumber: number, blockSize: number): { start: number; end: number } {\n return {\n start: blockNumber * blockSize,\n end: (blockNumber + 1) * blockSize,\n };\n}\n\nexport function getRequiredBlocks(startNode: number, endNode: number, blockSize: number): number[] {\n const startBlock = getBlockNumber(startNode, blockSize);\n const endBlock = getBlockNumber(endNode - 1, blockSize);\n\n const blocks: number[] = [];\n for (let i = startBlock; i <= endBlock; i++) {\n blocks.push(i);\n }\n return blocks;\n}\n\nexport async function loadBlock(\n dataSource: ServerSideDataSource,\n blockNumber: number,\n blockSize: number,\n params: Partial<GetRowsParams>,\n): Promise<GetRowsResult> {\n const range = getBlockRange(blockNumber, blockSize);\n\n return dataSource.getRows({\n startNode: range.start,\n endNode: range.end,\n sortModel: params.sortModel,\n filterModel: params.filterModel,\n });\n}\n\nexport function getRowFromCache(\n nodeIndex: number,\n blockSize: number,\n loadedBlocks: Map<number, unknown[]>,\n): unknown | undefined {\n const blockNumber = getBlockNumber(nodeIndex, blockSize);\n const block = loadedBlocks.get(blockNumber);\n if (!block) return undefined;\n\n const indexInBlock = nodeIndex % blockSize;\n return block[indexInBlock];\n}\n\nexport function isBlockLoaded(blockNumber: number, loadedBlocks: Map<number, unknown[]>): boolean {\n return loadedBlocks.has(blockNumber);\n}\n\nexport function isBlockLoading(blockNumber: number, loadingBlocks: Set<number>): boolean {\n return loadingBlocks.has(blockNumber);\n}\n","/**\n * Server-Side Data Plugin (Class-based)\n *\n * Central data orchestrator for the grid. Owns fetch + cache + row-model management.\n * Structural plugins (Tree, GroupingRows) claim data via events; core grid uses it\n * as flat rows when unclaimed.\n */\n\nimport {\n DATASOURCE_CHILD_FETCH_ERROR,\n DATASOURCE_FETCH_ERROR,\n DATASOURCE_NO_CHILD_HANDLER,\n DATASOURCE_THROTTLED,\n debugDiagnostic,\n errorDiagnostic,\n warnDiagnostic,\n} from '../../core/internal/diagnostics';\nimport { BaseGridPlugin, ScrollEvent, type PluginManifest, type PluginQuery } from '../../core/plugin/base-plugin';\nimport type { GridHost } from '../../core/types';\nimport { getBlockNumber, getRequiredBlocks, getRowFromCache, loadBlock } from './datasource';\nimport type {\n DataSourceChildrenDetail,\n DataSourceDataDetail,\n DataSourceErrorDetail,\n DataSourceLoadingDetail,\n FetchChildrenQuery,\n GetRowsParams,\n ServerSideDataSource,\n ViewportMappingQuery,\n ViewportMappingResponse,\n} from './datasource-types';\nimport type { ServerSideConfig } from './types';\n\n/** Scroll debounce delay in ms */\nconst SCROLL_DEBOUNCE_MS = 100;\n\n/**\n * Server-Side Data Plugin for tbw-grid\n *\n * Central data orchestrator for the grid. Manages fetch, cache, and row-model for\n * server-side data loading. Structural plugins (Tree, GroupingRows) can claim data\n * via events; the core grid uses it as flat rows when unclaimed.\n *\n * ## Installation\n *\n * ```ts\n * import { ServerSidePlugin } from '@toolbox-web/grid/plugins/server-side';\n * ```\n *\n * ## DataSource Interface\n *\n * ```ts\n * interface ServerSideDataSource {\n * getRows(params: GetRowsParams): Promise<GetRowsResult>;\n * getChildRows?(params: GetChildRowsParams): Promise<GetChildRowsResult>;\n * }\n * ```\n *\n * @example Basic Server-Side Loading\n * ```ts\n * import '@toolbox-web/grid';\n * import { ServerSidePlugin } from '@toolbox-web/grid/plugins/server-side';\n *\n * const dataSource = {\n * async getRows(params) {\n * const response = await fetch(\n * `/api/data?start=${params.startNode}&end=${params.endNode}`\n * );\n * const data = await response.json();\n * return { rows: data.rows, totalNodeCount: data.total };\n * },\n * };\n *\n * const plugin = new ServerSidePlugin({ pageSize: 50 });\n * grid.gridConfig = {\n * columns: [...],\n * plugins: [plugin],\n * };\n *\n * grid.ready().then(() => plugin.setDataSource(dataSource));\n * ```\n *\n * @see {@link ServerSideConfig} for configuration options\n * @see {@link ServerSideDataSource} for data source interface\n *\n * @internal Extends BaseGridPlugin\n */\nexport class ServerSidePlugin extends BaseGridPlugin<ServerSideConfig> {\n /**\n * Plugin manifest declaring capabilities, hooks, events, and queries.\n * @internal\n */\n static override readonly manifest: PluginManifest = {\n modifiesRowStructure: true,\n hookPriority: {\n processRows: -10, // Run before structural plugins (Tree, GroupingRows)\n },\n incompatibleWith: [\n {\n name: 'pivot',\n reason:\n 'PivotPlugin requires the full dataset to compute aggregations. ' +\n 'ServerSidePlugin lazy-loads rows in blocks, so pivot aggregation cannot be performed client-side.',\n },\n ],\n events: [\n { type: 'datasource:data', description: 'Root data page/block loaded' },\n { type: 'datasource:children', description: 'Child data loaded for a parent context' },\n { type: 'datasource:loading', description: 'Loading state changed' },\n { type: 'datasource:error', description: 'Fetch operation failed' },\n ],\n queries: [\n { type: 'datasource:fetch-children', description: 'Request child rows for a parent context' },\n { type: 'datasource:is-active', description: 'Check if ServerSide plugin has an active data source' },\n ],\n };\n\n /** @internal */\n readonly name = 'serverSide';\n\n /** @internal */\n protected override get defaultConfig(): Partial<ServerSideConfig> {\n return {\n pageSize: 100,\n cacheBlockSize: 100,\n maxConcurrentRequests: 2,\n };\n }\n\n // #region Internal State\n private dataSource: ServerSideDataSource | null = null;\n private totalNodeCount = 0;\n private loadedBlocks = new Map<number, unknown[]>();\n private loadingBlocks = new Set<number>();\n private lastRequestId = 0;\n private scrollDebounceTimer?: ReturnType<typeof setTimeout>;\n /** Persistent node array with stable placeholder references to avoid unnecessary DOM rebuilds. */\n private managedNodes: unknown[] = [];\n // #endregion\n\n // #region Lifecycle\n\n /** @internal */\n override attach(grid: import('../../core/plugin/base-plugin').GridElement): void {\n super.attach(grid);\n\n // Invalidate cache and refetch on sort/filter changes\n this.on('sort-change', () => this.onModelChange());\n this.on('filter-change', () => this.onModelChange());\n }\n\n /** @internal */\n override detach(): void {\n this.dataSource = null;\n this.totalNodeCount = 0;\n this.loadedBlocks.clear();\n this.loadingBlocks.clear();\n this.managedNodes = [];\n this.lastRequestId = 0;\n if (this.scrollDebounceTimer) {\n clearTimeout(this.scrollDebounceTimer);\n this.scrollDebounceTimer = undefined;\n }\n }\n // #endregion\n\n // #region Private Methods\n\n /**\n * Build enrichment params by querying sort/filter models from loaded plugins.\n */\n private getEnrichmentParams(): Partial<GetRowsParams> {\n const sortResults = this.grid?.query?.('sort:get-model', null) as\n | Array<{ field: string; direction: 'asc' | 'desc' }>[]\n | undefined;\n const filterResults = this.grid?.query?.('filter:get-model', null) as Record<string, unknown>[] | undefined;\n\n return {\n sortModel: sortResults?.[0],\n filterModel: filterResults?.[0],\n };\n }\n\n /**\n * Translate visible viewport indices to node-space indices via structural plugins.\n * Falls back to 1:1 mapping (flat data) when no structural plugin responds.\n */\n private getViewportMapping(viewportStart: number, viewportEnd: number): ViewportMappingResponse {\n const query: ViewportMappingQuery = { viewportStart, viewportEnd };\n const results = this.grid?.query?.('datasource:viewport-mapping', query) as ViewportMappingResponse[] | undefined;\n\n // Structural plugin responded — use its mapping\n if (results?.[0]) return results[0];\n\n // No structural plugin → 1:1 mapping (flat data)\n return {\n startNode: viewportStart,\n endNode: viewportEnd,\n totalLoadedNodes: this.totalNodeCount,\n };\n }\n\n /**\n * Handle sort or filter model changes.\n * Purge cache and refetch current viewport with new enrichment params.\n */\n private onModelChange(): void {\n if (!this.dataSource) return;\n this.loadedBlocks.clear();\n this.loadingBlocks.clear();\n this.managedNodes = [];\n this.totalNodeCount = 0;\n this.requestRender();\n }\n\n /**\n * Check current viewport and load any missing blocks.\n */\n private loadRequiredBlocks(): void {\n if (!this.dataSource) return;\n\n const gridRef = this.grid as unknown as GridHost;\n const blockSize = this.config.cacheBlockSize ?? 100;\n\n // Translate viewport to node space via structural plugins\n const viewport = this.getViewportMapping(gridRef._virtualization.start, gridRef._virtualization.end);\n\n // Determine which blocks are needed for current viewport (in node space)\n const requiredBlocks = getRequiredBlocks(viewport.startNode, viewport.endNode, blockSize);\n const enrichment = this.getEnrichmentParams();\n const gridId = this.grid?.getAttribute?.('id') ?? undefined;\n\n // Load missing blocks\n for (const blockNum of requiredBlocks) {\n if (this.loadedBlocks.has(blockNum) || this.loadingBlocks.has(blockNum)) {\n continue;\n }\n\n // Check concurrent request limit\n if (this.loadingBlocks.size >= (this.config.maxConcurrentRequests ?? 2)) {\n debugDiagnostic(DATASOURCE_THROTTLED, 'Concurrent request limit reached, deferring block load', gridId);\n break;\n }\n\n this.loadingBlocks.add(blockNum);\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: true });\n\n loadBlock(this.dataSource, blockNum, blockSize, enrichment)\n .then((result) => {\n this.loadedBlocks.set(blockNum, result.rows);\n this.totalNodeCount = result.totalNodeCount;\n this.loadingBlocks.delete(blockNum);\n\n // Update managed nodes in place for this block (avoids full processRows rebuild)\n const start = blockNum * blockSize;\n for (let i = 0; i < result.rows.length; i++) {\n if (start + i < this.managedNodes.length) {\n this.managedNodes[start + i] = result.rows[i];\n }\n }\n\n // Broadcast data event with claimed flag\n const detail: DataSourceDataDetail = {\n rows: result.rows,\n totalNodeCount: result.totalNodeCount,\n startNode: start,\n endNode: start + result.rows.length,\n claimed: false,\n };\n this.broadcast('datasource:data', detail);\n\n if (this.loadingBlocks.size === 0) {\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: false });\n }\n\n // Re-render visible rows without force geometry recalculation.\n // requestVirtualRefresh() skips spacer height writes that cause oscillation\n // with the scheduler's afterRender microtask. Node count hasn't changed —\n // only cached data replaced placeholders — so geometry is stable.\n this.requestVirtualRefresh();\n\n // Re-check with fresh viewport: user may have scrolled further\n this.loadRequiredBlocks();\n })\n .catch((error: unknown) => {\n this.loadingBlocks.delete(blockNum);\n const err = error instanceof Error ? error : new Error(String(error));\n errorDiagnostic(DATASOURCE_FETCH_ERROR, `getRows() failed: ${err.message}`, gridId);\n this.broadcast<DataSourceErrorDetail>('datasource:error', { error: err });\n\n if (this.loadingBlocks.size === 0) {\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: false });\n }\n });\n }\n }\n // #endregion\n\n // #region Hooks\n\n /** @internal */\n override processRows(rows: readonly unknown[]): unknown[] {\n if (!this.dataSource) return [...rows];\n\n const blockSize = this.config.cacheBlockSize ?? 100;\n\n // Guard against invalid totalNodeCount (e.g. undefined from a malformed datasource response,\n // or -1 for infinite scroll mode where the total is unknown).\n const nodeCount = Number.isFinite(this.totalNodeCount) && this.totalNodeCount >= 0 ? this.totalNodeCount : 0;\n\n // Grow array with stable placeholder objects (created once, reused across renders)\n while (this.managedNodes.length < nodeCount) {\n const i = this.managedNodes.length;\n this.managedNodes.push({ __loading: true, __index: i });\n }\n // Shrink if total decreased\n this.managedNodes.length = nodeCount;\n\n // Replace placeholders with cached data (stable refs for unchanged entries)\n for (let i = 0; i < nodeCount; i++) {\n const cached = getRowFromCache(i, blockSize, this.loadedBlocks);\n if (cached) {\n this.managedNodes[i] = cached;\n }\n }\n\n return this.managedNodes;\n }\n\n /** @internal */\n override onScroll(event: ScrollEvent): void {\n if (!this.dataSource) return;\n\n // Immediate check for blocks\n this.loadRequiredBlocks();\n\n // Debounce: when scrolling stops, do a final check with fresh viewport\n if (this.scrollDebounceTimer) {\n clearTimeout(this.scrollDebounceTimer);\n }\n this.scrollDebounceTimer = setTimeout(() => {\n this.loadRequiredBlocks();\n }, SCROLL_DEBOUNCE_MS);\n }\n\n /** @internal */\n override handleQuery(query: PluginQuery): unknown {\n switch (query.type) {\n case 'datasource:is-active':\n return this.dataSource != null;\n\n case 'datasource:fetch-children': {\n const { context } = query.context as FetchChildrenQuery;\n this.fetchChildren(context);\n return undefined;\n }\n }\n return undefined;\n }\n // #endregion\n\n // #region Child Data Fetching\n\n /**\n * Fetch child rows via the datasource and broadcast the result.\n */\n private fetchChildren(context: { source: string; [key: string]: unknown }): void {\n if (!this.dataSource) return;\n\n const gridId = this.grid?.getAttribute?.('id') ?? undefined;\n\n if (!this.dataSource.getChildRows) {\n warnDiagnostic(\n DATASOURCE_NO_CHILD_HANDLER,\n `Plugin \"${context.source}\" requested child rows but getChildRows() is not implemented on the dataSource`,\n gridId,\n );\n return;\n }\n\n const enrichment = this.getEnrichmentParams();\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: true, context });\n\n this.dataSource\n .getChildRows({ context, sortModel: enrichment.sortModel, filterModel: enrichment.filterModel })\n .then((result) => {\n const detail: DataSourceChildrenDetail = {\n rows: result.rows,\n context,\n claimed: false,\n };\n this.broadcast('datasource:children', detail);\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: false, context });\n })\n .catch((error: unknown) => {\n const err = error instanceof Error ? error : new Error(String(error));\n errorDiagnostic(DATASOURCE_CHILD_FETCH_ERROR, `getChildRows() failed: ${err.message}`, gridId);\n this.broadcast<DataSourceErrorDetail>('datasource:error', { error: err, context });\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: false, context });\n });\n }\n // #endregion\n\n // #region Public API\n\n /**\n * Set the data source for server-side loading.\n * @param dataSource - Data source implementing the getRows method (and optionally getChildRows)\n */\n setDataSource(dataSource: ServerSideDataSource): void {\n this.dataSource = dataSource;\n this.loadedBlocks.clear();\n this.loadingBlocks.clear();\n this.managedNodes = [];\n this.totalNodeCount = 0;\n\n // Load first block with enrichment params\n const blockSize = this.config.cacheBlockSize ?? 100;\n const enrichment = this.getEnrichmentParams();\n const gridId = this.grid?.getAttribute?.('id') ?? undefined;\n\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: true });\n\n loadBlock(dataSource, 0, blockSize, enrichment)\n .then((result) => {\n this.loadedBlocks.set(0, result.rows);\n this.totalNodeCount = result.totalNodeCount;\n\n const detail: DataSourceDataDetail = {\n rows: result.rows,\n totalNodeCount: result.totalNodeCount,\n startNode: 0,\n endNode: result.rows.length,\n claimed: false,\n };\n this.broadcast('datasource:data', detail);\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: false });\n this.requestRender();\n })\n .catch((error: unknown) => {\n const err = error instanceof Error ? error : new Error(String(error));\n errorDiagnostic(DATASOURCE_FETCH_ERROR, `getRows() failed: ${err.message}`, gridId);\n this.broadcast<DataSourceErrorDetail>('datasource:error', { error: err });\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: false });\n });\n }\n\n /**\n * Refresh all data from the server.\n * Purges cache and refetches from block 0.\n */\n refresh(): void {\n if (!this.dataSource) return;\n const ds = this.dataSource;\n this.loadedBlocks.clear();\n this.loadingBlocks.clear();\n this.managedNodes = [];\n this.totalNodeCount = 0;\n // Re-trigger load via setDataSource which handles enrichment and broadcasting\n this.setDataSource(ds);\n }\n\n /**\n * Clear all cached data without refreshing.\n */\n purgeCache(): void {\n this.loadedBlocks.clear();\n this.managedNodes = [];\n }\n\n /**\n * Get the total node count from the server.\n */\n getTotalNodeCount(): number {\n return this.totalNodeCount;\n }\n\n /**\n * @deprecated Use {@link getTotalNodeCount} instead. Will be removed in a future version.\n */\n getTotalRowCount(): number {\n return this.totalNodeCount;\n }\n\n /**\n * Check if a specific node is loaded in the cache.\n * @param nodeIndex - Node index to check\n */\n isNodeLoaded(nodeIndex: number): boolean {\n const blockSize = this.config.cacheBlockSize ?? 100;\n const blockNum = getBlockNumber(nodeIndex, blockSize);\n return this.loadedBlocks.has(blockNum);\n }\n\n /**\n * @deprecated Use {@link isNodeLoaded} instead. Will be removed in a future version.\n */\n isRowLoaded(rowIndex: number): boolean {\n return this.isNodeLoaded(rowIndex);\n }\n\n /**\n * Get the number of loaded cache blocks.\n */\n getLoadedBlockCount(): number {\n return this.loadedBlocks.size;\n }\n // #endregion\n}\n"],"names":["getBlockNumber","nodeIndex","blockSize","Math","floor","async","loadBlock","dataSource","blockNumber","params","range","start","end","getBlockRange","getRows","startNode","endNode","sortModel","filterModel","getRowFromCache","loadedBlocks","block","get","ServerSidePlugin","BaseGridPlugin","static","modifiesRowStructure","hookPriority","processRows","incompatibleWith","name","reason","events","type","description","queries","defaultConfig","pageSize","cacheBlockSize","maxConcurrentRequests","totalNodeCount","Map","loadingBlocks","Set","lastRequestId","scrollDebounceTimer","managedNodes","attach","grid","super","this","on","onModelChange","detach","clear","clearTimeout","getEnrichmentParams","sortResults","query","filterResults","getViewportMapping","viewportStart","viewportEnd","results","totalLoadedNodes","requestRender","loadRequiredBlocks","gridRef","config","viewport","_virtualization","requiredBlocks","startBlock","endBlock","blocks","i","push","getRequiredBlocks","enrichment","gridId","getAttribute","blockNum","has","size","debugDiagnostic","DATASOURCE_THROTTLED","add","broadcast","loading","then","result","set","rows","delete","length","detail","claimed","requestVirtualRefresh","catch","error","err","Error","String","errorDiagnostic","DATASOURCE_FETCH_ERROR","message","nodeCount","Number","isFinite","__loading","__index","cached","onScroll","event","setTimeout","handleQuery","context","fetchChildren","getChildRows","warnDiagnostic","DATASOURCE_NO_CHILD_HANDLER","source","DATASOURCE_CHILD_FETCH_ERROR","setDataSource","refresh","ds","purgeCache","getTotalNodeCount","getTotalRowCount","isNodeLoaded","isRowLoaded","rowIndex","getLoadedBlockCount"],"mappings":"6aAEO,SAASA,EAAeC,EAAmBC,GAChD,OAAOC,KAAKC,MAAMH,EAAYC,EAChC,CAoBAG,eAAsBC,EACpBC,EACAC,EACAN,EACAO,GAEA,MAAMC,EAxBD,SAAuBF,EAAqBN,GACjD,MAAO,CACLS,MAAOH,EAAcN,EACrBU,KAAMJ,EAAc,GAAKN,EAE7B,CAmBgBW,CAAcL,EAAaN,GAEzC,OAAOK,EAAWO,QAAQ,CACxBC,UAAWL,EAAMC,MACjBK,QAASN,EAAME,IACfK,UAAWR,EAAOQ,UAClBC,YAAaT,EAAOS,aAExB,CAEO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BJ,KAAKJ,aAAe,GACpBI,KAAKV,eAAiB,EAEtBU,KAAKyE,cAAcE,EACrB,CAKA,UAAAC,GACE5E,KAAK9B,aAAakC,QAClBJ,KAAKJ,aAAe,EACtB,CAKA,iBAAAiF,GACE,OAAO7E,KAAKV,cACd,CAKA,gBAAAwF,GACE,OAAO9E,KAAKV,cACd,CAMA,YAAAyF,CAAahI,GACX,MACMgF,EAAWjF,EAAeC,EADdiD,KAAKkB,OAAO9B,gBAAkB,KAEhD,OAAOY,KAAK9B,aAAa8D,IAAID,EAC/B,CAKA,WAAAiD,CAAYC,GACV,OAAOjF,KAAK+E,aAAaE,EAC3B,CAKA,mBAAAC,GACE,OAAOlF,KAAK9B,aAAa+D,IAC3B"}
1
+ {"version":3,"file":"server-side.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/server-side/datasource.ts","../../../../../libs/grid/src/lib/plugins/server-side/ServerSidePlugin.ts"],"sourcesContent":["import type { GetRowsParams, GetRowsResult, ServerSideDataSource } from './datasource-types';\n\nexport function getBlockNumber(nodeIndex: number, blockSize: number): number {\n return Math.floor(nodeIndex / blockSize);\n}\n\nexport function getBlockRange(blockNumber: number, blockSize: number): { start: number; end: number } {\n return {\n start: blockNumber * blockSize,\n end: (blockNumber + 1) * blockSize,\n };\n}\n\nexport function getRequiredBlocks(startNode: number, endNode: number, blockSize: number): number[] {\n const startBlock = getBlockNumber(startNode, blockSize);\n const endBlock = getBlockNumber(endNode - 1, blockSize);\n\n const blocks: number[] = [];\n for (let i = startBlock; i <= endBlock; i++) {\n blocks.push(i);\n }\n return blocks;\n}\n\nexport async function loadBlock(\n dataSource: ServerSideDataSource,\n blockNumber: number,\n blockSize: number,\n params: Partial<GetRowsParams>,\n): Promise<GetRowsResult> {\n const range = getBlockRange(blockNumber, blockSize);\n\n return dataSource.getRows({\n startNode: range.start,\n endNode: range.end,\n sortModel: params.sortModel,\n filterModel: params.filterModel,\n });\n}\n\nexport function getRowFromCache(\n nodeIndex: number,\n blockSize: number,\n loadedBlocks: Map<number, unknown[]>,\n): unknown | undefined {\n const blockNumber = getBlockNumber(nodeIndex, blockSize);\n const block = loadedBlocks.get(blockNumber);\n if (!block) return undefined;\n\n const indexInBlock = nodeIndex % blockSize;\n return block[indexInBlock];\n}\n\nexport function isBlockLoaded(blockNumber: number, loadedBlocks: Map<number, unknown[]>): boolean {\n return loadedBlocks.has(blockNumber);\n}\n\nexport function isBlockLoading(blockNumber: number, loadingBlocks: Set<number>): boolean {\n return loadingBlocks.has(blockNumber);\n}\n","/**\n * Server-Side Data Plugin (Class-based)\n *\n * Central data orchestrator for the grid. Owns fetch + cache + row-model management.\n * Structural plugins (Tree, GroupingRows) claim data via events; core grid uses it\n * as flat rows when unclaimed.\n */\n\nimport {\n DATASOURCE_CHILD_FETCH_ERROR,\n DATASOURCE_FETCH_ERROR,\n DATASOURCE_NO_CHILD_HANDLER,\n DATASOURCE_THROTTLED,\n debugDiagnostic,\n errorDiagnostic,\n warnDiagnostic,\n} from '../../core/internal/diagnostics';\nimport { BaseGridPlugin, ScrollEvent, type PluginManifest, type PluginQuery } from '../../core/plugin/base-plugin';\nimport type { GridHost } from '../../core/types';\nimport { getBlockNumber, getRequiredBlocks, getRowFromCache, loadBlock } from './datasource';\nimport type {\n DataSourceChildrenDetail,\n DataSourceDataDetail,\n DataSourceErrorDetail,\n DataSourceLoadingDetail,\n FetchChildrenQuery,\n GetRowsParams,\n GetRowsResult,\n ServerSideDataSource,\n ViewportMappingQuery,\n ViewportMappingResponse,\n} from './datasource-types';\nimport type { ServerSideConfig } from './types';\n\n/** Scroll debounce delay in ms */\nconst SCROLL_DEBOUNCE_MS = 100;\n\n/**\n * Server-Side Data Plugin for tbw-grid\n *\n * Central data orchestrator for the grid. Manages fetch, cache, and row-model for\n * server-side data loading. Structural plugins (Tree, GroupingRows) can claim data\n * via events; the core grid uses it as flat rows when unclaimed.\n *\n * ## Installation\n *\n * ```ts\n * import { ServerSidePlugin } from '@toolbox-web/grid/plugins/server-side';\n * ```\n *\n * ## DataSource Interface\n *\n * ```ts\n * interface ServerSideDataSource {\n * getRows(params: GetRowsParams): Promise<GetRowsResult>;\n * getChildRows?(params: GetChildRowsParams): Promise<GetChildRowsResult>;\n * }\n * ```\n *\n * @example Basic Server-Side Loading\n * ```ts\n * import '@toolbox-web/grid';\n * import { ServerSidePlugin } from '@toolbox-web/grid/plugins/server-side';\n *\n * const dataSource = {\n * async getRows(params) {\n * const response = await fetch(\n * `/api/data?start=${params.startNode}&end=${params.endNode}`\n * );\n * const data = await response.json();\n * return { rows: data.rows, totalNodeCount: data.total };\n * },\n * };\n *\n * const plugin = new ServerSidePlugin({ pageSize: 50 });\n * grid.gridConfig = {\n * columns: [...],\n * plugins: [plugin],\n * };\n *\n * grid.ready().then(() => plugin.setDataSource(dataSource));\n * ```\n *\n * @see {@link ServerSideConfig} for configuration options\n * @see {@link ServerSideDataSource} for data source interface\n *\n * @internal Extends BaseGridPlugin\n */\nexport class ServerSidePlugin extends BaseGridPlugin<ServerSideConfig> {\n /**\n * Plugin manifest declaring capabilities, hooks, events, and queries.\n * @internal\n */\n static override readonly manifest: PluginManifest = {\n modifiesRowStructure: true,\n hookPriority: {\n processRows: -10, // Run before structural plugins (Tree, GroupingRows)\n },\n incompatibleWith: [\n {\n name: 'pivot',\n reason:\n 'PivotPlugin requires the full dataset to compute aggregations. ' +\n 'ServerSidePlugin lazy-loads rows in blocks, so pivot aggregation cannot be performed client-side.',\n },\n ],\n events: [\n { type: 'datasource:data', description: 'Root data page/block loaded' },\n { type: 'datasource:children', description: 'Child data loaded for a parent context' },\n { type: 'datasource:loading', description: 'Loading state changed' },\n { type: 'datasource:error', description: 'Fetch operation failed' },\n ],\n queries: [\n { type: 'datasource:fetch-children', description: 'Request child rows for a parent context' },\n { type: 'datasource:is-active', description: 'Check if ServerSide plugin has an active data source' },\n ],\n };\n\n /** @internal */\n readonly name = 'serverSide';\n\n /** @internal */\n protected override get defaultConfig(): Partial<ServerSideConfig> {\n return {\n pageSize: 100,\n cacheBlockSize: 100,\n maxConcurrentRequests: 2,\n };\n }\n\n // #region Internal State\n private dataSource: ServerSideDataSource | null = null;\n private totalNodeCount = 0;\n private infiniteScrollMode = false;\n private loadedBlocks = new Map<number, unknown[]>();\n private loadingBlocks = new Set<number>();\n private lastRequestId = 0;\n private scrollDebounceTimer?: ReturnType<typeof setTimeout>;\n /** Persistent node array with stable placeholder references to avoid unnecessary DOM rebuilds. */\n private managedNodes: unknown[] = [];\n // #endregion\n\n // #region Lifecycle\n\n /** @internal */\n override attach(grid: import('../../core/plugin/base-plugin').GridElement): void {\n super.attach(grid);\n\n // Invalidate cache and refetch on sort/filter changes\n this.on('sort-change', () => this.onModelChange());\n this.on('filter-change', () => this.onModelChange());\n }\n\n /** @internal */\n override detach(): void {\n this.dataSource = null;\n this.totalNodeCount = 0;\n this.infiniteScrollMode = false;\n this.loadedBlocks.clear();\n this.loadingBlocks.clear();\n this.managedNodes = [];\n this.lastRequestId = 0;\n if (this.scrollDebounceTimer) {\n clearTimeout(this.scrollDebounceTimer);\n this.scrollDebounceTimer = undefined;\n }\n }\n // #endregion\n\n // #region Private Methods\n\n /**\n * Build enrichment params by querying sort/filter models from loaded plugins.\n */\n private getEnrichmentParams(): Partial<GetRowsParams> {\n const sortResults = this.grid?.query?.('sort:get-model', null) as\n | Array<{ field: string; direction: 'asc' | 'desc' }>[]\n | undefined;\n const filterResults = this.grid?.query?.('filter:get-model', null) as Record<string, unknown>[] | undefined;\n\n return {\n sortModel: sortResults?.[0],\n filterModel: filterResults?.[0],\n };\n }\n\n /**\n * Translate visible viewport indices to node-space indices via structural plugins.\n * Falls back to 1:1 mapping (flat data) when no structural plugin responds.\n */\n private getViewportMapping(viewportStart: number, viewportEnd: number): ViewportMappingResponse {\n const query: ViewportMappingQuery = { viewportStart, viewportEnd };\n const results = this.grid?.query?.('datasource:viewport-mapping', query) as ViewportMappingResponse[] | undefined;\n\n // Structural plugin responded — use its mapping\n if (results?.[0]) return results[0];\n\n // No structural plugin → 1:1 mapping (flat data)\n return {\n startNode: viewportStart,\n endNode: viewportEnd,\n totalLoadedNodes: this.totalNodeCount,\n };\n }\n\n /**\n * Handle sort or filter model changes.\n * Purge cache and refetch current viewport with new enrichment params.\n */\n private onModelChange(): void {\n if (!this.dataSource) return;\n this.loadedBlocks.clear();\n this.loadingBlocks.clear();\n this.managedNodes = [];\n this.totalNodeCount = 0;\n this.infiniteScrollMode = false;\n this.requestRender();\n }\n\n /**\n * Apply server response metadata: resolve totalNodeCount and infinite scroll mode.\n * When `lastNode` is provided, it takes priority and finalizes the total.\n * When `totalNodeCount` is -1, switch to infinite scroll (growing array).\n * When a block returns fewer rows than blockSize, detect end-of-data.\n */\n private applyServerResult(result: GetRowsResult, blockNum: number, blockSize: number): void {\n if (result.lastNode !== undefined) {\n // Server declared the exact end\n this.totalNodeCount = result.lastNode + 1;\n this.infiniteScrollMode = false;\n } else if (result.totalNodeCount === -1) {\n this.infiniteScrollMode = true;\n } else {\n this.totalNodeCount = result.totalNodeCount;\n this.infiniteScrollMode = false;\n }\n\n // Auto-detect end of data: short block means server has no more rows\n if (this.infiniteScrollMode && result.rows.length < blockSize) {\n this.totalNodeCount = blockNum * blockSize + result.rows.length;\n this.infiniteScrollMode = false;\n }\n }\n\n /**\n * Estimate the row count for infinite scroll mode.\n * Returns loaded rows + one extra block of placeholders to trigger next fetch.\n */\n private getInfiniteScrollEstimate(blockSize: number): number {\n let maxLoadedEnd = 0;\n for (const [block, rows] of this.loadedBlocks) {\n const end = block * blockSize + rows.length;\n if (end > maxLoadedEnd) maxLoadedEnd = end;\n }\n return maxLoadedEnd + blockSize;\n }\n\n /**\n * Check current viewport and load any missing blocks.\n */\n private loadRequiredBlocks(): void {\n if (!this.dataSource) return;\n\n const gridRef = this.grid as unknown as GridHost;\n const blockSize = this.config.cacheBlockSize ?? 100;\n\n // Translate viewport to node space via structural plugins\n const viewport = this.getViewportMapping(gridRef._virtualization.start, gridRef._virtualization.end);\n\n // Determine which blocks are needed for current viewport (in node space)\n const requiredBlocks = getRequiredBlocks(viewport.startNode, viewport.endNode, blockSize);\n const enrichment = this.getEnrichmentParams();\n const gridId = this.grid?.getAttribute?.('id') ?? undefined;\n\n // Load missing blocks\n for (const blockNum of requiredBlocks) {\n if (this.loadedBlocks.has(blockNum) || this.loadingBlocks.has(blockNum)) {\n continue;\n }\n\n // Check concurrent request limit\n if (this.loadingBlocks.size >= (this.config.maxConcurrentRequests ?? 2)) {\n debugDiagnostic(DATASOURCE_THROTTLED, 'Concurrent request limit reached, deferring block load', gridId);\n break;\n }\n\n this.loadingBlocks.add(blockNum);\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: true });\n\n loadBlock(this.dataSource, blockNum, blockSize, enrichment)\n .then((result) => {\n this.loadedBlocks.set(blockNum, result.rows);\n this.applyServerResult(result, blockNum, blockSize);\n this.loadingBlocks.delete(blockNum);\n\n // Update managed nodes in place for this block (avoids full processRows rebuild)\n const start = blockNum * blockSize;\n for (let i = 0; i < result.rows.length; i++) {\n if (start + i < this.managedNodes.length) {\n this.managedNodes[start + i] = result.rows[i];\n }\n }\n\n // Broadcast data event with claimed flag\n const detail: DataSourceDataDetail = {\n rows: result.rows,\n totalNodeCount: result.totalNodeCount,\n startNode: start,\n endNode: start + result.rows.length,\n claimed: false,\n };\n this.broadcast('datasource:data', detail);\n\n if (this.loadingBlocks.size === 0) {\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: false });\n }\n\n // Re-render visible rows without force geometry recalculation.\n // requestVirtualRefresh() skips spacer height writes that cause oscillation\n // with the scheduler's afterRender microtask. Node count hasn't changed —\n // only cached data replaced placeholders — so geometry is stable.\n this.requestVirtualRefresh();\n\n // Re-check with fresh viewport: user may have scrolled further\n this.loadRequiredBlocks();\n })\n .catch((error: unknown) => {\n this.loadingBlocks.delete(blockNum);\n const err = error instanceof Error ? error : new Error(String(error));\n errorDiagnostic(DATASOURCE_FETCH_ERROR, `getRows() failed: ${err.message}`, gridId);\n this.broadcast<DataSourceErrorDetail>('datasource:error', { error: err });\n\n if (this.loadingBlocks.size === 0) {\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: false });\n }\n });\n }\n }\n // #endregion\n\n // #region Hooks\n\n /** @internal */\n override processRows(rows: readonly unknown[]): unknown[] {\n if (!this.dataSource) return [...rows];\n\n const blockSize = this.config.cacheBlockSize ?? 100;\n\n // Guard against invalid totalNodeCount (e.g. undefined from a malformed datasource response).\n // In infinite scroll mode, estimate the total from loaded data + one extra block.\n const nodeCount = this.infiniteScrollMode\n ? this.getInfiniteScrollEstimate(blockSize)\n : Number.isFinite(this.totalNodeCount) && this.totalNodeCount >= 0\n ? this.totalNodeCount\n : 0;\n\n // Grow array with stable placeholder objects (created once, reused across renders)\n while (this.managedNodes.length < nodeCount) {\n const i = this.managedNodes.length;\n this.managedNodes.push({ __loading: true, __index: i });\n }\n // Shrink if total decreased\n this.managedNodes.length = nodeCount;\n\n // Replace placeholders with cached data (stable refs for unchanged entries)\n for (let i = 0; i < nodeCount; i++) {\n const cached = getRowFromCache(i, blockSize, this.loadedBlocks);\n if (cached) {\n this.managedNodes[i] = cached;\n }\n }\n\n return this.managedNodes;\n }\n\n /** @internal */\n override onScroll(event: ScrollEvent): void {\n if (!this.dataSource) return;\n\n // Immediate check for blocks\n this.loadRequiredBlocks();\n\n // Debounce: when scrolling stops, do a final check with fresh viewport\n if (this.scrollDebounceTimer) {\n clearTimeout(this.scrollDebounceTimer);\n }\n this.scrollDebounceTimer = setTimeout(() => {\n this.loadRequiredBlocks();\n }, SCROLL_DEBOUNCE_MS);\n }\n\n /** @internal */\n override handleQuery(query: PluginQuery): unknown {\n switch (query.type) {\n case 'datasource:is-active':\n return this.dataSource != null;\n\n case 'datasource:fetch-children': {\n const { context } = query.context as FetchChildrenQuery;\n this.fetchChildren(context);\n return undefined;\n }\n }\n return undefined;\n }\n // #endregion\n\n // #region Child Data Fetching\n\n /**\n * Fetch child rows via the datasource and broadcast the result.\n */\n private fetchChildren(context: { source: string; [key: string]: unknown }): void {\n if (!this.dataSource) return;\n\n const gridId = this.grid?.getAttribute?.('id') ?? undefined;\n\n if (!this.dataSource.getChildRows) {\n warnDiagnostic(\n DATASOURCE_NO_CHILD_HANDLER,\n `Plugin \"${context.source}\" requested child rows but getChildRows() is not implemented on the dataSource`,\n gridId,\n );\n return;\n }\n\n const enrichment = this.getEnrichmentParams();\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: true, context });\n\n this.dataSource\n .getChildRows({ context, sortModel: enrichment.sortModel, filterModel: enrichment.filterModel })\n .then((result) => {\n const detail: DataSourceChildrenDetail = {\n rows: result.rows,\n context,\n claimed: false,\n };\n this.broadcast('datasource:children', detail);\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: false, context });\n })\n .catch((error: unknown) => {\n const err = error instanceof Error ? error : new Error(String(error));\n errorDiagnostic(DATASOURCE_CHILD_FETCH_ERROR, `getChildRows() failed: ${err.message}`, gridId);\n this.broadcast<DataSourceErrorDetail>('datasource:error', { error: err, context });\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: false, context });\n });\n }\n // #endregion\n\n // #region Public API\n\n /**\n * Set the data source for server-side loading.\n * @param dataSource - Data source implementing the getRows method (and optionally getChildRows)\n */\n setDataSource(dataSource: ServerSideDataSource): void {\n this.dataSource = dataSource;\n this.loadedBlocks.clear();\n this.loadingBlocks.clear();\n this.managedNodes = [];\n this.totalNodeCount = 0;\n this.infiniteScrollMode = false;\n\n // Load first block with enrichment params\n const blockSize = this.config.cacheBlockSize ?? 100;\n const enrichment = this.getEnrichmentParams();\n const gridId = this.grid?.getAttribute?.('id') ?? undefined;\n\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: true });\n\n loadBlock(dataSource, 0, blockSize, enrichment)\n .then((result) => {\n this.loadedBlocks.set(0, result.rows);\n this.applyServerResult(result, 0, blockSize);\n\n const detail: DataSourceDataDetail = {\n rows: result.rows,\n totalNodeCount: result.totalNodeCount,\n startNode: 0,\n endNode: result.rows.length,\n claimed: false,\n };\n this.broadcast('datasource:data', detail);\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: false });\n this.requestRender();\n })\n .catch((error: unknown) => {\n const err = error instanceof Error ? error : new Error(String(error));\n errorDiagnostic(DATASOURCE_FETCH_ERROR, `getRows() failed: ${err.message}`, gridId);\n this.broadcast<DataSourceErrorDetail>('datasource:error', { error: err });\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: false });\n });\n }\n\n /**\n * Refresh all data from the server.\n * Purges cache and refetches from block 0.\n */\n refresh(): void {\n if (!this.dataSource) return;\n const ds = this.dataSource;\n this.loadedBlocks.clear();\n this.loadingBlocks.clear();\n this.managedNodes = [];\n this.totalNodeCount = 0;\n this.infiniteScrollMode = false;\n // Re-trigger load via setDataSource which handles enrichment and broadcasting\n this.setDataSource(ds);\n }\n\n /**\n * Clear all cached data without refreshing.\n */\n purgeCache(): void {\n this.loadedBlocks.clear();\n this.managedNodes = [];\n }\n\n /**\n * Get the total node count from the server.\n */\n getTotalNodeCount(): number {\n return this.totalNodeCount;\n }\n\n /**\n * @deprecated Use {@link getTotalNodeCount} instead. Will be removed in a future version.\n */\n getTotalRowCount(): number {\n return this.totalNodeCount;\n }\n\n /**\n * Check if a specific node is loaded in the cache.\n * @param nodeIndex - Node index to check\n */\n isNodeLoaded(nodeIndex: number): boolean {\n const blockSize = this.config.cacheBlockSize ?? 100;\n const blockNum = getBlockNumber(nodeIndex, blockSize);\n return this.loadedBlocks.has(blockNum);\n }\n\n /**\n * @deprecated Use {@link isNodeLoaded} instead. Will be removed in a future version.\n */\n isRowLoaded(rowIndex: number): boolean {\n return this.isNodeLoaded(rowIndex);\n }\n\n /**\n * Get the number of loaded cache blocks.\n */\n getLoadedBlockCount(): number {\n return this.loadedBlocks.size;\n }\n // #endregion\n}\n"],"names":["getBlockNumber","nodeIndex","blockSize","Math","floor","async","loadBlock","dataSource","blockNumber","params","range","start","end","getBlockRange","getRows","startNode","endNode","sortModel","filterModel","getRowFromCache","loadedBlocks","block","get","ServerSidePlugin","BaseGridPlugin","static","modifiesRowStructure","hookPriority","processRows","incompatibleWith","name","reason","events","type","description","queries","defaultConfig","pageSize","cacheBlockSize","maxConcurrentRequests","totalNodeCount","infiniteScrollMode","Map","loadingBlocks","Set","lastRequestId","scrollDebounceTimer","managedNodes","attach","grid","super","this","on","onModelChange","detach","clear","clearTimeout","getEnrichmentParams","sortResults","query","filterResults","getViewportMapping","viewportStart","viewportEnd","results","totalLoadedNodes","requestRender","applyServerResult","result","blockNum","lastNode","rows","length","getInfiniteScrollEstimate","maxLoadedEnd","loadRequiredBlocks","gridRef","config","viewport","_virtualization","requiredBlocks","startBlock","endBlock","blocks","i","push","getRequiredBlocks","enrichment","gridId","getAttribute","has","size","debugDiagnostic","DATASOURCE_THROTTLED","add","broadcast","loading","then","set","delete","detail","claimed","requestVirtualRefresh","catch","error","err","Error","String","errorDiagnostic","DATASOURCE_FETCH_ERROR","message","nodeCount","Number","isFinite","__loading","__index","cached","onScroll","event","setTimeout","handleQuery","context","fetchChildren","getChildRows","warnDiagnostic","DATASOURCE_NO_CHILD_HANDLER","source","DATASOURCE_CHILD_FETCH_ERROR","setDataSource","refresh","ds","purgeCache","getTotalNodeCount","getTotalRowCount","isNodeLoaded","isRowLoaded","rowIndex","getLoadedBlockCount"],"mappings":"6aAEO,SAASA,EAAeC,EAAmBC,GAChD,OAAOC,KAAKC,MAAMH,EAAYC,EAChC,CAoBAG,eAAsBC,EACpBC,EACAC,EACAN,EACAO,GAEA,MAAMC,EAxBD,SAAuBF,EAAqBN,GACjD,MAAO,CACLS,MAAOH,EAAcN,EACrBU,KAAMJ,EAAc,GAAKN,EAE7B,CAmBgBW,CAAcL,EAAaN,GAEzC,OAAOK,EAAWO,QAAQ,CACxBC,UAAWL,EAAMC,MACjBK,QAASN,EAAME,IACfK,UAAWR,EAAOQ,UAClBC,YAAaT,EAAOS,aAExB,CAEO,SAASC,EACdlB,E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eof exports&&"undefined"!=typeof module?o(exports,require("../../core/plugin/base-plugin")):"function"==typeof define&&define.amd?define(["exports","../../core/plugin/base-plugin"],o):o((t="undefined"!=typeof globalThis?globalThis:t||self).TbwGridPlugin_tooltip={},t.TbwGrid)}(this,function(t,o){"use strict";function e(t){return t.scrollWidth>t.clientWidth}function r(){return"function"==typeof HTMLElement.prototype?.showPopover}class i extends o.BaseGridPlugin{name="tooltip";styles='@layer tbw-plugins{.tbw-tooltip-popover{margin:0;padding:var(--tbw-tooltip-padding, var(--tbw-spacing-sm, .375rem) var(--tbw-spacing-md, .5rem));background:var(--tbw-tooltip-bg, light-dark(#333338, #484850));color:var(--tbw-tooltip-fg, light-dark(#f5f5f5, #f0f0f0));border:1px solid var(--tbw-tooltip-border, light-dark(#222226, #6a6a72));border-radius:var(--tbw-tooltip-radius, var(--tbw-border-radius, .25rem));box-shadow:none;filter:var(--tbw-tooltip-shadow, drop-shadow(0 4px 4px rgba(0, 0, 0, .45)));font-family:var(--tbw-font-family, system-ui, sans-serif);font-size:var(--tbw-tooltip-font-size, var(--tbw-font-size-sm, .9285em));max-width:var(--tbw-tooltip-max-width, 300px);white-space:pre-line;word-wrap:break-word;overflow-wrap:break-word;pointer-events:none;z-index:10001}.tbw-tooltip-popover:after{content:"";position:absolute;width:var(--tbw-tooltip-arrow-size, 14px);height:var(--tbw-tooltip-arrow-size, 14px);left:var(--tbw-tooltip-arrow-offset, 16px);background:inherit;pointer-events:none}.tbw-tooltip-popover:not(.tbw-tooltip-above):after{top:calc(var(--tbw-tooltip-arrow-size, 14px) / -2);transform:rotate(45deg);border-top:1px solid var(--tbw-tooltip-border, light-dark(#222226, #6a6a72));border-left:1px solid var(--tbw-tooltip-border, light-dark(#222226, #6a6a72))}.tbw-tooltip-popover.tbw-tooltip-above:after{bottom:calc(var(--tbw-tooltip-arrow-size, 14px) / -2);transform:rotate(45deg);border-bottom:1px solid var(--tbw-tooltip-border, light-dark(#222226, #6a6a72));border-right:1px solid var(--tbw-tooltip-border, light-dark(#222226, #6a6a72))}@supports (anchor-name: --test){.tbw-tooltip-popover{position-anchor:--tbw-tooltip-anchor;top:calc(anchor(bottom) + 11px);left:anchor(left);position-try-fallbacks:--tbw-tooltip-flip-above}@position-try --tbw-tooltip-flip-above{top:auto;bottom:calc(anchor(top) + 11px)}}}';static manifest={ownedProperties:[{property:"cellTooltip",level:"column",description:'the "cellTooltip" column property'},{property:"headerTooltip",level:"column",description:'the "headerTooltip" column property'}],configRules:[]};#t=null;#o=null;#e=!1;get#r(){return!1!==this.config.header}get#i(){return!1!==this.config.cell}attach(t){super.attach(t)}detach(){this.#l(),this.#t?.remove(),this.#t=null,this.#e=!1,super.detach()}afterRender(){this.#n(),this.#s()}#n(){if(this.#t)return;const t=document.createElement("div");t.className="tbw-tooltip-popover",t.setAttribute("popover","hint"),t.style.overflow="visible",t.style.margin="0",document.body.appendChild(t),this.#t=t}#p(t,o){if(this.#t){if(this.#a(),t.style.setProperty("anchor-name","--tbw-tooltip-anchor"),this.#o=t,this.#t.textContent=o,r())try{this.#t.showPopover()}catch{}"undefined"!=typeof CSS&&!0===CSS.supports?.("anchor-name","--test")?requestAnimationFrame(()=>this.#c(t)):this.#d(t)}}#l(){if(this.#t){if(r())try{this.#t.hidePopover()}catch{}this.#t.classList.remove("tbw-tooltip-above")}this.#a()}#a(){this.#o&&("--tbw-tooltip-anchor"===this.#o.style.getPropertyValue("anchor-name")&&this.#o.style.removeProperty("anchor-name"),this.#o=null)}#d(t){if(!this.#t)return;const o=t.getBoundingClientRect();this.#t.style.position="fixed",this.#t.style.left=`${o.left}px`;window.innerHeight-o.bottom<80?(this.#t.style.top="",this.#t.style.bottom=window.innerHeight-o.top+11+"px",this.#t.classList.add("tbw-tooltip-above")):(this.#t.style.top=`${o.bottom+11}px`,this.#t.style.bottom="",this.#t.classList.remove("tbw-tooltip-above"))}#c(t){if(!this.#t)return;const o=t.getBoundingClientRect(),e=this.#t.getBoundingClientRect();this.#t.classList.toggle("tbw-tooltip-above",e.bottom<=o.top)}#s(){if(this.#e)return;const t=this.gridElement?.querySelector(".tbw-grid-root");t&&(this.#e=!0,t.addEventListener("mouseover",t=>this.#h(t),{signal:this.disconnectSignal}),t.addEventListener("mouseout",t=>this.#u(t),{signal:this.disconnectSignal}))}#h(t){const o=t.target;if(!o?.closest)return;const e=o.closest('[part~="header-cell"]');if(e&&this.#r)return void this.#b(e);const r=o.closest("[data-row][data-col]");r&&this.#i&&!r.style.getPropertyValue("anchor-name")&&this.#f(r)}#u(t){const o=t.target;if(!o?.closest)return;const e=o.closest('[part~="header-cell"], [data-row][data-col]');if(!e)return;const r=t.relatedTarget;r&&e.contains(r)||this.#l()}#b(t){const o=parseInt(t.getAttribute("data-col")??"-1",10);if(o<0)return;const r=this.visibleColumns[o];if(!r)return;const i=function(t,o){const r=t.headerTooltip;if(!1===r)return null;if("string"==typeof r)return r;if("function"==typeof r)return r({column:t,value:t.header??t.field});const i=o.querySelector("span:first-child")??o;return e(i)&&i.textContent?.trim()||null}(r,t);i&&this.#p(t,i)}#f(t){const o=parseInt(t.getAttribute("data-row")??"-1",10),r=parseInt(t.getAttribute("data-col")??"-1",10);if(o<0||r<0)return;const i=this.visibleColumns[r];if(!i)return;const l=this.rows[o],n=l?.[i.field],s=function(t,o,r,i){const l=t.cellTooltip;if(!1===l)return null;if("string"==typeof l)return l;if("function"==typeof l)return l({value:i,row:r,column:t,field:t.field});return e(o)&&o.textContent?.trim()||null}(i,t,l,n);s&&this.#p(t,s)}}t.TooltipPlugin=i,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
1
+ !function(t,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("../../core/plugin/base-plugin")):"function"==typeof define&&define.amd?define(["exports","../../core/plugin/base-plugin"],o):o((t="undefined"!=typeof globalThis?globalThis:t||self).TbwGridPlugin_tooltip={},t.TbwGrid)}(this,function(t,o){"use strict";function e(t){return t.scrollWidth>t.clientWidth}function r(){return"function"==typeof HTMLElement.prototype?.showPopover}class i extends o.BaseGridPlugin{name="tooltip";styles='@layer tbw-plugins{.tbw-tooltip-popover{margin:0;padding:var(--tbw-tooltip-padding, var(--tbw-spacing-sm, .375rem) var(--tbw-spacing-md, .5rem));background:var(--tbw-tooltip-bg, light-dark(#333338, #484850));color:var(--tbw-tooltip-fg, light-dark(#f5f5f5, #f0f0f0));border:1px solid var(--tbw-tooltip-border, light-dark(#222226, #6a6a72));border-radius:var(--tbw-tooltip-radius, var(--tbw-border-radius, .25rem));box-shadow:none;filter:var(--tbw-tooltip-shadow, drop-shadow(0 4px 4px rgba(0, 0, 0, .45)));font-family:var(--tbw-font-family, system-ui, sans-serif);font-size:var(--tbw-tooltip-font-size, var(--tbw-font-size-sm, .9285em));max-width:var(--tbw-tooltip-max-width, 300px);white-space:pre-line;word-wrap:break-word;overflow-wrap:break-word;pointer-events:none;z-index:10001}.tbw-tooltip-popover:after{content:"";position:absolute;width:var(--tbw-tooltip-arrow-size, 14px);height:var(--tbw-tooltip-arrow-size, 14px);left:var(--tbw-tooltip-arrow-offset, 16px);background:inherit;pointer-events:none}.tbw-tooltip-popover:not(.tbw-tooltip-above):after{top:calc(var(--tbw-tooltip-arrow-size, 14px) / -2);transform:rotate(45deg);border-top:1px solid var(--tbw-tooltip-border, light-dark(#222226, #6a6a72));border-left:1px solid var(--tbw-tooltip-border, light-dark(#222226, #6a6a72))}.tbw-tooltip-popover.tbw-tooltip-above:after{bottom:calc(var(--tbw-tooltip-arrow-size, 14px) / -2);transform:rotate(45deg);border-bottom:1px solid var(--tbw-tooltip-border, light-dark(#222226, #6a6a72));border-right:1px solid var(--tbw-tooltip-border, light-dark(#222226, #6a6a72))}@supports (anchor-name: --test){.tbw-tooltip-popover{position-anchor:--tbw-tooltip-anchor;top:calc(anchor(bottom) + 11px);left:anchor(left);position-try-fallbacks:--tbw-tooltip-flip-above}@position-try --tbw-tooltip-flip-above{top:auto;bottom:calc(anchor(top) + 11px)}}}';static manifest={ownedProperties:[{property:"cellTooltip",level:"column",description:'the "cellTooltip" column property'},{property:"headerTooltip",level:"column",description:'the "headerTooltip" column property'}],configRules:[]};#t=null;#o=null;#e=!1;get#r(){return!1!==this.config.header}get#i(){return!1!==this.config.cell}attach(t){super.attach(t)}detach(){this.#l(),this.#t?.remove(),this.#t=null,this.#e=!1,super.detach()}afterRender(){this.#n(),this.#s()}#n(){if(this.#t)return;const t=document.createElement("div");t.className="tbw-tooltip-popover",t.setAttribute("popover","hint"),t.style.overflow="visible",t.style.margin="0",document.body.appendChild(t),this.#t=t}#p(t,o){if(this.#t){if(this.#a(),t.style.setProperty("anchor-name","--tbw-tooltip-anchor"),this.#o=t,this.#t.textContent=o,r())try{this.#t.showPopover()}catch{}"undefined"!=typeof CSS&&!0===CSS.supports?.("anchor-name","--test")?requestAnimationFrame(()=>this.#c(t)):this.#d(t)}}#l(){if(this.#t){if(r())try{this.#t.hidePopover()}catch{}this.#t.classList.remove("tbw-tooltip-above")}this.#a()}#a(){this.#o&&("--tbw-tooltip-anchor"===this.#o.style.getPropertyValue("anchor-name")&&this.#o.style.removeProperty("anchor-name"),this.#o=null)}#d(t){if(!this.#t)return;const o=t.getBoundingClientRect();this.#t.style.position="fixed",this.#t.style.left=`${o.left}px`;window.innerHeight-o.bottom<80?(this.#t.style.top="",this.#t.style.bottom=window.innerHeight-o.top+11+"px",this.#t.classList.add("tbw-tooltip-above")):(this.#t.style.top=`${o.bottom+11}px`,this.#t.style.bottom="",this.#t.classList.remove("tbw-tooltip-above"))}#c(t){if(!this.#t)return;const o=t.getBoundingClientRect(),e=this.#t.getBoundingClientRect();this.#t.classList.toggle("tbw-tooltip-above",e.bottom<=o.top)}#s(){if(this.#e)return;const t=this.gridElement?.querySelector(".tbw-grid-root");t&&(this.#e=!0,t.addEventListener("mouseover",t=>this.#h(t),{signal:this.disconnectSignal}),t.addEventListener("mouseout",t=>this.#u(t),{signal:this.disconnectSignal}))}#h(t){const o=t.target;if(!o?.closest)return;const e=o.closest('[part~="header-cell"]');if(e&&this.#r)return void this.#b(e);const r=o.closest("[data-row][data-col]");r&&this.#i&&!r.style.getPropertyValue("anchor-name")&&this.#f(r)}#u(t){const o=t.target;if(!o?.closest)return;const e=o.closest('[part~="header-cell"], [data-row][data-col]');if(!e)return;const r=t.relatedTarget;r&&e.contains(r)||this.#l()}#b(t){const o=parseInt(t.getAttribute("data-col")??"-1",10);if(o<0)return;const r=this.visibleColumns[o];if(!r)return;const i=function(t,o){const r=t.headerTooltip;if(!1===r)return null;if("string"==typeof r)return r;if("function"==typeof r)return r({column:t,value:t.header??t.field});const i=o.querySelector("span:first-child")??o;return e(i)&&i.textContent?.trim()||null}(r,t);i&&this.#p(t,i)}#f(t){const o=parseInt(t.getAttribute("data-row")??"-1",10),r=parseInt(t.getAttribute("data-col")??"-1",10);if(o<0||r<0)return;const i=this.visibleColumns[r];if(!i)return;const l=this.rows[o],n=l?.[i.field],s=function(t,o,r,i,l){const n=t.cellTooltip;if(!1===n)return null;if("string"==typeof n)return n;if("function"==typeof n)return n({value:i,row:r,column:t,field:t.field,grid:l});return e(o)&&o.textContent?.trim()||null}(i,t,l,n,this.grid);s&&this.#p(t,s)}}t.TooltipPlugin=i,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
2
2
  //# sourceMappingURL=tooltip.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/tooltip/TooltipPlugin.ts"],"sourcesContent":["/**\n * Tooltip Plugin\n *\n * Shows styled popover tooltips on header and data cells when text\n * overflows (ellipsis). Uses the Popover API (`popover=\"hint\"`) with\n * CSS anchor positioning for consistent, themed placement.\n *\n * Supports per-column overrides via `cellTooltip` and `headerTooltip`\n * on column config.\n */\n\nimport type { GridElement, PluginManifest } from '../../core/plugin/base-plugin';\nimport { BaseGridPlugin } from '../../core/plugin/base-plugin';\nimport type { CellRenderContext, ColumnConfig, HeaderLabelContext } from '../../core/types';\nimport tooltipStyles from './tooltip.css?inline';\nimport type { TooltipConfig } from './types';\n\n// #region Helpers\n\n/** Check if an element's text content overflows its visible width. */\nfunction isOverflowing(el: HTMLElement): boolean {\n return el.scrollWidth > el.clientWidth;\n}\n\n/**\n * Resolve the tooltip text for a cell.\n * Returns the text to show, or `null` to suppress.\n */\nfunction resolveCellTooltip(column: ColumnConfig, cell: HTMLElement, row: unknown, value: unknown): string | null {\n const spec = column.cellTooltip;\n\n if (spec === false) return null;\n if (typeof spec === 'string') return spec;\n if (typeof spec === 'function') {\n const ctx: CellRenderContext = { value, row, column, field: column.field };\n return spec(ctx);\n }\n\n // Default: show textContent only when overflowing\n if (isOverflowing(cell)) {\n return cell.textContent?.trim() || null;\n }\n\n return null;\n}\n\n/**\n * Resolve the tooltip text for a header cell.\n * Returns the text to show, or `null` to suppress.\n */\nfunction resolveHeaderTooltip(column: ColumnConfig, headerCell: HTMLElement): string | null {\n const spec = column.headerTooltip;\n\n if (spec === false) return null;\n if (typeof spec === 'string') return spec;\n if (typeof spec === 'function') {\n const ctx: HeaderLabelContext = {\n column,\n value: column.header ?? column.field,\n };\n return spec(ctx);\n }\n\n // Default: show header text only when overflowing\n const labelSpan = headerCell.querySelector('span:first-child') as HTMLElement | null;\n const target = labelSpan ?? headerCell;\n\n if (isOverflowing(target)) {\n return target.textContent?.trim() || null;\n }\n\n return null;\n}\n\n/** Runtime check — happy-dom and older browsers may lack Popover API. */\nfunction supportsPopover(): boolean {\n return typeof HTMLElement.prototype?.showPopover === 'function';\n}\n\n/** Runtime check for CSS anchor positioning. */\nfunction supportsAnchor(): boolean {\n return typeof CSS !== 'undefined' && CSS.supports?.('anchor-name', '--test') === true;\n}\n// #endregion\n\n// #region TooltipPlugin\n/**\n * Tooltip Plugin for tbw-grid\n *\n * Shows styled popover tooltips when header or cell text overflows its\n * container. Uses the Popover API with CSS anchor positioning for\n * consistent themed appearance across light and dark modes.\n *\n * ## Installation\n *\n * ```ts\n * import { TooltipPlugin } from '@toolbox-web/grid/plugins/tooltip';\n * ```\n *\n * @example Default — auto-tooltip on overflow\n * ```ts\n * grid.gridConfig = {\n * plugins: [new TooltipPlugin()],\n * };\n * ```\n *\n * @example Header-only tooltips\n * ```ts\n * grid.gridConfig = {\n * plugins: [new TooltipPlugin({ cell: false })],\n * };\n * ```\n *\n * @example Per-column overrides\n * ```ts\n * grid.gridConfig = {\n * columns: [\n * { field: 'name', cellTooltip: (ctx) => `${ctx.row.first} ${ctx.row.last}` },\n * { field: 'actions', cellTooltip: false },\n * { field: 'revenue', headerTooltip: 'Total revenue in USD (before tax)' },\n * ],\n * plugins: [new TooltipPlugin()],\n * };\n * ```\n *\n * @category Plugins\n */\nexport class TooltipPlugin extends BaseGridPlugin<TooltipConfig> {\n readonly name = 'tooltip';\n override readonly styles = tooltipStyles;\n\n static override readonly manifest: PluginManifest<TooltipConfig> = {\n ownedProperties: [\n { property: 'cellTooltip', level: 'column', description: 'the \"cellTooltip\" column property' },\n { property: 'headerTooltip', level: 'column', description: 'the \"headerTooltip\" column property' },\n ],\n configRules: [],\n };\n\n /** The shared popover element for all tooltips. */\n #popoverEl: HTMLElement | null = null;\n\n /** The cell currently acting as CSS anchor. */\n #anchorCell: HTMLElement | null = null;\n\n /** Whether delegated listeners are bound. */\n #bound = false;\n\n /** Whether header tooltips are enabled globally. */\n get #headerEnabled(): boolean {\n return this.config.header !== false;\n }\n\n /** Whether cell tooltips are enabled globally. */\n get #cellEnabled(): boolean {\n return this.config.cell !== false;\n }\n\n override attach(grid: GridElement): void {\n super.attach(grid);\n }\n\n override detach(): void {\n this.#hideTooltip();\n this.#popoverEl?.remove();\n this.#popoverEl = null;\n this.#bound = false;\n super.detach();\n }\n\n override afterRender(): void {\n this.#ensurePopover();\n this.#bindEvents();\n }\n\n // #region Popover Lifecycle\n\n /** Create the shared popover element (once). */\n #ensurePopover(): void {\n if (this.#popoverEl) return;\n const el = document.createElement('div');\n el.className = 'tbw-tooltip-popover';\n el.setAttribute('popover', 'hint');\n // Override UA popover defaults that @layer CSS cannot beat\n el.style.overflow = 'visible';\n el.style.margin = '0';\n document.body.appendChild(el);\n this.#popoverEl = el;\n }\n\n /** Show the popover anchored to `cell` with the given `text`. */\n #showTooltip(cell: HTMLElement, text: string): void {\n if (!this.#popoverEl) return;\n\n // Move the CSS anchor to the hovered cell\n this.#clearAnchor();\n cell.style.setProperty('anchor-name', '--tbw-tooltip-anchor');\n this.#anchorCell = cell;\n\n // Set content (always textContent — safe, no XSS)\n this.#popoverEl.textContent = text;\n\n // Show via Popover API\n if (supportsPopover()) {\n try {\n this.#popoverEl.showPopover();\n } catch {\n /* already shown */\n }\n }\n\n if (supportsAnchor()) {\n // Detect flip after the browser resolves position-try-fallbacks\n requestAnimationFrame(() => this.#detectFlip(cell));\n } else {\n this.#positionFallback(cell);\n }\n }\n\n /** Hide the popover and clear the anchor reference. */\n #hideTooltip(): void {\n if (this.#popoverEl) {\n if (supportsPopover()) {\n try {\n this.#popoverEl.hidePopover();\n } catch {\n /* already hidden */\n }\n }\n this.#popoverEl.classList.remove('tbw-tooltip-above');\n }\n this.#clearAnchor();\n }\n\n /** Remove the CSS anchor-name from the previous cell, but only if it's still our tooltip anchor. */\n #clearAnchor(): void {\n if (this.#anchorCell) {\n if (this.#anchorCell.style.getPropertyValue('anchor-name') === '--tbw-tooltip-anchor') {\n this.#anchorCell.style.removeProperty('anchor-name');\n }\n this.#anchorCell = null;\n }\n }\n\n /**\n * Fallback positioning for browsers without CSS anchor support.\n * Places the popover below or above the cell using fixed coordinates.\n */\n #positionFallback(cell: HTMLElement): void {\n if (!this.#popoverEl) return;\n const cellRect = cell.getBoundingClientRect();\n const arrowGap = 11;\n\n this.#popoverEl.style.position = 'fixed';\n this.#popoverEl.style.left = `${cellRect.left}px`;\n\n // Check if there's space below\n const spaceBelow = window.innerHeight - cellRect.bottom;\n if (spaceBelow < 80) {\n // Place above the cell\n this.#popoverEl.style.top = '';\n this.#popoverEl.style.bottom = `${window.innerHeight - cellRect.top + arrowGap}px`;\n this.#popoverEl.classList.add('tbw-tooltip-above');\n } else {\n this.#popoverEl.style.top = `${cellRect.bottom + arrowGap}px`;\n this.#popoverEl.style.bottom = '';\n this.#popoverEl.classList.remove('tbw-tooltip-above');\n }\n }\n\n /** Toggle the arrow direction class after CSS anchor positioning resolves. */\n #detectFlip(cell: HTMLElement): void {\n if (!this.#popoverEl) return;\n const cellRect = cell.getBoundingClientRect();\n const popoverRect = this.#popoverEl.getBoundingClientRect();\n // If the popover's bottom edge is above the cell's top, it flipped\n this.#popoverEl.classList.toggle('tbw-tooltip-above', popoverRect.bottom <= cellRect.top);\n }\n // #endregion\n\n // #region Event Delegation\n\n /** Bind delegated mouseover/mouseout once. */\n #bindEvents(): void {\n if (this.#bound) return;\n const container = this.gridElement?.querySelector('.tbw-grid-root');\n if (!container) return;\n\n this.#bound = true;\n\n container.addEventListener('mouseover', (e: Event) => this.#onMouseOver(e as MouseEvent), {\n signal: this.disconnectSignal,\n });\n\n container.addEventListener('mouseout', (e: Event) => this.#onMouseOut(e as MouseEvent), {\n signal: this.disconnectSignal,\n });\n }\n\n #onMouseOver(e: MouseEvent): void {\n const target = e.target as HTMLElement;\n if (!target?.closest) return;\n\n // Check for header cell\n const headerCell = target.closest('[part~=\"header-cell\"]') as HTMLElement | null;\n if (headerCell && this.#headerEnabled) {\n this.#showHeaderTooltip(headerCell);\n return;\n }\n\n // Check for data cell — skip cells that already have a CSS anchor (e.g. overlay editors)\n // to avoid overwriting their anchor-name and breaking their positioning.\n const dataCell = target.closest('[data-row][data-col]') as HTMLElement | null;\n if (dataCell && this.#cellEnabled && !dataCell.style.getPropertyValue('anchor-name')) {\n this.#showCellTooltip(dataCell);\n }\n }\n\n #onMouseOut(e: MouseEvent): void {\n const target = e.target as HTMLElement;\n if (!target?.closest) return;\n\n const cell = target.closest('[part~=\"header-cell\"], [data-row][data-col]') as HTMLElement | null;\n if (!cell) return;\n\n // Keep tooltip if pointer moved to a child still inside the same cell\n const related = e.relatedTarget as HTMLElement | null;\n if (related && cell.contains(related)) return;\n\n this.#hideTooltip();\n }\n // #endregion\n\n // #region Tooltip Resolution\n\n #showHeaderTooltip(headerCell: HTMLElement): void {\n const colIndex = parseInt(headerCell.getAttribute('data-col') ?? '-1', 10);\n if (colIndex < 0) return;\n\n const column = this.visibleColumns[colIndex];\n if (!column) return;\n\n const text = resolveHeaderTooltip(column, headerCell);\n if (text) {\n this.#showTooltip(headerCell, text);\n }\n }\n\n #showCellTooltip(cell: HTMLElement): void {\n const rowIndex = parseInt(cell.getAttribute('data-row') ?? '-1', 10);\n const colIndex = parseInt(cell.getAttribute('data-col') ?? '-1', 10);\n if (rowIndex < 0 || colIndex < 0) return;\n\n const column = this.visibleColumns[colIndex];\n if (!column) return;\n\n const row = this.rows[rowIndex];\n const value = row?.[column.field as keyof typeof row];\n\n const text = resolveCellTooltip(column, cell, row, value);\n if (text) {\n this.#showTooltip(cell, text);\n }\n }\n // #endregion\n}\n// #endregion\n"],"names":["isOverflowing","el","scrollWidth","clientWidth","supportsPopover","HTMLElement","prototype","showPopover","TooltipPlugin","BaseGridPlugin","name","styles","static","ownedProperties","property","level","description","configRules","popoverEl","anchorCell","bound","headerEnabled","this","config","header","cellEnabled","cell","attach","grid","super","detach","hideTooltip","remove","afterRender","ensurePopover","bindEvents","document","createElement","className","setAttribute","style","overflow","margin","body","appendChild","showTooltip","text","clearAnchor","setProperty","textContent","CSS","supports","requestAnimationFrame","detectFlip","positionFallback","hidePopover","classList","getPropertyValue","removeProperty","cellRect","getBoundingClientRect","position","left","window","innerHeight","bottom","top","add","popoverRect","toggle","container","gridElement","querySelector","addEventListener","e","onMouseOver","signal","disconnectSignal","onMouseOut","target","closest","headerCell","showHeaderTooltip","dataCell","showCellTooltip","related","relatedTarget","contains","colIndex","parseInt","getAttribute","column","visibleColumns","spec","headerTooltip","value","field","trim","resolveHeaderTooltip","rowIndex","row","rows","cellTooltip","resolveCellTooltip"],"mappings":"iVAoBA,SAASA,EAAcC,GACrB,OAAOA,EAAGC,YAAcD,EAAGE,WA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SAAS/D,EAAKgE,aAAa,aAAe,KAAM,IACjE,GAAIS,EAAW,GAAKX,EAAW,EAAG,OAElC,MAAMG,EAASrE,KAAKsE,eAAeJ,GACnC,IAAKG,EAAQ,OAEb,MAAMS,EAAM9E,KAAK+E,KAAKF,GAChBJ,EAAQK,IAAMT,EAAOK,OAErBlD,EA3UV,SAA4B6C,EAAsBjE,EAAmB0E,EAAcL,GACjF,MAAMF,EAAOF,EAAOW,YAEpB,IAAa,IAATT,EAAgB,OAAO,KAC3B,GAAoB,iBAATA,EAAmB,OAAOA,EACrC,GAAoB,mBAATA,EAET,OAAOA,EADwB,CAAEE,QAAOK,MAAKT,SAAQK,MAAOL,EAAOK,QAKrE,OAAIhG,EAAc0B,IACTA,EAAKuB,aAAagD,QAGpB,IACT,CA2TiBM,CAAmBZ,EAAQjE,EAAM0E,EAAKL,GAC/CjD,GACFxB,MAAKuB,EAAanB,EAAMoB,EAE5B"}
1
+ {"version":3,"file":"tooltip.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/tooltip/TooltipPlugin.ts"],"sourcesContent":["/**\n * Tooltip Plugin\n *\n * Shows styled popover tooltips on header and data cells when text\n * overflows (ellipsis). Uses the Popover API (`popover=\"hint\"`) with\n * CSS anchor positioning for consistent, themed placement.\n *\n * Supports per-column overrides via `cellTooltip` and `headerTooltip`\n * on column config.\n */\n\nimport type { GridElement, PluginManifest } from '../../core/plugin/base-plugin';\nimport { BaseGridPlugin } from '../../core/plugin/base-plugin';\nimport type { CellRenderContext, ColumnConfig, HeaderLabelContext } from '../../core/types';\nimport tooltipStyles from './tooltip.css?inline';\nimport type { TooltipConfig } from './types';\n\n// #region Helpers\n\n/** Check if an element's text content overflows its visible width. */\nfunction isOverflowing(el: HTMLElement): boolean {\n return el.scrollWidth > el.clientWidth;\n}\n\n/**\n * Resolve the tooltip text for a cell.\n * Returns the text to show, or `null` to suppress.\n */\nfunction resolveCellTooltip(\n column: ColumnConfig,\n cell: HTMLElement,\n row: unknown,\n value: unknown,\n grid?: GridElement,\n): string | null {\n const spec = column.cellTooltip;\n\n if (spec === false) return null;\n if (typeof spec === 'string') return spec;\n if (typeof spec === 'function') {\n const ctx: CellRenderContext = { value, row, column, field: column.field, grid: grid as any };\n return spec(ctx);\n }\n\n // Default: show textContent only when overflowing\n if (isOverflowing(cell)) {\n return cell.textContent?.trim() || null;\n }\n\n return null;\n}\n\n/**\n * Resolve the tooltip text for a header cell.\n * Returns the text to show, or `null` to suppress.\n */\nfunction resolveHeaderTooltip(column: ColumnConfig, headerCell: HTMLElement): string | null {\n const spec = column.headerTooltip;\n\n if (spec === false) return null;\n if (typeof spec === 'string') return spec;\n if (typeof spec === 'function') {\n const ctx: HeaderLabelContext = {\n column,\n value: column.header ?? column.field,\n };\n return spec(ctx);\n }\n\n // Default: show header text only when overflowing\n const labelSpan = headerCell.querySelector('span:first-child') as HTMLElement | null;\n const target = labelSpan ?? headerCell;\n\n if (isOverflowing(target)) {\n return target.textContent?.trim() || null;\n }\n\n return null;\n}\n\n/** Runtime check — happy-dom and older browsers may lack Popover API. */\nfunction supportsPopover(): boolean {\n return typeof HTMLElement.prototype?.showPopover === 'function';\n}\n\n/** Runtime check for CSS anchor positioning. */\nfunction supportsAnchor(): boolean {\n return typeof CSS !== 'undefined' && CSS.supports?.('anchor-name', '--test') === true;\n}\n// #endregion\n\n// #region TooltipPlugin\n/**\n * Tooltip Plugin for tbw-grid\n *\n * Shows styled popover tooltips when header or cell text overflows its\n * container. Uses the Popover API with CSS anchor positioning for\n * consistent themed appearance across light and dark modes.\n *\n * ## Installation\n *\n * ```ts\n * import { TooltipPlugin } from '@toolbox-web/grid/plugins/tooltip';\n * ```\n *\n * @example Default — auto-tooltip on overflow\n * ```ts\n * grid.gridConfig = {\n * plugins: [new TooltipPlugin()],\n * };\n * ```\n *\n * @example Header-only tooltips\n * ```ts\n * grid.gridConfig = {\n * plugins: [new TooltipPlugin({ cell: false })],\n * };\n * ```\n *\n * @example Per-column overrides\n * ```ts\n * grid.gridConfig = {\n * columns: [\n * { field: 'name', cellTooltip: (ctx) => `${ctx.row.first} ${ctx.row.last}` },\n * { field: 'actions', cellTooltip: false },\n * { field: 'revenue', headerTooltip: 'Total revenue in USD (before tax)' },\n * ],\n * plugins: [new TooltipPlugin()],\n * };\n * ```\n *\n * @category Plugins\n */\nexport class TooltipPlugin extends BaseGridPlugin<TooltipConfig> {\n readonly name = 'tooltip';\n override readonly styles = tooltipStyles;\n\n static override readonly manifest: PluginManifest<TooltipConfig> = {\n ownedProperties: [\n { property: 'cellTooltip', level: 'column', description: 'the \"cellTooltip\" column property' },\n { property: 'headerTooltip', level: 'column', description: 'the \"headerTooltip\" column property' },\n ],\n configRules: [],\n };\n\n /** The shared popover element for all tooltips. */\n #popoverEl: HTMLElement | null = null;\n\n /** The cell currently acting as CSS anchor. */\n #anchorCell: HTMLElement | null = null;\n\n /** Whether delegated listeners are bound. */\n #bound = false;\n\n /** Whether header tooltips are enabled globally. */\n get #headerEnabled(): boolean {\n return this.config.header !== false;\n }\n\n /** Whether cell tooltips are enabled globally. */\n get #cellEnabled(): boolean {\n return this.config.cell !== false;\n }\n\n override attach(grid: GridElement): void {\n super.attach(grid);\n }\n\n override detach(): void {\n this.#hideTooltip();\n this.#popoverEl?.remove();\n this.#popoverEl = null;\n this.#bound = false;\n super.detach();\n }\n\n override afterRender(): void {\n this.#ensurePopover();\n this.#bindEvents();\n }\n\n // #region Popover Lifecycle\n\n /** Create the shared popover element (once). */\n #ensurePopover(): void {\n if (this.#popoverEl) return;\n const el = document.createElement('div');\n el.className = 'tbw-tooltip-popover';\n el.setAttribute('popover', 'hint');\n // Override UA popover defaults that @layer CSS cannot beat\n el.style.overflow = 'visible';\n el.style.margin = '0';\n document.body.appendChild(el);\n this.#popoverEl = el;\n }\n\n /** Show the popover anchored to `cell` with the given `text`. */\n #showTooltip(cell: HTMLElement, text: string): void {\n if (!this.#popoverEl) return;\n\n // Move the CSS anchor to the hovered cell\n this.#clearAnchor();\n cell.style.setProperty('anchor-name', '--tbw-tooltip-anchor');\n this.#anchorCell = cell;\n\n // Set content (always textContent — safe, no XSS)\n this.#popoverEl.textContent = text;\n\n // Show via Popover API\n if (supportsPopover()) {\n try {\n this.#popoverEl.showPopover();\n } catch {\n /* already shown */\n }\n }\n\n if (supportsAnchor()) {\n // Detect flip after the browser resolves position-try-fallbacks\n requestAnimationFrame(() => this.#detectFlip(cell));\n } else {\n this.#positionFallback(cell);\n }\n }\n\n /** Hide the popover and clear the anchor reference. */\n #hideTooltip(): void {\n if (this.#popoverEl) {\n if (supportsPopover()) {\n try {\n this.#popoverEl.hidePopover();\n } catch {\n /* already hidden */\n }\n }\n this.#popoverEl.classList.remove('tbw-tooltip-above');\n }\n this.#clearAnchor();\n }\n\n /** Remove the CSS anchor-name from the previous cell, but only if it's still our tooltip anchor. */\n #clearAnchor(): void {\n if (this.#anchorCell) {\n if (this.#anchorCell.style.getPropertyValue('anchor-name') === '--tbw-tooltip-anchor') {\n this.#anchorCell.style.removeProperty('anchor-name');\n }\n this.#anchorCell = null;\n }\n }\n\n /**\n * Fallback positioning for browsers without CSS anchor support.\n * Places the popover below or above the cell using fixed coordinates.\n */\n #positionFallback(cell: HTMLElement): void {\n if (!this.#popoverEl) return;\n const cellRect = cell.getBoundingClientRect();\n const arrowGap = 11;\n\n this.#popoverEl.style.position = 'fixed';\n this.#popoverEl.style.left = `${cellRect.left}px`;\n\n // Check if there's space below\n const spaceBelow = window.innerHeight - cellRect.bottom;\n if (spaceBelow < 80) {\n // Place above the cell\n this.#popoverEl.style.top = '';\n this.#popoverEl.style.bottom = `${window.innerHeight - cellRect.top + arrowGap}px`;\n this.#popoverEl.classList.add('tbw-tooltip-above');\n } else {\n this.#popoverEl.style.top = `${cellRect.bottom + arrowGap}px`;\n this.#popoverEl.style.bottom = '';\n this.#popoverEl.classList.remove('tbw-tooltip-above');\n }\n }\n\n /** Toggle the arrow direction class after CSS anchor positioning resolves. */\n #detectFlip(cell: HTMLElement): void {\n if (!this.#popoverEl) return;\n const cellRect = cell.getBoundingClientRect();\n const popoverRect = this.#popoverEl.getBoundingClientRect();\n // If the popover's bottom edge is above the cell's top, it flipped\n this.#popoverEl.classList.toggle('tbw-tooltip-above', popoverRect.bottom <= cellRect.top);\n }\n // #endregion\n\n // #region Event Delegation\n\n /** Bind delegated mouseover/mouseout once. */\n #bindEvents(): void {\n if (this.#bound) return;\n const container = this.gridElement?.querySelector('.tbw-grid-root');\n if (!container) return;\n\n this.#bound = true;\n\n container.addEventListener('mouseover', (e: Event) => this.#onMouseOver(e as MouseEvent), {\n signal: this.disconnectSignal,\n });\n\n container.addEventListener('mouseout', (e: Event) => this.#onMouseOut(e as MouseEvent), {\n signal: this.disconnectSignal,\n });\n }\n\n #onMouseOver(e: MouseEvent): void {\n const target = e.target as HTMLElement;\n if (!target?.closest) return;\n\n // Check for header cell\n const headerCell = target.closest('[part~=\"header-cell\"]') as HTMLElement | null;\n if (headerCell && this.#headerEnabled) {\n this.#showHeaderTooltip(headerCell);\n return;\n }\n\n // Check for data cell — skip cells that already have a CSS anchor (e.g. overlay editors)\n // to avoid overwriting their anchor-name and breaking their positioning.\n const dataCell = target.closest('[data-row][data-col]') as HTMLElement | null;\n if (dataCell && this.#cellEnabled && !dataCell.style.getPropertyValue('anchor-name')) {\n this.#showCellTooltip(dataCell);\n }\n }\n\n #onMouseOut(e: MouseEvent): void {\n const target = e.target as HTMLElement;\n if (!target?.closest) return;\n\n const cell = target.closest('[part~=\"header-cell\"], [data-row][data-col]') as HTMLElement | null;\n if (!cell) return;\n\n // Keep tooltip if pointer moved to a child still inside the same cell\n const related = e.relatedTarget as HTMLElement | null;\n if (related && cell.contains(related)) return;\n\n this.#hideTooltip();\n }\n // #endregion\n\n // #region Tooltip Resolution\n\n #showHeaderTooltip(headerCell: HTMLElement): void {\n const colIndex = parseInt(headerCell.getAttribute('data-col') ?? '-1', 10);\n if (colIndex < 0) return;\n\n const column = this.visibleColumns[colIndex];\n if (!column) return;\n\n const text = resolveHeaderTooltip(column, headerCell);\n if (text) {\n this.#showTooltip(headerCell, text);\n }\n }\n\n #showCellTooltip(cell: HTMLElement): void {\n const rowIndex = parseInt(cell.getAttribute('data-row') ?? '-1', 10);\n const colIndex = parseInt(cell.getAttribute('data-col') ?? '-1', 10);\n if (rowIndex < 0 || colIndex < 0) return;\n\n const column = this.visibleColumns[colIndex];\n if (!column) return;\n\n const row = this.rows[rowIndex];\n const value = row?.[column.field as keyof typeof row];\n\n const text = resolveCellTooltip(column, cell, row, value, this.grid);\n if (text) {\n this.#showTooltip(cell, text);\n }\n }\n // #endregion\n}\n// #endregion\n"],"names":["isOverflowing","el","scrollWidth","clientWidth","supportsPopover","HTMLElement","prototype","showPopover","TooltipPlugin","BaseGridPlugin","name","styles","static","ownedProperties","property","level","description","configRules","popoverEl","anchorCell","bound","headerEnabled","this","config","header","cellEnabled","cell","attach","grid","super","detach","hideTooltip","remove","afterRender","ensurePopover","bindEvents","document","createElement","className","setAttribute","style","overflow","margin","body","appendChild","showTooltip","text","clearAnchor","setProperty","textContent","CSS","supports","requestAnimationFrame","detectFlip","positionFallback","hidePopover","classList","getPropertyValue","removeProperty","cellRect","getBoundingClientRect","position","left","window","innerHeight","bottom","top","add","popoverRect","toggle","container","gridElement","querySelector","addEventListener","e","onMouseOver","signal","disconnectSignal","onMouseOut","target","closest","headerCell","showHeaderTooltip","dataCell","showCellTooltip","related","relatedTarget","contains","colIndex","parseInt","getAttribute","column","visibleColumns","spec","headerTooltip","value","field","trim","resolveHeaderTooltip","rowIndex","row","rows","cellTooltip","resolveCellTooltip"],"mappings":"iVAoBA,SAASA,EAAcC,GACrB,OAAOA,EAAGC,YAAcD,EAAGE,WAC7B,CA2DA,SAASC,IACP,MAAqD,mBAAvCC,YAAYC,WAAWC,WACvC,CAkDO,MAAMC,UAAsBC,EAAAA,eACxBC,KAAO,UACEC,yzDAElBC,gBAAmE,CACjEC,gBAAiB,CACf,CAAEC,SAAU,cAAeC,MAAO,SAAUC,YAAa,qC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,EAAOK,OAErBlD,EAjVV,SACE6C,EACAjE,EACA0E,EACAL,EACAnE,GAEA,MAAMiE,EAAOF,EAAOW,YAEpB,IAAa,IAATT,EAAgB,OAAO,KAC3B,GAAoB,iBAATA,EAAmB,OAAOA,EACrC,GAAoB,mBAATA,EAET,OAAOA,EADwB,CAAEE,QAAOK,MAAKT,SAAQK,MAAOL,EAAOK,MAAOpE,SAK5E,OAAI5B,EAAc0B,IACTA,EAAKuB,aAAagD,QAGpB,IACT,CA2TiBM,CAAmBZ,EAAQjE,EAAM0E,EAAKL,EAAOzE,KAAKM,MAC3DkB,GACFxB,MAAKuB,EAAanB,EAAMoB,EAE5B"}
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("../../core/constants"),require("../../core/plugin/base-plugin")):"function"==typeof define&&define.amd?define(["exports","../../core/constants","../../core/plugin/base-plugin"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGridPlugin_tree={},e.TbwGrid,e.TbwGrid)}(this,function(e,t,n){"use strict";function r(e,t,n){return void 0!==e.id?String(e.id):n?`${n}-${t}`:String(t)}function i(e,t){const n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function s(e,t,n=null,i=0){const a=t.childrenField??"children",o=new Set;for(let d=0;d<e.length;d++){const l=e[d],c=r(l,d,n),h=l[a];if(Array.isArray(h)&&h.length>0){o.add(c);const e=s(h,t,c,i+1);for(const t of e)o.add(t)}}return o}function a(e,t,n,i=null,s=0){const o=n.childrenField??"children";for(let d=0;d<e.length;d++){const l=e[d],c=r(l,d,i);if(c===t)return[c];const h=l[o];if(Array.isArray(h)&&h.length>0){const e=a(h,t,n,c,s+1);if(e)return[c,...e]}}return null}function o(e,t,n,r){const i=a(e,t,n);if(!i)return r;const s=new Set(r);for(let a=0;a<i.length-1;a++)s.add(i[a]);return s}function d(e,t){const n=Math.min(t,e.length-1);if(n<0)return 0;let r=n;for(;r>0&&e[r].depth>0;)r--;let i=0;for(let s=0;s<=r;s++)0===e[s].depth&&i++;return i-1}function l(e,t="children"){if(!Array.isArray(e)||0===e.length)return!1;for(const n of e){if(!n)continue;const e=n[t];if(Array.isArray(e)&&e.length>0)return!0}return!1}class c extends n.BaseGridPlugin{static manifest={modifiesRowStructure:!0,hookPriority:{processRows:10},incompatibleWith:[{name:"groupingRows",reason:"Both plugins transform the entire row model. TreePlugin flattens nested hierarchies while GroupingRowsPlugin groups flat rows with synthetic headers. Use one approach per grid."},{name:"pivot",reason:"PivotPlugin replaces the entire row and column structure with aggregated pivot data. Tree hierarchy cannot coexist with pivot aggregation."}],events:[{type:"tree-expand",description:"Emitted when tree expansion state changes (toggle, expand all, collapse all). Broadcast to both DOM consumers and plugin bus."}],queries:[{type:"canMoveRow",description:"Returns false for rows with children (parent nodes cannot be reordered)"},{type:"datasource:viewport-mapping",description:"Translates flat viewport row indices to top-level node indices for ServerSide pagination."}]};static dependencies=[{name:"multiSort",required:!1,reason:"Queries sort model for coordinated tree sorting"},{name:"serverSide",required:!1,reason:"Consumes datasource events for lazy-loaded tree data"}];name="tree";styles='@layer tbw-plugins{tbw-grid .cell[data-field=__tbw_expander]{border-inline-end:none!important;padding:0;display:flex;align-items:center;justify-content:flex-start}tbw-grid .header-row .cell[data-field=__tbw_expander]{display:none}tbw-grid .header-row .cell[data-field=__tbw_expander]+.cell{grid-column:1 / 3}tbw-grid .tree-cell-wrapper{display:inline-flex;align-items:center;vertical-align:middle;overflow:visible;padding-inline-start:calc(var(--tbw-tree-depth, 0) * var(--tbw-tree-indent-width, var(--tbw-tree-toggle-size, 1.25em)))}tbw-grid .tree-expander{display:flex;align-items:center;justify-content:flex-start;width:100%;height:100%;box-sizing:border-box}tbw-grid .tree-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-tree-toggle-size, 1.25em);height:var(--tbw-tree-toggle-size, 1.25em);flex-shrink:0}tbw-grid .tree-toggle:hover{color:var(--tbw-tree-accent, var(--tbw-color-accent))}tbw-grid .tree-spacer{width:var(--tbw-tree-toggle-size, 1.25em);height:var(--tbw-tree-toggle-size, 1.25em);display:inline-block;flex-shrink:0}tbw-grid .data-grid-row.tbw-tree-slide-in{animation:tbw-tree-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}tbw-grid .data-grid-row.tbw-tree-fade-in{animation:tbw-tree-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-tree-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}@keyframes tbw-tree-fade-in{0%{opacity:0}to{opacity:1}}tbw-grid.tbw-tree-loading .rows-viewport:after{content:"";display:block;height:2px;background:linear-gradient(90deg,transparent,var(--tbw-color-accent, #2563eb),transparent);animation:tbw-tree-loading-bar 1s ease-in-out infinite;position:sticky;bottom:0;left:0;right:0}@keyframes tbw-tree-loading-bar{0%{transform:translate(-100%)}to{transform:translate(100%)}}}';get defaultConfig(){return{childrenField:"children",autoDetect:!0,defaultExpanded:!1,indentWidth:20,showExpandIcons:!0,animation:"slide"}}expandedKeys=new Set;initialExpansionDone=!1;flattenedRows=[];rowKeyMap=new Map;previousVisibleKeys=new Set;keysToAnimate=new Set;sortState=null;originalTreeColumnRenderer;wrappedTreeColumnField;detach(){this.expandedKeys.clear(),this.initialExpansionDone=!1,this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.sortState=null,this.originalTreeColumnRenderer=void 0,this.wrappedTreeColumnField=void 0}handleQuery(e){if("canMoveRow"===e.type){const t=e.context,n=this.config.childrenField??"children",r=t?.[n];if(Array.isArray(r)&&r.length>0)return!1}if("datasource:viewport-mapping"===e.type){const{viewportStart:t,viewportEnd:n}=e.context;if(0===this.flattenedRows.length)return;return{startNode:d(this.flattenedRows,t),endNode:d(this.flattenedRows,n)+1,totalLoadedNodes:function(e){let t=0;for(const n of e)0===n.depth&&t++;return t}(this.flattenedRows)}}}attach(e){super.attach(e),this.on("datasource:data",e=>{const t=e;t.claimed||(t.claimed=!0)}),this.on("datasource:children",e=>{const t=e;if("tree"!==t.context?.source)return;t.claimed=!0;const n=t.context.parentNode;if(n){n[this.config.childrenField??"children"]=t.rows,this.requestRender()}})}get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}detect(e){if(!this.config.autoDetect)return!1;const t=e,n=this.config.childrenField??function(e){if(!Array.isArray(e)||0===e.length)return null;const t=["children","items","nodes","subRows","nested"];for(const n of e)if(n&&"object"==typeof n)for(const e of t){const t=n[e];if(Array.isArray(t)&&t.length>0)return e}return null}(t)??"children";return l(t,n)}processRows(e){const t=this.config.childrenField??"children",n=e;if(0===n.length||!l(n,t))return this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),[...e];let r=this.withStableKeys(n);const i=this.resolveEffectiveSortState();i&&(r=this.sortTree(r,i.field,i.direction)),this.config.defaultExpanded&&!this.initialExpansionDone&&(this.expandedKeys=s(r,this.config),this.initialExpansionDone=!0),this.flattenedRows=this.flattenTree(r,this.expandedKeys),this.rowKeyMap.clear(),this.keysToAnimate.clear();const a=new Set;for(const s of this.flattenedRows)this.rowKeyMap.set(s.key,s),a.add(s.key),!this.previousVisibleKeys.has(s.key)&&s.depth>0&&this.keysToAnimate.add(s.key);return this.previousVisibleKeys=a,this.flattenedRows.map(e=>({...e.data,__treeKey:e.key,__treeDepth:e.depth,__treeHasChildren:e.hasChildren,__treeExpanded:e.isExpanded}))}withStableKeys(e,t=null){const n=this.config.childrenField??"children";return e.map((e,r)=>{const i=e.__stableKey,s=void 0!==e.id?String(e.id):i??(t?`${t}-${r}`:String(r)),a=e[n],o=Array.isArray(a)&&a.length>0;return{...e,__stableKey:s,...o?{[n]:this.withStableKeys(a,s)}:{}}})}flattenTree(e,t,n=0){const r=this.config.childrenField??"children",i=[];for(const s of e){const e=s.__stableKey??String(s.id??"?"),a=s[r],o=Array.isArray(a)&&a.length>0,d=t.has(e);i.push({key:e,data:s,depth:n,hasChildren:o,isExpanded:d,parentKey:n>0&&e.substring(0,e.lastIndexOf("-"))||null}),o&&d&&i.push(...this.flattenTree(a,t,n+1))}return i}resolveEffectiveSortState(){const e=this.grid?.query?.("sort:get-model",null);if(Array.isArray(e)&&e.length>0){const t=e[0];if(Array.isArray(t)&&t.length>0)return{field:t[0].field,direction:"desc"===t[0].direction?-1:1}}return this.sortState}sortTree(e,t,n){const r=this.config.childrenField??"children";return[...e].sort((e,r)=>{const i=e[t],s=r[t];return null==i&&null==s?0:null==i?-1:null==s?1:i>s?n:i<s?-n:0}).map(e=>{const i=e[r];return Array.isArray(i)&&i.length>0?{...e,[r]:this.sortTree(i,t,n)}:e})}processColumns(e){if(0===this.flattenedRows.length)return[...e];const n=[...e];if(0===n.length)return n;const{treeColumn:r}=this.config;let i=0;if(r){const e=n.findIndex(e=>e.field===r);e>=0&&(i=e)}const s=n[i],a=s.field;this.wrappedTreeColumnField!==a&&(this.originalTreeColumnRenderer=s.viewRenderer,this.wrappedTreeColumnField=a);const o=this.originalTreeColumnRenderer,d=()=>this.config,l=this.setIcon.bind(this);return n[i]={...s,viewRenderer:e=>{const{row:n,value:r}=e,{showExpandIcons:i=!0,indentWidth:s}=d(),a=n,c=a.__treeDepth??0,h=document.createElement("span");if(h.className="tree-cell-wrapper",h.style.setProperty("--tbw-tree-depth",String(c)),void 0!==s&&h.style.setProperty("--tbw-tree-indent-width",`${s}px`),i)if(a.__treeHasChildren){const e=document.createElement("span");e.className=`${t.GridClasses.TREE_TOGGLE}${a.__treeExpanded?` ${t.GridClasses.EXPANDED}`:""}`,l(e,a.__treeExpanded?"collapse":"expand"),e.setAttribute("data-tree-key",String(a.__treeKey??"")),h.appendChild(e)}else{const e=document.createElement("span");e.className="tree-spacer",h.appendChild(e)}const p=document.createElement("span");if(p.className="tree-content",o){const t=o(e);t instanceof Node?p.appendChild(t):"string"==typeof t&&(p.innerHTML=t)}else p.textContent=null!=r?String(r):"";return h.appendChild(p),h}},n}onCellClick(e){const n=e.originalEvent?.target;if(!n?.classList.contains(t.GridClasses.TREE_TOGGLE))return!1;const r=n.getAttribute("data-tree-key");if(!r)return!1;const s=this.rowKeyMap.get(r);return!!s&&(this.expandedKeys=i(this.expandedKeys,r),this.broadcast("tree-expand",{key:r,row:s.data,expanded:this.expandedKeys.has(r),depth:s.depth,expandedKeys:[...this.expandedKeys]}),this.requestRender(),!0)}onKeyDown(e){if(" "!==e.key)return;const t=this.grid._focusRow,n=this.flattenedRows[t];return n?.hasChildren?(e.preventDefault(),this.expandedKeys=i(this.expandedKeys,n.key),this.broadcast("tree-expand",{key:n.key,row:n.data,expanded:this.expandedKeys.has(n.key),depth:n.depth,expandedKeys:[...this.expandedKeys]}),this.requestRenderWithFocus(),!0):void 0}onHeaderClick(e){if(0===this.flattenedRows.length||!e.column.sortable)return!1;const t=this.grid?.query?.("sort:get-model",null);if(Array.isArray(t)&&t.length>0)return!1;const{field:n}=e.column;this.sortState&&this.sortState.field===n?1===this.sortState.direction?this.sortState={field:n,direction:-1}:this.sortState=null:this.sortState={field:n,direction:1};const r=this.grid;return void 0!==r._sortState&&(r._sortState=this.sortState?{...this.sortState}:null),this.broadcast("sort-change",{field:n,direction:this.sortState?.direction??0}),this.requestRender(),!0}afterRender(){const e=this.gridElement?.querySelector(".rows");if(!e)return;const t=this.animationStyle,n=!1!==t&&this.keysToAnimate.size>0,r="fade"===t?"tbw-tree-fade-in":"tbw-tree-slide-in";for(const i of e.querySelectorAll(".data-grid-row")){const e=i.querySelector(".cell[data-row]"),t=e?parseInt(e.getAttribute("data-row")??"-1",10):-1,s=this.flattenedRows[t];s?.hasChildren&&i.setAttribute("aria-expanded",String(s.isExpanded)),n&&s?.key&&this.keysToAnimate.has(s.key)&&(i.classList.add(r),i.addEventListener("animationend",()=>i.classList.remove(r),{once:!0}))}this.keysToAnimate.clear()}expand(e){this.expandedKeys.add(e),this.requestRender()}collapse(e){this.expandedKeys.delete(e),this.requestRender()}toggle(e){this.expandedKeys=i(this.expandedKeys,e);const t=this.rowKeyMap.get(e);t?this.broadcast("tree-expand",{key:e,row:t.data,expanded:this.expandedKeys.has(e),depth:t.depth,expandedKeys:[...this.expandedKeys]}):this.emitPluginEvent("tree-expand",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}expandAll(){this.expandedKeys=s(this.rows,this.config),this.emitPluginEvent("tree-expand",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}collapseAll(){this.expandedKeys=new Set,this.emitPluginEvent("tree-expand",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}getExpandedKeys(){return[...this.expandedKeys]}getFlattenedRows(){return[...this.flattenedRows]}getRowByKey(e){return this.rowKeyMap.get(e)?.data}expandToKey(e){this.expandedKeys=o(this.rows,e,this.config,this.expandedKeys),this.requestRender()}}e.TreePlugin=c,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("../../core/constants"),require("../../core/plugin/base-plugin")):"function"==typeof define&&define.amd?define(["exports","../../core/constants","../../core/plugin/base-plugin"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGridPlugin_tree={},e.TbwGrid,e.TbwGrid)}(this,function(e,t,n){"use strict";function r(e,t,n){return void 0!==e.id?String(e.id):n?`${n}-${t}`:String(t)}function i(e,t){const n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function s(e,t,n=null,i=0){const a=t.childrenField??"children",o=new Set;for(let d=0;d<e.length;d++){const l=e[d],h=r(l,d,n),c=l[a];if(Array.isArray(c)&&c.length>0){o.add(h);const e=s(c,t,h,i+1);for(const t of e)o.add(t)}}return o}function a(e,t,n,i=null,s=0){const o=n.childrenField??"children";for(let d=0;d<e.length;d++){const l=e[d],h=r(l,d,i);if(h===t)return[h];const c=l[o];if(Array.isArray(c)&&c.length>0){const e=a(c,t,n,h,s+1);if(e)return[h,...e]}}return null}function o(e,t,n,r){const i=a(e,t,n);if(!i)return r;const s=new Set(r);for(let a=0;a<i.length-1;a++)s.add(i[a]);return s}function d(e,t){const n=Math.min(t,e.length-1);if(n<0)return 0;let r=n;for(;r>0&&e[r].depth>0;)r--;let i=0;for(let s=0;s<=r;s++)0===e[s].depth&&i++;return i-1}function l(e,t="children"){if(!Array.isArray(e)||0===e.length)return!1;for(const n of e){if(!n)continue;const e=n[t];if(Array.isArray(e)&&e.length>0)return!0;if(null!=e&&!Array.isArray(e)&&e)return!0}return!1}class h extends n.BaseGridPlugin{static manifest={modifiesRowStructure:!0,hookPriority:{processRows:10},incompatibleWith:[{name:"groupingRows",reason:"Both plugins transform the entire row model. TreePlugin flattens nested hierarchies while GroupingRowsPlugin groups flat rows with synthetic headers. Use one approach per grid."},{name:"pivot",reason:"PivotPlugin replaces the entire row and column structure with aggregated pivot data. Tree hierarchy cannot coexist with pivot aggregation."}],events:[{type:"tree-expand",description:"Emitted when tree expansion state changes (toggle, expand all, collapse all). Broadcast to both DOM consumers and plugin bus."}],queries:[{type:"canMoveRow",description:"Returns false for rows with children (parent nodes cannot be reordered)"},{type:"datasource:viewport-mapping",description:"Translates flat viewport row indices to top-level node indices for ServerSide pagination."}]};static dependencies=[{name:"multiSort",required:!1,reason:"Queries sort model for coordinated tree sorting"},{name:"serverSide",required:!1,reason:"Consumes datasource events for lazy-loaded tree data"}];name="tree";styles='@layer tbw-plugins{tbw-grid .cell[data-field=__tbw_expander]{border-inline-end:none!important;padding:0;display:flex;align-items:center;justify-content:flex-start}tbw-grid .header-row .cell[data-field=__tbw_expander]{display:none}tbw-grid .header-row .cell[data-field=__tbw_expander]+.cell{grid-column:1 / 3}tbw-grid .tree-cell-wrapper{display:inline-flex;align-items:center;vertical-align:middle;overflow:visible;padding-inline-start:calc(var(--tbw-tree-depth, 0) * var(--tbw-tree-indent-width, var(--tbw-tree-toggle-size, 1.25em)))}tbw-grid .tree-expander{display:flex;align-items:center;justify-content:flex-start;width:100%;height:100%;box-sizing:border-box}tbw-grid .tree-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-tree-toggle-size, 1.25em);height:var(--tbw-tree-toggle-size, 1.25em);flex-shrink:0}tbw-grid .tree-toggle:hover{color:var(--tbw-tree-accent, var(--tbw-color-accent))}tbw-grid .tree-spacer{width:var(--tbw-tree-toggle-size, 1.25em);height:var(--tbw-tree-toggle-size, 1.25em);display:inline-block;flex-shrink:0}tbw-grid .data-grid-row.tbw-tree-slide-in{animation:tbw-tree-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}tbw-grid .data-grid-row.tbw-tree-fade-in{animation:tbw-tree-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-tree-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}@keyframes tbw-tree-fade-in{0%{opacity:0}to{opacity:1}}tbw-grid.tbw-tree-loading .rows-viewport:after{content:"";display:block;height:2px;background:linear-gradient(90deg,transparent,var(--tbw-color-accent, #2563eb),transparent);animation:tbw-tree-loading-bar 1s ease-in-out infinite;position:sticky;bottom:0;left:0;right:0}@keyframes tbw-tree-loading-bar{0%{transform:translate(-100%)}to{transform:translate(100%)}}}';get defaultConfig(){return{childrenField:"children",autoDetect:!0,defaultExpanded:!1,indentWidth:20,showExpandIcons:!0,animation:"slide"}}expandedKeys=new Set;initialExpansionDone=!1;flattenedRows=[];rowKeyMap=new Map;previousVisibleKeys=new Set;keysToAnimate=new Set;sortState=null;loadingKeys=new Set;originalTreeColumnRenderer;wrappedTreeColumnField;detach(){this.expandedKeys.clear(),this.initialExpansionDone=!1,this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.sortState=null,this.loadingKeys.clear(),this.originalTreeColumnRenderer=void 0,this.wrappedTreeColumnField=void 0}handleQuery(e){if("canMoveRow"===e.type){const t=e.context,n=this.config.childrenField??"children",r=t?.[n];if(Array.isArray(r)&&r.length>0)return!1}if("datasource:viewport-mapping"===e.type){const{viewportStart:t,viewportEnd:n}=e.context;if(0===this.flattenedRows.length)return;return{startNode:d(this.flattenedRows,t),endNode:d(this.flattenedRows,n)+1,totalLoadedNodes:function(e){let t=0;for(const n of e)0===n.depth&&t++;return t}(this.flattenedRows)}}}attach(e){super.attach(e),this.on("datasource:data",e=>{const t=e;t.claimed||(t.claimed=!0)}),this.on("datasource:children",e=>{const t=e;if("tree"!==t.context?.source)return;t.claimed=!0;const n=t.context.parentNode;if(n){n[this.config.childrenField??"children"]=t.rows;const e=n.__stableKey??String(n.id??"?");this.loadingKeys.delete(e),this.requestRender()}})}get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}detect(e){if(!this.config.autoDetect)return!1;const t=e,n=this.config.childrenField??function(e){if(!Array.isArray(e)||0===e.length)return null;const t=["children","items","nodes","subRows","nested"];for(const n of e)if(n&&"object"==typeof n)for(const e of t){const t=n[e];if(Array.isArray(t)&&t.length>0)return e}return null}(t)??"children";return l(t,n)}processRows(e){const t=this.config.childrenField??"children",n=e;if(0===n.length||!l(n,t))return this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),[...e];let r=this.withStableKeys(n);const i=this.resolveEffectiveSortState();i&&(r=this.sortTree(r,i.field,i.direction)),this.config.defaultExpanded&&!this.initialExpansionDone&&(this.expandedKeys=s(r,this.config),this.initialExpansionDone=!0),this.flattenedRows=this.flattenTree(r,this.expandedKeys),this.rowKeyMap.clear(),this.keysToAnimate.clear();const a=new Set;for(const s of this.flattenedRows)this.rowKeyMap.set(s.key,s),a.add(s.key),!this.previousVisibleKeys.has(s.key)&&s.depth>0&&this.keysToAnimate.add(s.key);return this.previousVisibleKeys=a,this.flattenedRows.map(e=>({...e.data,__treeKey:e.key,__treeDepth:e.depth,__treeHasChildren:e.hasChildren,__treeExpanded:e.isExpanded}))}withStableKeys(e,t=null){const n=this.config.childrenField??"children";return e.map((e,r)=>{const i=e.__stableKey,s=void 0!==e.id?String(e.id):i??(t?`${t}-${r}`:String(r)),a=e[n],o=Array.isArray(a)&&a.length>0;return{...e,__stableKey:s,...o?{[n]:this.withStableKeys(a,s)}:{}}})}flattenTree(e,t,n=0){const r=this.config.childrenField??"children",i=[];for(const s of e){const e=s.__stableKey??String(s.id??"?"),a=s[r],o=Array.isArray(a)&&a.length>0,d=null!=a&&!Array.isArray(a)&&!!a,l=o||d,h=t.has(e);i.push({key:e,data:s,depth:n,hasChildren:l,isExpanded:h,parentKey:n>0&&e.substring(0,e.lastIndexOf("-"))||null}),o&&h&&i.push(...this.flattenTree(a,t,n+1))}return i}requestLazyChildren(e){if(this.loadingKeys.has(e.key))return;const t=this.config.childrenField??"children",n=e.data[t];if(Array.isArray(n)&&n.length>0)return;const r=this.grid?.query?.("datasource:is-active",null);r&&(this.loadingKeys.add(e.key),this.grid.query("datasource:fetch-children",{context:{source:"tree",parentNode:e.data,nodePath:[e.key]}}))}resolveEffectiveSortState(){const e=this.grid?.query?.("sort:get-model",null);if(Array.isArray(e)&&e.length>0){const t=e[0];if(Array.isArray(t)&&t.length>0)return{field:t[0].field,direction:"desc"===t[0].direction?-1:1}}return this.sortState}sortTree(e,t,n){const r=this.config.childrenField??"children";return[...e].sort((e,r)=>{const i=e[t],s=r[t];return null==i&&null==s?0:null==i?-1:null==s?1:i>s?n:i<s?-n:0}).map(e=>{const i=e[r];return Array.isArray(i)&&i.length>0?{...e,[r]:this.sortTree(i,t,n)}:e})}processColumns(e){if(0===this.flattenedRows.length)return[...e];const n=[...e];if(0===n.length)return n;const{treeColumn:r}=this.config;let i=0;if(r){const e=n.findIndex(e=>e.field===r);e>=0&&(i=e)}const s=n[i],a=s.field;this.wrappedTreeColumnField!==a&&(this.originalTreeColumnRenderer=s.viewRenderer,this.wrappedTreeColumnField=a);const o=this.originalTreeColumnRenderer,d=()=>this.config,l=this.setIcon.bind(this);return n[i]={...s,viewRenderer:e=>{const{row:n,value:r}=e,{showExpandIcons:i=!0,indentWidth:s}=d(),a=n,h=a.__treeDepth??0,c=document.createElement("span");if(c.className="tree-cell-wrapper",c.style.setProperty("--tbw-tree-depth",String(h)),void 0!==s&&c.style.setProperty("--tbw-tree-indent-width",`${s}px`),i)if(a.__treeHasChildren){const e=document.createElement("span");e.className=`${t.GridClasses.TREE_TOGGLE}${a.__treeExpanded?` ${t.GridClasses.EXPANDED}`:""}`,l(e,a.__treeExpanded?"collapse":"expand"),e.setAttribute("data-tree-key",String(a.__treeKey??"")),c.appendChild(e)}else{const e=document.createElement("span");e.className="tree-spacer",c.appendChild(e)}const p=document.createElement("span");if(p.className="tree-content",o){const t=o(e);t instanceof Node?p.appendChild(t):"string"==typeof t&&(p.innerHTML=t)}else p.textContent=null!=r?String(r):"";return c.appendChild(p),c}},n}onCellClick(e){const n=e.originalEvent?.target;if(!n?.classList.contains(t.GridClasses.TREE_TOGGLE))return!1;const r=n.getAttribute("data-tree-key");if(!r)return!1;const s=this.rowKeyMap.get(r);return!!s&&(this.expandedKeys=i(this.expandedKeys,r),this.expandedKeys.has(r)&&this.requestLazyChildren(s),this.broadcast("tree-expand",{key:r,row:s.data,expanded:this.expandedKeys.has(r),depth:s.depth,expandedKeys:[...this.expandedKeys]}),this.requestRender(),!0)}onKeyDown(e){if(" "!==e.key)return;const t=this.grid._focusRow,n=this.flattenedRows[t];return n?.hasChildren?(e.preventDefault(),this.expandedKeys=i(this.expandedKeys,n.key),this.expandedKeys.has(n.key)&&this.requestLazyChildren(n),this.broadcast("tree-expand",{key:n.key,row:n.data,expanded:this.expandedKeys.has(n.key),depth:n.depth,expandedKeys:[...this.expandedKeys]}),this.requestRenderWithFocus(),!0):void 0}onHeaderClick(e){if(0===this.flattenedRows.length||!e.column.sortable)return!1;const t=this.grid?.query?.("sort:get-model",null);if(Array.isArray(t)&&t.length>0)return!1;const{field:n}=e.column;this.sortState&&this.sortState.field===n?1===this.sortState.direction?this.sortState={field:n,direction:-1}:this.sortState=null:this.sortState={field:n,direction:1};const r=this.grid;return void 0!==r._sortState&&(r._sortState=this.sortState?{...this.sortState}:null),this.broadcast("sort-change",{field:n,direction:this.sortState?.direction??0}),this.requestRender(),!0}afterRender(){const e=this.gridElement?.querySelector(".rows");if(!e)return;const t=this.animationStyle,n=!1!==t&&this.keysToAnimate.size>0,r="fade"===t?"tbw-tree-fade-in":"tbw-tree-slide-in";for(const i of e.querySelectorAll(".data-grid-row")){const e=i.querySelector(".cell[data-row]"),t=e?parseInt(e.getAttribute("data-row")??"-1",10):-1,s=this.flattenedRows[t];s?.hasChildren&&i.setAttribute("aria-expanded",String(s.isExpanded)),n&&s?.key&&this.keysToAnimate.has(s.key)&&(i.classList.add(r),i.addEventListener("animationend",()=>i.classList.remove(r),{once:!0}))}this.keysToAnimate.clear()}expand(e){this.expandedKeys.add(e);const t=this.rowKeyMap.get(e);t&&this.requestLazyChildren(t),this.requestRender()}collapse(e){this.expandedKeys.delete(e),this.requestRender()}toggle(e){this.expandedKeys=i(this.expandedKeys,e);const t=this.rowKeyMap.get(e);t?(this.expandedKeys.has(e)&&this.requestLazyChildren(t),this.broadcast("tree-expand",{key:e,row:t.data,expanded:this.expandedKeys.has(e),depth:t.depth,expandedKeys:[...this.expandedKeys]})):this.emitPluginEvent("tree-expand",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}expandAll(){this.expandedKeys=s(this.rows,this.config),this.emitPluginEvent("tree-expand",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}collapseAll(){this.expandedKeys=new Set,this.emitPluginEvent("tree-expand",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}getExpandedKeys(){return[...this.expandedKeys]}getFlattenedRows(){return[...this.flattenedRows]}getRowByKey(e){return this.rowKeyMap.get(e)?.data}expandToKey(e){this.expandedKeys=o(this.rows,e,this.config,this.expandedKeys),this.requestRender()}}e.TreePlugin=h,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
2
2
  //# sourceMappingURL=tree.umd.js.map