@toolbox-web/grid 2.0.0-rc.1 → 2.0.0-rc.2

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 (95) hide show
  1. package/README.md +23 -6
  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/sorting.d.ts +4 -0
  7. package/lib/core/plugin/base-plugin.d.ts +31 -0
  8. package/lib/core/plugin/plugin-manager.d.ts +4 -1
  9. package/lib/core/plugin/types.d.ts +2 -0
  10. package/lib/core/types.d.ts +20 -1
  11. package/lib/plugins/clipboard/ClipboardPlugin.d.ts +8 -1
  12. package/lib/plugins/clipboard/index.js +1 -1
  13. package/lib/plugins/clipboard/index.js.map +1 -1
  14. package/lib/plugins/column-virtualization/index.js +1 -1
  15. package/lib/plugins/column-virtualization/index.js.map +1 -1
  16. package/lib/plugins/context-menu/index.js +1 -1
  17. package/lib/plugins/context-menu/index.js.map +1 -1
  18. package/lib/plugins/editing/index.js +1 -1
  19. package/lib/plugins/editing/index.js.map +1 -1
  20. package/lib/plugins/export/ExportPlugin.d.ts +8 -1
  21. package/lib/plugins/export/index.js +1 -1
  22. package/lib/plugins/export/index.js.map +1 -1
  23. package/lib/plugins/filtering/index.js +1 -1
  24. package/lib/plugins/filtering/index.js.map +1 -1
  25. package/lib/plugins/grouping-columns/index.js +1 -1
  26. package/lib/plugins/grouping-columns/index.js.map +1 -1
  27. package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts +33 -1
  28. package/lib/plugins/grouping-rows/grouping-rows.d.ts +15 -1
  29. package/lib/plugins/grouping-rows/index.js +2 -2
  30. package/lib/plugins/grouping-rows/index.js.map +1 -1
  31. package/lib/plugins/master-detail/index.js +1 -1
  32. package/lib/plugins/master-detail/index.js.map +1 -1
  33. package/lib/plugins/multi-sort/index.js +1 -1
  34. package/lib/plugins/multi-sort/index.js.map +1 -1
  35. package/lib/plugins/pinned-columns/index.js +1 -1
  36. package/lib/plugins/pinned-columns/index.js.map +1 -1
  37. package/lib/plugins/pinned-rows/index.js +1 -1
  38. package/lib/plugins/pinned-rows/index.js.map +1 -1
  39. package/lib/plugins/pivot/PivotPlugin.d.ts +10 -0
  40. package/lib/plugins/pivot/index.js +1 -1
  41. package/lib/plugins/pivot/index.js.map +1 -1
  42. package/lib/plugins/print/index.js +1 -1
  43. package/lib/plugins/print/index.js.map +1 -1
  44. package/lib/plugins/reorder-columns/index.js +1 -1
  45. package/lib/plugins/reorder-columns/index.js.map +1 -1
  46. package/lib/plugins/reorder-rows/RowReorderPlugin.d.ts +3 -0
  47. package/lib/plugins/reorder-rows/index.js +1 -1
  48. package/lib/plugins/reorder-rows/index.js.map +1 -1
  49. package/lib/plugins/responsive/index.js +1 -1
  50. package/lib/plugins/responsive/index.js.map +1 -1
  51. package/lib/plugins/selection/index.js +1 -1
  52. package/lib/plugins/selection/index.js.map +1 -1
  53. package/lib/plugins/server-side/index.js +1 -1
  54. package/lib/plugins/server-side/index.js.map +1 -1
  55. package/lib/plugins/tooltip/index.js +1 -1
  56. package/lib/plugins/tooltip/index.js.map +1 -1
  57. package/lib/plugins/tree/TreePlugin.d.ts +16 -0
  58. package/lib/plugins/tree/index.js +1 -1
  59. package/lib/plugins/tree/index.js.map +1 -1
  60. package/lib/plugins/tree/types.d.ts +6 -0
  61. package/lib/plugins/undo-redo/index.js +1 -1
  62. package/lib/plugins/undo-redo/index.js.map +1 -1
  63. package/lib/plugins/visibility/index.js +1 -1
  64. package/lib/plugins/visibility/index.js.map +1 -1
  65. package/package.json +1 -1
  66. package/umd/grid.all.umd.js +1 -1
  67. package/umd/grid.all.umd.js.map +1 -1
  68. package/umd/grid.umd.js +1 -1
  69. package/umd/grid.umd.js.map +1 -1
  70. package/umd/plugins/clipboard.umd.js +1 -1
  71. package/umd/plugins/clipboard.umd.js.map +1 -1
  72. package/umd/plugins/context-menu.umd.js +1 -1
  73. package/umd/plugins/context-menu.umd.js.map +1 -1
  74. package/umd/plugins/editing.umd.js +1 -1
  75. package/umd/plugins/editing.umd.js.map +1 -1
  76. package/umd/plugins/export.umd.js +1 -1
  77. package/umd/plugins/export.umd.js.map +1 -1
  78. package/umd/plugins/grouping-rows.umd.js +1 -1
  79. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  80. package/umd/plugins/multi-sort.umd.js +1 -1
  81. package/umd/plugins/multi-sort.umd.js.map +1 -1
  82. package/umd/plugins/pinned-columns.umd.js +1 -1
  83. package/umd/plugins/pinned-columns.umd.js.map +1 -1
  84. package/umd/plugins/pivot.umd.js +1 -1
  85. package/umd/plugins/pivot.umd.js.map +1 -1
  86. package/umd/plugins/reorder-rows.umd.js +1 -1
  87. package/umd/plugins/reorder-rows.umd.js.map +1 -1
  88. package/umd/plugins/selection.umd.js +1 -1
  89. package/umd/plugins/selection.umd.js.map +1 -1
  90. package/umd/plugins/server-side.umd.js +1 -1
  91. package/umd/plugins/server-side.umd.js.map +1 -1
  92. package/umd/plugins/tooltip.umd.js +1 -1
  93. package/umd/plugins/tooltip.umd.js.map +1 -1
  94. package/umd/plugins/tree.umd.js +1 -1
  95. package/umd/plugins/tree.umd.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/tooltip/TooltipPlugin.ts"],"sourcesContent":["/**\n * Tooltip Plugin\n *\n * Shows styled popover tooltips on header and data cells when text\n * overflows (ellipsis). Uses the Popover API (`popover=\"hint\"`) with\n * CSS anchor positioning for consistent, themed placement.\n *\n * Supports per-column overrides via `cellTooltip` and `headerTooltip`\n * on column config.\n */\n\nimport type { GridElement, PluginManifest } from '../../core/plugin/base-plugin';\nimport { BaseGridPlugin } from '../../core/plugin/base-plugin';\nimport type { CellRenderContext, ColumnConfig, HeaderLabelContext } from '../../core/types';\nimport tooltipStyles from './tooltip.css?inline';\nimport type { TooltipConfig } from './types';\n\n// #region Helpers\n\n/** Check if an element's text content overflows its visible width. */\nfunction isOverflowing(el: HTMLElement): boolean {\n return el.scrollWidth > el.clientWidth;\n}\n\n/**\n * Resolve the tooltip text for a cell.\n * Returns the text to show, or `null` to suppress.\n */\nfunction resolveCellTooltip(column: ColumnConfig, cell: HTMLElement, row: unknown, value: unknown): string | null {\n const spec = column.cellTooltip;\n\n if (spec === false) return null;\n if (typeof spec === 'string') return spec;\n if (typeof spec === 'function') {\n const ctx: CellRenderContext = { value, row, column, field: column.field };\n return spec(ctx);\n }\n\n // Default: show textContent only when overflowing\n if (isOverflowing(cell)) {\n return cell.textContent?.trim() || null;\n }\n\n return null;\n}\n\n/**\n * Resolve the tooltip text for a header cell.\n * Returns the text to show, or `null` to suppress.\n */\nfunction resolveHeaderTooltip(column: ColumnConfig, headerCell: HTMLElement): string | null {\n const spec = column.headerTooltip;\n\n if (spec === false) return null;\n if (typeof spec === 'string') return spec;\n if (typeof spec === 'function') {\n const ctx: HeaderLabelContext = {\n column,\n value: column.header ?? column.field,\n };\n return spec(ctx);\n }\n\n // Default: show header text only when overflowing\n const labelSpan = headerCell.querySelector('span:first-child') as HTMLElement | null;\n const target = labelSpan ?? headerCell;\n\n if (isOverflowing(target)) {\n return target.textContent?.trim() || null;\n }\n\n return null;\n}\n\n/** Runtime check — happy-dom and older browsers may lack Popover API. */\nfunction supportsPopover(): boolean {\n return typeof HTMLElement.prototype?.showPopover === 'function';\n}\n\n/** Runtime check for CSS anchor positioning. */\nfunction supportsAnchor(): boolean {\n return typeof CSS !== 'undefined' && CSS.supports?.('anchor-name', '--test') === true;\n}\n// #endregion\n\n// #region TooltipPlugin\n/**\n * Tooltip Plugin for tbw-grid\n *\n * Shows styled popover tooltips when header or cell text overflows its\n * container. Uses the Popover API with CSS anchor positioning for\n * consistent themed appearance across light and dark modes.\n *\n * ## Installation\n *\n * ```ts\n * import { TooltipPlugin } from '@toolbox-web/grid/plugins/tooltip';\n * ```\n *\n * @example Default — auto-tooltip on overflow\n * ```ts\n * grid.gridConfig = {\n * plugins: [new TooltipPlugin()],\n * };\n * ```\n *\n * @example Header-only tooltips\n * ```ts\n * grid.gridConfig = {\n * plugins: [new TooltipPlugin({ cell: false })],\n * };\n * ```\n *\n * @example Per-column overrides\n * ```ts\n * grid.gridConfig = {\n * columns: [\n * { field: 'name', cellTooltip: (ctx) => `${ctx.row.first} ${ctx.row.last}` },\n * { field: 'actions', cellTooltip: false },\n * { field: 'revenue', headerTooltip: 'Total revenue in USD (before tax)' },\n * ],\n * plugins: [new TooltipPlugin()],\n * };\n * ```\n *\n * @category Plugins\n */\nexport class TooltipPlugin extends BaseGridPlugin<TooltipConfig> {\n readonly name = 'tooltip';\n override readonly styles = tooltipStyles;\n\n static override readonly manifest: PluginManifest<TooltipConfig> = {\n ownedProperties: [\n { property: 'cellTooltip', level: 'column', description: 'the \"cellTooltip\" column property' },\n { property: 'headerTooltip', level: 'column', description: 'the \"headerTooltip\" column property' },\n ],\n configRules: [],\n };\n\n /** The shared popover element for all tooltips. */\n #popoverEl: HTMLElement | null = null;\n\n /** The cell currently acting as CSS anchor. */\n #anchorCell: HTMLElement | null = null;\n\n /** Whether delegated listeners are bound. */\n #bound = false;\n\n /** Whether header tooltips are enabled globally. */\n get #headerEnabled(): boolean {\n return this.config.header !== false;\n }\n\n /** Whether cell tooltips are enabled globally. */\n get #cellEnabled(): boolean {\n return this.config.cell !== false;\n }\n\n override attach(grid: GridElement): void {\n super.attach(grid);\n }\n\n override detach(): void {\n this.#hideTooltip();\n this.#popoverEl?.remove();\n this.#popoverEl = null;\n this.#bound = false;\n super.detach();\n }\n\n override afterRender(): void {\n this.#ensurePopover();\n this.#bindEvents();\n }\n\n // #region Popover Lifecycle\n\n /** Create the shared popover element (once). */\n #ensurePopover(): void {\n if (this.#popoverEl) return;\n const el = document.createElement('div');\n el.className = 'tbw-tooltip-popover';\n el.setAttribute('popover', 'hint');\n // Override UA popover defaults that @layer CSS cannot beat\n el.style.overflow = 'visible';\n el.style.margin = '0';\n document.body.appendChild(el);\n this.#popoverEl = el;\n }\n\n /** Show the popover anchored to `cell` with the given `text`. */\n #showTooltip(cell: HTMLElement, text: string): void {\n if (!this.#popoverEl) return;\n\n // Move the CSS anchor to the hovered cell\n this.#clearAnchor();\n cell.style.setProperty('anchor-name', '--tbw-tooltip-anchor');\n this.#anchorCell = cell;\n\n // Set content (always textContent — safe, no XSS)\n this.#popoverEl.textContent = text;\n\n // Show via Popover API\n if (supportsPopover()) {\n try {\n this.#popoverEl.showPopover();\n } catch {\n /* already shown */\n }\n }\n\n if (supportsAnchor()) {\n // Detect flip after the browser resolves position-try-fallbacks\n requestAnimationFrame(() => this.#detectFlip(cell));\n } else {\n this.#positionFallback(cell);\n }\n }\n\n /** Hide the popover and clear the anchor reference. */\n #hideTooltip(): void {\n if (this.#popoverEl) {\n if (supportsPopover()) {\n try {\n this.#popoverEl.hidePopover();\n } catch {\n /* already hidden */\n }\n }\n this.#popoverEl.classList.remove('tbw-tooltip-above');\n }\n this.#clearAnchor();\n }\n\n /** Remove the CSS anchor-name from the previous cell. */\n #clearAnchor(): void {\n if (this.#anchorCell) {\n this.#anchorCell.style.removeProperty('anchor-name');\n this.#anchorCell = null;\n }\n }\n\n /**\n * Fallback positioning for browsers without CSS anchor support.\n * Places the popover below or above the cell using fixed coordinates.\n */\n #positionFallback(cell: HTMLElement): void {\n if (!this.#popoverEl) return;\n const cellRect = cell.getBoundingClientRect();\n const arrowGap = 11;\n\n this.#popoverEl.style.position = 'fixed';\n this.#popoverEl.style.left = `${cellRect.left}px`;\n\n // Check if there's space below\n const spaceBelow = window.innerHeight - cellRect.bottom;\n if (spaceBelow < 80) {\n // Place above the cell\n this.#popoverEl.style.top = '';\n this.#popoverEl.style.bottom = `${window.innerHeight - cellRect.top + arrowGap}px`;\n this.#popoverEl.classList.add('tbw-tooltip-above');\n } else {\n this.#popoverEl.style.top = `${cellRect.bottom + arrowGap}px`;\n this.#popoverEl.style.bottom = '';\n this.#popoverEl.classList.remove('tbw-tooltip-above');\n }\n }\n\n /** Toggle the arrow direction class after CSS anchor positioning resolves. */\n #detectFlip(cell: HTMLElement): void {\n if (!this.#popoverEl) return;\n const cellRect = cell.getBoundingClientRect();\n const popoverRect = this.#popoverEl.getBoundingClientRect();\n // If the popover's bottom edge is above the cell's top, it flipped\n this.#popoverEl.classList.toggle('tbw-tooltip-above', popoverRect.bottom <= cellRect.top);\n }\n // #endregion\n\n // #region Event Delegation\n\n /** Bind delegated mouseover/mouseout once. */\n #bindEvents(): void {\n if (this.#bound) return;\n const container = this.gridElement?.querySelector('.tbw-grid-root');\n if (!container) return;\n\n this.#bound = true;\n\n container.addEventListener('mouseover', (e: Event) => this.#onMouseOver(e as MouseEvent), {\n signal: this.disconnectSignal,\n });\n\n container.addEventListener('mouseout', (e: Event) => this.#onMouseOut(e as MouseEvent), {\n signal: this.disconnectSignal,\n });\n }\n\n #onMouseOver(e: MouseEvent): void {\n const target = e.target as HTMLElement;\n if (!target?.closest) return;\n\n // Check for header cell\n const headerCell = target.closest('[part~=\"header-cell\"]') as HTMLElement | null;\n if (headerCell && this.#headerEnabled) {\n this.#showHeaderTooltip(headerCell);\n return;\n }\n\n // Check for data cell\n const dataCell = target.closest('[data-row][data-col]') as HTMLElement | null;\n if (dataCell && this.#cellEnabled) {\n this.#showCellTooltip(dataCell);\n }\n }\n\n #onMouseOut(e: MouseEvent): void {\n const target = e.target as HTMLElement;\n if (!target?.closest) return;\n\n const cell = target.closest('[part~=\"header-cell\"], [data-row][data-col]') as HTMLElement | null;\n if (!cell) return;\n\n // Keep tooltip if pointer moved to a child still inside the same cell\n const related = e.relatedTarget as HTMLElement | null;\n if (related && cell.contains(related)) return;\n\n this.#hideTooltip();\n }\n // #endregion\n\n // #region Tooltip Resolution\n\n #showHeaderTooltip(headerCell: HTMLElement): void {\n const colIndex = parseInt(headerCell.getAttribute('data-col') ?? '-1', 10);\n if (colIndex < 0) return;\n\n const column = this.visibleColumns[colIndex];\n if (!column) return;\n\n const text = resolveHeaderTooltip(column, headerCell);\n if (text) {\n this.#showTooltip(headerCell, text);\n }\n }\n\n #showCellTooltip(cell: HTMLElement): void {\n const rowIndex = parseInt(cell.getAttribute('data-row') ?? '-1', 10);\n const colIndex = parseInt(cell.getAttribute('data-col') ?? '-1', 10);\n if (rowIndex < 0 || colIndex < 0) return;\n\n const column = this.visibleColumns[colIndex];\n if (!column) return;\n\n const row = this.rows[rowIndex];\n const value = row?.[column.field as keyof typeof row];\n\n const text = resolveCellTooltip(column, cell, row, value);\n if (text) {\n this.#showTooltip(cell, text);\n }\n }\n // #endregion\n}\n// #endregion\n"],"names":["isOverflowing","el","scrollWidth","clientWidth","supportsPopover","HTMLElement","prototype","showPopover","TooltipPlugin","BaseGridPlugin","name","styles","static","ownedProperties","property","level","description","configRules","popoverEl","anchorCell","bound","headerEnabled","this","config","header","cellEnabled","cell","attach","grid","super","detach","hideTooltip","remove","afterRender","ensurePopover","bindEvents","document","createElement","className","setAttribute","style","overflow","margin","body","appendChild","showTooltip","text","clearAnchor","setProperty","textContent","CSS","supports","requestAnimationFrame","detectFlip","positionFallback","hidePopover","classList","removeProperty","cellRect","getBoundingClientRect","position","left","window","innerHeight","bottom","top","add","popoverRect","toggle","container","gridElement","querySelector","addEventListener","e","onMouseOver","signal","disconnectSignal","onMouseOut","target","closest","headerCell","showHeaderTooltip","dataCell","showCellTooltip","related","relatedTarget","contains","colIndex","parseInt","getAttribute","column","visibleColumns","spec","headerTooltip","value","field","trim","resolveHeaderTooltip","rowIndex","row","rows","cellTooltip","resolveCellTooltip"],"mappings":"iVAoBA,SAASA,EAAcC,GACrB,OAAOA,EAAGC,YAAcD,EAAGE,WAC7B,CAqDA,SAASC,IACP,MAAqD,mBAAvCC,YAAYC,WAAWC,WACvC,CAkDO,MAAMC,UAAsBC,EAAAA,eACxBC,KAAO,UACEC,yzDAElBC,gBAAmE,CACjEC,gBAAiB,CACf,CAAEC,SAAU,cAAeC,MAAO,SAAUC,YAAa,qCACzD,CAAEF,SAAU,gBAAiBC,MAAO,SAAU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AAoB,iBAATA,EAAmB,OAAOA,EACrC,GAAoB,mBAATA,EAET,OAAOA,EADwB,CAAEE,QAAOK,MAAKT,SAAQK,MAAOL,EAAOK,QAKrE,OAAI/F,EAAc0B,IACTA,EAAKuB,aAAa+C,QAGpB,IACT,CAwTiBM,CAAmBZ,EAAQhE,EAAMyE,EAAKL,GAC/ChD,GACFxB,MAAKuB,EAAanB,EAAMoB,EAE5B"}
