@toolbox-web/grid 2.6.0 → 2.7.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 (57) hide show
  1. package/all.d.ts +1 -0
  2. package/all.js +2 -2
  3. package/all.js.map +1 -1
  4. package/index.js +1 -1
  5. package/index.js.map +1 -1
  6. package/lib/core/internal/aria.d.ts +4 -0
  7. package/lib/core/types.d.ts +43 -0
  8. package/lib/features/sticky-rows.d.ts +9 -0
  9. package/lib/features/sticky-rows.js +2 -0
  10. package/lib/features/sticky-rows.js.map +1 -0
  11. package/lib/plugins/clipboard/index.js.map +1 -1
  12. package/lib/plugins/column-virtualization/index.js.map +1 -1
  13. package/lib/plugins/context-menu/index.js +1 -1
  14. package/lib/plugins/context-menu/index.js.map +1 -1
  15. package/lib/plugins/editing/index.js.map +1 -1
  16. package/lib/plugins/export/index.js.map +1 -1
  17. package/lib/plugins/filtering/index.js.map +1 -1
  18. package/lib/plugins/grouping-columns/index.js.map +1 -1
  19. package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts +15 -0
  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.map +1 -1
  24. package/lib/plugins/pinned-columns/index.js.map +1 -1
  25. package/lib/plugins/pinned-rows/index.js.map +1 -1
  26. package/lib/plugins/pivot/index.js.map +1 -1
  27. package/lib/plugins/print/index.js.map +1 -1
  28. package/lib/plugins/reorder-columns/index.js.map +1 -1
  29. package/lib/plugins/reorder-rows/index.js.map +1 -1
  30. package/lib/plugins/responsive/index.js.map +1 -1
  31. package/lib/plugins/row-drag-drop/index.js.map +1 -1
  32. package/lib/plugins/selection/index.js.map +1 -1
  33. package/lib/plugins/server-side/index.js.map +1 -1
  34. package/lib/plugins/sticky-rows/StickyRowsPlugin.d.ts +114 -0
  35. package/lib/plugins/sticky-rows/index.d.ts +7 -0
  36. package/lib/plugins/sticky-rows/index.js +2 -0
  37. package/lib/plugins/sticky-rows/index.js.map +1 -0
  38. package/lib/plugins/sticky-rows/types.d.ts +67 -0
  39. package/lib/plugins/tooltip/index.js.map +1 -1
  40. package/lib/plugins/tree/index.js +1 -1
  41. package/lib/plugins/tree/index.js.map +1 -1
  42. package/lib/plugins/tree/types.d.ts +4 -0
  43. package/lib/plugins/undo-redo/index.js.map +1 -1
  44. package/lib/plugins/visibility/index.js.map +1 -1
  45. package/package.json +1 -1
  46. package/umd/grid.all.umd.js +1 -1
  47. package/umd/grid.all.umd.js.map +1 -1
  48. package/umd/grid.umd.js +1 -1
  49. package/umd/grid.umd.js.map +1 -1
  50. package/umd/plugins/context-menu.umd.js +1 -1
  51. package/umd/plugins/context-menu.umd.js.map +1 -1
  52. package/umd/plugins/grouping-rows.umd.js +1 -1
  53. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  54. package/umd/plugins/sticky-rows.umd.js +2 -0
  55. package/umd/plugins/sticky-rows.umd.js.map +1 -0
  56. package/umd/plugins/tree.umd.js +1 -1
  57. package/umd/plugins/tree.umd.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"tree.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/tree/tree-data.ts","../../../../../libs/grid/src/lib/plugins/tree/tree-datasource.ts","../../../../../libs/grid/src/lib/plugins/tree/tree-detect.ts","../../../../../libs/grid/src/lib/plugins/tree/TreePlugin.ts"],"sourcesContent":["/**\n * Core Tree Data Logic\n *\n * Pure functions for tree flattening, expansion, and traversal.\n */\n\nimport type { FlattenedTreeRow, TreeConfig, TreeRow } from './types';\n\n/**\n * Generates a unique key for a row.\n * Uses row.id if available, otherwise generates from path.\n */\nexport function generateRowKey(row: TreeRow, index: number, parentKey: string | null): string {\n if (row.id !== undefined) return String(row.id);\n return parentKey ? `${parentKey}-${index}` : String(index);\n}\n\n/**\n * Flattens a hierarchical tree into a flat array of rows with metadata.\n * Only includes children of expanded nodes.\n */\nexport function flattenTree(\n rows: readonly TreeRow[],\n config: TreeConfig,\n expandedKeys: Set<string>,\n parentKey: string | null = null,\n depth = 0,\n): FlattenedTreeRow[] {\n const childrenField = config.childrenField ?? 'children';\n const result: FlattenedTreeRow[] = [];\n\n for (let i = 0; i < rows.length; i++) {\n const row = rows[i];\n const key = generateRowKey(row, i, parentKey);\n const children = row[childrenField];\n const hasChildren = Array.isArray(children) && children.length > 0;\n const isExpanded = expandedKeys.has(key);\n\n result.push({\n key,\n data: row,\n depth,\n hasChildren,\n isExpanded,\n parentKey,\n });\n\n // Recursively add children if expanded\n if (hasChildren && isExpanded) {\n const childRows = flattenTree(children as TreeRow[], config, expandedKeys, key, depth + 1);\n result.push(...childRows);\n }\n }\n\n return result;\n}\n\n/**\n * Toggles the expansion state of a row.\n * Returns a new Set with the toggled state.\n */\nexport function toggleExpand(expandedKeys: Set<string>, key: string): Set<string> {\n const newExpanded = new Set(expandedKeys);\n if (newExpanded.has(key)) {\n newExpanded.delete(key);\n } else {\n newExpanded.add(key);\n }\n return newExpanded;\n}\n\n/**\n * Expands all nodes in the tree.\n * Returns a Set of all parent row keys.\n */\nexport function expandAll(\n rows: readonly TreeRow[],\n config: TreeConfig,\n parentKey: string | null = null,\n depth = 0,\n): Set<string> {\n const childrenField = config.childrenField ?? 'children';\n const keys = new Set<string>();\n\n for (let i = 0; i < rows.length; i++) {\n const row = rows[i];\n const key = generateRowKey(row, i, parentKey);\n const children = row[childrenField];\n\n if (Array.isArray(children) && children.length > 0) {\n keys.add(key);\n const childKeys = expandAll(children as TreeRow[], config, key, depth + 1);\n for (const k of childKeys) keys.add(k);\n }\n }\n\n return keys;\n}\n\n/**\n * Collapses all nodes.\n * Returns an empty Set.\n */\nexport function collapseAll(): Set<string> {\n return new Set();\n}\n\n/**\n * Gets all descendants of a node from the flattened row list.\n * Useful for operations that need to affect an entire subtree.\n */\nexport function getDescendants(flattenedRows: FlattenedTreeRow[], parentKey: string): FlattenedTreeRow[] {\n const descendants: FlattenedTreeRow[] = [];\n let collecting = false;\n let parentDepth = -1;\n\n for (const row of flattenedRows) {\n if (row.key === parentKey) {\n collecting = true;\n parentDepth = row.depth;\n continue;\n }\n\n if (collecting) {\n if (row.depth > parentDepth) {\n descendants.push(row);\n } else {\n break; // No longer a descendant\n }\n }\n }\n\n return descendants;\n}\n\n/**\n * Finds the path from root to a specific row key.\n * Returns an array of keys from root to the target (inclusive).\n */\nexport function getPathToKey(\n rows: readonly TreeRow[],\n targetKey: string,\n config: TreeConfig,\n parentKey: string | null = null,\n depth = 0,\n): string[] | null {\n const childrenField = config.childrenField ?? 'children';\n\n for (let i = 0; i < rows.length; i++) {\n const row = rows[i];\n const key = generateRowKey(row, i, parentKey);\n\n if (key === targetKey) {\n return [key];\n }\n\n const children = row[childrenField];\n if (Array.isArray(children) && children.length > 0) {\n const childPath = getPathToKey(children as TreeRow[], targetKey, config, key, depth + 1);\n if (childPath) {\n return [key, ...childPath];\n }\n }\n }\n\n return null;\n}\n\n/**\n * Expands all ancestors of a specific row to make it visible.\n * Returns a new Set with the required keys added.\n */\nexport function expandToKey(\n rows: readonly TreeRow[],\n targetKey: string,\n config: TreeConfig,\n existingExpanded: Set<string>,\n): Set<string> {\n const path = getPathToKey(rows, targetKey, config);\n if (!path) return existingExpanded;\n\n const newExpanded = new Set(existingExpanded);\n // Add all keys except the last one (the target itself)\n for (let i = 0; i < path.length - 1; i++) {\n newExpanded.add(path[i]);\n }\n return newExpanded;\n}\n","/**\n * Tree Viewport Mapping Utilities\n *\n * Pure functions for translating between flat viewport row indices and\n * top-level tree node indices. Used by the Tree plugin's\n * `datasource:viewport-mapping` query handler.\n */\n\nimport type { FlattenedTreeRow } from './types';\n\n/**\n * Given a flat row index in the viewport, find the index of the\n * top-level node (depth 0) that \"owns\" that row.\n *\n * Walk backwards from the row index until a depth-0 row is found,\n * then return its position among all depth-0 rows.\n */\nexport function getTopLevelNodeIndex(flattenedRows: FlattenedTreeRow[], flatRowIndex: number): number {\n // Clamp to valid range\n const idx = Math.min(flatRowIndex, flattenedRows.length - 1);\n if (idx < 0) return 0;\n\n // Walk backwards to find the owning top-level node\n let current = idx;\n while (current > 0 && flattenedRows[current].depth > 0) {\n current--;\n }\n\n // Count how many depth-0 nodes precede this one (inclusive)\n let topLevelIndex = 0;\n for (let i = 0; i <= current; i++) {\n if (flattenedRows[i].depth === 0) {\n topLevelIndex++;\n }\n }\n // Convert to 0-based\n return topLevelIndex - 1;\n}\n\n/**\n * Count the number of top-level (depth 0) nodes in the flattened rows.\n */\nexport function countTopLevelNodes(flattenedRows: FlattenedTreeRow[]): number {\n let count = 0;\n for (const row of flattenedRows) {\n if (row.depth === 0) count++;\n }\n return count;\n}\n","/**\n * Tree Structure Auto-Detection\n *\n * Utilities for detecting hierarchical tree data structures.\n */\n\nimport type { TreeRow } from './types';\n\n/**\n * Detects if the data has a tree structure by checking for children arrays.\n */\nexport function detectTreeStructure(rows: readonly TreeRow[], childrenField = 'children'): boolean {\n if (!Array.isArray(rows) || rows.length === 0) return false;\n\n // Check if any row has children (embedded array or lazy indicator)\n for (const row of rows) {\n if (!row) continue;\n const children = row[childrenField];\n // Embedded children: non-empty array\n if (Array.isArray(children) && children.length > 0) return true;\n // Lazy children: truthy non-array value (e.g. `true`, number > 0)\n if (children != null && !Array.isArray(children) && !!children) return true;\n }\n\n return false;\n}\n\n/**\n * Attempts to infer the children field name from common patterns.\n * Returns the first field that contains an array with items.\n */\nexport function inferChildrenField(rows: readonly TreeRow[]): string | null {\n if (!Array.isArray(rows) || rows.length === 0) return null;\n\n const commonArrayFields = ['children', 'items', 'nodes', 'subRows', 'nested'];\n\n for (const row of rows) {\n if (!row || typeof row !== 'object') continue;\n\n for (const field of commonArrayFields) {\n const value = row[field];\n if (Array.isArray(value) && value.length > 0) {\n return field;\n }\n }\n }\n\n return null;\n}\n\n/**\n * Calculates the maximum depth of the tree.\n * Useful for layout calculations and virtualization.\n */\nexport function getMaxDepth(rows: readonly TreeRow[], childrenField = 'children', currentDepth = 0): number {\n if (!Array.isArray(rows) || rows.length === 0) return currentDepth;\n\n let maxDepth = currentDepth;\n\n for (const row of rows) {\n if (!row) continue;\n const children = row[childrenField];\n if (Array.isArray(children) && children.length > 0) {\n const childDepth = getMaxDepth(children as TreeRow[], childrenField, currentDepth + 1);\n if (childDepth > maxDepth) {\n maxDepth = childDepth;\n }\n }\n }\n\n return maxDepth;\n}\n\n/**\n * Counts total nodes in the tree (including all descendants).\n */\nexport function countNodes(rows: readonly TreeRow[], childrenField = 'children'): number {\n if (!Array.isArray(rows)) return 0;\n\n let count = 0;\n for (const row of rows) {\n if (!row) continue;\n count++;\n const children = row[childrenField];\n if (Array.isArray(children)) {\n count += countNodes(children as TreeRow[], childrenField);\n }\n }\n\n return count;\n}\n","/**\n * Tree Data Plugin\n *\n * Enables hierarchical tree data with expand/collapse, sorting, and auto-detection.\n */\n\nimport { GridClasses } from '../../core/constants';\nimport { builtInSort } from '../../core/internal/sorting';\nimport type { GridElement } from '../../core/plugin/base-plugin';\nimport {\n BaseGridPlugin,\n CellClickEvent,\n HeaderClickEvent,\n type PluginManifest,\n type PluginQuery,\n} from '../../core/plugin/base-plugin';\nimport type { ColumnConfig, ColumnViewRenderer, GridHost, SortHandler } from '../../core/types';\nimport type {\n DataSourceChildrenDetail,\n DataSourceDataDetail,\n FetchChildrenQuery,\n ViewportMappingQuery,\n ViewportMappingResponse,\n} from '../server-side/datasource-types';\nimport { collapseAll, expandAll, expandToKey, toggleExpand } from './tree-data';\nimport { countTopLevelNodes, getTopLevelNodeIndex } from './tree-datasource';\nimport { detectTreeStructure, inferChildrenField } from './tree-detect';\nimport styles from './tree.css?inline';\nimport type { ExpandCollapseAnimation, FlattenedTreeRow, TreeConfig, TreeExpandDetail, TreeRow } from './types';\n\n/**\n * Tree Data Plugin for tbw-grid\n *\n * Transforms your flat grid into a hierarchical tree view with expandable parent-child\n * relationships. Ideal for file explorers, organizational charts, nested categories,\n * or any data with a natural hierarchy.\n *\n * ## Installation\n *\n * ```ts\n * import { TreePlugin } from '@toolbox-web/grid/plugins/tree';\n * ```\n *\n * ## CSS Custom Properties\n *\n * | Property | Default | Description |\n * |----------|---------|-------------|\n * | `--tbw-tree-toggle-size` | `1.25em` | Toggle icon width |\n * | `--tbw-tree-indent-width` | `var(--tbw-tree-toggle-size)` | Indentation per level |\n * | `--tbw-tree-accent` | `var(--tbw-color-accent)` | Toggle icon hover color |\n * | `--tbw-animation-duration` | `200ms` | Expand/collapse animation duration |\n * | `--tbw-animation-easing` | `ease-out` | Animation curve |\n *\n * @example Basic Tree with Nested Children\n * ```ts\n * import { queryGrid } from '@toolbox-web/grid';\n * import { TreePlugin } from '@toolbox-web/grid/plugins/tree';\n *\n * const grid = queryGrid('tbw-grid');\n * grid.gridConfig = {\n * columns: [\n * { field: 'name', header: 'Name' },\n * { field: 'type', header: 'Type' },\n * { field: 'size', header: 'Size' },\n * ],\n * plugins: [new TreePlugin({ childrenField: 'children', indentWidth: 24 })],\n * };\n * grid.rows = [\n * {\n * id: 1,\n * name: 'Documents',\n * type: 'folder',\n * children: [\n * { id: 2, name: 'Report.docx', type: 'file', size: '24 KB' },\n * ],\n * },\n * ];\n * ```\n *\n * @example Expanded by Default with Custom Animation\n * ```ts\n * new TreePlugin({\n * defaultExpanded: true,\n * animation: 'fade', // 'slide' | 'fade' | false\n * indentWidth: 32,\n * })\n * ```\n *\n * @see {@link TreeConfig} for all configuration options\n * @see {@link FlattenedTreeRow} for the flattened row structure\n *\n * @internal Extends BaseGridPlugin\n */\nexport class TreePlugin extends BaseGridPlugin<TreeConfig> {\n static override readonly manifest: PluginManifest = {\n modifiesRowStructure: true,\n hookPriority: {\n processRows: 10, // Run after ServerSide (-10) so we receive managedNodes[]\n },\n incompatibleWith: [\n {\n name: 'groupingRows',\n reason:\n 'Both plugins transform the entire row model. TreePlugin flattens nested hierarchies while ' +\n 'GroupingRowsPlugin groups flat rows with synthetic headers. Use one approach per grid.',\n },\n {\n name: 'pivot',\n reason:\n 'PivotPlugin replaces the entire row and column structure with aggregated pivot data. ' +\n 'Tree hierarchy cannot coexist with pivot aggregation.',\n },\n ],\n events: [\n {\n type: 'tree-expand',\n description:\n 'Emitted when tree expansion state changes (toggle, expand all, collapse all). Broadcast to both DOM consumers and plugin bus.',\n },\n ],\n queries: [\n {\n type: 'canMoveRow',\n description: 'Returns false for rows with children (parent nodes cannot be reordered)',\n },\n {\n type: 'datasource:viewport-mapping',\n description: 'Translates flat viewport row indices to top-level node indices for ServerSide pagination.',\n },\n ],\n };\n\n /**\n * Optional dependency on MultiSort for coordinated sorting.\n * When MultiSort is loaded, Tree defers header click sorting to it and queries the\n * sort model in processRows. When MultiSort is absent, Tree uses its own sort state.\n */\n static override readonly dependencies = [\n { name: 'multiSort', required: false, reason: 'Queries sort model for coordinated tree sorting' },\n { name: 'serverSide', required: false, reason: 'Consumes datasource events for lazy-loaded tree data' },\n ];\n\n /** @internal */\n readonly name = 'tree';\n /** @internal */\n override readonly styles = styles;\n\n /** @internal */\n protected override get defaultConfig(): Partial<TreeConfig> {\n return {\n childrenField: 'children',\n autoDetect: true,\n defaultExpanded: false,\n indentWidth: 20,\n showExpandIcons: true,\n animation: 'slide',\n };\n }\n\n // #region State\n\n private expandedKeys = new Set<string>();\n private initialExpansionDone = false;\n private flattenedRows: FlattenedTreeRow[] = [];\n private rowKeyMap = new Map<string, FlattenedTreeRow>();\n private previousVisibleKeys = new Set<string>();\n private keysToAnimate = new Set<string>();\n private sortState: { field: string; direction: 1 | -1 } | null = null;\n /** Keys of nodes that are currently loading lazy children via ServerSide. */\n private loadingKeys = new Set<string>();\n\n /**\n * Stable key cache keyed by row identity.\n * Persists across sort operations (object identity is preserved by sort);\n * replaces the previous `__stableKey` field-mutation approach so that\n * `_rows[i]` remains the user's original row reference and `updateRow(s)`\n * mutations survive the next `processRows` rebuild.\n *\n * INVARIANT: never mutate row objects to attach tree metadata — keep all\n * tree-specific state in this map and `#rowMeta` (see plugin-author rule\n * in `.github/knowledge/grid-plugins.md`).\n */\n #rowKeys = new WeakMap<object, string>();\n\n /**\n * Per-row tree metadata (depth, hasChildren, isExpanded, key) keyed by\n * row identity. Looked up by the column renderer via {@link getRowMeta}.\n * Reassigned to a fresh `WeakMap` at the start of each `processRows` call so\n * collapsed/hidden rows don't return stale metadata from a prior pass.\n */\n #rowMeta = new WeakMap<object, FlattenedTreeRow>();\n\n /** Cached original (unwrapped) renderer to prevent re-wrapping on repeated processColumns calls. */\n private originalTreeColumnRenderer: ColumnViewRenderer | undefined;\n /** Field name of the column currently wrapped with tree decorations. */\n private wrappedTreeColumnField: string | undefined;\n\n /** @internal */\n override detach(): void {\n this.expandedKeys.clear();\n this.initialExpansionDone = false;\n this.flattenedRows = [];\n this.rowKeyMap.clear();\n this.previousVisibleKeys.clear();\n this.keysToAnimate.clear();\n this.sortState = null;\n this.loadingKeys.clear();\n this.originalTreeColumnRenderer = undefined;\n this.wrappedTreeColumnField = undefined;\n // WeakMaps GC themselves once row references are dropped — nothing to clear.\n }\n\n /**\n * Handle plugin queries.\n * @internal\n */\n override handleQuery(query: PluginQuery): unknown {\n if (query.type === 'canMoveRow') {\n // Tree rows with children cannot be reordered\n const row = query.context as { [key: string]: unknown } | null | undefined;\n const childrenField = this.config.childrenField ?? 'children';\n const children = row?.[childrenField];\n if (Array.isArray(children) && children.length > 0) {\n return false;\n }\n }\n\n if (query.type === 'datasource:viewport-mapping') {\n // Translate visible flat row indices → top-level node indices for ServerSide pagination\n const { viewportStart, viewportEnd } = query.context as ViewportMappingQuery;\n if (this.flattenedRows.length === 0) return undefined;\n\n const startNode = getTopLevelNodeIndex(this.flattenedRows, viewportStart);\n const endNode = getTopLevelNodeIndex(this.flattenedRows, viewportEnd) + 1; // exclusive\n const totalLoadedNodes = countTopLevelNodes(this.flattenedRows);\n\n return { startNode, endNode, totalLoadedNodes } satisfies ViewportMappingResponse;\n }\n\n return undefined;\n }\n\n // #endregion\n\n // #region Lifecycle\n\n /** @internal */\n override attach(grid: GridElement): void {\n super.attach(grid);\n\n // Listen for datasource:data from ServerSidePlugin — claim data for tree processing\n this.on('datasource:data', (detail: unknown) => {\n const d = detail as DataSourceDataDetail;\n if (!d.claimed) {\n d.claimed = true;\n }\n // Data flows through processRows pipeline — Tree receives it via the rows parameter\n // since ServerSide's processRows (hookPriority -10) runs first and returns managedNodes[]\n });\n\n // Listen for datasource:children — consume child rows from ServerSide\n this.on('datasource:children', (detail: unknown) => {\n const d = detail as DataSourceChildrenDetail;\n if (d.context?.source !== 'tree') return;\n d.claimed = true;\n\n // Merge children into the parent node\n const parentRow = d.context.parentNode as TreeRow | undefined;\n if (parentRow) {\n const childrenField = this.config.childrenField ?? 'children';\n (parentRow as Record<string, unknown>)[childrenField] = d.rows;\n // Look up the stable key by row identity (was stored on row as __stableKey\n // historically; now lives in a parallel WeakMap to keep row identity intact).\n const key = this.#rowKeys.get(parentRow as object) ?? String(parentRow.id ?? '?');\n this.loadingKeys.delete(key);\n this.requestRender();\n }\n });\n }\n\n // #endregion\n\n // #region Animation\n\n /**\n * Get expand/collapse animation style from plugin config.\n * Uses base class isAnimationEnabled to respect grid-level settings.\n */\n private get animationStyle(): ExpandCollapseAnimation {\n if (!this.isAnimationEnabled) return false;\n return this.config.animation ?? 'slide';\n }\n\n // #endregion\n\n // #region Auto-Detection\n\n detect(rows: readonly unknown[]): boolean {\n if (!this.config.autoDetect) return false;\n const treeRows = rows as readonly TreeRow[];\n const field = this.config.childrenField ?? inferChildrenField(treeRows) ?? 'children';\n return detectTreeStructure(treeRows, field);\n }\n\n // #endregion\n\n // #region Data Processing\n\n /** @internal */\n override processRows(rows: readonly unknown[]): TreeRow[] {\n const childrenField = this.config.childrenField ?? 'children';\n\n const treeRows = rows as readonly TreeRow[];\n\n if (treeRows.length === 0 || !detectTreeStructure(treeRows, childrenField)) {\n this.flattenedRows = [];\n this.rowKeyMap.clear();\n this.previousVisibleKeys.clear();\n // _rows[i] must remain the user's row reference. Return a shallow array\n // copy (so callers can't mutate the input array via the returned ref)\n // but DO NOT spread/clone the row objects themselves.\n return [...rows] as TreeRow[];\n }\n\n // Initialize expansion if needed.\n // When MultiSort is active, use its model instead of local sort state so\n // Tree and MultiSort don't fight over sort ownership.\n const effectiveSortState = this.resolveEffectiveSortState();\n\n if (this.config.defaultExpanded && !this.initialExpansionDone) {\n this.expandedKeys = expandAll(treeRows, this.config);\n this.initialExpansionDone = true;\n }\n\n // Single pass: sort + flatten in one walk, never cloning row objects.\n // `data` on each FlattenedTreeRow stays === the user's source row.\n this.flattenedRows = this.#flattenWithSort(treeRows, this.expandedKeys, effectiveSortState, null, 0);\n\n // Reset per-row metadata so rows that are no longer in the flattened\n // output (e.g. children of a now-collapsed parent) don't keep returning\n // stale entries via getRowMeta(). WeakMap reassignment is cheap and the\n // old map becomes GC-eligible immediately.\n this.#rowMeta = new WeakMap();\n this.rowKeyMap.clear();\n this.keysToAnimate.clear();\n const currentKeys = new Set<string>();\n\n for (const row of this.flattenedRows) {\n this.rowKeyMap.set(row.key, row);\n this.#rowMeta.set(row.data as object, row);\n currentKeys.add(row.key);\n if (!this.previousVisibleKeys.has(row.key) && row.depth > 0) {\n this.keysToAnimate.add(row.key);\n }\n }\n this.previousVisibleKeys = currentKeys;\n\n // Return source row references directly. Tree metadata (depth/key/etc.)\n // is read by the renderer via `getRowMeta(row)` instead of being spread\n // onto cloned row objects \\u2014 this keeps `_rows[i]` === user's row so that\n // `grid.updateRow(s)` mutations survive the next ROWS-phase rebuild.\n return this.flattenedRows.map((r) => r.data);\n }\n\n /**\n * Resolve the stable key for a row, caching by identity in {@link #rowKeys}.\n * Prefers `row.id` (already stable across sort), then any previously cached\n * key for this row reference, then falls back to a path-based key.\n */\n #keyFor(row: TreeRow, index: number, parentKey: string | null): string {\n if (row.id !== undefined) {\n const key = String(row.id);\n this.#rowKeys.set(row as object, key);\n return key;\n }\n const cached = this.#rowKeys.get(row as object);\n if (cached !== undefined) return cached;\n const key = parentKey ? `${parentKey}-${index}` : String(index);\n this.#rowKeys.set(row as object, key);\n return key;\n }\n\n /**\n * Recursive single-pass sort + flatten.\n * - Per-level sort uses `[...rows].sort(...)` which produces a new array of\n * the SAME row references in a new order \\u2014 never spreads the row objects.\n * - Children arrays are NOT mutated on the source rows; the sort produces a\n * transient ordering used only for traversal.\n */\n #flattenWithSort(\n rows: readonly TreeRow[],\n expanded: Set<string>,\n sort: { field: string; direction: 1 | -1 } | null,\n parentKey: string | null,\n depth: number,\n ): FlattenedTreeRow[] {\n const childrenField = this.config.childrenField ?? 'children';\n // Assign stable keys using the ORIGINAL (unsorted) index so that\n // path-based keys match those produced by `expandAll` (which walks the\n // tree in source order). `#keyFor` caches by row identity, so the\n // subsequent lookup in the post-sort loop returns the same key.\n for (let i = 0; i < rows.length; i++) {\n this.#keyFor(rows[i], i, parentKey);\n }\n const ordered = sort ? this.#sortLevel(rows, sort.field, sort.direction) : rows;\n const result: FlattenedTreeRow[] = [];\n\n for (let i = 0; i < ordered.length; i++) {\n const row = ordered[i];\n const key = this.#keyFor(row, i, parentKey);\n const children = row[childrenField];\n const embeddedChildren = Array.isArray(children) && children.length > 0;\n // Lazy children: truthy non-array value (e.g. `children: true`) signals\n // that children exist on the server but haven't been fetched yet.\n const lazyChildren = children != null && !Array.isArray(children) && !!children;\n const hasChildren = embeddedChildren || lazyChildren;\n const isExpanded = expanded.has(key);\n\n result.push({\n key,\n data: row,\n depth,\n hasChildren,\n isExpanded,\n parentKey,\n });\n\n if (embeddedChildren && isExpanded) {\n result.push(...this.#flattenWithSort(children as TreeRow[], expanded, sort, key, depth + 1));\n }\n }\n return result;\n }\n\n /**\n * Sort rows at a single level, returning a new array of the SAME row references\n * in sorted order. Never clones row objects, and never mutates the input array\n * (children arrays are user-owned for tree rows — we always pass a shallow copy\n * to the handler so a custom in-place sortHandler can't corrupt user data).\n *\n * Delegates to the same handler chain core uses: `gridConfig.sortHandler` when\n * provided, otherwise `builtInSort` (which honors per-column `sortComparator`\n * and `valueAccessor`). Async handlers cannot be awaited inside the synchronous\n * tree flatten — fall back to `builtInSort` when one is detected, and swallow\n * any rejection so it doesn't surface as an unhandled promise rejection.\n */\n #sortLevel(rows: readonly TreeRow[], field: string, dir: 1 | -1): TreeRow[] {\n const host = this.grid as unknown as GridHost<TreeRow> | undefined;\n const columns = (host?._columns ?? []) as ColumnConfig<TreeRow>[];\n const handler: SortHandler<TreeRow> = host?.effectiveConfig?.sortHandler ?? builtInSort;\n const sortState = { field, direction: dir };\n // Always pass a shallow copy: `rows` may be a user-owned `row.children`\n // array, and a non-defensive sortHandler could otherwise mutate it.\n const input = [...rows] as TreeRow[];\n const result = handler(input, sortState, columns);\n if (result && typeof (result as Promise<unknown[]>).then === 'function') {\n void (result as Promise<unknown[]>).catch(() => undefined);\n return builtInSort(input, sortState, columns);\n }\n return result as TreeRow[];\n }\n\n /**\n * Request lazy children for a node via ServerSide's `datasource:fetch-children` query.\n * Called when expanding a node whose children are not yet embedded (lazy indicator only).\n * No-op if ServerSide is not active, children are already loading, or children are embedded.\n */\n private requestLazyChildren(flatRow: FlattenedTreeRow): void {\n if (this.loadingKeys.has(flatRow.key)) return;\n\n const childrenField = this.config.childrenField ?? 'children';\n const children = flatRow.data[childrenField];\n // Only fetch if children is a lazy indicator (truthy but not a non-empty array)\n if (Array.isArray(children) && children.length > 0) return;\n\n const isServerSideActive = this.grid?.query?.('datasource:is-active', null);\n if (!isServerSideActive) return;\n\n this.loadingKeys.add(flatRow.key);\n this.grid.query('datasource:fetch-children', {\n context: { source: 'tree', parentNode: flatRow.data, nodePath: [flatRow.key] },\n } satisfies FetchChildrenQuery);\n }\n\n /**\n * Resolve the effective sort state: prefer MultiSort's model when available,\n * fall back to local tree sort state.\n * This follows the same pattern as GroupingRowsPlugin.resolveGroupSortDirections.\n */\n private resolveEffectiveSortState(): { field: string; direction: 1 | -1 } | null {\n // When MultiSort is loaded, prefer its model for consistency\n const multiSortResults = this.grid?.query?.('sort:get-model', null);\n if (Array.isArray(multiSortResults) && multiSortResults.length > 0) {\n const sortModel = multiSortResults[0] as Array<{ field: string; direction: 'asc' | 'desc' }>;\n if (Array.isArray(sortModel) && sortModel.length > 0) {\n // Use the primary sort column from MultiSort\n return {\n field: sortModel[0].field,\n direction: sortModel[0].direction === 'desc' ? -1 : 1,\n };\n }\n }\n // Fallback: local sort state (when MultiSort is not loaded)\n return this.sortState;\n }\n\n /** @internal */\n override processColumns(columns: readonly ColumnConfig[]): ColumnConfig[] {\n if (this.flattenedRows.length === 0) return [...columns];\n\n const cols = [...columns] as ColumnConfig[];\n if (cols.length === 0) return cols;\n\n // Determine which column gets the tree toggle and indentation.\n // If treeColumn is configured, find it by field name; otherwise use the first column.\n const { treeColumn } = this.config;\n let targetIndex = 0;\n if (treeColumn) {\n const idx = cols.findIndex((c) => c.field === treeColumn);\n if (idx >= 0) targetIndex = idx;\n }\n const targetCol = cols[targetIndex];\n const targetField = targetCol.field;\n\n // Capture the original (unwrapped) renderer only once per target column.\n // On subsequent processColumns calls, reuse the cached original so we\n // don't nest tree-cell-wrappers.\n if (this.wrappedTreeColumnField !== targetField) {\n this.originalTreeColumnRenderer = targetCol.viewRenderer;\n this.wrappedTreeColumnField = targetField;\n }\n const originalRenderer = this.originalTreeColumnRenderer;\n const getConfig = () => this.config;\n const setIconFn = this.setIcon.bind(this);\n\n const wrappedRenderer: ColumnViewRenderer = (ctx) => {\n const { row, value } = ctx;\n const { showExpandIcons = true, indentWidth } = getConfig();\n const meta = this.#rowMeta.get(row as object);\n const depth = meta?.depth ?? 0;\n\n const container = document.createElement('span');\n container.className = 'tree-cell-wrapper';\n container.style.setProperty('--tbw-tree-depth', String(depth));\n // Allow config-based indentWidth to override CSS default\n if (indentWidth !== undefined) {\n container.style.setProperty('--tbw-tree-indent-width', `${indentWidth}px`);\n }\n\n // Add expand/collapse icon or spacer\n if (showExpandIcons) {\n if (meta && meta.hasChildren) {\n const icon = document.createElement('span');\n icon.className = `${GridClasses.TREE_TOGGLE}${meta.isExpanded ? ` ${GridClasses.EXPANDED}` : ''}`;\n setIconFn(icon, meta.isExpanded ? 'collapse' : 'expand');\n icon.setAttribute('data-tree-key', meta.key);\n container.appendChild(icon);\n } else {\n const spacer = document.createElement('span');\n spacer.className = 'tree-spacer';\n container.appendChild(spacer);\n }\n }\n\n // Add the original content\n const content = document.createElement('span');\n content.className = 'tree-content';\n if (originalRenderer) {\n const result = originalRenderer(ctx);\n if (result instanceof Node) {\n content.appendChild(result);\n } else if (typeof result === 'string') {\n content.innerHTML = result;\n }\n } else {\n content.textContent = value != null ? String(value) : '';\n }\n container.appendChild(content);\n\n return container;\n };\n\n cols[targetIndex] = { ...targetCol, viewRenderer: wrappedRenderer };\n return cols;\n }\n\n // #endregion\n\n // #region Event Handlers\n\n /** @internal */\n override onCellClick(event: CellClickEvent): boolean {\n const target = event.originalEvent?.target as HTMLElement;\n if (!target?.classList.contains(GridClasses.TREE_TOGGLE)) return false;\n\n const key = target.getAttribute('data-tree-key');\n if (!key) return false;\n\n const flatRow = this.rowKeyMap.get(key);\n if (!flatRow) return false;\n\n this.expandedKeys = toggleExpand(this.expandedKeys, key);\n\n // Request lazy children when expanding a node without embedded children\n if (this.expandedKeys.has(key)) {\n this.requestLazyChildren(flatRow);\n }\n\n this.broadcast<TreeExpandDetail>('tree-expand', {\n key,\n row: flatRow.data,\n expanded: this.expandedKeys.has(key),\n depth: flatRow.depth,\n expandedKeys: [...this.expandedKeys],\n });\n this.requestRender();\n return true;\n }\n\n /** @internal */\n override onKeyDown(event: KeyboardEvent): boolean | void {\n // SPACE toggles expansion when on a row with children\n if (event.key !== ' ') return;\n\n const focusRow = this.grid._focusRow;\n const flatRow = this.flattenedRows[focusRow];\n if (!flatRow?.hasChildren) return;\n\n event.preventDefault();\n this.expandedKeys = toggleExpand(this.expandedKeys, flatRow.key);\n\n // Request lazy children when expanding a node without embedded children\n if (this.expandedKeys.has(flatRow.key)) {\n this.requestLazyChildren(flatRow);\n }\n\n this.broadcast<TreeExpandDetail>('tree-expand', {\n key: flatRow.key,\n row: flatRow.data,\n expanded: this.expandedKeys.has(flatRow.key),\n depth: flatRow.depth,\n expandedKeys: [...this.expandedKeys],\n });\n this.requestRenderWithFocus();\n return true;\n }\n\n /** @internal */\n override onHeaderClick(event: HeaderClickEvent): boolean {\n if (this.flattenedRows.length === 0 || !event.column.sortable) return false;\n\n // When MultiSort is active, let it handle header clicks entirely.\n // Tree will pick up the sort model in processRows via resolveEffectiveSortState().\n const multiSortResults = this.grid?.query?.('sort:get-model', null);\n if (Array.isArray(multiSortResults) && multiSortResults.length > 0) {\n // MultiSort is loaded — don't consume the event, let MultiSort handle it\n return false;\n }\n\n // Fallback: manage own sort state when MultiSort is not loaded\n const { field } = event.column;\n if (!this.sortState || this.sortState.field !== field) {\n this.sortState = { field, direction: 1 };\n } else if (this.sortState.direction === 1) {\n this.sortState = { field, direction: -1 };\n } else {\n this.sortState = null;\n }\n\n // Sync grid sort indicator\n const gridEl = this.grid as unknown as GridHost;\n if (gridEl._sortState !== undefined) {\n gridEl._sortState = this.sortState ? { ...this.sortState } : null;\n }\n\n this.broadcast('sort-change', { field, direction: this.sortState?.direction ?? 0 });\n this.requestRender();\n return true;\n }\n\n /** @internal */\n override afterRender(): void {\n const body = this.gridElement?.querySelector('.rows');\n if (!body) return;\n\n const style = this.animationStyle;\n const shouldAnimate = style !== false && this.keysToAnimate.size > 0;\n const animClass = style === 'fade' ? 'tbw-tree-fade-in' : 'tbw-tree-slide-in';\n\n for (const rowEl of body.querySelectorAll('.data-grid-row')) {\n const cell = rowEl.querySelector('.cell[data-row]');\n const idx = cell ? parseInt(cell.getAttribute('data-row') ?? '-1', 10) : -1;\n const treeRow = this.flattenedRows[idx];\n\n // Set aria-expanded on parent rows for screen readers\n if (treeRow?.hasChildren) {\n rowEl.setAttribute('aria-expanded', String(treeRow.isExpanded));\n }\n\n if (shouldAnimate && treeRow?.key && this.keysToAnimate.has(treeRow.key)) {\n rowEl.classList.add(animClass);\n rowEl.addEventListener('animationend', () => rowEl.classList.remove(animClass), { once: true });\n }\n }\n this.keysToAnimate.clear();\n }\n\n // #endregion\n\n // #region Public API\n\n /**\n * Expand a specific tree node, revealing its children.\n *\n * If the node is already expanded, this is a no-op.\n * Does **not** emit a `tree-expand` event (use {@link toggle} for event emission).\n *\n * @param key - The unique key of the node to expand (from {@link FlattenedTreeRow.key})\n *\n * @example\n * ```ts\n * const tree = grid.getPluginByName('tree');\n * tree.expand('documents'); // Expand a root node\n * tree.expand('documents||reports'); // Expand a nested node\n * ```\n */\n expand(key: string): void {\n this.expandedKeys.add(key);\n const flatRow = this.rowKeyMap.get(key);\n if (flatRow) {\n this.requestLazyChildren(flatRow);\n }\n this.requestRender();\n }\n\n /**\n * Collapse a specific tree node, hiding its children.\n *\n * If the node is already collapsed, this is a no-op.\n * Does **not** emit a `tree-expand` event (use {@link toggle} for event emission).\n *\n * @param key - The unique key of the node to collapse (from {@link FlattenedTreeRow.key})\n *\n * @example\n * ```ts\n * const tree = grid.getPluginByName('tree');\n * tree.collapse('documents');\n * ```\n */\n collapse(key: string): void {\n this.expandedKeys.delete(key);\n this.requestRender();\n }\n\n /**\n * Toggle the expanded state of a tree node.\n *\n * If the node is expanded it will be collapsed, and vice versa.\n * Emits a `tree-expand` event (broadcast to both DOM consumers and plugin bus).\n *\n * @param key - The unique key of the node to toggle (from {@link FlattenedTreeRow.key})\n *\n * @example\n * ```ts\n * const tree = grid.getPluginByName('tree');\n * tree.toggle('documents'); // Expand if collapsed, collapse if expanded\n * ```\n */\n toggle(key: string): void {\n this.expandedKeys = toggleExpand(this.expandedKeys, key);\n const flatRow = this.rowKeyMap.get(key);\n if (flatRow) {\n // Request lazy children when expanding a node without embedded children\n if (this.expandedKeys.has(key)) {\n this.requestLazyChildren(flatRow);\n }\n this.broadcast<TreeExpandDetail>('tree-expand', {\n key,\n row: flatRow.data,\n expanded: this.expandedKeys.has(key),\n depth: flatRow.depth,\n expandedKeys: [...this.expandedKeys],\n });\n } else {\n this.emitPluginEvent('tree-expand', { expandedKeys: [...this.expandedKeys] });\n }\n this.requestRender();\n }\n\n /**\n * Expand all tree nodes recursively.\n *\n * Every node with children will be expanded, revealing the full tree hierarchy.\n * Emits a `tree-expand` plugin event.\n *\n * @example\n * ```ts\n * const tree = grid.getPluginByName('tree');\n * tree.expandAll();\n * ```\n */\n expandAll(): void {\n this.expandedKeys = expandAll(this.rows as TreeRow[], this.config);\n this.emitPluginEvent('tree-expand', { expandedKeys: [...this.expandedKeys] });\n this.requestRender();\n }\n\n /**\n * Collapse all tree nodes.\n *\n * Every node will be collapsed, showing only root-level rows.\n * Emits a `tree-expand` plugin event.\n *\n * @example\n * ```ts\n * const tree = grid.getPluginByName('tree');\n * tree.collapseAll();\n * ```\n */\n collapseAll(): void {\n this.expandedKeys = collapseAll();\n this.emitPluginEvent('tree-expand', { expandedKeys: [...this.expandedKeys] });\n this.requestRender();\n }\n\n /**\n * Check whether a specific tree node is currently expanded.\n *\n * @param key - The unique key of the node to check\n * @returns `true` if the node is expanded, `false` otherwise\n */\n isExpanded(key: string): boolean {\n return this.expandedKeys.has(key);\n }\n\n /**\n * Get the keys of all currently expanded nodes.\n *\n * Returns a snapshot copy — mutating the returned array does not affect the tree state.\n *\n * @returns Array of expanded node keys\n *\n * @example\n * ```ts\n * const tree = grid.getPluginByName('tree');\n * const keys = tree.getExpandedKeys();\n * localStorage.setItem('treeState', JSON.stringify(keys));\n * ```\n */\n getExpandedKeys(): string[] {\n return [...this.expandedKeys];\n }\n\n /**\n * Get the flattened row model used for rendering.\n *\n * Returns a snapshot copy of the internal flattened tree rows, including\n * hierarchy metadata (depth, hasChildren, isExpanded, parentKey).\n *\n * @returns Array of {@link FlattenedTreeRow} objects\n */\n getFlattenedRows(): FlattenedTreeRow[] {\n return [...this.flattenedRows];\n }\n\n /**\n * Get tree metadata (depth, key, hasChildren, isExpanded, parentKey) for a\n * specific row reference. Returns `undefined` if the row is not part of the\n * currently-flattened tree (e.g. collapsed under a parent or never processed).\n *\n * Tree metadata lives in a parallel WeakMap keyed by row identity \\u2014 it is\n * NOT stored on the row object itself. This preserves the invariant that\n * `_rows[i]` IS the user's source row reference, so `grid.updateRow(s)`\n * mutations survive the next ROWS-phase rebuild.\n *\n * @example\n * ```ts\n * const tree = grid.getPluginByName('tree');\n * const meta = tree.getRowMeta(grid.rows[0]);\n * console.log(meta?.depth, meta?.hasChildren);\n * ```\n */\n getRowMeta(row: TreeRow): FlattenedTreeRow | undefined {\n return this.#rowMeta.get(row as object);\n }\n\n /**\n * Look up an original row data object by its tree key.\n *\n * @param key - The unique key of the node\n * @returns The original row data, or `undefined` if not found\n */\n getRowByKey(key: string): TreeRow | undefined {\n return this.rowKeyMap.get(key)?.data;\n }\n\n /**\n * Expand all ancestor nodes of the target key, revealing it in the tree.\n *\n * Useful for \"scroll to node\" or search-and-reveal scenarios where a deeply\n * nested node needs to be made visible.\n *\n * @param key - The unique key of the node to reveal\n *\n * @example\n * ```ts\n * const tree = grid.getPluginByName('tree');\n * // Reveal a deeply nested node by expanding all its parents\n * tree.expandToKey('root||child||grandchild');\n * ```\n */\n expandToKey(key: string): void {\n this.expandedKeys = expandToKey(this.rows as TreeRow[], key, this.config, this.expandedKeys);\n this.requestRender();\n }\n\n // #endregion\n}\n"],"names":["generateRowKey","row","index","parentKey","id","String","toggleExpand","expandedKeys","key","newExpanded","Set","has","delete","add","expandAll","rows","config","depth","childrenField","keys","i","length","children","Array","isArray","childKeys","k","getPathToKey","targetKey","childPath","expandToKey","existingExpanded","path","getTopLevelNodeIndex","flattenedRows","flatRowIndex","idx","Math","min","current","topLevelIndex","detectTreeStructure","TreePlugin","BaseGridPlugin","static","modifiesRowStructure","hookPriority","processRows","incompatibleWith","name","reason","events","type","description","queries","required","styles","defaultConfig","autoDetect","defaultExpanded","indentWidth","showExpandIcons","animation","initialExpansionDone","rowKeyMap","Map","previousVisibleKeys","keysToAnimate","sortState","loadingKeys","rowKeys","WeakMap","rowMeta","originalTreeColumnRenderer","wrappedTreeColumnField","detach","this","clear","handleQuery","query","context","viewportStart","viewportEnd","startNode","endNode","totalLoadedNodes","count","countTopLevelNodes","attach","grid","super","on","detail","d","claimed","source","parentRow","parentNode","get","requestRender","animationStyle","isAnimationEnabled","detect","treeRows","field","commonArrayFields","value","inferChildrenField","effectiveSortState","resolveEffectiveSortState","flattenWithSort","currentKeys","set","data","map","r","keyFor","cached","expanded","sort","ordered","sortLevel","direction","result","embeddedChildren","lazyChildren","hasChildren","isExpanded","push","dir","host","columns","_columns","input","effectiveConfig","sortHandler","builtInSort","then","catch","requestLazyChildren","flatRow","isServerSideActive","nodePath","multiSortResults","sortModel","processColumns","cols","treeColumn","targetIndex","findIndex","c","targetCol","targetField","viewRenderer","originalRenderer","getConfig","setIconFn","setIcon","bind","ctx","meta","container","document","createElement","className","style","setProperty","icon","GridClasses","TREE_TOGGLE","EXPANDED","setAttribute","appendChild","spacer","content","Node","innerHTML","textContent","onCellClick","event","target","originalEvent","classList","contains","getAttribute","broadcast","onKeyDown","focusRow","_focusRow","preventDefault","requestRenderWithFocus","onHeaderClick","column","sortable","gridEl","_sortState","afterRender","body","gridElement","querySelector","shouldAnimate","size","animClass","rowEl","querySelectorAll","cell","parseInt","treeRow","addEventListener","remove","once","expand","collapse","toggle","emitPluginEvent","collapseAll","getExpandedKeys","getFlattenedRows","getRowMeta","getRowByKey"],"mappings":"keAYO,SAASA,EAAeC,EAAcC,EAAeC,GAC1D,YAAe,IAAXF,EAAIG,GAAyBC,OAAOJ,EAAIG,IACrCD,EAAY,GAAGA,KAAaD,IAAUG,OAAOH,EACtD,CA8CO,SAASI,EAAaC,EAA2BC,GACtD,MAAMC,EAAc,IAAIC,IAAIH,GAM5B,OALIE,EAAYE,IAAIH,GAClBC,EAAYG,OAAOJ,GAEnBC,EAAYI,IAAIL,GAEXC,CACT,CAMO,SAASK,EACdC,EACAC,EACAb,EAA2B,KAC3Bc,EAAQ,GAER,MAAMC,EAAgBF,EAAOE,eAAiB,WACxCC,MAAWT,IAEjB,IAAA,IAASU,EAAI,EAAG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E,KAAKuB,eACP,CAcA,SAAArF,GACE8D,KAAKrE,aAAeO,EAAU8D,KAAK7D,KAAmB6D,KAAK5D,QAC3D4D,KAAK0I,gBAAgB,cAAe,CAAE/M,aAAc,IAAIqE,KAAKrE,gBAC7DqE,KAAKuB,eACP,CAcA,WAAAoH,GACE3I,KAAKrE,iBH5sBIG,IG6sBTkE,KAAK0I,gBAAgB,cAAe,CAAE/M,aAAc,IAAIqE,KAAKrE,gBAC7DqE,KAAKuB,eACP,CAQA,UAAA4B,CAAWvH,GACT,OAAOoE,KAAKrE,aAAaI,IAAIH,EAC/B,CAgBA,eAAAgN,GACE,MAAO,IAAI5I,KAAKrE,aAClB,CAUA,gBAAAkN,GACE,MAAO,IAAI7I,KAAK1C,cAClB,CAmBA,UAAAwL,CAAWzN,GACT,OAAO2E,MAAKJ,EAAS0B,IAAIjG,EAC3B,CAQA,WAAA0N,CAAYnN,GACV,OAAOoE,KAAKZ,UAAUkC,IAAI1F,IAAMyG,IAClC,CAiBA,WAAAnF,CAAYtB,GACVoE,KAAKrE,aAAeuB,EAAY8C,KAAK7D,KAAmBP,EAAKoE,KAAK5D,OAAQ4D,KAAKrE,cAC/EqE,KAAKuB,eACP"}
