@toolbox-web/grid 2.1.1 → 2.2.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 (61) 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/constants.d.ts +18 -0
  6. package/lib/core/internal/value-accessor.d.ts +33 -0
  7. package/lib/core/types.d.ts +114 -0
  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.map +1 -1
  11. package/lib/plugins/context-menu/index.js.map +1 -1
  12. package/lib/plugins/editing/index.js +1 -1
  13. package/lib/plugins/editing/index.js.map +1 -1
  14. package/lib/plugins/export/index.js +1 -1
  15. package/lib/plugins/export/index.js.map +1 -1
  16. package/lib/plugins/filtering/FilteringPlugin.d.ts +19 -1
  17. package/lib/plugins/filtering/index.js +1 -1
  18. package/lib/plugins/filtering/index.js.map +1 -1
  19. package/lib/plugins/grouping-columns/index.js.map +1 -1
  20. package/lib/plugins/grouping-rows/index.js +2 -2
  21. package/lib/plugins/grouping-rows/index.js.map +1 -1
  22. package/lib/plugins/master-detail/index.js.map +1 -1
  23. package/lib/plugins/multi-sort/index.js +1 -1
  24. package/lib/plugins/multi-sort/index.js.map +1 -1
  25. package/lib/plugins/pinned-columns/index.js.map +1 -1
  26. package/lib/plugins/pinned-rows/index.js +1 -1
  27. package/lib/plugins/pinned-rows/index.js.map +1 -1
  28. package/lib/plugins/pivot/index.js.map +1 -1
  29. package/lib/plugins/print/index.js.map +1 -1
  30. package/lib/plugins/reorder-columns/index.js.map +1 -1
  31. package/lib/plugins/reorder-rows/index.js.map +1 -1
  32. package/lib/plugins/responsive/index.js.map +1 -1
  33. package/lib/plugins/selection/index.js.map +1 -1
  34. package/lib/plugins/server-side/ServerSidePlugin.d.ts +4 -0
  35. package/lib/plugins/server-side/index.js +1 -1
  36. package/lib/plugins/server-side/index.js.map +1 -1
  37. package/lib/plugins/server-side/types.d.ts +48 -0
  38. package/lib/plugins/tooltip/index.js.map +1 -1
  39. package/lib/plugins/tree/index.js.map +1 -1
  40. package/lib/plugins/undo-redo/index.js.map +1 -1
  41. package/lib/plugins/visibility/index.js.map +1 -1
  42. package/package.json +1 -1
  43. package/public.d.ts +4 -1
  44. package/umd/grid.all.umd.js +1 -1
  45. package/umd/grid.all.umd.js.map +1 -1
  46. package/umd/grid.umd.js +1 -1
  47. package/umd/grid.umd.js.map +1 -1
  48. package/umd/plugins/clipboard.umd.js +1 -1
  49. package/umd/plugins/clipboard.umd.js.map +1 -1
  50. package/umd/plugins/editing.umd.js +1 -1
  51. package/umd/plugins/editing.umd.js.map +1 -1
  52. package/umd/plugins/export.umd.js +1 -1
  53. package/umd/plugins/export.umd.js.map +1 -1
  54. package/umd/plugins/filtering.umd.js +1 -1
  55. package/umd/plugins/filtering.umd.js.map +1 -1
  56. package/umd/plugins/multi-sort.umd.js +1 -1
  57. package/umd/plugins/multi-sort.umd.js.map +1 -1
  58. package/umd/plugins/pinned-rows.umd.js +1 -1
  59. package/umd/plugins/pinned-rows.umd.js.map +1 -1
  60. package/umd/plugins/server-side.umd.js +1 -1
  61. package/umd/plugins/server-side.umd.js.map +1 -1
