@toolbox-web/grid 1.22.0 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +20 -10
  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/grid.d.ts +88 -1
  7. package/lib/core/grid.d.ts.map +1 -1
  8. package/lib/core/types.d.ts +61 -0
  9. package/lib/core/types.d.ts.map +1 -1
  10. package/lib/plugins/clipboard/index.js.map +1 -1
  11. package/lib/plugins/column-virtualization/index.js.map +1 -1
  12. package/lib/plugins/context-menu/index.js.map +1 -1
  13. package/lib/plugins/editing/EditingPlugin.d.ts +132 -1
  14. package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
  15. package/lib/plugins/editing/editors.d.ts.map +1 -1
  16. package/lib/plugins/editing/index.d.ts +1 -0
  17. package/lib/plugins/editing/index.d.ts.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/editing/internal/dirty-tracking.d.ts +90 -0
  21. package/lib/plugins/editing/internal/dirty-tracking.d.ts.map +1 -0
  22. package/lib/plugins/editing/types.d.ts +82 -0
  23. package/lib/plugins/editing/types.d.ts.map +1 -1
  24. package/lib/plugins/export/index.js.map +1 -1
  25. package/lib/plugins/filtering/FilteringPlugin.d.ts +17 -4
  26. package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
  27. package/lib/plugins/filtering/index.js +1 -1
  28. package/lib/plugins/filtering/index.js.map +1 -1
  29. package/lib/plugins/grouping-columns/index.js.map +1 -1
  30. package/lib/plugins/grouping-rows/index.js.map +1 -1
  31. package/lib/plugins/master-detail/index.js.map +1 -1
  32. package/lib/plugins/multi-sort/index.js.map +1 -1
  33. package/lib/plugins/pinned-columns/index.js.map +1 -1
  34. package/lib/plugins/pinned-rows/index.js.map +1 -1
  35. package/lib/plugins/pivot/index.js.map +1 -1
  36. package/lib/plugins/print/index.js.map +1 -1
  37. package/lib/plugins/reorder/index.js.map +1 -1
  38. package/lib/plugins/responsive/index.js.map +1 -1
  39. package/lib/plugins/row-reorder/index.js.map +1 -1
  40. package/lib/plugins/selection/index.js.map +1 -1
  41. package/lib/plugins/server-side/index.js.map +1 -1
  42. package/lib/plugins/tree/index.js.map +1 -1
  43. package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts +52 -7
  44. package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts.map +1 -1
  45. package/lib/plugins/undo-redo/history.d.ts +11 -4
  46. package/lib/plugins/undo-redo/history.d.ts.map +1 -1
  47. package/lib/plugins/undo-redo/index.d.ts +1 -1
  48. package/lib/plugins/undo-redo/index.d.ts.map +1 -1
  49. package/lib/plugins/undo-redo/index.js +1 -1
  50. package/lib/plugins/undo-redo/index.js.map +1 -1
  51. package/lib/plugins/undo-redo/types.d.ts +20 -3
  52. package/lib/plugins/undo-redo/types.d.ts.map +1 -1
  53. package/lib/plugins/visibility/index.js.map +1 -1
  54. package/package.json +1 -1
  55. package/public.d.ts +1 -1
  56. package/public.d.ts.map +1 -1
  57. package/umd/grid.all.umd.js +1 -1
  58. package/umd/grid.all.umd.js.map +1 -1
  59. package/umd/grid.umd.js +1 -1
  60. package/umd/grid.umd.js.map +1 -1
  61. package/umd/plugins/editing.umd.js +1 -1
  62. package/umd/plugins/editing.umd.js.map +1 -1
  63. package/umd/plugins/filtering.umd.js +1 -1
  64. package/umd/plugins/filtering.umd.js.map +1 -1
  65. package/umd/plugins/undo-redo.umd.js +1 -1
  66. package/umd/plugins/undo-redo.umd.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"editing.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/editing/editors.ts","../../../../../libs/grid/src/lib/plugins/editing/EditingPlugin.ts"],"sourcesContent":["/**\n * Default Editors Module\n *\n * Provides built-in editor factories for different column types.\n * Each editor type has its own factory function for consistency and readability.\n *\n * IMPORTANT: Editor factories should NOT call focus() on elements - they are called\n * before the element is appended to the DOM. The calling code (beginBulkEdit,\n * inlineEnterEdit) is responsible for focusing the correct editor after insertion.\n */\n\nimport type { ColumnConfig, ColumnEditorContext } from '../../core/types';\nimport type { DateEditorParams, NumberEditorParams, SelectEditorParams, TextEditorParams } from './types';\n\n// ============================================================================\n// Type Aliases\n// ============================================================================\n\n/** Option shape used by select editor (matches column.options) */\ntype ColumnOption = { label: string; value: unknown };\n\n/** Column with any row type (used for editor factories) */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyColumn = ColumnConfig<any>;\n\n// ============================================================================\n// Utilities\n// ============================================================================\n\n/** Resolve column.options (handles both array and function forms) */\nfunction resolveOptions(column: AnyColumn): ColumnOption[] {\n const raw = column.options;\n if (!raw) return [];\n return typeof raw === 'function' ? raw() : raw;\n}\n\n// ============================================================================\n// Editor Factories\n// ============================================================================\n\n/** Creates a number input editor */\nfunction createNumberEditor(column: AnyColumn): (ctx: ColumnEditorContext) => HTMLElement {\n return (ctx) => {\n const params = column.editorParams as NumberEditorParams | undefined;\n const input = document.createElement('input');\n input.type = 'number';\n input.value = ctx.value != null ? String(ctx.value) : '';\n\n if (params?.min !== undefined) input.min = String(params.min);\n if (params?.max !== undefined) input.max = String(params.max);\n if (params?.step !== undefined) input.step = String(params.step);\n if (params?.placeholder) input.placeholder = params.placeholder;\n\n const commit = () => ctx.commit(input.value === '' ? null : Number(input.value));\n input.addEventListener('blur', commit);\n input.addEventListener('keydown', (e) => {\n if (e.key === 'Enter') commit();\n if (e.key === 'Escape') ctx.cancel();\n });\n\n return input;\n };\n}\n\n/** Creates a checkbox editor for boolean values */\nfunction createBooleanEditor(): (ctx: ColumnEditorContext) => HTMLElement {\n return (ctx) => {\n const input = document.createElement('input');\n input.type = 'checkbox';\n input.checked = !!ctx.value;\n input.addEventListener('change', () => ctx.commit(input.checked));\n return input;\n };\n}\n\n/** Creates a date input editor */\nfunction createDateEditor(column: AnyColumn): (ctx: ColumnEditorContext) => HTMLElement {\n return (ctx) => {\n const params = column.editorParams as DateEditorParams | undefined;\n const input = document.createElement('input');\n input.type = 'date';\n\n // Set initial value - handle both Date objects and string dates\n if (ctx.value instanceof Date) {\n input.valueAsDate = ctx.value;\n } else if (typeof ctx.value === 'string' && ctx.value) {\n // String date like \"2019-10-09\" - set directly as value\n input.value = ctx.value.split('T')[0]; // Handle ISO strings too\n }\n if (params?.min) input.min = params.min;\n if (params?.max) input.max = params.max;\n if (params?.placeholder) input.placeholder = params.placeholder;\n\n // Commit function preserves original type (string vs Date)\n const commit = () => {\n if (typeof ctx.value === 'string') {\n // Original was string, return string in YYYY-MM-DD format\n ctx.commit(input.value);\n } else {\n ctx.commit(input.valueAsDate);\n }\n };\n\n input.addEventListener('change', commit);\n input.addEventListener('keydown', (e) => {\n if (e.key === 'Escape') ctx.cancel();\n });\n\n return input;\n };\n}\n\n/** Creates a select dropdown editor */\nfunction createSelectEditor(column: AnyColumn): (ctx: ColumnEditorContext) => HTMLElement {\n return (ctx) => {\n const params = column.editorParams as SelectEditorParams | undefined;\n const select = document.createElement('select');\n if (column.multi) select.multiple = true;\n\n // Add empty option if requested\n if (params?.includeEmpty) {\n const emptyOpt = document.createElement('option');\n emptyOpt.value = '';\n emptyOpt.textContent = params.emptyLabel ?? '';\n select.appendChild(emptyOpt);\n }\n\n // Populate options from column.options\n const options = resolveOptions(column);\n options.forEach((opt) => {\n const o = document.createElement('option');\n o.value = String(opt.value);\n o.textContent = opt.label;\n if (column.multi && Array.isArray(ctx.value) && ctx.value.includes(opt.value)) {\n o.selected = true;\n } else if (!column.multi && ctx.value === opt.value) {\n o.selected = true;\n }\n select.appendChild(o);\n });\n\n const commit = () => {\n if (column.multi) {\n const values = Array.from(select.selectedOptions).map((o) => o.value);\n ctx.commit(values);\n } else {\n ctx.commit(select.value);\n }\n };\n\n select.addEventListener('change', commit);\n select.addEventListener('blur', commit);\n select.addEventListener('keydown', (e) => {\n if (e.key === 'Escape') ctx.cancel();\n });\n\n return select;\n };\n}\n\n/** Creates a text input editor (default) */\nfunction createTextEditor(column: AnyColumn): (ctx: ColumnEditorContext) => HTMLElement {\n return (ctx) => {\n const params = column.editorParams as TextEditorParams | undefined;\n const input = document.createElement('input');\n input.type = 'text';\n input.value = ctx.value != null ? String(ctx.value) : '';\n\n if (params?.maxLength !== undefined) input.maxLength = params.maxLength;\n if (params?.pattern) input.pattern = params.pattern;\n if (params?.placeholder) input.placeholder = params.placeholder;\n\n // Commit function preserves original type when possible\n const commit = () => {\n const inputVal = input.value;\n // Preserve null/undefined: empty input on a null/undefined field means no change\n if ((ctx.value === null || ctx.value === undefined) && inputVal === '') {\n return;\n }\n // Preserve values with characters that <input> can't represent (newlines, etc.).\n // If stripping those characters produces the same string, the user didn't change anything.\n if (typeof ctx.value === 'string' && inputVal === ctx.value.replace(/[\\n\\r]/g, '')) {\n return;\n }\n // Preserve numeric type for custom column types (e.g., currency)\n if (typeof ctx.value === 'number' && inputVal !== '') {\n ctx.commit(Number(inputVal));\n } else {\n ctx.commit(inputVal);\n }\n };\n\n input.addEventListener('blur', commit);\n input.addEventListener('keydown', (e) => {\n if (e.key === 'Enter') commit();\n if (e.key === 'Escape') ctx.cancel();\n });\n\n return input;\n };\n}\n\n// ============================================================================\n// Main Entry Point\n// ============================================================================\n\n/**\n * Returns a default editor factory function for the given column type.\n * Each editor handles commit on blur/Enter, and cancel on Escape.\n *\n * Note: Focus is NOT called here - the calling code handles focusing after DOM insertion.\n */\nexport function defaultEditorFor(column: AnyColumn): (ctx: ColumnEditorContext) => HTMLElement | string {\n switch (column.type) {\n case 'number':\n return createNumberEditor(column);\n case 'boolean':\n return createBooleanEditor();\n case 'date':\n return createDateEditor(column);\n case 'select':\n return createSelectEditor(column);\n default:\n return createTextEditor(column);\n }\n}\n\n// ============================================================================\n// Utility Export (used by EditingPlugin)\n// ============================================================================\n\n/**\n * Gets the current value from an input element, with type coercion based on column type.\n */\nexport function getInputValue(\n input: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement,\n col: AnyColumn,\n): unknown {\n if (input instanceof HTMLSelectElement) {\n if (col.multi) {\n return Array.from(input.selectedOptions).map((o) => o.value);\n }\n return input.value;\n }\n if (input instanceof HTMLInputElement) {\n if (input.type === 'checkbox') return input.checked;\n if (input.type === 'number') return input.value === '' ? null : Number(input.value);\n if (input.type === 'date') return input.valueAsDate;\n }\n return input.value;\n}\n","/**\n * Editing Plugin\n *\n * Provides complete editing functionality for tbw-grid.\n * This plugin is FULLY SELF-CONTAINED - the grid has ZERO editing knowledge.\n *\n * The plugin:\n * - Owns all editing state (active cell, snapshots, changed rows)\n * - Uses event distribution (onCellClick, onKeyDown) to handle edit lifecycle\n * - Uses afterRender() hook to inject editors into cells\n * - Uses processColumns() to augment columns with editing metadata\n * - Emits its own events (cell-commit, row-commit, changed-rows-reset)\n *\n * Without this plugin, the grid cannot edit. With this plugin, editing\n * is fully functional without any core changes.\n */\n\nimport { ensureCellVisible } from '../../core/internal/keyboard';\nimport { FOCUSABLE_EDITOR_SELECTOR } from '../../core/internal/rows';\nimport type { AfterCellRenderContext, PluginManifest, PluginQuery } from '../../core/plugin/base-plugin';\nimport { BaseGridPlugin, type CellClickEvent, type GridElement } from '../../core/plugin/base-plugin';\nimport type {\n ColumnConfig,\n ColumnEditorSpec,\n ColumnInternal,\n InternalGrid,\n RowElementInternal,\n} from '../../core/types';\nimport styles from './editing.css?inline';\nimport { defaultEditorFor } from './editors';\nimport type {\n BeforeEditCloseDetail,\n CellCommitDetail,\n ChangedRowsResetDetail,\n EditCloseDetail,\n EditingConfig,\n EditOpenDetail,\n EditorContext,\n RowCommitDetail,\n} from './types';\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\n/**\n * Resolves the editor for a column using the priority chain:\n * 1. Column-level (`column.editor`)\n * 2. Light DOM template (`__editorTemplate` → returns 'template')\n * 3. Grid-level (`gridConfig.typeDefaults[column.type]`)\n * 4. App-level (framework adapter's `getTypeDefault`)\n * 5. Returns undefined (caller uses built-in defaultEditorFor)\n */\nfunction resolveEditor<TRow>(\n grid: InternalGrid<TRow>,\n col: ColumnInternal<TRow>,\n): ColumnEditorSpec<TRow, unknown> | 'template' | undefined {\n // 1. Column-level editor (highest priority)\n if (col.editor) return col.editor;\n\n // 2. Light DOM template\n const tplHolder = col.__editorTemplate;\n if (tplHolder) return 'template';\n\n // No type specified - no type defaults to check\n if (!col.type) return undefined;\n\n // 3. Grid-level typeDefaults (access via effectiveConfig)\n const gridTypeDefaults = (grid as any).effectiveConfig?.typeDefaults;\n if (gridTypeDefaults?.[col.type]?.editor) {\n return gridTypeDefaults[col.type].editor as ColumnEditorSpec<TRow, unknown>;\n }\n\n // 4. App-level registry (via framework adapter)\n const adapter = grid.__frameworkAdapter;\n if (adapter?.getTypeDefault) {\n const appDefault = adapter.getTypeDefault<TRow>(col.type);\n if (appDefault?.editor) {\n return appDefault.editor as ColumnEditorSpec<TRow, unknown>;\n }\n }\n\n // 5. No custom editor - caller uses built-in defaultEditorFor\n return undefined;\n}\n\n/**\n * Returns true if the given property key is safe to use on a plain object.\n */\nfunction isSafePropertyKey(key: unknown): key is string {\n if (typeof key !== 'string') return false;\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') return false;\n return true;\n}\n\n/**\n * Check if a row element has any cells in editing mode.\n */\nexport function hasEditingCells(rowEl: RowElementInternal): boolean {\n return (rowEl.__editingCellCount ?? 0) > 0;\n}\n\n/**\n * Increment the editing cell count on a row element.\n */\nfunction incrementEditingCount(rowEl: RowElementInternal): void {\n const count = (rowEl.__editingCellCount ?? 0) + 1;\n rowEl.__editingCellCount = count;\n rowEl.setAttribute('data-has-editing', '');\n}\n\n/**\n * Clear all editing state from a row element.\n */\nexport function clearEditingState(rowEl: RowElementInternal): void {\n rowEl.__editingCellCount = 0;\n rowEl.removeAttribute('data-has-editing');\n}\n\n/**\n * Get the typed value from an input element based on its type, column config, and original value.\n * Preserves the type of the original value (e.g., numeric currency values stay as numbers,\n * string dates stay as strings).\n */\nfunction getInputValue(\n input: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement,\n column?: ColumnConfig<any>,\n originalValue?: unknown,\n): unknown {\n if (input instanceof HTMLInputElement) {\n if (input.type === 'checkbox') return input.checked;\n if (input.type === 'number') return input.value === '' ? null : Number(input.value);\n if (input.type === 'date') {\n // Preserve original type: if original was a string, return string (YYYY-MM-DD format)\n if (typeof originalValue === 'string') {\n return input.value; // input.value is already in YYYY-MM-DD format\n }\n return input.valueAsDate;\n }\n // For text inputs, check if original value was a number to preserve type\n if (typeof originalValue === 'number') {\n return input.value === '' ? null : Number(input.value);\n }\n // Preserve null/undefined: if original was null/undefined and input is empty, return original\n if ((originalValue === null || originalValue === undefined) && input.value === '') {\n return originalValue;\n }\n // Preserve values with characters <input> can't represent (newlines, etc.)\n if (typeof originalValue === 'string' && input.value === originalValue.replace(/[\\n\\r]/g, '')) {\n return originalValue;\n }\n return input.value;\n }\n // For textarea/select, check column type OR original value type\n if (column?.type === 'number' && input.value !== '') {\n return Number(input.value);\n }\n // Preserve numeric type for custom column types (e.g., currency)\n if (typeof originalValue === 'number' && input.value !== '') {\n return Number(input.value);\n }\n // Preserve null/undefined: if original was null/undefined and input is empty, return original\n if ((originalValue === null || originalValue === undefined) && input.value === '') {\n return originalValue;\n }\n return input.value;\n}\n\n/**\n * No-op updateRow function for rows without IDs.\n * Extracted to a named function to satisfy eslint no-empty-function.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nfunction noopUpdateRow(_changes: unknown): void {\n // Row has no ID - cannot update\n}\n\n/**\n * Auto-wire commit/cancel lifecycle for input elements in string-returned editors.\n */\nfunction wireEditorInputs(\n editorHost: HTMLElement,\n column: ColumnConfig<unknown>,\n commit: (value: unknown) => void,\n originalValue?: unknown,\n): void {\n const input = editorHost.querySelector('input,textarea,select') as\n | HTMLInputElement\n | HTMLTextAreaElement\n | HTMLSelectElement\n | null;\n if (!input) return;\n\n input.addEventListener('blur', () => {\n commit(getInputValue(input, column, originalValue));\n });\n\n if (input instanceof HTMLInputElement && input.type === 'checkbox') {\n input.addEventListener('change', () => commit(input.checked));\n } else if (input instanceof HTMLSelectElement) {\n input.addEventListener('change', () => commit(getInputValue(input, column, originalValue)));\n }\n}\n\n// ============================================================================\n// EditingPlugin\n// ============================================================================\n\n/**\n * Editing Plugin for tbw-grid\n *\n * Enables inline cell editing in the grid. Provides built-in editors for common data types\n * and supports custom editor functions for specialized input scenarios.\n *\n * ## Why Opt-In?\n *\n * Editing is delivered as a plugin rather than built into the core grid:\n *\n * - **Smaller bundle** — Apps that only display data don't pay for editing code\n * - **Clear intent** — Explicit plugin registration makes editing capability obvious\n * - **Runtime validation** — Using `editable: true` without the plugin throws a helpful error\n *\n * ## Installation\n *\n * ```ts\n * import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';\n * ```\n *\n * ## Edit Triggers\n *\n * Configure how editing is triggered with the `editOn` option:\n *\n * | Value | Behavior |\n * |-------|----------|\n * | `'click'` | Single click enters edit mode (default) |\n * | `'dblclick'` | Double-click enters edit mode |\n *\n * ## Keyboard Shortcuts\n *\n * | Key | Action |\n * |-----|--------|\n * | `Enter` | Commit edit and move down |\n * | `Tab` | Commit edit and move right |\n * | `Escape` | Cancel edit, restore original value |\n * | `Arrow Keys` | Navigate between cells (when not editing) |\n *\n * @example Basic editing with double-click trigger\n * ```ts\n * grid.gridConfig = {\n * columns: [\n * { field: 'name', editable: true },\n * { field: 'price', type: 'number', editable: true },\n * { field: 'active', type: 'boolean', editable: true },\n * ],\n * plugins: [new EditingPlugin({ editOn: 'dblclick' })],\n * };\n *\n * grid.addEventListener('cell-commit', (e) => {\n * const { field, oldValue, newValue } = e.detail;\n * console.log(`${field}: ${oldValue} → ${newValue}`);\n * });\n * ```\n *\n * @example Custom editor function\n * ```ts\n * columns: [\n * {\n * field: 'status',\n * editable: true,\n * editor: (ctx) => {\n * const select = document.createElement('select');\n * ['pending', 'active', 'completed'].forEach(opt => {\n * const option = document.createElement('option');\n * option.value = opt;\n * option.textContent = opt;\n * option.selected = ctx.value === opt;\n * select.appendChild(option);\n * });\n * select.addEventListener('change', () => ctx.commit(select.value));\n * return select;\n * },\n * },\n * ]\n * ```\n *\n * @see {@link EditingConfig} for configuration options\n * @see {@link EditorContext} for custom editor context\n * @see [Live Demos](?path=/docs/grid-plugins-editing--docs) for interactive examples\n */\nexport class EditingPlugin<T = unknown> extends BaseGridPlugin<EditingConfig> {\n /**\n * Plugin manifest - declares owned properties for configuration validation.\n * @internal\n */\n static override readonly manifest: PluginManifest = {\n ownedProperties: [\n {\n property: 'editable',\n level: 'column',\n description: 'the \"editable\" column property',\n isUsed: (v) => v === true,\n },\n {\n property: 'editor',\n level: 'column',\n description: 'the \"editor\" column property',\n },\n {\n property: 'editorParams',\n level: 'column',\n description: 'the \"editorParams\" column property',\n },\n ],\n events: [\n {\n type: 'cell-edit-committed',\n description: 'Emitted when a cell edit is committed (for plugin-to-plugin coordination)',\n },\n ],\n queries: [\n {\n type: 'isEditing',\n description: 'Returns whether any cell is currently being edited',\n },\n ],\n };\n\n /** @internal */\n readonly name = 'editing';\n /** @internal */\n override readonly styles = styles;\n\n /** @internal */\n protected override get defaultConfig(): Partial<EditingConfig> {\n return {\n mode: 'row',\n editOn: 'click',\n };\n }\n\n /**\n * Whether the grid is in 'grid' mode (all cells always editable).\n */\n get #isGridMode(): boolean {\n return this.config.mode === 'grid';\n }\n\n // #region Editing State (fully owned by plugin)\n\n /** Currently active edit row index, or -1 if not editing */\n #activeEditRow = -1;\n\n /** Row ID of the currently active edit row (stable across _rows replacement) */\n #activeEditRowId: string | undefined;\n\n /** Reference to the row object at edit-open time. Used as fallback in\n * #exitRowEdit when no row ID is available (prevents stale-index access). */\n #activeEditRowRef: T | undefined;\n\n /** Currently active edit column index, or -1 if not editing */\n #activeEditCol = -1;\n\n /** Snapshots of row data before editing started */\n #rowEditSnapshots = new Map<number, T>();\n\n /** Set of row IDs that have been modified (ID-based for stability) */\n #changedRowIds = new Set<string>();\n\n /** Set of cells currently in edit mode: \"rowIndex:colIndex\" */\n #editingCells = new Set<string>();\n\n /**\n * Value-change callbacks for active editors.\n * Keyed by \"rowIndex:field\" → callback that pushes updated values to the editor.\n * Populated during #injectEditor, cleaned up when editors are removed.\n */\n #editorValueCallbacks = new Map<string, (newValue: unknown) => void>();\n\n /** Flag to restore focus after next render (used when exiting edit mode) */\n #pendingFocusRestore = false;\n\n /** Row index pending animation after render, or -1 if none */\n #pendingRowAnimation = -1;\n\n /**\n * Invalid cell tracking: Map<rowId, Map<field, message>>\n * Used for validation feedback without canceling edits.\n */\n #invalidCells = new Map<string, Map<string, string>>();\n\n /**\n * In grid mode, tracks whether an input field is currently focused.\n * When true: arrow keys work within input (edit mode).\n * When false: arrow keys navigate between cells (navigation mode).\n * Escape switches to navigation mode, Enter switches to edit mode.\n */\n #gridModeInputFocused = false;\n\n /**\n * In grid mode, when true, prevents inputs from auto-focusing.\n * This is set when Escape is pressed (navigation mode) and cleared\n * when Enter is pressed or user explicitly clicks an input.\n */\n #gridModeEditLocked = false;\n\n /**\n * When true, only a single cell is being edited (triggered by F2 or `beginCellEdit`).\n * Tab and Arrow keys commit and close the editor instead of navigating to adjacent cells.\n */\n #singleCellEdit = false;\n\n // #endregion\n\n // #region Lifecycle\n\n /** @internal */\n override attach(grid: GridElement): void {\n super.attach(grid);\n\n const signal = this.disconnectSignal;\n const internalGrid = grid as unknown as InternalGrid<T>;\n\n // Inject editing state and methods onto grid for backward compatibility\n internalGrid._activeEditRows = -1;\n internalGrid._rowEditSnapshots = new Map();\n\n // Inject changedRows getter\n Object.defineProperty(grid, 'changedRows', {\n get: () => this.changedRows,\n configurable: true,\n });\n\n // Inject changedRowIds getter (new ID-based API)\n Object.defineProperty(grid, 'changedRowIds', {\n get: () => this.changedRowIds,\n configurable: true,\n });\n\n // Inject resetChangedRows method\n (grid as any).resetChangedRows = (silent?: boolean) => this.resetChangedRows(silent);\n\n // Inject beginBulkEdit method (for backward compatibility)\n (grid as any).beginBulkEdit = (rowIndex: number, field?: string) => {\n if (field) {\n this.beginCellEdit(rowIndex, field);\n }\n // If no field specified, we can't start editing without a specific cell\n };\n\n // Document-level Escape to cancel editing (only in 'row' mode)\n document.addEventListener(\n 'keydown',\n (e: KeyboardEvent) => {\n // In grid mode, Escape doesn't exit edit mode\n if (this.#isGridMode) return;\n if (e.key === 'Escape' && this.#activeEditRow !== -1) {\n // Allow users to prevent edit close via callback (e.g., when overlay is open)\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(e);\n if (shouldClose === false) {\n return;\n }\n }\n this.#exitRowEdit(this.#activeEditRow, true);\n }\n },\n { capture: true, signal },\n );\n\n // Click outside to commit editing (only in 'row' mode)\n // Use queueMicrotask to allow pending change events to fire first.\n // This is important for Angular/React editors where the (change) event\n // fires after mousedown but before mouseup/click.\n document.addEventListener(\n 'mousedown',\n (e: MouseEvent) => {\n // In grid mode, clicking outside doesn't exit edit mode\n if (this.#isGridMode) return;\n if (this.#activeEditRow === -1) return;\n const rowEl = internalGrid.findRenderedRowElement?.(this.#activeEditRow);\n if (!rowEl) return;\n const path = (e.composedPath && e.composedPath()) || [];\n if (path.includes(rowEl)) return;\n\n // Check if click is inside a registered external focus container\n // (e.g., overlays, datepickers, dropdowns at <body> level)\n const target = e.target as Node | null;\n if (target && this.grid.containsFocus?.(target)) {\n return;\n }\n\n // Allow users to prevent edit close via callback (e.g., when click is inside an overlay)\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(e);\n if (shouldClose === false) {\n return;\n }\n }\n\n // Delay exit to allow pending change/commit events to fire\n queueMicrotask(() => {\n if (this.#activeEditRow !== -1) {\n this.#exitRowEdit(this.#activeEditRow, false);\n }\n });\n },\n { signal },\n );\n\n // Focus trap: when enabled, prevent focus from leaving the grid\n // while a row is being edited. If focus moves outside the grid\n // (and its registered external containers), reclaim it.\n if (this.config.focusTrap) {\n this.gridElement.addEventListener(\n 'focusout',\n (e: FocusEvent) => {\n // Only trap in row mode when actively editing\n if (this.#isGridMode) return;\n if (this.#activeEditRow === -1) return;\n\n const related = e.relatedTarget as Node | null;\n // If focus is going to an external container, that's fine\n if (related && this.grid.containsFocus?.(related)) return;\n // If focus is going to another element inside the grid, allow it\n if (related && this.gridElement.contains(related)) return;\n\n // Focus left the grid entirely — reclaim it\n queueMicrotask(() => {\n // Re-check in case editing was committed in the meantime\n if (this.#activeEditRow === -1) return;\n this.#focusCurrentCellEditor();\n });\n },\n { signal },\n );\n }\n\n // Listen for external row mutations to push updated values to active editors.\n // When field A commits and sets field B via updateRow(), field B's editor\n // (if open) must reflect the new value.\n this.gridElement.addEventListener(\n 'cell-change',\n (e: Event) => {\n const detail = (e as CustomEvent).detail as {\n rowIndex: number;\n field: string;\n newValue: unknown;\n source: string;\n };\n // Only push updates from cascade/api sources — not from the editor's own commit\n if (detail.source === 'user') return;\n const key = `${detail.rowIndex}:${detail.field}`;\n const cb = this.#editorValueCallbacks.get(key);\n if (cb) cb(detail.newValue);\n },\n { signal },\n );\n\n // In grid mode, request a full render to trigger afterCellRender hooks\n if (this.#isGridMode) {\n internalGrid._isGridEditMode = true;\n this.gridElement.classList.add('tbw-grid-mode');\n this.requestRender();\n\n // Track focus/blur on inputs to maintain navigation vs edit mode state\n this.gridElement.addEventListener(\n 'focusin',\n (e: FocusEvent) => {\n const target = e.target as HTMLElement;\n if (target.matches(FOCUSABLE_EDITOR_SELECTOR)) {\n // If edit is locked (navigation mode), blur the input immediately\n if (this.#gridModeEditLocked) {\n target.blur();\n this.gridElement.focus();\n return;\n }\n this.#gridModeInputFocused = true;\n }\n },\n { signal },\n );\n\n this.gridElement.addEventListener(\n 'focusout',\n (e: FocusEvent) => {\n const related = e.relatedTarget as HTMLElement | null;\n // Only clear if focus went outside grid (and external containers) or to a non-input element\n if (\n !related ||\n (!this.gridElement.contains(related) && !this.grid.containsFocus?.(related)) ||\n !related.matches(FOCUSABLE_EDITOR_SELECTOR)\n ) {\n this.#gridModeInputFocused = false;\n }\n },\n { signal },\n );\n\n // Handle Escape key directly on the grid element (capture phase)\n // This ensures we intercept Escape even when focus is inside an input\n this.gridElement.addEventListener(\n 'keydown',\n (e: KeyboardEvent) => {\n if (e.key === 'Escape' && this.#gridModeInputFocused) {\n // Allow users to prevent Escape handling via callback (e.g., when overlay is open).\n // In grid mode, Escape transitions from editing to navigation mode, so we check\n // onBeforeEditClose to let overlays (dropdowns, autocompletes) close first.\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(e);\n if (shouldClose === false) {\n return; // Let the overlay handle Escape\n }\n }\n const activeEl = document.activeElement as HTMLElement;\n if (activeEl && this.gridElement.contains(activeEl)) {\n activeEl.blur();\n // Move focus to the grid container so arrow keys work\n this.gridElement.focus();\n }\n this.#gridModeInputFocused = false;\n this.#gridModeEditLocked = true; // Lock edit mode until Enter/click\n e.preventDefault();\n e.stopPropagation();\n }\n },\n { capture: true, signal },\n );\n\n // Handle click on inputs - unlock edit mode when user explicitly clicks\n this.gridElement.addEventListener(\n 'mousedown',\n (e: MouseEvent) => {\n const target = e.target as HTMLElement;\n if (target.matches(FOCUSABLE_EDITOR_SELECTOR)) {\n this.#gridModeEditLocked = false; // User clicked input - allow edit\n }\n },\n { signal },\n );\n }\n }\n\n /** @internal */\n override detach(): void {\n const internalGrid = this.gridElement as unknown as InternalGrid<T>;\n internalGrid._isGridEditMode = false;\n this.gridElement.classList.remove('tbw-grid-mode');\n this.#activeEditRow = -1;\n this.#activeEditRowId = undefined;\n this.#activeEditRowRef = undefined;\n this.#activeEditCol = -1;\n this.#rowEditSnapshots.clear();\n this.#changedRowIds.clear();\n this.#editingCells.clear();\n this.#editorValueCallbacks.clear();\n this.#gridModeInputFocused = false;\n this.#gridModeEditLocked = false;\n this.#singleCellEdit = false;\n super.detach();\n }\n\n /**\n * Handle plugin queries.\n * @internal\n */\n override handleQuery(query: PluginQuery): unknown {\n if (query.type === 'isEditing') {\n // In grid mode, we're always editing\n return this.#isGridMode || this.#activeEditRow !== -1;\n }\n return undefined;\n }\n\n // #endregion\n\n // #region Event Handlers (event distribution)\n\n /**\n * Handle cell clicks - start editing if configured for click mode.\n * Both click and dblclick events come through this handler.\n * Starts row-based editing (all editable cells in the row get editors).\n * @internal\n */\n override onCellClick(event: CellClickEvent): boolean | void {\n // In grid mode, all cells are already editable - no need to trigger row edit\n if (this.#isGridMode) return false;\n\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const editOn = this.config.editOn ?? internalGrid.effectiveConfig?.editOn;\n\n // Check if editing is disabled\n if (editOn === false || editOn === 'manual') return false;\n\n // Check if this is click or dblclick mode\n if (editOn !== 'click' && editOn !== 'dblclick') return false;\n\n // Check if the event type matches the edit mode\n const isDoubleClick = event.originalEvent.type === 'dblclick';\n if (editOn === 'click' && isDoubleClick) return false; // In click mode, only handle single clicks\n if (editOn === 'dblclick' && !isDoubleClick) return false; // In dblclick mode, only handle double clicks\n\n const { rowIndex } = event;\n\n // Check if any column in the row is editable\n const hasEditableColumn = internalGrid._columns?.some((col) => col.editable);\n if (!hasEditableColumn) return false;\n\n // Start row-based editing (all editable cells get editors)\n event.originalEvent.stopPropagation();\n this.beginBulkEdit(rowIndex);\n return true; // Handled\n }\n\n /**\n * Handle keyboard events for edit lifecycle.\n * @internal\n */\n override onKeyDown(event: KeyboardEvent): boolean | void {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n\n // Escape: cancel current edit (row mode) or exit edit mode (grid mode)\n if (event.key === 'Escape') {\n // In grid mode: blur input to enable arrow key navigation\n if (this.#isGridMode && this.#gridModeInputFocused) {\n // Allow users to prevent Escape handling via callback (e.g., when overlay is open)\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(event);\n if (shouldClose === false) {\n return true; // Handled: block grid navigation, let overlay handle Escape\n }\n }\n const activeEl = document.activeElement as HTMLElement;\n if (activeEl && this.gridElement.contains(activeEl)) {\n activeEl.blur();\n }\n this.#gridModeInputFocused = false;\n // Update focus styling\n this.requestAfterRender();\n return true;\n }\n\n // In row mode: cancel edit\n if (this.#activeEditRow !== -1 && !this.#isGridMode) {\n // Allow users to prevent edit close via callback (e.g., when overlay is open)\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(event);\n if (shouldClose === false) {\n return true; // Handled: block grid navigation, let event reach overlay\n }\n }\n this.#exitRowEdit(this.#activeEditRow, true);\n return true;\n }\n }\n\n // Arrow keys in grid mode when not editing input: navigate cells\n if (\n this.#isGridMode &&\n !this.#gridModeInputFocused &&\n (event.key === 'ArrowUp' || event.key === 'ArrowDown' || event.key === 'ArrowLeft' || event.key === 'ArrowRight')\n ) {\n // Let the grid's default keyboard navigation handle this\n return false;\n }\n\n // Arrow Up/Down in grid mode when input is focused: let the editor handle it\n // (e.g., ArrowDown opens autocomplete/datepicker overlays, ArrowUp/Down navigates options)\n if (this.#isGridMode && this.#gridModeInputFocused && (event.key === 'ArrowUp' || event.key === 'ArrowDown')) {\n return true; // Handled: block grid navigation, let event reach editor\n }\n\n // Arrow Up/Down while editing: commit and exit edit mode, move to adjacent row (only in 'row' mode)\n if ((event.key === 'ArrowUp' || event.key === 'ArrowDown') && this.#activeEditRow !== -1 && !this.#isGridMode) {\n // Allow users to prevent row navigation via callback (e.g., when dropdown is open)\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(event);\n if (shouldClose === false) {\n return true; // Handled: block grid navigation, let event reach dropdown\n }\n }\n\n const maxRow = internalGrid._rows.length - 1;\n const currentRow = this.#activeEditRow;\n\n // Commit the current edit\n this.#exitRowEdit(currentRow, false);\n\n // Move focus to adjacent row (same column)\n if (event.key === 'ArrowDown') {\n internalGrid._focusRow = Math.min(maxRow, internalGrid._focusRow + 1);\n } else {\n internalGrid._focusRow = Math.max(0, internalGrid._focusRow - 1);\n }\n\n event.preventDefault();\n // Ensure the focused cell is scrolled into view\n ensureCellVisible(internalGrid);\n // Request render to update focus styling\n this.requestAfterRender();\n return true;\n }\n\n // Tab/Shift+Tab while editing: move to next/prev editable cell\n if (event.key === 'Tab' && (this.#activeEditRow !== -1 || this.#isGridMode)) {\n event.preventDefault();\n\n // In single-cell edit mode (F2), commit and close instead of navigating\n if (this.#singleCellEdit) {\n this.#exitRowEdit(this.#activeEditRow, false);\n return true;\n }\n\n const forward = !event.shiftKey;\n this.#handleTabNavigation(forward);\n return true;\n }\n\n // Space: toggle boolean cells (only when not in edit mode - let editors handle their own space)\n if (event.key === ' ' || event.key === 'Spacebar') {\n // If we're in row edit mode, let the event pass through to the editor (e.g., checkbox)\n if (this.#activeEditRow !== -1) {\n return false;\n }\n\n const focusRow = internalGrid._focusRow;\n const focusCol = internalGrid._focusCol;\n if (focusRow >= 0 && focusCol >= 0) {\n const column = internalGrid._visibleColumns[focusCol];\n const rowData = internalGrid._rows[focusRow];\n if (column?.editable && column.type === 'boolean' && rowData) {\n const field = column.field;\n if (isSafePropertyKey(field)) {\n const currentValue = (rowData as Record<string, unknown>)[field];\n const newValue = !currentValue;\n this.#commitCellValue(focusRow, column, newValue, rowData);\n event.preventDefault();\n // Re-render to update the UI\n this.requestRender();\n return true;\n }\n }\n }\n // Space on non-boolean cell - don't block keyboard navigation\n return false;\n }\n\n // Enter (unmodified): start row edit, commit, or enter edit mode in grid mode\n if (event.key === 'Enter' && !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey) {\n // In grid mode when not editing: focus the current cell's input\n if (this.#isGridMode && !this.#gridModeInputFocused) {\n this.#focusCurrentCellEditor();\n return true;\n }\n\n if (this.#activeEditRow !== -1) {\n // Allow users to prevent edit close via callback (e.g., when overlay is open)\n // This lets Enter select an item in a dropdown instead of committing the row\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(event);\n if (shouldClose === false) {\n return true; // Handled: block grid navigation, let event reach overlay\n }\n }\n // Already editing - let cell handlers deal with it\n return false;\n }\n\n // Start row-based editing (not just the focused cell)\n const editOn = this.config.editOn ?? internalGrid.effectiveConfig?.editOn;\n if (editOn === false || editOn === 'manual') return false;\n\n const focusRow = internalGrid._focusRow;\n const focusCol = internalGrid._focusCol;\n if (focusRow >= 0) {\n // Check if ANY column in the row is editable\n const hasEditableColumn = internalGrid._columns?.some((col) => col.editable);\n if (hasEditableColumn) {\n // Emit cell-activate event BEFORE starting edit\n // This ensures consumers always get the activation event\n const column = internalGrid._visibleColumns[focusCol];\n const row = internalGrid._rows[focusRow];\n const field = column?.field ?? '';\n const value = field && row ? (row as Record<string, unknown>)[field] : undefined;\n const cellEl = this.gridElement.querySelector(`[data-row=\"${focusRow}\"][data-col=\"${focusCol}\"]`) as\n | HTMLElement\n | undefined;\n\n const activateEvent = new CustomEvent('cell-activate', {\n cancelable: true,\n bubbles: true,\n detail: {\n rowIndex: focusRow,\n colIndex: focusCol,\n field,\n value,\n row,\n cellEl,\n trigger: 'keyboard' as const,\n originalEvent: event,\n },\n });\n this.gridElement.dispatchEvent(activateEvent);\n\n // Also emit deprecated activate-cell for backwards compatibility\n const legacyEvent = new CustomEvent('activate-cell', {\n cancelable: true,\n bubbles: true,\n detail: { row: focusRow, col: focusCol },\n });\n this.gridElement.dispatchEvent(legacyEvent);\n\n // If consumer canceled the activation, don't start editing\n if (activateEvent.defaultPrevented || legacyEvent.defaultPrevented) {\n event.preventDefault();\n return true;\n }\n\n this.beginBulkEdit(focusRow);\n return true;\n }\n }\n // No editable columns - don't block keyboard navigation\n return false;\n }\n\n // F2: begin single-cell edit on the focused cell\n if (event.key === 'F2') {\n if (this.#activeEditRow !== -1 || this.#isGridMode) return false;\n\n const editOn = this.config.editOn ?? internalGrid.effectiveConfig?.editOn;\n if (editOn === false) return false;\n\n const focusRow = internalGrid._focusRow;\n const focusCol = internalGrid._focusCol;\n if (focusRow >= 0 && focusCol >= 0) {\n const column = internalGrid._visibleColumns[focusCol];\n if (column?.editable && column.field) {\n event.preventDefault();\n this.beginCellEdit(focusRow, column.field);\n return true;\n }\n }\n return false;\n }\n\n // Don't block other keyboard events\n return false;\n }\n\n // #endregion\n\n // #region Render Hooks\n\n /**\n * Process columns to merge type-level editorParams with column-level.\n * Column-level params take precedence.\n * @internal\n */\n override processColumns(columns: ColumnConfig<T>[]): ColumnConfig<T>[] {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const typeDefaults = (internalGrid as any).effectiveConfig?.typeDefaults;\n const adapter = internalGrid.__frameworkAdapter;\n\n // If no type defaults configured anywhere, skip processing\n if (!typeDefaults && !adapter?.getTypeDefault) return columns;\n\n return columns.map((col) => {\n if (!col.type) return col;\n\n // Get type-level editorParams\n let typeEditorParams: Record<string, unknown> | undefined;\n\n // Check grid-level typeDefaults first\n if (typeDefaults?.[col.type]?.editorParams) {\n typeEditorParams = typeDefaults[col.type].editorParams;\n }\n\n // Then check app-level (adapter) typeDefaults\n if (!typeEditorParams && adapter?.getTypeDefault) {\n const appDefault = adapter.getTypeDefault<T>(col.type);\n if (appDefault?.editorParams) {\n typeEditorParams = appDefault.editorParams;\n }\n }\n\n // No type-level params to merge\n if (!typeEditorParams) return col;\n\n // Merge: type-level as base, column-level wins on conflicts\n return {\n ...col,\n editorParams: { ...typeEditorParams, ...col.editorParams },\n };\n });\n }\n\n /**\n * After render, reapply editors to cells in edit mode.\n * This handles virtualization - when a row scrolls back into view,\n * we need to re-inject the editor.\n * @internal\n */\n override afterRender(): void {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n\n // Restore focus after exiting edit mode\n if (this.#pendingFocusRestore) {\n this.#pendingFocusRestore = false;\n this.#restoreCellFocus(internalGrid);\n }\n\n // Animate the row after render completes (so the row element exists)\n if (this.#pendingRowAnimation !== -1) {\n const rowIndex = this.#pendingRowAnimation;\n this.#pendingRowAnimation = -1;\n internalGrid.animateRow?.(rowIndex, 'change');\n }\n\n // In 'grid' mode, editors are injected via afterCellRender hook during render\n if (this.#isGridMode) return;\n\n if (this.#editingCells.size === 0) return;\n\n // Re-inject editors for any editing cells that are visible\n for (const cellKey of this.#editingCells) {\n const [rowStr, colStr] = cellKey.split(':');\n const rowIndex = parseInt(rowStr, 10);\n const colIndex = parseInt(colStr, 10);\n\n const rowEl = internalGrid.findRenderedRowElement?.(rowIndex);\n if (!rowEl) continue;\n\n const cellEl = rowEl.querySelector(`.cell[data-col=\"${colIndex}\"]`) as HTMLElement | null;\n if (!cellEl || cellEl.classList.contains('editing')) continue;\n\n // Cell is visible but not in editing mode - reinject editor\n const rowData = internalGrid._rows[rowIndex];\n const column = internalGrid._visibleColumns[colIndex];\n if (rowData && column) {\n this.#injectEditor(rowData, rowIndex, column, colIndex, cellEl, true);\n }\n }\n }\n\n /**\n * Hook called after each cell is rendered.\n * In grid mode, injects editors into editable cells during render (no DOM queries needed).\n * @internal\n */\n override afterCellRender(context: AfterCellRenderContext): void {\n // Only inject editors in grid mode\n if (!this.#isGridMode) return;\n\n const { row, rowIndex, column, colIndex, cellElement } = context;\n\n // Skip non-editable columns\n if (!column.editable) return;\n\n // Skip if already has editor\n if (cellElement.classList.contains('editing')) return;\n\n // Inject editor (don't track in editingCells - we're always editing in grid mode)\n this.#injectEditor(row as T, rowIndex, column as ColumnConfig<T>, colIndex, cellElement, true);\n }\n\n /**\n * On scroll render, reapply editors to recycled cells.\n * @internal\n */\n override onScrollRender(): void {\n this.afterRender();\n }\n\n // #endregion\n\n // #region Public API\n\n /**\n * Get all rows that have been modified.\n * Uses ID-based lookup for stability when rows are reordered.\n */\n get changedRows(): T[] {\n const rows: T[] = [];\n for (const id of this.#changedRowIds) {\n const row = this.grid.getRow(id) as T | undefined;\n if (row) rows.push(row);\n }\n return rows;\n }\n\n /**\n * Get IDs of all modified rows.\n */\n get changedRowIds(): string[] {\n return Array.from(this.#changedRowIds);\n }\n\n /**\n * Get the currently active edit row index, or -1 if not editing.\n */\n get activeEditRow(): number {\n return this.#activeEditRow;\n }\n\n /**\n * Get the currently active edit column index, or -1 if not editing.\n */\n get activeEditCol(): number {\n return this.#activeEditCol;\n }\n\n /**\n * Check if a specific row is currently being edited.\n */\n isRowEditing(rowIndex: number): boolean {\n return this.#activeEditRow === rowIndex;\n }\n\n /**\n * Check if a specific cell is currently being edited.\n */\n isCellEditing(rowIndex: number, colIndex: number): boolean {\n return this.#editingCells.has(`${rowIndex}:${colIndex}`);\n }\n\n /**\n * Check if a specific row has been modified.\n * @param rowIndex - Row index to check (will be converted to ID internally)\n */\n isRowChanged(rowIndex: number): boolean {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const row = internalGrid._rows[rowIndex];\n if (!row) return false;\n try {\n const rowId = internalGrid.getRowId?.(row);\n return rowId ? this.#changedRowIds.has(rowId) : false;\n } catch {\n return false;\n }\n }\n\n /**\n * Check if a row with the given ID has been modified.\n * @param rowId - Row ID to check\n */\n isRowChangedById(rowId: string): boolean {\n return this.#changedRowIds.has(rowId);\n }\n\n // #region Cell Validation\n\n /**\n * Mark a cell as invalid with an optional validation message.\n * Invalid cells are marked with a `data-invalid` attribute for styling.\n *\n * @param rowId - The row ID (from getRowId)\n * @param field - The field name\n * @param message - Optional validation message (for tooltips or display)\n *\n * @example\n * ```typescript\n * // In cell-commit handler:\n * grid.addEventListener('cell-commit', (e) => {\n * if (e.detail.field === 'email' && !isValidEmail(e.detail.value)) {\n * e.detail.setInvalid('Invalid email format');\n * }\n * });\n *\n * // Or programmatically:\n * editingPlugin.setInvalid('row-123', 'email', 'Invalid email format');\n * ```\n */\n setInvalid(rowId: string, field: string, message = ''): void {\n let rowInvalids = this.#invalidCells.get(rowId);\n if (!rowInvalids) {\n rowInvalids = new Map();\n this.#invalidCells.set(rowId, rowInvalids);\n }\n rowInvalids.set(field, message);\n this.#syncInvalidCellAttribute(rowId, field, true);\n }\n\n /**\n * Clear the invalid state for a specific cell.\n *\n * @param rowId - The row ID (from getRowId)\n * @param field - The field name\n */\n clearInvalid(rowId: string, field: string): void {\n const rowInvalids = this.#invalidCells.get(rowId);\n if (rowInvalids) {\n rowInvalids.delete(field);\n if (rowInvalids.size === 0) {\n this.#invalidCells.delete(rowId);\n }\n }\n this.#syncInvalidCellAttribute(rowId, field, false);\n }\n\n /**\n * Clear all invalid cells for a specific row.\n *\n * @param rowId - The row ID (from getRowId)\n */\n clearRowInvalid(rowId: string): void {\n const rowInvalids = this.#invalidCells.get(rowId);\n if (rowInvalids) {\n const fields = Array.from(rowInvalids.keys());\n this.#invalidCells.delete(rowId);\n fields.forEach((field) => this.#syncInvalidCellAttribute(rowId, field, false));\n }\n }\n\n /**\n * Clear all invalid cell states across all rows.\n */\n clearAllInvalid(): void {\n const entries = Array.from(this.#invalidCells.entries());\n this.#invalidCells.clear();\n entries.forEach(([rowId, fields]) => {\n fields.forEach((_, field) => this.#syncInvalidCellAttribute(rowId, field, false));\n });\n }\n\n /**\n * Check if a specific cell is marked as invalid.\n *\n * @param rowId - The row ID (from getRowId)\n * @param field - The field name\n * @returns True if the cell is marked as invalid\n */\n isCellInvalid(rowId: string, field: string): boolean {\n return this.#invalidCells.get(rowId)?.has(field) ?? false;\n }\n\n /**\n * Get the validation message for an invalid cell.\n *\n * @param rowId - The row ID (from getRowId)\n * @param field - The field name\n * @returns The validation message, or undefined if cell is valid\n */\n getInvalidMessage(rowId: string, field: string): string | undefined {\n return this.#invalidCells.get(rowId)?.get(field);\n }\n\n /**\n * Check if a row has any invalid cells.\n *\n * @param rowId - The row ID (from getRowId)\n * @returns True if the row has at least one invalid cell\n */\n hasInvalidCells(rowId: string): boolean {\n const rowInvalids = this.#invalidCells.get(rowId);\n return rowInvalids ? rowInvalids.size > 0 : false;\n }\n\n /**\n * Get all invalid fields for a row.\n *\n * @param rowId - The row ID (from getRowId)\n * @returns Map of field names to validation messages\n */\n getInvalidFields(rowId: string): Map<string, string> {\n return new Map(this.#invalidCells.get(rowId) ?? []);\n }\n\n /**\n * Sync the data-invalid attribute on a cell element.\n */\n #syncInvalidCellAttribute(rowId: string, field: string, invalid: boolean): void {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const colIndex = internalGrid._visibleColumns?.findIndex((c) => c.field === field);\n if (colIndex === -1 || colIndex === undefined) return;\n\n // Find the row element by rowId\n const rows = internalGrid._rows;\n const rowIndex = rows?.findIndex((r) => {\n try {\n return internalGrid.getRowId?.(r) === rowId;\n } catch {\n return false;\n }\n });\n if (rowIndex === -1 || rowIndex === undefined) return;\n\n const rowEl = internalGrid.findRenderedRowElement?.(rowIndex);\n const cellEl = rowEl?.querySelector(`.cell[data-col=\"${colIndex}\"]`) as HTMLElement | null;\n if (!cellEl) return;\n\n if (invalid) {\n cellEl.setAttribute('data-invalid', 'true');\n const message = this.#invalidCells.get(rowId)?.get(field);\n if (message) {\n cellEl.setAttribute('title', message);\n }\n } else {\n cellEl.removeAttribute('data-invalid');\n cellEl.removeAttribute('title');\n }\n }\n\n // #endregion\n\n /**\n * Reset all change tracking.\n * @param silent - If true, suppresses the `changed-rows-reset` event\n * @fires changed-rows-reset - Emitted when tracking is reset (unless silent)\n */\n resetChangedRows(silent?: boolean): void {\n const rows = this.changedRows;\n const ids = this.changedRowIds;\n this.#changedRowIds.clear();\n this.#syncGridEditState();\n\n if (!silent) {\n this.emit<ChangedRowsResetDetail<T>>('changed-rows-reset', { rows, ids });\n }\n\n // Clear visual indicators\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n internalGrid._rowPool?.forEach((r) => r.classList.remove('changed'));\n }\n\n /**\n * Programmatically begin editing a cell.\n * @param rowIndex - Index of the row to edit\n * @param field - Field name of the column to edit\n * @fires cell-commit - Emitted when the cell value is committed (on blur or Enter)\n */\n beginCellEdit(rowIndex: number, field: string): void {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const colIndex = internalGrid._visibleColumns.findIndex((c) => c.field === field);\n if (colIndex === -1) return;\n\n const column = internalGrid._visibleColumns[colIndex];\n if (!column?.editable) return;\n\n const rowEl = internalGrid.findRenderedRowElement?.(rowIndex);\n const cellEl = rowEl?.querySelector(`.cell[data-col=\"${colIndex}\"]`) as HTMLElement | null;\n if (!cellEl) return;\n\n this.#singleCellEdit = true;\n this.#beginCellEdit(rowIndex, colIndex, cellEl);\n }\n\n /**\n * Programmatically begin editing all editable cells in a row.\n * @param rowIndex - Index of the row to edit\n * @fires cell-commit - Emitted for each cell value that is committed\n * @fires row-commit - Emitted when focus leaves the row\n */\n beginBulkEdit(rowIndex: number): void {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const editOn = this.config.editOn ?? internalGrid.effectiveConfig?.editOn;\n if (editOn === false) return;\n\n const hasEditableColumn = internalGrid._columns?.some((col) => col.editable);\n if (!hasEditableColumn) return;\n\n const rowEl = internalGrid.findRenderedRowElement?.(rowIndex);\n if (!rowEl) return;\n\n // Bulk edit clears single-cell mode\n this.#singleCellEdit = false;\n\n // Start row edit\n const rowData = internalGrid._rows[rowIndex];\n this.#startRowEdit(rowIndex, rowData);\n\n // Enter edit mode on all editable cells\n Array.from(rowEl.children).forEach((cell, i) => {\n const col = internalGrid._visibleColumns[i];\n if (col?.editable) {\n const cellEl = cell as HTMLElement;\n if (!cellEl.classList.contains('editing')) {\n this.#injectEditor(rowData, rowIndex, col, i, cellEl, true);\n }\n }\n });\n\n // Focus the first editable cell\n setTimeout(() => {\n let targetCell = rowEl.querySelector(`.cell[data-col=\"${internalGrid._focusCol}\"]`);\n if (!targetCell?.classList.contains('editing')) {\n targetCell = rowEl.querySelector('.cell.editing');\n }\n if (targetCell?.classList.contains('editing')) {\n const editor = (targetCell as HTMLElement).querySelector(FOCUSABLE_EDITOR_SELECTOR) as HTMLElement | null;\n try {\n editor?.focus({ preventScroll: true });\n } catch {\n /* empty */\n }\n }\n }, 0);\n }\n\n /**\n * Commit the currently active row edit.\n * @fires row-commit - Emitted after the row edit is committed\n */\n commitActiveRowEdit(): void {\n if (this.#activeEditRow !== -1) {\n this.#exitRowEdit(this.#activeEditRow, false);\n }\n }\n\n /**\n * Cancel the currently active row edit.\n */\n cancelActiveRowEdit(): void {\n if (this.#activeEditRow !== -1) {\n this.#exitRowEdit(this.#activeEditRow, true);\n }\n }\n\n // #endregion\n\n // #region Internal Methods\n\n /**\n * Begin editing a single cell.\n */\n #beginCellEdit(rowIndex: number, colIndex: number, cellEl: HTMLElement): void {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const rowData = internalGrid._rows[rowIndex];\n const column = internalGrid._visibleColumns[colIndex];\n\n if (!rowData || !column?.editable) return;\n if (cellEl.classList.contains('editing')) return;\n\n // Start row edit if not already\n if (this.#activeEditRow !== rowIndex) {\n this.#startRowEdit(rowIndex, rowData);\n }\n\n this.#activeEditCol = colIndex;\n this.#injectEditor(rowData, rowIndex, column, colIndex, cellEl, false);\n }\n\n /**\n * Focus the editor input in the currently focused cell (grid mode only).\n * Used when pressing Enter to enter edit mode from navigation mode.\n */\n #focusCurrentCellEditor(): void {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const focusRow = internalGrid._focusRow;\n const focusCol = internalGrid._focusCol;\n\n if (focusRow < 0 || focusCol < 0) return;\n\n const rowEl = internalGrid.findRenderedRowElement?.(focusRow);\n const cellEl = rowEl?.querySelector(`.cell[data-col=\"${focusCol}\"]`) as HTMLElement | null;\n\n if (cellEl?.classList.contains('editing')) {\n const editor = cellEl.querySelector(FOCUSABLE_EDITOR_SELECTOR) as HTMLElement | null;\n if (editor) {\n this.#gridModeEditLocked = false; // Unlock edit mode - user pressed Enter\n editor.focus();\n this.#gridModeInputFocused = true;\n // Select all text in text inputs for quick replacement\n if (editor instanceof HTMLInputElement && (editor.type === 'text' || editor.type === 'number')) {\n editor.select();\n }\n }\n }\n }\n\n /**\n * Handle Tab/Shift+Tab navigation while editing.\n * Moves to next/previous editable cell, staying in edit mode.\n * Wraps to next/previous row when reaching row boundaries.\n */\n #handleTabNavigation(forward: boolean): void {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const rows = internalGrid._rows;\n // In grid mode, use focusRow since there's no active edit row\n const currentRow = this.#isGridMode ? internalGrid._focusRow : this.#activeEditRow;\n\n // Get editable column indices\n const editableCols = internalGrid._visibleColumns.map((c, i) => (c.editable ? i : -1)).filter((i) => i >= 0);\n if (editableCols.length === 0) return;\n\n const currentIdx = editableCols.indexOf(internalGrid._focusCol);\n const nextIdx = currentIdx + (forward ? 1 : -1);\n\n // Can move within same row?\n if (nextIdx >= 0 && nextIdx < editableCols.length) {\n internalGrid._focusCol = editableCols[nextIdx];\n const rowEl = internalGrid.findRenderedRowElement?.(currentRow);\n const cellEl = rowEl?.querySelector(`.cell[data-col=\"${editableCols[nextIdx]}\"]`) as HTMLElement | null;\n if (cellEl?.classList.contains('editing')) {\n const editor = cellEl.querySelector(FOCUSABLE_EDITOR_SELECTOR) as HTMLElement | null;\n editor?.focus({ preventScroll: true });\n }\n ensureCellVisible(internalGrid, { forceHorizontalScroll: true });\n return;\n }\n\n // Can move to adjacent row?\n const nextRow = currentRow + (forward ? 1 : -1);\n if (nextRow >= 0 && nextRow < rows.length) {\n // In grid mode, just move focus (all rows are always editable)\n if (this.#isGridMode) {\n internalGrid._focusRow = nextRow;\n internalGrid._focusCol = forward ? editableCols[0] : editableCols[editableCols.length - 1];\n ensureCellVisible(internalGrid, { forceHorizontalScroll: true });\n // Focus the editor in the new cell after render\n this.requestAfterRender();\n setTimeout(() => {\n const rowEl = internalGrid.findRenderedRowElement?.(nextRow);\n const cellEl = rowEl?.querySelector(`.cell[data-col=\"${internalGrid._focusCol}\"]`) as HTMLElement | null;\n if (cellEl?.classList.contains('editing')) {\n const editor = cellEl.querySelector(FOCUSABLE_EDITOR_SELECTOR) as HTMLElement | null;\n editor?.focus({ preventScroll: true });\n }\n }, 0);\n } else {\n // In row mode, commit current row and enter next row\n this.#exitRowEdit(currentRow, false);\n internalGrid._focusRow = nextRow;\n internalGrid._focusCol = forward ? editableCols[0] : editableCols[editableCols.length - 1];\n this.beginBulkEdit(nextRow);\n ensureCellVisible(internalGrid, { forceHorizontalScroll: true });\n }\n }\n // else: at boundary - stay put\n }\n\n /**\n * Sync the internal grid state with the plugin's editing state.\n */\n #syncGridEditState(): void {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n internalGrid._activeEditRows = this.#activeEditRow;\n internalGrid._rowEditSnapshots = this.#rowEditSnapshots;\n }\n\n /**\n * Snapshot original row data and mark as editing.\n */\n #startRowEdit(rowIndex: number, rowData: T): void {\n if (this.#activeEditRow !== rowIndex) {\n this.#rowEditSnapshots.set(rowIndex, { ...rowData });\n this.#activeEditRow = rowIndex;\n this.#activeEditRowRef = rowData;\n\n // Store stable row ID for resilience against _rows replacement during editing\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n try {\n this.#activeEditRowId = internalGrid.getRowId?.(rowData) ?? undefined;\n } catch {\n this.#activeEditRowId = undefined;\n }\n\n this.#syncGridEditState();\n\n // Emit edit-open event (row mode only)\n if (!this.#isGridMode) {\n this.emit<EditOpenDetail<T>>('edit-open', {\n rowIndex,\n rowId: this.#activeEditRowId ?? '',\n row: rowData,\n });\n }\n }\n }\n\n /**\n * Exit editing for a row.\n */\n #exitRowEdit(rowIndex: number, revert: boolean): void {\n if (this.#activeEditRow !== rowIndex) return;\n\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const snapshot = this.#rowEditSnapshots.get(rowIndex);\n const rowEl = internalGrid.findRenderedRowElement?.(rowIndex);\n\n // Resolve the row being edited using the stored row ID.\n // The _rows array may have been replaced (e.g. Angular pushing new rows\n // via directive effect) since editing started, so _rows[rowIndex] could\n // point to a completely different row. The ID map is always up-to-date.\n // Without an ID we fall back to the stored row reference from edit-open\n // (#activeEditRowRef) — safer than _rows[rowIndex] which may be stale.\n let rowId = this.#activeEditRowId;\n const entry = rowId ? internalGrid._getRowEntry(rowId) : undefined;\n const current = entry?.row ?? this.#activeEditRowRef ?? internalGrid._rows[rowIndex];\n\n if (!rowId && current) {\n try {\n rowId = internalGrid.getRowId?.(current);\n } catch {\n // Row has no ID - skip ID-based tracking\n }\n }\n\n // Collect and commit values from active editors before re-rendering\n if (!revert && rowEl && current) {\n const editingCells = rowEl.querySelectorAll('.cell.editing');\n editingCells.forEach((cell) => {\n const colIndex = Number((cell as HTMLElement).getAttribute('data-col'));\n if (isNaN(colIndex)) return;\n const col = internalGrid._visibleColumns[colIndex];\n if (!col) return;\n\n // Skip cells with externally-managed editors (framework adapters like Angular/React/Vue).\n // These editors handle their own commits via the commit() callback - we should NOT\n // try to read values from their DOM inputs (which may contain formatted display values).\n if ((cell as HTMLElement).hasAttribute('data-editor-managed')) {\n return;\n }\n\n const input = cell.querySelector('input,textarea,select') as\n | HTMLInputElement\n | HTMLTextAreaElement\n | HTMLSelectElement\n | null;\n if (input) {\n const field = col.field as keyof T;\n const originalValue = current[field];\n const val = getInputValue(input, col, originalValue);\n if (originalValue !== val) {\n this.#commitCellValue(rowIndex, col, val, current);\n }\n }\n });\n }\n\n // Flush managed editors (framework adapters) before clearing state.\n // At this point the commit() callback is still active, so editors can\n // synchronously commit their pending values in response to this event.\n if (!revert && !this.#isGridMode && current) {\n this.emit<BeforeEditCloseDetail<T>>('before-edit-close', {\n rowIndex,\n rowId: rowId ?? '',\n row: current,\n });\n }\n\n // Revert if requested\n if (revert && snapshot && current) {\n Object.keys(snapshot as object).forEach((k) => {\n (current as Record<string, unknown>)[k] = (snapshot as Record<string, unknown>)[k];\n });\n if (rowId) {\n this.#changedRowIds.delete(rowId);\n this.clearRowInvalid(rowId);\n }\n } else if (!revert && current) {\n // Compare snapshot vs current to detect if changes were made during THIS edit session\n const changedThisSession = this.#hasRowChanged(snapshot, current);\n\n // Check if this row has any cumulative changes (via ID tracking)\n // Fall back to session-based detection when no row ID is available\n const changed = rowId ? this.#changedRowIds.has(rowId) : changedThisSession;\n\n // Emit cancelable row-commit event\n const cancelled = this.emitCancelable<RowCommitDetail<T>>('row-commit', {\n rowIndex,\n rowId: rowId ?? '',\n row: current,\n oldValue: snapshot,\n newValue: current,\n changed,\n changedRows: this.changedRows,\n changedRowIds: this.changedRowIds,\n });\n\n // If consumer called preventDefault(), revert the row\n if (cancelled && snapshot) {\n Object.keys(snapshot as object).forEach((k) => {\n (current as Record<string, unknown>)[k] = (snapshot as Record<string, unknown>)[k];\n });\n if (rowId) {\n this.#changedRowIds.delete(rowId);\n this.clearRowInvalid(rowId);\n }\n } else if (!cancelled && changedThisSession && this.isAnimationEnabled) {\n // Animate the row only if changes were made during this edit session\n // (deferred to afterRender so the row element exists after re-render)\n this.#pendingRowAnimation = rowIndex;\n }\n }\n\n // Clear editing state\n this.#rowEditSnapshots.delete(rowIndex);\n this.#activeEditRow = -1;\n this.#activeEditRowId = undefined;\n this.#activeEditRowRef = undefined;\n this.#activeEditCol = -1;\n this.#singleCellEdit = false;\n this.#syncGridEditState();\n\n // Remove all editing cells for this row.\n // Note: these keys use the rowIndex captured at edit-open time. Even if _rows\n // was replaced and the row moved to a different index, the keys still match\n // what was inserted during this edit session (same captured rowIndex).\n for (const cellKey of this.#editingCells) {\n if (cellKey.startsWith(`${rowIndex}:`)) {\n this.#editingCells.delete(cellKey);\n }\n }\n // Remove value-change callbacks for this row (same captured-index rationale)\n for (const callbackKey of this.#editorValueCallbacks.keys()) {\n if (callbackKey.startsWith(`${rowIndex}:`)) {\n this.#editorValueCallbacks.delete(callbackKey);\n }\n }\n\n // Mark that focus should be restored after the upcoming render completes.\n // This must be set BEFORE refreshVirtualWindow because it calls afterRender()\n // synchronously, which reads this flag.\n this.#pendingFocusRestore = true;\n\n // Re-render the row to remove editors\n if (rowEl) {\n // Remove editing class and re-render cells\n rowEl.querySelectorAll('.cell.editing').forEach((cell) => {\n cell.classList.remove('editing');\n clearEditingState(cell.parentElement as RowElementInternal);\n });\n\n // Refresh the virtual window to restore cell content WITHOUT rebuilding\n // the row model. requestRender() would trigger processRows (ROWS phase)\n // which re-sorts — causing the edited row to jump to a new position and\n // disappear from view. refreshVirtualWindow re-renders visible cells from\n // the current _rows order, keeping the row in place until the user\n // explicitly sorts again or new data arrives.\n internalGrid.refreshVirtualWindow(true);\n } else {\n // Row not visible - restore focus immediately (no render will happen)\n this.#restoreCellFocus(internalGrid);\n this.#pendingFocusRestore = false;\n }\n\n // Emit edit-close event (row mode only, fires for both commit and revert)\n if (!this.#isGridMode && current) {\n this.emit<EditCloseDetail<T>>('edit-close', {\n rowIndex,\n rowId: rowId ?? '',\n row: current,\n reverted: revert,\n });\n }\n }\n\n /**\n * Commit a single cell value change.\n * Uses ID-based change tracking for stability when rows are reordered.\n */\n #commitCellValue(rowIndex: number, column: ColumnConfig<T>, newValue: unknown, rowData: T): void {\n const field = column.field;\n if (!isSafePropertyKey(field)) return;\n const oldValue = (rowData as Record<string, unknown>)[field];\n if (oldValue === newValue) return;\n\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n\n // Get row ID for change tracking (may not exist if getRowId not configured)\n let rowId: string | undefined;\n try {\n rowId = this.grid.getRowId(rowData);\n } catch {\n // Row has no ID - will still work but won't be tracked in changedRowIds\n }\n\n const firstTime = rowId ? !this.#changedRowIds.has(rowId) : true;\n\n // Create updateRow helper for cascade updates (noop if row has no ID)\n const updateRow: (changes: Partial<T>) => void = rowId\n ? (changes) => this.grid.updateRow(rowId!, changes as Record<string, unknown>, 'cascade')\n : noopUpdateRow;\n\n // Track whether setInvalid was called during event handling\n let invalidWasSet = false;\n\n // Create setInvalid callback for validation (noop if row has no ID)\n const setInvalid = rowId\n ? (message?: string) => {\n invalidWasSet = true;\n this.setInvalid(rowId!, field, message ?? '');\n }\n : () => {}; // eslint-disable-line @typescript-eslint/no-empty-function\n\n // Emit cancelable event BEFORE applying the value\n const cancelled = this.emitCancelable<CellCommitDetail<T>>('cell-commit', {\n row: rowData,\n rowId: rowId ?? '',\n field,\n oldValue,\n value: newValue,\n rowIndex,\n changedRows: this.changedRows,\n changedRowIds: this.changedRowIds,\n firstTimeForRow: firstTime,\n updateRow,\n setInvalid,\n });\n\n // If consumer called preventDefault(), abort the commit\n if (cancelled) return;\n\n // Clear any previous invalid state for this cell ONLY if setInvalid wasn't called\n // (if setInvalid was called, the handler wants it to remain invalid)\n if (rowId && !invalidWasSet && this.isCellInvalid(rowId, field)) {\n this.clearInvalid(rowId, field);\n }\n\n // Apply the value and mark row as changed\n (rowData as Record<string, unknown>)[field] = newValue;\n if (rowId) {\n this.#changedRowIds.add(rowId);\n }\n this.#syncGridEditState();\n\n // Notify other plugins (e.g., UndoRedoPlugin) about the committed edit\n this.emitPluginEvent('cell-edit-committed', {\n rowIndex,\n field,\n oldValue,\n newValue,\n });\n\n // Mark the row visually as changed (animation happens when row edit closes)\n const rowEl = internalGrid.findRenderedRowElement?.(rowIndex);\n if (rowEl) {\n rowEl.classList.add('changed');\n }\n }\n\n /**\n * Inject an editor into a cell.\n */\n #injectEditor(\n rowData: T,\n rowIndex: number,\n column: ColumnConfig<T>,\n colIndex: number,\n cell: HTMLElement,\n skipFocus: boolean,\n ): void {\n if (!column.editable) return;\n if (cell.classList.contains('editing')) return;\n\n // Get row ID for updateRow helper (may not exist)\n let rowId: string | undefined;\n try {\n rowId = this.grid.getRowId(rowData);\n } catch {\n // Row has no ID\n }\n\n // Create updateRow helper for cascade updates (noop if row has no ID)\n const updateRow: (changes: Partial<T>) => void = rowId\n ? (changes) => this.grid.updateRow(rowId!, changes as Record<string, unknown>, 'cascade')\n : noopUpdateRow;\n\n const originalValue = isSafePropertyKey(column.field)\n ? (rowData as Record<string, unknown>)[column.field]\n : undefined;\n\n cell.classList.add('editing');\n this.#editingCells.add(`${rowIndex}:${colIndex}`);\n\n const rowEl = cell.parentElement as RowElementInternal | null;\n if (rowEl) incrementEditingCount(rowEl);\n\n let editFinalized = false;\n const commit = (newValue: unknown) => {\n // In grid mode, always allow commits (we're always editing)\n // In row mode, only allow commits if we're in an active edit session\n if (editFinalized || (!this.#isGridMode && this.#activeEditRow === -1)) return;\n // Resolve row and index fresh at commit time.\n // With a row ID we use _getRowEntry for O(1) lookup — this is resilient\n // against _rows being replaced (e.g. Angular directive effect).\n // Without a row ID we fall back to the captured rowData reference.\n // Using _rows[rowIndex] without an ID is unsafe: the index may be stale\n // after _rows replacement, which would commit to the WRONG row.\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const entry = rowId ? internalGrid._getRowEntry(rowId) : undefined;\n const currentRowData = (entry?.row ?? rowData) as T;\n const currentIndex = entry?.index ?? rowIndex;\n this.#commitCellValue(currentIndex, column, newValue, currentRowData);\n };\n const cancel = () => {\n editFinalized = true;\n if (isSafePropertyKey(column.field)) {\n // Same ID-first / captured-rowData fallback as commit — see comment above.\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const entry = rowId ? internalGrid._getRowEntry(rowId) : undefined;\n const currentRowData = (entry?.row ?? rowData) as T;\n (currentRowData as Record<string, unknown>)[column.field] = originalValue;\n }\n };\n\n const editorHost = document.createElement('div');\n editorHost.className = 'tbw-editor-host';\n cell.innerHTML = '';\n cell.appendChild(editorHost);\n\n // Keydown handler for Enter/Escape\n editorHost.addEventListener('keydown', (e: KeyboardEvent) => {\n if (e.key === 'Enter') {\n // In grid mode, Enter just commits without exiting\n if (this.#isGridMode) {\n e.stopPropagation();\n e.preventDefault();\n // Get current value and commit\n const input = editorHost.querySelector('input,textarea,select') as\n | HTMLInputElement\n | HTMLTextAreaElement\n | HTMLSelectElement\n | null;\n if (input) {\n commit(getInputValue(input, column as ColumnConfig<unknown>, originalValue));\n }\n return;\n }\n // Allow users to prevent edit close via callback (e.g., when overlay is open)\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(e);\n if (shouldClose === false) {\n return; // Let the event propagate to overlay\n }\n }\n e.stopPropagation();\n e.preventDefault();\n editFinalized = true;\n this.#exitRowEdit(rowIndex, false);\n }\n if (e.key === 'Escape') {\n // In grid mode, Escape doesn't exit edit mode\n if (this.#isGridMode) {\n e.stopPropagation();\n e.preventDefault();\n return;\n }\n // Allow users to prevent edit close via callback (e.g., when overlay is open)\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(e);\n if (shouldClose === false) {\n return; // Let the event propagate to overlay\n }\n }\n e.stopPropagation();\n e.preventDefault();\n cancel();\n this.#exitRowEdit(rowIndex, true);\n }\n });\n\n const colInternal = column as ColumnInternal<T>;\n const tplHolder = colInternal.__editorTemplate;\n // Resolve editor using priority chain: column → template → typeDefaults → adapter → built-in\n const editorSpec = resolveEditor(this.grid as unknown as InternalGrid<T>, colInternal) ?? defaultEditorFor(column);\n const value = originalValue;\n\n // Value-change callback registration.\n // Editors call onValueChange(cb) to receive pushes when the underlying row\n // is mutated externally (e.g., via updateRow from another cell's commit).\n // Multiple callbacks can be registered (user + auto-wire).\n const callbackKey = `${rowIndex}:${column.field}`;\n const callbacks: Array<(newValue: unknown) => void> = [];\n this.#editorValueCallbacks.set(callbackKey, (newVal) => {\n for (const cb of callbacks) cb(newVal);\n });\n const onValueChange = (cb: (newValue: unknown) => void) => {\n callbacks.push(cb);\n };\n\n if (editorSpec === 'template' && tplHolder) {\n this.#renderTemplateEditor(editorHost, colInternal, rowData, originalValue, commit, cancel, skipFocus, rowIndex);\n // Auto-update built-in template editors when value changes externally\n onValueChange((newVal) => {\n const input = editorHost.querySelector<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>(\n 'input,textarea,select',\n );\n if (input) {\n if (input instanceof HTMLInputElement && input.type === 'checkbox') {\n input.checked = !!newVal;\n } else {\n input.value = String(newVal ?? '');\n }\n }\n });\n } else if (typeof editorSpec === 'string') {\n const el = document.createElement(editorSpec) as HTMLElement & { value?: unknown };\n el.value = value;\n el.addEventListener('change', () => commit(el.value));\n // Auto-update custom element editors when value changes externally\n onValueChange((newVal) => {\n el.value = newVal;\n });\n editorHost.appendChild(el);\n if (!skipFocus) {\n queueMicrotask(() => {\n const focusable = editorHost.querySelector(FOCUSABLE_EDITOR_SELECTOR) as HTMLElement | null;\n focusable?.focus({ preventScroll: true });\n });\n }\n } else if (typeof editorSpec === 'function') {\n const ctx: EditorContext<T> = {\n row: rowData,\n rowId: rowId ?? '',\n value,\n field: column.field,\n column,\n commit,\n cancel,\n updateRow,\n onValueChange,\n };\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const produced = (editorSpec as any)(ctx);\n if (typeof produced === 'string') {\n editorHost.innerHTML = produced;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n wireEditorInputs(editorHost, column as any, commit, originalValue);\n // Auto-update wired inputs when value changes externally\n onValueChange((newVal) => {\n const input = editorHost.querySelector<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>(\n 'input,textarea,select',\n );\n if (input) {\n if (input instanceof HTMLInputElement && input.type === 'checkbox') {\n input.checked = !!newVal;\n } else {\n input.value = String(newVal ?? '');\n }\n }\n });\n } else if (produced instanceof Node) {\n editorHost.appendChild(produced);\n const isSimpleInput =\n produced instanceof HTMLInputElement ||\n produced instanceof HTMLSelectElement ||\n produced instanceof HTMLTextAreaElement;\n if (!isSimpleInput) {\n cell.setAttribute('data-editor-managed', '');\n } else {\n // Auto-update simple inputs returned by factory functions\n onValueChange((newVal) => {\n if (produced instanceof HTMLInputElement && produced.type === 'checkbox') {\n produced.checked = !!newVal;\n } else {\n (produced as HTMLInputElement).value = String(newVal ?? '');\n }\n });\n }\n }\n if (!skipFocus) {\n queueMicrotask(() => {\n const focusable = editorHost.querySelector(FOCUSABLE_EDITOR_SELECTOR) as HTMLElement | null;\n focusable?.focus({ preventScroll: true });\n });\n }\n } else if (editorSpec && typeof editorSpec === 'object') {\n const placeholder = document.createElement('div');\n placeholder.setAttribute('data-external-editor', '');\n placeholder.setAttribute('data-field', column.field);\n editorHost.appendChild(placeholder);\n cell.setAttribute('data-editor-managed', '');\n const context: EditorContext<T> = {\n row: rowData,\n rowId: rowId ?? '',\n value,\n field: column.field,\n column,\n commit,\n cancel,\n updateRow,\n onValueChange,\n };\n if (editorSpec.mount) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n editorSpec.mount({ placeholder, context: context as any, spec: editorSpec });\n } catch (e) {\n console.warn(`[tbw-grid] External editor mount error for column '${column.field}':`, e);\n }\n } else {\n (this.grid as unknown as HTMLElement).dispatchEvent(\n new CustomEvent('mount-external-editor', { detail: { placeholder, spec: editorSpec, context } }),\n );\n }\n }\n }\n\n /**\n * Render a template-based editor.\n */\n #renderTemplateEditor(\n editorHost: HTMLElement,\n column: ColumnInternal<T>,\n rowData: T,\n originalValue: unknown,\n commit: (value: unknown) => void,\n cancel: () => void,\n skipFocus: boolean,\n rowIndex: number,\n ): void {\n const tplHolder = column.__editorTemplate;\n if (!tplHolder) return;\n\n const clone = tplHolder.cloneNode(true) as HTMLElement;\n const compiledEditor = column.__compiledEditor;\n\n if (compiledEditor) {\n clone.innerHTML = compiledEditor({\n row: rowData,\n value: originalValue,\n field: column.field,\n column,\n commit,\n cancel,\n });\n } else {\n clone.querySelectorAll<HTMLElement>('*').forEach((node) => {\n if (node.childNodes.length === 1 && node.firstChild?.nodeType === Node.TEXT_NODE) {\n node.textContent =\n node.textContent\n ?.replace(/{{\\s*value\\s*}}/g, originalValue == null ? '' : String(originalValue))\n .replace(/{{\\s*row\\.([a-zA-Z0-9_]+)\\s*}}/g, (_m, g: string) => {\n if (!isSafePropertyKey(g)) return '';\n const v = (rowData as Record<string, unknown>)[g];\n return v == null ? '' : String(v);\n }) || '';\n }\n });\n }\n\n const input = clone.querySelector<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>(\n 'input,textarea,select',\n );\n if (input) {\n if (input instanceof HTMLInputElement && input.type === 'checkbox') {\n input.checked = !!originalValue;\n } else {\n input.value = String(originalValue ?? '');\n }\n\n let editFinalized = false;\n input.addEventListener('blur', () => {\n if (editFinalized) return;\n commit(getInputValue(input, column, originalValue));\n });\n input.addEventListener('keydown', (evt) => {\n const e = evt as KeyboardEvent;\n if (e.key === 'Enter') {\n // Allow users to prevent edit close via callback (e.g., when overlay is open)\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(e);\n if (shouldClose === false) {\n return; // Let the event propagate to overlay\n }\n }\n e.stopPropagation();\n e.preventDefault();\n editFinalized = true;\n commit(getInputValue(input, column, originalValue));\n this.#exitRowEdit(rowIndex, false);\n }\n if (e.key === 'Escape') {\n // Allow users to prevent edit close via callback (e.g., when overlay is open)\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(e);\n if (shouldClose === false) {\n return; // Let the event propagate to overlay\n }\n }\n e.stopPropagation();\n e.preventDefault();\n cancel();\n this.#exitRowEdit(rowIndex, true);\n }\n });\n if (input instanceof HTMLInputElement && input.type === 'checkbox') {\n input.addEventListener('change', () => commit(input.checked));\n }\n if (!skipFocus) {\n setTimeout(() => input.focus({ preventScroll: true }), 0);\n }\n }\n editorHost.appendChild(clone);\n }\n\n /**\n * Compare snapshot vs current row to detect if any values changed during this edit session.\n * Uses shallow comparison of all properties.\n */\n #hasRowChanged(snapshot: T | undefined, current: T): boolean {\n if (!snapshot) return false;\n\n const snapshotObj = snapshot as Record<string, unknown>;\n const currentObj = current as Record<string, unknown>;\n\n // Check all keys in both objects\n const allKeys = new Set([...Object.keys(snapshotObj), ...Object.keys(currentObj)]);\n for (const key of allKeys) {\n if (snapshotObj[key] !== currentObj[key]) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Restore focus to cell after exiting edit mode.\n */\n #restoreCellFocus(internalGrid: InternalGrid<T>): void {\n queueMicrotask(() => {\n try {\n const rowIdx = internalGrid._focusRow;\n const colIdx = internalGrid._focusCol;\n const rowEl = internalGrid.findRenderedRowElement?.(rowIdx);\n if (rowEl) {\n Array.from(internalGrid._bodyEl.querySelectorAll('.cell-focus')).forEach((el) =>\n el.classList.remove('cell-focus'),\n );\n const cell = rowEl.querySelector(`.cell[data-row=\"${rowIdx}\"][data-col=\"${colIdx}\"]`) as HTMLElement | null;\n if (cell) {\n cell.classList.add('cell-focus');\n cell.setAttribute('aria-selected', 'true');\n if (!cell.hasAttribute('tabindex')) cell.setAttribute('tabindex', '-1');\n cell.focus({ preventScroll: true });\n }\n }\n } catch {\n /* empty */\n }\n });\n }\n\n // #endregion\n}\n"],"names":["defaultEditorFor","column","type","ctx","params","editorParams","input","document","createElement","value","String","min","max","step","placeholder","commit","Number","addEventListener","e","key","cancel","createNumberEditor","checked","Date","valueAsDate","split","createDateEditor","select","multi","multiple","includeEmpty","emptyOpt","textContent","emptyLabel","appendChild","options","raw","resolveOptions","forEach","opt","o","label","Array","isArray","includes","selected","values","from","selectedOptions","map","createSelectEditor","maxLength","pattern","inputVal","replace","createTextEditor","isSafePropertyKey","getInputValue","originalValue","HTMLInputElement","noopUpdateRow","_changes","EditingPlugin","BaseGridPlugin","static","ownedProperties","property","level","description","isUsed","v","events","queries","name","styles","defaultConfig","mode","editOn","isGridMode","this","config","activeEditRow","activeEditRowId","activeEditRowRef","activeEditCol","rowEditSnapshots","Map","changedRowIds","Set","editingCells","editorValueCallbacks","pendingFocusRestore","pendingRowAnimation","invalidCells","gridModeInputFocused","gridModeEditLocked","singleCellEdit","attach","grid","super","signal","disconnectSignal","internalGrid","_activeEditRows","_rowEditSnapshots","Object","defineProperty","get","changedRows","configurable","resetChangedRows","silent","beginBulkEdit","rowIndex","field","beginCellEdit","onBeforeEditClose","exitRowEdit","capture","rowEl","findRenderedRowElement","composedPath","target","containsFocus","queueMicrotask","focusTrap","gridElement","related","relatedTarget","contains","focusCurrentCellEditor","detail","source","cb","newValue","_isGridEditMode","classList","add","requestRender","matches","FOCUSABLE_EDITOR_SELECTOR","blur","focus","activeEl","activeElement","preventDefault","stopPropagation","detach","remove","clear","handleQuery","query","onCellClick","event","effectiveConfig","isDoubleClick","originalEvent","hasEditableColumn","_columns","some","col","editable","onKeyDown","requestAfterRender","maxRow","_rows","length","currentRow","_focusRow","Math","ensureCellVisible","forward","shiftKey","handleTabNavigation","focusRow","focusCol","_focusCol","_visibleColumns","rowData","commitCellValue","ctrlKey","altKey","metaKey","row","cellEl","querySelector","activateEvent","CustomEvent","cancelable","bubbles","colIndex","trigger","dispatchEvent","legacyEvent","defaultPrevented","processColumns","columns","typeDefaults","adapter","__frameworkAdapter","getTypeDefault","typeEditorParams","appDefault","afterRender","restoreCellFocus","animateRow","size","cellKey","rowStr","colStr","parseInt","injectEditor","afterCellRender","context","cellElement","onScrollRender","rows","id","getRow","push","isRowEditing","isCellEditing","has","isRowChanged","rowId","getRowId","isRowChangedById","setInvalid","message","rowInvalids","set","syncInvalidCellAttribute","clearInvalid","delete","clearRowInvalid","fields","keys","clearAllInvalid","entries","_","isCellInvalid","getInvalidMessage","hasInvalidCells","getInvalidFields","invalid","findIndex","c","r","setAttribute","removeAttribute","ids","syncGridEditState","emit","_rowPool","startRowEdit","children","cell","i","setTimeout","targetCell","editor","preventScroll","commitActiveRowEdit","cancelActiveRowEdit","editableCols","filter","nextIdx","indexOf","forceHorizontalScroll","nextRow","revert","snapshot","entry","_getRowEntry","current","querySelectorAll","getAttribute","isNaN","hasAttribute","val","k","changedThisSession","hasRowChanged","changed","cancelled","emitCancelable","oldValue","isAnimationEnabled","startsWith","callbackKey","__editingCellCount","clearEditingState","parentElement","refreshVirtualWindow","reverted","firstTime","updateRow","changes","invalidWasSet","firstTimeForRow","emitPluginEvent","skipFocus","count","editFinalized","currentRowData","currentIndex","index","editorHost","className","innerHTML","colInternal","tplHolder","__editorTemplate","editorSpec","gridTypeDefaults","resolveEditor","callbacks","newVal","onValueChange","renderTemplateEditor","el","focusable","produced","HTMLSelectElement","wireEditorInputs","Node","HTMLTextAreaElement","mount","spec","console","warn","clone","cloneNode","compiledEditor","__compiledEditor","node","childNodes","firstChild","nodeType","TEXT_NODE","_m","g","evt","snapshotObj","currentObj","allKeys","rowIdx","colIdx","_bodyEl"],"mappings":"+eAoNO,SAASA,EAAiBC,GAC/B,OAAQA,EAAOC,MACb,IAAK,SACH,OA9KN,SAA4BD,GAC1B,OAAQE,IACN,MAAMC,EAASH,EAAOI,aAChBC,EAAQC,SAASC,cAAc,SACrCF,EAAMJ,KAAO,SACbI,EAAMG,MAAqB,MAAbN,EAAIM,MAAgBC,OAAOP,EAAIM,OAAS,QAElC,IAAhBL,GAAQO,QAAyBA,IAAMD,OAAON,EAAOO,WACrC,IAAhBP,GAAQQ,QAAyBA,IAAMF,OAAON,EAAOQ,WACpC,IAA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,kBAAkBlG,GAEhD,MAEJ,CACAA,EAAEgI,kBACFhI,EAAE+H,iBACF7H,IACA2D,MAAKsC,EAAaJ,GAAU,EAC9B,IAEE3G,aAAiBqD,kBAAmC,aAAfrD,EAAMJ,MAC7CI,EAAMW,iBAAiB,SAAU,IAAMF,EAAOT,EAAMgB,UAEjDuR,GACH3C,WAAW,IAAM5P,EAAMwI,MAAM,CAAEuH,eAAe,IAAS,EAE3D,CACA8C,EAAWjR,YAAYyS,EACzB,CAMA,EAAAjD,CAAeX,EAAyBG,GACtC,IAAKH,EAAU,OAAO,EAEtB,MAAMwE,EAAcxE,EACdyE,EAAatE,EAGbuE,EAAU,IAAIjQ,IAAI,IAAIiB,OAAOmI,KAAK2G,MAAiB9O,OAAOmI,KAAK4G,KACrE,IAAA,MAAWrU,KAAOsU,EAChB,GAAIF,EAAYpU,KAASqU,EAAWrU,GAClC,OAAO,EAGX,OAAO,CACT,CAKA,EAAAyL,CAAkBtG,GAChBsB,eAAe,KACb,IACE,MAAM8N,EAASpP,EAAakE,UACtBmL,EAASrP,EAAa0E,UACtBzD,EAAQjB,EAAakB,yBAAyBkO,GACpD,GAAInO,EAAO,CACT7E,MAAMK,KAAKuD,EAAasP,QAAQzE,iBAAiB,gBAAgB7O,QAAS0R,GACxEA,EAAGxL,UAAUY,OAAO,eAEtB,MAAM4G,EAAOzI,EAAMkE,cAAc,mBAAmBiK,iBAAsBC,OACtE3F,IACFA,EAAKxH,UAAUC,IAAI,cACnBuH,EAAKR,aAAa,gBAAiB,QAC9BQ,EAAKsB,aAAa,aAAatB,EAAKR,aAAa,WAAY,MAClEQ,EAAKlH,MAAM,CAAEuH,eAAe,IAEhC,CACF,CAAA,MAEA,GAEJ"}