1
+ {"version":3,"file":"tree.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/tree/tree-data.ts","../../../../../libs/grid/src/lib/plugins/tree/tree-datasource.ts","../../../../../libs/grid/src/lib/plugins/tree/tree-detect.ts","../../../../../libs/grid/src/lib/plugins/tree/TreePlugin.ts"],"sourcesContent":["/**\n * Core Tree Data Logic\n *\n * Pure functions for tree flattening, expansion, and traversal.\n */\n\nimport type { FlattenedTreeRow, TreeConfig, TreeRow } from './types';\n\n/**\n * Generates a unique key for a row.\n * Uses row.id if available, otherwise generates from path.\n */\nexport function generateRowKey(row: TreeRow, index: number, parentKey: string | null): string {\n if (row.id !== undefined) return String(row.id);\n return parentKey ? `${parentKey}-${index}` : String(index);\n}\n\n/**\n * Flattens a hierarchical tree into a flat array of rows with metadata.\n * Only includes children of expanded nodes.\n */\nexport function flattenTree(\n rows: readonly TreeRow[],\n config: TreeConfig,\n expandedKeys: Set<string>,\n parentKey: string | null = null,\n depth = 0,\n): FlattenedTreeRow[] {\n const childrenField = config.childrenField ?? 'children';\n const result: FlattenedTreeRow[] = [];\n\n for (let i = 0; i < rows.length; i++) {\n const row = rows[i];\n const key = generateRowKey(row, i, parentKey);\n const children = row[childrenField];\n const hasChildren = Array.isArray(children) && children.length > 0;\n const isExpanded = expandedKeys.has(key);\n\n result.push({\n key,\n data: row,\n depth,\n hasChildren,\n isExpanded,\n parentKey,\n posInSet: i + 1,\n setSize: rows.length,\n });\n\n // Recursively add children if expanded\n if (hasChildren && isExpanded) {\n const childRows = flattenTree(children as TreeRow[], config, expandedKeys, key, depth + 1);\n result.push(...childRows);\n }\n }\n\n return result;\n}\n\n/**\n * Toggles the expansion state of a row.\n * Returns a new Set with the toggled state.\n */\nexport function toggleExpand(expandedKeys: Set<string>, key: string): Set<string> {\n const newExpanded = new Set(expandedKeys);\n if (newExpanded.has(key)) {\n newExpanded.delete(key);\n } else {\n newExpanded.add(key);\n }\n return newExpanded;\n}\n\n/**\n * Expands all nodes in the tree.\n * Returns a Set of all parent row keys.\n */\nexport function expandAll(\n rows: readonly TreeRow[],\n config: TreeConfig,\n parentKey: string | null = null,\n depth = 0,\n): Set<string> {\n const childrenField = config.childrenField ?? 'children';\n const keys = new Set<string>();\n\n for (let i = 0; i < rows.length; i++) {\n const row = rows[i];\n const key = generateRowKey(row, i, parentKey);\n const children = row[childrenField];\n\n if (Array.isArray(children) && children.length > 0) {\n keys.add(key);\n const childKeys = expandAll(children as TreeRow[], config, key, depth + 1);\n for (const k of childKeys) keys.add(k);\n }\n }\n\n return keys;\n}\n\n/**\n * Collapses all nodes.\n * Returns an empty Set.\n */\nexport function collapseAll(): Set<string> {\n return new Set();\n}\n\n/**\n * Gets all descendants of a node from the flattened row list.\n * Useful for operations that need to affect an entire subtree.\n */\nexport function getDescendants(flattenedRows: FlattenedTreeRow[], parentKey: string): FlattenedTreeRow[] {\n const descendants: FlattenedTreeRow[] = [];\n let collecting = false;\n let parentDepth = -1;\n\n for (const row of flattenedRows) {\n if (row.key === parentKey) {\n collecting = true;\n parentDepth = row.depth;\n continue;\n }\n\n if (collecting) {\n if (row.depth > parentDepth) {\n descendants.push(row);\n } else {\n break; // No longer a descendant\n }\n }\n }\n\n return descendants;\n}\n\n/**\n * Finds the path from root to a specific row key.\n * Returns an array of keys from root to the target (inclusive).\n */\nexport function getPathToKey(\n rows: readonly TreeRow[],\n targetKey: string,\n config: TreeConfig,\n parentKey: string | null = null,\n depth = 0,\n): string[] | null {\n const childrenField = config.childrenField ?? 'children';\n\n for (let i = 0; i < rows.length; i++) {\n const row = rows[i];\n const key = generateRowKey(row, i, parentKey);\n\n if (key === targetKey) {\n return [key];\n }\n\n const children = row[childrenField];\n if (Array.isArray(children) && children.length > 0) {\n const childPath = getPathToKey(children as TreeRow[], targetKey, config, key, depth + 1);\n if (childPath) {\n return [key, ...childPath];\n }\n }\n }\n\n return null;\n}\n\n/**\n * Expands all ancestors of a specific row to make it visible.\n * Returns a new Set with the required keys added.\n */\nexport function expandToKey(\n rows: readonly TreeRow[],\n targetKey: string,\n config: TreeConfig,\n existingExpanded: Set<string>,\n): Set<string> {\n const path = getPathToKey(rows, targetKey, config);\n if (!path) return existingExpanded;\n\n const newExpanded = new Set(existingExpanded);\n // Add all keys except the last one (the target itself)\n for (let i = 0; i < path.length - 1; i++) {\n newExpanded.add(path[i]);\n }\n return newExpanded;\n}\n","/**\n * Tree Viewport Mapping Utilities\n *\n * Pure functions for translating between flat viewport row indices and\n * top-level tree node indices. Used by the Tree plugin's\n * `datasource:viewport-mapping` query handler.\n */\n\nimport type { FlattenedTreeRow } from './types';\n\n/**\n * Given a flat row index in the viewport, find the index of the\n * top-level node (depth 0) that \"owns\" that row.\n *\n * Walk backwards from the row index until a depth-0 row is found,\n * then return its position among all depth-0 rows.\n */\nexport function getTopLevelNodeIndex(flattenedRows: FlattenedTreeRow[], flatRowIndex: number): number {\n // Clamp to valid range\n const idx = Math.min(flatRowIndex, flattenedRows.length - 1);\n if (idx < 0) return 0;\n\n // Walk backwards to find the owning top-level node\n let current = idx;\n while (current > 0 && flattenedRows[current].depth > 0) {\n current--;\n }\n\n // Count how many depth-0 nodes precede this one (inclusive)\n let topLevelIndex = 0;\n for (let i = 0; i <= current; i++) {\n if (flattenedRows[i].depth === 0) {\n topLevelIndex++;\n }\n }\n // Convert to 0-based\n return topLevelIndex - 1;\n}\n\n/**\n * Count the number of top-level (depth 0) nodes in the flattened rows.\n */\nexport function countTopLevelNodes(flattenedRows: FlattenedTreeRow[]): number {\n let count = 0;\n for (const row of flattenedRows) {\n if (row.depth === 0) count++;\n }\n return count;\n}\n","/**\n * Tree Structure Auto-Detection\n *\n * Utilities for detecting hierarchical tree data structures.\n */\n\nimport type { TreeRow } from './types';\n\n/**\n * Detects if the data has a tree structure by checking for children arrays.\n */\nexport function detectTreeStructure(rows: readonly TreeRow[], childrenField = 'children'): boolean {\n if (!Array.isArray(rows) || rows.length === 0) return false;\n\n // Check if any row has children (embedded array or lazy indicator)\n for (const row of rows) {\n if (!row) continue;\n const children = row[childrenField];\n // Embedded children: non-empty array\n if (Array.isArray(children) && children.length > 0) return true;\n // Lazy children: truthy non-array value (e.g. `true`, number > 0)\n if (children != null && !Array.isArray(children) && !!children) return true;\n }\n\n return false;\n}\n\n/**\n * Attempts to infer the children field name from common patterns.\n * Returns the first field that contains an array with items.\n */\nexport function inferChildrenField(rows: readonly TreeRow[]): string | null {\n if (!Array.isArray(rows) || rows.length === 0) return null;\n\n const commonArrayFields = ['children', 'items', 'nodes', 'subRows', 'nested'];\n\n for (const row of rows) {\n if (!row || typeof row !== 'object') continue;\n\n for (const field of commonArrayFields) {\n const value = row[field];\n if (Array.isArray(value) && value.length > 0) {\n return field;\n }\n }\n }\n\n return null;\n}\n\n/**\n * Calculates the maximum depth of the tree.\n * Useful for layout calculations and virtualization.\n */\nexport function getMaxDepth(rows: readonly TreeRow[], childrenField = 'children', currentDepth = 0): number {\n if (!Array.isArray(rows) || rows.length === 0) return currentDepth;\n\n let maxDepth = currentDepth;\n\n for (const row of rows) {\n if (!row) continue;\n const children = row[childrenField];\n if (Array.isArray(children) && children.length > 0) {\n const childDepth = getMaxDepth(children as TreeRow[], childrenField, currentDepth + 1);\n if (childDepth > maxDepth) {\n maxDepth = childDepth;\n }\n }\n }\n\n return maxDepth;\n}\n\n/**\n * Counts total nodes in the tree (including all descendants).\n */\nexport function countNodes(rows: readonly TreeRow[], childrenField = 'children'): number {\n if (!Array.isArray(rows)) return 0;\n\n let count = 0;\n for (const row of rows) {\n if (!row) continue;\n count++;\n const children = row[childrenField];\n if (Array.isArray(children)) {\n count += countNodes(children as TreeRow[], childrenField);\n }\n }\n\n return count;\n}\n","/**\n * Tree Data Plugin\n *\n * Enables hierarchical tree data with expand/collapse, sorting, and auto-detection.\n */\n\nimport { GridClasses } from '../../core/constants';\nimport { builtInSort } from '../../core/internal/sorting';\nimport type { GridElement } from '../../core/plugin/base-plugin';\nimport {\n BaseGridPlugin,\n CellClickEvent,\n HeaderClickEvent,\n type PluginManifest,\n type PluginQuery,\n} from '../../core/plugin/base-plugin';\nimport type { ColumnConfig, ColumnViewRenderer, GridHost, SortHandler } from '../../core/types';\nimport type {\n DataSourceChildrenDetail,\n DataSourceDataDetail,\n FetchChildrenQuery,\n ViewportMappingQuery,\n ViewportMappingResponse,\n} from '../server-side/datasource-types';\nimport { collapseAll, expandAll, expandToKey, toggleExpand } from './tree-data';\nimport { countTopLevelNodes, getTopLevelNodeIndex } from './tree-datasource';\nimport { detectTreeStructure, inferChildrenField } from './tree-detect';\nimport styles from './tree.css?inline';\nimport type { ExpandCollapseAnimation, FlattenedTreeRow, TreeConfig, TreeExpandDetail, TreeRow } from './types';\n\n/**\n * Tree Data Plugin for tbw-grid\n *\n * Transforms your flat grid into a hierarchical tree view with expandable parent-child\n * relationships. Ideal for file explorers, organizational charts, nested categories,\n * or any data with a natural hierarchy.\n *\n * ## Installation\n *\n * ```ts\n * import { TreePlugin } from '@toolbox-web/grid/plugins/tree';\n * ```\n *\n * ## CSS Custom Properties\n *\n * | Property | Default | Description |\n * |----------|---------|-------------|\n * | `--tbw-tree-toggle-size` | `1.25em` | Toggle icon width |\n * | `--tbw-tree-indent-width` | `var(--tbw-tree-toggle-size)` | Indentation per level |\n * | `--tbw-tree-accent` | `var(--tbw-color-accent)` | Toggle icon hover color |\n * | `--tbw-animation-duration` | `200ms` | Expand/collapse animation duration |\n * | `--tbw-animation-easing` | `ease-out` | Animation curve |\n *\n * @example Basic Tree with Nested Children\n * ```ts\n * import { queryGrid } from '@toolbox-web/grid';\n * import { TreePlugin } from '@toolbox-web/grid/plugins/tree';\n *\n * const grid = queryGrid('tbw-grid');\n * grid.gridConfig = {\n * columns: [\n * { field: 'name', header: 'Name' },\n * { field: 'type', header: 'Type' },\n * { field: 'size', header: 'Size' },\n * ],\n * plugins: [new TreePlugin({ childrenField: 'children', indentWidth: 24 })],\n * };\n * grid.rows = [\n * {\n * id: 1,\n * name: 'Documents',\n * type: 'folder',\n * children: [\n * { id: 2, name: 'Report.docx', type: 'file', size: '24 KB' },\n * ],\n * },\n * ];\n * ```\n *\n * @example Expanded by Default with Custom Animation\n * ```ts\n * new TreePlugin({\n * defaultExpanded: true,\n * animation: 'fade', // 'slide' | 'fade' | false\n * indentWidth: 32,\n * })\n * ```\n *\n * @see {@link TreeConfig} for all configuration options\n * @see {@link FlattenedTreeRow} for the flattened row structure\n *\n * @internal Extends BaseGridPlugin\n */\nexport class TreePlugin extends BaseGridPlugin<TreeConfig> {\n static override readonly manifest: PluginManifest = {\n modifiesRowStructure: true,\n hookPriority: {\n processRows: 10, // Run after ServerSide (-10) so we receive managedNodes[]\n },\n incompatibleWith: [\n {\n name: 'groupingRows',\n reason:\n 'Both plugins transform the entire row model. TreePlugin flattens nested hierarchies while ' +\n 'GroupingRowsPlugin groups flat rows with synthetic headers. Use one approach per grid.',\n },\n {\n name: 'pivot',\n reason:\n 'PivotPlugin replaces the entire row and column structure with aggregated pivot data. ' +\n 'Tree hierarchy cannot coexist with pivot aggregation.',\n },\n ],\n events: [\n {\n type: 'tree-expand',\n description:\n 'Emitted when tree expansion state changes (toggle, expand all, collapse all). Broadcast to both DOM consumers and plugin bus.',\n },\n ],\n queries: [\n {\n type: 'canMoveRow',\n description: 'Returns false for rows with children (parent nodes cannot be reordered)',\n },\n {\n type: 'datasource:viewport-mapping',\n description: 'Translates flat viewport row indices to top-level node indices for ServerSide pagination.',\n },\n ],\n };\n\n /**\n * Optional dependency on MultiSort for coordinated sorting.\n * When MultiSort is loaded, Tree defers header click sorting to it and queries the\n * sort model in processRows. When MultiSort is absent, Tree uses its own sort state.\n */\n static override readonly dependencies = [\n { name: 'multiSort', required: false, reason: 'Queries sort model for coordinated tree sorting' },\n { name: 'serverSide', required: false, reason: 'Consumes datasource events for lazy-loaded tree data' },\n ];\n\n /** @internal */\n readonly name = 'tree';\n /** @internal */\n override readonly styles = styles;\n\n /** @internal */\n protected override get defaultConfig(): Partial<TreeConfig> {\n return {\n childrenField: 'children',\n autoDetect: true,\n defaultExpanded: false,\n indentWidth: 20,\n showExpandIcons: true,\n animation: 'slide',\n };\n }\n\n // #region State\n\n private expandedKeys = new Set<string>();\n private initialExpansionDone = false;\n private flattenedRows: FlattenedTreeRow[] = [];\n private rowKeyMap = new Map<string, FlattenedTreeRow>();\n private previousVisibleKeys = new Set<string>();\n private keysToAnimate = new Set<string>();\n private sortState: { field: string; direction: 1 | -1 } | null = null;\n /** Keys of nodes that are currently loading lazy children via ServerSide. */\n private loadingKeys = new Set<string>();\n\n /**\n * Stable key cache keyed by row identity.\n * Persists across sort operations (object identity is preserved by sort);\n * replaces the previous `__stableKey` field-mutation approach so that\n * `_rows[i]` remains the user's original row reference and `updateRow(s)`\n * mutations survive the next `processRows` rebuild.\n *\n * INVARIANT: never mutate row objects to attach tree metadata — keep all\n * tree-specific state in this map and `#rowMeta` (see plugin-author rule\n * in `.github/knowledge/grid-plugins.md`).\n */\n #rowKeys = new WeakMap<object, string>();\n\n /**\n * Per-row tree metadata (depth, hasChildren, isExpanded, key) keyed by\n * row identity. Looked up by the column renderer via {@link getRowMeta}.\n * Reassigned to a fresh `WeakMap` at the start of each `processRows` call so\n * collapsed/hidden rows don't return stale metadata from a prior pass.\n */\n #rowMeta = new WeakMap<object, FlattenedTreeRow>();\n\n /** Cached original (unwrapped) renderer to prevent re-wrapping on repeated processColumns calls. */\n private originalTreeColumnRenderer: ColumnViewRenderer | undefined;\n /** Field name of the column currently wrapped with tree decorations. */\n private wrappedTreeColumnField: string | undefined;\n\n /** @internal */\n override detach(): void {\n // Restore default `role=\"grid\"` on the rows-body so the grid stays\n // ARIA-valid after the plugin is removed (template default lives in\n // `core/internal/dom-builder.ts`). See WAI-ARIA Treegrid pattern.\n const rowsBody = this.gridElement?.querySelector('.rows-body');\n rowsBody?.setAttribute('role', 'grid');\n\n this.expandedKeys.clear();\n this.initialExpansionDone = false;\n this.flattenedRows = [];\n this.rowKeyMap.clear();\n this.previousVisibleKeys.clear();\n this.keysToAnimate.clear();\n this.sortState = null;\n this.loadingKeys.clear();\n this.originalTreeColumnRenderer = undefined;\n this.wrappedTreeColumnField = undefined;\n // WeakMaps GC themselves once row references are dropped — nothing to clear.\n }\n\n /**\n * Handle plugin queries.\n * @internal\n */\n override handleQuery(query: PluginQuery): unknown {\n if (query.type === 'canMoveRow') {\n // Tree rows with children cannot be reordered\n const row = query.context as { [key: string]: unknown } | null | undefined;\n const childrenField = this.config.childrenField ?? 'children';\n const children = row?.[childrenField];\n if (Array.isArray(children) && children.length > 0) {\n return false;\n }\n }\n\n if (query.type === 'datasource:viewport-mapping') {\n // Translate visible flat row indices → top-level node indices for ServerSide pagination\n const { viewportStart, viewportEnd } = query.context as ViewportMappingQuery;\n if (this.flattenedRows.length === 0) return undefined;\n\n const startNode = getTopLevelNodeIndex(this.flattenedRows, viewportStart);\n const endNode = getTopLevelNodeIndex(this.flattenedRows, viewportEnd) + 1; // exclusive\n const totalLoadedNodes = countTopLevelNodes(this.flattenedRows);\n\n return { startNode, endNode, totalLoadedNodes } satisfies ViewportMappingResponse;\n }\n\n return undefined;\n }\n\n // #endregion\n\n // #region Lifecycle\n\n /** @internal */\n override attach(grid: GridElement): void {\n super.attach(grid);\n\n // Listen for datasource:data from ServerSidePlugin — claim data for tree processing\n this.on('datasource:data', (detail: unknown) => {\n const d = detail as DataSourceDataDetail;\n if (!d.claimed) {\n d.claimed = true;\n }\n // Data flows through processRows pipeline — Tree receives it via the rows parameter\n // since ServerSide's processRows (hookPriority -10) runs first and returns managedNodes[]\n });\n\n // Listen for datasource:children — consume child rows from ServerSide\n this.on('datasource:children', (detail: unknown) => {\n const d = detail as DataSourceChildrenDetail;\n if (d.context?.source !== 'tree') return;\n d.claimed = true;\n\n // Merge children into the parent node\n const parentRow = d.context.parentNode as TreeRow | undefined;\n if (parentRow) {\n const childrenField = this.config.childrenField ?? 'children';\n (parentRow as Record<string, unknown>)[childrenField] = d.rows;\n // Look up the stable key by row identity (was stored on row as __stableKey\n // historically; now lives in a parallel WeakMap to keep row identity intact).\n const key = this.#rowKeys.get(parentRow as object) ?? String(parentRow.id ?? '?');\n this.loadingKeys.delete(key);\n this.requestRender();\n }\n });\n }\n\n // #endregion\n\n // #region Animation\n\n /**\n * Get expand/collapse animation style from plugin config.\n * Uses base class isAnimationEnabled to respect grid-level settings.\n */\n private get animationStyle(): ExpandCollapseAnimation {\n if (!this.isAnimationEnabled) return false;\n return this.config.animation ?? 'slide';\n }\n\n // #endregion\n\n // #region Auto-Detection\n\n detect(rows: readonly unknown[]): boolean {\n if (!this.config.autoDetect) return false;\n const treeRows = rows as readonly TreeRow[];\n const field = this.config.childrenField ?? inferChildrenField(treeRows) ?? 'children';\n return detectTreeStructure(treeRows, field);\n }\n\n // #endregion\n\n // #region Data Processing\n\n /** @internal */\n override processRows(rows: readonly unknown[]): TreeRow[] {\n const childrenField = this.config.childrenField ?? 'children';\n\n const treeRows = rows as readonly TreeRow[];\n\n if (treeRows.length === 0 || !detectTreeStructure(treeRows, childrenField)) {\n this.flattenedRows = [];\n this.rowKeyMap.clear();\n this.previousVisibleKeys.clear();\n // _rows[i] must remain the user's row reference. Return a shallow array\n // copy (so callers can't mutate the input array via the returned ref)\n // but DO NOT spread/clone the row objects themselves.\n return [...rows] as TreeRow[];\n }\n\n // Initialize expansion if needed.\n // When MultiSort is active, use its model instead of local sort state so\n // Tree and MultiSort don't fight over sort ownership.\n const effectiveSortState = this.resolveEffectiveSortState();\n\n if (this.config.defaultExpanded && !this.initialExpansionDone) {\n this.expandedKeys = expandAll(treeRows, this.config);\n this.initialExpansionDone = true;\n }\n\n // Single pass: sort + flatten in one walk, never cloning row objects.\n // `data` on each FlattenedTreeRow stays === the user's source row.\n this.flattenedRows = this.#flattenWithSort(treeRows, this.expandedKeys, effectiveSortState, null, 0);\n\n // Reset per-row metadata so rows that are no longer in the flattened\n // output (e.g. children of a now-collapsed parent) don't keep returning\n // stale entries via getRowMeta(). WeakMap reassignment is cheap and the\n // old map becomes GC-eligible immediately.\n this.#rowMeta = new WeakMap();\n this.rowKeyMap.clear();\n this.keysToAnimate.clear();\n const currentKeys = new Set<string>();\n\n for (const row of this.flattenedRows) {\n this.rowKeyMap.set(row.key, row);\n this.#rowMeta.set(row.data as object, row);\n currentKeys.add(row.key);\n if (!this.previousVisibleKeys.has(row.key) && row.depth > 0) {\n this.keysToAnimate.add(row.key);\n }\n }\n this.previousVisibleKeys = currentKeys;\n\n // Return source row references directly. Tree metadata (depth/key/etc.)\n // is read by the renderer via `getRowMeta(row)` instead of being spread\n // onto cloned row objects \\u2014 this keeps `_rows[i]` === user's row so that\n // `grid.updateRow(s)` mutations survive the next ROWS-phase rebuild.\n return this.flattenedRows.map((r) => r.data);\n }\n\n /**\n * Resolve the stable key for a row, caching by identity in {@link #rowKeys}.\n * Prefers `row.id` (already stable across sort), then any previously cached\n * key for this row reference, then falls back to a path-based key.\n */\n #keyFor(row: TreeRow, index: number, parentKey: string | null): string {\n if (row.id !== undefined) {\n const key = String(row.id);\n this.#rowKeys.set(row as object, key);\n return key;\n }\n const cached = this.#rowKeys.get(row as object);\n if (cached !== undefined) return cached;\n const key = parentKey ? `${parentKey}-${index}` : String(index);\n this.#rowKeys.set(row as object, key);\n return key;\n }\n\n /**\n * Recursive single-pass sort + flatten.\n * - Per-level sort uses `[...rows].sort(...)` which produces a new array of\n * the SAME row references in a new order \\u2014 never spreads the row objects.\n * - Children arrays are NOT mutated on the source rows; the sort produces a\n * transient ordering used only for traversal.\n */\n #flattenWithSort(\n rows: readonly TreeRow[],\n expanded: Set<string>,\n sort: { field: string; direction: 1 | -1 } | null,\n parentKey: string | null,\n depth: number,\n ): FlattenedTreeRow[] {\n const childrenField = this.config.childrenField ?? 'children';\n // Assign stable keys using the ORIGINAL (unsorted) index so that\n // path-based keys match those produced by `expandAll` (which walks the\n // tree in source order). `#keyFor` caches by row identity, so the\n // subsequent lookup in the post-sort loop returns the same key.\n for (let i = 0; i < rows.length; i++) {\n this.#keyFor(rows[i], i, parentKey);\n }\n const ordered = sort ? this.#sortLevel(rows, sort.field, sort.direction) : rows;\n const result: FlattenedTreeRow[] = [];\n\n for (let i = 0; i < ordered.length; i++) {\n const row = ordered[i];\n const key = this.#keyFor(row, i, parentKey);\n const children = row[childrenField];\n const embeddedChildren = Array.isArray(children) && children.length > 0;\n // Lazy children: truthy non-array value (e.g. `children: true`) signals\n // that children exist on the server but haven't been fetched yet.\n const lazyChildren = children != null && !Array.isArray(children) && !!children;\n const hasChildren = embeddedChildren || lazyChildren;\n const isExpanded = expanded.has(key);\n\n result.push({\n key,\n data: row,\n depth,\n hasChildren,\n isExpanded,\n parentKey,\n posInSet: i + 1,\n setSize: ordered.length,\n });\n\n if (embeddedChildren && isExpanded) {\n result.push(...this.#flattenWithSort(children as TreeRow[], expanded, sort, key, depth + 1));\n }\n }\n return result;\n }\n\n /**\n * Sort rows at a single level, returning a new array of the SAME row references\n * in sorted order. Never clones row objects, and never mutates the input array\n * (children arrays are user-owned for tree rows — we always pass a shallow copy\n * to the handler so a custom in-place sortHandler can't corrupt user data).\n *\n * Delegates to the same handler chain core uses: `gridConfig.sortHandler` when\n * provided, otherwise `builtInSort` (which honors per-column `sortComparator`\n * and `valueAccessor`). Async handlers cannot be awaited inside the synchronous\n * tree flatten — fall back to `builtInSort` when one is detected, and swallow\n * any rejection so it doesn't surface as an unhandled promise rejection.\n */\n #sortLevel(rows: readonly TreeRow[], field: string, dir: 1 | -1): TreeRow[] {\n const host = this.grid as unknown as GridHost<TreeRow> | undefined;\n const columns = (host?._columns ?? []) as ColumnConfig<TreeRow>[];\n const handler: SortHandler<TreeRow> = host?.effectiveConfig?.sortHandler ?? builtInSort;\n const sortState = { field, direction: dir };\n // Always pass a shallow copy: `rows` may be a user-owned `row.children`\n // array, and a non-defensive sortHandler could otherwise mutate it.\n const input = [...rows] as TreeRow[];\n const result = handler(input, sortState, columns);\n if (result && typeof (result as Promise<unknown[]>).then === 'function') {\n void (result as Promise<unknown[]>).catch(() => undefined);\n return builtInSort(input, sortState, columns);\n }\n return result as TreeRow[];\n }\n\n /**\n * Request lazy children for a node via ServerSide's `datasource:fetch-children` query.\n * Called when expanding a node whose children are not yet embedded (lazy indicator only).\n * No-op if ServerSide is not active, children are already loading, or children are embedded.\n */\n private requestLazyChildren(flatRow: FlattenedTreeRow): void {\n if (this.loadingKeys.has(flatRow.key)) return;\n\n const childrenField = this.config.childrenField ?? 'children';\n const children = flatRow.data[childrenField];\n // Only fetch if children is a lazy indicator (truthy but not a non-empty array)\n if (Array.isArray(children) && children.length > 0) return;\n\n const isServerSideActive = this.grid?.query?.('datasource:is-active', null);\n if (!isServerSideActive) return;\n\n this.loadingKeys.add(flatRow.key);\n this.grid.query('datasource:fetch-children', {\n context: { source: 'tree', parentNode: flatRow.data, nodePath: [flatRow.key] },\n } satisfies FetchChildrenQuery);\n }\n\n /**\n * Resolve the effective sort state: prefer MultiSort's model when available,\n * fall back to local tree sort state.\n * This follows the same pattern as GroupingRowsPlugin.resolveGroupSortDirections.\n */\n private resolveEffectiveSortState(): { field: string; direction: 1 | -1 } | null {\n // When MultiSort is loaded, prefer its model for consistency\n const multiSortResults = this.grid?.query?.('sort:get-model', null);\n if (Array.isArray(multiSortResults) && multiSortResults.length > 0) {\n const sortModel = multiSortResults[0] as Array<{ field: string; direction: 'asc' | 'desc' }>;\n if (Array.isArray(sortModel) && sortModel.length > 0) {\n // Use the primary sort column from MultiSort\n return {\n field: sortModel[0].field,\n direction: sortModel[0].direction === 'desc' ? -1 : 1,\n };\n }\n }\n // Fallback: local sort state (when MultiSort is not loaded)\n return this.sortState;\n }\n\n /** @internal */\n override processColumns(columns: readonly ColumnConfig[]): ColumnConfig[] {\n if (this.flattenedRows.length === 0) return [...columns];\n\n const cols = [...columns] as ColumnConfig[];\n if (cols.length === 0) return cols;\n\n // Determine which column gets the tree toggle and indentation.\n // If treeColumn is configured, find it by field name; otherwise use the first column.\n const { treeColumn } = this.config;\n let targetIndex = 0;\n if (treeColumn) {\n const idx = cols.findIndex((c) => c.field === treeColumn);\n if (idx >= 0) targetIndex = idx;\n }\n const targetCol = cols[targetIndex];\n const targetField = targetCol.field;\n\n // Capture the original (unwrapped) renderer only once per target column.\n // On subsequent processColumns calls, reuse the cached original so we\n // don't nest tree-cell-wrappers.\n if (this.wrappedTreeColumnField !== targetField) {\n this.originalTreeColumnRenderer = targetCol.viewRenderer;\n this.wrappedTreeColumnField = targetField;\n }\n const originalRenderer = this.originalTreeColumnRenderer;\n const getConfig = () => this.config;\n const setIconFn = this.setIcon.bind(this);\n\n const wrappedRenderer: ColumnViewRenderer = (ctx) => {\n const { row, value } = ctx;\n const { showExpandIcons = true, indentWidth } = getConfig();\n const meta = this.#rowMeta.get(row as object);\n const depth = meta?.depth ?? 0;\n\n const container = document.createElement('span');\n container.className = 'tree-cell-wrapper';\n container.style.setProperty('--tbw-tree-depth', String(depth));\n // Allow config-based indentWidth to override CSS default\n if (indentWidth !== undefined) {\n container.style.setProperty('--tbw-tree-indent-width', `${indentWidth}px`);\n }\n\n // Add expand/collapse icon or spacer\n if (showExpandIcons) {\n if (meta && meta.hasChildren) {\n const icon = document.createElement('span');\n icon.className = `${GridClasses.TREE_TOGGLE}${meta.isExpanded ? ` ${GridClasses.EXPANDED}` : ''}`;\n setIconFn(icon, meta.isExpanded ? 'collapse' : 'expand');\n icon.setAttribute('data-tree-key', meta.key);\n container.appendChild(icon);\n } else {\n const spacer = document.createElement('span');\n spacer.className = 'tree-spacer';\n container.appendChild(spacer);\n }\n }\n\n // Add the original content\n const content = document.createElement('span');\n content.className = 'tree-content';\n if (originalRenderer) {\n const result = originalRenderer(ctx);\n if (result instanceof Node) {\n content.appendChild(result);\n } else if (typeof result === 'string') {\n content.innerHTML = result;\n }\n } else {\n content.textContent = value != null ? String(value) : '';\n }\n container.appendChild(content);\n\n return container;\n };\n\n cols[targetIndex] = { ...targetCol, viewRenderer: wrappedRenderer };\n return cols;\n }\n\n // #endregion\n\n // #region Event Handlers\n\n /** @internal */\n override onCellClick(event: CellClickEvent): boolean {\n const target = event.originalEvent?.target as HTMLElement;\n if (!target?.classList.contains(GridClasses.TREE_TOGGLE)) return false;\n\n const key = target.getAttribute('data-tree-key');\n if (!key) return false;\n\n const flatRow = this.rowKeyMap.get(key);\n if (!flatRow) return false;\n\n this.expandedKeys = toggleExpand(this.expandedKeys, key);\n\n // Request lazy children when expanding a node without embedded children\n if (this.expandedKeys.has(key)) {\n this.requestLazyChildren(flatRow);\n }\n\n this.broadcast<TreeExpandDetail>('tree-expand', {\n key,\n row: flatRow.data,\n expanded: this.expandedKeys.has(key),\n depth: flatRow.depth,\n expandedKeys: [...this.expandedKeys],\n });\n this.requestRender();\n return true;\n }\n\n /** @internal */\n override onKeyDown(event: KeyboardEvent): boolean | void {\n // SPACE toggles expansion when on a row with children\n if (event.key !== ' ') return;\n\n const focusRow = this.grid._focusRow;\n const flatRow = this.flattenedRows[focusRow];\n if (!flatRow?.hasChildren) return;\n\n event.preventDefault();\n this.expandedKeys = toggleExpand(this.expandedKeys, flatRow.key);\n\n // Request lazy children when expanding a node without embedded children\n if (this.expandedKeys.has(flatRow.key)) {\n this.requestLazyChildren(flatRow);\n }\n\n this.broadcast<TreeExpandDetail>('tree-expand', {\n key: flatRow.key,\n row: flatRow.data,\n expanded: this.expandedKeys.has(flatRow.key),\n depth: flatRow.depth,\n expandedKeys: [...this.expandedKeys],\n });\n this.requestRenderWithFocus();\n return true;\n }\n\n /** @internal */\n override onHeaderClick(event: HeaderClickEvent): boolean {\n if (this.flattenedRows.length === 0 || !event.column.sortable) return false;\n\n // When MultiSort is active, let it handle header clicks entirely.\n // Tree will pick up the sort model in processRows via resolveEffectiveSortState().\n const multiSortResults = this.grid?.query?.('sort:get-model', null);\n if (Array.isArray(multiSortResults) && multiSortResults.length > 0) {\n // MultiSort is loaded — don't consume the event, let MultiSort handle it\n return false;\n }\n\n // Fallback: manage own sort state when MultiSort is not loaded\n const { field } = event.column;\n if (!this.sortState || this.sortState.field !== field) {\n this.sortState = { field, direction: 1 };\n } else if (this.sortState.direction === 1) {\n this.sortState = { field, direction: -1 };\n } else {\n this.sortState = null;\n }\n\n // Sync grid sort indicator\n const gridEl = this.grid as unknown as GridHost;\n if (gridEl._sortState !== undefined) {\n gridEl._sortState = this.sortState ? { ...this.sortState } : null;\n }\n\n this.broadcast('sort-change', { field, direction: this.sortState?.direction ?? 0 });\n this.requestRender();\n return true;\n }\n\n /** @internal */\n override afterRender(): void {\n // Tree introduces hierarchy → switch the rows-body role from `grid` to\n // `treegrid` per WAI-ARIA so `aria-expanded` / `aria-level` /\n // `aria-setsize` / `aria-posinset` are valid in context. Idempotent\n // setAttribute call; cheap on the hot path.\n const rowsBody = this.gridElement?.querySelector('.rows-body');\n if (rowsBody && rowsBody.getAttribute('role') !== 'treegrid') {\n rowsBody.setAttribute('role', 'treegrid');\n }\n\n const body = this.gridElement?.querySelector('.rows');\n if (!body) return;\n\n const style = this.animationStyle;\n const shouldAnimate = style !== false && this.keysToAnimate.size > 0;\n const animClass = style === 'fade' ? 'tbw-tree-fade-in' : 'tbw-tree-slide-in';\n\n for (const rowEl of body.querySelectorAll('.data-grid-row')) {\n const cell = rowEl.querySelector('.cell[data-row]');\n const idx = cell ? parseInt(cell.getAttribute('data-row') ?? '-1', 10) : -1;\n const treeRow = this.flattenedRows[idx];\n if (!treeRow) continue;\n\n // WAI-ARIA Treegrid: every row carries level/setsize/posinset so screen\n // readers can announce \"level 2, item 3 of 5\" while navigating.\n rowEl.setAttribute('aria-level', String(treeRow.depth + 1));\n rowEl.setAttribute('aria-setsize', String(treeRow.setSize));\n rowEl.setAttribute('aria-posinset', String(treeRow.posInSet));\n\n // Set aria-expanded on parent rows for screen readers\n if (treeRow.hasChildren) {\n rowEl.setAttribute('aria-expanded', String(treeRow.isExpanded));\n }\n\n if (shouldAnimate && treeRow.key && this.keysToAnimate.has(treeRow.key)) {\n rowEl.classList.add(animClass);\n rowEl.addEventListener('animationend', () => rowEl.classList.remove(animClass), { once: true });\n }\n }\n this.keysToAnimate.clear();\n }\n\n // #endregion\n\n // #region Public API\n\n /**\n * Expand a specific tree node, revealing its children.\n *\n * If the node is already expanded, this is a no-op.\n * Does **not** emit a `tree-expand` event (use {@link toggle} for event emission).\n *\n * @param key - The unique key of the node to expand (from {@link FlattenedTreeRow.key})\n *\n * @example\n * ```ts\n * const tree = grid.getPluginByName('tree');\n * tree.expand('documents'); // Expand a root node\n * tree.expand('documents||reports'); // Expand a nested node\n * ```\n */\n expand(key: string): void {\n this.expandedKeys.add(key);\n const flatRow = this.rowKeyMap.get(key);\n if (flatRow) {\n this.requestLazyChildren(flatRow);\n }\n this.requestRender();\n }\n\n /**\n * Collapse a specific tree node, hiding its children.\n *\n * If the node is already collapsed, this is a no-op.\n * Does **not** emit a `tree-expand` event (use {@link toggle} for event emission).\n *\n * @param key - The unique key of the node to collapse (from {@link FlattenedTreeRow.key})\n *\n * @example\n * ```ts\n * const tree = grid.getPluginByName('tree');\n * tree.collapse('documents');\n * ```\n */\n collapse(key: string): void {\n this.expandedKeys.delete(key);\n this.requestRender();\n }\n\n /**\n * Toggle the expanded state of a tree node.\n *\n * If the node is expanded it will be collapsed, and vice versa.\n * Emits a `tree-expand` event (broadcast to both DOM consumers and plugin bus).\n *\n * @param key - The unique key of the node to toggle (from {@link FlattenedTreeRow.key})\n *\n * @example\n * ```ts\n * const tree = grid.getPluginByName('tree');\n * tree.toggle('documents'); // Expand if collapsed, collapse if expanded\n * ```\n */\n toggle(key: string): void {\n this.expandedKeys = toggleExpand(this.expandedKeys, key);\n const flatRow = this.rowKeyMap.get(key);\n if (flatRow) {\n // Request lazy children when expanding a node without embedded children\n if (this.expandedKeys.has(key)) {\n this.requestLazyChildren(flatRow);\n }\n this.broadcast<TreeExpandDetail>('tree-expand', {\n key,\n row: flatRow.data,\n expanded: this.expandedKeys.has(key),\n depth: flatRow.depth,\n expandedKeys: [...this.expandedKeys],\n });\n } else {\n this.emitPluginEvent('tree-expand', { expandedKeys: [...this.expandedKeys] });\n }\n this.requestRender();\n }\n\n /**\n * Expand all tree nodes recursively.\n *\n * Every node with children will be expanded, revealing the full tree hierarchy.\n * Emits a `tree-expand` plugin event.\n *\n * @example\n * ```ts\n * const tree = grid.getPluginByName('tree');\n * tree.expandAll();\n * ```\n */\n expandAll(): void {\n this.expandedKeys = expandAll(this.rows as TreeRow[], this.config);\n this.emitPluginEvent('tree-expand', { expandedKeys: [...this.expandedKeys] });\n this.requestRender();\n }\n\n /**\n * Collapse all tree nodes.\n *\n * Every node will be collapsed, showing only root-level rows.\n * Emits a `tree-expand` plugin event.\n *\n * @example\n * ```ts\n * const tree = grid.getPluginByName('tree');\n * tree.collapseAll();\n * ```\n */\n collapseAll(): void {\n this.expandedKeys = collapseAll();\n this.emitPluginEvent('tree-expand', { expandedKeys: [...this.expandedKeys] });\n this.requestRender();\n }\n\n /**\n * Check whether a specific tree node is currently expanded.\n *\n * @param key - The unique key of the node to check\n * @returns `true` if the node is expanded, `false` otherwise\n */\n isExpanded(key: string): boolean {\n return this.expandedKeys.has(key);\n }\n\n /**\n * Get the keys of all currently expanded nodes.\n *\n * Returns a snapshot copy — mutating the returned array does not affect the tree state.\n *\n * @returns Array of expanded node keys\n *\n * @example\n * ```ts\n * const tree = grid.getPluginByName('tree');\n * const keys = tree.getExpandedKeys();\n * localStorage.setItem('treeState', JSON.stringify(keys));\n * ```\n */\n getExpandedKeys(): string[] {\n return [...this.expandedKeys];\n }\n\n /**\n * Get the flattened row model used for rendering.\n *\n * Returns a snapshot copy of the internal flattened tree rows, including\n * hierarchy metadata (depth, hasChildren, isExpanded, parentKey).\n *\n * @returns Array of {@link FlattenedTreeRow} objects\n */\n getFlattenedRows(): FlattenedTreeRow[] {\n return [...this.flattenedRows];\n }\n\n /**\n * Get tree metadata (depth, key, hasChildren, isExpanded, parentKey) for a\n * specific row reference. Returns `undefined` if the row is not part of the\n * currently-flattened tree (e.g. collapsed under a parent or never processed).\n *\n * Tree metadata lives in a parallel WeakMap keyed by row identity \\u2014 it is\n * NOT stored on the row object itself. This preserves the invariant that\n * `_rows[i]` IS the user's source row reference, so `grid.updateRow(s)`\n * mutations survive the next ROWS-phase rebuild.\n *\n * @example\n * ```ts\n * const tree = grid.getPluginByName('tree');\n * const meta = tree.getRowMeta(grid.rows[0]);\n * console.log(meta?.depth, meta?.hasChildren);\n * ```\n */\n getRowMeta(row: TreeRow): FlattenedTreeRow | undefined {\n return this.#rowMeta.get(row as object);\n }\n\n /**\n * Look up an original row data object by its tree key.\n *\n * @param key - The unique key of the node\n * @returns The original row data, or `undefined` if not found\n */\n getRowByKey(key: string): TreeRow | undefined {\n return this.rowKeyMap.get(key)?.data;\n }\n\n /**\n * Expand all ancestor nodes of the target key, revealing it in the tree.\n *\n * Useful for \"scroll to node\" or search-and-reveal scenarios where a deeply\n * nested node needs to be made visible.\n *\n * @param key - The unique key of the node to reveal\n *\n * @example\n * ```ts\n * const tree = grid.getPluginByName('tree');\n * // Reveal a deeply nested node by expanding all its parents\n * tree.expandToKey('root||child||grandchild');\n * ```\n */\n expandToKey(key: string): void {\n this.expandedKeys = expandToKey(this.rows as TreeRow[], key, this.config, this.expandedKeys);\n this.requestRender();\n }\n\n // #endregion\n}\n"],"names":["generateRowKey","row","index","parentKey","id","String","toggleExpand","expandedKeys","key","newExpanded","Set","has","delete","add","expandAll","rows","config","depth","childrenField","keys","i","length","children","Array","isArray","childKeys","k","getPathToKey","targetKey","childPath","expandToKey","existingExpanded","path","getTopLevelNodeIndex","flattenedRows","flatRowIndex","idx","Math","min","current","topLevelIndex","detectTreeStructure","TreePlugin","BaseGridPlugin","static","modifiesRowStructure","hookPriority","processRows","incompatibleWith","name","reason","events","type","description","queries","required","styles","defaultConfig","autoDetect","defaultExpanded","indentWidth","showExpandIcons","animation","initialExpansionDone","rowKeyMap","Map","previousVisibleKeys","keysToAnimate","sortState","loadingKeys","rowKeys","WeakMap","rowMeta","originalTreeColumnRenderer","wrappedTreeColumnField","detach","rowsBody","this","gridElement","querySelector","setAttribute","clear","handleQuery","query","context","viewportStart","viewportEnd","startNode","endNode","totalLoadedNodes","count","countTopLevelNodes","attach","grid","super","on","detail","d","claimed","source","parentRow","parentNode","get","requestRender","animationStyle","isAnimationEnabled","detect","treeRows","field","commonArrayFields","value","inferChildrenField","effectiveSortState","resolveEffectiveSortState","flattenWithSort","currentKeys","set","data","map","r","keyFor","cached","expanded","sort","ordered","sortLevel","direction","result","embeddedChildren","lazyChildren","hasChildren","isExpanded","push","posInSet","setSize","dir","host","columns","_columns","input","effectiveConfig","sortHandler","builtInSort","then","catch","requestLazyChildren","flatRow","isServerSideActive","nodePath","multiSortResults","sortModel","processColumns","cols","treeColumn","targetIndex","findIndex","c","targetCol","targetField","viewRenderer","originalRenderer","getConfig","setIconFn","setIcon","bind","ctx","meta","container","document","createElement","className","style","setProperty","icon","GridClasses","TREE_TOGGLE","EXPANDED","appendChild","spacer","content","Node","innerHTML","textContent","onCellClick","event","target","originalEvent","classList","contains","getAttribute","broadcast","onKeyDown","focusRow","_focusRow","preventDefault","requestRenderWithFocus","onHeaderClick","column","sortable","gridEl","_sortState","afterRender","body","shouldAnimate","size","animClass","rowEl","querySelectorAll","cell","parseInt","treeRow","addEventListener","remove","once","expand","collapse","toggle","emitPluginEvent","collapseAll","getExpandedKeys","getFlattenedRows","getRowMeta","getRowByKey"],"mappings":"keAYO,SAASA,EAAeC,EAAcC,EAAeC,GAC1D,YAAe,IAAXF,EAAIG,GAAyBC,OAAOJ,EAAIG,IACrCD,EAAY,GAAGA,KAAaD,IAAUG,OAAOH,EACtD,CAgDO,SAASI,EAAaC,EAA2BC,GACtD,MAAMC,EAAc,IAAIC,IAAIH,GAM5B,OALIE,EAAYE,IAAIH,GAClBC,EAAYG,OAAOJ,GAEnBC,EAAYI,IAAIL,GAEXC,CACT,CAMO,SAASK,EACdC,EACAC,EACAb,EAA2B,KAC3Bc,EAAQ,GAER,MAAMC,EAAgBF,EAAOE,eAAiB,WACxCC,MAAWT,IAEjB,IAAA,IAASU,EAAI,EAAGA,EAAIL,EAAKM,OAAQD,IAAK,CACpC,MAAMnB,EAAMc,EAAKK,GACXZ,EAAMR,EAAeC,EAAKmB,EAAGjB,GAC7BmB,EAAWrB,EAAIiB,GAErB,GAAIK,MAAMC,QAAQF,IAAaA,EAASD,OAAS,EAAG,CAClDF,EAAKN,IAAIL,GACT,MAAMiB,EAAYX,EAAUQ,EAAuBN,EAAQR,EAAKS,EAAQ,GACxE,IAAA,MAAWS,KAAKD,EAAWN,EAAKN,IAAIa,EACtC,CACF,CAEA,OAAOP,CACT,CA0CO,SAASQ,EACdZ,EACAa,EACAZ,EACAb,EAA2B,KAC3Bc,EAAQ,GAER,MAAMC,EAAgBF,EAAOE,eAAiB,WAE9C,IAAA,IAASE,EAAI,EAAGA,EAAIL,EAAKM,OAAQD,IAAK,CACpC,MAAMnB,EAAMc,EAAKK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