@toolbox-web/grid 0.0.4 → 0.0.5

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 (55) hide show
  1. package/all.d.ts +29 -6
  2. package/all.js +421 -421
  3. package/all.js.map +1 -1
  4. package/index.d.ts +28 -0
  5. package/index.js +774 -726
  6. package/index.js.map +1 -1
  7. package/lib/plugins/clipboard/index.js +55 -35
  8. package/lib/plugins/clipboard/index.js.map +1 -1
  9. package/lib/plugins/column-virtualization/index.js +49 -29
  10. package/lib/plugins/column-virtualization/index.js.map +1 -1
  11. package/lib/plugins/context-menu/index.js +35 -15
  12. package/lib/plugins/context-menu/index.js.map +1 -1
  13. package/lib/plugins/export/index.js +52 -32
  14. package/lib/plugins/export/index.js.map +1 -1
  15. package/lib/plugins/filtering/index.js +116 -99
  16. package/lib/plugins/filtering/index.js.map +1 -1
  17. package/lib/plugins/grouping-columns/index.js +42 -22
  18. package/lib/plugins/grouping-columns/index.js.map +1 -1
  19. package/lib/plugins/grouping-rows/index.js +20 -0
  20. package/lib/plugins/grouping-rows/index.js.map +1 -1
  21. package/lib/plugins/master-detail/index.js +50 -27
  22. package/lib/plugins/master-detail/index.js.map +1 -1
  23. package/lib/plugins/multi-sort/index.js +25 -5
  24. package/lib/plugins/multi-sort/index.js.map +1 -1
  25. package/lib/plugins/pinned-columns/index.js +20 -0
  26. package/lib/plugins/pinned-columns/index.js.map +1 -1
  27. package/lib/plugins/pinned-rows/index.js +20 -0
  28. package/lib/plugins/pinned-rows/index.js.map +1 -1
  29. package/lib/plugins/pivot/index.js +20 -0
  30. package/lib/plugins/pivot/index.js.map +1 -1
  31. package/lib/plugins/reorder/index.js +48 -28
  32. package/lib/plugins/reorder/index.js.map +1 -1
  33. package/lib/plugins/selection/index.js +51 -31
  34. package/lib/plugins/selection/index.js.map +1 -1
  35. package/lib/plugins/server-side/index.js +20 -0
  36. package/lib/plugins/server-side/index.js.map +1 -1
  37. package/lib/plugins/tree/index.js +76 -53
  38. package/lib/plugins/tree/index.js.map +1 -1
  39. package/lib/plugins/undo-redo/index.js +20 -0
  40. package/lib/plugins/undo-redo/index.js.map +1 -1
  41. package/lib/plugins/visibility/index.js +20 -0
  42. package/lib/plugins/visibility/index.js.map +1 -1
  43. package/package.json +1 -1
  44. package/umd/grid.all.umd.js +25 -25
  45. package/umd/grid.all.umd.js.map +1 -1
  46. package/umd/grid.umd.js +12 -12
  47. package/umd/grid.umd.js.map +1 -1
  48. package/umd/plugins/filtering.umd.js +3 -3
  49. package/umd/plugins/filtering.umd.js.map +1 -1
  50. package/umd/plugins/master-detail.umd.js +2 -2
  51. package/umd/plugins/master-detail.umd.js.map +1 -1
  52. package/umd/plugins/reorder.umd.js +1 -1
  53. package/umd/plugins/reorder.umd.js.map +1 -1
  54. package/umd/plugins/tree.umd.js +2 -2
  55. 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-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\n/* eslint-disable @typescript-eslint/no-explicit-any */\n// The tree plugin intentionally uses `any` for maximum flexibility with user-defined row types.\n\nimport type { FlattenedTreeRow, TreeConfig } 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: any, 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: any[],\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, 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(rows: any[], config: TreeConfig, parentKey: string | null = null, depth = 0): 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, 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: any[],\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, 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: any[],\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 Structure Auto-Detection\n *\n * Utilities for detecting hierarchical tree data structures.\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n// The tree plugin intentionally uses `any` for maximum flexibility with user-defined row types.\n\n/**\n * Detects if the data has a tree structure by checking for children arrays.\n */\nexport function detectTreeStructure(rows: any[], childrenField = 'children'): boolean {\n if (!Array.isArray(rows) || rows.length === 0) return false;\n\n // Check if any row has a non-empty children array\n for (const row of rows) {\n if (row && Array.isArray(row[childrenField]) && row[childrenField].length > 0) {\n return true;\n }\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: any[]): 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 if (Array.isArray(row[field]) && row[field].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: any[], 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, 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: any[], 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, childrenField);\n }\n }\n\n return count;\n}\n","/**\n * Tree Data Plugin (Class-based)\n *\n * Enables hierarchical tree data with expand/collapse and auto-detection.\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n// The tree plugin intentionally uses `any` for maximum flexibility with user-defined row types.\n\nimport { BaseGridPlugin, CellClickEvent } from '../../core/plugin/base-plugin';\nimport type { ColumnConfig } from '../../core/types';\nimport { collapseAll, expandAll, expandToKey, flattenTree, toggleExpand } from './tree-data';\nimport { detectTreeStructure, inferChildrenField } from './tree-detect';\nimport type { FlattenedTreeRow, TreeConfig, TreeExpandDetail } from './types';\n\n/**\n * Tree Data Plugin for tbw-grid\n *\n * Provides hierarchical tree data display with expand/collapse functionality.\n *\n * @example\n * ```ts\n * new TreePlugin({ defaultExpanded: true, indentWidth: 24 })\n * ```\n */\nexport class TreePlugin extends BaseGridPlugin<TreeConfig> {\n readonly name = 'tree';\n override readonly version = '1.0.0';\n\n protected override get defaultConfig(): Partial<TreeConfig> {\n return {\n enabled: true,\n childrenField: 'children',\n autoDetect: true,\n defaultExpanded: false,\n indentWidth: 20,\n showExpandIcons: true,\n };\n }\n\n // ===== Internal State =====\n\n /** Set of expanded row keys */\n private expandedKeys = new Set<string>();\n\n /** Whether initial expansion (based on defaultExpanded config) has been applied */\n private initialExpansionDone = false;\n\n /** Flattened tree rows for rendering */\n private flattenedRows: FlattenedTreeRow[] = [];\n\n /** Map from key to flattened row for quick lookup */\n private rowKeyMap = new Map<string, FlattenedTreeRow>();\n\n // ===== Lifecycle =====\n\n override detach(): void {\n this.expandedKeys.clear();\n this.initialExpansionDone = false;\n this.flattenedRows = [];\n this.rowKeyMap.clear();\n }\n\n // ===== Auto-Detection =====\n\n /**\n * Detects if tree functionality should be enabled based on data structure.\n * Called by the grid during plugin initialization.\n */\n detect(rows: readonly unknown[]): boolean {\n if (!this.config.autoDetect) return false;\n const childrenField = this.config.childrenField ?? inferChildrenField(rows as any[]) ?? 'children';\n return detectTreeStructure(rows as any[], childrenField);\n }\n\n // ===== Data Processing =====\n\n override processRows(rows: readonly unknown[]): any[] {\n const childrenField = this.config.childrenField ?? 'children';\n\n // Check if data is actually a tree\n if (!detectTreeStructure(rows as any[], childrenField)) {\n this.flattenedRows = [];\n this.rowKeyMap.clear();\n return [...rows];\n }\n\n // Initialize expansion state if needed (only once per grid lifecycle)\n if (this.config.defaultExpanded && !this.initialExpansionDone) {\n this.expandedKeys = expandAll(rows as any[], this.config);\n this.initialExpansionDone = true;\n }\n\n // Flatten tree\n this.flattenedRows = flattenTree(rows as any[], this.config, this.expandedKeys);\n\n // Build key map\n this.rowKeyMap.clear();\n for (const flatRow of this.flattenedRows) {\n this.rowKeyMap.set(flatRow.key, flatRow);\n }\n\n // Return flattened data for rendering with tree metadata\n return this.flattenedRows.map((fr) => ({\n ...fr.data,\n __treeKey: fr.key,\n __treeDepth: fr.depth,\n __treeHasChildren: fr.hasChildren,\n __treeExpanded: fr.isExpanded,\n }));\n }\n\n override processColumns(columns: readonly ColumnConfig[]): ColumnConfig[] {\n if (this.flattenedRows.length === 0) return [...columns];\n\n const indentWidth = this.config.indentWidth ?? 20;\n const showExpandIcons = this.config.showExpandIcons ?? true;\n\n // Wrap first column's renderer to add tree indentation\n const cols = [...columns] as ColumnConfig[];\n if (cols.length > 0) {\n const firstCol = { ...cols[0] };\n const originalRenderer = firstCol.viewRenderer;\n\n firstCol.viewRenderer = (renderCtx) => {\n const { value, row, column: colConfig } = renderCtx;\n const depth = row.__treeDepth ?? 0;\n const hasChildren = row.__treeHasChildren ?? false;\n const isExpanded = row.__treeExpanded ?? false;\n\n const container = document.createElement('span');\n container.style.display = 'flex';\n container.style.alignItems = 'center';\n container.style.paddingLeft = `${depth * indentWidth}px`;\n\n // Expand/collapse icon\n if (hasChildren && showExpandIcons) {\n const icon = document.createElement('span');\n icon.className = 'tree-toggle';\n icon.textContent = isExpanded ? '▼' : '▶';\n icon.style.cursor = 'pointer';\n icon.style.marginRight = '4px';\n icon.style.fontSize = '10px';\n icon.setAttribute('data-tree-key', row.__treeKey);\n container.appendChild(icon);\n } else if (showExpandIcons) {\n // Spacer for alignment\n const spacer = document.createElement('span');\n spacer.style.width = '14px';\n spacer.style.display = 'inline-block';\n container.appendChild(spacer);\n }\n\n // Cell content\n const content = document.createElement('span');\n if (originalRenderer) {\n const rendered = originalRenderer(renderCtx);\n if (rendered instanceof Node) {\n content.appendChild(rendered);\n } else {\n content.textContent = String(rendered ?? value ?? '');\n }\n } else {\n content.textContent = String(value ?? '');\n }\n container.appendChild(content);\n\n return container;\n };\n\n cols[0] = firstCol;\n }\n\n return cols;\n }\n\n // ===== Event Handlers =====\n\n override onCellClick(event: CellClickEvent): boolean {\n const target = event.originalEvent?.target as HTMLElement;\n if (!target?.classList.contains('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 this.emit<TreeExpandDetail>('tree-expand', {\n key,\n row: flatRow.data,\n expanded: this.expandedKeys.has(key),\n depth: flatRow.depth,\n });\n\n this.requestRender();\n return true;\n }\n\n // ===== Public API =====\n\n /**\n * Expand a specific node by key.\n */\n expand(key: string): void {\n this.expandedKeys.add(key);\n this.requestRender();\n }\n\n /**\n * Collapse a specific node by key.\n */\n collapse(key: string): void {\n this.expandedKeys.delete(key);\n this.requestRender();\n }\n\n /**\n * Toggle the expansion state of a node.\n */\n toggle(key: string): void {\n this.expandedKeys = toggleExpand(this.expandedKeys, key);\n this.requestRender();\n }\n\n /**\n * Expand all nodes in the tree.\n */\n expandAll(): void {\n this.expandedKeys = expandAll(this.rows as any[], this.config);\n this.requestRender();\n }\n\n /**\n * Collapse all nodes in the tree.\n */\n collapseAll(): void {\n this.expandedKeys = collapseAll();\n this.requestRender();\n }\n\n /**\n * Check if a node is currently expanded.\n */\n isExpanded(key: string): boolean {\n return this.expandedKeys.has(key);\n }\n\n /**\n * Get all currently expanded keys.\n */\n getExpandedKeys(): string[] {\n return [...this.expandedKeys];\n }\n\n /**\n * Get the flattened tree rows with metadata.\n */\n getFlattenedRows(): FlattenedTreeRow[] {\n return [...this.flattenedRows];\n }\n\n /**\n * Get a row's original data by its key.\n */\n getRowByKey(key: string): any | undefined {\n return this.rowKeyMap.get(key)?.data;\n }\n\n /**\n * Expand all ancestors of a node to make it visible.\n */\n expandToKey(key: string): void {\n this.expandedKeys = expandToKey(this.rows as any[], key, this.config, this.expandedKeys);\n this.requestRender();\n }\n\n // ===== Styles =====\n\n override readonly styles = `\n .tree-toggle {\n cursor: pointer;\n user-select: none;\n transition: transform 0.2s;\n }\n .tree-toggle:hover {\n color: var(--tbw-tree-accent, var(--tbw-color-accent));\n }\n `;\n}\n"],"names":["generateRowKey","row","index","parentKey","flattenTree","rows","config","expandedKeys","depth","childrenField","result","i","key","children","hasChildren","isExpanded","childRows","toggleExpand","newExpanded","expandAll","keys","childKeys","k","collapseAll","getPathToKey","targetKey","childPath","expandToKey","existingExpanded","path","detectTreeStructure","inferChildrenField","commonArrayFields","field","getMaxDepth","currentDepth","maxDepth","childDepth","countNodes","count","TreePlugin","BaseGridPlugin","flatRow","fr","columns","indentWidth","showExpandIcons","cols","firstCol","originalRenderer","renderCtx","value","colConfig","container","icon","spacer","content","rendered","event","target"],"mappings":"gUAeO,SAASA,EAAeC,EAAUC,EAAeC,EAAkC,CACxF,OAAIF,EAAI,KAAO,OAAkB,OAAOA,EAAI,EAAE,EACvCE,EAAY,GAAGA,CAAS,IAAID,CAAK,GAAK,OAAOA,CAAK,CAC3D,CAMO,SAASE,EACdC,EACAC,EACAC,EACAJ,EAA2B,KAC3BK,EAAQ,EACY,CACpB,MAAMC,EAAgBH,EAAO,eAAiB,WACxCI,EAA6B,CAAA,EAEnC,QAASC,EAAI,EAAGA,EAAIN,EAAK,OAAQM,IAAK,CACpC,MAAMV,EAAMI,EAAKM,CAAC,EACZC,EAAMZ,EAAeC,EAAKU,EAAGR,CAAS,EACtCU,EAAWZ,EAAIQ,CAAa,EAC5BK,EAAc,MAAM,QAAQD,CAAQ,GAAKA,EAAS,OAAS,EAC3DE,EAAaR,EAAa,IAAIK,CAAG,EAYvC,GAVAF,EAAO,KAAK,CACV,IAAAE,EACA,KAAMX,EACN,MAAAO,EACA,YAAAM,EACA,WAAAC,EACA,UAAAZ,CAAA,CACD,EAGGW,GAAeC,EAAY,CAC7B,MAAMC,EAAYZ,EAAYS,EAAUP,EAAQC,EAAcK,EAAKJ,EAAQ,CAAC,EAC5EE,EAAO,KAAK,GAAGM,CAAS,CAC1B,CACF,CAEA,OAAON,CACT,CAMO,SAASO,EAAaV,EAA2BK,EAA0B,CAChF,MAAMM,EAAc,IAAI,IAAIX,CAAY,EACxC,OAAIW,EAAY,IAAIN,CAAG,EACrBM,EAAY,OAAON,CAAG,EAEtBM,EAAY,IAAIN,CAAG,EAEdM,CACT,CAMO,SAASC,EAAUd,EAAaC,EAAoBH,EAA2B,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AAU,IAAIA,CAAG,GAAG,IAClC,CAKA,YAAYA,EAAmB,CAC7B,KAAK,aAAee,EAAY,KAAK,KAAef,EAAK,KAAK,OAAQ,KAAK,YAAY,EACvF,KAAK,cAAA,CACP,CAIkB,OAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAU7B"}