1
+ {"version":3,"file":"editing.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/editing/editors.ts","../../../../../libs/grid/src/lib/plugins/editing/internal/dirty-tracking.ts","../../../../../libs/grid/src/lib/plugins/editing/EditingPlugin.ts"],"sourcesContent":["/**\n * Default Editors Module\n *\n * Provides built-in editor factories for different column types.\n * Each editor type has its own factory function for consistency and readability.\n *\n * IMPORTANT: Editor factories should NOT call focus() on elements - they are called\n * before the element is appended to the DOM. The calling code (beginBulkEdit,\n * inlineEnterEdit) is responsible for focusing the correct editor after insertion.\n */\n\nimport type { ColumnConfig, ColumnEditorContext } from '../../core/types';\nimport type { DateEditorParams, NumberEditorParams, SelectEditorParams, TextEditorParams } from './types';\n\n// ============================================================================\n// Type Aliases\n// ============================================================================\n\n/** Option shape used by select editor (matches column.options) */\ntype ColumnOption = { label: string; value: unknown };\n\n/** Column with any row type (used for editor factories) */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyColumn = ColumnConfig<any>;\n\n// ============================================================================\n// Utilities\n// ============================================================================\n\n/** Resolve column.options (handles both array and function forms) */\nfunction resolveOptions(column: AnyColumn): ColumnOption[] {\n const raw = column.options;\n if (!raw) return [];\n return typeof raw === 'function' ? raw() : raw;\n}\n\n/** Format a Date as YYYY-MM-DD string */\nfunction toISODate(date: Date): string {\n const y = date.getFullYear();\n const m = String(date.getMonth() + 1).padStart(2, '0');\n const d = String(date.getDate()).padStart(2, '0');\n return `${y}-${m}-${d}`;\n}\n\n// ============================================================================\n// Editor Factories\n// ============================================================================\n\n/** Creates a number input editor */\nfunction createNumberEditor(column: AnyColumn): (ctx: ColumnEditorContext) => HTMLElement {\n return (ctx) => {\n const params = column.editorParams as NumberEditorParams | undefined;\n const input = document.createElement('input');\n input.type = 'number';\n input.value = ctx.value != null ? String(ctx.value) : '';\n\n if (params?.min !== undefined) input.min = String(params.min);\n if (params?.max !== undefined) input.max = String(params.max);\n if (params?.step !== undefined) input.step = String(params.step);\n if (params?.placeholder) input.placeholder = params.placeholder;\n\n const commit = () => {\n if (input.value === '') {\n if (column.nullable) {\n ctx.commit(null);\n } else {\n // Non-nullable: fall back to min value or 0\n ctx.commit(params?.min ?? 0);\n }\n } else {\n ctx.commit(Number(input.value));\n }\n };\n input.addEventListener('blur', commit);\n input.addEventListener('keydown', (e) => {\n if (e.key === 'Enter') commit();\n if (e.key === 'Escape') ctx.cancel();\n });\n\n return input;\n };\n}\n\n/** Creates a checkbox editor for boolean values */\nfunction createBooleanEditor(): (ctx: ColumnEditorContext) => HTMLElement {\n return (ctx) => {\n const input = document.createElement('input');\n input.type = 'checkbox';\n input.checked = !!ctx.value;\n input.addEventListener('change', () => ctx.commit(input.checked));\n return input;\n };\n}\n\n/** Creates a date input editor */\nfunction createDateEditor(column: AnyColumn): (ctx: ColumnEditorContext) => HTMLElement {\n return (ctx) => {\n const params = column.editorParams as DateEditorParams | undefined;\n const input = document.createElement('input');\n input.type = 'date';\n\n // Set initial value - handle both Date objects and string dates\n if (ctx.value instanceof Date) {\n input.valueAsDate = ctx.value;\n } else if (typeof ctx.value === 'string' && ctx.value) {\n // String date like \"2019-10-09\" - set directly as value\n input.value = ctx.value.split('T')[0]; // Handle ISO strings too\n }\n if (params?.min) input.min = params.min;\n if (params?.max) input.max = params.max;\n if (params?.placeholder) input.placeholder = params.placeholder;\n\n // Commit function preserves original type (string vs Date)\n const commit = () => {\n if (!input.value) {\n if (column.nullable) {\n ctx.commit(null);\n } else {\n // Non-nullable: use configured default or today\n const fallback = params?.default;\n if (typeof ctx.value === 'string' || typeof fallback === 'string') {\n // String mode: use default string or today as YYYY-MM-DD\n ctx.commit(typeof fallback === 'string' ? fallback : toISODate(fallback ?? new Date()));\n } else {\n // Date object mode\n ctx.commit(fallback instanceof Date ? fallback : new Date());\n }\n }\n return;\n }\n if (typeof ctx.value === 'string') {\n // Original was string, return string in YYYY-MM-DD format\n ctx.commit(input.value);\n } else {\n ctx.commit(input.valueAsDate);\n }\n };\n\n input.addEventListener('change', commit);\n input.addEventListener('keydown', (e) => {\n if (e.key === 'Escape') ctx.cancel();\n });\n\n return input;\n };\n}\n\n/** Sentinel value used internally to identify the nullable \"(Blank)\" option */\nconst NULLABLE_BLANK_VALUE = '__tbw_null__';\n\n/** Creates a select dropdown editor */\nfunction createSelectEditor(column: AnyColumn): (ctx: ColumnEditorContext) => HTMLElement {\n return (ctx) => {\n const params = column.editorParams as SelectEditorParams | undefined;\n const select = document.createElement('select');\n if (column.multi) select.multiple = true;\n\n // Add blank option: nullable columns always get one, otherwise respect includeEmpty\n const showBlank = column.nullable || params?.includeEmpty;\n if (showBlank) {\n const emptyOpt = document.createElement('option');\n emptyOpt.value = column.nullable ? NULLABLE_BLANK_VALUE : '';\n emptyOpt.textContent = column.nullable ? (params?.emptyLabel ?? '(Blank)') : (params?.emptyLabel ?? '');\n if (ctx.value == null) emptyOpt.selected = true;\n select.appendChild(emptyOpt);\n }\n\n // Populate options from column.options\n const options = resolveOptions(column);\n options.forEach((opt) => {\n const o = document.createElement('option');\n o.value = String(opt.value);\n o.textContent = opt.label;\n if (column.multi && Array.isArray(ctx.value) && ctx.value.includes(opt.value)) {\n o.selected = true;\n } else if (!column.multi && ctx.value === opt.value) {\n o.selected = true;\n }\n select.appendChild(o);\n });\n\n const commit = () => {\n if (column.multi) {\n const values = Array.from(select.selectedOptions).map((o) => o.value);\n ctx.commit(values);\n } else if (column.nullable && select.value === NULLABLE_BLANK_VALUE) {\n ctx.commit(null);\n } else {\n ctx.commit(select.value);\n }\n };\n\n select.addEventListener('change', commit);\n select.addEventListener('blur', commit);\n select.addEventListener('keydown', (e) => {\n if (e.key === 'Escape') ctx.cancel();\n });\n\n return select;\n };\n}\n\n/** Creates a text input editor (default) */\nfunction createTextEditor(column: AnyColumn): (ctx: ColumnEditorContext) => HTMLElement {\n return (ctx) => {\n const params = column.editorParams as TextEditorParams | undefined;\n const input = document.createElement('input');\n input.type = 'text';\n input.value = ctx.value != null ? String(ctx.value) : '';\n\n if (params?.maxLength !== undefined) input.maxLength = params.maxLength;\n if (params?.pattern) input.pattern = params.pattern;\n if (params?.placeholder) input.placeholder = params.placeholder;\n\n // Commit function preserves original type when possible\n const commit = () => {\n const inputVal = input.value;\n\n // Empty input handling\n if (inputVal === '') {\n if (column.nullable) {\n ctx.commit(null);\n } else {\n // Non-nullable: commit empty string so the field is never null\n ctx.commit('');\n }\n return;\n }\n\n // Preserve values with characters that <input> can't represent (newlines, etc.).\n // If stripping those characters produces the same string, the user didn't change anything.\n if (typeof ctx.value === 'string' && inputVal === ctx.value.replace(/[\\n\\r]/g, '')) {\n return;\n }\n // Preserve numeric type for custom column types (e.g., currency)\n if (typeof ctx.value === 'number') {\n ctx.commit(Number(inputVal));\n } else {\n ctx.commit(inputVal);\n }\n };\n\n input.addEventListener('blur', commit);\n input.addEventListener('keydown', (e) => {\n if (e.key === 'Enter') commit();\n if (e.key === 'Escape') ctx.cancel();\n });\n\n return input;\n };\n}\n\n// ============================================================================\n// Main Entry Point\n// ============================================================================\n\n/**\n * Returns a default editor factory function for the given column type.\n * Each editor handles commit on blur/Enter, and cancel on Escape.\n *\n * Note: Focus is NOT called here - the calling code handles focusing after DOM insertion.\n */\nexport function defaultEditorFor(column: AnyColumn): (ctx: ColumnEditorContext) => HTMLElement | string {\n switch (column.type) {\n case 'number':\n return createNumberEditor(column);\n case 'boolean':\n return createBooleanEditor();\n case 'date':\n return createDateEditor(column);\n case 'select':\n return createSelectEditor(column);\n default:\n return createTextEditor(column);\n }\n}\n\n// ============================================================================\n// Utility Export (used by EditingPlugin)\n// ============================================================================\n\n/**\n * Gets the current value from an input element, with type coercion based on column type.\n */\nexport function getInputValue(\n input: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement,\n col: AnyColumn,\n): unknown {\n if (input instanceof HTMLSelectElement) {\n if (col.multi) {\n return Array.from(input.selectedOptions).map((o) => o.value);\n }\n return input.value;\n }\n if (input instanceof HTMLInputElement) {\n if (input.type === 'checkbox') return input.checked;\n if (input.type === 'number') {\n if (input.value === '') {\n if (col.nullable) return null;\n const params = col.editorParams as NumberEditorParams | undefined;\n return params?.min ?? 0;\n }\n return Number(input.value);\n }\n if (input.type === 'date') {\n if (!input.value && col.nullable) return null;\n return input.valueAsDate;\n }\n }\n if (col.nullable && input.value === '') return null;\n return input.value;\n}\n","/**\n * Pure functions for dirty tracking baseline management.\n *\n * Extracted from EditingPlugin to keep the plugin under the 2,000 line target.\n * All functions are stateless — the caller owns the baseline `Map`.\n *\n * @internal\n */\n\n// #region Types\n\n/**\n * Detail for `dirty-change` custom events.\n */\nexport interface DirtyChangeDetail<T = unknown> {\n /** Row ID (from getRowId) */\n rowId: string;\n /** Current row data */\n row: T;\n /** Baseline (original) row data, or undefined for newly inserted rows */\n original: T | undefined;\n /**\n * Transition type:\n * - `'modified'` — row differs from baseline\n * - `'new'` — row was inserted via `insertRow()` and has no baseline\n * - `'reverted'` — row was reverted to baseline via `revertRow()`\n * - `'pristine'` — row was explicitly marked pristine via `markAsPristine()`\n */\n type: 'modified' | 'new' | 'reverted' | 'pristine';\n}\n\n/**\n * Result of getDirtyRows(): each entry has the row ID, original (baseline),\n * and current data.\n */\nexport interface DirtyRowEntry<T = unknown> {\n id: string;\n original: T;\n current: T;\n}\n\n/**\n * Detail for `baselines-captured` custom events.\n *\n * Emitted after the render pipeline completes when new baseline snapshots\n * were captured during `processRows`.\n */\nexport interface BaselinesCapturedDetail {\n /** Total number of tracked baselines (not just newly captured). */\n count: number;\n}\n\n// #endregion\n\n// #region Baseline Capture\n\n/**\n * Capture baselines for rows not already tracked (first-write-wins).\n *\n * Uses `structuredClone` for deep copy so nested objects cannot be mutated\n * through shared references.\n *\n * @param baselines - Map of rowId → deep-cloned baseline row data\n * @param rows - Rows to snapshot\n * @param getRowId - Function to resolve row ID (may throw; exceptions are swallowed)\n */\nexport function captureBaselines<T>(\n baselines: Map<string, T>,\n rows: readonly T[],\n getRowId: (row: T) => string | undefined,\n): void {\n for (const row of rows) {\n try {\n const id = getRowId(row);\n if (id != null && !baselines.has(id)) {\n baselines.set(id, structuredClone(row));\n }\n } catch {\n // Row has no resolvable ID — skip\n }\n }\n}\n\n// #endregion\n\n// #region Dirty Detection\n\n/**\n * Check whether a row's current data differs from its baseline.\n *\n * Uses deep property comparison so that `structuredClone`'d baselines\n * with nested objects/arrays/Dates compare correctly.\n */\nexport function isRowDirty<T>(baselines: Map<string, T>, rowId: string, currentRow: T): boolean {\n const baseline = baselines.get(rowId);\n if (!baseline) return false; // No baseline → row is \"new\" or untracked\n return !deepEqual(baseline, currentRow);\n}\n\n/**\n * Check whether a single cell (field) differs from its baseline value.\n *\n * Returns `false` when no baseline exists for the row.\n */\nexport function isCellDirty<T>(baselines: Map<string, T>, rowId: string, currentRow: T, field: string): boolean {\n const baseline = baselines.get(rowId);\n if (!baseline) return false;\n const baselineValue = (baseline as Record<string, unknown>)[field];\n const currentValue = (currentRow as Record<string, unknown>)[field];\n return !deepEqual(baselineValue, currentValue);\n}\n\n/**\n * Deep comparison of two values. Handles primitives, plain objects, arrays,\n * and Dates — the value types produced by `structuredClone` on row data.\n */\nfunction deepEqual(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n if (a == null || b == null) return false;\n if (typeof a !== typeof b) return false;\n\n // Date comparison\n if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();\n\n // Array comparison\n if (Array.isArray(a)) {\n if (!Array.isArray(b) || a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (!deepEqual(a[i], b[i])) return false;\n }\n return true;\n }\n\n // Object comparison\n if (typeof a === 'object') {\n const aObj = a as Record<string, unknown>;\n const bObj = b as Record<string, unknown>;\n const keysA = Object.keys(aObj);\n const keysB = Object.keys(bObj);\n if (keysA.length !== keysB.length) return false;\n for (const key of keysA) {\n if (!deepEqual(aObj[key], bObj[key])) return false;\n }\n return true;\n }\n\n return false;\n}\n\n// #endregion\n\n// #region State Transitions\n\n/**\n * Mark a row as pristine: re-snapshot baseline from current data.\n *\n * After calling this, `isRowDirty` returns `false` for the row (until it\n * is edited again).\n */\nexport function markPristine<T>(baselines: Map<string, T>, rowId: string, currentRow: T): void {\n baselines.set(rowId, structuredClone(currentRow));\n}\n\n/**\n * Get the original (baseline) row data as a deep clone.\n *\n * Returns `undefined` if no baseline exists (e.g. newly inserted row).\n */\nexport function getOriginalRow<T>(baselines: Map<string, T>, rowId: string): T | undefined {\n const baseline = baselines.get(rowId);\n return baseline ? structuredClone(baseline) : undefined;\n}\n\n/**\n * Revert a row to its baseline values by mutating the current row in-place.\n *\n * Returns `true` if a baseline existed and the row was reverted, `false` otherwise.\n */\nexport function revertToBaseline<T>(baselines: Map<string, T>, rowId: string, currentRow: T): boolean {\n const baseline = baselines.get(rowId);\n if (!baseline) return false;\n const baselineObj = baseline as Record<string, unknown>;\n const currentObj = currentRow as Record<string, unknown>;\n for (const key of Object.keys(baselineObj)) {\n currentObj[key] = baselineObj[key];\n }\n return true;\n}\n\n// #endregion\n","/**\n * Editing Plugin\n *\n * Provides complete editing functionality for tbw-grid.\n * This plugin is FULLY SELF-CONTAINED - the grid has ZERO editing knowledge.\n *\n * The plugin:\n * - Owns all editing state (active cell, snapshots, changed rows)\n * - Uses event distribution (onCellClick, onKeyDown) to handle edit lifecycle\n * - Uses afterRender() hook to inject editors into cells\n * - Uses processColumns() to augment columns with editing metadata\n * - Emits its own events (cell-commit, row-commit, changed-rows-reset)\n *\n * Without this plugin, the grid cannot edit. With this plugin, editing\n * is fully functional without any core changes.\n */\n\nimport { ensureCellVisible } from '../../core/internal/keyboard';\nimport { FOCUSABLE_EDITOR_SELECTOR } from '../../core/internal/rows';\nimport type {\n AfterCellRenderContext,\n AfterRowRenderContext,\n PluginManifest,\n PluginQuery,\n} from '../../core/plugin/base-plugin';\nimport { BaseGridPlugin, type CellClickEvent, type GridElement } from '../../core/plugin/base-plugin';\nimport type {\n ColumnConfig,\n ColumnEditorSpec,\n ColumnInternal,\n InternalGrid,\n RowElementInternal,\n} from '../../core/types';\nimport styles from './editing.css?inline';\nimport { defaultEditorFor } from './editors';\nimport {\n captureBaselines,\n getOriginalRow,\n isCellDirty,\n isRowDirty,\n markPristine,\n revertToBaseline,\n type BaselinesCapturedDetail,\n type DirtyChangeDetail,\n type DirtyRowEntry,\n} from './internal/dirty-tracking';\nimport type {\n BeforeEditCloseDetail,\n CellCommitDetail,\n ChangedRowsResetDetail,\n EditCloseDetail,\n EditingConfig,\n EditOpenDetail,\n EditorContext,\n RowCommitDetail,\n} from './types';\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\n/**\n * Resolves the editor for a column using the priority chain:\n * 1. Column-level (`column.editor`)\n * 2. Light DOM template (`__editorTemplate` → returns 'template')\n * 3. Grid-level (`gridConfig.typeDefaults[column.type]`)\n * 4. App-level (framework adapter's `getTypeDefault`)\n * 5. Returns undefined (caller uses built-in defaultEditorFor)\n */\nfunction resolveEditor<TRow>(\n grid: InternalGrid<TRow>,\n col: ColumnInternal<TRow>,\n): ColumnEditorSpec<TRow, unknown> | 'template' | undefined {\n // 1. Column-level editor (highest priority)\n if (col.editor) return col.editor;\n\n // 2. Light DOM template\n const tplHolder = col.__editorTemplate;\n if (tplHolder) return 'template';\n\n // No type specified - no type defaults to check\n if (!col.type) return undefined;\n\n // 3. Grid-level typeDefaults (access via effectiveConfig)\n const gridTypeDefaults = (grid as any).effectiveConfig?.typeDefaults;\n if (gridTypeDefaults?.[col.type]?.editor) {\n return gridTypeDefaults[col.type].editor as ColumnEditorSpec<TRow, unknown>;\n }\n\n // 4. App-level registry (via framework adapter)\n const adapter = grid.__frameworkAdapter;\n if (adapter?.getTypeDefault) {\n const appDefault = adapter.getTypeDefault<TRow>(col.type);\n if (appDefault?.editor) {\n return appDefault.editor as ColumnEditorSpec<TRow, unknown>;\n }\n }\n\n // 5. No custom editor - caller uses built-in defaultEditorFor\n return undefined;\n}\n\n/**\n * Returns true if the given property key is safe to use on a plain object.\n */\nfunction isSafePropertyKey(key: unknown): key is string {\n if (typeof key !== 'string') return false;\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') return false;\n return true;\n}\n\n/**\n * Check if a row element has any cells in editing mode.\n */\nexport function hasEditingCells(rowEl: RowElementInternal): boolean {\n return (rowEl.__editingCellCount ?? 0) > 0;\n}\n\n/**\n * Increment the editing cell count on a row element.\n */\nfunction incrementEditingCount(rowEl: RowElementInternal): void {\n const count = (rowEl.__editingCellCount ?? 0) + 1;\n rowEl.__editingCellCount = count;\n rowEl.setAttribute('data-has-editing', '');\n}\n\n/**\n * Clear all editing state from a row element.\n */\nexport function clearEditingState(rowEl: RowElementInternal): void {\n rowEl.__editingCellCount = 0;\n rowEl.removeAttribute('data-has-editing');\n}\n\n/**\n * Get the typed value from an input element based on its type, column config, and original value.\n * Preserves the type of the original value (e.g., numeric currency values stay as numbers,\n * string dates stay as strings).\n */\nfunction getInputValue(\n input: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement,\n column?: ColumnConfig<any>,\n originalValue?: unknown,\n): unknown {\n if (input instanceof HTMLInputElement) {\n if (input.type === 'checkbox') return input.checked;\n if (input.type === 'number') {\n if (input.value === '') {\n if (column?.nullable) return null;\n const params = column?.editorParams as { min?: number } | undefined;\n return params?.min ?? 0;\n }\n return Number(input.value);\n }\n if (input.type === 'date') {\n if (!input.value) {\n if (column?.nullable) return null;\n // Non-nullable: preserve original or fall back to today\n if (typeof originalValue === 'string') return originalValue || new Date().toISOString().slice(0, 10);\n return (originalValue as Date) ?? new Date();\n }\n // Preserve original type: if original was a string, return string (YYYY-MM-DD format)\n if (typeof originalValue === 'string') {\n return input.value; // input.value is already in YYYY-MM-DD format\n }\n return input.valueAsDate;\n }\n // For text inputs, check if original value was a number to preserve type\n if (typeof originalValue === 'number') {\n if (input.value === '') {\n if (column?.nullable) return null;\n const params = column?.editorParams as { min?: number } | undefined;\n return params?.min ?? 0;\n }\n return Number(input.value);\n }\n // Nullable text: empty → null; non-nullable: empty → ''\n if (input.value === '' && (originalValue === null || originalValue === undefined)) {\n return column?.nullable ? null : '';\n }\n // Preserve values with characters <input> can't represent (newlines, etc.)\n if (typeof originalValue === 'string' && input.value === originalValue.replace(/[\\n\\r]/g, '')) {\n return originalValue;\n }\n return input.value;\n }\n // For textarea/select, check column type OR original value type\n if (column?.type === 'number' && input.value !== '') {\n return Number(input.value);\n }\n // Preserve numeric type for custom column types (e.g., currency)\n if (typeof originalValue === 'number' && input.value !== '') {\n return Number(input.value);\n }\n // Nullable: empty → null; non-nullable: empty → ''\n if ((originalValue === null || originalValue === undefined) && input.value === '') {\n return column?.nullable ? null : '';\n }\n return input.value;\n}\n\n/**\n * No-op updateRow function for rows without IDs.\n * Extracted to a named function to satisfy eslint no-empty-function.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nfunction noopUpdateRow(_changes: unknown): void {\n // Row has no ID - cannot update\n}\n\n/**\n * Auto-wire commit/cancel lifecycle for input elements in string-returned editors.\n */\nfunction wireEditorInputs(\n editorHost: HTMLElement,\n column: ColumnConfig<unknown>,\n commit: (value: unknown) => void,\n originalValue?: unknown,\n): void {\n const input = editorHost.querySelector('input,textarea,select') as\n | HTMLInputElement\n | HTMLTextAreaElement\n | HTMLSelectElement\n | null;\n if (!input) return;\n\n input.addEventListener('blur', () => {\n commit(getInputValue(input, column, originalValue));\n });\n\n if (input instanceof HTMLInputElement && input.type === 'checkbox') {\n input.addEventListener('change', () => commit(input.checked));\n } else if (input instanceof HTMLSelectElement) {\n input.addEventListener('change', () => commit(getInputValue(input, column, originalValue)));\n }\n}\n\n// ============================================================================\n// EditingPlugin\n// ============================================================================\n\n/**\n * Editing Plugin for tbw-grid\n *\n * Enables inline cell editing in the grid. Provides built-in editors for common data types\n * and supports custom editor functions for specialized input scenarios.\n *\n * ## Why Opt-In?\n *\n * Editing is delivered as a plugin rather than built into the core grid:\n *\n * - **Smaller bundle** — Apps that only display data don't pay for editing code\n * - **Clear intent** — Explicit plugin registration makes editing capability obvious\n * - **Runtime validation** — Using `editable: true` without the plugin throws a helpful error\n *\n * ## Installation\n *\n * ```ts\n * import { EditingPlugin } from '@toolbox-web/grid/plugins/editing';\n * ```\n *\n * ## Edit Triggers\n *\n * Configure how editing is triggered with the `editOn` option:\n *\n * | Value | Behavior |\n * |-------|----------|\n * | `'click'` | Single click enters edit mode (default) |\n * | `'dblclick'` | Double-click enters edit mode |\n *\n * ## Keyboard Shortcuts\n *\n * | Key | Action |\n * |-----|--------|\n * | `Enter` | Commit edit and move down |\n * | `Tab` | Commit edit and move right |\n * | `Escape` | Cancel edit, restore original value |\n * | `Arrow Keys` | Navigate between cells (when not editing) |\n *\n * @example Basic editing with double-click trigger\n * ```ts\n * grid.gridConfig = {\n * columns: [\n * { field: 'name', editable: true },\n * { field: 'price', type: 'number', editable: true },\n * { field: 'active', type: 'boolean', editable: true },\n * ],\n * plugins: [new EditingPlugin({ editOn: 'dblclick' })],\n * };\n *\n * grid.addEventListener('cell-commit', (e) => {\n * const { field, oldValue, newValue } = e.detail;\n * console.log(`${field}: ${oldValue} → ${newValue}`);\n * });\n * ```\n *\n * @example Custom editor function\n * ```ts\n * columns: [\n * {\n * field: 'status',\n * editable: true,\n * editor: (ctx) => {\n * const select = document.createElement('select');\n * ['pending', 'active', 'completed'].forEach(opt => {\n * const option = document.createElement('option');\n * option.value = opt;\n * option.textContent = opt;\n * option.selected = ctx.value === opt;\n * select.appendChild(option);\n * });\n * select.addEventListener('change', () => ctx.commit(select.value));\n * return select;\n * },\n * },\n * ]\n * ```\n *\n * @see {@link EditingConfig} for configuration options\n * @see {@link EditorContext} for custom editor context\n * @see [Live Demos](?path=/docs/grid-plugins-editing--docs) for interactive examples\n */\nexport class EditingPlugin<T = unknown> extends BaseGridPlugin<EditingConfig> {\n /**\n * Plugin manifest - declares owned properties for configuration validation.\n * @internal\n */\n static override readonly manifest: PluginManifest = {\n ownedProperties: [\n {\n property: 'editable',\n level: 'column',\n description: 'the \"editable\" column property',\n isUsed: (v) => v === true,\n },\n {\n property: 'editor',\n level: 'column',\n description: 'the \"editor\" column property',\n },\n {\n property: 'editorParams',\n level: 'column',\n description: 'the \"editorParams\" column property',\n },\n {\n property: 'nullable',\n level: 'column',\n description: 'the \"nullable\" column property (allows null values)',\n },\n ],\n events: [\n {\n type: 'cell-edit-committed',\n description: 'Emitted when a cell edit is committed (for plugin-to-plugin coordination)',\n },\n ],\n queries: [\n {\n type: 'isEditing',\n description: 'Returns whether any cell is currently being edited',\n },\n ],\n };\n\n /** @internal */\n readonly name = 'editing';\n /** @internal */\n override readonly styles = styles;\n\n /** @internal */\n protected override get defaultConfig(): Partial<EditingConfig> {\n return {\n mode: 'row',\n editOn: 'click',\n };\n }\n\n /**\n * Whether the grid is in 'grid' mode (all cells always editable).\n */\n get #isGridMode(): boolean {\n return this.config.mode === 'grid';\n }\n\n // #region Editing State (fully owned by plugin)\n\n /** Currently active edit row index, or -1 if not editing */\n #activeEditRow = -1;\n\n /** Row ID of the currently active edit row (stable across _rows replacement) */\n #activeEditRowId: string | undefined;\n\n /** Reference to the row object at edit-open time. Used as fallback in\n * #exitRowEdit when no row ID is available (prevents stale-index access). */\n #activeEditRowRef: T | undefined;\n\n /** Currently active edit column index, or -1 if not editing */\n #activeEditCol = -1;\n\n /** Snapshots of row data before editing started */\n #rowEditSnapshots = new Map<number, T>();\n\n /** Set of row IDs that have been modified (ID-based for stability) */\n #changedRowIds = new Set<string>();\n\n /** Set of cells currently in edit mode: \"rowIndex:colIndex\" */\n #editingCells = new Set<string>();\n\n /**\n * Value-change callbacks for active editors.\n * Keyed by \"rowIndex:field\" → callback that pushes updated values to the editor.\n * Populated during #injectEditor, cleaned up when editors are removed.\n */\n #editorValueCallbacks = new Map<string, (newValue: unknown) => void>();\n\n /** Flag to restore focus after next render (used when exiting edit mode) */\n #pendingFocusRestore = false;\n\n /** Row index pending animation after render, or -1 if none */\n #pendingRowAnimation = -1;\n\n /**\n * Invalid cell tracking: Map<rowId, Map<field, message>>\n * Used for validation feedback without canceling edits.\n */\n #invalidCells = new Map<string, Map<string, string>>();\n\n /**\n * In grid mode, tracks whether an input field is currently focused.\n * When true: arrow keys work within input (edit mode).\n * When false: arrow keys navigate between cells (navigation mode).\n * Escape switches to navigation mode, Enter switches to edit mode.\n */\n #gridModeInputFocused = false;\n\n /**\n * In grid mode, when true, prevents inputs from auto-focusing.\n * This is set when Escape is pressed (navigation mode) and cleared\n * when Enter is pressed or user explicitly clicks an input.\n */\n #gridModeEditLocked = false;\n\n /**\n * When true, only a single cell is being edited (triggered by F2 or `beginCellEdit`).\n * Tab and Arrow keys commit and close the editor instead of navigating to adjacent cells.\n */\n #singleCellEdit = false;\n\n // --- Dirty Tracking State ---\n\n /**\n * Baseline snapshots: rowId → deep-cloned original row data.\n * Populated by processRows on first appearance (first-write-wins).\n * Only used when `config.dirtyTracking === true`.\n */\n #baselines = new Map<string, T>();\n /** Whether new baselines were captured during the current processRows cycle. */\n #baselinesWereCaptured = false;\n\n /**\n * Set of row IDs inserted via `insertRow()` (no baseline available).\n * These are always considered dirty with type 'new'.\n */\n #newRowIds = new Set<string>();\n\n /**\n * Set of row IDs whose edit session was committed (not cancelled).\n * Used to gate `tbw-row-dirty` — the class is only applied after\n * row-commit, not during active editing.\n */\n #committedDirtyRowIds = new Set<string>();\n\n // #endregion\n\n // #region Lifecycle\n\n /** @internal */\n override attach(grid: GridElement): void {\n super.attach(grid);\n\n const signal = this.disconnectSignal;\n const internalGrid = grid as unknown as InternalGrid<T>;\n\n // Inject editing state and methods onto grid for backward compatibility\n internalGrid._activeEditRows = -1;\n internalGrid._rowEditSnapshots = new Map();\n\n // Inject changedRows getter\n Object.defineProperty(grid, 'changedRows', {\n get: () => this.changedRows,\n configurable: true,\n });\n\n // Inject changedRowIds getter (new ID-based API)\n Object.defineProperty(grid, 'changedRowIds', {\n get: () => this.changedRowIds,\n configurable: true,\n });\n\n // Inject resetChangedRows method\n (grid as any).resetChangedRows = (silent?: boolean) => this.resetChangedRows(silent);\n\n // Inject beginBulkEdit method (for backward compatibility)\n (grid as any).beginBulkEdit = (rowIndex: number, field?: string) => {\n if (field) {\n this.beginCellEdit(rowIndex, field);\n }\n // If no field specified, we can't start editing without a specific cell\n };\n\n // Document-level Escape to cancel editing (only in 'row' mode)\n document.addEventListener(\n 'keydown',\n (e: KeyboardEvent) => {\n // In grid mode, Escape doesn't exit edit mode\n if (this.#isGridMode) return;\n if (e.key === 'Escape' && this.#activeEditRow !== -1) {\n // Allow users to prevent edit close via callback (e.g., when overlay is open)\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(e);\n if (shouldClose === false) {\n return;\n }\n }\n this.#exitRowEdit(this.#activeEditRow, true);\n }\n },\n { capture: true, signal },\n );\n\n // Click outside to commit editing (only in 'row' mode)\n // Use queueMicrotask to allow pending change events to fire first.\n // This is important for Angular/React editors where the (change) event\n // fires after mousedown but before mouseup/click.\n document.addEventListener(\n 'mousedown',\n (e: MouseEvent) => {\n // In grid mode, clicking outside doesn't exit edit mode\n if (this.#isGridMode) return;\n if (this.#activeEditRow === -1) return;\n const rowEl = internalGrid.findRenderedRowElement?.(this.#activeEditRow);\n if (!rowEl) return;\n const path = (e.composedPath && e.composedPath()) || [];\n if (path.includes(rowEl)) return;\n\n // Check if click is inside a registered external focus container\n // (e.g., overlays, datepickers, dropdowns at <body> level).\n // Only check targets OUTSIDE the grid — clicks on other rows inside\n // the grid should still commit the active edit row.\n const target = e.target as Node | null;\n if (target && !this.gridElement.contains(target) && this.grid.containsFocus?.(target)) {\n return;\n }\n\n // Allow users to prevent edit close via callback (e.g., when click is inside an overlay)\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(e);\n if (shouldClose === false) {\n return;\n }\n }\n\n // Delay exit to allow pending change/commit events to fire\n queueMicrotask(() => {\n if (this.#activeEditRow !== -1) {\n this.#exitRowEdit(this.#activeEditRow, false);\n }\n });\n },\n { signal },\n );\n\n // Focus trap: when enabled, prevent focus from leaving the grid\n // while a row is being edited. If focus moves outside the grid\n // (and its registered external containers), reclaim it.\n if (this.config.focusTrap) {\n this.gridElement.addEventListener(\n 'focusout',\n (e: FocusEvent) => {\n // Only trap in row mode when actively editing\n if (this.#isGridMode) return;\n if (this.#activeEditRow === -1) return;\n\n const related = e.relatedTarget as Node | null;\n // If focus is going to an external container, that's fine\n if (related && this.grid.containsFocus?.(related)) return;\n // If focus is going to another element inside the grid, allow it\n if (related && this.gridElement.contains(related)) return;\n\n // Focus left the grid entirely — reclaim it\n queueMicrotask(() => {\n // Re-check in case editing was committed in the meantime\n if (this.#activeEditRow === -1) return;\n this.#focusCurrentCellEditor();\n });\n },\n { signal },\n );\n }\n\n // Listen for external row mutations to push updated values to active editors.\n // When field A commits and sets field B via updateRow(), field B's editor\n // (if open) must reflect the new value.\n this.gridElement.addEventListener(\n 'cell-change',\n (e: Event) => {\n const detail = (e as CustomEvent).detail as {\n rowIndex: number;\n field: string;\n newValue: unknown;\n source: string;\n };\n // Only push updates from cascade/api sources — not from the editor's own commit\n if (detail.source === 'user') return;\n const key = `${detail.rowIndex}:${detail.field}`;\n const cb = this.#editorValueCallbacks.get(key);\n if (cb) cb(detail.newValue);\n },\n { signal },\n );\n\n // --- Dirty tracking: listen for undo/redo events to re-evaluate dirty state ---\n if (this.config.dirtyTracking) {\n const handleUndoRedo = (e: Event) => {\n const detail = (e as CustomEvent).detail as { action?: { rowIndex: number; field: string } };\n const action = detail?.action;\n if (!action) return;\n const row = this.rows[action.rowIndex] as T | undefined;\n if (!row) return;\n const rowId = this.grid.getRowId(row);\n if (!rowId) return;\n const dirty = isRowDirty(this.#baselines, rowId, row);\n this.emit<DirtyChangeDetail<T>>('dirty-change', {\n rowId,\n row,\n original: getOriginalRow(this.#baselines, rowId),\n type: dirty ? 'modified' : 'pristine',\n });\n };\n this.gridElement.addEventListener('undo', handleUndoRedo, { signal });\n this.gridElement.addEventListener('redo', handleUndoRedo, { signal });\n\n // Listen for row-inserted events to auto-mark new rows for dirty tracking\n this.on('row-inserted', (detail: { row: T; index: number }) => {\n const rowId = this.grid.getRowId(detail.row);\n if (rowId != null) {\n this.markAsNew(String(rowId));\n }\n });\n }\n\n // In grid mode, request a full render to trigger afterCellRender hooks\n if (this.#isGridMode) {\n internalGrid._isGridEditMode = true;\n this.gridElement.classList.add('tbw-grid-mode');\n this.requestRender();\n\n // Track focus/blur on inputs to maintain navigation vs edit mode state\n this.gridElement.addEventListener(\n 'focusin',\n (e: FocusEvent) => {\n const target = e.target as HTMLElement;\n if (target.matches(FOCUSABLE_EDITOR_SELECTOR)) {\n // If edit is locked (navigation mode), blur the input immediately\n if (this.#gridModeEditLocked) {\n target.blur();\n this.gridElement.focus();\n return;\n }\n this.#gridModeInputFocused = true;\n }\n },\n { signal },\n );\n\n this.gridElement.addEventListener(\n 'focusout',\n (e: FocusEvent) => {\n const related = e.relatedTarget as HTMLElement | null;\n // Only clear if focus went outside grid (and external containers) or to a non-input element\n if (\n !related ||\n (!this.gridElement.contains(related) && !this.grid.containsFocus?.(related)) ||\n !related.matches(FOCUSABLE_EDITOR_SELECTOR)\n ) {\n this.#gridModeInputFocused = false;\n }\n },\n { signal },\n );\n\n // Handle Escape key directly on the grid element (capture phase)\n // This ensures we intercept Escape even when focus is inside an input\n this.gridElement.addEventListener(\n 'keydown',\n (e: KeyboardEvent) => {\n if (e.key === 'Escape' && this.#gridModeInputFocused) {\n // Allow users to prevent Escape handling via callback (e.g., when overlay is open).\n // In grid mode, Escape transitions from editing to navigation mode, so we check\n // onBeforeEditClose to let overlays (dropdowns, autocompletes) close first.\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(e);\n if (shouldClose === false) {\n return; // Let the overlay handle Escape\n }\n }\n const activeEl = document.activeElement as HTMLElement;\n if (activeEl && this.gridElement.contains(activeEl)) {\n activeEl.blur();\n // Move focus to the grid container so arrow keys work\n this.gridElement.focus();\n }\n this.#gridModeInputFocused = false;\n this.#gridModeEditLocked = true; // Lock edit mode until Enter/click\n e.preventDefault();\n e.stopPropagation();\n }\n },\n { capture: true, signal },\n );\n\n // Handle click on inputs - unlock edit mode when user explicitly clicks\n this.gridElement.addEventListener(\n 'mousedown',\n (e: MouseEvent) => {\n const target = e.target as HTMLElement;\n if (target.matches(FOCUSABLE_EDITOR_SELECTOR)) {\n this.#gridModeEditLocked = false; // User clicked input - allow edit\n }\n },\n { signal },\n );\n }\n }\n\n /** @internal */\n override detach(): void {\n const internalGrid = this.gridElement as unknown as InternalGrid<T>;\n internalGrid._isGridEditMode = false;\n this.gridElement.classList.remove('tbw-grid-mode');\n this.#activeEditRow = -1;\n this.#activeEditRowId = undefined;\n this.#activeEditRowRef = undefined;\n this.#activeEditCol = -1;\n this.#rowEditSnapshots.clear();\n this.#changedRowIds.clear();\n this.#committedDirtyRowIds.clear();\n this.#editingCells.clear();\n this.#editorValueCallbacks.clear();\n this.#baselines.clear();\n this.#newRowIds.clear();\n this.#gridModeInputFocused = false;\n this.#gridModeEditLocked = false;\n this.#singleCellEdit = false;\n super.detach();\n }\n\n /**\n * Handle plugin queries.\n * @internal\n */\n override handleQuery(query: PluginQuery): unknown {\n if (query.type === 'isEditing') {\n // In grid mode, we're always editing\n return this.#isGridMode || this.#activeEditRow !== -1;\n }\n return undefined;\n }\n\n // #endregion\n\n // #region Event Handlers (event distribution)\n\n /**\n * Handle cell clicks - start editing if configured for click mode.\n * Both click and dblclick events come through this handler.\n * Starts row-based editing (all editable cells in the row get editors).\n * @internal\n */\n override onCellClick(event: CellClickEvent): boolean | void {\n // In grid mode, all cells are already editable - no need to trigger row edit\n if (this.#isGridMode) return false;\n\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const editOn = this.config.editOn ?? internalGrid.effectiveConfig?.editOn;\n\n // Check if editing is disabled\n if (editOn === false || editOn === 'manual') return false;\n\n // Check if this is click or dblclick mode\n if (editOn !== 'click' && editOn !== 'dblclick') return false;\n\n // Check if the event type matches the edit mode\n const isDoubleClick = event.originalEvent.type === 'dblclick';\n if (editOn === 'click' && isDoubleClick) return false; // In click mode, only handle single clicks\n if (editOn === 'dblclick' && !isDoubleClick) return false; // In dblclick mode, only handle double clicks\n\n const { rowIndex } = event;\n\n // Check if any column in the row is editable\n const hasEditableColumn = internalGrid._columns?.some((col) => col.editable);\n if (!hasEditableColumn) return false;\n\n // Start row-based editing (all editable cells get editors)\n event.originalEvent.stopPropagation();\n this.beginBulkEdit(rowIndex);\n return true; // Handled\n }\n\n /**\n * Handle keyboard events for edit lifecycle.\n * @internal\n */\n override onKeyDown(event: KeyboardEvent): boolean | void {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n\n // Escape: cancel current edit (row mode) or exit edit mode (grid mode)\n if (event.key === 'Escape') {\n // In grid mode: blur input to enable arrow key navigation\n if (this.#isGridMode && this.#gridModeInputFocused) {\n // Allow users to prevent Escape handling via callback (e.g., when overlay is open)\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(event);\n if (shouldClose === false) {\n return true; // Handled: block grid navigation, let overlay handle Escape\n }\n }\n const activeEl = document.activeElement as HTMLElement;\n if (activeEl && this.gridElement.contains(activeEl)) {\n activeEl.blur();\n }\n this.#gridModeInputFocused = false;\n // Update focus styling\n this.requestAfterRender();\n return true;\n }\n\n // In row mode: cancel edit\n if (this.#activeEditRow !== -1 && !this.#isGridMode) {\n // Allow users to prevent edit close via callback (e.g., when overlay is open)\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(event);\n if (shouldClose === false) {\n return true; // Handled: block grid navigation, let event reach overlay\n }\n }\n this.#exitRowEdit(this.#activeEditRow, true);\n return true;\n }\n }\n\n // Arrow keys in grid mode when not editing input: navigate cells\n if (\n this.#isGridMode &&\n !this.#gridModeInputFocused &&\n (event.key === 'ArrowUp' || event.key === 'ArrowDown' || event.key === 'ArrowLeft' || event.key === 'ArrowRight')\n ) {\n // Let the grid's default keyboard navigation handle this\n return false;\n }\n\n // Arrow Up/Down in grid mode when input is focused: let the editor handle it\n // (e.g., ArrowDown opens autocomplete/datepicker overlays, ArrowUp/Down navigates options)\n if (this.#isGridMode && this.#gridModeInputFocused && (event.key === 'ArrowUp' || event.key === 'ArrowDown')) {\n return true; // Handled: block grid navigation, let event reach editor\n }\n\n // Arrow Up/Down while editing: commit and exit edit mode, move to adjacent row (only in 'row' mode)\n if ((event.key === 'ArrowUp' || event.key === 'ArrowDown') && this.#activeEditRow !== -1 && !this.#isGridMode) {\n // Allow users to prevent row navigation via callback (e.g., when dropdown is open)\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(event);\n if (shouldClose === false) {\n return true; // Handled: block grid navigation, let event reach dropdown\n }\n }\n\n const maxRow = internalGrid._rows.length - 1;\n const currentRow = this.#activeEditRow;\n\n // Commit the current edit\n this.#exitRowEdit(currentRow, false);\n\n // Move focus to adjacent row (same column)\n if (event.key === 'ArrowDown') {\n internalGrid._focusRow = Math.min(maxRow, internalGrid._focusRow + 1);\n } else {\n internalGrid._focusRow = Math.max(0, internalGrid._focusRow - 1);\n }\n\n event.preventDefault();\n // Ensure the focused cell is scrolled into view\n ensureCellVisible(internalGrid);\n // Request render to update focus styling\n this.requestAfterRender();\n return true;\n }\n\n // Tab/Shift+Tab while editing: move to next/prev editable cell\n if (event.key === 'Tab' && (this.#activeEditRow !== -1 || this.#isGridMode)) {\n event.preventDefault();\n\n // In single-cell edit mode (F2), commit and close instead of navigating\n if (this.#singleCellEdit) {\n this.#exitRowEdit(this.#activeEditRow, false);\n return true;\n }\n\n const forward = !event.shiftKey;\n this.#handleTabNavigation(forward);\n return true;\n }\n\n // Space: toggle boolean cells (only when not in edit mode - let editors handle their own space)\n if (event.key === ' ' || event.key === 'Spacebar') {\n // If we're in row edit mode, let the event pass through to the editor (e.g., checkbox)\n if (this.#activeEditRow !== -1) {\n return false;\n }\n\n const focusRow = internalGrid._focusRow;\n const focusCol = internalGrid._focusCol;\n if (focusRow >= 0 && focusCol >= 0) {\n const column = internalGrid._visibleColumns[focusCol];\n const rowData = internalGrid._rows[focusRow];\n if (column?.editable && column.type === 'boolean' && rowData) {\n const field = column.field;\n if (isSafePropertyKey(field)) {\n const currentValue = (rowData as Record<string, unknown>)[field];\n const newValue = !currentValue;\n this.#commitCellValue(focusRow, column, newValue, rowData);\n event.preventDefault();\n // Re-render to update the UI\n this.requestRender();\n return true;\n }\n }\n }\n // Space on non-boolean cell - don't block keyboard navigation\n return false;\n }\n\n // Enter (unmodified): start row edit, commit, or enter edit mode in grid mode\n if (event.key === 'Enter' && !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey) {\n // In grid mode when not editing: focus the current cell's input\n if (this.#isGridMode && !this.#gridModeInputFocused) {\n this.#focusCurrentCellEditor();\n return true;\n }\n\n if (this.#activeEditRow !== -1) {\n // Allow users to prevent edit close via callback (e.g., when overlay is open)\n // This lets Enter select an item in a dropdown instead of committing the row\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(event);\n if (shouldClose === false) {\n return true; // Handled: block grid navigation, let event reach overlay\n }\n }\n // Already editing - let cell handlers deal with it\n return false;\n }\n\n // Start row-based editing (not just the focused cell)\n const editOn = this.config.editOn ?? internalGrid.effectiveConfig?.editOn;\n if (editOn === false || editOn === 'manual') return false;\n\n const focusRow = internalGrid._focusRow;\n const focusCol = internalGrid._focusCol;\n if (focusRow >= 0) {\n // Check if ANY column in the row is editable\n const hasEditableColumn = internalGrid._columns?.some((col) => col.editable);\n if (hasEditableColumn) {\n // Emit cell-activate event BEFORE starting edit\n // This ensures consumers always get the activation event\n const column = internalGrid._visibleColumns[focusCol];\n const row = internalGrid._rows[focusRow];\n const field = column?.field ?? '';\n const value = field && row ? (row as Record<string, unknown>)[field] : undefined;\n const cellEl = this.gridElement.querySelector(`[data-row=\"${focusRow}\"][data-col=\"${focusCol}\"]`) as\n | HTMLElement\n | undefined;\n\n const activateEvent = new CustomEvent('cell-activate', {\n cancelable: true,\n bubbles: true,\n detail: {\n rowIndex: focusRow,\n colIndex: focusCol,\n field,\n value,\n row,\n cellEl,\n trigger: 'keyboard' as const,\n originalEvent: event,\n },\n });\n this.gridElement.dispatchEvent(activateEvent);\n\n // Also emit deprecated activate-cell for backwards compatibility\n const legacyEvent = new CustomEvent('activate-cell', {\n cancelable: true,\n bubbles: true,\n detail: { row: focusRow, col: focusCol },\n });\n this.gridElement.dispatchEvent(legacyEvent);\n\n // If consumer canceled the activation, don't start editing\n if (activateEvent.defaultPrevented || legacyEvent.defaultPrevented) {\n event.preventDefault();\n return true;\n }\n\n this.beginBulkEdit(focusRow);\n return true;\n }\n }\n // No editable columns - don't block keyboard navigation\n return false;\n }\n\n // F2: begin single-cell edit on the focused cell\n if (event.key === 'F2') {\n if (this.#activeEditRow !== -1 || this.#isGridMode) return false;\n\n const editOn = this.config.editOn ?? internalGrid.effectiveConfig?.editOn;\n if (editOn === false) return false;\n\n const focusRow = internalGrid._focusRow;\n const focusCol = internalGrid._focusCol;\n if (focusRow >= 0 && focusCol >= 0) {\n const column = internalGrid._visibleColumns[focusCol];\n if (column?.editable && column.field) {\n event.preventDefault();\n this.beginCellEdit(focusRow, column.field);\n return true;\n }\n }\n return false;\n }\n\n // Don't block other keyboard events\n return false;\n }\n\n // #endregion\n\n // #region Render Hooks\n\n /**\n * Process columns to merge type-level editorParams with column-level.\n * Column-level params take precedence.\n * @internal\n */\n override processColumns(columns: ColumnConfig<T>[]): ColumnConfig<T>[] {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const typeDefaults = (internalGrid as any).effectiveConfig?.typeDefaults;\n const adapter = internalGrid.__frameworkAdapter;\n\n // If no type defaults configured anywhere, skip processing\n if (!typeDefaults && !adapter?.getTypeDefault) return columns;\n\n return columns.map((col) => {\n if (!col.type) return col;\n\n // Get type-level editorParams\n let typeEditorParams: Record<string, unknown> | undefined;\n\n // Check grid-level typeDefaults first\n if (typeDefaults?.[col.type]?.editorParams) {\n typeEditorParams = typeDefaults[col.type].editorParams;\n }\n\n // Then check app-level (adapter) typeDefaults\n if (!typeEditorParams && adapter?.getTypeDefault) {\n const appDefault = adapter.getTypeDefault<T>(col.type);\n if (appDefault?.editorParams) {\n typeEditorParams = appDefault.editorParams;\n }\n }\n\n // No type-level params to merge\n if (!typeEditorParams) return col;\n\n // Merge: type-level as base, column-level wins on conflicts\n return {\n ...col,\n editorParams: { ...typeEditorParams, ...col.editorParams },\n };\n });\n }\n\n /**\n * Stabilize the actively edited row across `rows` array replacements and\n * capture dirty tracking baselines.\n *\n * **Editing stability:** When the consumer reassigns `grid.rows` while\n * editing, the full pipeline (sort, filter, group) runs on the new data.\n * This hook finds the edited row in the new array by ID and swaps in the\n * in-progress row reference (`#activeEditRowRef`) so editors survive.\n *\n * **Dirty tracking baselines:** When `dirtyTracking` is enabled, captures\n * a `structuredClone` snapshot of each row on first appearance\n * (first-write-wins). This prevents Angular's feedback loop from\n * overwriting baselines.\n *\n * @internal Plugin API — part of the render pipeline\n */\n override processRows(rows: readonly T[]): T[] {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n\n // --- Dirty tracking: capture baselines (first-write-wins) ---\n if (this.config.dirtyTracking && internalGrid.getRowId) {\n const sizeBefore = this.#baselines.size;\n captureBaselines(this.#baselines, rows, (r) => {\n try {\n return internalGrid.getRowId?.(r);\n } catch {\n return undefined;\n }\n });\n // Track whether new baselines were captured so afterRender can emit the event\n if (this.#baselines.size > sizeBefore) {\n this.#baselinesWereCaptured = true;\n }\n }\n\n // --- Editing stability: swap in the in-progress row ---\n if (this.#activeEditRow === -1 || this.#isGridMode) return rows as T[];\n\n const editRowId = this.#activeEditRowId;\n const editRowRef = this.#activeEditRowRef;\n\n // Without a stable row ID we cannot match across array replacements\n if (!editRowId || !editRowRef) return rows as T[];\n\n const result = [...rows] as T[];\n\n // Find the edited row's new position by ID\n let newIndex = -1;\n for (let i = 0; i < result.length; i++) {\n try {\n if (internalGrid.getRowId?.(result[i]) === editRowId) {\n newIndex = i;\n break;\n }\n } catch {\n // Row has no ID — skip\n }\n }\n\n if (newIndex === -1) {\n // Row was deleted server-side — close the editor.\n // Cannot close synchronously during the processRows pipeline;\n // schedule for after the current render cycle completes.\n setTimeout(() => this.cancelActiveRowEdit(), 0);\n return result;\n }\n\n // Swap in the in-progress row data to preserve editor state\n result[newIndex] = editRowRef;\n\n // Update index-keyed state if the position changed (due to sort/filter)\n if (this.#activeEditRow !== newIndex) {\n this.#migrateEditRowIndex(this.#activeEditRow, newIndex);\n }\n\n return result;\n }\n\n /**\n * After render, reapply editors to cells in edit mode.\n * This handles virtualization - when a row scrolls back into view,\n * we need to re-inject the editor.\n * @internal\n */\n override afterRender(): void {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n\n // --- Editing stability: verify active edit row index ---\n // After processRows, subsequent plugins (filtering, grouping) may have\n // shifted row indices. Verify the index is still correct and fix if needed\n // before re-injecting editors.\n if (this.#activeEditRow !== -1 && this.#activeEditRowRef && !this.#isGridMode) {\n if (internalGrid._rows[this.#activeEditRow] !== this.#activeEditRowRef) {\n const newIndex = (internalGrid._rows as T[]).indexOf(this.#activeEditRowRef);\n if (newIndex !== -1) {\n this.#migrateEditRowIndex(this.#activeEditRow, newIndex);\n } else {\n // Row no longer in rendered set (filtered out or deleted)\n setTimeout(() => this.cancelActiveRowEdit(), 0);\n return;\n }\n }\n }\n\n // Restore focus after exiting edit mode\n if (this.#pendingFocusRestore) {\n this.#pendingFocusRestore = false;\n this.#restoreCellFocus(internalGrid);\n }\n\n // Animate the row after render completes (so the row element exists)\n if (this.#pendingRowAnimation !== -1) {\n const rowIndex = this.#pendingRowAnimation;\n this.#pendingRowAnimation = -1;\n internalGrid.animateRow?.(rowIndex, 'change');\n }\n\n // Emit baselines-captured event when new baselines were captured this cycle.\n // Emitted post-render so consumers can safely read grid.rows, query the DOM,\n // or call getOriginalRow() in their handler.\n if (this.#baselinesWereCaptured) {\n this.#baselinesWereCaptured = false;\n this.emit<BaselinesCapturedDetail>('baselines-captured', {\n count: this.#baselines.size,\n });\n }\n\n // In 'grid' mode, editors are injected via afterCellRender hook during render\n if (this.#isGridMode) return;\n\n if (this.#editingCells.size === 0) return;\n\n // Re-inject editors for any editing cells that are visible\n for (const cellKey of this.#editingCells) {\n const [rowStr, colStr] = cellKey.split(':');\n const rowIndex = parseInt(rowStr, 10);\n const colIndex = parseInt(colStr, 10);\n\n const rowEl = internalGrid.findRenderedRowElement?.(rowIndex);\n if (!rowEl) continue;\n\n const cellEl = rowEl.querySelector(`.cell[data-col=\"${colIndex}\"]`) as HTMLElement | null;\n if (!cellEl || cellEl.classList.contains('editing')) continue;\n\n // Cell is visible but not in editing mode - reinject editor\n const rowData = internalGrid._rows[rowIndex];\n const column = internalGrid._visibleColumns[colIndex];\n if (rowData && column) {\n this.#injectEditor(rowData, rowIndex, column, colIndex, cellEl, true);\n }\n }\n }\n\n /**\n * Hook called after each cell is rendered.\n * In grid mode, injects editors into editable cells during render (no DOM queries needed).\n * @internal\n */\n override afterCellRender(context: AfterCellRenderContext): void {\n // Only inject editors in grid mode\n if (!this.#isGridMode) return;\n\n const { row, rowIndex, column, colIndex, cellElement } = context;\n\n // Skip non-editable columns\n if (!column.editable) return;\n\n // Skip if already has editor\n if (cellElement.classList.contains('editing')) return;\n\n // Inject editor (don't track in editingCells - we're always editing in grid mode)\n this.#injectEditor(row as T, rowIndex, column as ColumnConfig<T>, colIndex, cellElement, true);\n }\n\n /**\n * Apply dirty-tracking CSS classes to each rendered row.\n *\n * - `tbw-cell-dirty` on individual cells whose value differs from baseline\n * (applied on cell-commit, visible during editing)\n * - `tbw-row-dirty` on the row element only after the row edit session is\n * committed (edit-close without cancel)\n * - `tbw-row-new` when a row was inserted via `insertRow()` with no baseline\n *\n * Only active when `dirtyTracking: true`.\n *\n * @internal Plugin API\n */\n override afterRowRender(context: AfterRowRenderContext): void {\n if (!this.config.dirtyTracking) return;\n\n const internalGrid = this.gridElement as unknown as InternalGrid;\n const rowId = internalGrid.getRowId?.(context.row);\n if (!rowId) return;\n\n const isNew = this.#newRowIds.has(rowId);\n // Row-dirty requires BOTH: row was committed AND data still differs from baseline.\n // The data check handles undo: after CTRL+Z restores all cells, the row should\n // no longer appear dirty even though it was previously committed.\n const isCommittedDirty =\n !isNew && this.#committedDirtyRowIds.has(rowId) && isRowDirty(this.#baselines, rowId, context.row);\n\n const el = context.rowElement;\n\n // Row-level classes (tbw-row-dirty only after row-commit AND data differs)\n el.classList.toggle('tbw-row-dirty', isCommittedDirty);\n el.classList.toggle('tbw-row-new', isNew);\n\n // Cell-level classes (tbw-cell-dirty on individual cells with changed values)\n // Only run the per-cell loop when the row has a baseline — avoids\n // querySelectorAll on the hot path for rows without dirty tracking state.\n const hasBaseline = this.#baselines.has(rowId);\n if (hasBaseline) {\n const cells = el.querySelectorAll('.cell[data-field]');\n for (let i = 0; i < cells.length; i++) {\n const cell = cells[i] as HTMLElement;\n const field = cell.getAttribute('data-field');\n if (field) {\n cell.classList.toggle('tbw-cell-dirty', isCellDirty(this.#baselines, rowId, context.row, field));\n }\n }\n } else {\n // Clean up stale tbw-cell-dirty classes on recycled row elements\n // that previously displayed a dirty row but now show a pristine one.\n const dirtyCells = el.querySelectorAll('.tbw-cell-dirty');\n for (let i = 0; i < dirtyCells.length; i++) {\n dirtyCells[i].classList.remove('tbw-cell-dirty');\n }\n }\n }\n\n /**\n * On scroll render, reapply editors to recycled cells.\n * @internal\n */\n override onScrollRender(): void {\n this.afterRender();\n }\n\n // #endregion\n\n // #region Public API\n\n /**\n * Get all rows that have been modified.\n * Uses ID-based lookup for stability when rows are reordered.\n */\n get changedRows(): T[] {\n const rows: T[] = [];\n for (const id of this.#changedRowIds) {\n const row = this.grid.getRow(id) as T | undefined;\n if (row) rows.push(row);\n }\n return rows;\n }\n\n /**\n * Get IDs of all modified rows.\n */\n get changedRowIds(): string[] {\n return Array.from(this.#changedRowIds);\n }\n\n /**\n * Get the currently active edit row index, or -1 if not editing.\n */\n get activeEditRow(): number {\n return this.#activeEditRow;\n }\n\n /**\n * Get the currently active edit column index, or -1 if not editing.\n */\n get activeEditCol(): number {\n return this.#activeEditCol;\n }\n\n /**\n * Check if a specific row is currently being edited.\n */\n isRowEditing(rowIndex: number): boolean {\n return this.#activeEditRow === rowIndex;\n }\n\n /**\n * Check if a specific cell is currently being edited.\n */\n isCellEditing(rowIndex: number, colIndex: number): boolean {\n return this.#editingCells.has(`${rowIndex}:${colIndex}`);\n }\n\n /**\n * Check if a specific row has been modified.\n * @param rowIndex - Row index to check (will be converted to ID internally)\n */\n isRowChanged(rowIndex: number): boolean {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const row = internalGrid._rows[rowIndex];\n if (!row) return false;\n try {\n const rowId = internalGrid.getRowId?.(row);\n return rowId ? this.#changedRowIds.has(rowId) : false;\n } catch {\n return false;\n }\n }\n\n /**\n * Check if a row with the given ID has been modified.\n * @param rowId - Row ID to check\n */\n isRowChangedById(rowId: string): boolean {\n return this.#changedRowIds.has(rowId);\n }\n\n // #region Dirty Tracking API\n\n /**\n * Check if a specific row's current data differs from its baseline.\n * Requires `dirtyTracking: true` in plugin config.\n *\n * @param rowId - Row ID (from `getRowId`)\n * @returns `true` if the row has been modified or is a new row\n */\n isDirty(rowId: string): boolean {\n if (!this.config.dirtyTracking) return false;\n if (this.#newRowIds.has(rowId)) return true;\n const row = this.grid.getRow(rowId) as T | undefined;\n if (!row) return false;\n return isRowDirty(this.#baselines, rowId, row);\n }\n\n /**\n * Check if a specific row matches its baseline (not dirty).\n * Requires `dirtyTracking: true` in plugin config.\n *\n * @param rowId - Row ID (from `getRowId`)\n */\n isPristine(rowId: string): boolean {\n return !this.isDirty(rowId);\n }\n\n /**\n * Whether any row in the grid is dirty.\n * Requires `dirtyTracking: true` in plugin config.\n */\n get dirty(): boolean {\n if (!this.config.dirtyTracking) return false;\n if (this.#newRowIds.size > 0) return true;\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n for (const [rowId, baseline] of this.#baselines) {\n const row = internalGrid._getRowEntry(rowId)?.row;\n if (row && isRowDirty(this.#baselines, rowId, row)) return true;\n }\n return false;\n }\n\n /**\n * Whether all rows in the grid are pristine (not dirty).\n * Requires `dirtyTracking: true` in plugin config.\n */\n get pristine(): boolean {\n return !this.dirty;\n }\n\n /**\n * Mark a row as pristine: re-snapshot baseline from current data.\n * Call after a successful backend save to set the new \"original.\"\n *\n * @param rowId - Row ID (from `getRowId`)\n */\n markAsPristine(rowId: string): void {\n if (!this.config.dirtyTracking) return;\n const row = this.grid.getRow(rowId) as T | undefined;\n if (!row) return;\n markPristine(this.#baselines, rowId, row);\n this.#newRowIds.delete(rowId);\n this.#changedRowIds.delete(rowId);\n this.#committedDirtyRowIds.delete(rowId);\n this.emit<DirtyChangeDetail<T>>('dirty-change', {\n rowId,\n row,\n original: row, // after mark-pristine, original === current\n type: 'pristine',\n });\n }\n\n /**\n * Programmatically mark a row as new (e.g. after `grid.insertRow()`).\n *\n * Adds the row to the new-row set so it receives the `tbw-row-new` CSS\n * class and is included in `getDirtyRows()` / `dirtyRowIds`.\n *\n * Called automatically when `grid.insertRow()` emits a `row-inserted`\n * plugin event and `dirtyTracking` is enabled — consumers typically\n * don't need to call this directly.\n *\n * @param rowId - Row ID (from `getRowId`)\n */\n markAsNew(rowId: string): void {\n if (!this.config.dirtyTracking) return;\n this.#newRowIds.add(rowId);\n this.#committedDirtyRowIds.add(rowId);\n const row = this.grid.getRow(rowId) as T | undefined;\n this.emit<DirtyChangeDetail<T>>('dirty-change', {\n rowId,\n row: row as T,\n original: undefined,\n type: 'new',\n });\n }\n\n /**\n * Programmatically mark a row as dirty (e.g. after an external mutation\n * that bypassed the editing pipeline).\n *\n * @param rowId - Row ID (from `getRowId`)\n */\n markAsDirty(rowId: string): void {\n if (!this.config.dirtyTracking) return;\n const row = this.grid.getRow(rowId) as T | undefined;\n if (!row) return;\n this.#changedRowIds.add(rowId);\n this.#committedDirtyRowIds.add(rowId);\n this.emit<DirtyChangeDetail<T>>('dirty-change', {\n rowId,\n row,\n original: getOriginalRow(this.#baselines, rowId),\n type: 'modified',\n });\n }\n\n /**\n * Mark all tracked rows as pristine. Call after a successful batch save.\n */\n markAllPristine(): void {\n if (!this.config.dirtyTracking) return;\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n for (const [rowId] of this.#baselines) {\n const row = internalGrid._getRowEntry(rowId)?.row;\n if (row) {\n markPristine(this.#baselines, rowId, row);\n }\n }\n this.#newRowIds.clear();\n this.#changedRowIds.clear();\n this.#committedDirtyRowIds.clear();\n }\n\n /**\n * Get the original (baseline) row data before any edits.\n *\n * Returns a **deep clone** of the row as it was when first seen by the grid.\n * Cache the result if calling repeatedly for the same row — each call\n * performs a full `structuredClone`.\n *\n * Returns `undefined` if no baseline exists (e.g. newly inserted row via\n * `grid.insertRow()`).\n *\n * @param rowId - Row ID (from `getRowId`)\n */\n getOriginalRow(rowId: string): T | undefined {\n if (!this.config.dirtyTracking) return undefined;\n return getOriginalRow<T>(this.#baselines, rowId);\n }\n\n /**\n * Check whether a baseline snapshot exists for a row.\n *\n * Lightweight alternative to `getOriginalRow()` when you only need to know\n * if the row has been tracked — no cloning is performed.\n *\n * Returns `false` when `dirtyTracking` is disabled.\n *\n * @param rowId - Row ID (from `getRowId`)\n */\n hasBaseline(rowId: string): boolean {\n if (!this.config.dirtyTracking) return false;\n return this.#baselines.has(rowId);\n }\n\n /**\n * Get all dirty rows with their original and current data.\n */\n getDirtyRows(): DirtyRowEntry<T>[] {\n if (!this.config.dirtyTracking) return [];\n const result: DirtyRowEntry<T>[] = [];\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n for (const [rowId, baseline] of this.#baselines) {\n const entry = internalGrid._getRowEntry(rowId);\n if (entry && isRowDirty(this.#baselines, rowId, entry.row as T)) {\n result.push({\n id: rowId,\n original: structuredClone(baseline),\n current: entry.row as T,\n });\n }\n }\n // Include new rows (no baseline)\n for (const newId of this.#newRowIds) {\n const entry = internalGrid._getRowEntry(newId);\n if (entry) {\n result.push({\n id: newId,\n original: undefined as unknown as T,\n current: entry.row as T,\n });\n }\n }\n return result;\n }\n\n /**\n * Get IDs of all dirty rows.\n */\n get dirtyRowIds(): string[] {\n if (!this.config.dirtyTracking) return [];\n const ids: string[] = [];\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n for (const [rowId] of this.#baselines) {\n const entry = internalGrid._getRowEntry(rowId);\n if (entry && isRowDirty(this.#baselines, rowId, entry.row as T)) {\n ids.push(rowId);\n }\n }\n for (const newId of this.#newRowIds) {\n ids.push(newId);\n }\n return ids;\n }\n\n /**\n * Revert a row to its baseline values (mutates the current row in-place).\n * Triggers a re-render.\n *\n * @param rowId - Row ID (from `getRowId`)\n */\n revertRow(rowId: string): void {\n if (!this.config.dirtyTracking) return;\n const row = this.grid.getRow(rowId) as T | undefined;\n if (!row) return;\n const reverted = revertToBaseline(this.#baselines, rowId, row);\n if (reverted) {\n this.#changedRowIds.delete(rowId);\n this.#committedDirtyRowIds.delete(rowId);\n this.emit<DirtyChangeDetail<T>>('dirty-change', {\n rowId,\n row,\n original: getOriginalRow(this.#baselines, rowId),\n type: 'reverted',\n });\n this.requestRender();\n }\n }\n\n /**\n * Revert all dirty rows to their baseline values and re-render.\n */\n revertAll(): void {\n if (!this.config.dirtyTracking) return;\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n for (const [rowId] of this.#baselines) {\n const entry = internalGrid._getRowEntry(rowId);\n if (entry) {\n revertToBaseline(this.#baselines, rowId, entry.row as T);\n }\n }\n this.#changedRowIds.clear();\n this.#committedDirtyRowIds.clear();\n this.requestRender();\n }\n\n // #endregion\n\n // #region Cell Validation\n\n /**\n * Mark a cell as invalid with an optional validation message.\n * Invalid cells are marked with a `data-invalid` attribute for styling.\n *\n * @param rowId - The row ID (from getRowId)\n * @param field - The field name\n * @param message - Optional validation message (for tooltips or display)\n *\n * @example\n * ```typescript\n * // In cell-commit handler:\n * grid.addEventListener('cell-commit', (e) => {\n * if (e.detail.field === 'email' && !isValidEmail(e.detail.value)) {\n * e.detail.setInvalid('Invalid email format');\n * }\n * });\n *\n * // Or programmatically:\n * editingPlugin.setInvalid('row-123', 'email', 'Invalid email format');\n * ```\n */\n setInvalid(rowId: string, field: string, message = ''): void {\n let rowInvalids = this.#invalidCells.get(rowId);\n if (!rowInvalids) {\n rowInvalids = new Map();\n this.#invalidCells.set(rowId, rowInvalids);\n }\n rowInvalids.set(field, message);\n this.#syncInvalidCellAttribute(rowId, field, true);\n }\n\n /**\n * Clear the invalid state for a specific cell.\n *\n * @param rowId - The row ID (from getRowId)\n * @param field - The field name\n */\n clearInvalid(rowId: string, field: string): void {\n const rowInvalids = this.#invalidCells.get(rowId);\n if (rowInvalids) {\n rowInvalids.delete(field);\n if (rowInvalids.size === 0) {\n this.#invalidCells.delete(rowId);\n }\n }\n this.#syncInvalidCellAttribute(rowId, field, false);\n }\n\n /**\n * Clear all invalid cells for a specific row.\n *\n * @param rowId - The row ID (from getRowId)\n */\n clearRowInvalid(rowId: string): void {\n const rowInvalids = this.#invalidCells.get(rowId);\n if (rowInvalids) {\n const fields = Array.from(rowInvalids.keys());\n this.#invalidCells.delete(rowId);\n fields.forEach((field) => this.#syncInvalidCellAttribute(rowId, field, false));\n }\n }\n\n /**\n * Clear all invalid cell states across all rows.\n */\n clearAllInvalid(): void {\n const entries = Array.from(this.#invalidCells.entries());\n this.#invalidCells.clear();\n entries.forEach(([rowId, fields]) => {\n fields.forEach((_, field) => this.#syncInvalidCellAttribute(rowId, field, false));\n });\n }\n\n /**\n * Check if a specific cell is marked as invalid.\n *\n * @param rowId - The row ID (from getRowId)\n * @param field - The field name\n * @returns True if the cell is marked as invalid\n */\n isCellInvalid(rowId: string, field: string): boolean {\n return this.#invalidCells.get(rowId)?.has(field) ?? false;\n }\n\n /**\n * Get the validation message for an invalid cell.\n *\n * @param rowId - The row ID (from getRowId)\n * @param field - The field name\n * @returns The validation message, or undefined if cell is valid\n */\n getInvalidMessage(rowId: string, field: string): string | undefined {\n return this.#invalidCells.get(rowId)?.get(field);\n }\n\n /**\n * Check if a row has any invalid cells.\n *\n * @param rowId - The row ID (from getRowId)\n * @returns True if the row has at least one invalid cell\n */\n hasInvalidCells(rowId: string): boolean {\n const rowInvalids = this.#invalidCells.get(rowId);\n return rowInvalids ? rowInvalids.size > 0 : false;\n }\n\n /**\n * Get all invalid fields for a row.\n *\n * @param rowId - The row ID (from getRowId)\n * @returns Map of field names to validation messages\n */\n getInvalidFields(rowId: string): Map<string, string> {\n return new Map(this.#invalidCells.get(rowId) ?? []);\n }\n\n /**\n * Sync the data-invalid attribute on a cell element.\n */\n #syncInvalidCellAttribute(rowId: string, field: string, invalid: boolean): void {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const colIndex = internalGrid._visibleColumns?.findIndex((c) => c.field === field);\n if (colIndex === -1 || colIndex === undefined) return;\n\n // Find the row element by rowId\n const rows = internalGrid._rows;\n const rowIndex = rows?.findIndex((r) => {\n try {\n return internalGrid.getRowId?.(r) === rowId;\n } catch {\n return false;\n }\n });\n if (rowIndex === -1 || rowIndex === undefined) return;\n\n const rowEl = internalGrid.findRenderedRowElement?.(rowIndex);\n const cellEl = rowEl?.querySelector(`.cell[data-col=\"${colIndex}\"]`) as HTMLElement | null;\n if (!cellEl) return;\n\n if (invalid) {\n cellEl.setAttribute('data-invalid', 'true');\n const message = this.#invalidCells.get(rowId)?.get(field);\n if (message) {\n cellEl.setAttribute('title', message);\n }\n } else {\n cellEl.removeAttribute('data-invalid');\n cellEl.removeAttribute('title');\n }\n }\n\n // #endregion\n\n /**\n * Reset all change tracking.\n * @param silent - If true, suppresses the `changed-rows-reset` event\n * @fires changed-rows-reset - Emitted when tracking is reset (unless silent)\n */\n resetChangedRows(silent?: boolean): void {\n const rows = this.changedRows;\n const ids = this.changedRowIds;\n this.#changedRowIds.clear();\n this.#committedDirtyRowIds.clear();\n this.#syncGridEditState();\n\n if (!silent) {\n this.emit<ChangedRowsResetDetail<T>>('changed-rows-reset', { rows, ids });\n }\n\n // Clear visual indicators\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n internalGrid._rowPool?.forEach((r) => r.classList.remove('changed'));\n }\n\n /**\n * Programmatically begin editing a cell.\n * @param rowIndex - Index of the row to edit\n * @param field - Field name of the column to edit\n * @fires cell-commit - Emitted when the cell value is committed (on blur or Enter)\n */\n beginCellEdit(rowIndex: number, field: string): void {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const colIndex = internalGrid._visibleColumns.findIndex((c) => c.field === field);\n if (colIndex === -1) return;\n\n const column = internalGrid._visibleColumns[colIndex];\n if (!column?.editable) return;\n\n const rowEl = internalGrid.findRenderedRowElement?.(rowIndex);\n const cellEl = rowEl?.querySelector(`.cell[data-col=\"${colIndex}\"]`) as HTMLElement | null;\n if (!cellEl) return;\n\n this.#singleCellEdit = true;\n this.#beginCellEdit(rowIndex, colIndex, cellEl);\n }\n\n /**\n * Programmatically begin editing all editable cells in a row.\n * @param rowIndex - Index of the row to edit\n * @fires cell-commit - Emitted for each cell value that is committed\n * @fires row-commit - Emitted when focus leaves the row\n */\n beginBulkEdit(rowIndex: number): void {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const editOn = this.config.editOn ?? internalGrid.effectiveConfig?.editOn;\n if (editOn === false) return;\n\n const hasEditableColumn = internalGrid._columns?.some((col) => col.editable);\n if (!hasEditableColumn) return;\n\n const rowEl = internalGrid.findRenderedRowElement?.(rowIndex);\n if (!rowEl) return;\n\n // Bulk edit clears single-cell mode\n this.#singleCellEdit = false;\n\n // Start row edit\n const rowData = internalGrid._rows[rowIndex];\n this.#startRowEdit(rowIndex, rowData);\n\n // Enter edit mode on all editable cells\n Array.from(rowEl.children).forEach((cell, i) => {\n const col = internalGrid._visibleColumns[i];\n if (col?.editable) {\n const cellEl = cell as HTMLElement;\n if (!cellEl.classList.contains('editing')) {\n this.#injectEditor(rowData, rowIndex, col, i, cellEl, true);\n }\n }\n });\n\n // Focus the first editable cell\n setTimeout(() => {\n let targetCell = rowEl.querySelector(`.cell[data-col=\"${internalGrid._focusCol}\"]`);\n if (!targetCell?.classList.contains('editing')) {\n targetCell = rowEl.querySelector('.cell.editing');\n }\n if (targetCell?.classList.contains('editing')) {\n const editor = (targetCell as HTMLElement).querySelector(FOCUSABLE_EDITOR_SELECTOR) as HTMLElement | null;\n try {\n editor?.focus({ preventScroll: true });\n } catch {\n /* empty */\n }\n }\n }, 0);\n }\n\n /**\n * Commit the currently active row edit.\n * @fires row-commit - Emitted after the row edit is committed\n */\n commitActiveRowEdit(): void {\n if (this.#activeEditRow !== -1) {\n this.#exitRowEdit(this.#activeEditRow, false);\n }\n }\n\n /**\n * Cancel the currently active row edit.\n */\n cancelActiveRowEdit(): void {\n if (this.#activeEditRow !== -1) {\n this.#exitRowEdit(this.#activeEditRow, true);\n }\n }\n\n // #endregion\n\n // #region Internal Methods\n\n /**\n * Migrate all index-keyed editing state when the active edit row moves to\n * a different position in `_rows` (e.g. after sort, filter, or new data push).\n *\n * Updates: `#activeEditRow`, `#editingCells`, `#rowEditSnapshots`,\n * `#editorValueCallbacks`, and syncs `_activeEditRows` on the grid.\n */\n #migrateEditRowIndex(oldIndex: number, newIndex: number): void {\n this.#activeEditRow = newIndex;\n\n // Migrate #editingCells keys (\"rowIndex:colIndex\")\n const migratedCells = new Set<string>();\n const prefix = `${oldIndex}:`;\n for (const cellKey of this.#editingCells) {\n if (cellKey.startsWith(prefix)) {\n migratedCells.add(`${newIndex}:${cellKey.substring(prefix.length)}`);\n } else {\n migratedCells.add(cellKey);\n }\n }\n this.#editingCells.clear();\n for (const key of migratedCells) {\n this.#editingCells.add(key);\n }\n\n // Migrate #rowEditSnapshots key\n const snapshot = this.#rowEditSnapshots.get(oldIndex);\n if (snapshot !== undefined) {\n this.#rowEditSnapshots.delete(oldIndex);\n this.#rowEditSnapshots.set(newIndex, snapshot);\n }\n\n // Migrate #editorValueCallbacks keys (\"rowIndex:field\")\n const updates: [string, (newValue: unknown) => void][] = [];\n for (const [key, cb] of this.#editorValueCallbacks) {\n if (key.startsWith(prefix)) {\n updates.push([`${newIndex}:${key.substring(prefix.length)}`, cb]);\n this.#editorValueCallbacks.delete(key);\n }\n }\n for (const [key, cb] of updates) {\n this.#editorValueCallbacks.set(key, cb);\n }\n\n // Sync the grid's rendering state so rows.ts checks the correct index\n this.#syncGridEditState();\n }\n\n /**\n * Begin editing a single cell.\n */\n #beginCellEdit(rowIndex: number, colIndex: number, cellEl: HTMLElement): void {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const rowData = internalGrid._rows[rowIndex];\n const column = internalGrid._visibleColumns[colIndex];\n\n if (!rowData || !column?.editable) return;\n if (cellEl.classList.contains('editing')) return;\n\n // Start row edit if not already\n if (this.#activeEditRow !== rowIndex) {\n this.#startRowEdit(rowIndex, rowData);\n }\n\n this.#activeEditCol = colIndex;\n this.#injectEditor(rowData, rowIndex, column, colIndex, cellEl, false);\n }\n\n /**\n * Focus the editor input in the currently focused cell (grid mode only).\n * Used when pressing Enter to enter edit mode from navigation mode.\n */\n #focusCurrentCellEditor(): void {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const focusRow = internalGrid._focusRow;\n const focusCol = internalGrid._focusCol;\n\n if (focusRow < 0 || focusCol < 0) return;\n\n const rowEl = internalGrid.findRenderedRowElement?.(focusRow);\n const cellEl = rowEl?.querySelector(`.cell[data-col=\"${focusCol}\"]`) as HTMLElement | null;\n\n if (cellEl?.classList.contains('editing')) {\n const editor = cellEl.querySelector(FOCUSABLE_EDITOR_SELECTOR) as HTMLElement | null;\n if (editor) {\n this.#gridModeEditLocked = false; // Unlock edit mode - user pressed Enter\n editor.focus();\n this.#gridModeInputFocused = true;\n // Select all text in text inputs for quick replacement\n if (editor instanceof HTMLInputElement && (editor.type === 'text' || editor.type === 'number')) {\n editor.select();\n }\n }\n }\n }\n\n /**\n * Handle Tab/Shift+Tab navigation while editing.\n * Moves to next/previous editable cell, staying in edit mode.\n * Wraps to next/previous row when reaching row boundaries.\n */\n #handleTabNavigation(forward: boolean): void {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const rows = internalGrid._rows;\n // In grid mode, use focusRow since there's no active edit row\n const currentRow = this.#isGridMode ? internalGrid._focusRow : this.#activeEditRow;\n\n // Get editable column indices\n const editableCols = internalGrid._visibleColumns.map((c, i) => (c.editable ? i : -1)).filter((i) => i >= 0);\n if (editableCols.length === 0) return;\n\n const currentIdx = editableCols.indexOf(internalGrid._focusCol);\n const nextIdx = currentIdx + (forward ? 1 : -1);\n\n // Can move within same row?\n if (nextIdx >= 0 && nextIdx < editableCols.length) {\n internalGrid._focusCol = editableCols[nextIdx];\n const rowEl = internalGrid.findRenderedRowElement?.(currentRow);\n const cellEl = rowEl?.querySelector(`.cell[data-col=\"${editableCols[nextIdx]}\"]`) as HTMLElement | null;\n if (cellEl?.classList.contains('editing')) {\n const editor = cellEl.querySelector(FOCUSABLE_EDITOR_SELECTOR) as HTMLElement | null;\n editor?.focus({ preventScroll: true });\n }\n ensureCellVisible(internalGrid, { forceHorizontalScroll: true });\n return;\n }\n\n // Can move to adjacent row?\n const nextRow = currentRow + (forward ? 1 : -1);\n if (nextRow >= 0 && nextRow < rows.length) {\n // In grid mode, just move focus (all rows are always editable)\n if (this.#isGridMode) {\n internalGrid._focusRow = nextRow;\n internalGrid._focusCol = forward ? editableCols[0] : editableCols[editableCols.length - 1];\n ensureCellVisible(internalGrid, { forceHorizontalScroll: true });\n // Focus the editor in the new cell after render\n this.requestAfterRender();\n setTimeout(() => {\n const rowEl = internalGrid.findRenderedRowElement?.(nextRow);\n const cellEl = rowEl?.querySelector(`.cell[data-col=\"${internalGrid._focusCol}\"]`) as HTMLElement | null;\n if (cellEl?.classList.contains('editing')) {\n const editor = cellEl.querySelector(FOCUSABLE_EDITOR_SELECTOR) as HTMLElement | null;\n editor?.focus({ preventScroll: true });\n }\n }, 0);\n } else {\n // In row mode, commit current row and enter next row\n this.#exitRowEdit(currentRow, false);\n internalGrid._focusRow = nextRow;\n internalGrid._focusCol = forward ? editableCols[0] : editableCols[editableCols.length - 1];\n this.beginBulkEdit(nextRow);\n ensureCellVisible(internalGrid, { forceHorizontalScroll: true });\n }\n }\n // else: at boundary - stay put\n }\n\n /**\n * Sync the internal grid state with the plugin's editing state.\n */\n #syncGridEditState(): void {\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n internalGrid._activeEditRows = this.#activeEditRow;\n internalGrid._rowEditSnapshots = this.#rowEditSnapshots;\n }\n\n /**\n * Snapshot original row data and mark as editing.\n */\n #startRowEdit(rowIndex: number, rowData: T): void {\n if (this.#activeEditRow !== rowIndex) {\n // Commit the previous row before starting a new one\n if (this.#activeEditRow !== -1) {\n this.#exitRowEdit(this.#activeEditRow, false);\n }\n this.#rowEditSnapshots.set(rowIndex, { ...rowData });\n this.#activeEditRow = rowIndex;\n this.#activeEditRowRef = rowData;\n\n // Store stable row ID for resilience against _rows replacement during editing\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n try {\n this.#activeEditRowId = internalGrid.getRowId?.(rowData) ?? undefined;\n } catch {\n this.#activeEditRowId = undefined;\n }\n\n this.#syncGridEditState();\n\n // Emit edit-open event (row mode only)\n if (!this.#isGridMode) {\n this.emit<EditOpenDetail<T>>('edit-open', {\n rowIndex,\n rowId: this.#activeEditRowId ?? '',\n row: rowData,\n });\n }\n }\n }\n\n /**\n * Exit editing for a row.\n */\n #exitRowEdit(rowIndex: number, revert: boolean): void {\n if (this.#activeEditRow !== rowIndex) return;\n\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const snapshot = this.#rowEditSnapshots.get(rowIndex);\n const rowEl = internalGrid.findRenderedRowElement?.(rowIndex);\n\n // Resolve the row being edited using the stored row ID.\n // The _rows array may have been replaced (e.g. Angular pushing new rows\n // via directive effect) since editing started, so _rows[rowIndex] could\n // point to a completely different row. The ID map is always up-to-date.\n // Without an ID we fall back to the stored row reference from edit-open\n // (#activeEditRowRef) — safer than _rows[rowIndex] which may be stale.\n let rowId = this.#activeEditRowId;\n const entry = rowId ? internalGrid._getRowEntry(rowId) : undefined;\n const current = entry?.row ?? this.#activeEditRowRef ?? internalGrid._rows[rowIndex];\n\n if (!rowId && current) {\n try {\n rowId = internalGrid.getRowId?.(current);\n } catch {\n // Row has no ID - skip ID-based tracking\n }\n }\n\n // Collect and commit values from active editors before re-rendering\n if (!revert && rowEl && current) {\n const editingCells = rowEl.querySelectorAll('.cell.editing');\n editingCells.forEach((cell) => {\n const colIndex = Number((cell as HTMLElement).getAttribute('data-col'));\n if (isNaN(colIndex)) return;\n const col = internalGrid._visibleColumns[colIndex];\n if (!col) return;\n\n // Skip cells with externally-managed editors (framework adapters like Angular/React/Vue).\n // These editors handle their own commits via the commit() callback - we should NOT\n // try to read values from their DOM inputs (which may contain formatted display values).\n if ((cell as HTMLElement).hasAttribute('data-editor-managed')) {\n return;\n }\n\n const input = cell.querySelector('input,textarea,select') as\n | HTMLInputElement\n | HTMLTextAreaElement\n | HTMLSelectElement\n | null;\n if (input) {\n const field = col.field as keyof T;\n const originalValue = current[field];\n const val = getInputValue(input, col, originalValue);\n if (originalValue !== val) {\n this.#commitCellValue(rowIndex, col, val, current);\n }\n }\n });\n }\n\n // Flush managed editors (framework adapters) before clearing state.\n // At this point the commit() callback is still active, so editors can\n // synchronously commit their pending values in response to this event.\n if (!revert && !this.#isGridMode && current) {\n this.emit<BeforeEditCloseDetail<T>>('before-edit-close', {\n rowIndex,\n rowId: rowId ?? '',\n row: current,\n });\n }\n\n // Revert if requested\n if (revert && snapshot && current) {\n Object.keys(snapshot as object).forEach((k) => {\n (current as Record<string, unknown>)[k] = (snapshot as Record<string, unknown>)[k];\n });\n if (rowId) {\n this.#changedRowIds.delete(rowId);\n this.#committedDirtyRowIds.delete(rowId);\n this.clearRowInvalid(rowId);\n }\n } else if (!revert && current) {\n // Compare snapshot vs current to detect if changes were made during THIS edit session\n const changedThisSession = this.#hasRowChanged(snapshot, current);\n\n // Check if this row has any cumulative changes (via ID tracking)\n // Fall back to session-based detection when no row ID is available\n const changed = rowId ? this.#changedRowIds.has(rowId) : changedThisSession;\n\n // Emit cancelable row-commit event\n const cancelled = this.emitCancelable<RowCommitDetail<T>>('row-commit', {\n rowIndex,\n rowId: rowId ?? '',\n row: current,\n oldValue: snapshot,\n newValue: current,\n changed,\n changedRows: this.changedRows,\n changedRowIds: this.changedRowIds,\n });\n\n // If consumer called preventDefault(), revert the row\n if (cancelled && snapshot) {\n Object.keys(snapshot as object).forEach((k) => {\n (current as Record<string, unknown>)[k] = (snapshot as Record<string, unknown>)[k];\n });\n if (rowId) {\n this.#changedRowIds.delete(rowId);\n this.#committedDirtyRowIds.delete(rowId);\n this.clearRowInvalid(rowId);\n }\n } else if (!cancelled) {\n // Mark row as committed-dirty if it has actual changes vs baseline\n if (rowId && this.config.dirtyTracking) {\n if (isRowDirty(this.#baselines, rowId, current)) {\n this.#committedDirtyRowIds.add(rowId);\n } else {\n this.#committedDirtyRowIds.delete(rowId);\n }\n }\n\n if (changedThisSession && this.isAnimationEnabled) {\n // Animate the row only if changes were made during this edit session\n // (deferred to afterRender so the row element exists after re-render)\n this.#pendingRowAnimation = rowIndex;\n }\n }\n }\n\n // Clear editing state\n this.#rowEditSnapshots.delete(rowIndex);\n this.#activeEditRow = -1;\n this.#activeEditRowId = undefined;\n this.#activeEditRowRef = undefined;\n this.#activeEditCol = -1;\n this.#singleCellEdit = false;\n this.#syncGridEditState();\n\n // Remove all editing cells for this row.\n // Note: these keys use the rowIndex captured at edit-open time. Even if _rows\n // was replaced and the row moved to a different index, the keys still match\n // what was inserted during this edit session (same captured rowIndex).\n for (const cellKey of this.#editingCells) {\n if (cellKey.startsWith(`${rowIndex}:`)) {\n this.#editingCells.delete(cellKey);\n }\n }\n // Remove value-change callbacks for this row (same captured-index rationale)\n for (const callbackKey of this.#editorValueCallbacks.keys()) {\n if (callbackKey.startsWith(`${rowIndex}:`)) {\n this.#editorValueCallbacks.delete(callbackKey);\n }\n }\n\n // Mark that focus should be restored after the upcoming render completes.\n // This must be set BEFORE refreshVirtualWindow because it calls afterRender()\n // synchronously, which reads this flag.\n this.#pendingFocusRestore = true;\n\n // Re-render the row to remove editors\n if (rowEl) {\n // Remove editing class and re-render cells\n rowEl.querySelectorAll('.cell.editing').forEach((cell) => {\n cell.classList.remove('editing');\n clearEditingState(cell.parentElement as RowElementInternal);\n });\n\n // Refresh the virtual window to restore cell content WITHOUT rebuilding\n // the row model. requestRender() would trigger processRows (ROWS phase)\n // which re-sorts — causing the edited row to jump to a new position and\n // disappear from view. refreshVirtualWindow re-renders visible cells from\n // the current _rows order, keeping the row in place until the user\n // explicitly sorts again or new data arrives.\n internalGrid.refreshVirtualWindow(true);\n } else {\n // Row not visible - restore focus immediately (no render will happen)\n this.#restoreCellFocus(internalGrid);\n this.#pendingFocusRestore = false;\n }\n\n // Emit edit-close event (row mode only, fires for both commit and revert)\n if (!this.#isGridMode && current) {\n this.emit<EditCloseDetail<T>>('edit-close', {\n rowIndex,\n rowId: rowId ?? '',\n row: current,\n reverted: revert,\n });\n }\n }\n\n /**\n * Commit a single cell value change.\n * Uses ID-based change tracking for stability when rows are reordered.\n */\n #commitCellValue(rowIndex: number, column: ColumnConfig<T>, newValue: unknown, rowData: T): void {\n const field = column.field;\n if (!isSafePropertyKey(field)) return;\n const oldValue = (rowData as Record<string, unknown>)[field];\n if (oldValue === newValue) return;\n\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n\n // Get row ID for change tracking (may not exist if getRowId not configured)\n let rowId: string | undefined;\n try {\n rowId = this.grid.getRowId(rowData);\n } catch {\n // Row has no ID - will still work but won't be tracked in changedRowIds\n }\n\n const firstTime = rowId ? !this.#changedRowIds.has(rowId) : true;\n\n // Create updateRow helper for cascade updates (noop if row has no ID)\n const updateRow: (changes: Partial<T>) => void = rowId\n ? (changes) => this.grid.updateRow(rowId!, changes as Record<string, unknown>, 'cascade')\n : noopUpdateRow;\n\n // Track whether setInvalid was called during event handling\n let invalidWasSet = false;\n\n // Create setInvalid callback for validation (noop if row has no ID)\n const setInvalid = rowId\n ? (message?: string) => {\n invalidWasSet = true;\n this.setInvalid(rowId!, field, message ?? '');\n }\n : () => {}; // eslint-disable-line @typescript-eslint/no-empty-function\n\n // Emit cancelable event BEFORE applying the value\n const cancelled = this.emitCancelable<CellCommitDetail<T>>('cell-commit', {\n row: rowData,\n rowId: rowId ?? '',\n field,\n oldValue,\n value: newValue,\n rowIndex,\n changedRows: this.changedRows,\n changedRowIds: this.changedRowIds,\n firstTimeForRow: firstTime,\n updateRow,\n setInvalid,\n });\n\n // If consumer called preventDefault(), abort the commit\n if (cancelled) return;\n\n // Clear any previous invalid state for this cell ONLY if setInvalid wasn't called\n // (if setInvalid was called, the handler wants it to remain invalid)\n if (rowId && !invalidWasSet && this.isCellInvalid(rowId, field)) {\n this.clearInvalid(rowId, field);\n }\n\n // Apply the value and mark row as changed\n (rowData as Record<string, unknown>)[field] = newValue;\n if (rowId) {\n this.#changedRowIds.add(rowId);\n }\n this.#syncGridEditState();\n\n // Emit dirty-change event if dirty tracking is enabled\n if (this.config.dirtyTracking && rowId) {\n const dirty = isRowDirty(this.#baselines, rowId, rowData);\n this.emit<DirtyChangeDetail<T>>('dirty-change', {\n rowId,\n row: rowData,\n original: getOriginalRow(this.#baselines, rowId),\n type: dirty ? 'modified' : 'pristine',\n });\n }\n\n // Notify other plugins (e.g., UndoRedoPlugin) about the committed edit\n this.emitPluginEvent('cell-edit-committed', {\n rowIndex,\n field,\n oldValue,\n newValue,\n });\n\n // Mark the row visually as changed (animation happens when row edit closes)\n const rowEl = internalGrid.findRenderedRowElement?.(rowIndex);\n if (rowEl) {\n rowEl.classList.add('changed');\n }\n }\n\n /**\n * Inject an editor into a cell.\n */\n #injectEditor(\n rowData: T,\n rowIndex: number,\n column: ColumnConfig<T>,\n colIndex: number,\n cell: HTMLElement,\n skipFocus: boolean,\n ): void {\n if (!column.editable) return;\n if (cell.classList.contains('editing')) return;\n\n // Get row ID for updateRow helper (may not exist)\n let rowId: string | undefined;\n try {\n rowId = this.grid.getRowId(rowData);\n } catch {\n // Row has no ID\n }\n\n // Create updateRow helper for cascade updates (noop if row has no ID)\n const updateRow: (changes: Partial<T>) => void = rowId\n ? (changes) => this.grid.updateRow(rowId!, changes as Record<string, unknown>, 'cascade')\n : noopUpdateRow;\n\n const originalValue = isSafePropertyKey(column.field)\n ? (rowData as Record<string, unknown>)[column.field]\n : undefined;\n\n cell.classList.add('editing');\n this.#editingCells.add(`${rowIndex}:${colIndex}`);\n\n const rowEl = cell.parentElement as RowElementInternal | null;\n if (rowEl) incrementEditingCount(rowEl);\n\n let editFinalized = false;\n const commit = (newValue: unknown) => {\n // In grid mode, always allow commits (we're always editing)\n // In row mode, only allow commits if we're in an active edit session\n if (editFinalized || (!this.#isGridMode && this.#activeEditRow === -1)) return;\n // Resolve row and index fresh at commit time.\n // With a row ID we use _getRowEntry for O(1) lookup — this is resilient\n // against _rows being replaced (e.g. Angular directive effect).\n // Without a row ID we fall back to the captured rowData reference.\n // Using _rows[rowIndex] without an ID is unsafe: the index may be stale\n // after _rows replacement, which would commit to the WRONG row.\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const entry = rowId ? internalGrid._getRowEntry(rowId) : undefined;\n const currentRowData = (entry?.row ?? rowData) as T;\n const currentIndex = entry?.index ?? rowIndex;\n this.#commitCellValue(currentIndex, column, newValue, currentRowData);\n };\n const cancel = () => {\n editFinalized = true;\n if (isSafePropertyKey(column.field)) {\n // Same ID-first / captured-rowData fallback as commit — see comment above.\n const internalGrid = this.grid as unknown as InternalGrid<T>;\n const entry = rowId ? internalGrid._getRowEntry(rowId) : undefined;\n const currentRowData = (entry?.row ?? rowData) as T;\n (currentRowData as Record<string, unknown>)[column.field] = originalValue;\n }\n };\n\n const editorHost = document.createElement('div');\n editorHost.className = 'tbw-editor-host';\n cell.innerHTML = '';\n cell.appendChild(editorHost);\n\n // Keydown handler for Enter/Escape\n editorHost.addEventListener('keydown', (e: KeyboardEvent) => {\n if (e.key === 'Enter') {\n // In grid mode, Enter just commits without exiting\n if (this.#isGridMode) {\n e.stopPropagation();\n e.preventDefault();\n // Get current value and commit\n const input = editorHost.querySelector('input,textarea,select') as\n | HTMLInputElement\n | HTMLTextAreaElement\n | HTMLSelectElement\n | null;\n if (input) {\n commit(getInputValue(input, column as ColumnConfig<unknown>, originalValue));\n }\n return;\n }\n // Allow users to prevent edit close via callback (e.g., when overlay is open)\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(e);\n if (shouldClose === false) {\n return; // Let the event propagate to overlay\n }\n }\n e.stopPropagation();\n e.preventDefault();\n editFinalized = true;\n this.#exitRowEdit(rowIndex, false);\n }\n if (e.key === 'Escape') {\n // In grid mode, Escape doesn't exit edit mode\n if (this.#isGridMode) {\n e.stopPropagation();\n e.preventDefault();\n return;\n }\n // Allow users to prevent edit close via callback (e.g., when overlay is open)\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(e);\n if (shouldClose === false) {\n return; // Let the event propagate to overlay\n }\n }\n e.stopPropagation();\n e.preventDefault();\n cancel();\n this.#exitRowEdit(rowIndex, true);\n }\n });\n\n const colInternal = column as ColumnInternal<T>;\n const tplHolder = colInternal.__editorTemplate;\n // Resolve editor using priority chain: column → template → typeDefaults → adapter → built-in\n const editorSpec = resolveEditor(this.grid as unknown as InternalGrid<T>, colInternal) ?? defaultEditorFor(column);\n const value = originalValue;\n\n // Value-change callback registration.\n // Editors call onValueChange(cb) to receive pushes when the underlying row\n // is mutated externally (e.g., via updateRow from another cell's commit).\n // Multiple callbacks can be registered (user + auto-wire).\n const callbackKey = `${rowIndex}:${column.field}`;\n const callbacks: Array<(newValue: unknown) => void> = [];\n this.#editorValueCallbacks.set(callbackKey, (newVal) => {\n for (const cb of callbacks) cb(newVal);\n });\n const onValueChange = (cb: (newValue: unknown) => void) => {\n callbacks.push(cb);\n };\n\n if (editorSpec === 'template' && tplHolder) {\n this.#renderTemplateEditor(editorHost, colInternal, rowData, originalValue, commit, cancel, skipFocus, rowIndex);\n // Auto-update built-in template editors when value changes externally\n onValueChange((newVal) => {\n const input = editorHost.querySelector<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>(\n 'input,textarea,select',\n );\n if (input) {\n if (input instanceof HTMLInputElement && input.type === 'checkbox') {\n input.checked = !!newVal;\n } else {\n input.value = String(newVal ?? '');\n }\n }\n });\n } else if (typeof editorSpec === 'string') {\n const el = document.createElement(editorSpec) as HTMLElement & { value?: unknown };\n el.value = value;\n el.addEventListener('change', () => commit(el.value));\n // Auto-update custom element editors when value changes externally\n onValueChange((newVal) => {\n el.value = newVal;\n });\n editorHost.appendChild(el);\n if (!skipFocus) {\n queueMicrotask(() => {\n const focusable = editorHost.querySelector(FOCUSABLE_EDITOR_SELECTOR) as HTMLElement | null;\n focusable?.focus({ preventScroll: true });\n });\n }\n } else if (typeof editorSpec === 'function') {\n const ctx: EditorContext<T> = {\n row: rowData,\n rowId: rowId ?? '',\n value,\n field: column.field,\n column,\n commit,\n cancel,\n updateRow,\n onValueChange,\n };\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const produced = (editorSpec as any)(ctx);\n if (typeof produced === 'string') {\n editorHost.innerHTML = produced;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n wireEditorInputs(editorHost, column as any, commit, originalValue);\n // Auto-update wired inputs when value changes externally\n onValueChange((newVal) => {\n const input = editorHost.querySelector<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>(\n 'input,textarea,select',\n );\n if (input) {\n if (input instanceof HTMLInputElement && input.type === 'checkbox') {\n input.checked = !!newVal;\n } else {\n input.value = String(newVal ?? '');\n }\n }\n });\n } else if (produced instanceof Node) {\n editorHost.appendChild(produced);\n const isSimpleInput =\n produced instanceof HTMLInputElement ||\n produced instanceof HTMLSelectElement ||\n produced instanceof HTMLTextAreaElement;\n if (!isSimpleInput) {\n cell.setAttribute('data-editor-managed', '');\n } else {\n // Auto-update simple inputs returned by factory functions\n onValueChange((newVal) => {\n if (produced instanceof HTMLInputElement && produced.type === 'checkbox') {\n produced.checked = !!newVal;\n } else {\n (produced as HTMLInputElement).value = String(newVal ?? '');\n }\n });\n }\n } else if (!produced && editorHost.hasChildNodes()) {\n // Factory returned void but mounted content into the editor host\n // (e.g. Angular/React/Vue adapter component editor). Mark the cell\n // as externally managed so the native commit loop in #exitRowEdit\n // does not read raw input values from framework editor DOM.\n cell.setAttribute('data-editor-managed', '');\n }\n if (!skipFocus) {\n queueMicrotask(() => {\n const focusable = editorHost.querySelector(FOCUSABLE_EDITOR_SELECTOR) as HTMLElement | null;\n focusable?.focus({ preventScroll: true });\n });\n }\n } else if (editorSpec && typeof editorSpec === 'object') {\n const placeholder = document.createElement('div');\n placeholder.setAttribute('data-external-editor', '');\n placeholder.setAttribute('data-field', column.field);\n editorHost.appendChild(placeholder);\n cell.setAttribute('data-editor-managed', '');\n const context: EditorContext<T> = {\n row: rowData,\n rowId: rowId ?? '',\n value,\n field: column.field,\n column,\n commit,\n cancel,\n updateRow,\n onValueChange,\n };\n if (editorSpec.mount) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n editorSpec.mount({ placeholder, context: context as any, spec: editorSpec });\n } catch (e) {\n console.warn(`[tbw-grid] External editor mount error for column '${column.field}':`, e);\n }\n } else {\n (this.grid as unknown as HTMLElement).dispatchEvent(\n new CustomEvent('mount-external-editor', { detail: { placeholder, spec: editorSpec, context } }),\n );\n }\n }\n }\n\n /**\n * Render a template-based editor.\n */\n #renderTemplateEditor(\n editorHost: HTMLElement,\n column: ColumnInternal<T>,\n rowData: T,\n originalValue: unknown,\n commit: (value: unknown) => void,\n cancel: () => void,\n skipFocus: boolean,\n rowIndex: number,\n ): void {\n const tplHolder = column.__editorTemplate;\n if (!tplHolder) return;\n\n const clone = tplHolder.cloneNode(true) as HTMLElement;\n const compiledEditor = column.__compiledEditor;\n\n if (compiledEditor) {\n clone.innerHTML = compiledEditor({\n row: rowData,\n value: originalValue,\n field: column.field,\n column,\n commit,\n cancel,\n });\n } else {\n clone.querySelectorAll<HTMLElement>('*').forEach((node) => {\n if (node.childNodes.length === 1 && node.firstChild?.nodeType === Node.TEXT_NODE) {\n node.textContent =\n node.textContent\n ?.replace(/{{\\s*value\\s*}}/g, originalValue == null ? '' : String(originalValue))\n .replace(/{{\\s*row\\.([a-zA-Z0-9_]+)\\s*}}/g, (_m, g: string) => {\n if (!isSafePropertyKey(g)) return '';\n const v = (rowData as Record<string, unknown>)[g];\n return v == null ? '' : String(v);\n }) || '';\n }\n });\n }\n\n const input = clone.querySelector<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>(\n 'input,textarea,select',\n );\n if (input) {\n if (input instanceof HTMLInputElement && input.type === 'checkbox') {\n input.checked = !!originalValue;\n } else {\n input.value = String(originalValue ?? '');\n }\n\n let editFinalized = false;\n input.addEventListener('blur', () => {\n if (editFinalized) return;\n commit(getInputValue(input, column, originalValue));\n });\n input.addEventListener('keydown', (evt) => {\n const e = evt as KeyboardEvent;\n if (e.key === 'Enter') {\n // Allow users to prevent edit close via callback (e.g., when overlay is open)\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(e);\n if (shouldClose === false) {\n return; // Let the event propagate to overlay\n }\n }\n e.stopPropagation();\n e.preventDefault();\n editFinalized = true;\n commit(getInputValue(input, column, originalValue));\n this.#exitRowEdit(rowIndex, false);\n }\n if (e.key === 'Escape') {\n // Allow users to prevent edit close via callback (e.g., when overlay is open)\n if (this.config.onBeforeEditClose) {\n const shouldClose = this.config.onBeforeEditClose(e);\n if (shouldClose === false) {\n return; // Let the event propagate to overlay\n }\n }\n e.stopPropagation();\n e.preventDefault();\n cancel();\n this.#exitRowEdit(rowIndex, true);\n }\n });\n if (input instanceof HTMLInputElement && input.type === 'checkbox') {\n input.addEventListener('change', () => commit(input.checked));\n }\n if (!skipFocus) {\n setTimeout(() => input.focus({ preventScroll: true }), 0);\n }\n }\n editorHost.appendChild(clone);\n }\n\n /**\n * Compare snapshot vs current row to detect if any values changed during this edit session.\n * Uses shallow comparison of all properties.\n */\n #hasRowChanged(snapshot: T | undefined, current: T): boolean {\n if (!snapshot) return false;\n\n const snapshotObj = snapshot as Record<string, unknown>;\n const currentObj = current as Record<string, unknown>;\n\n // Check all keys in both objects\n const allKeys = new Set([...Object.keys(snapshotObj), ...Object.keys(currentObj)]);\n for (const key of allKeys) {\n if (snapshotObj[key] !== currentObj[key]) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Restore focus to cell after exiting edit mode.\n */\n #restoreCellFocus(internalGrid: InternalGrid<T>): void {\n queueMicrotask(() => {\n try {\n const rowIdx = internalGrid._focusRow;\n const colIdx = internalGrid._focusCol;\n const rowEl = internalGrid.findRenderedRowElement?.(rowIdx);\n if (rowEl) {\n Array.from(internalGrid._bodyEl.querySelectorAll('.cell-focus')).forEach((el) =>\n el.classList.remove('cell-focus'),\n );\n const cell = rowEl.querySelector(`.cell[data-row=\"${rowIdx}\"][data-col=\"${colIdx}\"]`) as HTMLElement | null;\n if (cell) {\n cell.classList.add('cell-focus');\n cell.setAttribute('aria-selected', 'true');\n if (!cell.hasAttribute('tabindex')) cell.setAttribute('tabindex', '-1');\n cell.focus({ preventScroll: true });\n }\n }\n } catch {\n /* empty */\n }\n });\n }\n\n // #endregion\n}\n"],"names":["createDateEditor","column","ctx","params","editorParams","input","document","createElement","type","value","Date","valueAsDate","split","min","max","placeholder","addEventListener","date","commit","nullable","fallback","default","getFullYear","String","getMonth","padStart","getDate","e","key","cancel","NULLABLE_BLANK_VALUE","defaultEditorFor","step","Number","createNumberEditor","checked","select","multi","multiple","includeEmpty","emptyOpt","textContent","emptyLabel","selected","appendChild","options","raw","resolveOptions","forEach","opt","o","label","Array","isArray","includes","values","from","selectedOptions","map","createSelectEditor","maxLength","pattern","inputVal","replace","createTextEditor","isRowDirty","baselines","rowId","currentRow","baseline","get","deepEqual","isCellDirty","field","a","b","getTime","length","i","aObj","bObj","keysA","Object","keys","keysB","markPristine","set","structuredClone","getOriginalRow","revertToBaseline","baselineObj","currentObj","isSafePropertyKey","getInputValue","originalValue","HTMLInputElement","toISOString","slice","noopUpdateRow","_changes","EditingPlugin","BaseGridPlugin","static","ownedProperties","property","level","description","isUsed","v","events","queries","name","styles","defaultConfig","mode","editOn","isGridMode","this","config","activeEditRow","activeEditRowId","activeEditRowRef","activeEditCol","rowEditSnapshots","Map","changedRowIds","Set","editingCells","editorValueCallbacks","pendingFocusRestore","pendingRowAnimation","invalidCells","gridModeInputFocused","gridModeEditLocked","singleCellEdit","baselinesWereCaptured","newRowIds","committedDirtyRowIds","attach","grid","super","signal","disconnectSignal","internalGrid","_activeEditRows","_rowEditSnapshots","defineProperty","changedRows","configurable","resetChangedRows","silent","beginBulkEdit","rowIndex","beginCellEdit","onBeforeEditClose","exitRowEdit","capture","rowEl","findRenderedRowElement","composedPath","target","gridElement","contains","containsFocus","queueMicrotask","focusTrap","related","relatedTarget","focusCurrentCellEditor","detail","source","cb","newValue","dirtyTracking","handleUndoRedo","action","row","rows","getRowId","dirty","emit","original","on","markAsNew","_isGridEditMode","classList","add","requestRender","matches","FOCUSABLE_EDITOR_SELECTOR","blur","focus","activeEl","activeElement","preventDefault","stopPropagation","detach","remove","clear","handleQuery","query","onCellClick","event","effectiveConfig","isDoubleClick","originalEvent","hasEditableColumn","_columns","some","col","editable","onKeyDown","requestAfterRender","maxRow","_rows","_focusRow","Math","ensureCellVisible","forward","shiftKey","handleTabNavigation","focusRow","focusCol","_focusCol","_visibleColumns","rowData","commitCellValue","ctrlKey","altKey","metaKey","cellEl","querySelector","activateEvent","CustomEvent","cancelable","bubbles","colIndex","trigger","dispatchEvent","legacyEvent","defaultPrevented","processColumns","columns","typeDefaults","adapter","__frameworkAdapter","getTypeDefault","typeEditorParams","appDefault","processRows","sizeBefore","size","id","has","captureBaselines","r","editRowId","editRowRef","result","newIndex","setTimeout","cancelActiveRowEdit","migrateEditRowIndex","afterRender","indexOf","restoreCellFocus","animateRow","count","cellKey","rowStr","colStr","parseInt","injectEditor","afterCellRender","context","cellElement","afterRowRender","isNew","isCommittedDirty","el","rowElement","toggle","cells","querySelectorAll","cell","getAttribute","dirtyCells","onScrollRender","getRow","push","isRowEditing","isCellEditing","isRowChanged","isRowChangedById","isDirty","isPristine","_getRowEntry","pristine","markAsPristine","delete","markAsDirty","markAllPristine","hasBaseline","getDirtyRows","entry","current","newId","dirtyRowIds","ids","revertRow","revertAll","setInvalid","message","rowInvalids","syncInvalidCellAttribute","clearInvalid","clearRowInvalid","fields","clearAllInvalid","entries","_","isCellInvalid","getInvalidMessage","hasInvalidCells","getInvalidFields","invalid","findIndex","c","setAttribute","removeAttribute","syncGridEditState","_rowPool","startRowEdit","children","targetCell","editor","preventScroll","commitActiveRowEdit","oldIndex","migratedCells","prefix","startsWith","substring","snapshot","updates","editableCols","filter","nextIdx","forceHorizontalScroll","nextRow","revert","isNaN","hasAttribute","val","k","changedThisSession","hasRowChanged","changed","cancelled","emitCancelable","oldValue","isAnimationEnabled","callbackKey","__editingCellCount","clearEditingState","parentElement","refreshVirtualWindow","reverted","firstTime","updateRow","changes","invalidWasSet","firstTimeForRow","emitPluginEvent","skipFocus","editFinalized","currentRowData","currentIndex","index","editorHost","className","innerHTML","colInternal","tplHolder","__editorTemplate","editorSpec","gridTypeDefaults","resolveEditor","callbacks","newVal","onValueChange","renderTemplateEditor","focusable","produced","HTMLSelectElement","wireEditorInputs","Node","HTMLTextAreaElement","hasChildNodes","mount","spec","console","warn","clone","cloneNode","compiledEditor","__compiledEditor","node","childNodes","firstChild","nodeType","TEXT_NODE","_m","g","evt","snapshotObj","allKeys","rowIdx","colIdx","_bodyEl"],"mappings":"+eA+FA,SAASA,EAAiBC,GACxB,OAAQC,IACN,MAAMC,EAASF,EAAOG,aAChBC,EAAQC,SAASC,cAAc,SACrCF,EAAMG,KAAO,OAGTN,EAAIO,iBAAiBC,KACvBL,EAAMM,YAAcT,EAAIO,MACM,iBAAdP,EAAIO,OAAsBP,EAAIO,QAE9CJ,EAAMI,MAAQP,EAAIO,MAAMG,MAAM,KAAK,IAEjCT,GAAQU,MAAKR,EAAMQ,IAAMV,EAAOU,KAChCV,GAAQW,MAAKT,EAAMS,IAAMX,EAAOW,KAChCX,GAAQY,cAAaV,EAAMU,YAAcZ,EAAOY,aAiCpD,OALAV,EAAMW,iBAAiB,SAzBR,KA5EnB,IAAmBC,EA6Eb,GAAKZ,EAAMI,MAgBc,iBAAdP,EAAIO,MAEbP,EAAIgB,OAAOb,EAAMI,O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