@toolbox-web/grid 2.11.1 → 2.13.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.
- package/all.js +2 -2
- package/all.js.map +1 -1
- package/custom-elements.json +20 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/lib/core/grid.d.ts +24 -2
- package/lib/core/internal/empty.d.ts +73 -0
- package/lib/core/internal/focus-manager.d.ts +17 -0
- package/lib/core/internal/shell.d.ts +1 -1
- package/lib/core/internal/virtualization.d.ts +103 -1
- package/lib/core/styles/index.d.ts +3 -2
- package/lib/core/types.d.ts +103 -7
- package/lib/features/pinned-columns.js.map +1 -1
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/editing/EditingPlugin.d.ts +1 -1
- package/lib/plugins/editing/index.js +1 -1
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/editing/types.d.ts +9 -1
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/index.js +1 -1
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js +1 -1
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/print/index.js.map +1 -1
- package/lib/plugins/reorder-columns/index.js +1 -1
- package/lib/plugins/reorder-columns/index.js.map +1 -1
- package/lib/plugins/reorder-rows/index.js +1 -1
- package/lib/plugins/reorder-rows/index.js.map +1 -1
- package/lib/plugins/responsive/index.js +1 -1
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/row-drag-drop/RowDragDropPlugin.d.ts +1 -1
- package/lib/plugins/row-drag-drop/index.js +1 -1
- package/lib/plugins/row-drag-drop/index.js.map +1 -1
- package/lib/plugins/selection/SelectionPlugin.d.ts +1 -1
- package/lib/plugins/selection/index.d.ts +1 -1
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/ServerSidePlugin.d.ts +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/sticky-rows/index.js.map +1 -1
- package/lib/plugins/tooltip/index.js.map +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/public.d.ts +10 -1
- package/umd/grid.all.umd.js +1 -1
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +1 -1
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/editing.umd.js.map +1 -1
- package/umd/plugins/pinned-columns.umd.js +1 -1
- package/umd/plugins/pinned-columns.umd.js.map +1 -1
- package/umd/plugins/reorder-rows.umd.js.map +1 -1
- package/umd/plugins/row-drag-drop.umd.js.map +1 -1
- package/umd/plugins/selection.umd.js.map +1 -1
- 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, Subscribable } 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\nfunction isSubscribable<T>(value: unknown): value is Subscribable<T> {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { subscribe?: unknown }).subscribe === 'function' &&\n // Promises don't have `.subscribe`, but defensively rule them out.\n typeof (value as { then?: unknown }).then !== 'function'\n );\n}\n\nfunction makeAbortError(): DOMException {\n return new DOMException('Aborted', 'AbortError');\n}\n\n/**\n * Bridge a `Promise | Subscribable` getRows return value into a single\n * `Promise<GetRowsResult>`. For Subscribables, abort triggers `unsubscribe()`\n * so the underlying request (e.g. Angular `HttpClient` XHR) is cancelled.\n * Promise sources should pass `signal` to `fetch` themselves — we still reject\n * on abort either way so the plugin's abort path is consistent.\n */\nexport function toResultPromise<T>(\n source: Promise<T> | Subscribable<T>,\n signal: AbortSignal,\n): Promise<T> {\n if (signal.aborted) {\n return Promise.reject(makeAbortError());\n }\n if (!isSubscribable<T>(source)) {\n // Promise path: reject on abort so the plugin's catch sees a consistent\n // signal even if the underlying fetch ignored params.signal.\n return new Promise<T>((resolve, reject) => {\n const onAbort = () => reject(makeAbortError());\n signal.addEventListener('abort', onAbort, { once: true });\n Promise.resolve(source).then(\n (v) => {\n signal.removeEventListener('abort', onAbort);\n resolve(v);\n },\n (e) => {\n signal.removeEventListener('abort', onAbort);\n reject(e);\n },\n );\n });\n }\n // Subscribable path: subscribe once, settle on next/error/complete, and\n // unsubscribe on abort — that's what cancels HttpClient's XHR.\n return new Promise<T>((resolve, reject) => {\n let settled = false;\n const subscription = source.subscribe({\n next: (value) => {\n if (settled) return;\n settled = true;\n resolve(value);\n subscription.unsubscribe();\n },\n error: (err) => {\n if (settled) return;\n settled = true;\n reject(err);\n },\n complete: () => {\n if (settled) return;\n settled = true;\n reject(new Error('getRows observable completed without emitting a value'));\n },\n });\n if (settled) return; // synchronous emit\n const onAbort = () => {\n if (settled) return;\n settled = true;\n subscription.unsubscribe();\n reject(makeAbortError());\n };\n signal.addEventListener('abort', onAbort, { once: true });\n });\n}\n\nexport function loadBlock(\n dataSource: ServerSideDataSource,\n blockNumber: number,\n blockSize: number,\n params: Partial<GetRowsParams>,\n signal: AbortSignal,\n): Promise<GetRowsResult> {\n const range = getBlockRange(blockNumber, blockSize);\n\n const result = dataSource.getRows({\n startNode: range.start,\n endNode: range.end,\n sortModel: params.sortModel,\n filterModel: params.filterModel,\n signal,\n });\n return toResultPromise(result, signal);\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 * @since 0.1.1\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 /**\n * Per-block AbortControllers for in-flight requests. Aborted when a block\n * is superseded (sort/filter change, refresh, purgeCache, detach) so data\n * sources that honor `params.signal` (e.g. `fetch`, RxJS via `fromObservable`)\n * can cancel the underlying network call.\n */\n private blockControllers = new Map<number, AbortController>();\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.abortAllBlocks();\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 * Abort all in-flight block requests. Called when the plugin tears down,\n * the data source is replaced, the cache is purged, or the sort/filter\n * model changes (the previously loaded block coordinates no longer apply).\n */\n private abortAllBlocks(): void {\n for (const controller of this.blockControllers.values()) {\n controller.abort();\n }\n this.blockControllers.clear();\n }\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.abortAllBlocks();\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 const controller = new AbortController();\n this.blockControllers.set(blockNum, controller);\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: true });\n\n loadBlock(this.dataSource, blockNum, blockSize, enrichment, controller.signal)\n .then((result) => {\n this.blockControllers.delete(blockNum);\n // Drop results from a request that was superseded after the await\n // resolved (data source ignored the abort signal). Without this guard\n // a stale block would land in the cache after a sort/filter change.\n if (controller.signal.aborted) {\n this.loadingBlocks.delete(blockNum);\n if (this.loadingBlocks.size === 0) {\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: false });\n }\n return;\n }\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.blockControllers.delete(blockNum);\n this.loadingBlocks.delete(blockNum);\n // A superseded request may surface as either an AbortError or as a\n // user-thrown error after the data source detected the abort —\n // suppress diagnostics in both cases. Real failures still surface.\n if (controller.signal.aborted) {\n if (this.loadingBlocks.size === 0) {\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: false });\n }\n return;\n }\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 // Honor user's gridConfig.sortHandler when provided — same resolution\n // as core's reapplyCoreSort/applySort. processRows is synchronous, so\n // async handlers cannot be awaited here: keep the current managedNodes\n // order for this pass and swallow any rejection so it doesn't surface\n // as an unhandled promise rejection. The next core sort cycle (or the\n // next block load) will re-invoke this path with up-to-date state.\n const handler = host.effectiveConfig?.sortHandler ?? builtInSort;\n const result = handler(this.managedNodes, host._sortState, columns);\n if (result && typeof (result as Promise<unknown[]>).then === 'function') {\n void (result as Promise<unknown[]>).catch(() => undefined);\n return this.managedNodes;\n }\n return result as unknown[];\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.abortAllBlocks();\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 const controller = new AbortController();\n this.blockControllers.set(0, controller);\n this.loadingBlocks.add(0);\n\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: true });\n\n loadBlock(dataSource, 0, blockSize, enrichment, controller.signal)\n .then((result) => {\n this.blockControllers.delete(0);\n this.loadingBlocks.delete(0);\n if (controller.signal.aborted) {\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: false });\n return;\n }\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 this.blockControllers.delete(0);\n this.loadingBlocks.delete(0);\n if (controller.signal.aborted) {\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: false });\n return;\n }\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.abortAllBlocks();\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.abortAllBlocks();\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","makeAbortError","DOMException","loadBlock","dataSource","blockNumber","params","signal","range","start","end","getBlockRange","source","aborted","Promise","reject","value","subscribe","then","resolve","onAbort","addEventListener","once","v","removeEventListener","e","settled","subscription","next","unsubscribe","error","err","complete","Error","toResultPromise","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","blockControllers","lastRequestId","scrollDebounceTimer","managedNodes","attach","grid","super","this","on","config","sortMode","requestRender","onModelChange","filterMode","setDataSource","detach","clear","abortAllBlocks","clearTimeout","controller","values","abort","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","AbortController","set","broadcast","loading","delete","previousManagedLength","detail","claimed","Number","isFinite","requestVirtualRefresh","catch","String","errorDiagnostic","DATASOURCE_FETCH_ERROR","message","nodeCount","__loading","__index","cached","columns","_columns","effectiveConfig","sortHandler","builtInSort","onScroll","event","setTimeout","handleQuery","context","fetchChildren","getChildRows","warnDiagnostic","DATASOURCE_NO_CHILD_HANDLER","DATASOURCE_CHILD_FETCH_ERROR","refresh","ds","purgeCache","getTotalNodeCount","getTotalRowCount","isNodeLoaded","isRowLoaded","rowIndex","getLoadedBlockCount"],"mappings":"8fAEO,SAASA,EAAeC,EAAmBC,GAChD,OAAOC,KAAKC,MAAMH,EAAYC,EAChC,CA8BA,SAASG,IACP,OAAO,IAAIC,aAAa,UAAW,aACrC,CAmEO,SAASC,EACdC,EACAC,EACAP,EACAQ,EACAC,GAEA,MAAMC,EAxGD,SAAuBH,EAAqBP,GACjD,MAAO,CACLW,MAAOJ,EAAcP,EACrBY,KAAML,EAAc,GAAKP,EAE7B,CAmGgBa,CAAcN,EAAaP,GASzC,OA1EK,SACLc,EACAL,GAEA,OAAIA,EAAOM,QACFC,QAAQC,OAAOd,KAxBL,iBAFMe,EA4BFJ,IAzBX,OAAVI,GACwD,mBAAhDA,EAAkCC,WAEI,mBAAtCD,EAA6BE,KAyB9B,IAAIJ,QAAW,CAACK,EAASJ,KAC9B,MAAMK,EAAU,IAAML,EAAOd,KAC7BM,EAAOc,iBAAiB,QAASD,EAAS,CAAEE,MAAM,IAClDR,QAAQK,QAAQP,GAAQM,KACrBK,IACChB,EAAOiB,oBAAoB,QAASJ,GACpCD,EAAQI,IAETE,IACClB,EAAOiB,oBAAoB,QAASJ,GACpCL,EAAOU,OAOR,IAAIX,QAAW,CAACK,EAASJ,KAC9B,IAAIW,GAAU,EACd,MAAMC,EAAef,EAAOK,UAAU,CACpCW,KAAOZ,IACDU,IACJA,GAAU,EACVP,EAAQH,GACRW,EAAaE,gBAEfC,MAAQC,IACFL,IACJA,GAAU,EACVX,EAAOgB,KAETC,SAAU,KACJN,IACJA,GAAU,EACVX,EAAO,IAAIkB,MAAM,8DAGjBP,GAOJnB,EAAOc,iBAAiB,QANR,KACVK,IACJA,GAAU,EACVC,EAAaE,cACbd,EAAOd,OAEiC,CAAEqB,MAAM,MA3EtD,IAA2BN,CA6E3B,CAkBSkB,CAPQ9B,EAAW+B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|
+
{"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, Subscribable } 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\nfunction isSubscribable<T>(value: unknown): value is Subscribable<T> {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { subscribe?: unknown }).subscribe === 'function' &&\n // Promises don't have `.subscribe`, but defensively rule them out.\n typeof (value as { then?: unknown }).then !== 'function'\n );\n}\n\nfunction makeAbortError(): DOMException {\n return new DOMException('Aborted', 'AbortError');\n}\n\n/**\n * Bridge a `Promise | Subscribable` getRows return value into a single\n * `Promise<GetRowsResult>`. For Subscribables, abort triggers `unsubscribe()`\n * so the underlying request (e.g. Angular `HttpClient` XHR) is cancelled.\n * Promise sources should pass `signal` to `fetch` themselves — we still reject\n * on abort either way so the plugin's abort path is consistent.\n */\nexport function toResultPromise<T>(\n source: Promise<T> | Subscribable<T>,\n signal: AbortSignal,\n): Promise<T> {\n if (signal.aborted) {\n return Promise.reject(makeAbortError());\n }\n if (!isSubscribable<T>(source)) {\n // Promise path: reject on abort so the plugin's catch sees a consistent\n // signal even if the underlying fetch ignored params.signal.\n return new Promise<T>((resolve, reject) => {\n const onAbort = () => reject(makeAbortError());\n signal.addEventListener('abort', onAbort, { once: true });\n Promise.resolve(source).then(\n (v) => {\n signal.removeEventListener('abort', onAbort);\n resolve(v);\n },\n (e) => {\n signal.removeEventListener('abort', onAbort);\n reject(e);\n },\n );\n });\n }\n // Subscribable path: subscribe once, settle on next/error/complete, and\n // unsubscribe on abort — that's what cancels HttpClient's XHR.\n return new Promise<T>((resolve, reject) => {\n let settled = false;\n const subscription = source.subscribe({\n next: (value) => {\n if (settled) return;\n settled = true;\n resolve(value);\n subscription.unsubscribe();\n },\n error: (err) => {\n if (settled) return;\n settled = true;\n reject(err);\n },\n complete: () => {\n if (settled) return;\n settled = true;\n reject(new Error('getRows observable completed without emitting a value'));\n },\n });\n if (settled) return; // synchronous emit\n const onAbort = () => {\n if (settled) return;\n settled = true;\n subscription.unsubscribe();\n reject(makeAbortError());\n };\n signal.addEventListener('abort', onAbort, { once: true });\n });\n}\n\nexport function loadBlock(\n dataSource: ServerSideDataSource,\n blockNumber: number,\n blockSize: number,\n params: Partial<GetRowsParams>,\n signal: AbortSignal,\n): Promise<GetRowsResult> {\n const range = getBlockRange(blockNumber, blockSize);\n\n const result = dataSource.getRows({\n startNode: range.start,\n endNode: range.end,\n sortModel: params.sortModel,\n filterModel: params.filterModel,\n signal,\n });\n return toResultPromise(result, signal);\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 * @since 0.1.1\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 /**\n * Per-block AbortControllers for in-flight requests. Aborted when a block\n * is superseded (sort/filter change, refresh, purgeCache, detach) so data\n * sources that honor `params.signal` (e.g. `fetch`, RxJS via `fromObservable`)\n * can cancel the underlying network call.\n */\n private blockControllers = new Map<number, AbortController>();\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.abortAllBlocks();\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 * Abort all in-flight block requests. Called when the plugin tears down,\n * the data source is replaced, the cache is purged, or the sort/filter\n * model changes (the previously loaded block coordinates no longer apply).\n */\n private abortAllBlocks(): void {\n for (const controller of this.blockControllers.values()) {\n controller.abort();\n }\n this.blockControllers.clear();\n }\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.abortAllBlocks();\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 const controller = new AbortController();\n this.blockControllers.set(blockNum, controller);\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: true });\n\n loadBlock(this.dataSource, blockNum, blockSize, enrichment, controller.signal)\n .then((result) => {\n this.blockControllers.delete(blockNum);\n // Drop results from a request that was superseded after the await\n // resolved (data source ignored the abort signal). Without this guard\n // a stale block would land in the cache after a sort/filter change.\n if (controller.signal.aborted) {\n this.loadingBlocks.delete(blockNum);\n if (this.loadingBlocks.size === 0) {\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: false });\n }\n return;\n }\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.blockControllers.delete(blockNum);\n this.loadingBlocks.delete(blockNum);\n // A superseded request may surface as either an AbortError or as a\n // user-thrown error after the data source detected the abort —\n // suppress diagnostics in both cases. Real failures still surface.\n if (controller.signal.aborted) {\n if (this.loadingBlocks.size === 0) {\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: false });\n }\n return;\n }\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 // Honor user's gridConfig.sortHandler when provided — same resolution\n // as core's reapplyCoreSort/applySort. processRows is synchronous, so\n // async handlers cannot be awaited here: keep the current managedNodes\n // order for this pass and swallow any rejection so it doesn't surface\n // as an unhandled promise rejection. The next core sort cycle (or the\n // next block load) will re-invoke this path with up-to-date state.\n const handler = host.effectiveConfig?.sortHandler ?? builtInSort;\n const result = handler(this.managedNodes, host._sortState, columns);\n if (result && typeof (result as Promise<unknown[]>).then === 'function') {\n void (result as Promise<unknown[]>).catch(() => undefined);\n return this.managedNodes;\n }\n return result as unknown[];\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.abortAllBlocks();\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 const controller = new AbortController();\n this.blockControllers.set(0, controller);\n this.loadingBlocks.add(0);\n\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: true });\n\n loadBlock(dataSource, 0, blockSize, enrichment, controller.signal)\n .then((result) => {\n this.blockControllers.delete(0);\n this.loadingBlocks.delete(0);\n if (controller.signal.aborted) {\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: false });\n return;\n }\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 this.blockControllers.delete(0);\n this.loadingBlocks.delete(0);\n if (controller.signal.aborted) {\n this.broadcast<DataSourceLoadingDetail>('datasource:loading', { loading: false });\n return;\n }\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.abortAllBlocks();\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.abortAllBlocks();\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","makeAbortError","DOMException","loadBlock","dataSource","blockNumber","params","signal","range","start","end","getBlockRange","source","aborted","Promise","reject","value","subscribe","then","resolve","onAbort","addEventListener","once","v","removeEventListener","e","settled","subscription","next","unsubscribe","error","err","complete","Error","toResultPromise","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","blockControllers","lastRequestId","scrollDebounceTimer","managedNodes","attach","grid","super","this","on","config","sortMode","requestRender","onModelChange","filterMode","setDataSource","detach","clear","abortAllBlocks","clearTimeout","controller","values","abort","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","AbortController","set","broadcast","loading","delete","previousManagedLength","detail","claimed","Number","isFinite","requestVirtualRefresh","catch","String","errorDiagnostic","DATASOURCE_FETCH_ERROR","message","nodeCount","__loading","__index","cached","columns","_columns","effectiveConfig","sortHandler","builtInSort","onScroll","_event","setTimeout","handleQuery","context","fetchChildren","getChildRows","warnDiagnostic","DATASOURCE_NO_CHILD_HANDLER","DATASOURCE_CHILD_FETCH_ERROR","refresh","ds","purgeCache","getTotalNodeCount","getTotalRowCount","isNodeLoaded","isRowLoaded","rowIndex","getLoadedBlockCount"],"mappings":"8fAEO,SAASA,EAAeC,EAAmBC,GAChD,OAAOC,KAAKC,MAAMH,EAAYC,EAChC,CA8BA,SAASG,IACP,OAAO,IAAIC,aAAa,UAAW,aACrC,CAmEO,SAASC,EACdC,EACAC,EACAP,EACAQ,EACAC,GAEA,MAAMC,EAxGD,SAAuBH,EAAqBP,GACjD,MAAO,CACLW,MAAOJ,EAAcP,EACrBY,KAAML,EAAc,GAAKP,EAE7B,CAmGgBa,CAAcN,EAAaP,GASzC,OA1EK,SACLc,EACAL,GAEA,OAAIA,EAAOM,QACFC,QAAQC,OAAOd,KAxBL,iBAFMe,EA4BFJ,IAzBX,OAAVI,GACwD,mBAAhDA,EAAkCC,WAEI,mBAAtCD,EAA6BE,KAyB9B,IAAIJ,QAAW,CAACK,EAASJ,KAC9B,MAAMK,EAAU,IAAML,EAAOd,KAC7BM,EAAOc,iBAAiB,QAASD,EAAS,CAAEE,MAAM,IAClDR,QAAQK,QAAQP,GAAQM,KACrBK,IACChB,EAAOiB,oBAAoB,QAASJ,GACpCD,EAAQI,IAETE,IACClB,EAAOiB,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