1
+ {"version":3,"file":"tree.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/tree/tree-data.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\n/* eslint-disable @typescript-eslint/no-explicit-any */\n// The tree plugin intentionally uses `any` for maximum flexibility with user-defined row types.\n\nimport type { FlattenedTreeRow, TreeConfig } 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: any, 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: any[],\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, 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(rows: any[], config: TreeConfig, parentKey: string | null = null, depth = 0): 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, 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: any[],\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, 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: any[],\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 Structure Auto-Detection\n *\n * Utilities for detecting hierarchical tree data structures.\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n// The tree plugin intentionally uses `any` for maximum flexibility with user-defined row types.\n\n/**\n * Detects if the data has a tree structure by checking for children arrays.\n */\nexport function detectTreeStructure(rows: any[], childrenField = 'children'): boolean {\n if (!Array.isArray(rows) || rows.length === 0) return false;\n\n // Check if any row has a non-empty children array\n for (const row of rows) {\n if (row && Array.isArray(row[childrenField]) && row[childrenField].length > 0) {\n return true;\n }\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: any[]): 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 if (Array.isArray(row[field]) && row[field].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: any[], 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, 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: any[], 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, childrenField);\n }\n }\n\n return count;\n}\n","/**\n * Tree Data Plugin (Class-based)\n *\n * Enables hierarchical tree data with expand/collapse and auto-detection.\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n// The tree plugin intentionally uses `any` for maximum flexibility with user-defined row types.\n\nimport { BaseGridPlugin, CellClickEvent } from '../../core/plugin/base-plugin';\nimport type { ColumnConfig } from '../../core/types';\nimport { collapseAll, expandAll, expandToKey, flattenTree, toggleExpand } from './tree-data';\nimport { detectTreeStructure, inferChildrenField } from './tree-detect';\nimport type { FlattenedTreeRow, TreeConfig, TreeExpandDetail } from './types';\n\n/**\n * Tree Data Plugin for tbw-grid\n *\n * Provides hierarchical tree data display with expand/collapse functionality.\n *\n * @example\n * ```ts\n * new TreePlugin({ defaultExpanded: true, indentWidth: 24 })\n * ```\n */\nexport class TreePlugin extends BaseGridPlugin<TreeConfig> {\n readonly name = 'tree';\n override readonly version = '1.0.0';\n\n protected override get defaultConfig(): Partial<TreeConfig> {\n return {\n enabled: true,\n childrenField: 'children',\n autoDetect: true,\n defaultExpanded: false,\n indentWidth: 20,\n showExpandIcons: true,\n };\n }\n\n // ===== Internal State =====\n\n /** Set of expanded row keys */\n private expandedKeys = new Set<string>();\n\n /** Whether initial expansion (based on defaultExpanded config) has been applied */\n private initialExpansionDone = false;\n\n /** Flattened tree rows for rendering */\n private flattenedRows: FlattenedTreeRow[] = [];\n\n /** Map from key to flattened row for quick lookup */\n private rowKeyMap = new Map<string, FlattenedTreeRow>();\n\n // ===== Lifecycle =====\n\n override detach(): void {\n this.expandedKeys.clear();\n this.initialExpansionDone = false;\n this.flattenedRows = [];\n this.rowKeyMap.clear();\n }\n\n // ===== Auto-Detection =====\n\n /**\n * Detects if tree functionality should be enabled based on data structure.\n * Called by the grid during plugin initialization.\n */\n detect(rows: readonly unknown[]): boolean {\n if (!this.config.autoDetect) return false;\n const childrenField = this.config.childrenField ?? inferChildrenField(rows as any[]) ?? 'children';\n return detectTreeStructure(rows as any[], childrenField);\n }\n\n // ===== Data Processing =====\n\n override processRows(rows: readonly unknown[]): any[] {\n const childrenField = this.config.childrenField ?? 'children';\n\n // Check if data is actually a tree\n if (!detectTreeStructure(rows as any[], childrenField)) {\n this.flattenedRows = [];\n this.rowKeyMap.clear();\n return [...rows];\n }\n\n // Initialize expansion state if needed (only once per grid lifecycle)\n if (this.config.defaultExpanded && !this.initialExpansionDone) {\n this.expandedKeys = expandAll(rows as any[], this.config);\n this.initialExpansionDone = true;\n }\n\n // Flatten tree\n this.flattenedRows = flattenTree(rows as any[], this.config, this.expandedKeys);\n\n // Build key map\n this.rowKeyMap.clear();\n for (const flatRow of this.flattenedRows) {\n this.rowKeyMap.set(flatRow.key, flatRow);\n }\n\n // Return flattened data for rendering with tree metadata\n return this.flattenedRows.map((fr) => ({\n ...fr.data,\n __treeKey: fr.key,\n __treeDepth: fr.depth,\n __treeHasChildren: fr.hasChildren,\n __treeExpanded: fr.isExpanded,\n }));\n }\n\n override processColumns(columns: readonly ColumnConfig[]): ColumnConfig[] {\n if (this.flattenedRows.length === 0) return [...columns];\n\n const indentWidth = this.config.indentWidth ?? 20;\n const showExpandIcons = this.config.showExpandIcons ?? true;\n\n // Wrap first column's renderer to add tree indentation\n const cols = [...columns] as ColumnConfig[];\n if (cols.length > 0) {\n const firstCol = { ...cols[0] };\n const originalRenderer = firstCol.viewRenderer;\n\n // Skip if already wrapped by this plugin (prevents double-wrapping on re-render)\n if ((originalRenderer as any)?.__treeWrapped) {\n return cols;\n }\n\n const wrappedRenderer = (renderCtx: Parameters<NonNullable<typeof originalRenderer>>[0]) => {\n const { value, row, column: colConfig } = renderCtx;\n const depth = row.__treeDepth ?? 0;\n const hasChildren = row.__treeHasChildren ?? false;\n const isExpanded = row.__treeExpanded ?? false;\n\n const container = document.createElement('span');\n container.style.display = 'flex';\n container.style.alignItems = 'center';\n container.style.paddingLeft = `${depth * indentWidth}px`;\n\n // Expand/collapse icon\n if (hasChildren && showExpandIcons) {\n const icon = document.createElement('span');\n icon.className = 'tree-toggle';\n icon.textContent = isExpanded ? '▼' : '▶';\n icon.style.cursor = 'pointer';\n icon.style.marginRight = '4px';\n icon.style.fontSize = '10px';\n icon.setAttribute('data-tree-key', row.__treeKey);\n container.appendChild(icon);\n } else if (showExpandIcons) {\n // Spacer for alignment\n const spacer = document.createElement('span');\n spacer.style.width = '14px';\n spacer.style.display = 'inline-block';\n container.appendChild(spacer);\n }\n\n // Cell content\n const content = document.createElement('span');\n if (originalRenderer) {\n const rendered = originalRenderer(renderCtx);\n if (rendered instanceof Node) {\n content.appendChild(rendered);\n } else {\n content.textContent = String(rendered ?? value ?? '');\n }\n } else {\n content.textContent = String(value ?? '');\n }\n container.appendChild(content);\n\n return container;\n };\n\n // Mark renderer as wrapped to prevent double-wrapping\n (wrappedRenderer as any).__treeWrapped = true;\n firstCol.viewRenderer = wrappedRenderer;\n\n cols[0] = firstCol;\n }\n\n return cols;\n }\n\n // ===== Event Handlers =====\n\n override onCellClick(event: CellClickEvent): boolean {\n const target = event.originalEvent?.target as HTMLElement;\n if (!target?.classList.contains('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 this.emit<TreeExpandDetail>('tree-expand', {\n key,\n row: flatRow.data,\n expanded: this.expandedKeys.has(key),\n depth: flatRow.depth,\n });\n\n this.requestRender();\n return true;\n }\n\n // ===== Public API =====\n\n /**\n * Expand a specific node by key.\n */\n expand(key: string): void {\n this.expandedKeys.add(key);\n this.requestRender();\n }\n\n /**\n * Collapse a specific node by key.\n */\n collapse(key: string): void {\n this.expandedKeys.delete(key);\n this.requestRender();\n }\n\n /**\n * Toggle the expansion state of a node.\n */\n toggle(key: string): void {\n this.expandedKeys = toggleExpand(this.expandedKeys, key);\n this.requestRender();\n }\n\n /**\n * Expand all nodes in the tree.\n */\n expandAll(): void {\n this.expandedKeys = expandAll(this.rows as any[], this.config);\n this.requestRender();\n }\n\n /**\n * Collapse all nodes in the tree.\n */\n collapseAll(): void {\n this.expandedKeys = collapseAll();\n this.requestRender();\n }\n\n /**\n * Check if a node is currently expanded.\n */\n isExpanded(key: string): boolean {\n return this.expandedKeys.has(key);\n }\n\n /**\n * Get all currently expanded keys.\n */\n getExpandedKeys(): string[] {\n return [...this.expandedKeys];\n }\n\n /**\n * Get the flattened tree rows with metadata.\n */\n getFlattenedRows(): FlattenedTreeRow[] {\n return [...this.flattenedRows];\n }\n\n /**\n * Get a row's original data by its key.\n */\n getRowByKey(key: string): any | undefined {\n return this.rowKeyMap.get(key)?.data;\n }\n\n /**\n * Expand all ancestors of a node to make it visible.\n */\n expandToKey(key: string): void {\n this.expandedKeys = expandToKey(this.rows as any[], key, this.config, this.expandedKeys);\n this.requestRender();\n }\n\n // ===== Styles =====\n\n override readonly styles = `\n .tree-toggle {\n cursor: pointer;\n user-select: none;\n transition: transform 0.2s;\n }\n .tree-toggle:hover {\n color: var(--tbw-tree-accent, var(--tbw-color-accent));\n }\n `;\n}\n"],"names":["generateRowKey","row","index","parentKey","flattenTree","rows","config","expandedKeys","depth","childrenField","result","i","key","children","hasChildren","isExpanded","childRows","toggleExpand","newExpanded","expandAll","keys","childKeys","k","collapseAll","getPathToKey","targetKey","childPath","expandToKey","existingExpanded","path","detectTreeStructure","inferChildrenField","commonArrayFields","field","getMaxDepth","currentDepth","maxDepth","childDepth","countNodes","count","TreePlugin","BaseGridPlugin","flatRow","fr","columns","indentWidth","showExpandIcons","cols","firstCol","originalRenderer","wrappedRenderer","renderCtx","value","colConfig","container","icon","spacer","content","rendered","event","target"],"mappings":"gUAeO,SAASA,EAAeC,EAAUC,EAAeC,EAAkC,CACxF,OAAIF,EAAI,KAAO,OAAkB,OAAOA,EAAI,EAAE,EACvCE,EAAY,GAAGA,CAAS,IAAID,CAAK,GAAK,OAAOA,CAAK,CAC3D,CAMO,SAASE,EACdC,EACAC,EACAC,EACAJ,EAA2B,KAC3BK,EAAQ,EACY,CACpB,MAAMC,EAAgBH,EAAO,eAAiB,WACxCI,EAA6B,CAAA,EAEnC,QAASC,EAAI,EAAGA,EAAIN,EAAK,OAAQM,IAAK,CACpC,MAAMV,EAAMI,EAAKM,CAAC,EACZC,EAAMZ,EAAeC,EAAKU,EAAGR,CAAS,EACtCU,EAAWZ,EAAIQ,CAAa,EAC5BK,EAAc,MAAM,QAAQD,CAAQ,GAAKA,EAAS,OAAS,EAC3DE,EAAaR,EAAa,IAAIK,CAAG,EAYvC,GAVAF,EAAO,KAAK,CACV,IAAAE,EACA,KAAMX,EACN,MAAAO,EACA,YAAAM,EACA,WAAAC,EACA,UAAAZ,CAAA,CACD,EAGGW,GAAeC,EAAY,CAC7B,MAAMC,EAAYZ,EAAYS,EAAUP,EAAQC,EAAcK,EAAKJ,EAAQ,CAAC,EAC5EE,EAAO,KAAK,GAAGM,CAAS,CAC1B,CACF,CAEA,OAAON,CACT,CAMO,SAASO,EAAaV,EAA2BK,EAA0B,CAChF,MAAMM,EAAc,IAAI,IAAIX,CAAY,EACxC,OAAIW,EAAY,IAAIN,CAAG,EACrBM,EAAY,OAAON,CAAG,EAEtBM,EAAY,IAAIN,CAAG,EAEdM,CACT,CAMO,SAASC,EAAUd,EAAaC,EAAoBH,EAA2B,KAAMK,EAAQ,EAAgB,CAClH,MAAMC,EAAgBH,EAAO,eAAiB,WACxCc,MAAW,IAEjB,QAAST,EAAI,EAAGA,EAAIN,EAAK,OAAQM,IAAK,CACpC,MAAMV,EAAMI,EAAKM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