@toolbox-web/grid 2.11.1 → 2.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/all.js +2 -2
  2. package/all.js.map +1 -1
  3. package/custom-elements.json +20 -1
  4. package/index.js +1 -1
  5. package/index.js.map +1 -1
  6. package/lib/core/grid.d.ts +24 -2
  7. package/lib/core/internal/empty.d.ts +73 -0
  8. package/lib/core/internal/focus-manager.d.ts +17 -0
  9. package/lib/core/internal/shell.d.ts +1 -1
  10. package/lib/core/internal/virtualization.d.ts +103 -1
  11. package/lib/core/styles/index.d.ts +3 -2
  12. package/lib/core/types.d.ts +103 -7
  13. package/lib/features/pinned-columns.js.map +1 -1
  14. package/lib/plugins/clipboard/index.js.map +1 -1
  15. package/lib/plugins/column-virtualization/index.js.map +1 -1
  16. package/lib/plugins/context-menu/index.js.map +1 -1
  17. package/lib/plugins/editing/EditingPlugin.d.ts +1 -1
  18. package/lib/plugins/editing/index.js +1 -1
  19. package/lib/plugins/editing/index.js.map +1 -1
  20. package/lib/plugins/editing/types.d.ts +9 -1
  21. package/lib/plugins/export/index.js.map +1 -1
  22. package/lib/plugins/filtering/index.js +1 -1
  23. package/lib/plugins/filtering/index.js.map +1 -1
  24. package/lib/plugins/grouping-columns/index.js.map +1 -1
  25. package/lib/plugins/grouping-rows/index.js.map +1 -1
  26. package/lib/plugins/master-detail/index.js.map +1 -1
  27. package/lib/plugins/multi-sort/index.js.map +1 -1
  28. package/lib/plugins/pinned-columns/index.js +1 -1
  29. package/lib/plugins/pinned-columns/index.js.map +1 -1
  30. package/lib/plugins/pinned-rows/index.js.map +1 -1
  31. package/lib/plugins/pivot/index.js.map +1 -1
  32. package/lib/plugins/print/index.js.map +1 -1
  33. package/lib/plugins/reorder-columns/index.js +1 -1
  34. package/lib/plugins/reorder-columns/index.js.map +1 -1
  35. package/lib/plugins/reorder-rows/index.js +1 -1
  36. package/lib/plugins/reorder-rows/index.js.map +1 -1
  37. package/lib/plugins/responsive/index.js +1 -1
  38. package/lib/plugins/responsive/index.js.map +1 -1
  39. package/lib/plugins/row-drag-drop/RowDragDropPlugin.d.ts +1 -1
  40. package/lib/plugins/row-drag-drop/index.js +1 -1
  41. package/lib/plugins/row-drag-drop/index.js.map +1 -1
  42. package/lib/plugins/selection/SelectionPlugin.d.ts +1 -1
  43. package/lib/plugins/selection/index.d.ts +1 -1
  44. package/lib/plugins/selection/index.js.map +1 -1
  45. package/lib/plugins/server-side/ServerSidePlugin.d.ts +1 -1
  46. package/lib/plugins/server-side/index.js.map +1 -1
  47. package/lib/plugins/sticky-rows/index.js.map +1 -1
  48. package/lib/plugins/tooltip/index.js.map +1 -1
  49. package/lib/plugins/tree/index.js.map +1 -1
  50. package/lib/plugins/undo-redo/index.js.map +1 -1
  51. package/lib/plugins/visibility/index.js.map +1 -1
  52. package/package.json +1 -1
  53. package/public.d.ts +10 -1
  54. package/umd/grid.all.umd.js +1 -1
  55. package/umd/grid.all.umd.js.map +1 -1
  56. package/umd/grid.umd.js +1 -1
  57. package/umd/grid.umd.js.map +1 -1
  58. package/umd/plugins/editing.umd.js.map +1 -1
  59. package/umd/plugins/pinned-columns.umd.js +1 -1
  60. package/umd/plugins/pinned-columns.umd.js.map +1 -1
  61. package/umd/plugins/reorder-rows.umd.js.map +1 -1
  62. package/umd/plugins/row-drag-drop.umd.js.map +1 -1
  63. package/umd/plugins/selection.umd.js.map +1 -1
  64. package/umd/plugins/server-side.umd.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"reorder-rows.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/shared/drag-drop-protocol.ts","../../../../../libs/grid/src/lib/plugins/row-drag-drop/RowDragDropPlugin.ts"],"sourcesContent":["/**\n * Drag-Drop Protocol — shared utilities for cross-grid row drag-and-drop.\n *\n * Used by `RowDragDropPlugin` (and any future plugin that participates in the\n * tbw row-drag protocol). Centralises:\n *\n * - MIME type constants and zone tagging (visible in `dataTransfer.types`)\n * - Payload codec for cross-window / cross-iframe transfers\n * - Drop-position math (midpoint algorithm)\n * - Auto-scroll engine (rAF loop, edge detection, boundary clamp)\n * - Plain-text TSV fallback for drags out to Notepad / Excel / Slack\n *\n * @internal Plugin shared utility (not part of the public API).\n */\n\nimport type { ColumnConfig } from '../../core/types';\n\n// ---------------------------------------------------------------------------\n// Same-window current-session tracker\n// ---------------------------------------------------------------------------\n\n/**\n * Module-level \"active drag session\" — set on dragstart by the source grid,\n * cleared on dragend. Lets target grids read the full payload synchronously\n * during `dragover` (browsers hide `dataTransfer.getData()` during dragover\n * for security). Cross-window drags don't have access to this module and\n * fall back to a generic accept-check followed by a drop-time canDrop call.\n *\n * @internal\n */\nlet currentSession: { sessionId: string; payload: RowDragPayload<unknown> } | null = null;\n\n/** @internal */\nexport function setCurrentDragSession<T>(sessionId: string, payload: RowDragPayload<T>): void {\n currentSession = { sessionId, payload: payload as RowDragPayload<unknown> };\n}\n\n/** @internal */\nexport function getCurrentDragSession<T = unknown>(): { sessionId: string; payload: RowDragPayload<T> } | null {\n return currentSession as { sessionId: string; payload: RowDragPayload<T> } | null;\n}\n\n/** @internal */\nexport function clearCurrentDragSession(): void {\n currentSession = null;\n}\n\n// ---------------------------------------------------------------------------\n// MIME types\n// ---------------------------------------------------------------------------\n\n/** Base MIME type carried on `dataTransfer` for tbw row drags. */\nexport const TBW_ROW_DRAG_MIME = 'application/x-tbw-grid-rows+json';\n\n/** Build a zone-tagged MIME type, visible in `dataTransfer.types` during dragover. */\nexport function mimeForZone(zone: string): string {\n return `${TBW_ROW_DRAG_MIME};zone=${encodeURIComponent(zone)}`;\n}\n\n/** Extract the zone from a tagged MIME, or `null` if untagged. */\nexport function parseZoneFromMime(mime: string): string | null {\n const match = mime.match(/^application\\/x-tbw-grid-rows\\+json;zone=(.*)$/);\n if (!match) return null;\n try {\n return decodeURIComponent(match[1]);\n } catch {\n return match[1];\n }\n}\n\n/**\n * Find the first MIME entry in `types` whose zone matches `zone`.\n * Used during `dragover` for the accept-check (browsers hide `getData()`\n * during dragover, but `types` is always visible).\n */\nexport function findMatchingZoneMime(types: readonly string[], zone: string): string | null {\n for (const t of types) {\n if (parseZoneFromMime(t) === zone) return t;\n }\n return null;\n}\n\n/** Returns true if any tbw row-drag MIME is present in `types`. */\nexport function hasAnyRowDragMime(types: readonly string[]): boolean {\n for (const t of types) {\n if (t === TBW_ROW_DRAG_MIME || t.startsWith(`${TBW_ROW_DRAG_MIME};`)) return true;\n }\n return false;\n}\n\n// ---------------------------------------------------------------------------\n// Payload\n// ---------------------------------------------------------------------------\n\n/**\n * Cross-grid drag payload, carried on `dataTransfer` and (for same-window\n * recovery) keyed in the WeakRef registry by `sessionId`.\n */\nexport interface RowDragPayload<T = unknown> {\n /** Drag session id (matches the WeakRef registry key). */\n sessionId: string;\n /** Source grid id (`grid.id` or auto-generated UUID). */\n sourceGridId: string;\n /** Drop zone the source grid is participating in. */\n dropZone: string;\n /** Serialized row payload (JSON-safe). For same-window drops, recovered live via the registry. */\n rows: T[];\n /** Original indices in the source grid's `_rows` array. */\n rowIndices: number[];\n /** Move (default) removes from source; copy leaves source intact. */\n operation: 'move' | 'copy';\n}\n\n/** Encode a payload to the JSON string written to `dataTransfer`. */\nexport function encodePayload<T>(payload: RowDragPayload<T>): string {\n return JSON.stringify(payload);\n}\n\n/** Decode a payload from the JSON string read off `dataTransfer`. */\nexport function decodePayload<T = unknown>(raw: string): RowDragPayload<T> | null {\n if (!raw) return null;\n try {\n const parsed = JSON.parse(raw) as RowDragPayload<T>;\n if (\n typeof parsed?.sessionId !== 'string' ||\n typeof parsed?.sourceGridId !== 'string' ||\n typeof parsed?.dropZone !== 'string' ||\n !Array.isArray(parsed?.rows) ||\n !Array.isArray(parsed?.rowIndices) ||\n (parsed.operation !== 'move' && parsed.operation !== 'copy')\n ) {\n return null;\n }\n // `rowIndices` is later used for sorting and splicing — reject anything\n // that isn't a finite, non-negative integer to avoid JS coercion bugs\n // (NaN ordering, float splice indices, string concatenation, etc.).\n for (const idx of parsed.rowIndices) {\n if (typeof idx !== 'number' || !Number.isInteger(idx) || idx < 0) return null;\n }\n return parsed;\n } catch {\n return null;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Drop position math\n// ---------------------------------------------------------------------------\n\nexport interface DropPosition {\n /** Target visual row index that the cursor is over, or `null` for empty area. */\n overIndex: number | null;\n /** Final insertion index in the target grid's `_rows`. */\n insertIndex: number;\n /** True when the cursor is above the row midpoint. */\n isBefore: boolean;\n}\n\n/**\n * Compute the insertion index for a drop, given the row element under the\n * cursor (if any), the cursor's clientY, and the total row count when the\n * cursor is in empty space below the last row.\n *\n * - Cursor above row midpoint → insert at `targetIndex`\n * - Cursor below row midpoint → insert at `targetIndex + 1`\n * - Cursor over empty area below the last row → append (`insertIndex = totalRows`)\n */\nexport function computeDropPosition(\n rowEl: HTMLElement | null,\n clientY: number,\n rowIndexResolver: (el: HTMLElement) => number,\n totalRows: number,\n): DropPosition {\n if (!rowEl) {\n return { overIndex: null, insertIndex: totalRows, isBefore: false };\n }\n const targetIndex = rowIndexResolver(rowEl);\n if (targetIndex < 0) {\n return { overIndex: null, insertIndex: totalRows, isBefore: false };\n }\n const rect = rowEl.getBoundingClientRect();\n const midY = rect.top + rect.height / 2;\n const isBefore = clientY < midY;\n return {\n overIndex: targetIndex,\n insertIndex: isBefore ? targetIndex : targetIndex + 1,\n isBefore,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Auto-scroll engine\n// ---------------------------------------------------------------------------\n\nexport interface AutoScrollOptions {\n /** Pixels from the top/bottom edge that activate auto-scroll. */\n edgeSize?: number;\n /** Base scroll speed in pixels-per-frame near the edge. */\n speed?: number;\n /** Max speed at the very edge (linear ramp from `speed` → `maxSpeed`). */\n maxSpeed?: number;\n}\n\nexport interface AutoScroller {\n /** Update pointer position; starts the rAF loop if needed. */\n onPointerMove(clientY: number): void;\n /** Stop the rAF loop and reset state. */\n stop(): void;\n /** True when actively auto-scrolling. */\n readonly isScrolling: boolean;\n}\n\n/**\n * Create an auto-scroller for a viewport element.\n *\n * The scroller runs a `requestAnimationFrame` loop only while the pointer is\n * within `edgeSize` of the viewport's top or bottom and there is room to\n * scroll. Speed ramps linearly from `speed` (at the edge boundary) to\n * `maxSpeed` (at the very edge).\n */\nexport function createAutoScroller(\n viewport: HTMLElement,\n options: AutoScrollOptions = {},\n onScrollChange?: (active: boolean) => void,\n): AutoScroller {\n const edgeSize = options.edgeSize ?? 60;\n const baseSpeed = options.speed ?? 8;\n const maxSpeed = options.maxSpeed ?? 24;\n\n let rafId: number | null = null;\n let pointerY: number | null = null;\n let active = false;\n\n const setActive = (next: boolean): void => {\n if (next === active) return;\n active = next;\n onScrollChange?.(next);\n };\n\n const tick = (): void => {\n rafId = null;\n if (pointerY === null) {\n setActive(false);\n return;\n }\n const rect = viewport.getBoundingClientRect();\n let delta = 0;\n\n if (pointerY < rect.top + edgeSize) {\n const distance = Math.max(0, pointerY - rect.top);\n const ratio = 1 - distance / edgeSize;\n delta = -Math.round(baseSpeed + (maxSpeed - baseSpeed) * ratio);\n } else if (pointerY > rect.bottom - edgeSize) {\n const distance = Math.max(0, rect.bottom - pointerY);\n const ratio = 1 - distance / edgeSize;\n delta = Math.round(baseSpeed + (maxSpeed - baseSpeed) * ratio);\n }\n\n if (delta === 0) {\n setActive(false);\n return;\n }\n\n const before = viewport.scrollTop;\n viewport.scrollTop = before + delta;\n\n // Stop if we hit a boundary (no movement happened)\n if (viewport.scrollTop === before) {\n setActive(false);\n return;\n }\n\n setActive(true);\n rafId = requestAnimationFrame(tick);\n };\n\n return {\n onPointerMove(clientY: number): void {\n pointerY = clientY;\n if (rafId === null) {\n rafId = requestAnimationFrame(tick);\n }\n },\n stop(): void {\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n rafId = null;\n }\n pointerY = null;\n setActive(false);\n },\n get isScrolling(): boolean {\n return active;\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// TSV fallback\n// ---------------------------------------------------------------------------\n\n/**\n * Format rows as a TSV string for the `text/plain` drag fallback.\n * Used when the drop target is an external app (Excel, Notepad, Slack).\n *\n * - One row per line, fields separated by `\\t`.\n * - Tabs and newlines in cell values are replaced with spaces.\n * - Skips columns flagged as `utility` (drag handle, checkbox, etc.).\n */\nexport function formatRowsAsTSV<T extends Record<string, unknown>>(\n rows: readonly T[],\n columns: readonly ColumnConfig[],\n): string {\n const dataColumns = columns.filter(\n (c) => !(c as { utility?: boolean }).utility && typeof c.field === 'string' && c.field !== '',\n );\n const lines: string[] = [];\n for (const row of rows) {\n const cells = dataColumns.map((col) => {\n const value = row[col.field];\n if (value === null || value === undefined) return '';\n const str = String(value);\n return str.replace(/[\\t\\r\\n]+/g, ' ');\n });\n lines.push(cells.join('\\t'));\n }\n return lines.join('\\n');\n}\n","/**\n * Row Drag-Drop Plugin\n *\n * Drag rows within a single grid (parity with the deprecated\n * `RowReorderPlugin`) **and** between grids that share a `dropZone`.\n *\n * Architecture overview is documented in the issue body and in\n * `.github/knowledge/grid-plugins.md`. Key invariants:\n *\n * - Mutations write to `grid._rows`; the user's input `sourceRows` array is\n * never mutated on either side. Persistence is consumer-driven via the\n * `row-move` (intra-grid) and `row-transfer` (cross-grid) events.\n * - Same-window cross-grid drops use the WeakRef registry in\n * `core/internal/drag-drop-registry` to recover live row references.\n * Cross-window drops fall back to `JSON.parse(JSON.stringify(row))` (or the\n * `serializeRow`/`deserializeRow` hooks for non-JSON values).\n * - `RowReorderPlugin` is an alias re-export of this class. The PluginManager\n * alias-collapse pre-pass merges configs when both names are instantiated.\n *\n * @see {@link RowDragDropConfig} for all configuration options.\n */\n\nimport { GridClasses } from '../../core/constants';\nimport {\n clearDragSession,\n lookupDragSession,\n newDragSessionId,\n registerDragSession,\n} from '../../core/internal/drag-drop-registry';\nimport { ensureCellVisible } from '../../core/internal/keyboard';\nimport { BaseGridPlugin, type GridElement, type PluginManifest } from '../../core/plugin/base-plugin';\nimport type { ColumnConfig, GridHost } from '../../core/types';\nimport {\n type AutoScroller,\n type RowDragPayload,\n TBW_ROW_DRAG_MIME,\n clearCurrentDragSession,\n computeDropPosition,\n createAutoScroller,\n decodePayload,\n encodePayload,\n findMatchingZoneMime,\n formatRowsAsTSV,\n getCurrentDragSession,\n hasAnyRowDragMime,\n mimeForZone,\n setCurrentDragSession,\n} from '../shared/drag-drop-protocol';\nimport styles from './row-drag-drop.css?inline';\nimport type {\n PendingMove,\n RowDragDropConfig,\n RowDragEndDetail,\n RowDragStartDetail,\n RowDropDetail,\n RowMoveDetail,\n RowTransferDetail,\n} from './types';\n\n/** Field name for the drag handle column. * @since 2.4.0\n */\nexport const ROW_DRAG_HANDLE_FIELD = '__tbw_row_drag';\n\n// ---------------------------------------------------------------------------\n// Cross-window coordination via BroadcastChannel\n// ---------------------------------------------------------------------------\n//\n// Same-window cross-grid drops can locate the source grid and its plugin via\n// `document.getElementById(sourceGridId)` — the target plugin handles both\n// sides of the transfer in `onDrop` (insert into target + remove from source\n// + emit `row-transfer` on both grids).\n//\n// Cross-window drops can't reach the source DOM that way. The target window\n// broadcasts a `tbw-row-drag-drop:transfer` message; each window has a single\n// channel and fans the message out to every attached plugin instance, which\n// matches on `sourceGridId === this.gridId` and runs the source-side path\n// (row removal on `move`, `row-transfer` emit, `dragAccepted` flip).\n//\n// The channel is created lazily on the first plugin that needs it and shared\n// across all instances in the window. It's torn down when the last instance\n// detaches so we don't leak a handle in environments where the plugin is\n// repeatedly attached/detached.\n\n/** @internal */\ninterface RemoteTransferMessage {\n type: 'tbw-row-drag-drop:transfer';\n sessionId: string;\n sourceGridId: string;\n toGridId: string;\n dropZone: string;\n rowIndices: number[];\n toIndex: number;\n operation: 'move' | 'copy';\n /** Pre-serialized rows (the same shape `serializeRow` produced on dragstart). */\n serializedRows: unknown[];\n}\n\ntype RemoteTransferListener = (msg: RemoteTransferMessage) => void;\n\nconst CROSS_WINDOW_CHANNEL_NAME = 'tbw-row-drag-drop';\nlet sharedChannel: BroadcastChannel | null = null;\nconst remoteListeners = new Set<RemoteTransferListener>();\n\nfunction ensureCrossWindowChannel(): BroadcastChannel | null {\n if (typeof BroadcastChannel === 'undefined') return null;\n if (sharedChannel) return sharedChannel;\n try {\n sharedChannel = new BroadcastChannel(CROSS_WINDOW_CHANNEL_NAME);\n sharedChannel.addEventListener('message', (event: MessageEvent) => {\n const data = event.data as RemoteTransferMessage | undefined;\n if (!data || data.type !== 'tbw-row-drag-drop:transfer') return;\n // Snapshot to tolerate listeners that detach during dispatch.\n for (const listener of Array.from(remoteListeners)) {\n try {\n listener(data);\n } catch {\n /* listener errors must not break sibling listeners */\n }\n }\n });\n } catch {\n sharedChannel = null;\n }\n return sharedChannel;\n}\n\nfunction registerRemoteTransferListener(listener: RemoteTransferListener): void {\n remoteListeners.add(listener);\n ensureCrossWindowChannel();\n}\n\nfunction unregisterRemoteTransferListener(listener: RemoteTransferListener): void {\n remoteListeners.delete(listener);\n if (remoteListeners.size === 0 && sharedChannel) {\n try {\n sharedChannel.close();\n } catch {\n /* noop */\n }\n sharedChannel = null;\n }\n}\n\nfunction broadcastRemoteTransfer(msg: RemoteTransferMessage): void {\n const channel = ensureCrossWindowChannel();\n if (!channel) return;\n try {\n channel.postMessage(msg);\n } catch {\n /* postMessage may throw on uncloneable payloads — acceptable; user can\n * supply `serializeRow` to provide a structured-cloneable shape. */\n }\n}\n\n/**\n * Row Drag-Drop Plugin for `<tbw-grid>`.\n *\n * @example Intra-grid (parity with deprecated `RowReorderPlugin`)\n * ```ts\n * import { RowDragDropPlugin } from '@toolbox-web/grid/plugins/row-drag-drop';\n *\n * grid.gridConfig = {\n * plugins: [new RowDragDropPlugin()],\n * };\n * ```\n *\n * @example Cross-grid transfer list\n * ```ts\n * gridA.gridConfig = { plugins: [new RowDragDropPlugin({ dropZone: 'tasks' })] };\n * gridB.gridConfig = { plugins: [new RowDragDropPlugin({ dropZone: 'tasks' })] };\n *\n * gridA.addEventListener('row-transfer', (e) => persist(e.detail));\n * gridB.addEventListener('row-transfer', (e) => persist(e.detail));\n * ```\n *\n * @category Plugin\n */\nexport class RowDragDropPlugin<T = unknown> extends BaseGridPlugin<RowDragDropConfig<T>> {\n /** @internal */\n readonly name = 'rowDragDrop';\n\n /**\n * Backwards-compatible aliases. `RowReorderPlugin`'s legacy plugin name\n * (`reorderRows`) and short alias (`rowReorder`) both resolve here so that\n * `getPluginByName('reorderRows')` keeps working.\n * @internal\n */\n override readonly aliases = ['reorderRows', 'rowReorder'] as const;\n\n /** @internal */\n override readonly styles = styles;\n\n /** @internal */\n static override readonly manifest: PluginManifest<RowDragDropConfig> = {\n events: [\n { type: 'row-move', description: 'Intra-grid row reorder.', cancelable: true },\n { type: 'row-drag-start', description: 'Cross-grid drag started on this grid.', cancelable: true },\n { type: 'row-drag-end', description: 'Drag finished on this grid (regardless of outcome).' },\n { type: 'row-drop', description: 'Cross-grid drop landing on this grid.', cancelable: true },\n { type: 'row-transfer', description: 'Cross-grid transfer completed (fires on both grids).' },\n ],\n };\n\n /** @internal */\n protected override get defaultConfig(): Partial<RowDragDropConfig<T>> {\n return {\n enableKeyboard: true,\n // `showDragHandle` default depends on `dragFrom` — resolved by\n // `shouldRenderDragHandle()` rather than here so a single `dragFrom`\n // change reshapes both at once.\n dragHandlePosition: 'left',\n dragHandleWidth: 40,\n debounceMs: 150,\n animation: 'flip',\n operation: 'move',\n autoScroll: true,\n dragFrom: 'handle',\n };\n }\n\n /**\n * Resolve whether the grip column should be rendered. The handle is shown\n * unless the user explicitly set `showDragHandle: false`, OR `dragFrom`\n * is `'row'` and `showDragHandle` was not explicitly set to `true`.\n */\n private shouldRenderDragHandle(): boolean {\n const explicit = this.config.showDragHandle;\n if (explicit === false) return false;\n if (explicit === true) return true;\n return this.config.dragFrom !== 'row';\n }\n\n /** Whether the row element itself should accept native HTML5 drag. */\n private get rowIsDraggable(): boolean {\n return this.config.dragFrom === 'row' || this.config.dragFrom === 'both';\n }\n\n /** Resolve animation type from plugin config (respects grid-level reduced-motion). */\n private get animationType(): false | 'flip' {\n if (!this.isAnimationEnabled) return false;\n if (this.config.animation !== undefined) return this.config.animation;\n return 'flip';\n }\n\n // #region Internal State\n private isDragging = false;\n private draggedRowIndex: number | null = null;\n private draggedRows: T[] = [];\n private draggedIndices: number[] = [];\n private dragSessionId: string | null = null;\n private dragAccepted = false;\n private dropRowIndex: number | null = null;\n private pendingMove: PendingMove | null = null;\n private debounceTimer: ReturnType<typeof setTimeout> | null = null;\n private lastFocusCol = 0;\n private autoScroller: AutoScroller | null = null;\n /** Stable id for this grid instance (used as `sourceGridId` in payloads). */\n private gridId = '';\n\n /** Bound listener so we can register/unregister the same reference. */\n private readonly remoteTransferListener: RemoteTransferListener = (msg) => this.onRemoteTransfer(msg);\n\n /** Typed internal grid accessor. */\n private get internalGrid(): GridHost {\n return this.grid as unknown as GridHost;\n }\n // #endregion\n\n // #region Lifecycle\n /** @internal */\n override attach(grid: GridElement): void {\n super.attach(grid);\n const host = this.gridElement;\n if (host) {\n this.gridId = host.id || `tbw-grid-${newDragSessionId().slice(0, 8)}`;\n if (!host.id) host.id = this.gridId;\n this.setupDelegatedDragListeners();\n registerRemoteTransferListener(this.remoteTransferListener);\n }\n }\n\n /** @internal */\n override detach(): void {\n this.clearDebounceTimer();\n this.autoScroller?.stop();\n this.autoScroller = null;\n unregisterRemoteTransferListener(this.remoteTransferListener);\n if (this.dragSessionId) clearDragSession(this.dragSessionId);\n clearCurrentDragSession();\n this.resetDragState();\n super.detach();\n }\n // #endregion\n\n // #region Hooks\n\n /** @internal */\n override processColumns(columns: readonly ColumnConfig[]): ColumnConfig[] {\n if (!this.shouldRenderDragHandle()) return [...columns];\n\n const dragHandleColumn: ColumnConfig = {\n field: ROW_DRAG_HANDLE_FIELD,\n header: '',\n width: this.config.dragHandleWidth ?? 40,\n resizable: false,\n sortable: false,\n filterable: false,\n lockPosition: true,\n utility: true,\n viewRenderer: () => {\n const container = document.createElement('div');\n container.className = 'dg-row-drag-handle';\n container.setAttribute('aria-label', 'Drag to reorder');\n container.setAttribute('role', 'button');\n container.setAttribute('tabindex', '-1');\n container.draggable = true;\n this.setIcon(container, 'dragHandle');\n return container;\n },\n };\n\n return this.config.dragHandlePosition === 'right' ? [...columns, dragHandleColumn] : [dragHandleColumn, ...columns];\n }\n\n /** @internal */\n override afterRender(): void {\n this.applyRowDraggable();\n }\n\n /** @internal */\n override onScrollRender(): void {\n // Virtualization recycles row DOM elements during scroll; re-apply the\n // `draggable` attribute so newly-shown rows still accept HTML5 drag.\n this.applyRowDraggable();\n }\n\n /**\n * Set or clear the `draggable` attribute on every visible row, depending on\n * `config.dragFrom`. Idempotent and cheap (one attribute write per row).\n */\n private applyRowDraggable(): void {\n const body = this.internalGrid._bodyEl;\n if (!body) return;\n const wantDraggable = this.rowIsDraggable;\n const rows = body.querySelectorAll<HTMLElement>('.data-grid-row');\n for (const row of rows) {\n if (wantDraggable) {\n if (row.getAttribute('draggable') !== 'true') row.setAttribute('draggable', 'true');\n } else if (row.hasAttribute('draggable')) {\n row.removeAttribute('draggable');\n }\n }\n }\n\n /** @internal */\n override onKeyDown(event: KeyboardEvent): boolean | void {\n if (!this.config.enableKeyboard) return;\n if (!event.ctrlKey || (event.key !== 'ArrowUp' && event.key !== 'ArrowDown')) return;\n\n const grid = this.internalGrid;\n const focusRow = grid._focusRow;\n const rows = grid._rows ?? this.sourceRows;\n if (focusRow < 0 || focusRow >= rows.length) return;\n\n const direction = event.key === 'ArrowUp' ? 'up' : 'down';\n const toIndex = direction === 'up' ? focusRow - 1 : focusRow + 1;\n if (toIndex < 0 || toIndex >= rows.length) return;\n\n const row = rows[focusRow];\n if (!this.canMoveRow(focusRow, toIndex)) return;\n\n this.handleKeyboardMove(row, focusRow, toIndex, grid._focusCol);\n event.preventDefault();\n event.stopPropagation();\n return true;\n }\n\n /** @internal */\n override onCellClick(): void {\n this.flushPendingMove();\n }\n // #endregion\n\n // #region Public API\n /** Move a row to a new position programmatically (intra-grid). */\n moveRow(fromIndex: number, toIndex: number): void {\n const rows = [...this.sourceRows];\n if (fromIndex < 0 || fromIndex >= rows.length) return;\n if (toIndex < 0 || toIndex >= rows.length) return;\n if (fromIndex === toIndex) return;\n if (!this.canMoveRow(fromIndex, toIndex)) return;\n this.executeIntraGridMove(rows[fromIndex], fromIndex, toIndex, 'keyboard');\n }\n\n /**\n * Check if a row can be moved within this grid.\n * Consults the user-provided `canMove` callback (or `canDrag` veto for the\n * source row), the plugin query system (`canMoveRow`), and `canDrop` for\n * the target.\n */\n canMoveRow(fromIndex: number, toIndex: number): boolean {\n // During debounced keyboard moves, `grid._rows` diverges from\n // `sourceRows` (the user-facing snapshot) because the plugin mutates\n // `_rows` per keystroke and only commits on flush. `onKeyDown` resolves\n // the focused row from `_rows ?? sourceRows`, so validation must read\n // from the same array — otherwise we'd run `canDrag`/`canMove`/queries\n // against the wrong row.\n const rows = this.internalGrid._rows ?? this.sourceRows;\n if (fromIndex < 0 || fromIndex >= rows.length) return false;\n if (toIndex < 0 || toIndex >= rows.length) return false;\n if (fromIndex === toIndex) return false;\n\n // Plugin query veto (Tree, GroupingRows)\n const row = rows[fromIndex] as T;\n const queryResults = this.grid?.query?.<boolean>('canMoveRow', row);\n if (Array.isArray(queryResults) && queryResults.includes(false)) return false;\n\n // canDrag veto (dragstart side)\n if (this.config.canDrag && !this.config.canDrag(row, fromIndex)) return false;\n\n // Legacy canMove callback\n if (this.config.canMove) {\n const direction = toIndex < fromIndex ? 'up' : 'down';\n if (!this.config.canMove(row, fromIndex, toIndex, direction)) return false;\n }\n\n // canDrop callback (intra-grid synthesised payload)\n if (this.config.canDrop) {\n const payload: RowDragPayload<T> = {\n sessionId: 'intra',\n sourceGridId: this.gridId,\n dropZone: this.config.dropZone ?? '',\n rows: [row],\n rowIndices: [fromIndex],\n operation: 'move',\n };\n if (!this.config.canDrop(payload, toIndex)) return false;\n }\n\n return true;\n }\n // #endregion\n\n // #region Drag Setup\n\n private setupDelegatedDragListeners(): void {\n const gridEl = this.gridElement;\n if (!gridEl) return;\n const signal = this.disconnectSignal;\n\n gridEl.addEventListener('dragstart', (e) => this.onDragStart(e as DragEvent), { signal });\n gridEl.addEventListener('dragend', () => this.onDragEnd(), { signal });\n gridEl.addEventListener('dragover', (e) => this.onDragOver(e as DragEvent), { signal });\n gridEl.addEventListener('dragleave', (e) => this.onDragLeave(e as DragEvent), { signal });\n gridEl.addEventListener('drop', (e) => this.onDrop(e as DragEvent), { signal });\n }\n\n private onDragStart(de: DragEvent): void {\n const target = de.target as HTMLElement | null;\n if (!target) return;\n\n // Resolve the row element being picked up. Order matters: a click on the\n // grip column inside a row-draggable grid should still go through the\n // handle path so the cursor offset feels right.\n const handle = target.closest('.dg-row-drag-handle') as HTMLElement | null;\n let rowEl: HTMLElement | null = null;\n let initiatedFromHandle = false;\n if (handle) {\n rowEl = handle.closest('.data-grid-row') as HTMLElement | null;\n initiatedFromHandle = true;\n } else if (this.rowIsDraggable) {\n // Row-as-handle: any cell may start the drag, but interactive\n // descendants (inputs, buttons, anchors, contenteditable, open\n // editors, selection checkboxes) keep their native behaviour.\n if (this.isInteractiveDragOrigin(target)) return;\n rowEl = target.closest('.data-grid-row') as HTMLElement | null;\n }\n if (!rowEl) return;\n\n const rowIndex = this.getRowIndex(rowEl);\n if (rowIndex < 0) return;\n\n // Resolve the rows being dragged: whole selection if dragged row is selected.\n const { rows, indices } = this.resolveDraggedRows(rowIndex);\n if (rows.length === 0) return;\n\n // canDrag veto on the originating row\n if (this.config.canDrag && !this.config.canDrag(rows[0], rowIndex)) {\n de.preventDefault();\n return;\n }\n\n const operation = this.config.operation ?? 'move';\n const dropZone = this.config.dropZone ?? '';\n const sessionId = newDragSessionId();\n\n // Emit cancelable row-drag-start (source-side veto)\n const startDetail: RowDragStartDetail<T> = { rows, indices, operation, dropZone };\n if (this.emitCancelable('row-drag-start', startDetail)) {\n de.preventDefault();\n return;\n }\n\n this.isDragging = true;\n this.draggedRowIndex = rowIndex;\n this.draggedRows = rows;\n this.draggedIndices = indices;\n this.dragSessionId = sessionId;\n this.dragAccepted = false;\n\n // Build the cross-grid payload (always built, even when dropZone is empty —\n // intra-grid drops still benefit from the registry round-trip)\n const serialize = this.config.serializeRow ?? ((r: T) => r);\n const payload: RowDragPayload<T> = {\n sessionId,\n sourceGridId: this.gridId,\n dropZone,\n rows: rows.map(serialize) as T[],\n rowIndices: indices,\n operation,\n };\n\n if (de.dataTransfer) {\n de.dataTransfer.effectAllowed = operation === 'copy' ? 'copyMove' : 'move';\n try {\n de.dataTransfer.setData(TBW_ROW_DRAG_MIME, encodePayload(payload));\n if (dropZone) de.dataTransfer.setData(mimeForZone(dropZone), encodePayload(payload));\n // Plain-text TSV fallback for external drop targets\n de.dataTransfer.setData('text/plain', formatRowsAsTSV(rows as Record<string, unknown>[], this.columns));\n } catch {\n /* JSDOM/happy-dom may throw on setData; harmless */\n }\n\n // Drag image: full-row clone for single-row drags (more legible than\n // the handle alone); count badge for multi-row drags.\n if (rows.length > 1) {\n const badge = document.createElement('div');\n badge.className = 'tbw-row-drag-count';\n badge.textContent = `${rows.length} rows`;\n document.body.appendChild(badge);\n try {\n de.dataTransfer.setDragImage(badge, 10, 10);\n } catch {\n /* ignore */\n }\n setTimeout(() => badge.remove(), 0);\n } else {\n this.attachRowCloneDragImage(de, rowEl, initiatedFromHandle ? handle : null);\n }\n }\n\n // Same-window registry + current-session marker\n registerDragSession(sessionId, rows as unknown[]);\n setCurrentDragSession(sessionId, payload);\n\n rowEl.classList.add(GridClasses.DRAGGING);\n this.gridElement.classList.add('tbw-grid--drag-source');\n }\n\n /**\n * Selectors whose dragstart should NOT initiate a row drag in `dragFrom: 'row'`\n * mode. Keeps native interactions (text input, button clicks, link drag,\n * cell editing, selection checkboxes) working unchanged.\n */\n private static readonly INTERACTIVE_DRAG_SELECTORS =\n 'input,textarea,select,button,a,[contenteditable=\"\"],[contenteditable=\"true\"],.dg-cell-editor,.tbw-checkbox-cell';\n\n /** @internal */\n private isInteractiveDragOrigin(target: HTMLElement): boolean {\n return target.closest(RowDragDropPlugin.INTERACTIVE_DRAG_SELECTORS) !== null;\n }\n\n /**\n * Build a full-row drag image by cloning `rowEl` so the user sees the\n * actual row — not just the grip icon — while dragging.\n *\n * The clone is appended off-screen, snapshotted by the browser via\n * `setDragImage`, then removed on the next tick (after the snapshot).\n * The cursor offset is preserved relative to where the user pressed.\n */\n private attachRowCloneDragImage(de: DragEvent, rowEl: HTMLElement, handle: HTMLElement | null): void {\n if (!de.dataTransfer) return;\n const rect = rowEl.getBoundingClientRect();\n const clone = rowEl.cloneNode(true) as HTMLElement;\n clone.classList.add('tbw-row-drag-clone');\n // Strip transient classes that would look wrong in the drag image.\n clone.classList.remove('dragging', 'drop-target', 'drop-before', 'drop-after', 'flip-animating', 'row-focus');\n clone.removeAttribute('aria-selected');\n // Preserve the actual rendered width so cells don't reflow in the snapshot.\n clone.style.width = `${rect.width}px`;\n clone.style.height = `${rect.height}px`;\n // The clone MUST stay inside the grid host: every core row/cell rule is\n // scoped under `tbw-grid …` (see core/styles/*.css), and the\n // `--tbw-column-template` custom property is set on the host. If the\n // clone is moved to `document.body`, none of those rules match and the\n // drag image collapses to an empty box. Off-screen positioning via\n // `position: fixed` works the same regardless of the DOM parent.\n this.gridElement.appendChild(clone);\n // Cursor offset: where the user pressed inside the source row. Falls\n // back to the centre of the handle when initiated from the grip.\n let offsetX = de.clientX - rect.left;\n let offsetY = de.clientY - rect.top;\n if (handle) {\n const handleRect = handle.getBoundingClientRect();\n offsetX = handleRect.left - rect.left + handleRect.width / 2;\n offsetY = handleRect.top - rect.top + handleRect.height / 2;\n }\n // Clamp into the row bounds so the cursor stays inside the drag image.\n offsetX = Math.max(0, Math.min(rect.width, offsetX));\n offsetY = Math.max(0, Math.min(rect.height, offsetY));\n try {\n de.dataTransfer.setDragImage(clone, offsetX, offsetY);\n } catch {\n /* JSDOM/happy-dom: harmless */\n }\n setTimeout(() => clone.remove(), 0);\n }\n\n private onDragOver(de: DragEvent): void {\n const dt = de.dataTransfer;\n if (!dt) return;\n\n // Identify whether a tbw row drag is in progress and whether it matches our zone.\n const types = dt.types ? Array.from(dt.types) : [];\n if (!hasAnyRowDragMime(types) && !this.isDragging) return;\n\n const dropZone = this.config.dropZone ?? '';\n const session = getCurrentDragSession<T>();\n\n // For cross-grid drags we require a matching zone-tagged MIME OR the\n // session payload's dropZone must match ours.\n const isIntra = this.isDragging && session?.payload.sourceGridId === this.gridId;\n if (!isIntra) {\n if (!dropZone) return; // intra-grid only — ignore external drags\n const matchingMime = findMatchingZoneMime(types, dropZone);\n if (!matchingMime && !(session && session.payload.dropZone === dropZone)) return;\n }\n\n de.preventDefault();\n if (dt) dt.dropEffect = (session?.payload.operation ?? this.config.operation ?? 'move') as 'copy' | 'move';\n\n // Compute drop position\n const rowEl = (de.target as HTMLElement).closest('.data-grid-row') as HTMLElement | null;\n const rows = this.internalGrid._rows ?? [];\n const pos = computeDropPosition(rowEl, de.clientY, (el) => this.getRowIndex(el), rows.length);\n\n // Same-row no-op for intra-grid\n if (isIntra && pos.overIndex !== null && pos.overIndex === this.draggedRowIndex) {\n this.clearDropTargetClasses();\n return;\n }\n\n // canDrop check (same-window only — payload visible)\n if (session && this.config.canDrop) {\n const accepted = this.config.canDrop(session.payload, pos.insertIndex);\n this.gridElement.classList.toggle('tbw-grid--drop-target-active', accepted);\n this.gridElement.classList.toggle('tbw-grid--drop-target-rejected', !accepted);\n if (!accepted) {\n this.clearDropTargetClasses();\n return;\n }\n } else {\n this.gridElement.classList.add('tbw-grid--drop-target-active');\n }\n\n this.dropRowIndex = pos.insertIndex;\n this.applyDropPositionClasses(rowEl, pos.isBefore);\n\n // Auto-scroll the target viewport\n if (this.config.autoScroll !== false) {\n this.ensureAutoScroller();\n this.autoScroller?.onPointerMove(de.clientY);\n }\n }\n\n private onDragLeave(de: DragEvent): void {\n const rowEl = (de.target as HTMLElement).closest('.data-grid-row') as HTMLElement | null;\n if (rowEl) rowEl.classList.remove('drop-target', 'drop-before', 'drop-after');\n // Tear down grid-level state when the cursor leaves the grid entirely\n if (de.currentTarget && !this.gridElement.contains(de.relatedTarget as Node)) {\n this.gridElement.classList.remove('tbw-grid--drop-target-active', 'tbw-grid--drop-target-rejected');\n this.autoScroller?.stop();\n }\n }\n\n private onDrop(de: DragEvent): void {\n de.preventDefault();\n this.autoScroller?.stop();\n this.gridElement.classList.remove('tbw-grid--drop-target-active', 'tbw-grid--drop-target-rejected');\n this.clearDropTargetClasses();\n\n const dt = de.dataTransfer;\n if (!dt) return;\n\n // Resolve payload — prefer same-window session, fall back to dataTransfer JSON\n const session = getCurrentDragSession<T>();\n let payload: RowDragPayload<T> | null = session?.payload ?? null;\n let liveRows: T[] | null = null;\n\n if (payload) {\n const lookup = lookupDragSession<T>(payload.sessionId);\n if (lookup) liveRows = lookup;\n } else {\n const raw = dt.getData(TBW_ROW_DRAG_MIME);\n payload = decodePayload<T>(raw);\n if (payload) {\n const lookup = lookupDragSession<T>(payload.sessionId);\n if (lookup) liveRows = lookup;\n }\n }\n if (!payload) return;\n\n // Drop position (recompute in case dragover wasn't called for a few frames)\n const rowEl = (de.target as HTMLElement).closest('.data-grid-row') as HTMLElement | null;\n const rows = this.internalGrid._rows ?? [];\n const pos = computeDropPosition(rowEl, de.clientY, (el) => this.getRowIndex(el), rows.length);\n let targetIndex = this.dropRowIndex ?? pos.insertIndex;\n\n const isIntra = payload.sourceGridId === this.gridId;\n const dropZone = this.config.dropZone ?? '';\n\n if (isIntra) {\n // Intra-grid path — preserve `RowReorderPlugin` semantics: emit `row-move`.\n const fromIndex = payload.rowIndices[0];\n // Adjust toIndex when dropping after the dragged row (single-row only)\n if (payload.rowIndices.length === 1 && targetIndex > fromIndex) targetIndex--;\n if (fromIndex === targetIndex) return;\n const row = (liveRows ?? payload.rows)[0];\n if (!this.canMoveRow(fromIndex, targetIndex)) return;\n this.executeIntraGridMove(row, fromIndex, targetIndex, 'drag');\n return;\n }\n\n // Cross-grid path\n if (!dropZone || dropZone !== payload.dropZone) return;\n\n // canDrop final check\n if (this.config.canDrop && !this.config.canDrop(payload, targetIndex)) {\n this.gridElement.classList.add('tbw-grid--drop-target-rejected');\n setTimeout(() => this.gridElement.classList.remove('tbw-grid--drop-target-rejected'), 200);\n return;\n }\n\n // Resolve final row references — live (same-window) or deserialized JSON\n const deserialize = this.config.deserializeRow ?? ((r: unknown) => r as T);\n const incomingRows: T[] = liveRows ?? payload.rows.map((r) => deserialize(r as unknown));\n\n const dropDetail: RowDropDetail<T> = {\n payload,\n sourceGridId: payload.sourceGridId,\n targetIndex,\n operation: payload.operation,\n };\n if (this.emitCancelable('row-drop', dropDetail)) return;\n\n // Insert into target grid's _rows\n const targetRows = [...rows];\n targetRows.splice(targetIndex, 0, ...(incomingRows as unknown[]));\n this.grid.rows = targetRows;\n\n // Locate the source plugin in THIS window. If it's here we handle the\n // source-side mutation directly; if it isn't, we broadcast a message and\n // let the source-window plugin (if any) handle removal + transfer emit.\n const sourcePlugin = this.findPeerOnGrid(payload.sourceGridId);\n\n // Remove from source grid's _rows when operation === 'move' (same-window)\n if (payload.operation === 'move' && sourcePlugin) {\n const sourceGrid = document.getElementById(payload.sourceGridId) as\n | (HTMLElement & { rows?: unknown[]; _rows?: unknown[] })\n | null;\n if (sourceGrid) {\n const srcRows = (sourceGrid._rows ?? sourceGrid.rows ?? []).slice();\n // Remove from highest index down so earlier indices stay stable\n const sortedIndices = [...payload.rowIndices].sort((a, b) => b - a);\n for (const idx of sortedIndices) {\n if (idx >= 0 && idx < srcRows.length) srcRows.splice(idx, 1);\n }\n sourceGrid.rows = srcRows;\n }\n }\n\n // Mark accepted on the source plugin so dragend knows (same-window only —\n // cross-window source flips its own flag in `onRemoteTransfer`).\n if (sourcePlugin) sourcePlugin.dragAccepted = true;\n\n // Emit row-transfer on the target. The source's `row-transfer` is fired\n // either here (same-window) or by the source plugin in `onRemoteTransfer`\n // (cross-window).\n const transferDetail: RowTransferDetail<T> = {\n rows: incomingRows,\n fromGridId: payload.sourceGridId,\n toGridId: this.gridId,\n fromIndices: payload.rowIndices,\n toIndex: targetIndex,\n operation: payload.operation,\n };\n this.emit('row-transfer', transferDetail);\n\n if (sourcePlugin) {\n sourcePlugin.emitTransfer(transferDetail);\n } else {\n // Cross-window: broadcast so the source window can finish its half of\n // the transfer (row removal on `move`, `row-transfer` emit, accepted flip).\n broadcastRemoteTransfer({\n type: 'tbw-row-drag-drop:transfer',\n sessionId: payload.sessionId,\n sourceGridId: payload.sourceGridId,\n toGridId: this.gridId,\n dropZone,\n rowIndices: payload.rowIndices,\n toIndex: targetIndex,\n operation: payload.operation,\n // Re-use the payload's already-serialized rows so the source side can\n // round-trip them through `deserializeRow` for its `row-transfer` event.\n serializedRows: payload.rows as unknown[],\n });\n }\n }\n\n /**\n * Source-window handler for a remote `row-transfer` broadcast from a target\n * window. Only runs on the plugin instance whose grid id matches the message.\n * @internal\n */\n private onRemoteTransfer(msg: RemoteTransferMessage): void {\n if (msg.sourceGridId !== this.gridId) return;\n // Defensive: only act when the message zone matches our zone. This prevents\n // a stray message from a grid sharing the same id but a different zone\n // (e.g. independent demos in different tabs) from mutating our rows.\n const dropZone = this.config.dropZone ?? '';\n if (!dropZone || msg.dropZone !== dropZone) return;\n\n // Resolve incoming rows (for the `row-transfer` event payload).\n const deserialize = this.config.deserializeRow ?? ((r: unknown) => r as T);\n const incomingRows: T[] = msg.serializedRows.map((r) => deserialize(r));\n\n if (msg.operation === 'move') {\n const srcRows = (this.internalGrid._rows ?? this.sourceRows).slice();\n const sortedIndices = [...msg.rowIndices].sort((a, b) => b - a);\n for (const idx of sortedIndices) {\n if (idx >= 0 && idx < srcRows.length) srcRows.splice(idx, 1);\n }\n this.grid.rows = srcRows as unknown[];\n }\n\n // Flip accepted before dragend (best-effort — the message may arrive after\n // dragend has already fired with `accepted: false`; `row-transfer` is the\n // authoritative success signal).\n this.dragAccepted = true;\n\n this.emit('row-transfer', {\n rows: incomingRows,\n fromGridId: msg.sourceGridId,\n toGridId: msg.toGridId,\n fromIndices: msg.rowIndices,\n toIndex: msg.toIndex,\n operation: msg.operation,\n } as RowTransferDetail<T>);\n }\n\n private onDragEnd(): void {\n if (this.dragSessionId) clearDragSession(this.dragSessionId);\n clearCurrentDragSession();\n this.autoScroller?.stop();\n this.gridElement.classList.remove('tbw-grid--drag-source');\n\n if (this.isDragging) {\n const endDetail: RowDragEndDetail<T> = {\n rows: this.draggedRows,\n indices: this.draggedIndices,\n accepted: this.dragAccepted,\n };\n this.emit('row-drag-end', endDetail);\n }\n this.clearDragClasses();\n this.resetDragState();\n }\n // #endregion\n\n // #region Helpers\n\n /** Public wrapper so a peer plugin can dispatch `row-transfer` on this grid. @internal */\n emitTransfer(detail: RowTransferDetail<T>): void {\n this.emit('row-transfer', detail);\n }\n\n /** Find the peer `RowDragDropPlugin` instance on another grid by id. */\n private findPeerOnGrid(gridId: string): RowDragDropPlugin<T> | null {\n const peerEl = document.getElementById(gridId) as\n | (HTMLElement & { getPluginByName?: (name: string) => RowDragDropPlugin<T> | undefined })\n | null;\n if (!peerEl?.getPluginByName) return null;\n return peerEl.getPluginByName('rowDragDrop') ?? null;\n }\n\n private resolveDraggedRows(originIndex: number): { rows: T[]; indices: number[] } {\n const rows = this.internalGrid._rows ?? this.sourceRows;\n const originRow = rows[originIndex] as T;\n\n // If a selection plugin is loaded and the dragged row is selected, drag the whole selection.\n const selection = this.grid?.getPluginByName?.('selection') as\n | { getSelectedRowIndices?: () => number[]; getSelectedRows?: <U>() => U[] }\n | undefined;\n if (selection?.getSelectedRowIndices) {\n const selectedIndices = selection.getSelectedRowIndices();\n if (selectedIndices.includes(originIndex) && selectedIndices.length > 1) {\n const sorted = [...selectedIndices].sort((a, b) => a - b);\n return {\n rows: sorted.map((i) => rows[i] as T),\n indices: sorted,\n };\n }\n }\n return { rows: [originRow], indices: [originIndex] };\n }\n\n private ensureAutoScroller(): void {\n if (this.autoScroller) return;\n const viewport = this.gridElement.querySelector<HTMLElement>('.rows-viewport');\n if (!viewport) return;\n const opts = typeof this.config.autoScroll === 'object' ? this.config.autoScroll : undefined;\n this.autoScroller = createAutoScroller(viewport, opts, (active) => {\n this.gridElement.classList.toggle('tbw-grid--auto-scrolling', active);\n });\n }\n\n private applyDropPositionClasses(rowEl: HTMLElement | null, isBefore: boolean): void {\n this.clearDropTargetClasses();\n if (!rowEl) return;\n rowEl.classList.add('drop-target');\n rowEl.classList.toggle('drop-before', isBefore);\n rowEl.classList.toggle('drop-after', !isBefore);\n }\n\n private clearDropTargetClasses(): void {\n this.gridElement?.querySelectorAll('.data-grid-row.drop-target').forEach((row) => {\n row.classList.remove('drop-target', 'drop-before', 'drop-after');\n });\n }\n\n private clearDragClasses(): void {\n this.gridElement?.querySelectorAll('.data-grid-row').forEach((row) => {\n row.classList.remove(GridClasses.DRAGGING, 'drop-target', 'drop-before', 'drop-after');\n });\n }\n\n private resetDragState(): void {\n this.isDragging = false;\n this.draggedRowIndex = null;\n this.draggedRows = [];\n this.draggedIndices = [];\n this.dragSessionId = null;\n this.dragAccepted = false;\n this.dropRowIndex = null;\n this.pendingMove = null;\n }\n\n private getRowIndex(rowEl: HTMLElement): number {\n const cell = rowEl.querySelector('.cell[data-row]');\n return cell ? parseInt(cell.getAttribute('data-row') ?? '-1', 10) : -1;\n }\n\n private clearDebounceTimer(): void {\n if (this.debounceTimer) {\n clearTimeout(this.debounceTimer);\n this.debounceTimer = null;\n }\n }\n\n // #endregion\n\n // #region Intra-Grid Move (parity with RowReorderPlugin)\n\n private handleKeyboardMove(row: T, fromIndex: number, toIndex: number, focusCol: number): void {\n if (!this.pendingMove) {\n this.pendingMove = { originalIndex: fromIndex, currentIndex: toIndex, row };\n } else {\n this.pendingMove.currentIndex = toIndex;\n }\n this.lastFocusCol = focusCol;\n\n const grid = this.internalGrid;\n const rows = [...(grid._rows ?? this.sourceRows)];\n const [movedRow] = rows.splice(fromIndex, 1);\n rows.splice(toIndex, 0, movedRow);\n\n grid._rows = rows;\n grid._focusRow = toIndex;\n grid._focusCol = focusCol;\n grid.refreshVirtualWindow(true);\n ensureCellVisible(grid);\n\n this.clearDebounceTimer();\n this.debounceTimer = setTimeout(() => this.flushPendingMove(), this.config.debounceMs ?? 300);\n }\n\n private flushPendingMove(): void {\n this.clearDebounceTimer();\n if (!this.pendingMove) return;\n const { originalIndex, currentIndex, row: movedRow } = this.pendingMove;\n this.pendingMove = null;\n if (originalIndex === currentIndex) return;\n\n const grid = this.internalGrid;\n // `grid._rows` already reflects the post-move order (mutated incrementally\n // by `handleKeyboardMove`); report it as `detail.rows` so consumers see\n // the actual reordered array, not the original `sourceRows` snapshot.\n const postMoveRows = (grid._rows ?? this.sourceRows) as T[];\n const detail: RowMoveDetail<T> = {\n row: movedRow as T,\n fromIndex: originalIndex,\n toIndex: currentIndex,\n rows: [...postMoveRows],\n source: 'keyboard',\n };\n const cancelled = this.emitCancelable('row-move', detail);\n if (cancelled) {\n // Revert: restore the original snapshot. `sourceRows` was never mutated\n // during the pending move (only `grid._rows` was), so resetting from it\n // is the correct rollback regardless of how many incremental keyboard\n // moves accumulated.\n grid._rows = [...this.sourceRows];\n grid._focusRow = originalIndex;\n grid._focusCol = this.lastFocusCol;\n grid.refreshVirtualWindow(true);\n ensureCellVisible(grid);\n }\n }\n\n private executeIntraGridMove(row: unknown, fromIndex: number, toIndex: number, source: 'keyboard' | 'drag'): void {\n const rows = [...this.sourceRows];\n const [movedRow] = rows.splice(fromIndex, 1);\n rows.splice(toIndex, 0, movedRow);\n const detail: RowMoveDetail<T> = {\n row: row as T,\n fromIndex,\n toIndex,\n rows: rows as T[],\n source,\n };\n const cancelled = this.emitCancelable('row-move', detail);\n if (cancelled) return;\n if (this.animationType === 'flip' && this.gridElement) {\n const oldPositions = this.captureRowPositions();\n this.grid.rows = rows;\n requestAnimationFrame(() => {\n void this.gridElement.offsetHeight;\n this.animateFLIP(oldPositions, fromIndex, toIndex);\n });\n } else {\n this.grid.rows = rows;\n }\n }\n\n private captureRowPositions(): Map<number, number> {\n const positions = new Map<number, number>();\n this.gridElement?.querySelectorAll('.data-grid-row').forEach((row) => {\n const rowIndex = this.getRowIndex(row as HTMLElement);\n if (rowIndex >= 0) positions.set(rowIndex, row.getBoundingClientRect().top);\n });\n return positions;\n }\n\n private animateFLIP(oldPositions: Map<number, number>, fromIndex: number, toIndex: number): void {\n const gridEl = this.gridElement;\n if (!gridEl || oldPositions.size === 0) return;\n\n const minIndex = Math.min(fromIndex, toIndex);\n const maxIndex = Math.max(fromIndex, toIndex);\n const rowsToAnimate: { el: HTMLElement; deltaY: number }[] = [];\n\n gridEl.querySelectorAll('.data-grid-row').forEach((row) => {\n const rowEl = row as HTMLElement;\n const newRowIndex = this.getRowIndex(rowEl);\n if (newRowIndex < 0 || newRowIndex < minIndex || newRowIndex > maxIndex) return;\n let oldIndex: number;\n if (newRowIndex === toIndex) oldIndex = fromIndex;\n else if (fromIndex < toIndex) oldIndex = newRowIndex + 1;\n else oldIndex = newRowIndex - 1;\n const oldTop = oldPositions.get(oldIndex);\n if (oldTop === undefined) return;\n const newTop = rowEl.getBoundingClientRect().top;\n const deltaY = oldTop - newTop;\n if (Math.abs(deltaY) > 1) rowsToAnimate.push({ el: rowEl, deltaY });\n });\n\n if (rowsToAnimate.length === 0) return;\n\n rowsToAnimate.forEach(({ el, deltaY }) => {\n el.style.transform = `translateY(${deltaY}px)`;\n });\n void gridEl.offsetHeight;\n\n const duration = this.animationDuration;\n requestAnimationFrame(() => {\n rowsToAnimate.forEach(({ el }) => {\n el.classList.add('flip-animating');\n el.style.transform = '';\n });\n setTimeout(() => {\n rowsToAnimate.forEach(({ el }) => {\n el.style.transform = '';\n el.classList.remove('flip-animating');\n });\n }, duration + 50);\n });\n }\n\n // #endregion\n}\n"],"names":["currentSession","getCurrentDragSession","clearCurrentDragSession","TBW_ROW_DRAG_MIME","parseZoneFromMime","mime","match","decodeURIComponent","encodePayload","payload","JSON","stringify","computeDropPosition","rowEl","clientY","rowIndexResolver","totalRows","overIndex","insertIndex","isBefore","targetIndex","rect","getBoundingClientRect","top","height","sharedChannel","remoteListeners","Set","ensureCrossWindowChannel","BroadcastChannel","addEventListener","event","data","type","listener","Array","from","RowDragDropPlugin","BaseGridPlugin","name","aliases","styles","static","events","description","cancelable","defaultConfig","enableKeyboard","dragHandlePosition","dragHandleWidth","debounceMs","animation","operation","autoScroll","dragFrom","shouldRenderDragHandle","explicit","this","config","showDragHandle","rowIsDraggable","animationType","isAnimationEnabled","isDragging","draggedRowIndex","draggedRows","draggedIndices","dragSessionId","dragAccepted","dropRowIndex","pendingMove","debounceTimer","lastFocusCol","autoScroller","gridId","remoteTransferListener","msg","onRemoteTransfer","internalGrid","grid","attach","super","host","gridElement","id","newDragSessionId","slice","setupDelegatedDragListeners","add","detach","clearDebounceTimer","stop","delete","size","close","unregisterRemoteTransferListener","clearDragSession","resetDragState","processColumns","columns","dragHandleColumn","field","header","width","resizable","sortable","filterable","lockPosition","utility","viewRenderer","container","document","createElement","className","setAttribute","draggable","setIcon","afterRender","applyRowDraggable","onScrollRender","body","_bodyEl","wantDraggable","rows","querySelectorAll","row","getAttribute","hasAttribute","removeAttribute","onKeyDown","ctrlKey","key","focusRow","_focusRow","_rows","sourceRows","length","toIndex","canMoveRow","handleKeyboardMove","_focusCol","preventDefault","stopPropagation","onCellClick","flushPendingMove","moveRow","fromIndex","executeIntraGridMove","queryResults","query","isArray","includes","canDrag","canMove","direction","canDrop","sessionId","sourceGridId","dropZone","rowIndices","gridEl","signal","disconnectSignal","e","onDragStart","onDragEnd","onDragOver","onDragLeave","onDrop","de","target","handle","closest","initiatedFromHandle","isInteractiveDragOrigin","rowIndex","getRowIndex","indices","resolveDraggedRows","startDetail","emitCancelable","serialize","serializeRow","r","map","dataTransfer","effectAllowed","setData","encodeURIComponent","dataColumns","filter","c","lines","cells","col","value","String","replace","push","join","formatRowsAsTSV","badge","textContent","appendChild","setDragImage","setTimeout","remove","attachRowCloneDragImage","registerDragSession","setCurrentDragSession","classList","GridClasses","DRAGGING","INTERACTIVE_DRAG_SELECTORS","clone","cloneNode","style","offsetX","clientX","left","offsetY","handleRect","Math","max","min","dt","types","t","startsWith","hasAnyRowDragMime","session","isIntra","matchingMime","zone","findMatchingZoneMime","dropEffect","pos","el","clearDropTargetClasses","accepted","toggle","applyDropPositionClasses","ensureAutoScroller","onPointerMove","currentTarget","contains","relatedTarget","liveRows","lookup","lookupDragSession","raw","parsed","parse","idx","Number","isInteger","decodePayload","getData","deserialize","deserializeRow","incomingRows","dropDetail","targetRows","splice","sourcePlugin","findPeerOnGrid","sourceGrid","getElementById","srcRows","sortedIndices","sort","a","b","transferDetail","fromGridId","toGridId","fromIndices","emit","emitTransfer","channel","postMessage","broadcastRemoteTransfer","serializedRows","endDetail","clearDragClasses","detail","peerEl","getPluginByName","originIndex","originRow","selection","getSelectedRowIndices","selectedIndices","sorted","i","viewport","querySelector","opts","options","onScrollChange","edgeSize","baseSpeed","speed","maxSpeed","rafId","pointerY","active","setActive","next","tick","delta","ratio","round","bottom","before","scrollTop","requestAnimationFrame","cancelAnimationFrame","isScrolling","createAutoScroller","forEach","cell","parseInt","clearTimeout","focusCol","currentIndex","originalIndex","movedRow","refreshVirtualWindow","ensureCellVisible","source","oldPositions","captureRowPositions","offsetHeight","animateFLIP","positions","Map","set","minIndex","maxIndex","rowsToAnimate","newRowIndex","oldIndex","oldTop","get","deltaY","abs","transform","duration","animationDuration"],"mappings":"klBA8BA,IAAIA,EAAiF,KAQ9E,SAASC,IACd,OAAOD,CACT,CAGO,SAASE,IACdF,EAAiB,IACnB,CAOO,MAAMG,EAAoB,mCAQ1B,SAASC,EAAkBC,GAChC,MAAMC,EAAQD,EAAKC,MAAM,kDACzB,IAAKA,EAAO,OAAO,KACnB,IACE,OAAOC,mBAAmBD,EAAM,GAClC,CAAA,MACE,OAAOA,EAAM,EACf,CACF,CA8CO,SAASE,EAAiBC,GAC/B,OAAOC,KAAKC,UAAUF,EACxB,CAmDO,SAASG,EACdC,EACAC,EACAC,EACAC,GAEA,IAAKH,EACH,MAAO,CAAEI,UAAW,KAAMC,YAAaF,EAAWG,UAAU,G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GAAgC,IAAtB2K,EAAa9O,KAAY,OAExC,MAAMqP,EAAWpH,KAAKE,IAAI9E,EAAWT,GAC/B0M,EAAWrH,KAAKC,IAAI7E,EAAWT,GAC/B2M,EAAuD,GAiB7D,GAfApL,EAAOpC,iBAAiB,kBAAkBoM,QAASnM,IACjD,MAAMhH,EAAQgH,EACRwN,EAAc5R,KAAKuH,YAAYnK,GACrC,GAAIwU,EAAc,GAAKA,EAAcH,GAAYG,EAAcF,EAAU,OACzE,IAAIG,EACyBA,EAAzBD,IAAgB5M,EAAoBS,EAC/BA,EAAYT,EAAoB4M,EAAc,EACvCA,EAAc,EAC9B,MAAME,EAASZ,EAAaa,IAAIF,GAChC,QAAe,IAAXC,EAAsB,OAC1B,MACME,EAASF,EADA1U,EAAMS,wBAAwBC,IAEzCuM,KAAK4H,IAAID,GAAU,GAAGL,EAAc9I,KAAK,CAAEuC,GAAIhO,EAAO4U,aAG/B,IAAzBL,EAAc5M,OAAc,OAEhC4M,EAAcpB,QAAQ,EAAGnF,KAAI4G,aAC3B5G,EAAGrB,MAAMmI,UAAY,cAAcF,SAEhCzL,EAAO6K,aAEZ,MAAMe,EAAWnS,KAAKoS,kBACtBjC,sBAAsB,KACpBwB,EAAcpB,QAAQ,EAAGnF,SACvBA,EAAG3B,UAAU1H,IAAI,kBACjBqJ,EAAGrB,MAAMmI,UAAY,KAEvB9I,WAAW,KACTuI,EAAcpB,QAAQ,EAAGnF,SACvBA,EAAGrB,MAAMmI,UAAY,GACrB9G,EAAG3B,UAAUJ,OAAO,qBAErB8I,EAAW,KAElB"}
