@toolbox-web/grid-angular 0.11.1 → 0.12.1

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.
@@ -1,4 +1,4 @@
1
- import { inject, ElementRef, signal } from '@angular/core';
1
+ import { inject, ElementRef, DestroyRef, signal } from '@angular/core';
2
2
  import { registerFeature } from '@toolbox-web/grid-angular';
3
3
  import { SelectionPlugin } from '@toolbox-web/grid/plugins/selection';
4
4
 
@@ -85,10 +85,40 @@ registerFeature('selection', (config) => {
85
85
  */
86
86
  function injectGridSelection() {
87
87
  const elementRef = inject(ElementRef);
88
+ const destroyRef = inject(DestroyRef);
88
89
  const isReady = signal(false, ...(ngDevMode ? [{ debugName: "isReady" }] : []));
90
+ // Reactive selection state
91
+ const selectionSignal = signal(null, ...(ngDevMode ? [{ debugName: "selectionSignal" }] : []));
92
+ const selectedRowIndicesSignal = signal([], ...(ngDevMode ? [{ debugName: "selectedRowIndicesSignal" }] : []));
89
93
  // Lazy discovery: cached grid reference
90
94
  let cachedGrid = null;
91
95
  let readyPromiseStarted = false;
96
+ let listenerAttached = false;
97
+ /**
98
+ * Handle selection-change events from the grid.
99
+ * Updates both reactive signals.
100
+ */
101
+ const onSelectionChange = (e) => {
102
+ const detail = e.detail;
103
+ const plugin = getPlugin();
104
+ if (plugin) {
105
+ selectionSignal.set(plugin.getSelection());
106
+ selectedRowIndicesSignal.set(detail.mode === 'row' ? plugin.getSelectedRowIndices() : []);
107
+ }
108
+ };
109
+ /**
110
+ * Attach the selection-change event listener to the grid element.
111
+ * Called once when the grid is first discovered.
112
+ */
113
+ const attachListener = (grid) => {
114
+ if (listenerAttached)
115
+ return;
116
+ listenerAttached = true;
117
+ grid.addEventListener('selection-change', onSelectionChange);
118
+ destroyRef.onDestroy(() => {
119
+ grid.removeEventListener('selection-change', onSelectionChange);
120
+ });
121
+ };
92
122
  /**
93
123
  * Lazily find the grid element. Called on each method invocation.
94
124
  * Caches the reference once found and triggers ready() check.
@@ -99,6 +129,7 @@ function injectGridSelection() {
99
129
  const grid = elementRef.nativeElement.querySelector('tbw-grid');
100
130
  if (grid) {
101
131
  cachedGrid = grid;
132
+ attachListener(grid);
102
133
  // Start ready() check only once
103
134
  if (!readyPromiseStarted) {
104
135
  readyPromiseStarted = true;
@@ -112,6 +143,8 @@ function injectGridSelection() {
112
143
  };
113
144
  return {
114
145
  isReady: isReady.asReadonly(),
146
+ selection: selectionSignal.asReadonly(),
147
+ selectedRowIndices: selectedRowIndicesSignal.asReadonly(),
115
148
  selectAll: () => {
116
149
  const plugin = getPlugin();
117
150
  if (!plugin) {
@@ -1 +1 @@
1
- {"version":3,"file":"toolbox-web-grid-angular-features-selection.mjs","sources":["../../../../libs/grid-angular/features/selection/src/index.ts","../../../../libs/grid-angular/features/selection/src/toolbox-web-grid-angular-features-selection.ts"],"sourcesContent":["/**\n * Selection feature for @toolbox-web/grid-angular\n *\n * Import this module to enable the `selection` input on Grid directive.\n * Also exports `injectGridSelection()` for programmatic selection control.\n *\n * @example\n * ```typescript\n * import '@toolbox-web/grid-angular/features/selection';\n *\n * <tbw-grid [selection]=\"'range'\" />\n * ```\n *\n * @example Using injectGridSelection\n * ```typescript\n * import { injectGridSelection } from '@toolbox-web/grid-angular/features/selection';\n *\n * @Component({...})\n * export class MyComponent {\n * private selection = injectGridSelection<Employee>();\n *\n * selectAll() {\n * this.selection.selectAll();\n * }\n *\n * getSelected() {\n * return this.selection.getSelection();\n * }\n * }\n * ```\n *\n * @packageDocumentation\n */\n\nimport { ElementRef, inject, signal, type Signal } from '@angular/core';\nimport type { DataGridElement } from '@toolbox-web/grid';\nimport { registerFeature } from '@toolbox-web/grid-angular';\nimport { SelectionPlugin, type CellRange, type SelectionResult } from '@toolbox-web/grid/plugins/selection';\n\nregisterFeature('selection', (config) => {\n // Handle shorthand: 'cell', 'row', 'range'\n if (config === 'cell' || config === 'row' || config === 'range') {\n return new SelectionPlugin({ mode: config });\n }\n // Full config object\n return new SelectionPlugin(config ?? undefined);\n});\n\n/**\n * Selection methods returned from injectGridSelection.\n *\n * Uses lazy discovery - the grid is found on first method call, not during initialization.\n * This ensures it works with lazy-rendered tabs, conditional rendering, etc.\n */\nexport interface SelectionMethods {\n /**\n * Select all rows (row mode) or all cells (range mode).\n */\n selectAll: () => void;\n\n /**\n * Clear all selection.\n */\n clearSelection: () => void;\n\n /**\n * Get the current selection state.\n * Use this to derive selected rows, indices, etc.\n */\n getSelection: () => SelectionResult | null;\n\n /**\n * Check if a specific cell is selected.\n */\n isCellSelected: (row: number, col: number) => boolean;\n\n /**\n * Set selection ranges programmatically.\n */\n setRanges: (ranges: CellRange[]) => void;\n\n /**\n * Signal indicating if grid is ready.\n * The grid is discovered lazily, so this updates when first method call succeeds.\n */\n isReady: Signal<boolean>;\n}\n\n/**\n * Angular inject function for programmatic selection control.\n *\n * Uses **lazy grid discovery** - the grid element is found when methods are called,\n * not during initialization. This ensures it works reliably with:\n * - Lazy-rendered tabs\n * - Conditional rendering (*ngIf)\n * - Dynamic component loading\n *\n * @example\n * ```typescript\n * import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';\n * import { Grid } from '@toolbox-web/grid-angular';\n * import '@toolbox-web/grid-angular/features/selection';\n * import { injectGridSelection } from '@toolbox-web/grid-angular/features/selection';\n *\n * @Component({\n * selector: 'app-my-grid',\n * imports: [Grid],\n * schemas: [CUSTOM_ELEMENTS_SCHEMA],\n * template: `\n * <button (click)=\"handleSelectAll()\">Select All</button>\n * <tbw-grid [rows]=\"rows\" [selection]=\"'range'\"></tbw-grid>\n * `\n * })\n * export class MyGridComponent {\n * selection = injectGridSelection();\n *\n * handleSelectAll() {\n * this.selection.selectAll();\n * }\n *\n * getSelectedRows() {\n * const selection = this.selection.getSelection();\n * if (!selection) return [];\n * // Derive rows from selection.ranges as needed\n * }\n * }\n * ```\n */\nexport function injectGridSelection<TRow = unknown>(): SelectionMethods {\n const elementRef = inject(ElementRef);\n const isReady = signal(false);\n\n // Lazy discovery: cached grid reference\n let cachedGrid: DataGridElement<TRow> | null = null;\n let readyPromiseStarted = false;\n\n /**\n * Lazily find the grid element. Called on each method invocation.\n * Caches the reference once found and triggers ready() check.\n */\n const getGrid = (): DataGridElement<TRow> | null => {\n if (cachedGrid) return cachedGrid;\n\n const grid = elementRef.nativeElement.querySelector('tbw-grid') as DataGridElement<TRow> | null;\n if (grid) {\n cachedGrid = grid;\n // Start ready() check only once\n if (!readyPromiseStarted) {\n readyPromiseStarted = true;\n grid.ready?.().then(() => isReady.set(true));\n }\n }\n return grid;\n };\n\n const getPlugin = (): SelectionPlugin | undefined => {\n return getGrid()?.getPlugin(SelectionPlugin);\n };\n\n return {\n isReady: isReady.asReadonly(),\n\n selectAll: () => {\n const plugin = getPlugin();\n if (!plugin) {\n console.warn(\n `[tbw-grid:selection] SelectionPlugin not found.\\n\\n` +\n ` → Enable selection on the grid:\\n` +\n ` <tbw-grid [selection]=\"'range'\" />`,\n );\n return;\n }\n const grid = getGrid();\n // Cast to any to access protected config\n const mode = (plugin as any).config?.mode;\n\n if (mode === 'row') {\n const rowCount = grid?.rows?.length ?? 0;\n const allIndices = new Set<number>();\n for (let i = 0; i < rowCount; i++) allIndices.add(i);\n (plugin as any).selected = allIndices;\n (plugin as any).requestAfterRender?.();\n } else if (mode === 'range') {\n const rowCount = grid?.rows?.length ?? 0;\n const colCount = (grid as any)?._columns?.length ?? 0;\n if (rowCount > 0 && colCount > 0) {\n plugin.setRanges([{ from: { row: 0, col: 0 }, to: { row: rowCount - 1, col: colCount - 1 } }]);\n }\n }\n },\n\n clearSelection: () => {\n getPlugin()?.clearSelection();\n },\n\n getSelection: () => {\n return getPlugin()?.getSelection() ?? null;\n },\n\n isCellSelected: (row: number, col: number) => {\n return getPlugin()?.isCellSelected(row, col) ?? false;\n },\n\n setRanges: (ranges: CellRange[]) => {\n getPlugin()?.setRanges(ranges);\n },\n };\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings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AAE,EAAE,cAAc,EAAE;QAC/B,CAAC;QAED,YAAY,EAAE,MAAK;AACjB,YAAA,OAAO,SAAS,EAAE,EAAE,YAAY,EAAE,IAAI,IAAI;QAC5C,CAAC;AAED,QAAA,cAAc,EAAE,CAAC,GAAW,EAAE,GAAW,KAAI;YAC3C,OAAO,SAAS,EAAE,EAAE,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,KAAK;QACvD,CAAC;AAED,QAAA,SAAS,EAAE,CAAC,MAAmB,KAAI;AACjC,YAAA,SAAS,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC;QAChC,CAAC;KACF;AACH;;AC/MA;;AAEG;;;;"}
1
+ {"version":3,"file":"toolbox-web-grid-angular-features-selection.mjs","sources":["../../../../libs/grid-angular/features/selection/src/index.ts","../../../../libs/grid-angular/features/selection/src/toolbox-web-grid-angular-features-selection.ts"],"sourcesContent":["/**\n * Selection feature for @toolbox-web/grid-angular\n *\n * Import this module to enable the `selection` input on Grid directive.\n * Also exports `injectGridSelection()` for programmatic selection control.\n *\n * @example\n * ```typescript\n * import '@toolbox-web/grid-angular/features/selection';\n *\n * <tbw-grid [selection]=\"'range'\" />\n * ```\n *\n * @example Using injectGridSelection\n * ```typescript\n * import { injectGridSelection } from '@toolbox-web/grid-angular/features/selection';\n *\n * @Component({...})\n * export class MyComponent {\n * private selection = injectGridSelection<Employee>();\n *\n * selectAll() {\n * this.selection.selectAll();\n * }\n *\n * getSelected() {\n * return this.selection.getSelection();\n * }\n * }\n * ```\n *\n * @packageDocumentation\n */\n\nimport { DestroyRef, ElementRef, inject, signal, type Signal } from '@angular/core';\nimport type { DataGridElement } from '@toolbox-web/grid';\nimport { registerFeature } from '@toolbox-web/grid-angular';\nimport {\n SelectionPlugin,\n type CellRange,\n type SelectionChangeDetail,\n type SelectionResult,\n} from '@toolbox-web/grid/plugins/selection';\n\nregisterFeature('selection', (config) => {\n // Handle shorthand: 'cell', 'row', 'range'\n if (config === 'cell' || config === 'row' || config === 'range') {\n return new SelectionPlugin({ mode: config });\n }\n // Full config object\n return new SelectionPlugin(config ?? undefined);\n});\n\n/**\n * Selection methods returned from injectGridSelection.\n *\n * Uses lazy discovery - the grid is found on first method call, not during initialization.\n * This ensures it works with lazy-rendered tabs, conditional rendering, etc.\n */\nexport interface SelectionMethods {\n /**\n * Select all rows (row mode) or all cells (range mode).\n */\n selectAll: () => void;\n\n /**\n * Clear all selection.\n */\n clearSelection: () => void;\n\n /**\n * Get the current selection state (imperative, point-in-time snapshot).\n * For reactive selection state, use the `selection` signal instead.\n */\n getSelection: () => SelectionResult | null;\n\n /**\n * Check if a specific cell is selected.\n */\n isCellSelected: (row: number, col: number) => boolean;\n\n /**\n * Set selection ranges programmatically.\n */\n setRanges: (ranges: CellRange[]) => void;\n\n /**\n * Reactive selection state. Updates automatically whenever the selection changes.\n * Null when no SelectionPlugin is active or no selection has been made yet.\n *\n * @example\n * ```typescript\n * readonly selection = injectGridSelection();\n *\n * // In template:\n * // {{ selection.selection()?.ranges?.length ?? 0 }} cells selected\n *\n * // In computed:\n * readonly hasSelection = computed(() => (this.selection.selection()?.ranges?.length ?? 0) > 0);\n * ```\n */\n selection: Signal<SelectionResult | null>;\n\n /**\n * Reactive selected row indices (sorted ascending). Updates automatically.\n * Convenience signal for row-mode selection — returns `[]` in cell/range modes\n * or when nothing is selected.\n *\n * @example\n * ```typescript\n * readonly selection = injectGridSelection();\n *\n * // In template:\n * // {{ selection.selectedRowIndices().length }} rows selected\n *\n * // In computed:\n * readonly selectedRows = computed(() =>\n * this.selection.selectedRowIndices().map(i => this.rows[i])\n * );\n * ```\n */\n selectedRowIndices: Signal<number[]>;\n\n /**\n * Signal indicating if grid is ready.\n * The grid is discovered lazily, so this updates when first method call succeeds.\n */\n isReady: Signal<boolean>;\n}\n\n/**\n * Angular inject function for programmatic selection control.\n *\n * Uses **lazy grid discovery** - the grid element is found when methods are called,\n * not during initialization. This ensures it works reliably with:\n * - Lazy-rendered tabs\n * - Conditional rendering (*ngIf)\n * - Dynamic component loading\n *\n * @example\n * ```typescript\n * import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';\n * import { Grid } from '@toolbox-web/grid-angular';\n * import '@toolbox-web/grid-angular/features/selection';\n * import { injectGridSelection } from '@toolbox-web/grid-angular/features/selection';\n *\n * @Component({\n * selector: 'app-my-grid',\n * imports: [Grid],\n * schemas: [CUSTOM_ELEMENTS_SCHEMA],\n * template: `\n * <button (click)=\"handleSelectAll()\">Select All</button>\n * <tbw-grid [rows]=\"rows\" [selection]=\"'range'\"></tbw-grid>\n * `\n * })\n * export class MyGridComponent {\n * selection = injectGridSelection();\n *\n * handleSelectAll() {\n * this.selection.selectAll();\n * }\n *\n * getSelectedRows() {\n * const selection = this.selection.getSelection();\n * if (!selection) return [];\n * // Derive rows from selection.ranges as needed\n * }\n * }\n * ```\n */\nexport function injectGridSelection<TRow = unknown>(): SelectionMethods {\n const elementRef = inject(ElementRef);\n const destroyRef = inject(DestroyRef);\n const isReady = signal(false);\n\n // Reactive selection state\n const selectionSignal = signal<SelectionResult | null>(null);\n const selectedRowIndicesSignal = signal<number[]>([]);\n\n // Lazy discovery: cached grid reference\n let cachedGrid: DataGridElement<TRow> | null = null;\n let readyPromiseStarted = false;\n let listenerAttached = false;\n\n /**\n * Handle selection-change events from the grid.\n * Updates both reactive signals.\n */\n const onSelectionChange = (e: Event): void => {\n const detail = (e as CustomEvent<SelectionChangeDetail>).detail;\n const plugin = getPlugin();\n if (plugin) {\n selectionSignal.set(plugin.getSelection());\n selectedRowIndicesSignal.set(detail.mode === 'row' ? plugin.getSelectedRowIndices() : []);\n }\n };\n\n /**\n * Attach the selection-change event listener to the grid element.\n * Called once when the grid is first discovered.\n */\n const attachListener = (grid: DataGridElement<TRow>): void => {\n if (listenerAttached) return;\n listenerAttached = true;\n\n grid.addEventListener('selection-change', onSelectionChange);\n\n destroyRef.onDestroy(() => {\n grid.removeEventListener('selection-change', onSelectionChange);\n });\n };\n\n /**\n * Lazily find the grid element. Called on each method invocation.\n * Caches the reference once found and triggers ready() check.\n */\n const getGrid = (): DataGridElement<TRow> | null => {\n if (cachedGrid) return cachedGrid;\n\n const grid = elementRef.nativeElement.querySelector('tbw-grid') as DataGridElement<TRow> | null;\n if (grid) {\n cachedGrid = grid;\n attachListener(grid);\n // Start ready() check only once\n if (!readyPromiseStarted) {\n readyPromiseStarted = true;\n grid.ready?.().then(() => isReady.set(true));\n }\n }\n return grid;\n };\n\n const getPlugin = (): SelectionPlugin | undefined => {\n return getGrid()?.getPlugin(SelectionPlugin);\n };\n\n return {\n isReady: isReady.asReadonly(),\n selection: selectionSignal.asReadonly(),\n selectedRowIndices: selectedRowIndicesSignal.asReadonly(),\n\n selectAll: () => {\n const plugin = getPlugin();\n if (!plugin) {\n console.warn(\n `[tbw-grid:selection] SelectionPlugin not found.\\n\\n` +\n ` → Enable selection on the grid:\\n` +\n ` <tbw-grid [selection]=\"'range'\" />`,\n );\n return;\n }\n const grid = getGrid();\n // Cast to any to access protected config\n const mode = (plugin as any).config?.mode;\n\n if (mode === 'row') {\n const rowCount = grid?.rows?.length ?? 0;\n const allIndices = new Set<number>();\n for (let i = 0; i < rowCount; i++) allIndices.add(i);\n (plugin as any).selected = allIndices;\n (plugin as any).requestAfterRender?.();\n } else if (mode === 'range') {\n const rowCount = grid?.rows?.length ?? 0;\n const colCount = (grid as any)?._columns?.length ?? 0;\n if (rowCount > 0 && colCount > 0) {\n plugin.setRanges([{ from: { row: 0, col: 0 }, to: { row: rowCount - 1, col: colCount - 1 } }]);\n }\n }\n },\n\n clearSelection: () => {\n getPlugin()?.clearSelection();\n },\n\n getSelection: () => {\n return getPlugin()?.getSelection() ?? null;\n },\n\n isCellSelected: (row: number, col: number) => {\n return getPlugin()?.isCellSelected(row, col) ?? false;\n },\n\n setRanges: (ranges: CellRange[]) => {\n getPlugin()?.setRanges(ranges);\n },\n };\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";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GAAW,KAAI;YAC3C,OAAO,SAAS,EAAE,EAAE,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,KAAK;QACvD,CAAC;AAED,QAAA,SAAS,EAAE,CAAC,MAAmB,KAAI;AACjC,YAAA,SAAS,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC;QAChC,CAAC;KACF;AACH;;AC9RA;;AAEG;;;;"}
@@ -1413,6 +1413,10 @@ class GridAdapter {
1413
1413
  if (config.editor && isComponentClass(config.editor)) {
1414
1414
  processedConfig.editor = this.createComponentEditor(config.editor);
1415
1415
  }
1416
+ // Convert filterPanelRenderer component class to function
1417
+ if (config.filterPanelRenderer && isComponentClass(config.filterPanelRenderer)) {
1418
+ processedConfig.filterPanelRenderer = this.createComponentFilterPanelRenderer(config.filterPanelRenderer);
1419
+ }
1416
1420
  processed[type] = processedConfig;
1417
1421
  }
1418
1422
  return processed;
@@ -1560,10 +1564,14 @@ class GridAdapter {
1560
1564
  $implicit: ctx.value,
1561
1565
  value: ctx.value,
1562
1566
  row: ctx.row,
1567
+ field: ctx.field,
1563
1568
  column: ctx.column,
1569
+ rowId: ctx.rowId ?? '',
1564
1570
  // Preferred: simple callback functions
1565
1571
  onCommit,
1566
1572
  onCancel,
1573
+ updateRow: ctx.updateRow,
1574
+ onValueChange: ctx.onValueChange,
1567
1575
  // FormControl from FormArray (if available)
1568
1576
  control,
1569
1577
  // Deprecated: EventEmitters (for backwards compatibility)
@@ -1589,6 +1597,25 @@ class GridAdapter {
1589
1597
  ctx.cancel();
1590
1598
  });
1591
1599
  }
1600
+ // Auto-update editor when value changes externally (e.g., via updateRow cascade).
1601
+ // This keeps Angular template editors in sync without manual DOM patching.
1602
+ ctx.onValueChange?.((newVal) => {
1603
+ context.$implicit = newVal;
1604
+ context.value = newVal;
1605
+ viewRef.markForCheck();
1606
+ // Also patch raw DOM inputs as a fallback for editors that don't bind to context
1607
+ if (rootNode) {
1608
+ const input = rootNode.querySelector?.('input,textarea,select');
1609
+ if (input) {
1610
+ if (input instanceof HTMLInputElement && input.type === 'checkbox') {
1611
+ input.checked = !!newVal;
1612
+ }
1613
+ else {
1614
+ input.value = String(newVal ?? '');
1615
+ }
1616
+ }
1617
+ }
1618
+ });
1592
1619
  return rootNode;
1593
1620
  };
1594
1621
  }
@@ -1757,6 +1784,13 @@ class GridAdapter {
1757
1784
  // Type assertion needed: adapter bridges TRow to core's unknown
1758
1785
  typeDefault.editor = this.createComponentEditor(config.editor);
1759
1786
  }
1787
+ // Create filterPanelRenderer function that instantiates the Angular component
1788
+ if (config.filterPanelRenderer && isComponentClass(config.filterPanelRenderer)) {
1789
+ typeDefault.filterPanelRenderer = this.createComponentFilterPanelRenderer(config.filterPanelRenderer);
1790
+ }
1791
+ else if (config.filterPanelRenderer) {
1792
+ typeDefault.filterPanelRenderer = config.filterPanelRenderer;
1793
+ }
1760
1794
  return typeDefault;
1761
1795
  }
1762
1796
  /**
@@ -1846,9 +1880,57 @@ class GridAdapter {
1846
1880
  column: ctx.column,
1847
1881
  });
1848
1882
  this.wireEditorCallbacks(hostElement, componentRef, (value) => ctx.commit(value), () => ctx.cancel());
1883
+ // Auto-update editor when value changes externally (e.g., via updateRow cascade).
1884
+ // This keeps Angular component editors in sync without manual DOM patching.
1885
+ ctx.onValueChange?.((newVal) => {
1886
+ try {
1887
+ componentRef.setInput('value', newVal);
1888
+ componentRef.changeDetectorRef.detectChanges();
1889
+ }
1890
+ catch {
1891
+ // Input doesn't exist or component is destroyed — fall back to DOM patching
1892
+ const input = hostElement.querySelector?.('input,textarea,select');
1893
+ if (input) {
1894
+ if (input instanceof HTMLInputElement && input.type === 'checkbox') {
1895
+ input.checked = !!newVal;
1896
+ }
1897
+ else {
1898
+ input.value = String(newVal ?? '');
1899
+ }
1900
+ }
1901
+ }
1902
+ });
1849
1903
  return hostElement;
1850
1904
  };
1851
1905
  }
1906
+ /**
1907
+ * Creates a filter panel renderer function from an Angular component class.
1908
+ *
1909
+ * The component must implement `FilterPanel` (i.e., have a `params` input).
1910
+ * The component is mounted into the filter panel container element.
1911
+ * @internal
1912
+ */
1913
+ createComponentFilterPanelRenderer(componentClass) {
1914
+ return (container, params) => {
1915
+ const hostElement = document.createElement('span');
1916
+ hostElement.style.display = 'contents';
1917
+ const componentRef = createComponent(componentClass, {
1918
+ environmentInjector: this.injector,
1919
+ hostElement,
1920
+ });
1921
+ // Set params input
1922
+ try {
1923
+ componentRef.setInput('params', params);
1924
+ }
1925
+ catch {
1926
+ // Input doesn't exist on component — ignore
1927
+ }
1928
+ this.appRef.attachView(componentRef.hostView);
1929
+ this.componentRefs.push(componentRef);
1930
+ componentRef.changeDetectorRef.detectChanges();
1931
+ container.appendChild(hostElement);
1932
+ };
1933
+ }
1852
1934
  /**
1853
1935
  * Subscribes to an Angular output on a component instance.
1854
1936
  * Works with both EventEmitter and OutputEmitterRef (signal outputs).
@@ -2409,6 +2491,9 @@ function clearFeatureRegistry() {
2409
2491
  */
2410
2492
  class BaseGridEditor {
2411
2493
  elementRef = inject(ElementRef);
2494
+ _destroyRef = inject(DestroyRef);
2495
+ /** Cleanup function for the edit-close listener */
2496
+ _editCloseCleanup = null;
2412
2497
  // ============================================================================
2413
2498
  // Inputs
2414
2499
  // ============================================================================
@@ -2504,8 +2589,51 @@ class BaseGridEditor {
2504
2589
  return Object.entries(ctrl.errors).map(([key, value]) => this.getErrorMessage(key, value));
2505
2590
  }, ...(ngDevMode ? [{ debugName: "allErrorMessages" }] : []));
2506
2591
  // ============================================================================
2592
+ // Lifecycle
2593
+ // ============================================================================
2594
+ constructor() {
2595
+ afterNextRender(() => this._initEditCloseListener());
2596
+ this._destroyRef.onDestroy(() => {
2597
+ this._editCloseCleanup?.();
2598
+ this._editCloseCleanup = null;
2599
+ });
2600
+ }
2601
+ _initEditCloseListener() {
2602
+ const grid = this.elementRef.nativeElement.closest('tbw-grid');
2603
+ if (!grid)
2604
+ return;
2605
+ const handler = () => this.onEditClose();
2606
+ grid.addEventListener('edit-close', handler, { once: true });
2607
+ this._editCloseCleanup = () => grid.removeEventListener('edit-close', handler);
2608
+ }
2609
+ // ============================================================================
2507
2610
  // Methods
2508
2611
  // ============================================================================
2612
+ /**
2613
+ * Whether this editor's cell is the currently focused cell.
2614
+ *
2615
+ * In row editing mode the grid creates editors for every editable cell
2616
+ * in the row simultaneously. Use this to conditionally auto-focus inputs
2617
+ * or open panels only in the active cell.
2618
+ *
2619
+ * Performs a synchronous DOM check — safe to call from `ngAfterViewInit`.
2620
+ */
2621
+ isCellFocused() {
2622
+ return this.elementRef.nativeElement.closest('[part="cell"]')?.classList.contains('cell-focus') ?? false;
2623
+ }
2624
+ /**
2625
+ * Called when the grid ends the editing session for this cell.
2626
+ *
2627
+ * Override to perform cleanup such as closing overlay panels, autocomplete
2628
+ * dropdowns, or other floating UI that lives at `<body>` level and would
2629
+ * otherwise persist after the editor DOM is removed.
2630
+ *
2631
+ * The listener is set up automatically via `afterNextRender` — no manual
2632
+ * wiring required.
2633
+ */
2634
+ onEditClose() {
2635
+ // Default: no-op. Subclasses override.
2636
+ }
2509
2637
  /**
2510
2638
  * Commit a new value. Emits the commit output AND dispatches a DOM event.
2511
2639
  * The DOM event enables the grid's auto-wiring to catch the commit.
@@ -2569,7 +2697,7 @@ class BaseGridEditor {
2569
2697
  }
2570
2698
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: BaseGridEditor, decorators: [{
2571
2699
  type: Directive
2572
- }], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }], row: [{ type: i0.Input, args: [{ isSignal: true, alias: "row", required: false }] }], column: [{ type: i0.Input, args: [{ isSignal: true, alias: "column", required: false }] }], control: [{ type: i0.Input, args: [{ isSignal: true, alias: "control", required: false }] }], commit: [{ type: i0.Output, args: ["commit"] }], cancel: [{ type: i0.Output, args: ["cancel"] }] } });
2700
+ }], ctorParameters: () => [], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }], row: [{ type: i0.Input, args: [{ isSignal: true, alias: "row", required: false }] }], column: [{ type: i0.Input, args: [{ isSignal: true, alias: "column", required: false }] }], control: [{ type: i0.Input, args: [{ isSignal: true, alias: "control", required: false }] }], commit: [{ type: i0.Output, args: ["commit"] }], cancel: [{ type: i0.Output, args: ["cancel"] }] } });
2573
2701
 
2574
2702
  // Symbol for storing form context on the grid element (shared with GridFormArray)
2575
2703
  const FORM_ARRAY_CONTEXT = Symbol('formArrayContext');