1
+ {"version":3,"file":"tooltip.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/tooltip/TooltipPlugin.ts"],"sourcesContent":["/**\n * Tooltip Plugin\n *\n * Shows styled popover tooltips on header and data cells when text\n * overflows (ellipsis). Uses the Popover API (`popover=\"hint\"`) with\n * CSS anchor positioning for consistent, themed placement.\n *\n * Supports per-column overrides via `cellTooltip` and `headerTooltip`\n * on column config.\n */\n\nimport type { GridElement, PluginManifest } from '../../core/plugin/base-plugin';\nimport { BaseGridPlugin } from '../../core/plugin/base-plugin';\nimport type { CellRenderContext, ColumnConfig, HeaderLabelContext } from '../../core/types';\nimport tooltipStyles from './tooltip.css?inline';\nimport type { TooltipConfig } from './types';\n\n// #region Helpers\n\n/** Check if an element's text content overflows its visible width. */\nfunction isOverflowing(el: HTMLElement): boolean {\n return el.scrollWidth > el.clientWidth;\n}\n\n/**\n * Resolve the tooltip text for a cell.\n * Returns the text to show, or `null` to suppress.\n */\nfunction resolveCellTooltip(column: ColumnConfig, cell: HTMLElement, row: unknown, value: unknown): string | null {\n const spec = column.cellTooltip;\n\n if (spec === false) return null;\n if (typeof spec === 'string') return spec;\n if (typeof spec === 'function') {\n const ctx: CellRenderContext = { value, row, column, field: column.field };\n return spec(ctx);\n }\n\n // Default: show textContent only when overflowing\n if (isOverflowing(cell)) {\n return cell.textContent?.trim() || null;\n }\n\n return null;\n}\n\n/**\n * Resolve the tooltip text for a header cell.\n * Returns the text to show, or `null` to suppress.\n */\nfunction resolveHeaderTooltip(column: ColumnConfig, headerCell: HTMLElement): string | null {\n const spec = column.headerTooltip;\n\n if (spec === false) return null;\n if (typeof spec === 'string') return spec;\n if (typeof spec === 'function') {\n const ctx: HeaderLabelContext = {\n column,\n value: column.header ?? column.field,\n };\n return spec(ctx);\n }\n\n // Default: show header text only when overflowing\n const labelSpan = headerCell.querySelector('span:first-child') as HTMLElement | null;\n const target = labelSpan ?? headerCell;\n\n if (isOverflowing(target)) {\n return target.textContent?.trim() || null;\n }\n\n return null;\n}\n\n/** Runtime check — happy-dom and older browsers may lack Popover API. */\nfunction supportsPopover(): boolean {\n return typeof HTMLElement.prototype?.showPopover === 'function';\n}\n\n/** Runtime check for CSS anchor positioning. */\nfunction supportsAnchor(): boolean {\n return typeof CSS !== 'undefined' && CSS.supports?.('anchor-name', '--test') === true;\n}\n// #endregion\n\n// #region TooltipPlugin\n/**\n * Tooltip Plugin for tbw-grid\n *\n * Shows styled popover tooltips when header or cell text overflows its\n * container. Uses the Popover API with CSS anchor positioning for\n * consistent themed appearance across light and dark modes.\n *\n * ## Installation\n *\n * ```ts\n * import { TooltipPlugin } from '@toolbox-web/grid/plugins/tooltip';\n * ```\n *\n * @example Default — auto-tooltip on overflow\n * ```ts\n * grid.gridConfig = {\n * plugins: [new TooltipPlugin()],\n * };\n * ```\n *\n * @example Header-only tooltips\n * ```ts\n * grid.gridConfig = {\n * plugins: [new TooltipPlugin({ cell: false })],\n * };\n * ```\n *\n * @example Per-column overrides\n * ```ts\n * grid.gridConfig = {\n * columns: [\n * { field: 'name', cellTooltip: (ctx) => `${ctx.row.first} ${ctx.row.last}` },\n * { field: 'actions', cellTooltip: false },\n * { field: 'revenue', headerTooltip: 'Total revenue in USD (before tax)' },\n * ],\n * plugins: [new TooltipPlugin()],\n * };\n * ```\n *\n * @category Plugins\n */\nexport class TooltipPlugin extends BaseGridPlugin<TooltipConfig> {\n readonly name = 'tooltip';\n override readonly styles = tooltipStyles;\n\n static override readonly manifest: PluginManifest<TooltipConfig> = {\n ownedProperties: [\n { property: 'cellTooltip', level: 'column', description: 'the \"cellTooltip\" column property' },\n { property: 'headerTooltip', level: 'column', description: 'the \"headerTooltip\" column property' },\n ],\n configRules: [],\n };\n\n /** The shared popover element for all tooltips. */\n #popoverEl: HTMLElement | null = null;\n\n /** The cell currently acting as CSS anchor. */\n #anchorCell: HTMLElement | null = null;\n\n /** Whether delegated listeners are bound. */\n #bound = false;\n\n /** Whether header tooltips are enabled globally. */\n get #headerEnabled(): boolean {\n return this.config.header !== false;\n }\n\n /** Whether cell tooltips are enabled globally. */\n get #cellEnabled(): boolean {\n return this.config.cell !== false;\n }\n\n override attach(grid: GridElement): void {\n super.attach(grid);\n }\n\n override detach(): void {\n this.#hideTooltip();\n this.#popoverEl?.remove();\n this.#popoverEl = null;\n this.#bound = false;\n super.detach();\n }\n\n override afterRender(): void {\n this.#ensurePopover();\n this.#bindEvents();\n }\n\n // #region Popover Lifecycle\n\n /** Create the shared popover element (once). */\n #ensurePopover(): void {\n if (this.#popoverEl) return;\n const el = document.createElement('div');\n el.className = 'tbw-tooltip-popover';\n el.setAttribute('popover', 'hint');\n // Override UA popover defaults that @layer CSS cannot beat\n el.style.overflow = 'visible';\n el.style.margin = '0';\n document.body.appendChild(el);\n this.#popoverEl = el;\n }\n\n /** Show the popover anchored to `cell` with the given `text`. */\n #showTooltip(cell: HTMLElement, text: string): void {\n if (!this.#popoverEl) return;\n\n // Move the CSS anchor to the hovered cell\n this.#clearAnchor();\n cell.style.setProperty('anchor-name', '--tbw-tooltip-anchor');\n this.#anchorCell = cell;\n\n // Set content (always textContent — safe, no XSS)\n this.#popoverEl.textContent = text;\n\n // Show via Popover API\n if (supportsPopover()) {\n try {\n this.#popoverEl.showPopover();\n } catch {\n /* already shown */\n }\n }\n\n if (supportsAnchor()) {\n // Detect flip after the browser resolves position-try-fallbacks\n requestAnimationFrame(() => this.#detectFlip(cell));\n } else {\n this.#positionFallback(cell);\n }\n }\n\n /** Hide the popover and clear the anchor reference. */\n #hideTooltip(): void {\n if (this.#popoverEl) {\n if (supportsPopover()) {\n try {\n this.#popoverEl.hidePopover();\n } catch {\n /* already hidden */\n }\n }\n this.#popoverEl.classList.remove('tbw-tooltip-above');\n }\n this.#clearAnchor();\n }\n\n /** Remove the CSS anchor-name from the previous cell, but only if it's still our tooltip anchor. */\n #clearAnchor(): void {\n if (this.#anchorCell) {\n if (this.#anchorCell.style.getPropertyValue('anchor-name') === '--tbw-tooltip-anchor') {\n this.#anchorCell.style.removeProperty('anchor-name');\n }\n this.#anchorCell = null;\n }\n }\n\n /**\n * Fallback positioning for browsers without CSS anchor support.\n * Places the popover below or above the cell using fixed coordinates.\n */\n #positionFallback(cell: HTMLElement): void {\n if (!this.#popoverEl) return;\n const cellRect = cell.getBoundingClientRect();\n const arrowGap = 11;\n\n this.#popoverEl.style.position = 'fixed';\n this.#popoverEl.style.left = `${cellRect.left}px`;\n\n // Check if there's space below\n const spaceBelow = window.innerHeight - cellRect.bottom;\n if (spaceBelow < 80) {\n // Place above the cell\n this.#popoverEl.style.top = '';\n this.#popoverEl.style.bottom = `${window.innerHeight - cellRect.top + arrowGap}px`;\n this.#popoverEl.classList.add('tbw-tooltip-above');\n } else {\n this.#popoverEl.style.top = `${cellRect.bottom + arrowGap}px`;\n this.#popoverEl.style.bottom = '';\n this.#popoverEl.classList.remove('tbw-tooltip-above');\n }\n }\n\n /** Toggle the arrow direction class after CSS anchor positioning resolves. */\n #detectFlip(cell: HTMLElement): void {\n if (!this.#popoverEl) return;\n const cellRect = cell.getBoundingClientRect();\n const popoverRect = this.#popoverEl.getBoundingClientRect();\n // If the popover's bottom edge is above the cell's top, it flipped\n this.#popoverEl.classList.toggle('tbw-tooltip-above', popoverRect.bottom <= cellRect.top);\n }\n // #endregion\n\n // #region Event Delegation\n\n /** Bind delegated mouseover/mouseout once. */\n #bindEvents(): void {\n if (this.#bound) return;\n const container = this.gridElement?.querySelector('.tbw-grid-root');\n if (!container) return;\n\n this.#bound = true;\n\n container.addEventListener('mouseover', (e: Event) => this.#onMouseOver(e as MouseEvent), {\n signal: this.disconnectSignal,\n });\n\n container.addEventListener('mouseout', (e: Event) => this.#onMouseOut(e as MouseEvent), {\n signal: this.disconnectSignal,\n });\n }\n\n #onMouseOver(e: MouseEvent): void {\n const target = e.target as HTMLElement;\n if (!target?.closest) return;\n\n // Check for header cell\n const headerCell = target.closest('[part~=\"header-cell\"]') as HTMLElement | null;\n if (headerCell && this.#headerEnabled) {\n this.#showHeaderTooltip(headerCell);\n return;\n }\n\n // Check for data cell — skip cells that already have a CSS anchor (e.g. overlay editors)\n // to avoid overwriting their anchor-name and breaking their positioning.\n const dataCell = target.closest('[data-row][data-col]') as HTMLElement | null;\n if (dataCell && this.#cellEnabled && !dataCell.style.getPropertyValue('anchor-name')) {\n this.#showCellTooltip(dataCell);\n }\n }\n\n #onMouseOut(e: MouseEvent): void {\n const target = e.target as HTMLElement;\n if (!target?.closest) return;\n\n const cell = target.closest('[part~=\"header-cell\"], [data-row][data-col]') as HTMLElement | null;\n if (!cell) return;\n\n // Keep tooltip if pointer moved to a child still inside the same cell\n const related = e.relatedTarget as HTMLElement | null;\n if (related && cell.contains(related)) return;\n\n this.#hideTooltip();\n }\n // #endregion\n\n // #region Tooltip Resolution\n\n #showHeaderTooltip(headerCell: HTMLElement): void {\n const colIndex = parseInt(headerCell.getAttribute('data-col') ?? '-1', 10);\n if (colIndex < 0) return;\n\n const column = this.visibleColumns[colIndex];\n if (!column) return;\n\n const text = resolveHeaderTooltip(column, headerCell);\n if (text) {\n this.#showTooltip(headerCell, text);\n }\n }\n\n #showCellTooltip(cell: HTMLElement): void {\n const rowIndex = parseInt(cell.getAttribute('data-row') ?? '-1', 10);\n const colIndex = parseInt(cell.getAttribute('data-col') ?? '-1', 10);\n if (rowIndex < 0 || colIndex < 0) return;\n\n const column = this.visibleColumns[colIndex];\n if (!column) return;\n\n const row = this.rows[rowIndex];\n const value = row?.[column.field as keyof typeof row];\n\n const text = resolveCellTooltip(column, cell, row, value);\n if (text) {\n this.#showTooltip(cell, text);\n }\n }\n // #endregion\n}\n// #endregion\n"],"names":["isOverflowing","el","scrollWidth","clientWidth","supportsPopover","HTMLElement","prototype","showPopover","TooltipPlugin","BaseGridPlugin","name","styles","static","ownedProperties","property","level","description","configRules","popoverEl","anchorCell","bound","headerEnabled","this","config","header","cellEnabled","cell","attach","grid","super","detach","hideTooltip","remove","afterRender","ensurePopover","bindEvents","document","createElement","className","setAttribute","style","overflow","margin","body","appendChild","showTooltip","text","clearAnchor","setProperty","textContent","CSS","supports","requestAnimationFrame","detectFlip","positionFallback","hidePopover","classList","getPropertyValue","removeProperty","cellRect","getBoundingClientRect","position","left","window","innerHeight","bottom","top","add","popoverRect","toggle","container","gridElement","querySelector","addEventListener","e","onMouseOver","signal","disconnectSignal","onMouseOut","target","closest","headerCell","showHeaderTooltip","dataCell","showCellTooltip","related","relatedTarget","contains","colIndex","parseInt","getAttribute","column","visibleColumns","spec","headerTooltip","value","field","trim","resolveHeaderTooltip","rowIndex","row","rows","cellTooltip","resolveCellTooltip"],"mappings":"iVAoBA,SAASA,EAAcC,GACrB,OAAOA,EAAGC,YAAcD,EAAGE,WAC7B,CAqDA,SAASC,IACP,MAAqD,mBAAvCC,YAAYC,WAAWC,WACvC,CAkDO,MAAMC,UAAsBC,EAAAA,eACxBC,KAAO,UACEC,yzDAElBC,gBAAmE,CACjEC,gBAAiB,CACf,CAAEC,SAAU,cAAeC,MAAO,SAAUC,YAAa,qCACzD,CAAEF,SAAU,gBAAiBC,MAAO,SAAUC,YAAa,wCAE7DC,YAAa,IAIfC,GAAiC,KAGjCC,GAAkC,KAGlCC,IAAS,EAGT,KAAIC,GACF,OAA8B,IAAvBC,KAAKC,OAAOC,MACrB,CAGA,KAAIC,GACF,OAA4B,IAArBH,KAAKC,OAAOG,IACrB,CAES,MAAAC,CAAOC,GACdC,MAAMF,OAAOC,EACf,CAES,MAAAE,GACPR,MAAKS,IACLT,MAAKJ,GAAYc,SACjBV,MAAKJ,EAAa,KAClBI,MAAKF,GAAS,EACdS,MAAMC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KuB,EAAanB,EAAMoB,EAE5B"}
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("../../core/constants"),require("../../core/plugin/base-plugin")):"function"==typeof define&&define.amd?define(["exports","../../core/constants","../../core/plugin/base-plugin"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGridPlugin_tree={},e.TbwGrid,e.TbwGrid)}(this,function(e,t,n){"use strict";function i(e,t,n){return void 0!==e.id?String(e.id):n?`${n}-${t}`:String(t)}function r(e,t){const n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function s(e,t,n=null,r=0){const a=t.childrenField??"children",d=new Set;for(let o=0;o<e.length;o++){const l=e[o],h=i(l,o,n),c=l[a];if(Array.isArray(c)&&c.length>0){d.add(h);const e=s(c,t,h,r+1);for(const t of e)d.add(t)}}return d}function a(e,t,n,r=null,s=0){const d=n.childrenField??"children";for(let o=0;o<e.length;o++){const l=e[o],h=i(l,o,r);if(h===t)return[h];const c=l[d];if(Array.isArray(c)&&c.length>0){const e=a(c,t,n,h,s+1);if(e)return[h,...e]}}return null}function d(e,t,n,i){const r=a(e,t,n);if(!r)return i;const s=new Set(i);for(let a=0;a<r.length-1;a++)s.add(r[a]);return s}function o(e,t="children"){if(!Array.isArray(e)||0===e.length)return!1;for(const n of e){if(!n)continue;const e=n[t];if(Array.isArray(e)&&e.length>0)return!0}return!1}class l extends n.BaseGridPlugin{static manifest={incompatibleWith:[{name:"groupingRows",reason:"Both plugins transform the entire row model. TreePlugin flattens nested hierarchies while GroupingRowsPlugin groups flat rows with synthetic headers. Use one approach per grid."},{name:"pivot",reason:"PivotPlugin replaces the entire row and column structure with aggregated pivot data. Tree hierarchy cannot coexist with pivot aggregation."},{name:"serverSide",reason:"TreePlugin requires the full hierarchy to flatten and manage expansion state. ServerSidePlugin lazy-loads rows in blocks and cannot provide nested children on demand."}],events:[{type:"tree-state-change",description:"Emitted when tree expansion state changes (toggle, expand all, collapse all)"}],queries:[{type:"canMoveRow",description:"Returns false for rows with children (parent nodes cannot be reordered)"}]};name="tree";styles="@layer tbw-plugins{tbw-grid .cell[data-field=__tbw_expander]{border-inline-end:none!important;padding:0;display:flex;align-items:center;justify-content:flex-start}tbw-grid .header-row .cell[data-field=__tbw_expander]{display:none}tbw-grid .header-row .cell[data-field=__tbw_expander]+.cell{grid-column:1 / 3}tbw-grid .tree-cell-wrapper{display:inline-flex;align-items:center;padding-inline-start:calc(var(--tbw-tree-depth, 0) * var(--tbw-tree-indent-width, var(--tbw-tree-toggle-size, 1.25em)))}tbw-grid .tree-expander{display:flex;align-items:center;justify-content:flex-start;width:100%;height:100%;box-sizing:border-box}tbw-grid .tree-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-tree-toggle-size, 1.25em);height:var(--tbw-tree-toggle-size, 1.25em);flex-shrink:0}tbw-grid .tree-toggle:hover{color:var(--tbw-tree-accent, var(--tbw-color-accent))}tbw-grid .tree-spacer{width:var(--tbw-tree-toggle-size, 1.25em);display:inline-block;flex-shrink:0}tbw-grid .data-grid-row.tbw-tree-slide-in{animation:tbw-tree-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}tbw-grid .data-grid-row.tbw-tree-fade-in{animation:tbw-tree-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-tree-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}@keyframes tbw-tree-fade-in{0%{opacity:0}to{opacity:1}}}";get defaultConfig(){return{childrenField:"children",autoDetect:!0,defaultExpanded:!1,indentWidth:20,showExpandIcons:!0,animation:"slide"}}expandedKeys=new Set;initialExpansionDone=!1;flattenedRows=[];rowKeyMap=new Map;previousVisibleKeys=new Set;keysToAnimate=new Set;sortState=null;detach(){this.expandedKeys.clear(),this.initialExpansionDone=!1,this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.sortState=null}handleQuery(e){if("canMoveRow"===e.type){const t=e.context,n=this.config.childrenField??"children",i=t?.[n];if(Array.isArray(i)&&i.length>0)return!1}}get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}detect(e){if(!this.config.autoDetect)return!1;const t=e,n=this.config.childrenField??function(e){if(!Array.isArray(e)||0===e.length)return null;const t=["children","items","nodes","subRows","nested"];for(const n of e)if(n&&"object"==typeof n)for(const e of t){const t=n[e];if(Array.isArray(t)&&t.length>0)return e}return null}(t)??"children";return o(t,n)}processRows(e){const t=e;if(!o(t,this.config.childrenField??"children"))return this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),[...e];let n=this.withStableKeys(t);this.sortState&&(n=this.sortTree(n,this.sortState.field,this.sortState.direction)),this.config.defaultExpanded&&!this.initialExpansionDone&&(this.expandedKeys=s(n,this.config),this.initialExpansionDone=!0),this.flattenedRows=this.flattenTree(n,this.expandedKeys),this.rowKeyMap.clear(),this.keysToAnimate.clear();const i=new Set;for(const r of this.flattenedRows)this.rowKeyMap.set(r.key,r),i.add(r.key),!this.previousVisibleKeys.has(r.key)&&r.depth>0&&this.keysToAnimate.add(r.key);return this.previousVisibleKeys=i,this.flattenedRows.map(e=>({...e.data,__treeKey:e.key,__treeDepth:e.depth,__treeHasChildren:e.hasChildren,__treeExpanded:e.isExpanded}))}withStableKeys(e,t=null){const n=this.config.childrenField??"children";return e.map((e,i)=>{const r=e.__stableKey,s=void 0!==e.id?String(e.id):r??(t?`${t}-${i}`:String(i)),a=e[n],d=Array.isArray(a)&&a.length>0;return{...e,__stableKey:s,...d?{[n]:this.withStableKeys(a,s)}:{}}})}flattenTree(e,t,n=0){const i=this.config.childrenField??"children",r=[];for(const s of e){const e=s.__stableKey??String(s.id??"?"),a=s[i],d=Array.isArray(a)&&a.length>0,o=t.has(e);r.push({key:e,data:s,depth:n,hasChildren:d,isExpanded:o,parentKey:n>0&&e.substring(0,e.lastIndexOf("-"))||null}),d&&o&&r.push(...this.flattenTree(a,t,n+1))}return r}sortTree(e,t,n){const i=this.config.childrenField??"children";return[...e].sort((e,i)=>{const r=e[t],s=i[t];return null==r&&null==s?0:null==r?-1:null==s?1:r>s?n:r<s?-n:0}).map(e=>{const r=e[i];return Array.isArray(r)&&r.length>0?{...e,[i]:this.sortTree(r,t,n)}:e})}processColumns(e){if(0===this.flattenedRows.length)return[...e];const n=[...e];if(0===n.length)return n;const i=n[0],r=i.viewRenderer,s=()=>this.config,a=this.setIcon.bind(this);return n[0]={...i,viewRenderer:e=>{const{row:n,value:i}=e,{showExpandIcons:d=!0,indentWidth:o}=s(),l=n,h=l.__treeDepth??0,c=document.createElement("span");if(c.className="tree-cell-wrapper",c.style.setProperty("--tbw-tree-depth",String(h)),void 0!==o&&c.style.setProperty("--tbw-tree-indent-width",`${o}px`),d)if(l.__treeHasChildren){const e=document.createElement("span");e.className=`${t.GridClasses.TREE_TOGGLE}${l.__treeExpanded?` ${t.GridClasses.EXPANDED}`:""}`,a(e,l.__treeExpanded?"collapse":"expand"),e.setAttribute("data-tree-key",String(l.__treeKey??"")),c.appendChild(e)}else{const e=document.createElement("span");e.className="tree-spacer",c.appendChild(e)}const p=document.createElement("span");if(p.className="tree-content",r){const t=r(e);t instanceof Node?p.appendChild(t):"string"==typeof t&&(p.innerHTML=t)}else p.textContent=null!=i?String(i):"";return c.appendChild(p),c}},n}onCellClick(e){const n=e.originalEvent?.target;if(!n?.classList.contains(t.GridClasses.TREE_TOGGLE))return!1;const i=n.getAttribute("data-tree-key");if(!i)return!1;const s=this.rowKeyMap.get(i);return!!s&&(this.expandedKeys=r(this.expandedKeys,i),this.emit("tree-expand",{key:i,row:s.data,expanded:this.expandedKeys.has(i),depth:s.depth}),this.requestRender(),!0)}onKeyDown(e){if(" "!==e.key)return;const t=this.grid._focusRow,n=this.flattenedRows[t];return n?.hasChildren?(e.preventDefault(),this.expandedKeys=r(this.expandedKeys,n.key),this.emit("tree-expand",{key:n.key,row:n.data,expanded:this.expandedKeys.has(n.key),depth:n.depth}),this.requestRenderWithFocus(),!0):void 0}onHeaderClick(e){if(0===this.flattenedRows.length||!e.column.sortable)return!1;const{field:t}=e.column;this.sortState&&this.sortState.field===t?1===this.sortState.direction?this.sortState={field:t,direction:-1}:this.sortState=null:this.sortState={field:t,direction:1};const n=this.grid;return void 0!==n._sortState&&(n._sortState=this.sortState?{...this.sortState}:null),this.emit("sort-change",{field:t,direction:this.sortState?.direction??0}),this.requestRender(),!0}afterRender(){const e=this.gridElement?.querySelector(".rows");if(!e)return;const t=this.animationStyle,n=!1!==t&&this.keysToAnimate.size>0,i="fade"===t?"tbw-tree-fade-in":"tbw-tree-slide-in";for(const r of e.querySelectorAll(".data-grid-row")){const e=r.querySelector(".cell[data-row]"),t=e?parseInt(e.getAttribute("data-row")??"-1",10):-1,s=this.flattenedRows[t];s?.hasChildren&&r.setAttribute("aria-expanded",String(s.isExpanded)),n&&s?.key&&this.keysToAnimate.has(s.key)&&(r.classList.add(i),r.addEventListener("animationend",()=>r.classList.remove(i),{once:!0}))}this.keysToAnimate.clear()}expand(e){this.expandedKeys.add(e),this.requestRender()}collapse(e){this.expandedKeys.delete(e),this.requestRender()}toggle(e){this.expandedKeys=r(this.expandedKeys,e),this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}expandAll(){this.expandedKeys=s(this.rows,this.config),this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}collapseAll(){this.expandedKeys=new Set,this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}getExpandedKeys(){return[...this.expandedKeys]}getFlattenedRows(){return[...this.flattenedRows]}getRowByKey(e){return this.rowKeyMap.get(e)?.data}expandToKey(e){this.expandedKeys=d(this.rows,e,this.config,this.expandedKeys),this.requestRender()}}e.TreePlugin=l,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("../../core/constants"),require("../../core/plugin/base-plugin")):"function"==typeof define&&define.amd?define(["exports","../../core/constants","../../core/plugin/base-plugin"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGridPlugin_tree={},e.TbwGrid,e.TbwGrid)}(this,function(e,t,n){"use strict";function i(e,t,n){return void 0!==e.id?String(e.id):n?`${n}-${t}`:String(t)}function r(e,t){const n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function s(e,t,n=null,r=0){const a=t.childrenField??"children",o=new Set;for(let d=0;d<e.length;d++){const l=e[d],c=i(l,d,n),h=l[a];if(Array.isArray(h)&&h.length>0){o.add(c);const e=s(h,t,c,r+1);for(const t of e)o.add(t)}}return o}function a(e,t,n,r=null,s=0){const o=n.childrenField??"children";for(let d=0;d<e.length;d++){const l=e[d],c=i(l,d,r);if(c===t)return[c];const h=l[o];if(Array.isArray(h)&&h.length>0){const e=a(h,t,n,c,s+1);if(e)return[c,...e]}}return null}function o(e,t,n,i){const r=a(e,t,n);if(!r)return i;const s=new Set(i);for(let a=0;a<r.length-1;a++)s.add(r[a]);return s}function d(e,t="children"){if(!Array.isArray(e)||0===e.length)return!1;for(const n of e){if(!n)continue;const e=n[t];if(Array.isArray(e)&&e.length>0)return!0}return!1}class l extends n.BaseGridPlugin{static manifest={modifiesRowStructure:!0,incompatibleWith:[{name:"groupingRows",reason:"Both plugins transform the entire row model. TreePlugin flattens nested hierarchies while GroupingRowsPlugin groups flat rows with synthetic headers. Use one approach per grid."},{name:"pivot",reason:"PivotPlugin replaces the entire row and column structure with aggregated pivot data. Tree hierarchy cannot coexist with pivot aggregation."},{name:"serverSide",reason:"TreePlugin requires the full hierarchy to flatten and manage expansion state. ServerSidePlugin lazy-loads rows in blocks and cannot provide nested children on demand."}],events:[{type:"tree-state-change",description:"Emitted when tree expansion state changes (toggle, expand all, collapse all)"}],queries:[{type:"canMoveRow",description:"Returns false for rows with children (parent nodes cannot be reordered)"}]};static dependencies=[{name:"multiSort",required:!1,reason:"Queries sort model for coordinated tree sorting"}];name="tree";styles="@layer tbw-plugins{tbw-grid .cell[data-field=__tbw_expander]{border-inline-end:none!important;padding:0;display:flex;align-items:center;justify-content:flex-start}tbw-grid .header-row .cell[data-field=__tbw_expander]{display:none}tbw-grid .header-row .cell[data-field=__tbw_expander]+.cell{grid-column:1 / 3}tbw-grid .tree-cell-wrapper{display:inline-flex;align-items:center;overflow:visible;padding-inline-start:calc(var(--tbw-tree-depth, 0) * var(--tbw-tree-indent-width, var(--tbw-tree-toggle-size, 1.25em)))}tbw-grid .tree-expander{display:flex;align-items:center;justify-content:flex-start;width:100%;height:100%;box-sizing:border-box}tbw-grid .tree-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-tree-toggle-size, 1.25em);height:var(--tbw-tree-toggle-size, 1.25em);flex-shrink:0}tbw-grid .tree-toggle:hover{color:var(--tbw-tree-accent, var(--tbw-color-accent))}tbw-grid .tree-spacer{width:var(--tbw-tree-toggle-size, 1.25em);display:inline-block;flex-shrink:0}tbw-grid .data-grid-row.tbw-tree-slide-in{animation:tbw-tree-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}tbw-grid .data-grid-row.tbw-tree-fade-in{animation:tbw-tree-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-tree-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}@keyframes tbw-tree-fade-in{0%{opacity:0}to{opacity:1}}}";get defaultConfig(){return{childrenField:"children",autoDetect:!0,defaultExpanded:!1,indentWidth:20,showExpandIcons:!0,animation:"slide"}}expandedKeys=new Set;initialExpansionDone=!1;flattenedRows=[];rowKeyMap=new Map;previousVisibleKeys=new Set;keysToAnimate=new Set;sortState=null;detach(){this.expandedKeys.clear(),this.initialExpansionDone=!1,this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),this.keysToAnimate.clear(),this.sortState=null}handleQuery(e){if("canMoveRow"===e.type){const t=e.context,n=this.config.childrenField??"children",i=t?.[n];if(Array.isArray(i)&&i.length>0)return!1}}get animationStyle(){return!!this.isAnimationEnabled&&(this.config.animation??"slide")}detect(e){if(!this.config.autoDetect)return!1;const t=e,n=this.config.childrenField??function(e){if(!Array.isArray(e)||0===e.length)return null;const t=["children","items","nodes","subRows","nested"];for(const n of e)if(n&&"object"==typeof n)for(const e of t){const t=n[e];if(Array.isArray(t)&&t.length>0)return e}return null}(t)??"children";return d(t,n)}processRows(e){const t=e;if(!d(t,this.config.childrenField??"children"))return this.flattenedRows=[],this.rowKeyMap.clear(),this.previousVisibleKeys.clear(),[...e];let n=this.withStableKeys(t);const i=this.resolveEffectiveSortState();i&&(n=this.sortTree(n,i.field,i.direction)),this.config.defaultExpanded&&!this.initialExpansionDone&&(this.expandedKeys=s(n,this.config),this.initialExpansionDone=!0),this.flattenedRows=this.flattenTree(n,this.expandedKeys),this.rowKeyMap.clear(),this.keysToAnimate.clear();const r=new Set;for(const s of this.flattenedRows)this.rowKeyMap.set(s.key,s),r.add(s.key),!this.previousVisibleKeys.has(s.key)&&s.depth>0&&this.keysToAnimate.add(s.key);return this.previousVisibleKeys=r,this.flattenedRows.map(e=>({...e.data,__treeKey:e.key,__treeDepth:e.depth,__treeHasChildren:e.hasChildren,__treeExpanded:e.isExpanded}))}withStableKeys(e,t=null){const n=this.config.childrenField??"children";return e.map((e,i)=>{const r=e.__stableKey,s=void 0!==e.id?String(e.id):r??(t?`${t}-${i}`:String(i)),a=e[n],o=Array.isArray(a)&&a.length>0;return{...e,__stableKey:s,...o?{[n]:this.withStableKeys(a,s)}:{}}})}flattenTree(e,t,n=0){const i=this.config.childrenField??"children",r=[];for(const s of e){const e=s.__stableKey??String(s.id??"?"),a=s[i],o=Array.isArray(a)&&a.length>0,d=t.has(e);r.push({key:e,data:s,depth:n,hasChildren:o,isExpanded:d,parentKey:n>0&&e.substring(0,e.lastIndexOf("-"))||null}),o&&d&&r.push(...this.flattenTree(a,t,n+1))}return r}resolveEffectiveSortState(){const e=this.grid?.query?.("sort:get-model",null);if(Array.isArray(e)&&e.length>0){const t=e[0];if(Array.isArray(t)&&t.length>0)return{field:t[0].field,direction:"desc"===t[0].direction?-1:1}}return this.sortState}sortTree(e,t,n){const i=this.config.childrenField??"children";return[...e].sort((e,i)=>{const r=e[t],s=i[t];return null==r&&null==s?0:null==r?-1:null==s?1:r>s?n:r<s?-n:0}).map(e=>{const r=e[i];return Array.isArray(r)&&r.length>0?{...e,[i]:this.sortTree(r,t,n)}:e})}processColumns(e){if(0===this.flattenedRows.length)return[...e];const n=[...e];if(0===n.length)return n;const{treeColumn:i}=this.config;let r=0;if(i){const e=n.findIndex(e=>e.field===i);e>=0&&(r=e)}const s=n[r],a=s.viewRenderer,o=()=>this.config,d=this.setIcon.bind(this);return n[r]={...s,viewRenderer:e=>{const{row:n,value:i}=e,{showExpandIcons:r=!0,indentWidth:s}=o(),l=n,c=l.__treeDepth??0,h=document.createElement("span");if(h.className="tree-cell-wrapper",h.style.setProperty("--tbw-tree-depth",String(c)),void 0!==s&&h.style.setProperty("--tbw-tree-indent-width",`${s}px`),r)if(l.__treeHasChildren){const e=document.createElement("span");e.className=`${t.GridClasses.TREE_TOGGLE}${l.__treeExpanded?` ${t.GridClasses.EXPANDED}`:""}`,d(e,l.__treeExpanded?"collapse":"expand"),e.setAttribute("data-tree-key",String(l.__treeKey??"")),h.appendChild(e)}else{const e=document.createElement("span");e.className="tree-spacer",h.appendChild(e)}const u=document.createElement("span");if(u.className="tree-content",a){const t=a(e);t instanceof Node?u.appendChild(t):"string"==typeof t&&(u.innerHTML=t)}else u.textContent=null!=i?String(i):"";return h.appendChild(u),h}},n}onCellClick(e){const n=e.originalEvent?.target;if(!n?.classList.contains(t.GridClasses.TREE_TOGGLE))return!1;const i=n.getAttribute("data-tree-key");if(!i)return!1;const s=this.rowKeyMap.get(i);return!!s&&(this.expandedKeys=r(this.expandedKeys,i),this.emit("tree-expand",{key:i,row:s.data,expanded:this.expandedKeys.has(i),depth:s.depth}),this.requestRender(),!0)}onKeyDown(e){if(" "!==e.key)return;const t=this.grid._focusRow,n=this.flattenedRows[t];return n?.hasChildren?(e.preventDefault(),this.expandedKeys=r(this.expandedKeys,n.key),this.emit("tree-expand",{key:n.key,row:n.data,expanded:this.expandedKeys.has(n.key),depth:n.depth}),this.requestRenderWithFocus(),!0):void 0}onHeaderClick(e){if(0===this.flattenedRows.length||!e.column.sortable)return!1;const t=this.grid?.query?.("sort:get-model",null);if(Array.isArray(t)&&t.length>0)return!1;const{field:n}=e.column;this.sortState&&this.sortState.field===n?1===this.sortState.direction?this.sortState={field:n,direction:-1}:this.sortState=null:this.sortState={field:n,direction:1};const i=this.grid;return void 0!==i._sortState&&(i._sortState=this.sortState?{...this.sortState}:null),this.broadcast("sort-change",{field:n,direction:this.sortState?.direction??0}),this.requestRender(),!0}afterRender(){const e=this.gridElement?.querySelector(".rows");if(!e)return;const t=this.animationStyle,n=!1!==t&&this.keysToAnimate.size>0,i="fade"===t?"tbw-tree-fade-in":"tbw-tree-slide-in";for(const r of e.querySelectorAll(".data-grid-row")){const e=r.querySelector(".cell[data-row]"),t=e?parseInt(e.getAttribute("data-row")??"-1",10):-1,s=this.flattenedRows[t];s?.hasChildren&&r.setAttribute("aria-expanded",String(s.isExpanded)),n&&s?.key&&this.keysToAnimate.has(s.key)&&(r.classList.add(i),r.addEventListener("animationend",()=>r.classList.remove(i),{once:!0}))}this.keysToAnimate.clear()}expand(e){this.expandedKeys.add(e),this.requestRender()}collapse(e){this.expandedKeys.delete(e),this.requestRender()}toggle(e){this.expandedKeys=r(this.expandedKeys,e),this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}expandAll(){this.expandedKeys=s(this.rows,this.config),this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}collapseAll(){this.expandedKeys=new Set,this.emitPluginEvent("tree-state-change",{expandedKeys:[...this.expandedKeys]}),this.requestRender()}isExpanded(e){return this.expandedKeys.has(e)}getExpandedKeys(){return[...this.expandedKeys]}getFlattenedRows(){return[...this.flattenedRows]}getRowByKey(e){return this.rowKeyMap.get(e)?.data}expandToKey(e){this.expandedKeys=o(this.rows,e,this.config,this.expandedKeys),this.requestRender()}}e.TreePlugin=l,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
2
2
  //# sourceMappingURL=tree.umd.js.map
@@ -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\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 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 a non-empty children array\n for (const row of rows) {\n if (!row) continue;\n const children = row[childrenField];\n if (Array.isArray(children) && children.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: 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 {\n BaseGridPlugin,\n CellClickEvent,\n HeaderClickEvent,\n type PluginManifest,\n type PluginQuery,\n} from '../../core/plugin/base-plugin';\nimport type { ColumnConfig, ColumnViewRenderer, GridHost } from '../../core/types';\nimport { collapseAll, expandAll, expandToKey, toggleExpand } from './tree-data';\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 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 name: 'serverSide',\n reason:\n 'TreePlugin requires the full hierarchy to flatten and manage expansion state. ' +\n 'ServerSidePlugin lazy-loads rows in blocks and cannot provide nested children on demand.',\n },\n ],\n events: [\n {\n type: 'tree-state-change',\n description: 'Emitted when tree expansion state changes (toggle, expand all, collapse all)',\n },\n ],\n queries: [\n {\n type: 'canMoveRow',\n description: 'Returns false for rows with children (parent nodes cannot be reordered)',\n },\n ],\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\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 }\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 return undefined;\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 const treeRows = rows as readonly TreeRow[];\n\n if (!detectTreeStructure(treeRows, childrenField)) {\n this.flattenedRows = [];\n this.rowKeyMap.clear();\n this.previousVisibleKeys.clear();\n return [...rows] as TreeRow[];\n }\n\n // Assign stable keys, then optionally sort\n let data = this.withStableKeys(treeRows);\n if (this.sortState) {\n data = this.sortTree(data, this.sortState.field, this.sortState.direction);\n }\n\n // Initialize expansion if needed\n if (this.config.defaultExpanded && !this.initialExpansionDone) {\n this.expandedKeys = expandAll(data, this.config);\n this.initialExpansionDone = true;\n }\n\n // Flatten and track animations\n this.flattenedRows = this.flattenTree(data, this.expandedKeys);\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 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 this.flattenedRows.map((r) => ({\n ...r.data,\n __treeKey: r.key,\n __treeDepth: r.depth,\n __treeHasChildren: r.hasChildren,\n __treeExpanded: r.isExpanded,\n }));\n }\n\n /** Assign stable keys to rows (preserves key across sort operations) */\n private withStableKeys(rows: readonly TreeRow[], parentKey: string | null = null): TreeRow[] {\n const childrenField = this.config.childrenField ?? 'children';\n return rows.map((row, i) => {\n const stableKey = row.__stableKey as string | undefined;\n const key = row.id !== undefined ? String(row.id) : (stableKey ?? (parentKey ? `${parentKey}-${i}` : String(i)));\n const children = row[childrenField];\n const hasChildren = Array.isArray(children) && children.length > 0;\n return {\n ...row,\n __stableKey: key,\n ...(hasChildren ? { [childrenField]: this.withStableKeys(children as TreeRow[], key) } : {}),\n };\n });\n }\n\n /** Flatten tree using stable keys */\n private flattenTree(rows: readonly TreeRow[], expanded: Set<string>, depth = 0): FlattenedTreeRow[] {\n const childrenField = this.config.childrenField ?? 'children';\n const result: FlattenedTreeRow[] = [];\n\n for (const row of rows) {\n const stableKey = row.__stableKey as string | undefined;\n const key = stableKey ?? String(row.id ?? '?');\n const children = row[childrenField];\n const hasChildren = Array.isArray(children) && children.length > 0;\n const isExpanded = expanded.has(key);\n\n result.push({\n key,\n data: row,\n depth,\n hasChildren,\n isExpanded,\n parentKey: depth > 0 ? key.substring(0, key.lastIndexOf('-')) || null : null,\n });\n\n if (hasChildren && isExpanded) {\n result.push(...this.flattenTree(children as TreeRow[], expanded, depth + 1));\n }\n }\n return result;\n }\n\n /** Sort tree recursively, keeping children with parents */\n private sortTree(rows: readonly TreeRow[], field: string, dir: 1 | -1): TreeRow[] {\n const childrenField = this.config.childrenField ?? 'children';\n const sorted = [...rows].sort((a, b) => {\n const aVal = a[field],\n bVal = b[field];\n if (aVal == null && bVal == null) return 0;\n if (aVal == null) return -1;\n if (bVal == null) return 1;\n return aVal > bVal ? dir : aVal < bVal ? -dir : 0;\n });\n return sorted.map((row) => {\n const children = row[childrenField];\n return Array.isArray(children) && children.length > 0\n ? { ...row, [childrenField]: this.sortTree(children as TreeRow[], field, dir) }\n : row;\n });\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 // Wrap the first column's renderer to add tree indentation and expand icons\n // This is the correct approach for trees because:\n // 1. Indentation can grow naturally with depth\n // 2. Expand icons appear inline with content\n // 3. Works with column reordering (icons stay with first visible column)\n const firstCol = cols[0];\n const originalRenderer = firstCol.viewRenderer;\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 treeRow = row as TreeRow;\n const depth = treeRow.__treeDepth ?? 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 (treeRow.__treeHasChildren) {\n const icon = document.createElement('span');\n icon.className = `${GridClasses.TREE_TOGGLE}${treeRow.__treeExpanded ? ` ${GridClasses.EXPANDED}` : ''}`;\n setIconFn(icon, treeRow.__treeExpanded ? 'collapse' : 'expand');\n icon.setAttribute('data-tree-key', String(treeRow.__treeKey ?? ''));\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[0] = { ...firstCol, 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 this.emit<TreeExpandDetail>('tree-expand', {\n key,\n row: flatRow.data,\n expanded: this.expandedKeys.has(key),\n depth: flatRow.depth,\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 this.emit<TreeExpandDetail>('tree-expand', {\n key: flatRow.key,\n row: flatRow.data,\n expanded: this.expandedKeys.has(flatRow.key),\n depth: flatRow.depth,\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 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.emit('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 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-state-change` plugin event with the updated expanded keys.\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 this.emitPluginEvent('tree-state-change', { expandedKeys: [...this.expandedKeys] });\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-state-change` 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-state-change', { 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-state-change` 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-state-change', { 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 * 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","detectTreeStructure","TreePlugin","BaseGridPlugin","static","incompatibleWith","name","reason","events","type","description","queries","styles","defaultConfig","autoDetect","defaultExpanded","indentWidth","showExpandIcons","animation","initialExpansionDone","flattenedRows","rowKeyMap","Map","previousVisibleKeys","keysToAnimate","sortState","detach","this","clear","handleQuery","query","context","animationStyle","isAnimationEnabled","detect","treeRows","field","commonArrayFields","value","inferChildrenField","processRows","data","withStableKeys","sortTree","direction","flattenTree","currentKeys","set","map","r","__treeKey","__treeDepth","__treeHasChildren","hasChildren","__treeExpanded","isExpanded","stableKey","__stableKey","expanded","result","push","substring","lastIndexOf","dir","sort","a","b","aVal","bVal","processColumns","columns","cols","firstCol","originalRenderer","viewRenderer","getConfig","setIconFn","setIcon","bind","ctx","treeRow","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","flatRow","get","emit","requestRender","onKeyDown","focusRow","grid","_focusRow","preventDefault","requestRenderWithFocus","onHeaderClick","column","sortable","gridEl","_sortState","afterRender","body","gridElement","querySelector","shouldAnimate","size","animClass","rowEl","querySelectorAll","cell","idx","parseInt","addEventListener","remove","once","expand","collapse","toggle","emitPluginEvent","collapseAll","getExpandedKeys","getFlattenedRows","getRowByKey"],"mappings":"iZAYO,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,EAAGA,EAAIL,EAAKM,OAAQ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E5F,CACA3G,KAAKH,cAAcI,OACrB,CAqBA,MAAA2G,CAAO/J,GACLmD,KAAKpD,aAAaM,IAAIL,GACtBmD,KAAKiF,eACP,CAgBA,QAAA4B,CAAShK,GACPmD,KAAKpD,aAAaK,OAAOJ,GACzBmD,KAAKiF,eACP,CAgBA,MAAA6B,CAAOjK,GACLmD,KAAKpD,aAAeD,EAAaqD,KAAKpD,aAAcC,GACpDmD,KAAK+G,gBAAgB,oBAAqB,CAAEnK,aAAc,IAAIoD,KAAKpD,gBACnEoD,KAAKiF,eACP,CAcA,SAAA9H,GACE6C,KAAKpD,aAAeO,EAAU6C,KAAK5C,KAAmB4C,KAAK3C,QAC3D2C,KAAK+G,gBAAgB,oBAAqB,CAAEnK,aAAc,IAAIoD,KAAKpD,gBACnEoD,KAAKiF,eACP,CAcA,WAAA+B,GACEhH,KAAKpD,iBFrdIG,IEsdTiD,KAAK+G,gBAAgB,oBAAqB,CAAEnK,aAAc,IAAIoD,KAAKpD,gBACnEoD,KAAKiF,eACP,CAQA,UAAArD,CAAW/E,GACT,OAAOmD,KAAKpD,aAAaI,IAAIH,EAC/B,CAgBA,eAAAoK,GACE,MAAO,IAAIjH,KAAKpD,aAClB,CAUA,gBAAAsK,GACE,MAAO,IAAIlH,KAAKP,cAClB,CAQA,WAAA0H,CAAYtK,GACV,OAAOmD,KAAKN,UAAUqF,IAAIlI,IAAMiE,IAClC,CAiBA,WAAA3C,CAAYtB,GACVmD,KAAKpD,aAAeuB,EAAY6B,KAAK5C,KAAmBP,EAAKmD,KAAK3C,OAAQ2C,KAAKpD,cAC/EoD,KAAKiF,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-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 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 a non-empty children array\n for (const row of rows) {\n if (!row) continue;\n const children = row[childrenField];\n if (Array.isArray(children) && children.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: 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 {\n BaseGridPlugin,\n CellClickEvent,\n HeaderClickEvent,\n type PluginManifest,\n type PluginQuery,\n} from '../../core/plugin/base-plugin';\nimport type { ColumnConfig, ColumnViewRenderer, GridHost } from '../../core/types';\nimport { collapseAll, expandAll, expandToKey, toggleExpand } from './tree-data';\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 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 name: 'serverSide',\n reason:\n 'TreePlugin requires the full hierarchy to flatten and manage expansion state. ' +\n 'ServerSidePlugin lazy-loads rows in blocks and cannot provide nested children on demand.',\n },\n ],\n events: [\n {\n type: 'tree-state-change',\n description: 'Emitted when tree expansion state changes (toggle, expand all, collapse all)',\n },\n ],\n queries: [\n {\n type: 'canMoveRow',\n description: 'Returns false for rows with children (parent nodes cannot be reordered)',\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 ];\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\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 }\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 return undefined;\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 const treeRows = rows as readonly TreeRow[];\n\n if (!detectTreeStructure(treeRows, childrenField)) {\n this.flattenedRows = [];\n this.rowKeyMap.clear();\n this.previousVisibleKeys.clear();\n return [...rows] as TreeRow[];\n }\n\n // Assign stable keys, then optionally sort.\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 let data = this.withStableKeys(treeRows);\n const effectiveSortState = this.resolveEffectiveSortState();\n if (effectiveSortState) {\n data = this.sortTree(data, effectiveSortState.field, effectiveSortState.direction);\n }\n\n // Initialize expansion if needed\n if (this.config.defaultExpanded && !this.initialExpansionDone) {\n this.expandedKeys = expandAll(data, this.config);\n this.initialExpansionDone = true;\n }\n\n // Flatten and track animations\n this.flattenedRows = this.flattenTree(data, this.expandedKeys);\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 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 this.flattenedRows.map((r) => ({\n ...r.data,\n __treeKey: r.key,\n __treeDepth: r.depth,\n __treeHasChildren: r.hasChildren,\n __treeExpanded: r.isExpanded,\n }));\n }\n\n /** Assign stable keys to rows (preserves key across sort operations) */\n private withStableKeys(rows: readonly TreeRow[], parentKey: string | null = null): TreeRow[] {\n const childrenField = this.config.childrenField ?? 'children';\n return rows.map((row, i) => {\n const stableKey = row.__stableKey as string | undefined;\n const key = row.id !== undefined ? String(row.id) : (stableKey ?? (parentKey ? `${parentKey}-${i}` : String(i)));\n const children = row[childrenField];\n const hasChildren = Array.isArray(children) && children.length > 0;\n return {\n ...row,\n __stableKey: key,\n ...(hasChildren ? { [childrenField]: this.withStableKeys(children as TreeRow[], key) } : {}),\n };\n });\n }\n\n /** Flatten tree using stable keys */\n private flattenTree(rows: readonly TreeRow[], expanded: Set<string>, depth = 0): FlattenedTreeRow[] {\n const childrenField = this.config.childrenField ?? 'children';\n const result: FlattenedTreeRow[] = [];\n\n for (const row of rows) {\n const stableKey = row.__stableKey as string | undefined;\n const key = stableKey ?? String(row.id ?? '?');\n const children = row[childrenField];\n const hasChildren = Array.isArray(children) && children.length > 0;\n const isExpanded = expanded.has(key);\n\n result.push({\n key,\n data: row,\n depth,\n hasChildren,\n isExpanded,\n parentKey: depth > 0 ? key.substring(0, key.lastIndexOf('-')) || null : null,\n });\n\n if (hasChildren && isExpanded) {\n result.push(...this.flattenTree(children as TreeRow[], expanded, depth + 1));\n }\n }\n return result;\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 /** Sort tree recursively, keeping children with parents */\n private sortTree(rows: readonly TreeRow[], field: string, dir: 1 | -1): TreeRow[] {\n const childrenField = this.config.childrenField ?? 'children';\n const sorted = [...rows].sort((a, b) => {\n const aVal = a[field],\n bVal = b[field];\n if (aVal == null && bVal == null) return 0;\n if (aVal == null) return -1;\n if (bVal == null) return 1;\n return aVal > bVal ? dir : aVal < bVal ? -dir : 0;\n });\n return sorted.map((row) => {\n const children = row[childrenField];\n return Array.isArray(children) && children.length > 0\n ? { ...row, [childrenField]: this.sortTree(children as TreeRow[], field, dir) }\n : row;\n });\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 originalRenderer = targetCol.viewRenderer;\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 treeRow = row as TreeRow;\n const depth = treeRow.__treeDepth ?? 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 (treeRow.__treeHasChildren) {\n const icon = document.createElement('span');\n icon.className = `${GridClasses.TREE_TOGGLE}${treeRow.__treeExpanded ? ` ${GridClasses.EXPANDED}` : ''}`;\n setIconFn(icon, treeRow.__treeExpanded ? 'collapse' : 'expand');\n icon.setAttribute('data-tree-key', String(treeRow.__treeKey ?? ''));\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 this.emit<TreeExpandDetail>('tree-expand', {\n key,\n row: flatRow.data,\n expanded: this.expandedKeys.has(key),\n depth: flatRow.depth,\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 this.emit<TreeExpandDetail>('tree-expand', {\n key: flatRow.key,\n row: flatRow.data,\n expanded: this.expandedKeys.has(flatRow.key),\n depth: flatRow.depth,\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 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-state-change` plugin event with the updated expanded keys.\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 this.emitPluginEvent('tree-state-change', { expandedKeys: [...this.expandedKeys] });\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-state-change` 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-state-change', { 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-state-change` 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-state-change', { 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 * 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","detectTreeStructure","TreePlugin","BaseGridPlugin","static","modifiesRowStructure","incompatibleWith","name","reason","events","type","description","queries","required","styles","defaultConfig","autoDetect","defaultExpanded","indentWidth","showExpandIcons","animation","initialExpansionDone","flattenedRows","rowKeyMap","Map","previousVisibleKeys","keysToAnimate","sortState","detach","this","clear","handleQuery","query","context","animationStyle","isAnimationEnabled","detect","treeRows","field","commonArrayFields","value","inferChildrenField","processRows","data","withStableKeys","effectiveSortState","resolveEffectiveSortState","sortTree","direction","flattenTree","currentKeys","set","map","r","__treeKey","__treeDepth","__treeHasChildren","hasChildren","__treeExpanded","isExpanded","stableKey","__stableKey","expanded","result","push","substring","lastIndexOf","multiSortResults","grid","sortModel","dir","sort","a","b","aVal","bVal","processColumns","columns","cols","treeColumn","targetIndex","idx","findIndex","c","targetCol","originalRenderer","viewRenderer","getConfig","setIconFn","setIcon","bind","ctx","treeRow","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","flatRow","get","emit","requestRender","onKeyDown","focusRow","_focusRow","preventDefault","requestRenderWithFocus","onHeaderClick","column","sortable","gridEl","_sortState","broadcast","afterRender","body","gridElement","querySelector","shouldAnimate","size","animClass","rowEl","querySelectorAll","cell","parseInt","addEventListener","remove","once","expand","collapse","toggle","emitPluginEvent","collapseAll","getExpandedKeys","getFlattenedRows","getRowByKey"],"mappings":"iZAYO,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,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,GACXZ,EAAMR,EAAeC,EAAKmB,EAAGjB,GAEnC,GAAIK,IAAQoB,EACV,MAAO,CAACpB,GAGV,MAAMc,EAAWrB,EAAIiB,GACrB,GAAIK,MAAMC,QAAQF,IAAaA,EAASD,OAAS,EAAG,CAClD,MAAMQ,EAAYF,EAAaL,EAAuBM,EAAW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