@toolbox-web/grid 1.13.0 → 1.14.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.
- package/all.js +1483 -1403
- package/all.js.map +1 -1
- package/index.js +11 -4
- package/index.js.map +1 -1
- package/lib/core/internal/row-animation.d.ts.map +1 -1
- package/lib/core/plugin/types.d.ts +1 -1
- package/lib/core/plugin/types.d.ts.map +1 -1
- package/lib/core/types.d.ts +44 -1
- package/lib/core/types.d.ts.map +1 -1
- package/lib/plugins/clipboard/ClipboardPlugin.d.ts +69 -8
- package/lib/plugins/clipboard/ClipboardPlugin.d.ts.map +1 -1
- package/lib/plugins/clipboard/index.d.ts +1 -1
- package/lib/plugins/clipboard/index.d.ts.map +1 -1
- package/lib/plugins/clipboard/index.js +257 -192
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/clipboard/types.d.ts +31 -0
- package/lib/plugins/clipboard/types.d.ts.map +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/ContextMenuPlugin.d.ts +8 -0
- package/lib/plugins/context-menu/ContextMenuPlugin.d.ts.map +1 -1
- package/lib/plugins/context-menu/index.js +75 -60
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/context-menu/types.d.ts +7 -0
- package/lib/plugins/context-menu/types.d.ts.map +1 -1
- package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
- package/lib/plugins/editing/editors.d.ts +2 -2
- package/lib/plugins/editing/editors.d.ts.map +1 -1
- package/lib/plugins/editing/index.js +420 -381
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/editing/types.d.ts +6 -23
- package/lib/plugins/editing/types.d.ts.map +1 -1
- package/lib/plugins/export/ExportPlugin.d.ts.map +1 -1
- package/lib/plugins/export/index.js +75 -66
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/index.d.ts +1 -1
- package/lib/plugins/filtering/index.d.ts.map +1 -1
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts +1 -0
- package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts.map +1 -1
- package/lib/plugins/pinned-rows/index.js +118 -87
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pinned-rows/pinned-rows.d.ts +2 -1
- package/lib/plugins/pinned-rows/pinned-rows.d.ts.map +1 -1
- package/lib/plugins/pinned-rows/types.d.ts +23 -2
- package/lib/plugins/pinned-rows/types.d.ts.map +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/print/index.js.map +1 -1
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/row-reorder/index.js.map +1 -1
- package/lib/plugins/selection/SelectionPlugin.d.ts.map +1 -1
- package/lib/plugins/selection/index.js +147 -139
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/shared/data-collection.d.ts +33 -0
- package/lib/plugins/shared/data-collection.d.ts.map +1 -0
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +23 -23
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +2 -2
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/clipboard.umd.js +5 -5
- package/umd/plugins/clipboard.umd.js.map +1 -1
- package/umd/plugins/context-menu.umd.js +1 -1
- package/umd/plugins/context-menu.umd.js.map +1 -1
- package/umd/plugins/editing.umd.js +1 -1
- package/umd/plugins/editing.umd.js.map +1 -1
- package/umd/plugins/export.umd.js +7 -7
- package/umd/plugins/export.umd.js.map +1 -1
- package/umd/plugins/pinned-rows.umd.js +1 -1
- package/umd/plugins/pinned-rows.umd.js.map +1 -1
- package/umd/plugins/selection.umd.js +2 -2
- package/umd/plugins/selection.umd.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/selection/range-selection.ts","../../../../../libs/grid/src/lib/plugins/selection/SelectionPlugin.ts"],"sourcesContent":["/**\n * Cell Range Selection Core Logic\n *\n * Pure functions for cell range selection operations.\n */\n\nimport type { InternalCellRange, CellRange } from './types';\n\n/**\n * Normalize a range so startRow/startCol are always <= endRow/endCol.\n * This handles cases where user drags from bottom-right to top-left.\n *\n * @param range - The range to normalize\n * @returns Normalized range with start <= end for both dimensions\n */\nexport function normalizeRange(range: InternalCellRange): InternalCellRange {\n return {\n startRow: Math.min(range.startRow, range.endRow),\n startCol: Math.min(range.startCol, range.endCol),\n endRow: Math.max(range.startRow, range.endRow),\n endCol: Math.max(range.startCol, range.endCol),\n };\n}\n\n/**\n * Convert an internal range to the public event format.\n *\n * @param range - The internal range to convert\n * @returns Public CellRange format with from/to coordinates\n */\nexport function toPublicRange(range: InternalCellRange): CellRange {\n const normalized = normalizeRange(range);\n return {\n from: { row: normalized.startRow, col: normalized.startCol },\n to: { row: normalized.endRow, col: normalized.endCol },\n };\n}\n\n/**\n * Convert multiple internal ranges to public format.\n *\n * @param ranges - Array of internal ranges\n * @returns Array of public CellRange format\n */\nexport function toPublicRanges(ranges: InternalCellRange[]): CellRange[] {\n return ranges.map(toPublicRange);\n}\n\n/**\n * Check if a cell is within a specific range.\n *\n * @param row - The row index to check\n * @param col - The column index to check\n * @param range - The range to check against\n * @returns True if the cell is within the range\n */\nexport function isCellInRange(row: number, col: number, range: InternalCellRange): boolean {\n const normalized = normalizeRange(range);\n return (\n row >= normalized.startRow && row <= normalized.endRow && col >= normalized.startCol && col <= normalized.endCol\n );\n}\n\n/**\n * Check if a cell is within any of the provided ranges.\n *\n * @param row - The row index to check\n * @param col - The column index to check\n * @param ranges - Array of ranges to check against\n * @returns True if the cell is within any range\n */\nexport function isCellInAnyRange(row: number, col: number, ranges: InternalCellRange[]): boolean {\n return ranges.some((range) => isCellInRange(row, col, range));\n}\n\n/**\n * Get all cells within a range as an array of {row, col} objects.\n *\n * @param range - The range to enumerate\n * @returns Array of all cell coordinates in the range\n */\nexport function getCellsInRange(range: InternalCellRange): Array<{ row: number; col: number }> {\n const cells: Array<{ row: number; col: number }> = [];\n const normalized = normalizeRange(range);\n\n for (let row = normalized.startRow; row <= normalized.endRow; row++) {\n for (let col = normalized.startCol; col <= normalized.endCol; col++) {\n cells.push({ row, col });\n }\n }\n\n return cells;\n}\n\n/**\n * Get all unique cells across multiple ranges.\n * Deduplicates cells that appear in overlapping ranges.\n *\n * @param ranges - Array of ranges to enumerate\n * @returns Array of unique cell coordinates\n */\nexport function getAllCellsInRanges(ranges: InternalCellRange[]): Array<{ row: number; col: number }> {\n const cellMap = new Map<string, { row: number; col: number }>();\n\n for (const range of ranges) {\n for (const cell of getCellsInRange(range)) {\n cellMap.set(`${cell.row},${cell.col}`, cell);\n }\n }\n\n return [...cellMap.values()];\n}\n\n/**\n * Merge overlapping or adjacent ranges into fewer ranges.\n * Simple implementation - returns ranges as-is for now.\n * More complex merging logic can be added later for optimization.\n *\n * @param ranges - Array of ranges to merge\n * @returns Merged array of ranges\n */\nexport function mergeRanges(ranges: InternalCellRange[]): InternalCellRange[] {\n // Simple implementation - more complex merging can be added later\n return ranges;\n}\n\n/**\n * Create a range from an anchor cell to a current cell position.\n * The range is not normalized - it preserves the direction of selection.\n *\n * @param anchor - The anchor cell (where selection started)\n * @param current - The current cell (where selection ends)\n * @returns An InternalCellRange from anchor to current\n */\nexport function createRangeFromAnchor(\n anchor: { row: number; col: number },\n current: { row: number; col: number }\n): InternalCellRange {\n return {\n startRow: anchor.row,\n startCol: anchor.col,\n endRow: current.row,\n endCol: current.col,\n };\n}\n\n/**\n * Calculate the number of cells in a range.\n *\n * @param range - The range to measure\n * @returns Total number of cells in the range\n */\nexport function getRangeCellCount(range: InternalCellRange): number {\n const normalized = normalizeRange(range);\n const rowCount = normalized.endRow - normalized.startRow + 1;\n const colCount = normalized.endCol - normalized.startCol + 1;\n return rowCount * colCount;\n}\n\n/**\n * Check if two ranges are equal (same boundaries).\n *\n * @param a - First range\n * @param b - Second range\n * @returns True if ranges have same boundaries after normalization\n */\nexport function rangesEqual(a: InternalCellRange, b: InternalCellRange): boolean {\n const normA = normalizeRange(a);\n const normB = normalizeRange(b);\n return (\n normA.startRow === normB.startRow &&\n normA.startCol === normB.startCol &&\n normA.endRow === normB.endRow &&\n normA.endCol === normB.endCol\n );\n}\n\n/**\n * Check if a range is a single cell (1x1).\n *\n * @param range - The range to check\n * @returns True if the range is exactly one cell\n */\nexport function isSingleCell(range: InternalCellRange): boolean {\n const normalized = normalizeRange(range);\n return normalized.startRow === normalized.endRow && normalized.startCol === normalized.endCol;\n}\n","/**\n * Selection Plugin (Class-based)\n *\n * Provides selection functionality for tbw-grid.\n * Supports three modes:\n * - 'cell': Single cell selection (default). No border, just focus highlight.\n * - 'row': Row selection. Clicking a cell selects the entire row.\n * - 'range': Range selection. Shift+click or drag to select rectangular cell ranges.\n */\n\nimport { clearCellFocus, getRowIndexFromCell } from '../../core/internal/utils';\nimport type { GridElement, PluginManifest, PluginQuery } from '../../core/plugin/base-plugin';\nimport { BaseGridPlugin, CellClickEvent, CellMouseEvent } from '../../core/plugin/base-plugin';\nimport { isExpanderColumn, isUtilityColumn } from '../../core/plugin/expander-column';\nimport type { ColumnConfig } from '../../core/types';\nimport {\n createRangeFromAnchor,\n getAllCellsInRanges,\n isCellInAnyRange,\n normalizeRange,\n rangesEqual,\n toPublicRanges,\n} from './range-selection';\nimport styles from './selection.css?inline';\nimport type {\n CellRange,\n InternalCellRange,\n SelectionChangeDetail,\n SelectionConfig,\n SelectionMode,\n SelectionResult,\n} from './types';\n\n/** Special field name for the selection checkbox column */\nconst CHECKBOX_COLUMN_FIELD = '__tbw_checkbox';\n\n/**\n * Build the selection change event detail for the current state.\n */\nfunction buildSelectionEvent(\n mode: SelectionMode,\n state: {\n selectedCell: { row: number; col: number } | null;\n selected: Set<number>;\n ranges: InternalCellRange[];\n },\n colCount: number,\n): SelectionChangeDetail {\n if (mode === 'cell' && state.selectedCell) {\n return {\n mode,\n ranges: [\n {\n from: { row: state.selectedCell.row, col: state.selectedCell.col },\n to: { row: state.selectedCell.row, col: state.selectedCell.col },\n },\n ],\n };\n }\n\n if (mode === 'row' && state.selected.size > 0) {\n // Sort rows and merge contiguous indices into minimal ranges\n const sorted = [...state.selected].sort((a, b) => a - b);\n const ranges: CellRange[] = [];\n let start = sorted[0];\n let end = start;\n for (let i = 1; i < sorted.length; i++) {\n if (sorted[i] === end + 1) {\n end = sorted[i];\n } else {\n ranges.push({ from: { row: start, col: 0 }, to: { row: end, col: colCount - 1 } });\n start = sorted[i];\n end = start;\n }\n }\n ranges.push({ from: { row: start, col: 0 }, to: { row: end, col: colCount - 1 } });\n return { mode, ranges };\n }\n\n if (mode === 'range' && state.ranges.length > 0) {\n return { mode, ranges: toPublicRanges(state.ranges) };\n }\n\n return { mode, ranges: [] };\n}\n\n/**\n * Selection Plugin for tbw-grid\n *\n * Adds cell, row, and range selection capabilities to the grid with full keyboard support.\n * Whether you need simple cell highlighting or complex multi-range selections, this plugin has you covered.\n *\n * ## Installation\n *\n * ```ts\n * import { SelectionPlugin } from '@toolbox-web/grid/plugins/selection';\n * ```\n *\n * ## Selection Modes\n *\n * Configure the plugin with one of three modes via {@link SelectionConfig}:\n *\n * - **`'cell'`** - Single cell selection (default). Click cells to select individually.\n * - **`'row'`** - Full row selection. Click anywhere in a row to select the entire row.\n * - **`'range'`** - Rectangular selection. Click and drag or Shift+Click to select ranges.\n *\n * ## Keyboard Shortcuts\n *\n * | Shortcut | Action |\n * |----------|--------|\n * | `Arrow Keys` | Move selection |\n * | `Shift + Arrow` | Extend selection (range mode) |\n * | `Ctrl/Cmd + Click` | Toggle selection (multi-select) |\n * | `Shift + Click` | Extend to clicked cell/row |\n * | `Ctrl/Cmd + A` | Select all (range mode) |\n * | `Escape` | Clear selection |\n *\n * ## CSS Custom Properties\n *\n * | Property | Description |\n * |----------|-------------|\n * | `--tbw-focus-background` | Focused row background |\n * | `--tbw-range-selection-bg` | Range selection fill |\n * | `--tbw-range-border-color` | Range selection border |\n *\n * @example Basic row selection\n * ```ts\n * grid.gridConfig = {\n * columns: [...],\n * plugins: [new SelectionPlugin({ mode: 'row' })],\n * };\n * ```\n *\n * @example Range selection with event handling\n * ```ts\n * grid.gridConfig = {\n * plugins: [new SelectionPlugin({ mode: 'range' })],\n * };\n *\n * grid.addEventListener('selection-change', (e) => {\n * const { mode, ranges } = e.detail;\n * console.log(`Selected ${ranges.length} ranges in ${mode} mode`);\n * });\n * ```\n *\n * @example Programmatic selection control\n * ```ts\n * const plugin = grid.getPlugin(SelectionPlugin);\n *\n * // Get current selection\n * const selection = plugin.getSelection();\n * console.log(selection.ranges);\n *\n * // Set selection programmatically\n * plugin.setRanges([{ from: { row: 0, col: 0 }, to: { row: 5, col: 3 } }]);\n *\n * // Clear all selection\n * plugin.clearSelection();\n * ```\n *\n * @see {@link SelectionMode} for detailed mode descriptions\n * @see {@link SelectionConfig} for configuration options\n * @see {@link SelectionResult} for the selection result structure\n * @see [Live Demos](?path=/docs/grid-plugins-selection--docs) for interactive examples\n */\nexport class SelectionPlugin extends BaseGridPlugin<SelectionConfig> {\n /**\n * Plugin manifest - declares queries and configuration validation rules.\n * @internal\n */\n static override readonly manifest: PluginManifest<SelectionConfig> = {\n queries: [{ type: 'getSelection', description: 'Get the current selection state' }],\n configRules: [\n {\n id: 'selection/range-dblclick',\n severity: 'warn',\n message:\n `\"triggerOn: 'dblclick'\" has no effect when mode is \"range\".\\n` +\n ` → Range selection uses drag interaction (mousedown → mousemove), not click events.\\n` +\n ` → The \"triggerOn\" option only affects \"cell\" and \"row\" selection modes.`,\n check: (config) => config.mode === 'range' && config.triggerOn === 'dblclick',\n },\n ],\n };\n\n /** @internal */\n readonly name = 'selection';\n /** @internal */\n override readonly styles = styles;\n\n /** @internal */\n protected override get defaultConfig(): Partial<SelectionConfig> {\n return {\n mode: 'cell',\n triggerOn: 'click',\n enabled: true,\n };\n }\n\n // #region Internal State\n /** Row selection state (row mode) */\n private selected = new Set<number>();\n private lastSelected: number | null = null;\n private anchor: number | null = null;\n\n /** Range selection state (range mode) */\n private ranges: InternalCellRange[] = [];\n private activeRange: InternalCellRange | null = null;\n private cellAnchor: { row: number; col: number } | null = null;\n private isDragging = false;\n\n /** Pending keyboard navigation update (processed in afterRender) */\n private pendingKeyboardUpdate: { shiftKey: boolean } | null = null;\n\n /** Cell selection state (cell mode) */\n private selectedCell: { row: number; col: number } | null = null;\n\n /** Last synced focus row — used to detect when grid focus moves so selection follows */\n private lastSyncedFocusRow = -1;\n /** Last synced focus col (cell mode) */\n private lastSyncedFocusCol = -1;\n\n /** True when selection was explicitly set (click/keyboard) — prevents #syncSelectionToFocus from overwriting */\n private explicitSelection = false;\n\n // #endregion\n\n // #region Private Helpers - Selection Enabled Check\n\n /**\n * Check if selection is enabled at the grid level.\n * Grid-wide `selectable: false` or plugin's `enabled: false` disables all selection.\n */\n private isSelectionEnabled(): boolean {\n // Check plugin config first\n if (this.config.enabled === false) return false;\n // Check grid-level config\n return this.grid.effectiveConfig?.selectable !== false;\n }\n\n // #endregion\n\n // #region Private Helpers - Selectability\n\n /**\n * Check if a row/cell is selectable.\n * Returns true if selectable, false if not.\n */\n private checkSelectable(rowIndex: number, colIndex?: number): boolean {\n const { isSelectable } = this.config;\n if (!isSelectable) return true; // No callback = all selectable\n\n const row = this.rows[rowIndex];\n if (!row) return false;\n\n const column = colIndex !== undefined ? this.columns[colIndex] : undefined;\n return isSelectable(row, rowIndex, column, colIndex);\n }\n\n /**\n * Check if an entire row is selectable (for row mode).\n */\n private isRowSelectable(rowIndex: number): boolean {\n return this.checkSelectable(rowIndex);\n }\n\n /**\n * Check if a cell is selectable (for cell/range modes).\n */\n private isCellSelectable(rowIndex: number, colIndex: number): boolean {\n return this.checkSelectable(rowIndex, colIndex);\n }\n\n // #endregion\n\n // #region Lifecycle\n\n /** @internal */\n override attach(grid: GridElement): void {\n super.attach(grid);\n\n // Subscribe to events that invalidate selection\n // When rows change due to filtering/grouping/tree operations, selection indices become invalid\n this.on('filter-applied', () => this.clearSelectionSilent());\n this.on('grouping-state-change', () => this.clearSelectionSilent());\n this.on('tree-state-change', () => this.clearSelectionSilent());\n }\n\n /**\n * Handle queries from other plugins.\n * @internal\n */\n override handleQuery(query: PluginQuery): unknown {\n if (query.type === 'getSelection') {\n return this.getSelection();\n }\n return undefined;\n }\n\n /** @internal */\n override detach(): void {\n this.selected.clear();\n this.ranges = [];\n this.activeRange = null;\n this.cellAnchor = null;\n this.isDragging = false;\n this.selectedCell = null;\n this.pendingKeyboardUpdate = null;\n this.lastSyncedFocusRow = -1;\n this.lastSyncedFocusCol = -1;\n }\n\n /**\n * Clear selection without emitting an event.\n * Used when selection is invalidated by external changes (filtering, grouping, etc.)\n */\n private clearSelectionSilent(): void {\n this.selected.clear();\n this.ranges = [];\n this.activeRange = null;\n this.cellAnchor = null;\n this.selectedCell = null;\n this.lastSelected = null;\n this.anchor = null;\n this.lastSyncedFocusRow = -1;\n this.lastSyncedFocusCol = -1;\n this.requestAfterRender();\n }\n\n // #endregion\n\n // #region Event Handlers\n\n /** @internal */\n override onCellClick(event: CellClickEvent): boolean {\n // Skip all selection if disabled at grid level or plugin level\n if (!this.isSelectionEnabled()) return false;\n\n const { rowIndex, colIndex, originalEvent } = event;\n const { mode, triggerOn = 'click' } = this.config;\n\n // Skip if event type doesn't match configured trigger\n // This allows dblclick mode to only select on double-click\n if (originalEvent.type !== triggerOn) {\n return false;\n }\n\n // Check if this is a utility column (expander columns, etc.)\n const column = this.columns[colIndex];\n const isUtility = column && isUtilityColumn(column);\n\n // CELL MODE: Single cell selection - skip utility columns and non-selectable cells\n if (mode === 'cell') {\n if (isUtility) {\n return false; // Allow event to propagate, but don't select utility cells\n }\n if (!this.isCellSelectable(rowIndex, colIndex)) {\n return false; // Cell is not selectable\n }\n // Only emit if selection actually changed\n const currentCell = this.selectedCell;\n if (currentCell && currentCell.row === rowIndex && currentCell.col === colIndex) {\n return false; // Same cell already selected\n }\n this.selectedCell = { row: rowIndex, col: colIndex };\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n this.requestAfterRender();\n return false;\n }\n\n // ROW MODE: Multi-select with Shift/Ctrl, checkbox toggle, or single select\n if (mode === 'row') {\n if (!this.isRowSelectable(rowIndex)) {\n return false; // Row is not selectable\n }\n\n const shiftKey = originalEvent.shiftKey;\n const ctrlKey = originalEvent.ctrlKey || originalEvent.metaKey;\n const isCheckbox = column?.meta?.checkboxColumn === true;\n\n if (shiftKey && this.anchor !== null) {\n // Shift+Click: Range select from anchor to clicked row\n const start = Math.min(this.anchor, rowIndex);\n const end = Math.max(this.anchor, rowIndex);\n if (!ctrlKey) {\n this.selected.clear();\n }\n for (let i = start; i <= end; i++) {\n if (this.isRowSelectable(i)) {\n this.selected.add(i);\n }\n }\n } else if (ctrlKey || isCheckbox) {\n // Ctrl+Click or checkbox click: Toggle individual row\n if (this.selected.has(rowIndex)) {\n this.selected.delete(rowIndex);\n } else {\n this.selected.add(rowIndex);\n }\n this.anchor = rowIndex;\n } else {\n // Plain click: Clear all, select only clicked row\n if (this.selected.size === 1 && this.selected.has(rowIndex)) {\n return false; // Same row already selected\n }\n this.selected.clear();\n this.selected.add(rowIndex);\n this.anchor = rowIndex;\n }\n\n this.lastSelected = rowIndex;\n this.explicitSelection = true;\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n this.requestAfterRender();\n return false;\n }\n\n // RANGE MODE: Shift+click extends selection, click starts new\n if (mode === 'range') {\n // Skip utility columns in range mode - don't start selection from them\n if (isUtility) {\n return false;\n }\n\n // Skip non-selectable cells in range mode\n if (!this.isCellSelectable(rowIndex, colIndex)) {\n return false;\n }\n\n const shiftKey = originalEvent.shiftKey;\n const ctrlKey = originalEvent.ctrlKey || originalEvent.metaKey;\n\n if (shiftKey && this.cellAnchor) {\n // Extend selection from anchor\n const newRange = createRangeFromAnchor(this.cellAnchor, { row: rowIndex, col: colIndex });\n\n // Check if range actually changed\n const currentRange = this.ranges.length > 0 ? this.ranges[this.ranges.length - 1] : null;\n if (currentRange && rangesEqual(currentRange, newRange)) {\n return false; // Same range already selected\n }\n\n if (ctrlKey) {\n if (this.ranges.length > 0) {\n this.ranges[this.ranges.length - 1] = newRange;\n } else {\n this.ranges.push(newRange);\n }\n } else {\n this.ranges = [newRange];\n }\n this.activeRange = newRange;\n } else if (ctrlKey) {\n const newRange: InternalCellRange = {\n startRow: rowIndex,\n startCol: colIndex,\n endRow: rowIndex,\n endCol: colIndex,\n };\n this.ranges.push(newRange);\n this.activeRange = newRange;\n this.cellAnchor = { row: rowIndex, col: colIndex };\n } else {\n // Plain click - check if same single-cell range already selected\n const newRange: InternalCellRange = {\n startRow: rowIndex,\n startCol: colIndex,\n endRow: rowIndex,\n endCol: colIndex,\n };\n\n // Only emit if selection actually changed\n if (this.ranges.length === 1 && rangesEqual(this.ranges[0], newRange)) {\n return false; // Same cell already selected\n }\n\n this.ranges = [newRange];\n this.activeRange = newRange;\n this.cellAnchor = { row: rowIndex, col: colIndex };\n }\n\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n\n this.requestAfterRender();\n return false;\n }\n\n return false;\n }\n\n /** @internal */\n override onKeyDown(event: KeyboardEvent): boolean {\n // Skip all selection if disabled at grid level or plugin level\n if (!this.isSelectionEnabled()) return false;\n\n const { mode } = this.config;\n const navKeys = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Tab', 'Home', 'End', 'PageUp', 'PageDown'];\n const isNavKey = navKeys.includes(event.key);\n\n // Escape clears selection in all modes\n if (event.key === 'Escape') {\n if (mode === 'cell') {\n this.selectedCell = null;\n } else if (mode === 'row') {\n this.selected.clear();\n this.anchor = null;\n } else if (mode === 'range') {\n this.ranges = [];\n this.activeRange = null;\n this.cellAnchor = null;\n }\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n this.requestAfterRender();\n return true;\n }\n\n // CELL MODE: Selection follows focus (but respects selectability)\n if (mode === 'cell' && isNavKey) {\n // Use queueMicrotask so grid's handler runs first and updates focusRow/focusCol\n queueMicrotask(() => {\n const focusRow = this.grid._focusRow;\n const focusCol = this.grid._focusCol;\n // Only select if the cell is selectable\n if (this.isCellSelectable(focusRow, focusCol)) {\n this.selectedCell = { row: focusRow, col: focusCol };\n } else {\n // Clear selection when navigating to non-selectable cell\n this.selectedCell = null;\n }\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n this.requestAfterRender();\n });\n return false; // Let grid handle navigation\n }\n\n // ROW MODE: Arrow keys move selection, Shift+Arrow extends, Ctrl+A selects all\n if (mode === 'row') {\n if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {\n const shiftKey = event.shiftKey;\n\n // Set anchor before grid moves focus\n if (shiftKey && this.anchor === null) {\n this.anchor = this.grid._focusRow;\n }\n\n // Let grid move focus first, then sync row selection\n queueMicrotask(() => {\n const focusRow = this.grid._focusRow;\n\n if (shiftKey && this.anchor !== null) {\n // Shift+Arrow: Extend selection from anchor\n this.selected.clear();\n const start = Math.min(this.anchor, focusRow);\n const end = Math.max(this.anchor, focusRow);\n for (let i = start; i <= end; i++) {\n if (this.isRowSelectable(i)) {\n this.selected.add(i);\n }\n }\n } else {\n // Plain arrow: Single select\n if (this.isRowSelectable(focusRow)) {\n this.selected.clear();\n this.selected.add(focusRow);\n this.anchor = focusRow;\n } else {\n this.selected.clear();\n }\n }\n\n this.lastSelected = focusRow;\n this.explicitSelection = true;\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n this.requestAfterRender();\n });\n return false; // Let grid handle navigation\n }\n\n // Ctrl+A: Select all rows\n if (event.key === 'a' && (event.ctrlKey || event.metaKey)) {\n event.preventDefault();\n event.stopPropagation();\n this.selectAll();\n return true;\n }\n }\n\n // RANGE MODE: Shift+Arrow extends, plain Arrow resets\n // Tab key always navigates without extending (even with Shift)\n if (mode === 'range' && isNavKey) {\n // Tab should not extend selection - it just navigates to the next/previous cell\n const isTabKey = event.key === 'Tab';\n const shouldExtend = event.shiftKey && !isTabKey;\n\n // Capture anchor BEFORE grid moves focus (synchronous)\n // This ensures the anchor is the starting point, not the destination\n if (shouldExtend && !this.cellAnchor) {\n this.cellAnchor = { row: this.grid._focusRow, col: this.grid._focusCol };\n }\n\n // Mark pending update - will be processed in afterRender when grid updates focus\n this.pendingKeyboardUpdate = { shiftKey: shouldExtend };\n\n // Schedule afterRender to run after grid's keyboard handler completes\n // Grid's refreshVirtualWindow(false) skips afterRender for performance,\n // so we explicitly request it to process pendingKeyboardUpdate\n queueMicrotask(() => this.requestAfterRender());\n\n return false; // Let grid handle navigation\n }\n\n // Ctrl+A selects all in range mode\n if (mode === 'range' && event.key === 'a' && (event.ctrlKey || event.metaKey)) {\n event.preventDefault();\n event.stopPropagation();\n this.selectAll();\n return true;\n }\n\n return false;\n }\n\n /** @internal */\n override onCellMouseDown(event: CellMouseEvent): boolean | void {\n // Skip all selection if disabled at grid level or plugin level\n if (!this.isSelectionEnabled()) return;\n\n if (this.config.mode !== 'range') return;\n if (event.rowIndex === undefined || event.colIndex === undefined) return;\n if (event.rowIndex < 0) return; // Header\n\n // Skip utility columns (expander columns, etc.)\n const column = this.columns[event.colIndex];\n if (column && isUtilityColumn(column)) {\n return; // Don't start selection on utility columns\n }\n\n // Skip non-selectable cells - don't start drag from them\n if (!this.isCellSelectable(event.rowIndex, event.colIndex)) {\n return;\n }\n\n // Let onCellClick handle shift+click for range extension\n if (event.originalEvent.shiftKey && this.cellAnchor) {\n return;\n }\n\n // Start drag selection\n this.isDragging = true;\n const rowIndex = event.rowIndex;\n const colIndex = event.colIndex;\n\n const ctrlKey = event.originalEvent.ctrlKey || event.originalEvent.metaKey;\n\n const newRange: InternalCellRange = {\n startRow: rowIndex,\n startCol: colIndex,\n endRow: rowIndex,\n endCol: colIndex,\n };\n\n // Check if selection is actually changing (for non-Ctrl clicks)\n if (!ctrlKey && this.ranges.length === 1 && rangesEqual(this.ranges[0], newRange)) {\n // Same cell already selected, just update anchor for potential drag\n this.cellAnchor = { row: rowIndex, col: colIndex };\n return true;\n }\n\n this.cellAnchor = { row: rowIndex, col: colIndex };\n\n if (!ctrlKey) {\n this.ranges = [];\n }\n\n this.ranges.push(newRange);\n this.activeRange = newRange;\n\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n this.requestAfterRender();\n return true;\n }\n\n /** @internal */\n override onCellMouseMove(event: CellMouseEvent): boolean | void {\n // Skip all selection if disabled at grid level or plugin level\n if (!this.isSelectionEnabled()) return;\n\n if (this.config.mode !== 'range') return;\n if (!this.isDragging || !this.cellAnchor) return;\n if (event.rowIndex === undefined || event.colIndex === undefined) return;\n if (event.rowIndex < 0) return;\n\n // When dragging, clamp to first data column (skip utility columns)\n let targetCol = event.colIndex;\n const column = this.columns[targetCol];\n if (column && isUtilityColumn(column)) {\n // Find the first non-utility column\n const firstDataCol = this.columns.findIndex((col) => !isUtilityColumn(col));\n if (firstDataCol >= 0) {\n targetCol = firstDataCol;\n }\n }\n\n const newRange = createRangeFromAnchor(this.cellAnchor, { row: event.rowIndex, col: targetCol });\n\n // Only update and emit if the range actually changed\n const currentRange = this.ranges.length > 0 ? this.ranges[this.ranges.length - 1] : null;\n if (currentRange && rangesEqual(currentRange, newRange)) {\n return true; // Range unchanged, no need to update\n }\n\n if (this.ranges.length > 0) {\n this.ranges[this.ranges.length - 1] = newRange;\n } else {\n this.ranges.push(newRange);\n }\n this.activeRange = newRange;\n\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n this.requestAfterRender();\n return true;\n }\n\n /** @internal */\n override onCellMouseUp(_event: CellMouseEvent): boolean | void {\n // Skip all selection if disabled at grid level or plugin level\n if (!this.isSelectionEnabled()) return;\n\n if (this.config.mode !== 'range') return;\n if (this.isDragging) {\n this.isDragging = false;\n return true;\n }\n }\n\n // #region Checkbox Column\n\n /**\n * Inject checkbox column when `checkbox: true` and mode is `'row'`.\n * @internal\n */\n override processColumns(columns: ColumnConfig[]): ColumnConfig[] {\n if (this.config.checkbox && this.config.mode === 'row') {\n // Check if checkbox column already exists\n if (columns.some((col) => col.field === CHECKBOX_COLUMN_FIELD)) {\n return columns;\n }\n const checkboxCol = this.#createCheckboxColumn();\n // Insert after expander column if present, otherwise first\n const expanderIdx = columns.findIndex(isExpanderColumn);\n const insertAt = expanderIdx >= 0 ? expanderIdx + 1 : 0;\n return [...columns.slice(0, insertAt), checkboxCol, ...columns.slice(insertAt)];\n }\n return columns;\n }\n\n /**\n * Create the checkbox utility column configuration.\n */\n #createCheckboxColumn(): ColumnConfig {\n return {\n field: CHECKBOX_COLUMN_FIELD,\n header: '',\n width: 32,\n resizable: false,\n sortable: false,\n meta: {\n lockPosition: true,\n suppressMovable: true,\n utility: true,\n checkboxColumn: true,\n },\n headerRenderer: () => {\n const container = document.createElement('div');\n container.className = 'tbw-checkbox-header';\n const checkbox = document.createElement('input');\n checkbox.type = 'checkbox';\n checkbox.className = 'tbw-select-all-checkbox';\n checkbox.addEventListener('click', (e) => {\n e.stopPropagation(); // Prevent header sort\n if ((e.target as HTMLInputElement).checked) {\n this.selectAll();\n } else {\n this.clearSelection();\n }\n });\n container.appendChild(checkbox);\n return container;\n },\n renderer: (ctx) => {\n const checkbox = document.createElement('input');\n checkbox.type = 'checkbox';\n checkbox.className = 'tbw-select-row-checkbox';\n // Set initial checked state from current selection\n const cellEl = ctx.cellEl;\n if (cellEl) {\n const rowIndex = parseInt(cellEl.getAttribute('data-row') ?? '-1', 10);\n if (rowIndex >= 0) {\n checkbox.checked = this.selected.has(rowIndex);\n }\n }\n return checkbox;\n },\n };\n }\n\n /**\n * Update checkbox checked states to reflect current selection.\n * Called from #applySelectionClasses.\n */\n #updateCheckboxStates(gridEl: HTMLElement): void {\n // Update row checkboxes\n const rowCheckboxes = gridEl.querySelectorAll('.tbw-select-row-checkbox') as NodeListOf<HTMLInputElement>;\n rowCheckboxes.forEach((checkbox) => {\n const cell = checkbox.closest('.cell');\n const rowIndex = cell ? getRowIndexFromCell(cell) : -1;\n if (rowIndex >= 0) {\n checkbox.checked = this.selected.has(rowIndex);\n }\n });\n\n // Update header select-all checkbox\n const headerCheckbox = gridEl.querySelector('.tbw-select-all-checkbox') as HTMLInputElement | null;\n if (headerCheckbox) {\n const rowCount = this.rows.length;\n let selectableCount = 0;\n if (this.config.isSelectable) {\n for (let i = 0; i < rowCount; i++) {\n if (this.isRowSelectable(i)) selectableCount++;\n }\n } else {\n selectableCount = rowCount;\n }\n const allSelected = selectableCount > 0 && this.selected.size >= selectableCount;\n const someSelected = this.selected.size > 0;\n headerCheckbox.checked = allSelected;\n headerCheckbox.indeterminate = someSelected && !allSelected;\n }\n }\n\n // #endregion\n\n /**\n * Sync selection state to the grid's current focus position.\n * In row mode, keeps `selected` in sync with `_focusRow`.\n * In cell mode, keeps `selectedCell` in sync with `_focusRow`/`_focusCol`.\n * Only updates when the focus has changed since the last sync.\n * Skips when `explicitSelection` is set (click/keyboard set selection directly).\n */\n #syncSelectionToFocus(mode: string): void {\n const focusRow = this.grid._focusRow;\n const focusCol = this.grid._focusCol;\n\n if (mode === 'row') {\n // Skip auto-sync when selection was explicitly set (Shift/Ctrl click, keyboard)\n if (this.explicitSelection) {\n this.explicitSelection = false;\n this.lastSyncedFocusRow = focusRow;\n return;\n }\n\n if (focusRow !== this.lastSyncedFocusRow) {\n this.lastSyncedFocusRow = focusRow;\n if (this.isRowSelectable(focusRow)) {\n if (!this.selected.has(focusRow) || this.selected.size !== 1) {\n this.selected.clear();\n this.selected.add(focusRow);\n this.lastSelected = focusRow;\n this.anchor = focusRow;\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n }\n }\n }\n }\n\n if (mode === 'cell') {\n if (this.explicitSelection) {\n this.explicitSelection = false;\n this.lastSyncedFocusRow = focusRow;\n this.lastSyncedFocusCol = focusCol;\n return;\n }\n\n if (focusRow !== this.lastSyncedFocusRow || focusCol !== this.lastSyncedFocusCol) {\n this.lastSyncedFocusRow = focusRow;\n this.lastSyncedFocusCol = focusCol;\n if (this.isCellSelectable(focusRow, focusCol)) {\n const cur = this.selectedCell;\n if (!cur || cur.row !== focusRow || cur.col !== focusCol) {\n this.selectedCell = { row: focusRow, col: focusCol };\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n }\n }\n }\n }\n }\n\n /**\n * Apply CSS selection classes to row/cell elements.\n * Shared by afterRender and onScrollRender.\n */\n #applySelectionClasses(): void {\n const gridEl = this.gridElement;\n if (!gridEl) return;\n\n const { mode } = this.config;\n const hasSelectableCallback = !!this.config.isSelectable;\n\n // Clear all selection classes first\n const allCells = gridEl.querySelectorAll('.cell');\n allCells.forEach((cell) => {\n cell.classList.remove('selected', 'top', 'bottom', 'first', 'last');\n // Clear selectable attribute - will be re-applied below\n if (hasSelectableCallback) {\n cell.removeAttribute('data-selectable');\n }\n });\n\n const allRows = gridEl.querySelectorAll('.data-grid-row');\n allRows.forEach((row) => {\n row.classList.remove('selected', 'row-focus');\n // Clear selectable attribute - will be re-applied below\n if (hasSelectableCallback) {\n row.removeAttribute('data-selectable');\n }\n });\n\n // ROW MODE: Add row-focus class to selected rows, disable cell-focus, update checkboxes\n if (mode === 'row') {\n // In row mode, disable ALL cell-focus styling - row selection takes precedence\n clearCellFocus(gridEl);\n\n allRows.forEach((row) => {\n const firstCell = row.querySelector('.cell[data-row]');\n const rowIndex = getRowIndexFromCell(firstCell);\n if (rowIndex >= 0) {\n // Mark non-selectable rows\n if (hasSelectableCallback && !this.isRowSelectable(rowIndex)) {\n row.setAttribute('data-selectable', 'false');\n }\n if (this.selected.has(rowIndex)) {\n row.classList.add('selected', 'row-focus');\n }\n }\n });\n\n // Update checkbox states if checkbox column is enabled\n if (this.config.checkbox) {\n this.#updateCheckboxStates(gridEl);\n }\n }\n\n // CELL/RANGE MODE: Mark non-selectable cells\n if ((mode === 'cell' || mode === 'range') && hasSelectableCallback) {\n const cells = gridEl.querySelectorAll('.cell[data-row][data-col]');\n cells.forEach((cell) => {\n const rowIndex = parseInt(cell.getAttribute('data-row') ?? '-1', 10);\n const colIndex = parseInt(cell.getAttribute('data-col') ?? '-1', 10);\n if (rowIndex >= 0 && colIndex >= 0) {\n if (!this.isCellSelectable(rowIndex, colIndex)) {\n cell.setAttribute('data-selectable', 'false');\n }\n }\n });\n }\n\n // RANGE MODE: Add selected and edge classes to cells\n // Uses neighbor-based edge detection for correct multi-range borders\n if (mode === 'range' && this.ranges.length > 0) {\n // Clear all cell-focus first - selection plugin manages focus styling in range mode\n clearCellFocus(gridEl);\n\n // Pre-normalize ranges for efficient neighbor checks\n const normalizedRanges = this.ranges.map(normalizeRange);\n\n // Fast selection check against pre-normalized ranges\n const isInSelection = (r: number, c: number): boolean => {\n for (const range of normalizedRanges) {\n if (r >= range.startRow && r <= range.endRow && c >= range.startCol && c <= range.endCol) {\n return true;\n }\n }\n return false;\n };\n\n const cells = gridEl.querySelectorAll('.cell[data-row][data-col]');\n cells.forEach((cell) => {\n const rowIndex = parseInt(cell.getAttribute('data-row') ?? '-1', 10);\n const colIndex = parseInt(cell.getAttribute('data-col') ?? '-1', 10);\n if (rowIndex >= 0 && colIndex >= 0) {\n // Skip utility columns entirely - don't add any selection classes\n const column = this.columns[colIndex];\n if (column && isUtilityColumn(column)) {\n return;\n }\n\n if (isInSelection(rowIndex, colIndex)) {\n cell.classList.add('selected');\n\n // Edge detection: add border class where neighbor is not selected\n // This handles single ranges, multi-range, and irregular selections correctly\n if (!isInSelection(rowIndex - 1, colIndex)) cell.classList.add('top');\n if (!isInSelection(rowIndex + 1, colIndex)) cell.classList.add('bottom');\n if (!isInSelection(rowIndex, colIndex - 1)) cell.classList.add('first');\n if (!isInSelection(rowIndex, colIndex + 1)) cell.classList.add('last');\n }\n }\n });\n }\n\n // CELL MODE: Let the grid's native .cell-focus styling handle cell highlighting\n // No additional action needed - the grid already manages focus styling\n }\n\n /** @internal */\n override afterRender(): void {\n // Skip rendering selection if disabled at grid level or plugin level\n if (!this.isSelectionEnabled()) return;\n\n const gridEl = this.gridElement;\n if (!gridEl) return;\n\n const container = gridEl.children[0];\n const { mode } = this.config;\n\n // Process pending keyboard navigation update (range mode)\n // This runs AFTER the grid has updated focusRow/focusCol\n if (this.pendingKeyboardUpdate && mode === 'range') {\n const { shiftKey } = this.pendingKeyboardUpdate;\n this.pendingKeyboardUpdate = null;\n\n const currentRow = this.grid._focusRow;\n const currentCol = this.grid._focusCol;\n\n if (shiftKey && this.cellAnchor) {\n // Extend selection from anchor to current focus\n const newRange = createRangeFromAnchor(this.cellAnchor, { row: currentRow, col: currentCol });\n this.ranges = [newRange];\n this.activeRange = newRange;\n } else if (!shiftKey) {\n // Without shift, clear selection (cell-focus will show instead)\n this.ranges = [];\n this.activeRange = null;\n this.cellAnchor = { row: currentRow, col: currentCol }; // Reset anchor to current position\n }\n\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n }\n\n // Sync selection to grid's focus position.\n // This ensures selection follows keyboard navigation (Tab, arrows, etc.)\n // regardless of which plugin moved the focus.\n this.#syncSelectionToFocus(mode);\n\n // Set data attribute on host for CSS variable scoping\n (this.grid as unknown as Element).setAttribute('data-selection-mode', mode);\n\n // Toggle .selecting class during drag to prevent text selection\n if (container) {\n container.classList.toggle('selecting', this.isDragging);\n }\n\n this.#applySelectionClasses();\n }\n\n /**\n * Called after scroll-triggered row rendering.\n * Reapplies selection classes to recycled DOM elements.\n * @internal\n */\n override onScrollRender(): void {\n // Skip rendering selection classes if disabled\n if (!this.isSelectionEnabled()) return;\n\n this.#applySelectionClasses();\n }\n\n // #endregion\n\n // #region Public API\n\n /**\n * Get the current selection as a unified result.\n * Works for all selection modes and always returns ranges.\n *\n * @example\n * ```ts\n * const selection = plugin.getSelection();\n * if (selection.ranges.length > 0) {\n * const { from, to } = selection.ranges[0];\n * // For cell mode: from === to (single cell)\n * // For row mode: from.col = 0, to.col = lastCol (full row)\n * // For range mode: rectangular selection\n * }\n * ```\n */\n getSelection(): SelectionResult {\n return {\n mode: this.config.mode,\n ranges: this.#buildEvent().ranges,\n anchor: this.cellAnchor,\n };\n }\n\n /**\n * Get all selected cells across all ranges.\n */\n getSelectedCells(): Array<{ row: number; col: number }> {\n return getAllCellsInRanges(this.ranges);\n }\n\n /**\n * Check if a specific cell is in range selection.\n */\n isCellSelected(row: number, col: number): boolean {\n return isCellInAnyRange(row, col, this.ranges);\n }\n\n /**\n * Select all selectable rows (row mode) or all cells (range mode).\n *\n * In row mode, selects every row where `isSelectable` returns true (or all rows if no callback).\n * In range mode, creates a single range spanning all rows and columns.\n * Has no effect in cell mode.\n *\n * @example\n * ```ts\n * const plugin = grid.getPlugin(SelectionPlugin);\n * plugin.selectAll(); // Selects everything in current mode\n * ```\n */\n selectAll(): void {\n const { mode } = this.config;\n\n if (mode === 'row') {\n this.selected.clear();\n for (let i = 0; i < this.rows.length; i++) {\n if (this.isRowSelectable(i)) {\n this.selected.add(i);\n }\n }\n this.explicitSelection = true;\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n this.requestAfterRender();\n } else if (mode === 'range') {\n const rowCount = this.rows.length;\n const colCount = this.columns.length;\n if (rowCount > 0 && colCount > 0) {\n const allRange: InternalCellRange = {\n startRow: 0,\n startCol: 0,\n endRow: rowCount - 1,\n endCol: colCount - 1,\n };\n this.ranges = [allRange];\n this.activeRange = allRange;\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n this.requestAfterRender();\n }\n }\n }\n\n /**\n * Select specific rows by index (row mode only).\n * Replaces the current selection with the provided row indices.\n * Indices that are out of bounds or fail the `isSelectable` check are ignored.\n *\n * @param indices - Array of row indices to select\n *\n * @example\n * ```ts\n * const plugin = grid.getPlugin(SelectionPlugin);\n * plugin.selectRows([0, 2, 4]); // Select rows 0, 2, and 4\n * ```\n */\n selectRows(indices: number[]): void {\n if (this.config.mode !== 'row') return;\n this.selected.clear();\n for (const idx of indices) {\n if (idx >= 0 && idx < this.rows.length && this.isRowSelectable(idx)) {\n this.selected.add(idx);\n }\n }\n this.anchor = indices.length > 0 ? indices[indices.length - 1] : null;\n this.explicitSelection = true;\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n this.requestAfterRender();\n }\n\n /**\n * Get the indices of all selected rows (convenience for row mode).\n * Returns indices sorted in ascending order.\n *\n * @example\n * ```ts\n * const plugin = grid.getPlugin(SelectionPlugin);\n * const rows = plugin.getSelectedRowIndices(); // [0, 2, 4]\n * ```\n */\n getSelectedRowIndices(): number[] {\n return [...this.selected].sort((a, b) => a - b);\n }\n\n /**\n * Clear all selection.\n */\n clearSelection(): void {\n this.selectedCell = null;\n this.selected.clear();\n this.anchor = null;\n this.ranges = [];\n this.activeRange = null;\n this.cellAnchor = null;\n this.emit<SelectionChangeDetail>('selection-change', { mode: this.config.mode, ranges: [] });\n this.requestAfterRender();\n }\n\n /**\n * Set selected ranges programmatically.\n */\n setRanges(ranges: CellRange[]): void {\n this.ranges = ranges.map((r) => ({\n startRow: r.from.row,\n startCol: r.from.col,\n endRow: r.to.row,\n endCol: r.to.col,\n }));\n this.activeRange = this.ranges.length > 0 ? this.ranges[this.ranges.length - 1] : null;\n this.emit<SelectionChangeDetail>('selection-change', {\n mode: this.config.mode,\n ranges: toPublicRanges(this.ranges),\n });\n this.requestAfterRender();\n }\n\n // #endregion\n\n // #region Private Helpers\n\n #buildEvent(): SelectionChangeDetail {\n return buildSelectionEvent(\n this.config.mode,\n {\n selectedCell: this.selectedCell,\n selected: this.selected,\n ranges: this.ranges,\n },\n this.columns.length,\n );\n }\n\n // #endregion\n}\n"],"names":["normalizeRange","range","toPublicRange","normalized","toPublicRanges","ranges","isCellInRange","row","col","isCellInAnyRange","getCellsInRange","cells","getAllCellsInRanges","cellMap","cell","createRangeFromAnchor","anchor","current","rangesEqual","a","b","normA","normB","CHECKBOX_COLUMN_FIELD","buildSelectionEvent","mode","state","colCount","sorted","start","end","i","SelectionPlugin","BaseGridPlugin","config","styles","rowIndex","colIndex","isSelectable","column","grid","query","event","originalEvent","triggerOn","isUtility","isUtilityColumn","currentCell","#buildEvent","shiftKey","ctrlKey","isCheckbox","newRange","currentRange","isNavKey","focusRow","focusCol","isTabKey","shouldExtend","targetCol","firstDataCol","_event","columns","checkboxCol","#createCheckboxColumn","expanderIdx","isExpanderColumn","insertAt","container","checkbox","e","ctx","cellEl","#updateCheckboxStates","gridEl","getRowIndexFromCell","headerCheckbox","rowCount","selectableCount","allSelected","someSelected","#syncSelectionToFocus","cur","#applySelectionClasses","hasSelectableCallback","allRows","clearCellFocus","firstCell","normalizedRanges","isInSelection","r","c","currentRow","currentCol","allRange","indices","idx"],"mappings":"+eAeO,SAASA,EAAeC,EAA6C,CAC1E,MAAO,CACL,SAAU,KAAK,IAAIA,EAAM,SAAUA,EAAM,MAAM,EAC/C,SAAU,KAAK,IAAIA,EAAM,SAAUA,EAAM,MAAM,EAC/C,OAAQ,KAAK,IAAIA,EAAM,SAAUA,EAAM,MAAM,EAC7C,OAAQ,KAAK,IAAIA,EAAM,SAAUA,EAAM,MAAM,CAAA,CAEjD,CAQO,SAASC,EAAcD,EAAqC,CACjE,MAAME,EAAaH,EAAeC,CAAK,EACvC,MAAO,CACL,KAAM,CAAE,IAAKE,EAAW,SAAU,IAAKA,EAAW,QAAA,EAClD,GAAI,CAAE,IAAKA,EAAW,OAAQ,IAAKA,EAAW,MAAA,CAAO,CAEzD,CAQO,SAASC,EAAeC,EAA0C,CACvE,OAAOA,EAAO,IAAIH,CAAa,CACjC,CAUO,SAASI,EAAcC,EAAaC,EAAaP,EAAmC,CACzF,MAAME,EAAaH,EAAeC,CAAK,EACvC,OACEM,GAAOJ,EAAW,U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G,EAGzB,KAAK,OAASD,EAAQ,OAAS,EAAIA,EAAQA,EAAQ,OAAS,CAAC,EAAI,KACjE,KAAK,kBAAoB,GACzB,KAAK,KAA4B,mBAAoB,KAAK/C,GAAA,CAAa,EACvE,KAAK,mBAAA,EACP,CAYA,uBAAkC,CAChC,MAAO,CAAC,GAAG,KAAK,QAAQ,EAAE,KAAK,CAAC7B,EAAGC,IAAMD,EAAIC,CAAC,CAChD,CAKA,gBAAuB,CACrB,KAAK,aAAe,KACpB,KAAK,SAAS,MAAA,EACd,KAAK,OAAS,KACd,KAAK,OAAS,CAAA,EACd,KAAK,YAAc,KACnB,KAAK,WAAa,KAClB,KAAK,KAA4B,mBAAoB,CAAE,KAAM,KAAK,OAAO,KAAM,OAAQ,CAAA,EAAI,EAC3F,KAAK,mBAAA,CACP,CAKA,UAAUf,EAA2B,CACnC,KAAK,OAASA,EAAO,IAAKqF,IAAO,CAC/B,SAAUA,EAAE,KAAK,IACjB,SAAUA,EAAE,KAAK,IACjB,OAAQA,EAAE,GAAG,IACb,OAAQA,EAAE,GAAG,GAAA,EACb,EACF,KAAK,YAAc,KAAK,OAAO,OAAS,EAAI,KAAK,OAAO,KAAK,OAAO,OAAS,CAAC,EAAI,KAClF,KAAK,KAA4B,mBAAoB,CACnD,KAAM,KAAK,OAAO,KAClB,OAAQtF,EAAe,KAAK,MAAM,CAAA,CACnC,EACD,KAAK,mBAAA,CACP,CAMA4C,IAAqC,CACnC,OAAOxB,EACL,KAAK,OAAO,KACZ,CACE,aAAc,KAAK,aACnB,SAAU,KAAK,SACf,OAAQ,KAAK,MAAA,EAEf,KAAK,QAAQ,MAAA,CAEjB,CAGF"}
|
|
1
|
+
{"version":3,"file":"selection.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/selection/range-selection.ts","../../../../../libs/grid/src/lib/plugins/selection/SelectionPlugin.ts"],"sourcesContent":["/**\n * Cell Range Selection Core Logic\n *\n * Pure functions for cell range selection operations.\n */\n\nimport type { InternalCellRange, CellRange } from './types';\n\n/**\n * Normalize a range so startRow/startCol are always <= endRow/endCol.\n * This handles cases where user drags from bottom-right to top-left.\n *\n * @param range - The range to normalize\n * @returns Normalized range with start <= end for both dimensions\n */\nexport function normalizeRange(range: InternalCellRange): InternalCellRange {\n return {\n startRow: Math.min(range.startRow, range.endRow),\n startCol: Math.min(range.startCol, range.endCol),\n endRow: Math.max(range.startRow, range.endRow),\n endCol: Math.max(range.startCol, range.endCol),\n };\n}\n\n/**\n * Convert an internal range to the public event format.\n *\n * @param range - The internal range to convert\n * @returns Public CellRange format with from/to coordinates\n */\nexport function toPublicRange(range: InternalCellRange): CellRange {\n const normalized = normalizeRange(range);\n return {\n from: { row: normalized.startRow, col: normalized.startCol },\n to: { row: normalized.endRow, col: normalized.endCol },\n };\n}\n\n/**\n * Convert multiple internal ranges to public format.\n *\n * @param ranges - Array of internal ranges\n * @returns Array of public CellRange format\n */\nexport function toPublicRanges(ranges: InternalCellRange[]): CellRange[] {\n return ranges.map(toPublicRange);\n}\n\n/**\n * Check if a cell is within a specific range.\n *\n * @param row - The row index to check\n * @param col - The column index to check\n * @param range - The range to check against\n * @returns True if the cell is within the range\n */\nexport function isCellInRange(row: number, col: number, range: InternalCellRange): boolean {\n const normalized = normalizeRange(range);\n return (\n row >= normalized.startRow && row <= normalized.endRow && col >= normalized.startCol && col <= normalized.endCol\n );\n}\n\n/**\n * Check if a cell is within any of the provided ranges.\n *\n * @param row - The row index to check\n * @param col - The column index to check\n * @param ranges - Array of ranges to check against\n * @returns True if the cell is within any range\n */\nexport function isCellInAnyRange(row: number, col: number, ranges: InternalCellRange[]): boolean {\n return ranges.some((range) => isCellInRange(row, col, range));\n}\n\n/**\n * Get all cells within a range as an array of {row, col} objects.\n *\n * @param range - The range to enumerate\n * @returns Array of all cell coordinates in the range\n */\nexport function getCellsInRange(range: InternalCellRange): Array<{ row: number; col: number }> {\n const cells: Array<{ row: number; col: number }> = [];\n const normalized = normalizeRange(range);\n\n for (let row = normalized.startRow; row <= normalized.endRow; row++) {\n for (let col = normalized.startCol; col <= normalized.endCol; col++) {\n cells.push({ row, col });\n }\n }\n\n return cells;\n}\n\n/**\n * Get all unique cells across multiple ranges.\n * Deduplicates cells that appear in overlapping ranges.\n *\n * @param ranges - Array of ranges to enumerate\n * @returns Array of unique cell coordinates\n */\nexport function getAllCellsInRanges(ranges: InternalCellRange[]): Array<{ row: number; col: number }> {\n const cellMap = new Map<string, { row: number; col: number }>();\n\n for (const range of ranges) {\n for (const cell of getCellsInRange(range)) {\n cellMap.set(`${cell.row},${cell.col}`, cell);\n }\n }\n\n return [...cellMap.values()];\n}\n\n/**\n * Merge overlapping or adjacent ranges into fewer ranges.\n * Simple implementation - returns ranges as-is for now.\n * More complex merging logic can be added later for optimization.\n *\n * @param ranges - Array of ranges to merge\n * @returns Merged array of ranges\n */\nexport function mergeRanges(ranges: InternalCellRange[]): InternalCellRange[] {\n // Simple implementation - more complex merging can be added later\n return ranges;\n}\n\n/**\n * Create a range from an anchor cell to a current cell position.\n * The range is not normalized - it preserves the direction of selection.\n *\n * @param anchor - The anchor cell (where selection started)\n * @param current - The current cell (where selection ends)\n * @returns An InternalCellRange from anchor to current\n */\nexport function createRangeFromAnchor(\n anchor: { row: number; col: number },\n current: { row: number; col: number }\n): InternalCellRange {\n return {\n startRow: anchor.row,\n startCol: anchor.col,\n endRow: current.row,\n endCol: current.col,\n };\n}\n\n/**\n * Calculate the number of cells in a range.\n *\n * @param range - The range to measure\n * @returns Total number of cells in the range\n */\nexport function getRangeCellCount(range: InternalCellRange): number {\n const normalized = normalizeRange(range);\n const rowCount = normalized.endRow - normalized.startRow + 1;\n const colCount = normalized.endCol - normalized.startCol + 1;\n return rowCount * colCount;\n}\n\n/**\n * Check if two ranges are equal (same boundaries).\n *\n * @param a - First range\n * @param b - Second range\n * @returns True if ranges have same boundaries after normalization\n */\nexport function rangesEqual(a: InternalCellRange, b: InternalCellRange): boolean {\n const normA = normalizeRange(a);\n const normB = normalizeRange(b);\n return (\n normA.startRow === normB.startRow &&\n normA.startCol === normB.startCol &&\n normA.endRow === normB.endRow &&\n normA.endCol === normB.endCol\n );\n}\n\n/**\n * Check if a range is a single cell (1x1).\n *\n * @param range - The range to check\n * @returns True if the range is exactly one cell\n */\nexport function isSingleCell(range: InternalCellRange): boolean {\n const normalized = normalizeRange(range);\n return normalized.startRow === normalized.endRow && normalized.startCol === normalized.endCol;\n}\n","/**\n * Selection Plugin (Class-based)\n *\n * Provides selection functionality for tbw-grid.\n * Supports three modes:\n * - 'cell': Single cell selection (default). No border, just focus highlight.\n * - 'row': Row selection. Clicking a cell selects the entire row.\n * - 'range': Range selection. Shift+click or drag to select rectangular cell ranges.\n */\n\nimport { clearCellFocus, getRowIndexFromCell } from '../../core/internal/utils';\nimport type { GridElement, PluginManifest, PluginQuery } from '../../core/plugin/base-plugin';\nimport { BaseGridPlugin, CellClickEvent, CellMouseEvent } from '../../core/plugin/base-plugin';\nimport { isExpanderColumn, isUtilityColumn } from '../../core/plugin/expander-column';\nimport type { ColumnConfig } from '../../core/types';\nimport {\n createRangeFromAnchor,\n getAllCellsInRanges,\n isCellInAnyRange,\n normalizeRange,\n rangesEqual,\n toPublicRanges,\n} from './range-selection';\nimport styles from './selection.css?inline';\nimport type {\n CellRange,\n InternalCellRange,\n SelectionChangeDetail,\n SelectionConfig,\n SelectionMode,\n SelectionResult,\n} from './types';\n\n/** Special field name for the selection checkbox column */\nconst CHECKBOX_COLUMN_FIELD = '__tbw_checkbox';\n\n/**\n * Build the selection change event detail for the current state.\n */\nfunction buildSelectionEvent(\n mode: SelectionMode,\n state: {\n selectedCell: { row: number; col: number } | null;\n selected: Set<number>;\n ranges: InternalCellRange[];\n },\n colCount: number,\n): SelectionChangeDetail {\n if (mode === 'cell' && state.selectedCell) {\n return {\n mode,\n ranges: [\n {\n from: { row: state.selectedCell.row, col: state.selectedCell.col },\n to: { row: state.selectedCell.row, col: state.selectedCell.col },\n },\n ],\n };\n }\n\n if (mode === 'row' && state.selected.size > 0) {\n // Sort rows and merge contiguous indices into minimal ranges\n const sorted = [...state.selected].sort((a, b) => a - b);\n const ranges: CellRange[] = [];\n let start = sorted[0];\n let end = start;\n for (let i = 1; i < sorted.length; i++) {\n if (sorted[i] === end + 1) {\n end = sorted[i];\n } else {\n ranges.push({ from: { row: start, col: 0 }, to: { row: end, col: colCount - 1 } });\n start = sorted[i];\n end = start;\n }\n }\n ranges.push({ from: { row: start, col: 0 }, to: { row: end, col: colCount - 1 } });\n return { mode, ranges };\n }\n\n if (mode === 'range' && state.ranges.length > 0) {\n return { mode, ranges: toPublicRanges(state.ranges) };\n }\n\n return { mode, ranges: [] };\n}\n\n/**\n * Selection Plugin for tbw-grid\n *\n * Adds cell, row, and range selection capabilities to the grid with full keyboard support.\n * Whether you need simple cell highlighting or complex multi-range selections, this plugin has you covered.\n *\n * ## Installation\n *\n * ```ts\n * import { SelectionPlugin } from '@toolbox-web/grid/plugins/selection';\n * ```\n *\n * ## Selection Modes\n *\n * Configure the plugin with one of three modes via {@link SelectionConfig}:\n *\n * - **`'cell'`** - Single cell selection (default). Click cells to select individually.\n * - **`'row'`** - Full row selection. Click anywhere in a row to select the entire row.\n * - **`'range'`** - Rectangular selection. Click and drag or Shift+Click to select ranges.\n *\n * ## Keyboard Shortcuts\n *\n * | Shortcut | Action |\n * |----------|--------|\n * | `Arrow Keys` | Move selection |\n * | `Shift + Arrow` | Extend selection (range mode) |\n * | `Ctrl/Cmd + Click` | Toggle selection (multi-select) |\n * | `Shift + Click` | Extend to clicked cell/row |\n * | `Ctrl/Cmd + A` | Select all (range mode) |\n * | `Escape` | Clear selection |\n *\n * ## CSS Custom Properties\n *\n * | Property | Description |\n * |----------|-------------|\n * | `--tbw-focus-background` | Focused row background |\n * | `--tbw-range-selection-bg` | Range selection fill |\n * | `--tbw-range-border-color` | Range selection border |\n *\n * @example Basic row selection\n * ```ts\n * grid.gridConfig = {\n * columns: [...],\n * plugins: [new SelectionPlugin({ mode: 'row' })],\n * };\n * ```\n *\n * @example Range selection with event handling\n * ```ts\n * grid.gridConfig = {\n * plugins: [new SelectionPlugin({ mode: 'range' })],\n * };\n *\n * grid.addEventListener('selection-change', (e) => {\n * const { mode, ranges } = e.detail;\n * console.log(`Selected ${ranges.length} ranges in ${mode} mode`);\n * });\n * ```\n *\n * @example Programmatic selection control\n * ```ts\n * const plugin = grid.getPlugin(SelectionPlugin);\n *\n * // Get current selection\n * const selection = plugin.getSelection();\n * console.log(selection.ranges);\n *\n * // Set selection programmatically\n * plugin.setRanges([{ from: { row: 0, col: 0 }, to: { row: 5, col: 3 } }]);\n *\n * // Clear all selection\n * plugin.clearSelection();\n * ```\n *\n * @see {@link SelectionMode} for detailed mode descriptions\n * @see {@link SelectionConfig} for configuration options\n * @see {@link SelectionResult} for the selection result structure\n * @see [Live Demos](?path=/docs/grid-plugins-selection--docs) for interactive examples\n */\nexport class SelectionPlugin extends BaseGridPlugin<SelectionConfig> {\n /**\n * Plugin manifest - declares queries and configuration validation rules.\n * @internal\n */\n static override readonly manifest: PluginManifest<SelectionConfig> = {\n queries: [\n { type: 'getSelection', description: 'Get the current selection state' },\n { type: 'selectRows', description: 'Select specific rows by index (row mode only)' },\n { type: 'getSelectedRowIndices', description: 'Get sorted array of selected row indices' },\n ],\n configRules: [\n {\n id: 'selection/range-dblclick',\n severity: 'warn',\n message:\n `\"triggerOn: 'dblclick'\" has no effect when mode is \"range\".\\n` +\n ` → Range selection uses drag interaction (mousedown → mousemove), not click events.\\n` +\n ` → The \"triggerOn\" option only affects \"cell\" and \"row\" selection modes.`,\n check: (config) => config.mode === 'range' && config.triggerOn === 'dblclick',\n },\n ],\n };\n\n /** @internal */\n readonly name = 'selection';\n /** @internal */\n override readonly styles = styles;\n\n /** @internal */\n protected override get defaultConfig(): Partial<SelectionConfig> {\n return {\n mode: 'cell',\n triggerOn: 'click',\n enabled: true,\n };\n }\n\n // #region Internal State\n /** Row selection state (row mode) */\n private selected = new Set<number>();\n private lastSelected: number | null = null;\n private anchor: number | null = null;\n\n /** Range selection state (range mode) */\n private ranges: InternalCellRange[] = [];\n private activeRange: InternalCellRange | null = null;\n private cellAnchor: { row: number; col: number } | null = null;\n private isDragging = false;\n\n /** Pending keyboard navigation update (processed in afterRender) */\n private pendingKeyboardUpdate: { shiftKey: boolean } | null = null;\n\n /** Cell selection state (cell mode) */\n private selectedCell: { row: number; col: number } | null = null;\n\n /** Last synced focus row — used to detect when grid focus moves so selection follows */\n private lastSyncedFocusRow = -1;\n /** Last synced focus col (cell mode) */\n private lastSyncedFocusCol = -1;\n\n /** True when selection was explicitly set (click/keyboard) — prevents #syncSelectionToFocus from overwriting */\n private explicitSelection = false;\n\n // #endregion\n\n // #region Private Helpers - Selection Enabled Check\n\n /**\n * Check if selection is enabled at the grid level.\n * Grid-wide `selectable: false` or plugin's `enabled: false` disables all selection.\n */\n private isSelectionEnabled(): boolean {\n // Check plugin config first\n if (this.config.enabled === false) return false;\n // Check grid-level config\n return this.grid.effectiveConfig?.selectable !== false;\n }\n\n // #endregion\n\n // #region Private Helpers - Selectability\n\n /**\n * Check if a row/cell is selectable.\n * Returns true if selectable, false if not.\n */\n private checkSelectable(rowIndex: number, colIndex?: number): boolean {\n const { isSelectable } = this.config;\n if (!isSelectable) return true; // No callback = all selectable\n\n const row = this.rows[rowIndex];\n if (!row) return false;\n\n const column = colIndex !== undefined ? this.columns[colIndex] : undefined;\n return isSelectable(row, rowIndex, column, colIndex);\n }\n\n /**\n * Check if an entire row is selectable (for row mode).\n */\n private isRowSelectable(rowIndex: number): boolean {\n return this.checkSelectable(rowIndex);\n }\n\n /**\n * Check if a cell is selectable (for cell/range modes).\n */\n private isCellSelectable(rowIndex: number, colIndex: number): boolean {\n return this.checkSelectable(rowIndex, colIndex);\n }\n\n // #endregion\n\n // #region Lifecycle\n\n /** @internal */\n override attach(grid: GridElement): void {\n super.attach(grid);\n\n // Subscribe to events that invalidate selection\n // When rows change due to filtering/grouping/tree operations, selection indices become invalid\n this.on('filter-applied', () => this.clearSelectionSilent());\n this.on('grouping-state-change', () => this.clearSelectionSilent());\n this.on('tree-state-change', () => this.clearSelectionSilent());\n }\n\n /**\n * Handle queries from other plugins.\n * @internal\n */\n override handleQuery(query: PluginQuery): unknown {\n if (query.type === 'getSelection') {\n return this.getSelection();\n }\n if (query.type === 'getSelectedRowIndices') {\n return this.getSelectedRowIndices();\n }\n if (query.type === 'selectRows') {\n this.selectRows(query.context as number[]);\n return true;\n }\n return undefined;\n }\n\n /** @internal */\n override detach(): void {\n this.selected.clear();\n this.ranges = [];\n this.activeRange = null;\n this.cellAnchor = null;\n this.isDragging = false;\n this.selectedCell = null;\n this.pendingKeyboardUpdate = null;\n this.lastSyncedFocusRow = -1;\n this.lastSyncedFocusCol = -1;\n }\n\n /**\n * Clear selection without emitting an event.\n * Used when selection is invalidated by external changes (filtering, grouping, etc.)\n */\n private clearSelectionSilent(): void {\n this.selected.clear();\n this.ranges = [];\n this.activeRange = null;\n this.cellAnchor = null;\n this.selectedCell = null;\n this.lastSelected = null;\n this.anchor = null;\n this.lastSyncedFocusRow = -1;\n this.lastSyncedFocusCol = -1;\n this.requestAfterRender();\n }\n\n // #endregion\n\n // #region Event Handlers\n\n /** @internal */\n override onCellClick(event: CellClickEvent): boolean {\n // Skip all selection if disabled at grid level or plugin level\n if (!this.isSelectionEnabled()) return false;\n\n const { rowIndex, colIndex, originalEvent } = event;\n const { mode, triggerOn = 'click' } = this.config;\n\n // Skip if event type doesn't match configured trigger\n // This allows dblclick mode to only select on double-click\n if (originalEvent.type !== triggerOn) {\n return false;\n }\n\n // Check if this is a utility column (expander columns, etc.)\n const column = this.columns[colIndex];\n const isUtility = column && isUtilityColumn(column);\n\n // CELL MODE: Single cell selection - skip utility columns and non-selectable cells\n if (mode === 'cell') {\n if (isUtility) {\n return false; // Allow event to propagate, but don't select utility cells\n }\n if (!this.isCellSelectable(rowIndex, colIndex)) {\n return false; // Cell is not selectable\n }\n // Only emit if selection actually changed\n const currentCell = this.selectedCell;\n if (currentCell && currentCell.row === rowIndex && currentCell.col === colIndex) {\n return false; // Same cell already selected\n }\n this.selectedCell = { row: rowIndex, col: colIndex };\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n this.requestAfterRender();\n return false;\n }\n\n // ROW MODE: Multi-select with Shift/Ctrl, checkbox toggle, or single select\n if (mode === 'row') {\n if (!this.isRowSelectable(rowIndex)) {\n return false; // Row is not selectable\n }\n\n const shiftKey = originalEvent.shiftKey;\n const ctrlKey = originalEvent.ctrlKey || originalEvent.metaKey;\n const isCheckbox = column?.meta?.checkboxColumn === true;\n\n if (shiftKey && this.anchor !== null) {\n // Shift+Click: Range select from anchor to clicked row\n const start = Math.min(this.anchor, rowIndex);\n const end = Math.max(this.anchor, rowIndex);\n if (!ctrlKey) {\n this.selected.clear();\n }\n for (let i = start; i <= end; i++) {\n if (this.isRowSelectable(i)) {\n this.selected.add(i);\n }\n }\n } else if (ctrlKey || isCheckbox) {\n // Ctrl+Click or checkbox click: Toggle individual row\n if (this.selected.has(rowIndex)) {\n this.selected.delete(rowIndex);\n } else {\n this.selected.add(rowIndex);\n }\n this.anchor = rowIndex;\n } else {\n // Plain click: Clear all, select only clicked row\n if (this.selected.size === 1 && this.selected.has(rowIndex)) {\n return false; // Same row already selected\n }\n this.selected.clear();\n this.selected.add(rowIndex);\n this.anchor = rowIndex;\n }\n\n this.lastSelected = rowIndex;\n this.explicitSelection = true;\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n this.requestAfterRender();\n return false;\n }\n\n // RANGE MODE: Shift+click extends selection, click starts new\n if (mode === 'range') {\n // Skip utility columns in range mode - don't start selection from them\n if (isUtility) {\n return false;\n }\n\n // Skip non-selectable cells in range mode\n if (!this.isCellSelectable(rowIndex, colIndex)) {\n return false;\n }\n\n const shiftKey = originalEvent.shiftKey;\n const ctrlKey = originalEvent.ctrlKey || originalEvent.metaKey;\n\n if (shiftKey && this.cellAnchor) {\n // Extend selection from anchor\n const newRange = createRangeFromAnchor(this.cellAnchor, { row: rowIndex, col: colIndex });\n\n // Check if range actually changed\n const currentRange = this.ranges.length > 0 ? this.ranges[this.ranges.length - 1] : null;\n if (currentRange && rangesEqual(currentRange, newRange)) {\n return false; // Same range already selected\n }\n\n if (ctrlKey) {\n if (this.ranges.length > 0) {\n this.ranges[this.ranges.length - 1] = newRange;\n } else {\n this.ranges.push(newRange);\n }\n } else {\n this.ranges = [newRange];\n }\n this.activeRange = newRange;\n } else if (ctrlKey) {\n const newRange: InternalCellRange = {\n startRow: rowIndex,\n startCol: colIndex,\n endRow: rowIndex,\n endCol: colIndex,\n };\n this.ranges.push(newRange);\n this.activeRange = newRange;\n this.cellAnchor = { row: rowIndex, col: colIndex };\n } else {\n // Plain click - check if same single-cell range already selected\n const newRange: InternalCellRange = {\n startRow: rowIndex,\n startCol: colIndex,\n endRow: rowIndex,\n endCol: colIndex,\n };\n\n // Only emit if selection actually changed\n if (this.ranges.length === 1 && rangesEqual(this.ranges[0], newRange)) {\n return false; // Same cell already selected\n }\n\n this.ranges = [newRange];\n this.activeRange = newRange;\n this.cellAnchor = { row: rowIndex, col: colIndex };\n }\n\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n\n this.requestAfterRender();\n return false;\n }\n\n return false;\n }\n\n /** @internal */\n override onKeyDown(event: KeyboardEvent): boolean {\n // Skip all selection if disabled at grid level or plugin level\n if (!this.isSelectionEnabled()) return false;\n\n const { mode } = this.config;\n const navKeys = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Tab', 'Home', 'End', 'PageUp', 'PageDown'];\n const isNavKey = navKeys.includes(event.key);\n\n // Escape clears selection in all modes\n // But if editing is active, let the EditingPlugin handle Escape first\n if (event.key === 'Escape') {\n const isEditing = this.grid.query<boolean>('isEditing');\n if (isEditing.some(Boolean)) {\n return false; // Defer to EditingPlugin to cancel the active edit\n }\n\n if (mode === 'cell') {\n this.selectedCell = null;\n } else if (mode === 'row') {\n this.selected.clear();\n this.anchor = null;\n } else if (mode === 'range') {\n this.ranges = [];\n this.activeRange = null;\n this.cellAnchor = null;\n }\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n this.requestAfterRender();\n return true;\n }\n\n // CELL MODE: Selection follows focus (but respects selectability)\n if (mode === 'cell' && isNavKey) {\n // Use queueMicrotask so grid's handler runs first and updates focusRow/focusCol\n queueMicrotask(() => {\n const focusRow = this.grid._focusRow;\n const focusCol = this.grid._focusCol;\n // Only select if the cell is selectable\n if (this.isCellSelectable(focusRow, focusCol)) {\n this.selectedCell = { row: focusRow, col: focusCol };\n } else {\n // Clear selection when navigating to non-selectable cell\n this.selectedCell = null;\n }\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n this.requestAfterRender();\n });\n return false; // Let grid handle navigation\n }\n\n // ROW MODE: Arrow keys move selection, Shift+Arrow extends, Ctrl+A selects all\n if (mode === 'row') {\n if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {\n const shiftKey = event.shiftKey;\n\n // Set anchor before grid moves focus\n if (shiftKey && this.anchor === null) {\n this.anchor = this.grid._focusRow;\n }\n\n // Let grid move focus first, then sync row selection\n queueMicrotask(() => {\n const focusRow = this.grid._focusRow;\n\n if (shiftKey && this.anchor !== null) {\n // Shift+Arrow: Extend selection from anchor\n this.selected.clear();\n const start = Math.min(this.anchor, focusRow);\n const end = Math.max(this.anchor, focusRow);\n for (let i = start; i <= end; i++) {\n if (this.isRowSelectable(i)) {\n this.selected.add(i);\n }\n }\n } else {\n // Plain arrow: Single select\n if (this.isRowSelectable(focusRow)) {\n this.selected.clear();\n this.selected.add(focusRow);\n this.anchor = focusRow;\n } else {\n this.selected.clear();\n }\n }\n\n this.lastSelected = focusRow;\n this.explicitSelection = true;\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n this.requestAfterRender();\n });\n return false; // Let grid handle navigation\n }\n\n // Ctrl+A: Select all rows\n if (event.key === 'a' && (event.ctrlKey || event.metaKey)) {\n event.preventDefault();\n event.stopPropagation();\n this.selectAll();\n return true;\n }\n }\n\n // RANGE MODE: Shift+Arrow extends, plain Arrow resets\n // Tab key always navigates without extending (even with Shift)\n if (mode === 'range' && isNavKey) {\n // Tab should not extend selection - it just navigates to the next/previous cell\n const isTabKey = event.key === 'Tab';\n const shouldExtend = event.shiftKey && !isTabKey;\n\n // Capture anchor BEFORE grid moves focus (synchronous)\n // This ensures the anchor is the starting point, not the destination\n if (shouldExtend && !this.cellAnchor) {\n this.cellAnchor = { row: this.grid._focusRow, col: this.grid._focusCol };\n }\n\n // Mark pending update - will be processed in afterRender when grid updates focus\n this.pendingKeyboardUpdate = { shiftKey: shouldExtend };\n\n // Schedule afterRender to run after grid's keyboard handler completes\n // Grid's refreshVirtualWindow(false) skips afterRender for performance,\n // so we explicitly request it to process pendingKeyboardUpdate\n queueMicrotask(() => this.requestAfterRender());\n\n return false; // Let grid handle navigation\n }\n\n // Ctrl+A selects all in range mode\n if (mode === 'range' && event.key === 'a' && (event.ctrlKey || event.metaKey)) {\n event.preventDefault();\n event.stopPropagation();\n this.selectAll();\n return true;\n }\n\n return false;\n }\n\n /** @internal */\n override onCellMouseDown(event: CellMouseEvent): boolean | void {\n // Skip all selection if disabled at grid level or plugin level\n if (!this.isSelectionEnabled()) return;\n\n if (this.config.mode !== 'range') return;\n if (event.rowIndex === undefined || event.colIndex === undefined) return;\n if (event.rowIndex < 0) return; // Header\n\n // Skip utility columns (expander columns, etc.)\n const column = this.columns[event.colIndex];\n if (column && isUtilityColumn(column)) {\n return; // Don't start selection on utility columns\n }\n\n // Skip non-selectable cells - don't start drag from them\n if (!this.isCellSelectable(event.rowIndex, event.colIndex)) {\n return;\n }\n\n // Let onCellClick handle shift+click for range extension\n if (event.originalEvent.shiftKey && this.cellAnchor) {\n return;\n }\n\n // Start drag selection\n this.isDragging = true;\n const rowIndex = event.rowIndex;\n const colIndex = event.colIndex;\n\n const ctrlKey = event.originalEvent.ctrlKey || event.originalEvent.metaKey;\n\n const newRange: InternalCellRange = {\n startRow: rowIndex,\n startCol: colIndex,\n endRow: rowIndex,\n endCol: colIndex,\n };\n\n // Check if selection is actually changing (for non-Ctrl clicks)\n if (!ctrlKey && this.ranges.length === 1 && rangesEqual(this.ranges[0], newRange)) {\n // Same cell already selected, just update anchor for potential drag\n this.cellAnchor = { row: rowIndex, col: colIndex };\n return true;\n }\n\n this.cellAnchor = { row: rowIndex, col: colIndex };\n\n if (!ctrlKey) {\n this.ranges = [];\n }\n\n this.ranges.push(newRange);\n this.activeRange = newRange;\n\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n this.requestAfterRender();\n return true;\n }\n\n /** @internal */\n override onCellMouseMove(event: CellMouseEvent): boolean | void {\n // Skip all selection if disabled at grid level or plugin level\n if (!this.isSelectionEnabled()) return;\n\n if (this.config.mode !== 'range') return;\n if (!this.isDragging || !this.cellAnchor) return;\n if (event.rowIndex === undefined || event.colIndex === undefined) return;\n if (event.rowIndex < 0) return;\n\n // When dragging, clamp to first data column (skip utility columns)\n let targetCol = event.colIndex;\n const column = this.columns[targetCol];\n if (column && isUtilityColumn(column)) {\n // Find the first non-utility column\n const firstDataCol = this.columns.findIndex((col) => !isUtilityColumn(col));\n if (firstDataCol >= 0) {\n targetCol = firstDataCol;\n }\n }\n\n const newRange = createRangeFromAnchor(this.cellAnchor, { row: event.rowIndex, col: targetCol });\n\n // Only update and emit if the range actually changed\n const currentRange = this.ranges.length > 0 ? this.ranges[this.ranges.length - 1] : null;\n if (currentRange && rangesEqual(currentRange, newRange)) {\n return true; // Range unchanged, no need to update\n }\n\n if (this.ranges.length > 0) {\n this.ranges[this.ranges.length - 1] = newRange;\n } else {\n this.ranges.push(newRange);\n }\n this.activeRange = newRange;\n\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n this.requestAfterRender();\n return true;\n }\n\n /** @internal */\n override onCellMouseUp(_event: CellMouseEvent): boolean | void {\n // Skip all selection if disabled at grid level or plugin level\n if (!this.isSelectionEnabled()) return;\n\n if (this.config.mode !== 'range') return;\n if (this.isDragging) {\n this.isDragging = false;\n return true;\n }\n }\n\n // #region Checkbox Column\n\n /**\n * Inject checkbox column when `checkbox: true` and mode is `'row'`.\n * @internal\n */\n override processColumns(columns: ColumnConfig[]): ColumnConfig[] {\n if (this.config.checkbox && this.config.mode === 'row') {\n // Check if checkbox column already exists\n if (columns.some((col) => col.field === CHECKBOX_COLUMN_FIELD)) {\n return columns;\n }\n const checkboxCol = this.#createCheckboxColumn();\n // Insert after expander column if present, otherwise first\n const expanderIdx = columns.findIndex(isExpanderColumn);\n const insertAt = expanderIdx >= 0 ? expanderIdx + 1 : 0;\n return [...columns.slice(0, insertAt), checkboxCol, ...columns.slice(insertAt)];\n }\n return columns;\n }\n\n /**\n * Create the checkbox utility column configuration.\n */\n #createCheckboxColumn(): ColumnConfig {\n return {\n field: CHECKBOX_COLUMN_FIELD,\n header: '',\n width: 32,\n resizable: false,\n sortable: false,\n meta: {\n lockPosition: true,\n suppressMovable: true,\n utility: true,\n checkboxColumn: true,\n },\n headerRenderer: () => {\n const container = document.createElement('div');\n container.className = 'tbw-checkbox-header';\n const checkbox = document.createElement('input');\n checkbox.type = 'checkbox';\n checkbox.className = 'tbw-select-all-checkbox';\n checkbox.addEventListener('click', (e) => {\n e.stopPropagation(); // Prevent header sort\n if ((e.target as HTMLInputElement).checked) {\n this.selectAll();\n } else {\n this.clearSelection();\n }\n });\n container.appendChild(checkbox);\n return container;\n },\n renderer: (ctx) => {\n const checkbox = document.createElement('input');\n checkbox.type = 'checkbox';\n checkbox.className = 'tbw-select-row-checkbox';\n // Set initial checked state from current selection\n const cellEl = ctx.cellEl;\n if (cellEl) {\n const rowIndex = parseInt(cellEl.getAttribute('data-row') ?? '-1', 10);\n if (rowIndex >= 0) {\n checkbox.checked = this.selected.has(rowIndex);\n }\n }\n return checkbox;\n },\n };\n }\n\n /**\n * Update checkbox checked states to reflect current selection.\n * Called from #applySelectionClasses.\n */\n #updateCheckboxStates(gridEl: HTMLElement): void {\n // Update row checkboxes\n const rowCheckboxes = gridEl.querySelectorAll('.tbw-select-row-checkbox') as NodeListOf<HTMLInputElement>;\n rowCheckboxes.forEach((checkbox) => {\n const cell = checkbox.closest('.cell');\n const rowIndex = cell ? getRowIndexFromCell(cell) : -1;\n if (rowIndex >= 0) {\n checkbox.checked = this.selected.has(rowIndex);\n }\n });\n\n // Update header select-all checkbox\n const headerCheckbox = gridEl.querySelector('.tbw-select-all-checkbox') as HTMLInputElement | null;\n if (headerCheckbox) {\n const rowCount = this.rows.length;\n let selectableCount = 0;\n if (this.config.isSelectable) {\n for (let i = 0; i < rowCount; i++) {\n if (this.isRowSelectable(i)) selectableCount++;\n }\n } else {\n selectableCount = rowCount;\n }\n const allSelected = selectableCount > 0 && this.selected.size >= selectableCount;\n const someSelected = this.selected.size > 0;\n headerCheckbox.checked = allSelected;\n headerCheckbox.indeterminate = someSelected && !allSelected;\n }\n }\n\n // #endregion\n\n /**\n * Sync selection state to the grid's current focus position.\n * In row mode, keeps `selected` in sync with `_focusRow`.\n * In cell mode, keeps `selectedCell` in sync with `_focusRow`/`_focusCol`.\n * Only updates when the focus has changed since the last sync.\n * Skips when `explicitSelection` is set (click/keyboard set selection directly).\n */\n #syncSelectionToFocus(mode: string): void {\n const focusRow = this.grid._focusRow;\n const focusCol = this.grid._focusCol;\n\n if (mode === 'row') {\n // Skip auto-sync when selection was explicitly set (Shift/Ctrl click, keyboard)\n if (this.explicitSelection) {\n this.explicitSelection = false;\n this.lastSyncedFocusRow = focusRow;\n return;\n }\n\n if (focusRow !== this.lastSyncedFocusRow) {\n this.lastSyncedFocusRow = focusRow;\n if (this.isRowSelectable(focusRow)) {\n if (!this.selected.has(focusRow) || this.selected.size !== 1) {\n this.selected.clear();\n this.selected.add(focusRow);\n this.lastSelected = focusRow;\n this.anchor = focusRow;\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n }\n }\n }\n }\n\n if (mode === 'cell') {\n if (this.explicitSelection) {\n this.explicitSelection = false;\n this.lastSyncedFocusRow = focusRow;\n this.lastSyncedFocusCol = focusCol;\n return;\n }\n\n if (focusRow !== this.lastSyncedFocusRow || focusCol !== this.lastSyncedFocusCol) {\n this.lastSyncedFocusRow = focusRow;\n this.lastSyncedFocusCol = focusCol;\n if (this.isCellSelectable(focusRow, focusCol)) {\n const cur = this.selectedCell;\n if (!cur || cur.row !== focusRow || cur.col !== focusCol) {\n this.selectedCell = { row: focusRow, col: focusCol };\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n }\n }\n }\n }\n }\n\n /**\n * Apply CSS selection classes to row/cell elements.\n * Shared by afterRender and onScrollRender.\n */\n #applySelectionClasses(): void {\n const gridEl = this.gridElement;\n if (!gridEl) return;\n\n const { mode } = this.config;\n const hasSelectableCallback = !!this.config.isSelectable;\n\n // Clear all selection classes first\n const allCells = gridEl.querySelectorAll('.cell');\n allCells.forEach((cell) => {\n cell.classList.remove('selected', 'top', 'bottom', 'first', 'last');\n // Clear selectable attribute - will be re-applied below\n if (hasSelectableCallback) {\n cell.removeAttribute('data-selectable');\n }\n });\n\n const allRows = gridEl.querySelectorAll('.data-grid-row');\n allRows.forEach((row) => {\n row.classList.remove('selected', 'row-focus');\n // Clear selectable attribute - will be re-applied below\n if (hasSelectableCallback) {\n row.removeAttribute('data-selectable');\n }\n });\n\n // ROW MODE: Add row-focus class to selected rows, disable cell-focus, update checkboxes\n if (mode === 'row') {\n // In row mode, disable ALL cell-focus styling - row selection takes precedence\n clearCellFocus(gridEl);\n\n allRows.forEach((row) => {\n const firstCell = row.querySelector('.cell[data-row]');\n const rowIndex = getRowIndexFromCell(firstCell);\n if (rowIndex >= 0) {\n // Mark non-selectable rows\n if (hasSelectableCallback && !this.isRowSelectable(rowIndex)) {\n row.setAttribute('data-selectable', 'false');\n }\n if (this.selected.has(rowIndex)) {\n row.classList.add('selected', 'row-focus');\n }\n }\n });\n\n // Update checkbox states if checkbox column is enabled\n if (this.config.checkbox) {\n this.#updateCheckboxStates(gridEl);\n }\n }\n\n // CELL/RANGE MODE: Mark non-selectable cells\n if ((mode === 'cell' || mode === 'range') && hasSelectableCallback) {\n const cells = gridEl.querySelectorAll('.cell[data-row][data-col]');\n cells.forEach((cell) => {\n const rowIndex = parseInt(cell.getAttribute('data-row') ?? '-1', 10);\n const colIndex = parseInt(cell.getAttribute('data-col') ?? '-1', 10);\n if (rowIndex >= 0 && colIndex >= 0) {\n if (!this.isCellSelectable(rowIndex, colIndex)) {\n cell.setAttribute('data-selectable', 'false');\n }\n }\n });\n }\n\n // RANGE MODE: Add selected and edge classes to cells\n // Uses neighbor-based edge detection for correct multi-range borders\n if (mode === 'range' && this.ranges.length > 0) {\n // Clear all cell-focus first - selection plugin manages focus styling in range mode\n clearCellFocus(gridEl);\n\n // Pre-normalize ranges for efficient neighbor checks\n const normalizedRanges = this.ranges.map(normalizeRange);\n\n // Fast selection check against pre-normalized ranges\n const isInSelection = (r: number, c: number): boolean => {\n for (const range of normalizedRanges) {\n if (r >= range.startRow && r <= range.endRow && c >= range.startCol && c <= range.endCol) {\n return true;\n }\n }\n return false;\n };\n\n const cells = gridEl.querySelectorAll('.cell[data-row][data-col]');\n cells.forEach((cell) => {\n const rowIndex = parseInt(cell.getAttribute('data-row') ?? '-1', 10);\n const colIndex = parseInt(cell.getAttribute('data-col') ?? '-1', 10);\n if (rowIndex >= 0 && colIndex >= 0) {\n // Skip utility columns entirely - don't add any selection classes\n const column = this.columns[colIndex];\n if (column && isUtilityColumn(column)) {\n return;\n }\n\n if (isInSelection(rowIndex, colIndex)) {\n cell.classList.add('selected');\n\n // Edge detection: add border class where neighbor is not selected\n // This handles single ranges, multi-range, and irregular selections correctly\n if (!isInSelection(rowIndex - 1, colIndex)) cell.classList.add('top');\n if (!isInSelection(rowIndex + 1, colIndex)) cell.classList.add('bottom');\n if (!isInSelection(rowIndex, colIndex - 1)) cell.classList.add('first');\n if (!isInSelection(rowIndex, colIndex + 1)) cell.classList.add('last');\n }\n }\n });\n }\n\n // CELL MODE: Let the grid's native .cell-focus styling handle cell highlighting\n // No additional action needed - the grid already manages focus styling\n }\n\n /** @internal */\n override afterRender(): void {\n // Skip rendering selection if disabled at grid level or plugin level\n if (!this.isSelectionEnabled()) return;\n\n const gridEl = this.gridElement;\n if (!gridEl) return;\n\n const container = gridEl.children[0];\n const { mode } = this.config;\n\n // Process pending keyboard navigation update (range mode)\n // This runs AFTER the grid has updated focusRow/focusCol\n if (this.pendingKeyboardUpdate && mode === 'range') {\n const { shiftKey } = this.pendingKeyboardUpdate;\n this.pendingKeyboardUpdate = null;\n\n const currentRow = this.grid._focusRow;\n const currentCol = this.grid._focusCol;\n\n if (shiftKey && this.cellAnchor) {\n // Extend selection from anchor to current focus\n const newRange = createRangeFromAnchor(this.cellAnchor, { row: currentRow, col: currentCol });\n this.ranges = [newRange];\n this.activeRange = newRange;\n } else if (!shiftKey) {\n // Without shift, clear selection (cell-focus will show instead)\n this.ranges = [];\n this.activeRange = null;\n this.cellAnchor = { row: currentRow, col: currentCol }; // Reset anchor to current position\n }\n\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n }\n\n // Sync selection to grid's focus position.\n // This ensures selection follows keyboard navigation (Tab, arrows, etc.)\n // regardless of which plugin moved the focus.\n this.#syncSelectionToFocus(mode);\n\n // Set data attribute on host for CSS variable scoping\n (this.grid as unknown as Element).setAttribute('data-selection-mode', mode);\n\n // Toggle .selecting class during drag to prevent text selection\n if (container) {\n container.classList.toggle('selecting', this.isDragging);\n }\n\n this.#applySelectionClasses();\n }\n\n /**\n * Called after scroll-triggered row rendering.\n * Reapplies selection classes to recycled DOM elements.\n * @internal\n */\n override onScrollRender(): void {\n // Skip rendering selection classes if disabled\n if (!this.isSelectionEnabled()) return;\n\n this.#applySelectionClasses();\n }\n\n // #endregion\n\n // #region Public API\n\n /**\n * Get the current selection as a unified result.\n * Works for all selection modes and always returns ranges.\n *\n * @example\n * ```ts\n * const selection = plugin.getSelection();\n * if (selection.ranges.length > 0) {\n * const { from, to } = selection.ranges[0];\n * // For cell mode: from === to (single cell)\n * // For row mode: from.col = 0, to.col = lastCol (full row)\n * // For range mode: rectangular selection\n * }\n * ```\n */\n getSelection(): SelectionResult {\n return {\n mode: this.config.mode,\n ranges: this.#buildEvent().ranges,\n anchor: this.cellAnchor,\n };\n }\n\n /**\n * Get all selected cells across all ranges.\n */\n getSelectedCells(): Array<{ row: number; col: number }> {\n return getAllCellsInRanges(this.ranges);\n }\n\n /**\n * Check if a specific cell is in range selection.\n */\n isCellSelected(row: number, col: number): boolean {\n return isCellInAnyRange(row, col, this.ranges);\n }\n\n /**\n * Select all selectable rows (row mode) or all cells (range mode).\n *\n * In row mode, selects every row where `isSelectable` returns true (or all rows if no callback).\n * In range mode, creates a single range spanning all rows and columns.\n * Has no effect in cell mode.\n *\n * @example\n * ```ts\n * const plugin = grid.getPlugin(SelectionPlugin);\n * plugin.selectAll(); // Selects everything in current mode\n * ```\n */\n selectAll(): void {\n const { mode } = this.config;\n\n if (mode === 'row') {\n this.selected.clear();\n for (let i = 0; i < this.rows.length; i++) {\n if (this.isRowSelectable(i)) {\n this.selected.add(i);\n }\n }\n this.explicitSelection = true;\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n this.requestAfterRender();\n } else if (mode === 'range') {\n const rowCount = this.rows.length;\n const colCount = this.columns.length;\n if (rowCount > 0 && colCount > 0) {\n const allRange: InternalCellRange = {\n startRow: 0,\n startCol: 0,\n endRow: rowCount - 1,\n endCol: colCount - 1,\n };\n this.ranges = [allRange];\n this.activeRange = allRange;\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n this.requestAfterRender();\n }\n }\n }\n\n /**\n * Select specific rows by index (row mode only).\n * Replaces the current selection with the provided row indices.\n * Indices that are out of bounds or fail the `isSelectable` check are ignored.\n *\n * @param indices - Array of row indices to select\n *\n * @example\n * ```ts\n * const plugin = grid.getPlugin(SelectionPlugin);\n * plugin.selectRows([0, 2, 4]); // Select rows 0, 2, and 4\n * ```\n */\n selectRows(indices: number[]): void {\n if (this.config.mode !== 'row') return;\n this.selected.clear();\n for (const idx of indices) {\n if (idx >= 0 && idx < this.rows.length && this.isRowSelectable(idx)) {\n this.selected.add(idx);\n }\n }\n this.anchor = indices.length > 0 ? indices[indices.length - 1] : null;\n this.explicitSelection = true;\n this.emit<SelectionChangeDetail>('selection-change', this.#buildEvent());\n this.requestAfterRender();\n }\n\n /**\n * Get the indices of all selected rows (convenience for row mode).\n * Returns indices sorted in ascending order.\n *\n * @example\n * ```ts\n * const plugin = grid.getPlugin(SelectionPlugin);\n * const rows = plugin.getSelectedRowIndices(); // [0, 2, 4]\n * ```\n */\n getSelectedRowIndices(): number[] {\n return [...this.selected].sort((a, b) => a - b);\n }\n\n /**\n * Clear all selection.\n */\n clearSelection(): void {\n this.selectedCell = null;\n this.selected.clear();\n this.anchor = null;\n this.ranges = [];\n this.activeRange = null;\n this.cellAnchor = null;\n this.emit<SelectionChangeDetail>('selection-change', { mode: this.config.mode, ranges: [] });\n this.requestAfterRender();\n }\n\n /**\n * Set selected ranges programmatically.\n */\n setRanges(ranges: CellRange[]): void {\n this.ranges = ranges.map((r) => ({\n startRow: r.from.row,\n startCol: r.from.col,\n endRow: r.to.row,\n endCol: r.to.col,\n }));\n this.activeRange = this.ranges.length > 0 ? this.ranges[this.ranges.length - 1] : null;\n this.emit<SelectionChangeDetail>('selection-change', {\n mode: this.config.mode,\n ranges: toPublicRanges(this.ranges),\n });\n this.requestAfterRender();\n }\n\n // #endregion\n\n // #region Private Helpers\n\n #buildEvent(): SelectionChangeDetail {\n return buildSelectionEvent(\n this.config.mode,\n {\n selectedCell: this.selectedCell,\n selected: this.selected,\n ranges: this.ranges,\n },\n this.columns.length,\n );\n }\n\n // #endregion\n}\n"],"names":["normalizeRange","range","toPublicRange","normalized","toPublicRanges","ranges","isCellInRange","row","col","isCellInAnyRange","getCellsInRange","cells","getAllCellsInRanges","cellMap","cell","createRangeFromAnchor","anchor","current","rangesEqual","a","b","normA","normB","CHECKBOX_COLUMN_FIELD","buildSelectionEvent","mode","state","colCount","sorted","start","end","i","SelectionPlugin","BaseGridPlugin","config","styles","rowIndex","colIndex","isSelectable","column","grid","query","event","originalEvent","triggerOn","isUtility","isUtilityColumn","currentCell","#buildEvent","shiftKey","ctrlKey","isCheckbox","newRange","currentRange","isNavKey","focusRow","focusCol","isTabKey","shouldExtend","targetCol","firstDataCol","_event","columns","checkboxCol","#createCheckboxColumn","expanderIdx","isExpanderColumn","insertAt","container","checkbox","e","ctx","cellEl","#updateCheckboxStates","gridEl","getRowIndexFromCell","headerCheckbox","rowCount","selectableCount","allSelected","someSelected","#syncSelectionToFocus","cur","#applySelectionClasses","hasSelectableCallback","allRows","clearCellFocus","firstCell","normalizedRanges","isInSelection","r","c","currentRow","currentCol","allRange","indices","idx"],"mappings":"+eAeO,SAASA,EAAeC,EAA6C,CAC1E,MAAO,CACL,SAAU,KAAK,IAAIA,EAAM,SAAUA,EAAM,MAAM,EAC/C,SAAU,KAAK,IAAIA,EAAM,SAAUA,EAAM,MAAM,EAC/C,OAAQ,KAAK,IAAIA,EAAM,SAAUA,EAAM,MAAM,EAC7C,OAAQ,KAAK,IAAIA,EAAM,SAAUA,EAAM,MAAM,CAAA,CAEjD,CAQO,SAASC,EAAcD,EAAqC,CACjE,MAAME,EAAaH,EAAeC,CAAK,EACvC,MAAO,CACL,KAAM,CAAE,IAAKE,EAAW,SAAU,IAAKA,EAAW,QAAA,EAClD,GAAI,CAAE,IAAKA,EAAW,OAAQ,IAAKA,EAAW,MAAA,CAAO,CAEzD,CAQO,SAASC,EAAeC,EAA0C,CACvE,OAAOA,EAAO,IAAIH,CAAa,CACjC,CAUO,SAASI,EAAcC,EAAaC,EAAaP,EAAmC,CACzF,MAAME,EAAaH,EAAeC,CAAK,EACvC,OACEM,GAAOJ,EAAW,UAAYI,GAAOJ,EAAW,QAAUK,GAAOL,EAAW,UAAYK,GAAOL,EAAW,MAE9G,CAUO,SAASM,EAAiBF,EAAaC,EAAaH,EAAsC,CAC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