@@ -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 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 '@toolbox-web/grid/features/server-side';\n *\n * grid.gridConfig = {\n * columns: [...],\n * features: {\n * serverSide: {\n * pageSize: 50,\n * 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 * },\n * };\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 // Auto-initialize from config when dataSource is provided declaratively\n if (this.config.dataSource) {\n this.setDataSource(this.config.dataSource);\n }\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","config","setDataSource","detach","clear","clearTimeout","getEnrichmentParams","sortResults","query","filterResults","getViewportMapping","viewportStart","viewportEnd","results","totalLoadedNodes","requestRender","applyServerResult","result","blockNum","lastNode","rows","length","getInfiniteScrollEstimate","maxLoadedEnd","loadRequiredBlocks","gridRef","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","refresh","ds","purgeCache","getTotalNodeCount","getTotalRowCount","isNodeLoaded","isRowLoaded","rowIndex","getLoadedBlockCount"],"mappings":"6aAEO,SAAS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,EACrB,CAKA,UAAAC,GACEhF,KAAK/B,aAAaqC,QAClBN,KAAKJ,aAAe,EACtB,CAKA,iBAAAqF,GACE,OAAOjF,KAAKX,cACd,CAKA,gBAAA6F,GACE,OAAOlF,KAAKX,cACd,CAMA,YAAA8F,CAAarI,GACX,MACMsE,EAAWvE,EAAeC,EADdkD,KAAKG,OAAOhB,gBAAkB,KAEhD,OAAOa,KAAK/B,aAAauE,IAAIpB,EAC/B,CAKA,WAAAgE,CAAYC,GACV,OAAOrF,KAAKmF,aAAaE,EAC3B,CAKA,mBAAAC,GACE,OAAOtF,KAAK/B,aAAawE,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 { builtInSort } from '../../core/internal/sorting';\nimport { BaseGridPlugin, ScrollEvent, type PluginManifest, type PluginQuery } from '../../core/plugin/base-plugin';\nimport type { ColumnConfig, 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 '@toolbox-web/grid/features/server-side';\n *\n * grid.gridConfig = {\n * columns: [...],\n * features: {\n * serverSide: {\n * pageSize: 50,\n * 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 * },\n * };\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 — gated by sortMode/filterMode.\n // 'local' (opt-in): keep cache; sort/filter the loaded rows in place via a re-render.\n // See getEnrichmentParams() — local-mode state is also omitted from block fetch params\n // so scroll-triggered loadRequiredBlocks() doesn't leak local state to the backend.\n this.on('sort-change', () => {\n if (this.config.sortMode === 'local') {\n this.requestRender();\n } else {\n this.onModelChange();\n }\n });\n this.on('filter-change', () => {\n if (this.config.filterMode === 'local') {\n this.requestRender();\n } else {\n this.onModelChange();\n }\n });\n\n // Auto-initialize from config when dataSource is provided declaratively\n if (this.config.dataSource) {\n this.setDataSource(this.config.dataSource);\n }\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 * When `sortMode === 'local'` the `sortModel` is omitted so scroll-triggered\n * block fetches don't ask the backend for an ordering it isn't applying.\n * Same for `filterMode === 'local'` and `filterModel`.\n */\n private getEnrichmentParams(): Partial<GetRowsParams> {\n const sortLocal = this.config.sortMode === 'local';\n const filterLocal = this.config.filterMode === 'local';\n const sortResults = sortLocal\n ? undefined\n : (this.grid?.query?.('sort:get-model', null) as\n | Array<{ field: string; direction: 'asc' | 'desc' }>[]\n | undefined);\n const filterResults = filterLocal\n ? undefined\n : (this.grid?.query?.('filter:get-model', null) as Record<string, unknown>[] | undefined);\n\n // Fallback to core single-column sort state when no plugin answers the\n // 'sort:get-model' query (e.g. MultiSortPlugin not loaded). Translate the\n // numeric direction (1/-1) to the public 'asc'/'desc' string form.\n let sortModel = sortResults?.[0];\n const host = this.grid as unknown as GridHost | undefined;\n if (!sortLocal && !sortModel && host?._sortState) {\n const { field, direction } = host._sortState;\n sortModel = [{ field, direction: direction === 1 ? 'asc' : 'desc' }];\n }\n\n return {\n sortModel,\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 // Eagerly fetch the current viewport with the new enrichment params.\n // Without this, the table stays blank until the user scrolls (no other\n // path triggers a fetch — processRows just rebuilds from cached blocks).\n this.loadRequiredBlocks();\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 // Expand the viewport by loadThreshold in both directions to prefetch\n // blocks the user is about to scroll into. The end is clamped to\n // totalNodeCount when known so we don't request blocks past the end of\n // data — but `totalNodeCount = 0` means \"not yet loaded\" (e.g. just after\n // purgeCache or before the first fetch resolves), in which case we leave\n // it unclamped so the initial block can be fetched.\n const threshold = Math.max(0, this.config.loadThreshold ?? 0);\n const expandedStart = Math.max(0, viewport.startNode - threshold);\n const knownTotal = this.totalNodeCount > 0 ? this.totalNodeCount : Infinity;\n const expandedEnd = Math.min(knownTotal, viewport.endNode + threshold);\n if (expandedEnd <= expandedStart) return;\n\n // Determine which blocks are needed for current viewport (in node space)\n const requiredBlocks = getRequiredBlocks(expandedStart, expandedEnd, 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 // Capture pre-update length so we can detect whether processRows must\n // re-run to grow the managedNodes array (e.g. after onModelChange reset).\n const previousManagedLength = this.managedNodes.length;\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 // If managedNodes still hasn't been sized for the (possibly newly known)\n // totalNodeCount — typically because onModelChange() reset it to 0 right\n // before this fetch — we MUST run processRows to grow the array. The\n // in-place writes above are no-ops in that case (length is 0).\n // Without this, sort/filter changes leave the grid permanently blank\n // until something else triggers a ROWS phase.\n const needsRowModelRebuild =\n previousManagedLength === 0 ||\n this.managedNodes.length < (Number.isFinite(this.totalNodeCount) ? this.totalNodeCount : 0);\n\n if (needsRowModelRebuild) {\n this.requestRender();\n } else {\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\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 // Local-mode sort: when sortMode === 'local' the plugin owns ordering of\n // the loaded rows itself (core sort ran on the input but we discarded it\n // by returning managedNodes). Apply the current core sort state on top of\n // managedNodes so the user sees in-place sorting without a refetch.\n // Note: any plugin sort that runs after us (priority > -10, e.g. multi-sort)\n // will further re-sort our output, which is the intended chain.\n const host = this.grid as unknown as GridHost | undefined;\n if (this.config.sortMode === 'local' && host?._sortState) {\n const columns = (host._columns ?? []) as ColumnConfig[];\n return builtInSort(this.managedNodes, host._sortState, columns);\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 // When loadThreshold is configured, re-check the viewport so the\n // prefetch can pull in additional blocks immediately rather than\n // waiting for the user's first scroll. Gated on the threshold to\n // preserve the historical \"first fetch loads block 0 only\" behavior.\n if ((this.config.loadThreshold ?? 0) > 0) {\n this.loadRequiredBlocks();\n }\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","config","sortMode","requestRender","onModelChange","filterMode","setDataSource","detach","clear","clearTimeout","getEnrichmentParams","sortLocal","filterLocal","sortResults","query","filterResults","host","_sortState","field","direction","getViewportMapping","viewportStart","viewportEnd","results","totalLoadedNodes","loadRequiredBlocks","applyServerResult","result","blockNum","lastNode","rows","length","getInfiniteScrollEstimate","maxLoadedEnd","gridRef","viewport","_virtualization","threshold","max","loadThreshold","expandedStart","knownTotal","Infinity","expandedEnd","min","requiredBlocks","startBlock","endBlock","blocks","i","push","getRequiredBlocks","enrichment","gridId","getAttribute","has","size","debugDiagnostic","DATASOURCE_THROTTLED","add","broadcast","loading","then","set","previousManagedLength","delete","detail","claimed","Number","isFinite","requestVirtualRefresh","catch","error","err","Error","String","errorDiagnostic","DATASOURCE_FETCH_ERROR","message","nodeCount","__loading","__index","cached","columns","_columns","builtInSort","onScroll","event","setTimeout","handleQuery","context","fetchChildren","getChildRows","warnDiagnostic","DATASOURCE_NO_CHILD_HANDLER","source","DATASOURCE_CHILD_FETCH_ERROR","refresh","ds","purgeCache","getTotalNodeCount","getTotalRowCount","isNodeLoaded","isRowLoaded","rowIndex","getLoadedBlockCount"],"mappings":"8fAEO,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,EACAC,EACAkB,GAEA,MAAMZ,EAAcR,EAAeC,EAAWC,GACxCmB,EAAQD,EAAaE,IAAId,GAC/B,IAAKa,EAAO,OAGZ,OAAOA,EADcpB,EAAYC,EAEnC,CCsCO,MAAMqB,UAAyBC,EAAAA,eAKpCC,gBAAoD,CAClDC,sBAAsB,EACtBC,aAAc,CACZC,aAAa,IAEfC,iBAAkB,CAChB,CACEC,KAAM,QACNC,OACE,qKAINC,OAAQ,CACN,CAAEC,KAAM,kBAAmBC,YAAa,+BACxC,CAAED,KAAM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