1
+ {"version":3,"file":"reorder-rows.umd.js","sources":["../../../../../libs/grid/src/lib/plugins/shared/drag-drop-protocol.ts","../../../../../libs/grid/src/lib/plugins/row-drag-drop/RowDragDropPlugin.ts"],"sourcesContent":["/**\n * Drag-Drop Protocol — shared utilities for cross-grid row drag-and-drop.\n *\n * Used by `RowDragDropPlugin` (and any future plugin that participates in the\n * tbw row-drag protocol). Centralises:\n *\n * - MIME type constants and zone tagging (visible in `dataTransfer.types`)\n * - Payload codec for cross-window / cross-iframe transfers\n * - Drop-position math (midpoint algorithm)\n * - Auto-scroll engine (rAF loop, edge detection, boundary clamp)\n * - Plain-text TSV fallback for drags out to Notepad / Excel / Slack\n *\n * @internal Plugin shared utility (not part of the public API).\n */\n\nimport type { ColumnConfig } from '../../core/types';\n\n// ---------------------------------------------------------------------------\n// Same-window current-session tracker\n// ---------------------------------------------------------------------------\n\n/**\n * Module-level \"active drag session\" — set on dragstart by the source grid,\n * cleared on dragend. Lets target grids read the full payload synchronously\n * during `dragover` (browsers hide `dataTransfer.getData()` during dragover\n * for security). Cross-window drags don't have access to this module and\n * fall back to a generic accept-check followed by a drop-time canDrop call.\n *\n * @internal\n */\nlet currentSession: { sessionId: string; payload: RowDragPayload<unknown> } | null = null;\n\n/** @internal */\nexport function setCurrentDragSession<T>(sessionId: string, payload: RowDragPayload<T>): void {\n currentSession = { sessionId, payload: payload as RowDragPayload<unknown> };\n}\n\n/** @internal */\nexport function getCurrentDragSession<T = unknown>(): { sessionId: string; payload: RowDragPayload<T> } | null {\n return currentSession as { sessionId: string; payload: RowDragPayload<T> } | null;\n}\n\n/** @internal */\nexport function clearCurrentDragSession(): void {\n currentSession = null;\n}\n\n// ---------------------------------------------------------------------------\n// MIME types\n// ---------------------------------------------------------------------------\n\n/** Base MIME type carried on `dataTransfer` for tbw row drags. */\nexport const TBW_ROW_DRAG_MIME = 'application/x-tbw-grid-rows+json';\n\n/** Build a zone-tagged MIME type, visible in `dataTransfer.types` during dragover. */\nexport function mimeForZone(zone: string): string {\n return `${TBW_ROW_DRAG_MIME};zone=${encodeURIComponent(zone)}`;\n}\n\n/** Extract the zone from a tagged MIME, or `null` if untagged. */\nexport function parseZoneFromMime(mime: string): string | null {\n const match = mime.match(/^application\\/x-tbw-grid-rows\\+json;zone=(.*)$/);\n if (!match) return null;\n try {\n return decodeURIComponent(match[1]);\n } catch {\n return match[1];\n }\n}\n\n/**\n * Find the first MIME entry in `types` whose zone matches `zone`.\n * Used during `dragover` for the accept-check (browsers hide `getData()`\n * during dragover, but `types` is always visible).\n */\nexport function findMatchingZoneMime(types: readonly string[], zone: string): string | null {\n for (const t of types) {\n if (parseZoneFromMime(t) === zone) return t;\n }\n return null;\n}\n\n/** Returns true if any tbw row-drag MIME is present in `types`. */\nexport function hasAnyRowDragMime(types: readonly string[]): boolean {\n for (const t of types) {\n if (t === TBW_ROW_DRAG_MIME || t.startsWith(`${TBW_ROW_DRAG_MIME};`)) return true;\n }\n return false;\n}\n\n// ---------------------------------------------------------------------------\n// Payload\n// ---------------------------------------------------------------------------\n\n/**\n * Cross-grid drag payload, carried on `dataTransfer` and (for same-window\n * recovery) keyed in the WeakRef registry by `sessionId`.\n */\nexport interface RowDragPayload<T = unknown> {\n /** Drag session id (matches the WeakRef registry key). */\n sessionId: string;\n /** Source grid id (`grid.id` or auto-generated UUID). */\n sourceGridId: string;\n /** Drop zone the source grid is participating in. */\n dropZone: string;\n /** Serialized row payload (JSON-safe). For same-window drops, recovered live via the registry. */\n rows: T[];\n /** Original indices in the source grid's `_rows` array. */\n rowIndices: number[];\n /** Move (default) removes from source; copy leaves source intact. */\n operation: 'move' | 'copy';\n}\n\n/** Encode a payload to the JSON string written to `dataTransfer`. */\nexport function encodePayload<T>(payload: RowDragPayload<T>): string {\n return JSON.stringify(payload);\n}\n\n/** Decode a payload from the JSON string read off `dataTransfer`. */\nexport function decodePayload<T = unknown>(raw: string): RowDragPayload<T> | null {\n if (!raw) return null;\n try {\n const parsed = JSON.parse(raw) as RowDragPayload<T>;\n if (\n typeof parsed?.sessionId !== 'string' ||\n typeof parsed?.sourceGridId !== 'string' ||\n typeof parsed?.dropZone !== 'string' ||\n !Array.isArray(parsed?.rows) ||\n !Array.isArray(parsed?.rowIndices) ||\n (parsed.operation !== 'move' && parsed.operation !== 'copy')\n ) {\n return null;\n }\n // `rowIndices` is later used for sorting and splicing — reject anything\n // that isn't a finite, non-negative integer to avoid JS coercion bugs\n // (NaN ordering, float splice indices, string concatenation, etc.).\n for (const idx of parsed.rowIndices) {\n if (typeof idx !== 'number' || !Number.isInteger(idx) || idx < 0) return null;\n }\n return parsed;\n } catch {\n return null;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Drop position math\n// ---------------------------------------------------------------------------\n\nexport interface DropPosition {\n /** Target visual row index that the cursor is over, or `null` for empty area. */\n overIndex: number | null;\n /** Final insertion index in the target grid's `_rows`. */\n insertIndex: number;\n /** True when the cursor is above the row midpoint. */\n isBefore: boolean;\n}\n\n/**\n * Compute the insertion index for a drop, given the row element under the\n * cursor (if any), the cursor's clientY, and the total row count when the\n * cursor is in empty space below the last row.\n *\n * - Cursor above row midpoint → insert at `targetIndex`\n * - Cursor below row midpoint → insert at `targetIndex + 1`\n * - Cursor over empty area below the last row → append (`insertIndex = totalRows`)\n */\nexport function computeDropPosition(\n rowEl: HTMLElement | null,\n clientY: number,\n rowIndexResolver: (el: HTMLElement) => number,\n totalRows: number,\n): DropPosition {\n if (!rowEl) {\n return { overIndex: null, insertIndex: totalRows, isBefore: false };\n }\n const targetIndex = rowIndexResolver(rowEl);\n if (targetIndex < 0) {\n return { overIndex: null, insertIndex: totalRows, isBefore: false };\n }\n const rect = rowEl.getBoundingClientRect();\n const midY = rect.top + rect.height / 2;\n const isBefore = clientY < midY;\n return {\n overIndex: targetIndex,\n insertIndex: isBefore ? targetIndex : targetIndex + 1,\n isBefore,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Auto-scroll engine\n// ---------------------------------------------------------------------------\n\nexport interface AutoScrollOptions {\n /** Pixels from the top/bottom edge that activate auto-scroll. */\n edgeSize?: number;\n /** Base scroll speed in pixels-per-frame near the edge. */\n speed?: number;\n /** Max speed at the very edge (linear ramp from `speed` → `maxSpeed`). */\n maxSpeed?: number;\n}\n\nexport interface AutoScroller {\n /** Update pointer position; starts the rAF loop if needed. */\n onPointerMove(clientY: number): void;\n /** Stop the rAF loop and reset state. */\n stop(): void;\n /** True when actively auto-scrolling. */\n readonly isScrolling: boolean;\n}\n\n/**\n * Create an auto-scroller for a viewport element.\n *\n * The scroller runs a `requestAnimationFrame` loop only while the pointer is\n * within `edgeSize` of the viewport's top or bottom and there is room to\n * scroll. Speed ramps linearly from `speed` (at the edge boundary) to\n * `maxSpeed` (at the very edge).\n */\nexport function createAutoScroller(\n viewport: HTMLElement,\n options: AutoScrollOptions = {},\n onScrollChange?: (active: boolean) => void,\n): AutoScroller {\n const edgeSize = options.edgeSize ?? 60;\n const baseSpeed = options.speed ?? 8;\n const maxSpeed = options.maxSpeed ?? 24;\n\n let rafId: number | null = null;\n let pointerY: number | null = null;\n let active = false;\n\n const setActive = (next: boolean): void => {\n if (next === active) return;\n active = next;\n onScrollChange?.(next);\n };\n\n const tick = (): void => {\n rafId = null;\n if (pointerY === null) {\n setActive(false);\n return;\n }\n const rect = viewport.getBoundingClientRect();\n let delta = 0;\n\n if (pointerY < rect.top + edgeSize) {\n const distance = Math.max(0, pointerY - rect.top);\n const ratio = 1 - distance / edgeSize;\n delta = -Math.round(baseSpeed + (maxSpeed - baseSpeed) * ratio);\n } else if (pointerY > rect.bottom - edgeSize) {\n const distance = Math.max(0, rect.bottom - pointerY);\n const ratio = 1 - distance / edgeSize;\n delta = Math.round(baseSpeed + (maxSpeed - baseSpeed) * ratio);\n }\n\n if (delta === 0) {\n setActive(false);\n return;\n }\n\n const before = viewport.scrollTop;\n viewport.scrollTop = before + delta;\n\n // Stop if we hit a boundary (no movement happened)\n if (viewport.scrollTop === before) {\n setActive(false);\n return;\n }\n\n setActive(true);\n rafId = requestAnimationFrame(tick);\n };\n\n return {\n onPointerMove(clientY: number): void {\n pointerY = clientY;\n if (rafId === null) {\n rafId = requestAnimationFrame(tick);\n }\n },\n stop(): void {\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n rafId = null;\n }\n pointerY = null;\n setActive(false);\n },\n get isScrolling(): boolean {\n return active;\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// TSV fallback\n// ---------------------------------------------------------------------------\n\n/**\n * Format rows as a TSV string for the `text/plain` drag fallback.\n * Used when the drop target is an external app (Excel, Notepad, Slack).\n *\n * - One row per line, fields separated by `\\t`.\n * - Tabs and newlines in cell values are replaced with spaces.\n * - Skips columns flagged as `utility` (drag handle, checkbox, etc.).\n */\nexport function formatRowsAsTSV<T extends Record<string, unknown>>(\n rows: readonly T[],\n columns: readonly ColumnConfig[],\n): string {\n const dataColumns = columns.filter(\n (c) => !(c as { utility?: boolean }).utility && typeof c.field === 'string' && c.field !== '',\n );\n const lines: string[] = [];\n for (const row of rows) {\n const cells = dataColumns.map((col) => {\n const value = row[col.field];\n if (value === null || value === undefined) return '';\n const str = String(value);\n return str.replace(/[\\t\\r\\n]+/g, ' ');\n });\n lines.push(cells.join('\\t'));\n }\n return lines.join('\\n');\n}\n","/**\n * Row Drag-Drop Plugin\n *\n * Drag rows within a single grid (parity with the deprecated\n * `RowReorderPlugin`) **and** between grids that share a `dropZone`.\n *\n * Architecture overview is documented in the issue body and in\n * `.github/knowledge/grid-plugins.md`. Key invariants:\n *\n * - Mutations write to `grid._rows`; the user's input `sourceRows` array is\n * never mutated on either side. Persistence is consumer-driven via the\n * `row-move` (intra-grid) and `row-transfer` (cross-grid) events.\n * - Same-window cross-grid drops use the WeakRef registry in\n * `core/internal/drag-drop-registry` to recover live row references.\n * Cross-window drops fall back to `JSON.parse(JSON.stringify(row))` (or the\n * `serializeRow`/`deserializeRow` hooks for non-JSON values).\n * - `RowReorderPlugin` is an alias re-export of this class. The PluginManager\n * alias-collapse pre-pass merges configs when both names are instantiated.\n *\n * @see {@link RowDragDropConfig} for all configuration options.\n */\n\nimport { GridClasses } from '../../core/constants';\nimport {\n clearDragSession,\n lookupDragSession,\n newDragSessionId,\n registerDragSession,\n} from '../../core/internal/drag-drop-registry';\nimport { ensureCellVisible } from '../../core/internal/keyboard';\nimport { BaseGridPlugin, type GridElement, type PluginManifest } from '../../core/plugin/base-plugin';\nimport type { ColumnConfig, GridHost } from '../../core/types';\nimport {\n type AutoScroller,\n type RowDragPayload,\n TBW_ROW_DRAG_MIME,\n clearCurrentDragSession,\n computeDropPosition,\n createAutoScroller,\n decodePayload,\n encodePayload,\n findMatchingZoneMime,\n formatRowsAsTSV,\n getCurrentDragSession,\n hasAnyRowDragMime,\n mimeForZone,\n setCurrentDragSession,\n} from '../shared/drag-drop-protocol';\nimport styles from './row-drag-drop.css?inline';\nimport type {\n PendingMove,\n RowDragDropConfig,\n RowDragEndDetail,\n RowDragStartDetail,\n RowDropDetail,\n RowMoveDetail,\n RowTransferDetail,\n} from './types';\n\n/** Field name for the drag handle column. * @since 2.4.0\n */\nexport const ROW_DRAG_HANDLE_FIELD = '__tbw_row_drag';\n\n// ---------------------------------------------------------------------------\n// Cross-window coordination via BroadcastChannel\n// ---------------------------------------------------------------------------\n//\n// Same-window cross-grid drops can locate the source grid and its plugin via\n// `document.getElementById(sourceGridId)` — the target plugin handles both\n// sides of the transfer in `onDrop` (insert into target + remove from source\n// + emit `row-transfer` on both grids).\n//\n// Cross-window drops can't reach the source DOM that way. The target window\n// broadcasts a `tbw-row-drag-drop:transfer` message; each window has a single\n// channel and fans the message out to every attached plugin instance, which\n// matches on `sourceGridId === this.gridId` and runs the source-side path\n// (row removal on `move`, `row-transfer` emit, `dragAccepted` flip).\n//\n// The channel is created lazily on the first plugin that needs it and shared\n// across all instances in the window. It's torn down when the last instance\n// detaches so we don't leak a handle in environments where the plugin is\n// repeatedly attached/detached.\n\n/** @internal */\ninterface RemoteTransferMessage {\n type: 'tbw-row-drag-drop:transfer';\n sessionId: string;\n sourceGridId: string;\n toGridId: string;\n dropZone: string;\n rowIndices: number[];\n toIndex: number;\n operation: 'move' | 'copy';\n /** Pre-serialized rows (the same shape `serializeRow` produced on dragstart). */\n serializedRows: unknown[];\n}\n\ntype RemoteTransferListener = (msg: RemoteTransferMessage) => void;\n\nconst CROSS_WINDOW_CHANNEL_NAME = 'tbw-row-drag-drop';\nlet sharedChannel: BroadcastChannel | null = null;\nconst remoteListeners = new Set<RemoteTransferListener>();\n\nfunction ensureCrossWindowChannel(): BroadcastChannel | null {\n if (typeof BroadcastChannel === 'undefined') return null;\n if (sharedChannel) return sharedChannel;\n try {\n sharedChannel = new BroadcastChannel(CROSS_WINDOW_CHANNEL_NAME);\n sharedChannel.addEventListener('message', (event: MessageEvent) => {\n const data = event.data as RemoteTransferMessage | undefined;\n if (!data || data.type !== 'tbw-row-drag-drop:transfer') return;\n // Snapshot to tolerate listeners that detach during dispatch.\n for (const listener of Array.from(remoteListeners)) {\n try {\n listener(data);\n } catch {\n /* listener errors must not break sibling listeners */\n }\n }\n });\n } catch {\n sharedChannel = null;\n }\n return sharedChannel;\n}\n\nfunction registerRemoteTransferListener(listener: RemoteTransferListener): void {\n remoteListeners.add(listener);\n ensureCrossWindowChannel();\n}\n\nfunction unregisterRemoteTransferListener(listener: RemoteTransferListener): void {\n remoteListeners.delete(listener);\n if (remoteListeners.size === 0 && sharedChannel) {\n try {\n sharedChannel.close();\n } catch {\n /* noop */\n }\n sharedChannel = null;\n }\n}\n\nfunction broadcastRemoteTransfer(msg: RemoteTransferMessage): void {\n const channel = ensureCrossWindowChannel();\n if (!channel) return;\n try {\n channel.postMessage(msg);\n } catch {\n /* postMessage may throw on uncloneable payloads — acceptable; user can\n * supply `serializeRow` to provide a structured-cloneable shape. */\n }\n}\n\n/**\n * Row Drag-Drop Plugin for `<tbw-grid>`.\n *\n * @example Intra-grid (parity with deprecated RowReorderPlugin)\n * ```ts\n * import { RowDragDropPlugin } from '@toolbox-web/grid/plugins/row-drag-drop';\n *\n * grid.gridConfig = {\n * plugins: [new RowDragDropPlugin()],\n * };\n * ```\n *\n * @example Cross-grid transfer list\n * ```ts\n * gridA.gridConfig = { plugins: [new RowDragDropPlugin({ dropZone: 'tasks' })] };\n * gridB.gridConfig = { plugins: [new RowDragDropPlugin({ dropZone: 'tasks' })] };\n *\n * gridA.addEventListener('row-transfer', (e) => persist(e.detail));\n * gridB.addEventListener('row-transfer', (e) => persist(e.detail));\n * ```\n *\n * @category Plugin\n */\nexport class RowDragDropPlugin<T = unknown> extends BaseGridPlugin<RowDragDropConfig<T>> {\n /** @internal */\n readonly name = 'rowDragDrop';\n\n /**\n * Backwards-compatible aliases. `RowReorderPlugin`'s legacy plugin name\n * (`reorderRows`) and short alias (`rowReorder`) both resolve here so that\n * `getPluginByName('reorderRows')` keeps working.\n * @internal\n */\n override readonly aliases = ['reorderRows', 'rowReorder'] as const;\n\n /** @internal */\n override readonly styles = styles;\n\n /** @internal */\n static override readonly manifest: PluginManifest<RowDragDropConfig> = {\n events: [\n { type: 'row-move', description: 'Intra-grid row reorder.', cancelable: true },\n { type: 'row-drag-start', description: 'Cross-grid drag started on this grid.', cancelable: true },\n { type: 'row-drag-end', description: 'Drag finished on this grid (regardless of outcome).' },\n { type: 'row-drop', description: 'Cross-grid drop landing on this grid.', cancelable: true },\n { type: 'row-transfer', description: 'Cross-grid transfer completed (fires on both grids).' },\n ],\n };\n\n /** @internal */\n protected override get defaultConfig(): Partial<RowDragDropConfig<T>> {\n return {\n enableKeyboard: true,\n // `showDragHandle` default depends on `dragFrom` — resolved by\n // `shouldRenderDragHandle()` rather than here so a single `dragFrom`\n // change reshapes both at once.\n dragHandlePosition: 'left',\n dragHandleWidth: 40,\n debounceMs: 150,\n animation: 'flip',\n operation: 'move',\n autoScroll: true,\n dragFrom: 'handle',\n };\n }\n\n /**\n * Resolve whether the grip column should be rendered. The handle is shown\n * unless the user explicitly set `showDragHandle: false`, OR `dragFrom`\n * is `'row'` and `showDragHandle` was not explicitly set to `true`.\n */\n private shouldRenderDragHandle(): boolean {\n const explicit = this.config.showDragHandle;\n if (explicit === false) return false;\n if (explicit === true) return true;\n return this.config.dragFrom !== 'row';\n }\n\n /** Whether the row element itself should accept native HTML5 drag. */\n private get rowIsDraggable(): boolean {\n return this.config.dragFrom === 'row' || this.config.dragFrom === 'both';\n }\n\n /** Resolve animation type from plugin config (respects grid-level reduced-motion). */\n private get animationType(): false | 'flip' {\n if (!this.isAnimationEnabled) return false;\n if (this.config.animation !== undefined) return this.config.animation;\n return 'flip';\n }\n\n // #region Internal State\n private isDragging = false;\n private draggedRowIndex: number | null = null;\n private draggedRows: T[] = [];\n private draggedIndices: number[] = [];\n private dragSessionId: string | null = null;\n private dragAccepted = false;\n private dropRowIndex: number | null = null;\n private pendingMove: PendingMove | null = null;\n private debounceTimer: ReturnType<typeof setTimeout> | null = null;\n private lastFocusCol = 0;\n private autoScroller: AutoScroller | null = null;\n /** Stable id for this grid instance (used as `sourceGridId` in payloads). */\n private gridId = '';\n\n /** Bound listener so we can register/unregister the same reference. */\n private readonly remoteTransferListener: RemoteTransferListener = (msg) => this.onRemoteTransfer(msg);\n\n /** Typed internal grid accessor. */\n private get internalGrid(): GridHost {\n return this.grid as unknown as GridHost;\n }\n // #endregion\n\n // #region Lifecycle\n /** @internal */\n override attach(grid: GridElement): void {\n super.attach(grid);\n const host = this.gridElement;\n if (host) {\n this.gridId = host.id || `tbw-grid-${newDragSessionId().slice(0, 8)}`;\n if (!host.id) host.id = this.gridId;\n this.setupDelegatedDragListeners();\n registerRemoteTransferListener(this.remoteTransferListener);\n }\n }\n\n /** @internal */\n override detach(): void {\n this.clearDebounceTimer();\n this.autoScroller?.stop();\n this.autoScroller = null;\n unregisterRemoteTransferListener(this.remoteTransferListener);\n if (this.dragSessionId) clearDragSession(this.dragSessionId);\n clearCurrentDragSession();\n this.resetDragState();\n super.detach();\n }\n // #endregion\n\n // #region Hooks\n\n /** @internal */\n override processColumns(columns: readonly ColumnConfig[]): ColumnConfig[] {\n if (!this.shouldRenderDragHandle()) return [...columns];\n\n const dragHandleColumn: ColumnConfig = {\n field: ROW_DRAG_HANDLE_FIELD,\n header: '',\n width: this.config.dragHandleWidth ?? 40,\n resizable: false,\n sortable: false,\n filterable: false,\n lockPosition: true,\n utility: true,\n viewRenderer: () => {\n const container = document.createElement('div');\n container.className = 'dg-row-drag-handle';\n container.setAttribute('aria-label', 'Drag to reorder');\n container.setAttribute('role', 'button');\n container.setAttribute('tabindex', '-1');\n container.draggable = true;\n this.setIcon(container, 'dragHandle');\n return container;\n },\n };\n\n return this.config.dragHandlePosition === 'right' ? [...columns, dragHandleColumn] : [dragHandleColumn, ...columns];\n }\n\n /** @internal */\n override afterRender(): void {\n this.applyRowDraggable();\n }\n\n /** @internal */\n override onScrollRender(): void {\n // Virtualization recycles row DOM elements during scroll; re-apply the\n // `draggable` attribute so newly-shown rows still accept HTML5 drag.\n this.applyRowDraggable();\n }\n\n /**\n * Set or clear the `draggable` attribute on every visible row, depending on\n * `config.dragFrom`. Idempotent and cheap (one attribute write per row).\n */\n private applyRowDraggable(): void {\n const body = this.internalGrid._bodyEl;\n if (!body) return;\n const wantDraggable = this.rowIsDraggable;\n const rows = body.querySelectorAll<HTMLElement>('.data-grid-row');\n for (const row of rows) {\n if (wantDraggable) {\n if (row.getAttribute('draggable') !== 'true') row.setAttribute('draggable', 'true');\n } else if (row.hasAttribute('draggable')) {\n row.removeAttribute('draggable');\n }\n }\n }\n\n /** @internal */\n override onKeyDown(event: KeyboardEvent): boolean | void {\n if (!this.config.enableKeyboard) return;\n if (!event.ctrlKey || (event.key !== 'ArrowUp' && event.key !== 'ArrowDown')) return;\n\n const grid = this.internalGrid;\n const focusRow = grid._focusRow;\n const rows = grid._rows ?? this.sourceRows;\n if (focusRow < 0 || focusRow >= rows.length) return;\n\n const direction = event.key === 'ArrowUp' ? 'up' : 'down';\n const toIndex = direction === 'up' ? focusRow - 1 : focusRow + 1;\n if (toIndex < 0 || toIndex >= rows.length) return;\n\n const row = rows[focusRow];\n if (!this.canMoveRow(focusRow, toIndex)) return;\n\n this.handleKeyboardMove(row, focusRow, toIndex, grid._focusCol);\n event.preventDefault();\n event.stopPropagation();\n return true;\n }\n\n /** @internal */\n override onCellClick(): void {\n this.flushPendingMove();\n }\n // #endregion\n\n // #region Public API\n /** Move a row to a new position programmatically (intra-grid). */\n moveRow(fromIndex: number, toIndex: number): void {\n const rows = [...this.sourceRows];\n if (fromIndex < 0 || fromIndex >= rows.length) return;\n if (toIndex < 0 || toIndex >= rows.length) return;\n if (fromIndex === toIndex) return;\n if (!this.canMoveRow(fromIndex, toIndex)) return;\n this.executeIntraGridMove(rows[fromIndex], fromIndex, toIndex, 'keyboard');\n }\n\n /**\n * Check if a row can be moved within this grid.\n * Consults the user-provided `canMove` callback (or `canDrag` veto for the\n * source row), the plugin query system (`canMoveRow`), and `canDrop` for\n * the target.\n */\n canMoveRow(fromIndex: number, toIndex: number): boolean {\n // During debounced keyboard moves, `grid._rows` diverges from\n // `sourceRows` (the user-facing snapshot) because the plugin mutates\n // `_rows` per keystroke and only commits on flush. `onKeyDown` resolves\n // the focused row from `_rows ?? sourceRows`, so validation must read\n // from the same array — otherwise we'd run `canDrag`/`canMove`/queries\n // against the wrong row.\n const rows = this.internalGrid._rows ?? this.sourceRows;\n if (fromIndex < 0 || fromIndex >= rows.length) return false;\n if (toIndex < 0 || toIndex >= rows.length) return false;\n if (fromIndex === toIndex) return false;\n\n // Plugin query veto (Tree, GroupingRows)\n const row = rows[fromIndex] as T;\n const queryResults = this.grid?.query?.<boolean>('canMoveRow', row);\n if (Array.isArray(queryResults) && queryResults.includes(false)) return false;\n\n // canDrag veto (dragstart side)\n if (this.config.canDrag && !this.config.canDrag(row, fromIndex)) return false;\n\n // Legacy canMove callback\n if (this.config.canMove) {\n const direction = toIndex < fromIndex ? 'up' : 'down';\n if (!this.config.canMove(row, fromIndex, toIndex, direction)) return false;\n }\n\n // canDrop callback (intra-grid synthesised payload)\n if (this.config.canDrop) {\n const payload: RowDragPayload<T> = {\n sessionId: 'intra',\n sourceGridId: this.gridId,\n dropZone: this.config.dropZone ?? '',\n rows: [row],\n rowIndices: [fromIndex],\n operation: 'move',\n };\n if (!this.config.canDrop(payload, toIndex)) return false;\n }\n\n return true;\n }\n // #endregion\n\n // #region Drag Setup\n\n private setupDelegatedDragListeners(): void {\n const gridEl = this.gridElement;\n if (!gridEl) return;\n const signal = this.disconnectSignal;\n\n gridEl.addEventListener('dragstart', (e) => this.onDragStart(e as DragEvent), { signal });\n gridEl.addEventListener('dragend', () => this.onDragEnd(), { signal });\n gridEl.addEventListener('dragover', (e) => this.onDragOver(e as DragEvent), { signal });\n gridEl.addEventListener('dragleave', (e) => this.onDragLeave(e as DragEvent), { signal });\n gridEl.addEventListener('drop', (e) => this.onDrop(e as DragEvent), { signal });\n }\n\n private onDragStart(de: DragEvent): void {\n const target = de.target as HTMLElement | null;\n if (!target) return;\n\n // Resolve the row element being picked up. Order matters: a click on the\n // grip column inside a row-draggable grid should still go through the\n // handle path so the cursor offset feels right.\n const handle = target.closest('.dg-row-drag-handle') as HTMLElement | null;\n let rowEl: HTMLElement | null = null;\n let initiatedFromHandle = false;\n if (handle) {\n rowEl = handle.closest('.data-grid-row') as HTMLElement | null;\n initiatedFromHandle = true;\n } else if (this.rowIsDraggable) {\n // Row-as-handle: any cell may start the drag, but interactive\n // descendants (inputs, buttons, anchors, contenteditable, open\n // editors, selection checkboxes) keep their native behaviour.\n if (this.isInteractiveDragOrigin(target)) return;\n rowEl = target.closest('.data-grid-row') as HTMLElement | null;\n }\n if (!rowEl) return;\n\n const rowIndex = this.getRowIndex(rowEl);\n if (rowIndex < 0) return;\n\n // Resolve the rows being dragged: whole selection if dragged row is selected.\n const { rows, indices } = this.resolveDraggedRows(rowIndex);\n if (rows.length === 0) return;\n\n // canDrag veto on the originating row\n if (this.config.canDrag && !this.config.canDrag(rows[0], rowIndex)) {\n de.preventDefault();\n return;\n }\n\n const operation = this.config.operation ?? 'move';\n const dropZone = this.config.dropZone ?? '';\n const sessionId = newDragSessionId();\n\n // Emit cancelable row-drag-start (source-side veto)\n const startDetail: RowDragStartDetail<T> = { rows, indices, operation, dropZone };\n if (this.emitCancelable('row-drag-start', startDetail)) {\n de.preventDefault();\n return;\n }\n\n this.isDragging = true;\n this.draggedRowIndex = rowIndex;\n this.draggedRows = rows;\n this.draggedIndices = indices;\n this.dragSessionId = sessionId;\n this.dragAccepted = false;\n\n // Build the cross-grid payload (always built, even when dropZone is empty —\n // intra-grid drops still benefit from the registry round-trip)\n const serialize = this.config.serializeRow ?? ((r: T) => r);\n const payload: RowDragPayload<T> = {\n sessionId,\n sourceGridId: this.gridId,\n dropZone,\n rows: rows.map(serialize) as T[],\n rowIndices: indices,\n operation,\n };\n\n if (de.dataTransfer) {\n de.dataTransfer.effectAllowed = operation === 'copy' ? 'copyMove' : 'move';\n try {\n de.dataTransfer.setData(TBW_ROW_DRAG_MIME, encodePayload(payload));\n if (dropZone) de.dataTransfer.setData(mimeForZone(dropZone), encodePayload(payload));\n // Plain-text TSV fallback for external drop targets\n de.dataTransfer.setData('text/plain', formatRowsAsTSV(rows as Record<string, unknown>[], this.columns));\n } catch {\n /* JSDOM/happy-dom may throw on setData; harmless */\n }\n\n // Drag image: full-row clone for single-row drags (more legible than\n // the handle alone); count badge for multi-row drags.\n if (rows.length > 1) {\n const badge = document.createElement('div');\n badge.className = 'tbw-row-drag-count';\n badge.textContent = `${rows.length} rows`;\n document.body.appendChild(badge);\n try {\n de.dataTransfer.setDragImage(badge, 10, 10);\n } catch {\n /* ignore */\n }\n setTimeout(() => badge.remove(), 0);\n } else {\n this.attachRowCloneDragImage(de, rowEl, initiatedFromHandle ? handle : null);\n }\n }\n\n // Same-window registry + current-session marker\n registerDragSession(sessionId, rows as unknown[]);\n setCurrentDragSession(sessionId, payload);\n\n rowEl.classList.add(GridClasses.DRAGGING);\n this.gridElement.classList.add('tbw-grid--drag-source');\n }\n\n /**\n * Selectors whose dragstart should NOT initiate a row drag in `dragFrom: 'row'`\n * mode. Keeps native interactions (text input, button clicks, link drag,\n * cell editing, selection checkboxes) working unchanged.\n */\n private static readonly INTERACTIVE_DRAG_SELECTORS =\n 'input,textarea,select,button,a,[contenteditable=\"\"],[contenteditable=\"true\"],.dg-cell-editor,.tbw-checkbox-cell';\n\n /** @internal */\n private isInteractiveDragOrigin(target: HTMLElement): boolean {\n return target.closest(RowDragDropPlugin.INTERACTIVE_DRAG_SELECTORS) !== null;\n }\n\n /**\n * Build a full-row drag image by cloning `rowEl` so the user sees the\n * actual row — not just the grip icon — while dragging.\n *\n * The clone is appended off-screen, snapshotted by the browser via\n * `setDragImage`, then removed on the next tick (after the snapshot).\n * The cursor offset is preserved relative to where the user pressed.\n */\n private attachRowCloneDragImage(de: DragEvent, rowEl: HTMLElement, handle: HTMLElement | null): void {\n if (!de.dataTransfer) return;\n const rect = rowEl.getBoundingClientRect();\n const clone = rowEl.cloneNode(true) as HTMLElement;\n clone.classList.add('tbw-row-drag-clone');\n // Strip transient classes that would look wrong in the drag image.\n clone.classList.remove('dragging', 'drop-target', 'drop-before', 'drop-after', 'flip-animating', 'row-focus');\n clone.removeAttribute('aria-selected');\n // Preserve the actual rendered width so cells don't reflow in the snapshot.\n clone.style.width = `${rect.width}px`;\n clone.style.height = `${rect.height}px`;\n // The clone MUST stay inside the grid host: every core row/cell rule is\n // scoped under `tbw-grid …` (see core/styles/*.css), and the\n // `--tbw-column-template` custom property is set on the host. If the\n // clone is moved to `document.body`, none of those rules match and the\n // drag image collapses to an empty box. Off-screen positioning via\n // `position: fixed` works the same regardless of the DOM parent.\n this.gridElement.appendChild(clone);\n // Cursor offset: where the user pressed inside the source row. Falls\n // back to the centre of the handle when initiated from the grip.\n let offsetX = de.clientX - rect.left;\n let offsetY = de.clientY - rect.top;\n if (handle) {\n const handleRect = handle.getBoundingClientRect();\n offsetX = handleRect.left - rect.left + handleRect.width / 2;\n offsetY = handleRect.top - rect.top + handleRect.height / 2;\n }\n // Clamp into the row bounds so the cursor stays inside the drag image.\n offsetX = Math.max(0, Math.min(rect.width, offsetX));\n offsetY = Math.max(0, Math.min(rect.height, offsetY));\n try {\n de.dataTransfer.setDragImage(clone, offsetX, offsetY);\n } catch {\n /* JSDOM/happy-dom: harmless */\n }\n setTimeout(() => clone.remove(), 0);\n }\n\n private onDragOver(de: DragEvent): void {\n const dt = de.dataTransfer;\n if (!dt) return;\n\n // Identify whether a tbw row drag is in progress and whether it matches our zone.\n const types = dt.types ? Array.from(dt.types) : [];\n if (!hasAnyRowDragMime(types) && !this.isDragging) return;\n\n const dropZone = this.config.dropZone ?? '';\n const session = getCurrentDragSession<T>();\n\n // For cross-grid drags we require a matching zone-tagged MIME OR the\n // session payload's dropZone must match ours.\n const isIntra = this.isDragging && session?.payload.sourceGridId === this.gridId;\n if (!isIntra) {\n if (!dropZone) return; // intra-grid only — ignore external drags\n const matchingMime = findMatchingZoneMime(types, dropZone);\n if (!matchingMime && !(session && session.payload.dropZone === dropZone)) return;\n }\n\n de.preventDefault();\n if (dt) dt.dropEffect = (session?.payload.operation ?? this.config.operation ?? 'move') as 'copy' | 'move';\n\n // Compute drop position\n const rowEl = (de.target as HTMLElement).closest('.data-grid-row') as HTMLElement | null;\n const rows = this.internalGrid._rows ?? [];\n const pos = computeDropPosition(rowEl, de.clientY, (el) => this.getRowIndex(el), rows.length);\n\n // Same-row no-op for intra-grid\n if (isIntra && pos.overIndex !== null && pos.overIndex === this.draggedRowIndex) {\n this.clearDropTargetClasses();\n return;\n }\n\n // canDrop check (same-window only — payload visible)\n if (session && this.config.canDrop) {\n const accepted = this.config.canDrop(session.payload, pos.insertIndex);\n this.gridElement.classList.toggle('tbw-grid--drop-target-active', accepted);\n this.gridElement.classList.toggle('tbw-grid--drop-target-rejected', !accepted);\n if (!accepted) {\n this.clearDropTargetClasses();\n return;\n }\n } else {\n this.gridElement.classList.add('tbw-grid--drop-target-active');\n }\n\n this.dropRowIndex = pos.insertIndex;\n this.applyDropPositionClasses(rowEl, pos.isBefore);\n\n // Auto-scroll the target viewport\n if (this.config.autoScroll !== false) {\n this.ensureAutoScroller();\n this.autoScroller?.onPointerMove(de.clientY);\n }\n }\n\n private onDragLeave(de: DragEvent): void {\n const rowEl = (de.target as HTMLElement).closest('.data-grid-row') as HTMLElement | null;\n if (rowEl) rowEl.classList.remove('drop-target', 'drop-before', 'drop-after');\n // Tear down grid-level state when the cursor leaves the grid entirely\n if (de.currentTarget && !this.gridElement.contains(de.relatedTarget as Node)) {\n this.gridElement.classList.remove('tbw-grid--drop-target-active', 'tbw-grid--drop-target-rejected');\n this.autoScroller?.stop();\n }\n }\n\n private onDrop(de: DragEvent): void {\n de.preventDefault();\n this.autoScroller?.stop();\n this.gridElement.classList.remove('tbw-grid--drop-target-active', 'tbw-grid--drop-target-rejected');\n this.clearDropTargetClasses();\n\n const dt = de.dataTransfer;\n if (!dt) return;\n\n // Resolve payload — prefer same-window session, fall back to dataTransfer JSON\n const session = getCurrentDragSession<T>();\n let payload: RowDragPayload<T> | null = session?.payload ?? null;\n let liveRows: T[] | null = null;\n\n if (payload) {\n const lookup = lookupDragSession<T>(payload.sessionId);\n if (lookup) liveRows = lookup;\n } else {\n const raw = dt.getData(TBW_ROW_DRAG_MIME);\n payload = decodePayload<T>(raw);\n if (payload) {\n const lookup = lookupDragSession<T>(payload.sessionId);\n if (lookup) liveRows = lookup;\n }\n }\n if (!payload) return;\n\n // Drop position (recompute in case dragover wasn't called for a few frames)\n const rowEl = (de.target as HTMLElement).closest('.data-grid-row') as HTMLElement | null;\n const rows = this.internalGrid._rows ?? [];\n const pos = computeDropPosition(rowEl, de.clientY, (el) => this.getRowIndex(el), rows.length);\n let targetIndex = this.dropRowIndex ?? pos.insertIndex;\n\n const isIntra = payload.sourceGridId === this.gridId;\n const dropZone = this.config.dropZone ?? '';\n\n if (isIntra) {\n // Intra-grid path — preserve `RowReorderPlugin` semantics: emit `row-move`.\n const fromIndex = payload.rowIndices[0];\n // Adjust toIndex when dropping after the dragged row (single-row only)\n if (payload.rowIndices.length === 1 && targetIndex > fromIndex) targetIndex--;\n if (fromIndex === targetIndex) return;\n const row = (liveRows ?? payload.rows)[0];\n if (!this.canMoveRow(fromIndex, targetIndex)) return;\n this.executeIntraGridMove(row, fromIndex, targetIndex, 'drag');\n return;\n }\n\n // Cross-grid path\n if (!dropZone || dropZone !== payload.dropZone) return;\n\n // canDrop final check\n if (this.config.canDrop && !this.config.canDrop(payload, targetIndex)) {\n this.gridElement.classList.add('tbw-grid--drop-target-rejected');\n setTimeout(() => this.gridElement.classList.remove('tbw-grid--drop-target-rejected'), 200);\n return;\n }\n\n // Resolve final row references — live (same-window) or deserialized JSON\n const deserialize = this.config.deserializeRow ?? ((r: unknown) => r as T);\n const incomingRows: T[] = liveRows ?? payload.rows.map((r) => deserialize(r as unknown));\n\n const dropDetail: RowDropDetail<T> = {\n payload,\n sourceGridId: payload.sourceGridId,\n targetIndex,\n operation: payload.operation,\n };\n if (this.emitCancelable('row-drop', dropDetail)) return;\n\n // Insert into target grid's _rows\n const targetRows = [...rows];\n targetRows.splice(targetIndex, 0, ...(incomingRows as unknown[]));\n this.grid.rows = targetRows;\n\n // Locate the source plugin in THIS window. If it's here we handle the\n // source-side mutation directly; if it isn't, we broadcast a message and\n // let the source-window plugin (if any) handle removal + transfer emit.\n const sourcePlugin = this.findPeerOnGrid(payload.sourceGridId);\n\n // Remove from source grid's _rows when operation === 'move' (same-window)\n if (payload.operation === 'move' && sourcePlugin) {\n const sourceGrid = document.getElementById(payload.sourceGridId) as\n | (HTMLElement & { rows?: unknown[]; _rows?: unknown[] })\n | null;\n if (sourceGrid) {\n const srcRows = (sourceGrid._rows ?? sourceGrid.rows ?? []).slice();\n // Remove from highest index down so earlier indices stay stable\n const sortedIndices = [...payload.rowIndices].sort((a, b) => b - a);\n for (const idx of sortedIndices) {\n if (idx >= 0 && idx < srcRows.length) srcRows.splice(idx, 1);\n }\n sourceGrid.rows = srcRows;\n }\n }\n\n // Mark accepted on the source plugin so dragend knows (same-window only —\n // cross-window source flips its own flag in `onRemoteTransfer`).\n if (sourcePlugin) sourcePlugin.dragAccepted = true;\n\n // Emit row-transfer on the target. The source's `row-transfer` is fired\n // either here (same-window) or by the source plugin in `onRemoteTransfer`\n // (cross-window).\n const transferDetail: RowTransferDetail<T> = {\n rows: incomingRows,\n fromGridId: payload.sourceGridId,\n toGridId: this.gridId,\n fromIndices: payload.rowIndices,\n toIndex: targetIndex,\n operation: payload.operation,\n };\n this.emit('row-transfer', transferDetail);\n\n if (sourcePlugin) {\n sourcePlugin.emitTransfer(transferDetail);\n } else {\n // Cross-window: broadcast so the source window can finish its half of\n // the transfer (row removal on `move`, `row-transfer` emit, accepted flip).\n broadcastRemoteTransfer({\n type: 'tbw-row-drag-drop:transfer',\n sessionId: payload.sessionId,\n sourceGridId: payload.sourceGridId,\n toGridId: this.gridId,\n dropZone,\n rowIndices: payload.rowIndices,\n toIndex: targetIndex,\n operation: payload.operation,\n // Re-use the payload's already-serialized rows so the source side can\n // round-trip them through `deserializeRow` for its `row-transfer` event.\n serializedRows: payload.rows as unknown[],\n });\n }\n }\n\n /**\n * Source-window handler for a remote `row-transfer` broadcast from a target\n * window. Only runs on the plugin instance whose grid id matches the message.\n * @internal\n */\n private onRemoteTransfer(msg: RemoteTransferMessage): void {\n if (msg.sourceGridId !== this.gridId) return;\n // Defensive: only act when the message zone matches our zone. This prevents\n // a stray message from a grid sharing the same id but a different zone\n // (e.g. independent demos in different tabs) from mutating our rows.\n const dropZone = this.config.dropZone ?? '';\n if (!dropZone || msg.dropZone !== dropZone) return;\n\n // Resolve incoming rows (for the `row-transfer` event payload).\n const deserialize = this.config.deserializeRow ?? ((r: unknown) => r as T);\n const incomingRows: T[] = msg.serializedRows.map((r) => deserialize(r));\n\n if (msg.operation === 'move') {\n const srcRows = (this.internalGrid._rows ?? this.sourceRows).slice();\n const sortedIndices = [...msg.rowIndices].sort((a, b) => b - a);\n for (const idx of sortedIndices) {\n if (idx >= 0 && idx < srcRows.length) srcRows.splice(idx, 1);\n }\n this.grid.rows = srcRows as unknown[];\n }\n\n // Flip accepted before dragend (best-effort — the message may arrive after\n // dragend has already fired with `accepted: false`; `row-transfer` is the\n // authoritative success signal).\n this.dragAccepted = true;\n\n this.emit('row-transfer', {\n rows: incomingRows,\n fromGridId: msg.sourceGridId,\n toGridId: msg.toGridId,\n fromIndices: msg.rowIndices,\n toIndex: msg.toIndex,\n operation: msg.operation,\n } as RowTransferDetail<T>);\n }\n\n private onDragEnd(): void {\n if (this.dragSessionId) clearDragSession(this.dragSessionId);\n clearCurrentDragSession();\n this.autoScroller?.stop();\n this.gridElement.classList.remove('tbw-grid--drag-source');\n\n if (this.isDragging) {\n const endDetail: RowDragEndDetail<T> = {\n rows: this.draggedRows,\n indices: this.draggedIndices,\n accepted: this.dragAccepted,\n };\n this.emit('row-drag-end', endDetail);\n }\n this.clearDragClasses();\n this.resetDragState();\n }\n // #endregion\n\n // #region Helpers\n\n /** Public wrapper so a peer plugin can dispatch `row-transfer` on this grid. @internal */\n emitTransfer(detail: RowTransferDetail<T>): void {\n this.emit('row-transfer', detail);\n }\n\n /** Find the peer `RowDragDropPlugin` instance on another grid by id. */\n private findPeerOnGrid(gridId: string): RowDragDropPlugin<T> | null {\n const peerEl = document.getElementById(gridId) as\n | (HTMLElement & { getPluginByName?: (name: string) => RowDragDropPlugin<T> | undefined })\n | null;\n if (!peerEl?.getPluginByName) return null;\n return peerEl.getPluginByName('rowDragDrop') ?? null;\n }\n\n private resolveDraggedRows(originIndex: number): { rows: T[]; indices: number[] } {\n const rows = this.internalGrid._rows ?? this.sourceRows;\n const originRow = rows[originIndex] as T;\n\n // If a selection plugin is loaded and the dragged row is selected, drag the whole selection.\n const selection = this.grid?.getPluginByName?.('selection') as\n | { getSelectedRowIndices?: () => number[]; getSelectedRows?: <U>() => U[] }\n | undefined;\n if (selection?.getSelectedRowIndices) {\n const selectedIndices = selection.getSelectedRowIndices();\n if (selectedIndices.includes(originIndex) && selectedIndices.length > 1) {\n const sorted = [...selectedIndices].sort((a, b) => a - b);\n return {\n rows: sorted.map((i) => rows[i] as T),\n indices: sorted,\n };\n }\n }\n return { rows: [originRow], indices: [originIndex] };\n }\n\n private ensureAutoScroller(): void {\n if (this.autoScroller) return;\n const viewport = this.gridElement.querySelector<HTMLElement>('.rows-viewport');\n if (!viewport) return;\n const opts = typeof this.config.autoScroll === 'object' ? this.config.autoScroll : undefined;\n this.autoScroller = createAutoScroller(viewport, opts, (active) => {\n this.gridElement.classList.toggle('tbw-grid--auto-scrolling', active);\n });\n }\n\n private applyDropPositionClasses(rowEl: HTMLElement | null, isBefore: boolean): void {\n this.clearDropTargetClasses();\n if (!rowEl) return;\n rowEl.classList.add('drop-target');\n rowEl.classList.toggle('drop-before', isBefore);\n rowEl.classList.toggle('drop-after', !isBefore);\n }\n\n private clearDropTargetClasses(): void {\n this.gridElement?.querySelectorAll('.data-grid-row.drop-target').forEach((row) => {\n row.classList.remove('drop-target', 'drop-before', 'drop-after');\n });\n }\n\n private clearDragClasses(): void {\n this.gridElement?.querySelectorAll('.data-grid-row').forEach((row) => {\n row.classList.remove(GridClasses.DRAGGING, 'drop-target', 'drop-before', 'drop-after');\n });\n }\n\n private resetDragState(): void {\n this.isDragging = false;\n this.draggedRowIndex = null;\n this.draggedRows = [];\n this.draggedIndices = [];\n this.dragSessionId = null;\n this.dragAccepted = false;\n this.dropRowIndex = null;\n this.pendingMove = null;\n }\n\n private getRowIndex(rowEl: HTMLElement): number {\n const cell = rowEl.querySelector('.cell[data-row]');\n return cell ? parseInt(cell.getAttribute('data-row') ?? '-1', 10) : -1;\n }\n\n private clearDebounceTimer(): void {\n if (this.debounceTimer) {\n clearTimeout(this.debounceTimer);\n this.debounceTimer = null;\n }\n }\n\n // #endregion\n\n // #region Intra-Grid Move (parity with RowReorderPlugin)\n\n private handleKeyboardMove(row: T, fromIndex: number, toIndex: number, focusCol: number): void {\n if (!this.pendingMove) {\n this.pendingMove = { originalIndex: fromIndex, currentIndex: toIndex, row };\n } else {\n this.pendingMove.currentIndex = toIndex;\n }\n this.lastFocusCol = focusCol;\n\n const grid = this.internalGrid;\n const rows = [...(grid._rows ?? this.sourceRows)];\n const [movedRow] = rows.splice(fromIndex, 1);\n rows.splice(toIndex, 0, movedRow);\n\n grid._rows = rows;\n grid._focusRow = toIndex;\n grid._focusCol = focusCol;\n grid.refreshVirtualWindow(true);\n ensureCellVisible(grid);\n\n this.clearDebounceTimer();\n this.debounceTimer = setTimeout(() => this.flushPendingMove(), this.config.debounceMs ?? 300);\n }\n\n private flushPendingMove(): void {\n this.clearDebounceTimer();\n if (!this.pendingMove) return;\n const { originalIndex, currentIndex, row: movedRow } = this.pendingMove;\n this.pendingMove = null;\n if (originalIndex === currentIndex) return;\n\n const grid = this.internalGrid;\n // `grid._rows` already reflects the post-move order (mutated incrementally\n // by `handleKeyboardMove`); report it as `detail.rows` so consumers see\n // the actual reordered array, not the original `sourceRows` snapshot.\n const postMoveRows = (grid._rows ?? this.sourceRows) as T[];\n const detail: RowMoveDetail<T> = {\n row: movedRow as T,\n fromIndex: originalIndex,\n toIndex: currentIndex,\n rows: [...postMoveRows],\n source: 'keyboard',\n };\n const cancelled = this.emitCancelable('row-move', detail);\n if (cancelled) {\n // Revert: restore the original snapshot. `sourceRows` was never mutated\n // during the pending move (only `grid._rows` was), so resetting from it\n // is the correct rollback regardless of how many incremental keyboard\n // moves accumulated.\n grid._rows = [...this.sourceRows];\n grid._focusRow = originalIndex;\n grid._focusCol = this.lastFocusCol;\n grid.refreshVirtualWindow(true);\n ensureCellVisible(grid);\n }\n }\n\n private executeIntraGridMove(row: unknown, fromIndex: number, toIndex: number, source: 'keyboard' | 'drag'): void {\n const rows = [...this.sourceRows];\n const [movedRow] = rows.splice(fromIndex, 1);\n rows.splice(toIndex, 0, movedRow);\n const detail: RowMoveDetail<T> = {\n row: row as T,\n fromIndex,\n toIndex,\n rows: rows as T[],\n source,\n };\n const cancelled = this.emitCancelable('row-move', detail);\n if (cancelled) return;\n if (this.animationType === 'flip' && this.gridElement) {\n const oldPositions = this.captureRowPositions();\n this.grid.rows = rows;\n requestAnimationFrame(() => {\n void this.gridElement.offsetHeight;\n this.animateFLIP(oldPositions, fromIndex, toIndex);\n });\n } else {\n this.grid.rows = rows;\n }\n }\n\n private captureRowPositions(): Map<number, number> {\n const positions = new Map<number, number>();\n this.gridElement?.querySelectorAll('.data-grid-row').forEach((row) => {\n const rowIndex = this.getRowIndex(row as HTMLElement);\n if (rowIndex >= 0) positions.set(rowIndex, row.getBoundingClientRect().top);\n });\n return positions;\n }\n\n private animateFLIP(oldPositions: Map<number, number>, fromIndex: number, toIndex: number): void {\n const gridEl = this.gridElement;\n if (!gridEl || oldPositions.size === 0) return;\n\n const minIndex = Math.min(fromIndex, toIndex);\n const maxIndex = Math.max(fromIndex, toIndex);\n const rowsToAnimate: { el: HTMLElement; deltaY: number }[] = [];\n\n gridEl.querySelectorAll('.data-grid-row').forEach((row) => {\n const rowEl = row as HTMLElement;\n const newRowIndex = this.getRowIndex(rowEl);\n if (newRowIndex < 0 || newRowIndex < minIndex || newRowIndex > maxIndex) return;\n let oldIndex: number;\n if (newRowIndex === toIndex) oldIndex = fromIndex;\n else if (fromIndex < toIndex) oldIndex = newRowIndex + 1;\n else oldIndex = newRowIndex - 1;\n const oldTop = oldPositions.get(oldIndex);\n if (oldTop === undefined) return;\n const newTop = rowEl.getBoundingClientRect().top;\n const deltaY = oldTop - newTop;\n if (Math.abs(deltaY) > 1) rowsToAnimate.push({ el: rowEl, deltaY });\n });\n\n if (rowsToAnimate.length === 0) return;\n\n rowsToAnimate.forEach(({ el, deltaY }) => {\n el.style.transform = `translateY(${deltaY}px)`;\n });\n void gridEl.offsetHeight;\n\n const duration = this.animationDuration;\n requestAnimationFrame(() => {\n rowsToAnimate.forEach(({ el }) => {\n el.classList.add('flip-animating');\n el.style.transform = '';\n });\n setTimeout(() => {\n rowsToAnimate.forEach(({ el }) => {\n el.style.transform = '';\n el.classList.remove('flip-animating');\n });\n }, duration + 50);\n });\n }\n\n // #endregion\n}\n"],"names":["currentSession","getCurrentDragSession","clearCurrentDragSession","TBW_ROW_DRAG_MIME","parseZoneFromMime","mime","match","decodeURIComponent","encodePayload","payload","JSON","stringify","computeDropPosition","rowEl","clientY","rowIndexResolver","totalRows","overIndex","insertIndex","isBefore","targetIndex","rect","getBoundingClientRect","top","height","sharedChannel","remoteListeners","Set","ensureCrossWindowChannel","BroadcastChannel","addEventListener","event","data","type","listener","Array","from","RowDragDropPlugin","BaseGridPlugin","name","aliases","styles","static","events","description","cancelable","defaultConfig","enableKeyboard","dragHandlePosition","dragHandleWidth","debounceMs","animation","operation","autoScroll","dragFrom","shouldRenderDragHandle","explicit","this","config","showDragHandle","rowIsDraggable","animationType","isAnimationEnabled","isDragging","draggedRowIndex","draggedRows","draggedIndices","dragSessionId","dragAccepted","dropRowIndex","pendingMove","debounceTimer","lastFocusCol","autoScroller","gridId","remoteTransferListener","msg","onRemoteTransfer","internalGrid","grid","attach","super","host","gridElement","id","newDragSessionId","slice","setupDelegatedDragListeners","add","detach","clearDebounceTimer","stop","delete","size","close","unregisterRemoteTransferListener","clearDragSession","resetDragState","processColumns","columns","dragHandleColumn","field","header","width","resizable","sortable","filterable","lockPosition","utility","viewRenderer","container","document","createElement","className","setAttribute","draggable","setIcon","afterRender","applyRowDraggable","onScrollRender","body","_bodyEl","wantDraggable","rows","querySelectorAll","row","getAttribute","hasAttribute","removeAttribute","onKeyDown","ctrlKey","key","focusRow","_focusRow","_rows","sourceRows","length","toIndex","canMoveRow","handleKeyboardMove","_focusCol","preventDefault","stopPropagation","onCellClick","flushPendingMove","moveRow","fromIndex","executeIntraGridMove","queryResults","query","isArray","includes","canDrag","canMove","direction","canDrop","sessionId","sourceGridId","dropZone","rowIndices","gridEl","signal","disconnectSignal","e","onDragStart","onDragEnd","onDragOver","onDragLeave","onDrop","de","target","handle","closest","initiatedFromHandle","isInteractiveDragOrigin","rowIndex","getRowIndex","indices","resolveDraggedRows","startDetail","emitCancelable","serialize","serializeRow","r","map","dataTransfer","effectAllowed","setData","encodeURIComponent","dataColumns","filter","c","lines","cells","col","value","String","replace","push","join","formatRowsAsTSV","badge","textContent","appendChild","setDragImage","setTimeout","remove","attachRowCloneDragImage","registerDragSession","setCurrentDragSession","classList","GridClasses","DRAGGING","INTERACTIVE_DRAG_SELECTORS","clone","cloneNode","style","offsetX","clientX","left","offsetY","handleRect","Math","max","min","dt","types","t","startsWith","hasAnyRowDragMime","session","isIntra","matchingMime","zone","findMatchingZoneMime","dropEffect","pos","el","clearDropTargetClasses","accepted","toggle","applyDropPositionClasses","ensureAutoScroller","onPointerMove","currentTarget","contains","relatedTarget","liveRows","lookup","lookupDragSession","raw","parsed","parse","idx","Number","isInteger","decodePayload","getData","deserialize","deserializeRow","incomingRows","dropDetail","targetRows","splice","sourcePlugin","findPeerOnGrid","sourceGrid","getElementById","srcRows","sortedIndices","sort","a","b","transferDetail","fromGridId","toGridId","fromIndices","emit","emitTransfer","channel","postMessage","broadcastRemoteTransfer","serializedRows","endDetail","clearDragClasses","detail","peerEl","getPluginByName","originIndex","originRow","selection","getSelectedRowIndices","selectedIndices","sorted","i","viewport","querySelector","opts","options","onScrollChange","edgeSize","baseSpeed","speed","maxSpeed","rafId","pointerY","active","setActive","next","tick","delta","ratio","round","bottom","before","scrollTop","requestAnimationFrame","cancelAnimationFrame","isScrolling","createAutoScroller","forEach","cell","parseInt","clearTimeout","focusCol","currentIndex","originalIndex","movedRow","refreshVirtualWindow","ensureCellVisible","source","oldPositions","captureRowPositions","offsetHeight","animateFLIP","positions","Map","set","minIndex","maxIndex","rowsToAnimate","newRowIndex","oldIndex","oldTop","get","deltaY","abs","transform","duration","animationDuration"],"mappings":"klBA8BA,IAAIA,EAAiF,KAQ9E,SAASC,IACd,OAAOD,CACT,CAGO,SAASE,IACdF,EAAiB,IACnB,CAOO,MAAMG,EAAoB,mCAQ1B,SAASC,EAAkBC,GAChC,MAAMC,EAAQD,EAAKC,MAAM,kDACzB,IAAKA,EAAO,OAAO,KACnB,IACE,OAAOC,mBAAmBD,EAAM,GAClC,CAAA,MACE,OAAOA,EAAM,EACf,CACF,CA8CO,SAASE,EAAiBC,GAC/B,OAAOC,KAAKC,UAAUF,EACxB,CAmDO,SAASG,EACdC,EACAC,EACAC,EACAC,GAEA,IAAKH,EACH,MAAO,CAAEI,UAAW,KAAMC,Y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